@sgflabs/storefront-core 0.1.19 → 0.1.21
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/package.json +7 -7
- package/src/components/cells/MobileNavbar/MobileNavbar.tsx +4 -1
- package/src/components/cells/UserDropdown/UserDropdown.tsx +7 -4
- package/src/components/molecules/LegalDocument/LegalDocument.tsx +14 -5
- package/src/components/organisms/Header/Header.tsx +5 -3
- package/src/components/organisms/Header/HeaderAccountControls.tsx +2 -2
- package/src/lib/data/brand.ts +3 -3
- package/src/lib/data/vendor-signup.ts +31 -0
- package/src/pages/main/legal/page.tsx +7 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sgflabs/storefront-core",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.21",
|
|
4
4
|
"description": "Shared storefront library consumed as raw TypeScript source by the brand apps.",
|
|
5
5
|
"license": "PolyForm-Shield-1.0.0",
|
|
6
6
|
"sideEffects": [
|
|
@@ -56,9 +56,9 @@
|
|
|
56
56
|
"devDependencies": {
|
|
57
57
|
"@sentry/nextjs": "^10.63.0",
|
|
58
58
|
"@sgflabs/artha-go-sdk": "^0.3.0",
|
|
59
|
-
"@sgflabs/gstin": "^0.1.
|
|
60
|
-
"@sgflabs/page-spec": "^0.1.
|
|
61
|
-
"@sgflabs/storefront-core-common": "^0.1.
|
|
59
|
+
"@sgflabs/gstin": "^0.1.21",
|
|
60
|
+
"@sgflabs/page-spec": "^0.1.21",
|
|
61
|
+
"@sgflabs/storefront-core-common": "^0.1.21",
|
|
62
62
|
"@testing-library/dom": "^10.4.1",
|
|
63
63
|
"@testing-library/jest-dom": "^7.0.0",
|
|
64
64
|
"@testing-library/react": "^16.3.2",
|
|
@@ -74,9 +74,9 @@
|
|
|
74
74
|
"peerDependencies": {
|
|
75
75
|
"@sentry/nextjs": "^10.63.0",
|
|
76
76
|
"@sgflabs/artha-go-sdk": "^0.3.0",
|
|
77
|
-
"@sgflabs/gstin": "^0.1.
|
|
78
|
-
"@sgflabs/page-spec": "^0.1.
|
|
79
|
-
"@sgflabs/storefront-core-common": "^0.1.
|
|
77
|
+
"@sgflabs/gstin": "^0.1.21",
|
|
78
|
+
"@sgflabs/page-spec": "^0.1.21",
|
|
79
|
+
"@sgflabs/storefront-core-common": "^0.1.21",
|
|
80
80
|
"next": "15.5.27",
|
|
81
81
|
"react": "^19.3.1",
|
|
82
82
|
"react-dom": "^19.3.1"
|
|
@@ -17,10 +17,13 @@ export const MobileNavbar = ({
|
|
|
17
17
|
categories,
|
|
18
18
|
parentCategories,
|
|
19
19
|
isLoggedIn = false,
|
|
20
|
+
vendorSignupUrl = `${process.env.NEXT_PUBLIC_VENDOR_URL}/register`,
|
|
20
21
|
}: {
|
|
21
22
|
categories: HttpTypes.StoreProductCategory[];
|
|
22
23
|
parentCategories: HttpTypes.StoreProductCategory[];
|
|
23
24
|
isLoggedIn?: boolean;
|
|
25
|
+
/** Where "Become a Vendor" goes; a seller storefront passes the link carrying its referral code. */
|
|
26
|
+
vendorSignupUrl?: string;
|
|
24
27
|
}) => {
|
|
25
28
|
const [isOpen, setIsOpen] = useState(false);
|
|
26
29
|
|
|
@@ -112,7 +115,7 @@ export const MobileNavbar = ({
|
|
|
112
115
|
Auctions
|
|
113
116
|
</LocalizedClientLink>
|
|
114
117
|
<a
|
|
115
|
-
href={
|
|
118
|
+
href={vendorSignupUrl}
|
|
116
119
|
target="_blank"
|
|
117
120
|
rel="noopener noreferrer"
|
|
118
121
|
className="text-sm font-medium text-action"
|
|
@@ -16,9 +16,9 @@ import { useState } from "react"
|
|
|
16
16
|
* with no space for it (design §1) — it moved into the account menu rather than
|
|
17
17
|
* being dropped. External link, so not a LocalizedClientLink.
|
|
18
18
|
*/
|
|
19
|
-
const BecomeVendorItem = () => (
|
|
19
|
+
const BecomeVendorItem = ({ href }: { href: string }) => (
|
|
20
20
|
<a
|
|
21
|
-
href={
|
|
21
|
+
href={href}
|
|
22
22
|
target="_blank"
|
|
23
23
|
rel="noopener noreferrer"
|
|
24
24
|
className="block px-4 py-3 label-md hover:bg-component-secondary"
|
|
@@ -30,8 +30,11 @@ const BecomeVendorItem = () => (
|
|
|
30
30
|
|
|
31
31
|
export const UserDropdown = ({
|
|
32
32
|
isLoggedIn,
|
|
33
|
+
vendorSignupUrl = `${process.env.NEXT_PUBLIC_VENDOR_URL}/register`,
|
|
33
34
|
}: {
|
|
34
35
|
isLoggedIn: boolean
|
|
36
|
+
/** Where "Become a vendor" goes; a seller storefront passes the link carrying its referral code. */
|
|
37
|
+
vendorSignupUrl?: string
|
|
35
38
|
}) => {
|
|
36
39
|
const [open, setOpen] = useState(false)
|
|
37
40
|
|
|
@@ -80,7 +83,7 @@ export const UserDropdown = ({
|
|
|
80
83
|
<NavigationItem href="/user/bids">My bids</NavigationItem>
|
|
81
84
|
<Divider />
|
|
82
85
|
<NavigationItem href="/user/settings">Settings</NavigationItem>
|
|
83
|
-
<BecomeVendorItem />
|
|
86
|
+
<BecomeVendorItem href={vendorSignupUrl} />
|
|
84
87
|
<LogoutButton />
|
|
85
88
|
</div>
|
|
86
89
|
) : (
|
|
@@ -98,7 +101,7 @@ export const UserDropdown = ({
|
|
|
98
101
|
Register
|
|
99
102
|
</LoginReturnLink>
|
|
100
103
|
<Divider />
|
|
101
|
-
<BecomeVendorItem />
|
|
104
|
+
<BecomeVendorItem href={vendorSignupUrl} />
|
|
102
105
|
</div>
|
|
103
106
|
)}
|
|
104
107
|
</Dropdown>
|
|
@@ -18,11 +18,22 @@ const HEADINGS = {
|
|
|
18
18
|
}
|
|
19
19
|
|
|
20
20
|
/**
|
|
21
|
-
*
|
|
22
|
-
* and the author-written content. The content is untrusted: react-markdown renders it as React
|
|
21
|
+
* The author-written policy text. The content is untrusted: react-markdown renders it as React
|
|
23
22
|
* elements with raw HTML escaped to text (no `rehype-raw`) and unsafe URL schemes dropped, so
|
|
24
23
|
* it can never inject markup or script.
|
|
25
24
|
*/
|
|
25
|
+
export function LegalContent({ content }: { content: string }) {
|
|
26
|
+
return (
|
|
27
|
+
<div className="text-neutral-700 leading-relaxed break-words [&_h2]:text-xl [&_h2]:font-semibold [&_h2]:mt-6 [&_h2]:mb-2 [&_h3]:text-lg [&_h3]:font-semibold [&_h3]:mt-4 [&_h3]:mb-2 [&_p]:my-3 [&_ul]:list-disc [&_ul]:pl-6 [&_ol]:list-decimal [&_ol]:pl-6 [&_a]:underline">
|
|
28
|
+
<ReactMarkdown components={HEADINGS}>{content}</ReactMarkdown>
|
|
29
|
+
</div>
|
|
30
|
+
)
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* A policy for reading: title, effective version (the content hash a checkout acceptance pins)
|
|
35
|
+
* and the author-written content.
|
|
36
|
+
*/
|
|
26
37
|
export function LegalDocument({
|
|
27
38
|
doc,
|
|
28
39
|
fallbackTitle,
|
|
@@ -53,9 +64,7 @@ export function LegalDocument({
|
|
|
53
64
|
</p>
|
|
54
65
|
)}
|
|
55
66
|
</header>
|
|
56
|
-
<
|
|
57
|
-
<ReactMarkdown components={HEADINGS}>{doc.content}</ReactMarkdown>
|
|
58
|
-
</div>
|
|
67
|
+
<LegalContent content={doc.content} />
|
|
59
68
|
</article>
|
|
60
69
|
)
|
|
61
70
|
}
|
|
@@ -13,6 +13,7 @@ import LocalizedClientLink from "../../molecules/LocalizedLink/LocalizedLink"
|
|
|
13
13
|
import { listCategories } from "../../../lib/data/categories"
|
|
14
14
|
import { listAllCollectionsForBrowse } from "../../../lib/data/collections"
|
|
15
15
|
import { listRegions } from "../../../lib/data/regions"
|
|
16
|
+
import { getVendorSignupUrl } from "../../../lib/data/vendor-signup"
|
|
16
17
|
import { listBrowseApplications } from "../../../lib/data/browse-navigation"
|
|
17
18
|
import { listAllSellersForNav } from "../../../lib/data/seller"
|
|
18
19
|
import { isCategoriesCollectionsBrowseMode } from "../../../lib/storefront/browse-nav-flags"
|
|
@@ -32,7 +33,7 @@ export const Header = async ({ locale, logo, actions, siteName = "Home", hideVen
|
|
|
32
33
|
/** Optional brand call-to-action for the desktop row, placed after Auctions. */
|
|
33
34
|
actions?: ReactNode
|
|
34
35
|
}) => {
|
|
35
|
-
const regions = await listRegions()
|
|
36
|
+
const [regions, vendorSignupUrl] = await Promise.all([listRegions(), getVendorSignupUrl()])
|
|
36
37
|
const categoriesCollectionsMode = isCategoriesCollectionsBrowseMode()
|
|
37
38
|
|
|
38
39
|
// listCategories rejects when the calling publishable key isn't linked to
|
|
@@ -150,7 +151,7 @@ export const Header = async ({ locale, logo, actions, siteName = "Home", hideVen
|
|
|
150
151
|
<Suspense fallback={<div className="w-16 h-10" aria-hidden />}>
|
|
151
152
|
<CountrySelector regions={regions} />
|
|
152
153
|
</Suspense>
|
|
153
|
-
<HeaderAccountControls locale={locale} />
|
|
154
|
+
<HeaderAccountControls locale={locale} vendorSignupUrl={vendorSignupUrl} />
|
|
154
155
|
<CartDropdown />
|
|
155
156
|
</div>
|
|
156
157
|
</div>
|
|
@@ -164,6 +165,7 @@ export const Header = async ({ locale, logo, actions, siteName = "Home", hideVen
|
|
|
164
165
|
parentCategories={parentCategories}
|
|
165
166
|
categories={categories}
|
|
166
167
|
isLoggedIn={false}
|
|
168
|
+
vendorSignupUrl={vendorSignupUrl}
|
|
167
169
|
/>
|
|
168
170
|
</div>
|
|
169
171
|
|
|
@@ -180,7 +182,7 @@ export const Header = async ({ locale, logo, actions, siteName = "Home", hideVen
|
|
|
180
182
|
className="ml-auto flex items-center gap-3.5"
|
|
181
183
|
data-testid="header-actions-mobile"
|
|
182
184
|
>
|
|
183
|
-
<HeaderAccountControls locale={locale} />
|
|
185
|
+
<HeaderAccountControls locale={locale} vendorSignupUrl={vendorSignupUrl} />
|
|
184
186
|
<CartDropdown />
|
|
185
187
|
</div>
|
|
186
188
|
</div>
|
|
@@ -12,7 +12,7 @@ const TALKJS_APP_ID = process.env.NEXT_PUBLIC_TALKJS_APP_ID || ""
|
|
|
12
12
|
|
|
13
13
|
const HeaderMessages = dynamic(() => import("./HeaderMessages"), { ssr: false })
|
|
14
14
|
|
|
15
|
-
export const HeaderAccountControls = ({ locale }: { locale: string }) => {
|
|
15
|
+
export const HeaderAccountControls = ({ locale, vendorSignupUrl }: { locale: string; vendorSignupUrl?: string }) => {
|
|
16
16
|
const session = useCustomerSession(locale)
|
|
17
17
|
// Match ProductCard: undefined = still loading, distinct from logged-out.
|
|
18
18
|
const isSessionLoading = session === undefined
|
|
@@ -40,7 +40,7 @@ export const HeaderAccountControls = ({ locale }: { locale: string }) => {
|
|
|
40
40
|
)}
|
|
41
41
|
</LocalizedClientLink>
|
|
42
42
|
)}
|
|
43
|
-
{!isSessionLoading && <UserDropdown isLoggedIn={isLoggedIn} />}
|
|
43
|
+
{!isSessionLoading && <UserDropdown isLoggedIn={isLoggedIn} vendorSignupUrl={vendorSignupUrl} />}
|
|
44
44
|
</>
|
|
45
45
|
)
|
|
46
46
|
|
package/src/lib/data/brand.ts
CHANGED
|
@@ -61,7 +61,7 @@ const readPageSpec = (raw: unknown) => {
|
|
|
61
61
|
}
|
|
62
62
|
|
|
63
63
|
// `cache` is a server-render API; plain React (unit tests) has none, and a single call needs no dedupe.
|
|
64
|
-
const perRequest: <T>(fn: () => Promise<T>) => () => Promise<T> = React.cache ?? ((fn) => fn)
|
|
64
|
+
export const perRequest: <T>(fn: () => Promise<T>) => () => Promise<T> = React.cache ?? ((fn) => fn)
|
|
65
65
|
|
|
66
66
|
// The backend already refuses anything else; this keeps a bad link inert if that ever changes.
|
|
67
67
|
const isSafeLink = (url: string) => /^https:\/\/\S+$/.test(url) || /^\/(?![/\\])\S*$/.test(url)
|
|
@@ -73,10 +73,10 @@ let failures = 0
|
|
|
73
73
|
export const brandFetchFailures = () => failures
|
|
74
74
|
|
|
75
75
|
// ponytail: races the call, the SDK method takes no AbortSignal so the socket lives on until the platform's own timeout; thread a signal through the generated SDK if that matters.
|
|
76
|
-
const withTimeout = <T>(work: Promise<T
|
|
76
|
+
export const withTimeout = <T>(work: Promise<T>, label = "brand fetch") => {
|
|
77
77
|
let timer: ReturnType<typeof setTimeout>
|
|
78
78
|
const timeout = new Promise<never>((_, reject) => {
|
|
79
|
-
timer = setTimeout(() => reject(new Error(
|
|
79
|
+
timer = setTimeout(() => reject(new Error(`${label} timed out`)), BRAND_TIMEOUT_MS)
|
|
80
80
|
})
|
|
81
81
|
return Promise.race([work, timeout]).finally(() => clearTimeout(timer))
|
|
82
82
|
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { getOpticommSdk } from "../config"
|
|
2
|
+
import { getTenantOrigin } from "../helpers/request-base-url"
|
|
3
|
+
import { isVendorDeployment, perRequest, withTimeout } from "./brand"
|
|
4
|
+
|
|
5
|
+
/** The vendor sign-up code format (see REFERRAL_CODE_RE in the backend); anything else never reaches a URL. */
|
|
6
|
+
const REFERRAL_CODE_RE = /^[A-HJ-NP-Z2-9]{10}$/
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Where a "Become a vendor" link goes: the vendor panel's sign-up page, carrying the live referral code of the
|
|
10
|
+
* seller whose storefront this is, so a vendor who signs up from a seller's site is that seller's referral. The
|
|
11
|
+
* platform storefront (neither a vendor deployment nor a tenant host) gets the plain page with no backend call. A
|
|
12
|
+
* missing, malformed, failed or slow (> 2 s) read gives the plain page too. The code rotates, so it is read on every
|
|
13
|
+
* request and never cached beyond it.
|
|
14
|
+
*/
|
|
15
|
+
export const getVendorSignupUrl = perRequest(async (): Promise<string> => {
|
|
16
|
+
const base = `${process.env.NEXT_PUBLIC_VENDOR_URL}/register`
|
|
17
|
+
if (!isVendorDeployment() && (await getTenantOrigin()) === null) {
|
|
18
|
+
return base
|
|
19
|
+
}
|
|
20
|
+
try {
|
|
21
|
+
const { referral_code } = await withTimeout((await getOpticommSdk()).store.opticomm.retrieveReferralCode(), "vendor referral code fetch")
|
|
22
|
+
return referral_code && REFERRAL_CODE_RE.test(referral_code) ? `${base}?ref=${referral_code}` : base
|
|
23
|
+
} catch (error) {
|
|
24
|
+
// Next's control-flow signals (static bailouts) must propagate, not be read as a failed fetch.
|
|
25
|
+
if ((error as { digest?: string } | null)?.digest) {
|
|
26
|
+
throw error
|
|
27
|
+
}
|
|
28
|
+
console.error("vendor referral code read failed, serving the plain sign-up link", error instanceof Error ? error.message : "unknown")
|
|
29
|
+
return base
|
|
30
|
+
}
|
|
31
|
+
})
|
|
@@ -2,6 +2,7 @@ import { Metadata } from "next"
|
|
|
2
2
|
|
|
3
3
|
import { getStoreLegal } from "../../../lib/data/legal"
|
|
4
4
|
import LocalizedClientLink from "../../../components/molecules/LocalizedLink/LocalizedLink"
|
|
5
|
+
import { LegalContent } from "../../../components/molecules/LegalDocument/LegalDocument"
|
|
5
6
|
import { getRequestBaseUrl } from "../../../lib/helpers/request-base-url"
|
|
6
7
|
import { generateBreadcrumbJsonLd, toSafeJsonLdString } from "../../../lib/helpers/seo"
|
|
7
8
|
import { docForSlug, LEGAL_SLUG_LABELS, LEGAL_SLUGS } from "./legal-docs"
|
|
@@ -52,6 +53,12 @@ export default async function LegalPage({ params }: { params: Promise<{ locale:
|
|
|
52
53
|
<h2 className="heading-md mb-2">{doc.title?.trim() || LEGAL_SLUG_LABELS[slug]}</h2>
|
|
53
54
|
<p className="text-neutral-600 text-sm">Version {doc.content_hash.slice(0, 12)}</p>
|
|
54
55
|
</LocalizedClientLink>
|
|
56
|
+
<details className="mt-2 px-4 md:px-6" data-testid="legal-inline">
|
|
57
|
+
<summary className="cursor-pointer py-2 text-sm font-medium text-neutral-700">
|
|
58
|
+
Read the full text
|
|
59
|
+
</summary>
|
|
60
|
+
<LegalContent content={doc.content} />
|
|
61
|
+
</details>
|
|
55
62
|
</li>
|
|
56
63
|
))}
|
|
57
64
|
</ul>
|