@sgflabs/storefront-core 0.1.4 → 0.1.6
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 +21 -0
- package/package.json +7 -7
- package/src/components/atoms/Breadcrumbs/Breadcrumbs.tsx +22 -11
- package/src/components/atoms/Input/Input.tsx +2 -0
- package/src/components/cells/ActiveFilterElement/ActiveFilterElement.tsx +2 -0
- package/src/components/cells/ProductBuyBox/ProductBuyBox.tsx +11 -1
- package/src/components/cells/ProductDetailsHeader/ProductDetailsHeader.tsx +48 -13
- package/src/components/cells/ProductPageDetails/ProductPageDetails.tsx +2 -1
- package/src/components/cells/WishlistButton/WishlistButton.tsx +2 -0
- package/src/components/molecules/LoginForm/LoginForm.tsx +4 -1
- package/src/components/molecules/RegisterForm/RegisterForm.tsx +13 -1
- package/src/components/organisms/BlogCard/BlogCard.tsx +18 -0
- package/src/components/organisms/Header/HeaderAccountControls.tsx +1 -0
- package/src/components/organisms/HomeProductsCarousel/HomeProductsCarousel.tsx +2 -13
- package/src/components/organisms/ListingFilterSidebar/ListingFilterSidebar.tsx +12 -2
- package/src/components/organisms/ProductQuickViewModal/ProductQuickViewModal.tsx +6 -1
- package/src/components/providers/BrandSlots/BrandSlotsProvider.tsx +14 -0
- package/src/components/sections/BlogSection/BlogSection.tsx +30 -2
- package/src/components/sections/HomeProductSection/HomeProductSection.tsx +24 -1
- package/src/data/footerLinks.ts +6 -0
- package/src/lib/data/bidding.ts +19 -10
- package/src/lib/helpers/format-specification-cell.ts +23 -0
- package/src/lib/helpers/sso-hub.ts +48 -5
- package/src/pages/api/auth/handoff/route.ts +6 -3
- package/src/pages/api/google-callback/route.ts +13 -1
- package/src/pages/api/google-start/route.ts +10 -7
- package/src/pages/main/auctions/[id]/page.tsx +5 -1
- package/src/pages/main/user/orders/[id]/page.tsx +11 -2
package/README.md
CHANGED
|
@@ -60,3 +60,24 @@ apex's single registered callback (state cookie and nonce helpers in `src/lib/he
|
|
|
60
60
|
`src/lib/data/finish-google-login.ts`). The flow, abuse cases and required env (`SSO_HUB_SECRET`) are in
|
|
61
61
|
[`apps/opticomm-storefront/README.md`](../../apps/opticomm-storefront/README.md). Only the opticomm storefront re-exports
|
|
62
62
|
`google-start` and `auth/handoff`; the other storefronts keep their own `google-callback` and are unchanged.
|
|
63
|
+
|
|
64
|
+
### Registered return origins and hub-client apps
|
|
65
|
+
|
|
66
|
+
A separate first-party storefront on its own host (not a subdomain of the apex) can log in with Google through the same
|
|
67
|
+
single callback, with no Google Console change.
|
|
68
|
+
|
|
69
|
+
- On the apex set `SSO_HUB_RETURN_ORIGINS=<comma separated exact origins>`, for example `https://polymers.example.org`.
|
|
70
|
+
Each entry must be a bare origin (no path, query, userinfo, wildcard, trailing dot or uppercase), https unless the apex
|
|
71
|
+
itself is http, and not the apex. Invalid entries are dropped. Registered hosts receive customer JWTs that are valid
|
|
72
|
+
across the backend, so only first-party hosts belong on the list.
|
|
73
|
+
- The backend `vendor_domains` feature must be on: handoff mint and redeem return 404 without it, so the login fails
|
|
74
|
+
after Google.
|
|
75
|
+
- Registered hosts must not log query strings on `/api/auth/handoff`: the one-time code is in the URL for up to 60 seconds.
|
|
76
|
+
- On the consuming app set `NEXT_PUBLIC_SSO_HUB_ORIGIN=<apex origin>` (build time and runtime). Do NOT set
|
|
77
|
+
`SSO_HUB_SECRET` or `SSO_HUB_RETURN_ORIGINS` there. The app's `google-callback` refuses to exchange a code when this
|
|
78
|
+
variable is set.
|
|
79
|
+
- Re-export `auth/handoff` only: never `google-start`, and delete any `google-callback` re-export.
|
|
80
|
+
- Mount `<TenantHostProvider isTenantHost={false} googleSsoOrigin={ssoHubOrigin()}>`.
|
|
81
|
+
- `NEXT_PUBLIC_BASE_URL` must be the exact public https origin of the app, and its proxy must send
|
|
82
|
+
`x-forwarded-proto: https`. In this mode the handoff redeems for that configured host, never the `Host` header, so it works only for the
|
|
83
|
+
exact host of `NEXT_PUBLIC_BASE_URL`: an alternate hostname that is also listed in `SSO_HUB_RETURN_ORIGINS` will not work.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sgflabs/storefront-core",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.6",
|
|
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": [
|
|
@@ -55,9 +55,9 @@
|
|
|
55
55
|
"devDependencies": {
|
|
56
56
|
"@sentry/nextjs": "^10.63.0",
|
|
57
57
|
"@sgflabs/artha-go-sdk": "^0.2.0",
|
|
58
|
-
"@sgflabs/gstin": "^0.1.
|
|
59
|
-
"@sgflabs/page-spec": "^0.1.
|
|
60
|
-
"@sgflabs/storefront-core-common": "^0.1.
|
|
58
|
+
"@sgflabs/gstin": "^0.1.6",
|
|
59
|
+
"@sgflabs/page-spec": "^0.1.6",
|
|
60
|
+
"@sgflabs/storefront-core-common": "^0.1.6",
|
|
61
61
|
"@testing-library/dom": "^10.4.1",
|
|
62
62
|
"@testing-library/jest-dom": "^7.0.0",
|
|
63
63
|
"@testing-library/react": "^16.3.2",
|
|
@@ -73,9 +73,9 @@
|
|
|
73
73
|
"peerDependencies": {
|
|
74
74
|
"@sentry/nextjs": "^10.63.0",
|
|
75
75
|
"@sgflabs/artha-go-sdk": "^0.2.0",
|
|
76
|
-
"@sgflabs/gstin": "^0.1.
|
|
77
|
-
"@sgflabs/page-spec": "^0.1.
|
|
78
|
-
"@sgflabs/storefront-core-common": "^0.1.
|
|
76
|
+
"@sgflabs/gstin": "^0.1.6",
|
|
77
|
+
"@sgflabs/page-spec": "^0.1.6",
|
|
78
|
+
"@sgflabs/storefront-core-common": "^0.1.6",
|
|
79
79
|
"next": "15.5.27",
|
|
80
80
|
"react": "^19.2.3",
|
|
81
81
|
"react-dom": "^19.2.3"
|
|
@@ -22,17 +22,28 @@ export function Breadcrumbs({ items, className, "data-testid": dataTestId }: Bre
|
|
|
22
22
|
return (
|
|
23
23
|
<li key={path} className="inline-flex items-center" data-testid={`breadcrumb-item-${index}`}>
|
|
24
24
|
{index > 0 && <ForwardIcon size={16} />}
|
|
25
|
-
|
|
26
|
-
href
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
index > 0 && "ml-2"
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
25
|
+
{path === "" ? (
|
|
26
|
+
// Current page: no destination, so no link (an empty href resolved to the homepage).
|
|
27
|
+
<span
|
|
28
|
+
aria-current="page"
|
|
29
|
+
className={cn("inline-flex items-center label-md text-secondary", index > 0 && "ml-2")}
|
|
30
|
+
data-testid={dataTestId ? `${dataTestId}-link-${index}` : `breadcrumbs-link-${index}`}
|
|
31
|
+
>
|
|
32
|
+
{label}
|
|
33
|
+
</span>
|
|
34
|
+
) : (
|
|
35
|
+
<LocalizedClientLink
|
|
36
|
+
href={path}
|
|
37
|
+
className={cn(
|
|
38
|
+
"inline-flex items-center label-md text-primary",
|
|
39
|
+
index > 0 && "ml-2",
|
|
40
|
+
isActive && "text-secondary"
|
|
41
|
+
)}
|
|
42
|
+
data-testid={dataTestId ? `${dataTestId}-link-${index}` : `breadcrumbs-link-${index}`}
|
|
43
|
+
>
|
|
44
|
+
{label}
|
|
45
|
+
</LocalizedClientLink>
|
|
46
|
+
)}
|
|
36
47
|
</li>
|
|
37
48
|
)
|
|
38
49
|
})}
|
|
@@ -100,6 +100,8 @@ export function Input({
|
|
|
100
100
|
<button
|
|
101
101
|
type="button"
|
|
102
102
|
onClick={() => setShowPassword(!showPassword)}
|
|
103
|
+
aria-label={showPassword ? "Hide password" : "Show password"}
|
|
104
|
+
aria-pressed={showPassword}
|
|
103
105
|
className="text-ui-fg-subtle px-4 focus:outline-none transition-all duration-150 outline-none focus:text-ui-fg-base absolute right-0 top-4"
|
|
104
106
|
data-testid={dataTestId ? `${dataTestId}-password-button` : 'input-password-button'}
|
|
105
107
|
>
|
|
@@ -13,9 +13,11 @@ import {
|
|
|
13
13
|
selectOfferBySellerHandle,
|
|
14
14
|
toEffectiveProduct,
|
|
15
15
|
} from "../../../lib/helpers/product-offers"
|
|
16
|
+
import { getProductPrice } from "../../../lib/helpers/get-product-price"
|
|
16
17
|
import { resolveSelectedVariantId } from "../../../lib/helpers/resolve-selected-variant-id"
|
|
17
18
|
import { ProductDetailsHeader } from "../ProductDetailsHeader/ProductDetailsHeader"
|
|
18
19
|
import { VolumePricingTable } from "../VolumePricingTable/VolumePricingTable"
|
|
20
|
+
import { useUnpricedLabel } from "../../providers/BrandSlots/BrandSlotsProvider"
|
|
19
21
|
import { VendorSelector } from "../../molecules/VendorSelector/VendorSelector"
|
|
20
22
|
import type { MoqRule } from "../../../lib/data/moq-rules"
|
|
21
23
|
import type { QuoteThreshold } from "../../../lib/data/quote-thresholds"
|
|
@@ -88,8 +90,15 @@ export function ProductBuyBox({
|
|
|
88
90
|
const selectedOfferVariant =
|
|
89
91
|
activeOffer?.variants.find((variant) => variant.id === selectedEffectiveVariantId) ?? null
|
|
90
92
|
|
|
93
|
+
// A brand that opts in (BrandSlots `unpricedLabel`) words an unpriced product
|
|
94
|
+
// as e.g. "Price on request" instead of a regional restriction.
|
|
95
|
+
const unpricedLabel = useUnpricedLabel()
|
|
96
|
+
const isUnpriced = getProductPrice({ product: effectiveProduct }).cheapestPrice === null
|
|
97
|
+
|
|
91
98
|
const addToCartDisabledReason = noValidOffer
|
|
92
|
-
?
|
|
99
|
+
? isUnpriced
|
|
100
|
+
? (unpricedLabel ?? NOT_AVAILABLE_REASON)
|
|
101
|
+
: NOT_AVAILABLE_REASON
|
|
93
102
|
: missingPackSize
|
|
94
103
|
? NOT_OFFERED_REASON
|
|
95
104
|
: null
|
|
@@ -112,6 +121,7 @@ export function ProductBuyBox({
|
|
|
112
121
|
onUnitsQuantityChange={handleUnitsQuantityChange}
|
|
113
122
|
addToCartDisabledReason={addToCartDisabledReason}
|
|
114
123
|
authContinueInPlace={authContinueInPlace}
|
|
124
|
+
pageHandle={product.handle}
|
|
115
125
|
/>
|
|
116
126
|
<VolumePricingTable
|
|
117
127
|
tiers={selectedOfferVariant?.tiers ?? []}
|
|
@@ -17,6 +17,7 @@ import { WishlistButton } from "../WishlistButton/WishlistButton"
|
|
|
17
17
|
import { toast } from "../../../lib/helpers/toast"
|
|
18
18
|
import { track } from "../../../lib/vendor-analytics/track"
|
|
19
19
|
import { useCartContext } from "../../providers"
|
|
20
|
+
import { useSampleIdleLabel, useUnpricedLabel } from "../../providers/BrandSlots/BrandSlotsProvider"
|
|
20
21
|
import { useEffect, useMemo, useState, type ReactElement } from "react"
|
|
21
22
|
import type { MoqRule } from "../../../lib/data/moq-rules"
|
|
22
23
|
import type { QuoteThreshold } from "../../../lib/data/quote-thresholds"
|
|
@@ -78,6 +79,7 @@ export const ProductDetailsHeader = ({
|
|
|
78
79
|
onUnitsQuantityChange,
|
|
79
80
|
addToCartDisabledReason = null,
|
|
80
81
|
authContinueInPlace = false,
|
|
82
|
+
pageHandle,
|
|
81
83
|
}: {
|
|
82
84
|
product: HttpTypes.StoreProduct & { seller?: SellerProps }
|
|
83
85
|
locale: string
|
|
@@ -91,8 +93,12 @@ export const ProductDetailsHeader = ({
|
|
|
91
93
|
addToCartDisabledReason?: string | null
|
|
92
94
|
/** Quick View: embed login in the sample prompt so the modal stays open after password/OTP. */
|
|
93
95
|
authContinueInPlace?: boolean
|
|
96
|
+
/** Handle of the page's own product, for the share link. Defaults to `product.handle`; a multi-seller page passes its own because `product` is then the active offer's. */
|
|
97
|
+
pageHandle?: string
|
|
94
98
|
}) => {
|
|
95
99
|
const { addToCart, onAddToCart, cart, isAddingItem } = useCartContext()
|
|
100
|
+
const sampleIdleLabel = useSampleIdleLabel() ?? "Add sample"
|
|
101
|
+
const unpricedLabel = useUnpricedLabel()
|
|
96
102
|
const pathname = usePathname()
|
|
97
103
|
const searchParams = useSearchParams()
|
|
98
104
|
// A per_lb product reads in lb unless the shopper has explicitly chosen a
|
|
@@ -116,12 +122,28 @@ export const ProductDetailsHeader = ({
|
|
|
116
122
|
const [copied, setCopied] = useState(false)
|
|
117
123
|
const [pageUrl, setPageUrl] = useState("")
|
|
118
124
|
|
|
125
|
+
// The product's own URL, not window.location: inside Quick View that is the
|
|
126
|
+
// listing the modal is open on (`/categories?preview=...`).
|
|
127
|
+
const handle = pageHandle ?? product.handle
|
|
128
|
+
// Keep the selection (?seller=, option params) so the link opens the same
|
|
129
|
+
// view; in Quick View (`preview`) only ?seller= is kept.
|
|
130
|
+
const shareQuery = useMemo(() => {
|
|
131
|
+
const query = new URLSearchParams(searchParams?.toString() ?? "")
|
|
132
|
+
// Quick View sits on a listing: its filters and pagination are not the product's selection.
|
|
133
|
+
if (query.has("preview")) {
|
|
134
|
+
const seller = query.get("seller")
|
|
135
|
+
return seller ? new URLSearchParams({ seller }).toString() : ""
|
|
136
|
+
}
|
|
137
|
+
return query.toString()
|
|
138
|
+
}, [searchParams])
|
|
119
139
|
useEffect(() => {
|
|
120
|
-
setPageUrl(
|
|
121
|
-
|
|
140
|
+
setPageUrl(
|
|
141
|
+
`${window.location.origin}/${locale}/products/${handle}${shareQuery ? `?${shareQuery}` : ""}`
|
|
142
|
+
)
|
|
143
|
+
}, [locale, handle, shareQuery])
|
|
122
144
|
|
|
123
145
|
const handleCopyLink = () => {
|
|
124
|
-
navigator.clipboard.writeText(
|
|
146
|
+
navigator.clipboard.writeText(pageUrl).then(() => {
|
|
125
147
|
setCopied(true)
|
|
126
148
|
setTimeout(() => setCopied(false), 2000)
|
|
127
149
|
})
|
|
@@ -139,8 +161,9 @@ export const ProductDetailsHeader = ({
|
|
|
139
161
|
)
|
|
140
162
|
}, [moqRules, selectedVariantRow?.id])
|
|
141
163
|
const variantThreshold = useMemo(
|
|
142
|
-
|
|
143
|
-
|
|
164
|
+
// A Sample pack is never quoted, so it carries no quote minimum.
|
|
165
|
+
() => (isSelectedSampleVariant ? null : quoteThresholds?.find((t) => t.variant_id === selectedVariantRow?.id) ?? null),
|
|
166
|
+
[quoteThresholds, selectedVariantRow?.id, isSelectedSampleVariant]
|
|
144
167
|
)
|
|
145
168
|
const variantMoqRequirement = useMemo(
|
|
146
169
|
() => moqRequirements?.find((r) => r.variant_id === selectedVariantRow?.id) ?? null,
|
|
@@ -611,7 +634,7 @@ export const ProductDetailsHeader = ({
|
|
|
611
634
|
</div>
|
|
612
635
|
) : (
|
|
613
636
|
<span className="text-sm text-secondary" data-testid="product-price-unavailable">
|
|
614
|
-
Not available in your region
|
|
637
|
+
{unpricedLabel ?? "Not available in your region"}
|
|
615
638
|
</span>
|
|
616
639
|
)}
|
|
617
640
|
</div>
|
|
@@ -663,7 +686,13 @@ export const ProductDetailsHeader = ({
|
|
|
663
686
|
)}
|
|
664
687
|
data-testid="product-add-to-cart-button"
|
|
665
688
|
>
|
|
666
|
-
{!hasAnyPrice
|
|
689
|
+
{!hasAnyPrice
|
|
690
|
+
? (unpricedLabel ?? "NOT AVAILABLE IN YOUR REGION")
|
|
691
|
+
: isPriceOnRequest
|
|
692
|
+
? "Price on Request"
|
|
693
|
+
: variantHasPrice
|
|
694
|
+
? "Add to Cart"
|
|
695
|
+
: "NOT AVAILABLE"}
|
|
667
696
|
</Button>
|
|
668
697
|
)}
|
|
669
698
|
{hasAnyPrice && variantHasPrice && !quoteEligibility.hidden && (
|
|
@@ -707,7 +736,7 @@ export const ProductDetailsHeader = ({
|
|
|
707
736
|
"w-full py-2.5 rounded-lg bg-neutral-900 text-white hover:bg-neutral-800 transition-colors text-sm font-bold uppercase tracking-wide disabled:opacity-50 disabled:cursor-not-allowed flex justify-center items-center gap-2",
|
|
708
737
|
promptClassName:
|
|
709
738
|
"w-full py-2.5 rounded-lg bg-neutral-900 text-white hover:bg-neutral-800 transition-colors text-sm font-bold uppercase tracking-wide flex justify-center items-center gap-2",
|
|
710
|
-
idleLabel:
|
|
739
|
+
idleLabel: sampleIdleLabel,
|
|
711
740
|
inCartPrefix: "In cart",
|
|
712
741
|
})}
|
|
713
742
|
|
|
@@ -744,7 +773,7 @@ export const ProductDetailsHeader = ({
|
|
|
744
773
|
)}
|
|
745
774
|
</>
|
|
746
775
|
) : (
|
|
747
|
-
<span className="text-sm text-neutral-500">Not available in your region</span>
|
|
776
|
+
<span className="text-sm text-neutral-500">{unpricedLabel ?? "Not available in your region"}</span>
|
|
748
777
|
)}
|
|
749
778
|
{addToCartDisabledReason && (
|
|
750
779
|
<span className="mt-0.5 text-[11px] text-neutral-500">{addToCartDisabledReason}</span>
|
|
@@ -761,7 +790,13 @@ export const ProductDetailsHeader = ({
|
|
|
761
790
|
)}
|
|
762
791
|
data-testid="product-mobile-add-to-cart-button"
|
|
763
792
|
>
|
|
764
|
-
{!hasAnyPrice
|
|
793
|
+
{!hasAnyPrice
|
|
794
|
+
? (unpricedLabel ?? "Unavailable")
|
|
795
|
+
: isPriceOnRequest
|
|
796
|
+
? "Price on Request"
|
|
797
|
+
: variantHasPrice
|
|
798
|
+
? "Add to Cart"
|
|
799
|
+
: "Unavailable"}
|
|
765
800
|
</Button>
|
|
766
801
|
)}
|
|
767
802
|
</div>
|
|
@@ -850,7 +885,7 @@ export const ProductDetailsHeader = ({
|
|
|
850
885
|
</div>
|
|
851
886
|
) : (
|
|
852
887
|
<span className="text-sm text-secondary" data-testid="product-price-unavailable">
|
|
853
|
-
Not available in your region
|
|
888
|
+
{unpricedLabel ?? "Not available in your region"}
|
|
854
889
|
</span>
|
|
855
890
|
)}
|
|
856
891
|
</div>
|
|
@@ -889,7 +924,7 @@ export const ProductDetailsHeader = ({
|
|
|
889
924
|
data-testid="product-add-to-cart-button"
|
|
890
925
|
>
|
|
891
926
|
{!hasAnyPrice
|
|
892
|
-
? "NOT AVAILABLE IN YOUR REGION"
|
|
927
|
+
? (unpricedLabel ?? "NOT AVAILABLE IN YOUR REGION")
|
|
893
928
|
: isPriceOnRequest
|
|
894
929
|
? "Price on Request"
|
|
895
930
|
: variantHasPrice
|
|
@@ -934,7 +969,7 @@ export const ProductDetailsHeader = ({
|
|
|
934
969
|
"w-full mt-1.5 py-2 rounded-lg border border-neutral-800 bg-neutral-900 text-white hover:bg-neutral-800 transition-colors text-sm font-semibold uppercase tracking-wide disabled:opacity-50 disabled:cursor-not-allowed flex justify-center",
|
|
935
970
|
promptClassName:
|
|
936
971
|
"w-full mt-1.5 py-2 rounded-lg border border-neutral-800 bg-neutral-900 text-white hover:bg-neutral-800 transition-colors text-sm font-semibold uppercase tracking-wide flex justify-center",
|
|
937
|
-
idleLabel:
|
|
972
|
+
idleLabel: sampleIdleLabel,
|
|
938
973
|
inCartPrefix: "Sample in cart",
|
|
939
974
|
})}
|
|
940
975
|
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { ProductPageAccordion } from "../../molecules"
|
|
2
|
+
import { formatSpecificationCell } from "../../../lib/helpers/format-specification-cell"
|
|
2
3
|
import { productDescriptionToMarkdown } from "../../../lib/helpers/product-description-markdown"
|
|
3
4
|
import { Children, isValidElement } from "react"
|
|
4
5
|
import type { ComponentPropsWithoutRef, ReactNode } from "react"
|
|
@@ -63,7 +64,7 @@ function TechnicalSpecificationCell({
|
|
|
63
64
|
node: _node,
|
|
64
65
|
...props
|
|
65
66
|
}: ComponentPropsWithoutRef<"td"> & ExtraProps) {
|
|
66
|
-
return <td {...props}>{getTextContent(children)}</td>
|
|
67
|
+
return <td {...props}>{formatSpecificationCell(getTextContent(children))}</td>
|
|
67
68
|
}
|
|
68
69
|
|
|
69
70
|
function getTextContent(children: ReactNode): string {
|
|
@@ -70,6 +70,8 @@ export const WishlistButton = ({
|
|
|
70
70
|
<Button
|
|
71
71
|
onClick={isWishlisted ? () => handleRemoveFromWishlist() : () => handleAddToWishlist()}
|
|
72
72
|
variant="tonal"
|
|
73
|
+
aria-label={isWishlisted ? "Remove from wishlist" : "Add to wishlist"}
|
|
74
|
+
aria-pressed={isWishlisted}
|
|
73
75
|
className="flex h-10 w-10 items-center justify-center p-0"
|
|
74
76
|
loading={isWishlistAdding}
|
|
75
77
|
disabled={isWishlistAdding}
|
|
@@ -407,10 +407,12 @@ const Form = ({
|
|
|
407
407
|
</div>
|
|
408
408
|
|
|
409
409
|
{mode === 'password' ? (
|
|
410
|
-
<form onSubmit={handleSubmit(submit)} data-testid="login-form">
|
|
410
|
+
<form onSubmit={handleSubmit(submit)} noValidate data-testid="login-form">
|
|
411
411
|
<div className="space-y-4">
|
|
412
412
|
<LabeledInput
|
|
413
413
|
label="E-mail"
|
|
414
|
+
type="email"
|
|
415
|
+
autoComplete="email"
|
|
414
416
|
placeholder="Your e-mail address"
|
|
415
417
|
error={
|
|
416
418
|
(errors.email as FieldError) ||
|
|
@@ -425,6 +427,7 @@ const Form = ({
|
|
|
425
427
|
label="Password"
|
|
426
428
|
placeholder="Your password"
|
|
427
429
|
type="password"
|
|
430
|
+
autoComplete="current-password"
|
|
428
431
|
error={
|
|
429
432
|
(errors.password as FieldError) ||
|
|
430
433
|
(isAuthError ? ({ message: '' } as FieldError) : undefined)
|
|
@@ -173,9 +173,21 @@ const Form = ({ isUnlinkedCompletion }: { isUnlinkedCompletion: boolean }) => {
|
|
|
173
173
|
</div>
|
|
174
174
|
)}
|
|
175
175
|
|
|
176
|
+
<p className="label-sm text-secondary mt-6" data-testid="register-consent-notice">
|
|
177
|
+
By creating an account you agree to our{" "}
|
|
178
|
+
<Link href={`/${locale}/legal/terms`} className="underline">
|
|
179
|
+
Terms & Conditions
|
|
180
|
+
</Link>{" "}
|
|
181
|
+
and acknowledge our{" "}
|
|
182
|
+
<Link href={`/${locale}/legal/privacy`} className="underline">
|
|
183
|
+
Privacy Policy
|
|
184
|
+
</Link>
|
|
185
|
+
, which explains what personal data we collect and why.
|
|
186
|
+
</p>
|
|
187
|
+
|
|
176
188
|
<Button
|
|
177
189
|
type="submit"
|
|
178
|
-
className="w-full flex justify-center mt-
|
|
190
|
+
className="w-full flex justify-center mt-4 uppercase"
|
|
179
191
|
disabled={isSubmitting}
|
|
180
192
|
loading={isSubmitting}
|
|
181
193
|
data-testid="register-submit-button"
|
|
@@ -10,6 +10,24 @@ interface BlogCardProps {
|
|
|
10
10
|
}
|
|
11
11
|
|
|
12
12
|
export function BlogCard({ post, index }: BlogCardProps) {
|
|
13
|
+
// A post with no link and no image (the specialty-chemical copy) is a plain
|
|
14
|
+
// card: there is nowhere to send the shopper and nothing to illustrate it.
|
|
15
|
+
if (!post.href || !post.image) {
|
|
16
|
+
return (
|
|
17
|
+
<article
|
|
18
|
+
className={cn(
|
|
19
|
+
"flex h-full flex-col rounded-lg border border-neutral-800 bg-neutral-900 p-5"
|
|
20
|
+
)}
|
|
21
|
+
>
|
|
22
|
+
<p className="mb-2 text-xs font-semibold uppercase tracking-wider text-neutral-300">
|
|
23
|
+
{post.category}
|
|
24
|
+
</p>
|
|
25
|
+
<h3 className="mb-2 text-lg font-semibold text-white">{post.title}</h3>
|
|
26
|
+
<p className="text-sm text-neutral-400">{post.excerpt}</p>
|
|
27
|
+
</article>
|
|
28
|
+
)
|
|
29
|
+
}
|
|
30
|
+
|
|
13
31
|
return (
|
|
14
32
|
<LocalizedClientLink
|
|
15
33
|
href={post.href}
|
|
@@ -4,22 +4,11 @@ import { ProductCard } from "../ProductCard/ProductCard"
|
|
|
4
4
|
import { listProducts, listProductsWithSort } from "../../../lib/data/products"
|
|
5
5
|
import { fetchQuoteThresholdsForProducts } from "../../../lib/helpers/fetch-quote-thresholds-for-products"
|
|
6
6
|
|
|
7
|
-
/**
|
|
8
|
-
* A 404 from a seller-scoped route, however the SDK surfaced it. Checked
|
|
9
|
-
* structurally rather than by message so a reworded backend error does not
|
|
10
|
-
* silently turn a degraded section back into a failed page.
|
|
11
|
-
*/
|
|
12
|
-
function isNotFound(error: unknown): boolean {
|
|
13
|
-
if (typeof error !== "object" || error === null) {
|
|
14
|
-
return false
|
|
15
|
-
}
|
|
16
|
-
const status = (error as { status?: unknown }).status
|
|
17
|
-
return status === 404
|
|
18
|
-
}
|
|
19
7
|
import {
|
|
20
8
|
HOME_FEATURED_PRODUCT_FIELDS,
|
|
21
9
|
PRODUCT_CARD_FIELDS,
|
|
22
10
|
} from "../../../lib/data/product-fields"
|
|
11
|
+
import { isNotFoundError } from "../../../lib/helpers/medusa-error"
|
|
23
12
|
import { SellerProps } from "../../../types/seller"
|
|
24
13
|
|
|
25
14
|
const CAROUSEL_SLIDE =
|
|
@@ -119,7 +108,7 @@ export const HomeProductsCarousel = async ({
|
|
|
119
108
|
// products"; anything else still throws, because hiding a real
|
|
120
109
|
// failure behind an empty carousel is the bug this PR removed
|
|
121
110
|
// everywhere else.
|
|
122
|
-
if (
|
|
111
|
+
if (isNotFoundError(error)) {
|
|
123
112
|
return { response: { products: [], count: 0 } }
|
|
124
113
|
}
|
|
125
114
|
throw error
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use client"
|
|
2
2
|
|
|
3
3
|
import { usePathname, useRouter, useSearchParams } from "next/navigation"
|
|
4
|
-
import { useState } from "react"
|
|
4
|
+
import { useEffect, useState } from "react"
|
|
5
5
|
|
|
6
6
|
import { CloseIcon } from "../../../icons"
|
|
7
7
|
import { cn } from "../../../lib/utils"
|
|
@@ -27,6 +27,15 @@ export const ListingFilterSidebar = ({
|
|
|
27
27
|
const pathname = usePathname()
|
|
28
28
|
const searchParams = useSearchParams()
|
|
29
29
|
|
|
30
|
+
useEffect(() => {
|
|
31
|
+
if (!filterModal) return
|
|
32
|
+
const onKeyDown = (event: KeyboardEvent) => {
|
|
33
|
+
if (event.key === "Escape") setFilterModal(false)
|
|
34
|
+
}
|
|
35
|
+
document.addEventListener("keydown", onKeyDown)
|
|
36
|
+
return () => document.removeEventListener("keydown", onKeyDown)
|
|
37
|
+
}, [filterModal])
|
|
38
|
+
|
|
30
39
|
const clearAll = () => {
|
|
31
40
|
const kept = new URLSearchParams()
|
|
32
41
|
for (const key of preserveParams) {
|
|
@@ -55,7 +64,8 @@ export const ListingFilterSidebar = ({
|
|
|
55
64
|
className={cn(
|
|
56
65
|
"w-full bg-primary md:rounded-md md:border md:border-primary md:overflow-hidden",
|
|
57
66
|
filterModal
|
|
58
|
-
?
|
|
67
|
+
? // z-50: must clear the sticky site header (z-40) or Close/Clear all are untappable.
|
|
68
|
+
"fixed inset-0 z-50 md:relative md:inset-auto md:z-10"
|
|
59
69
|
: "hidden md:block md:sticky md:top-[88px] md:z-10"
|
|
60
70
|
)}
|
|
61
71
|
data-testid="listing-sidebar-drawer"
|
|
@@ -214,7 +214,12 @@ function QuickViewContent({ locale }: { locale: string }) {
|
|
|
214
214
|
<div className="absolute inset-0 bg-black/50 backdrop-blur-sm" onClick={close} />
|
|
215
215
|
|
|
216
216
|
{/* Modal panel */}
|
|
217
|
-
<div
|
|
217
|
+
<div
|
|
218
|
+
role="dialog"
|
|
219
|
+
aria-modal="true"
|
|
220
|
+
aria-label="Quick view"
|
|
221
|
+
className="relative bg-white rounded-2xl shadow-2xl w-full max-w-4xl max-h-[90vh] overflow-hidden flex flex-col"
|
|
222
|
+
>
|
|
218
223
|
|
|
219
224
|
{/* Cart-added confirmation banner (sits above header bar) */}
|
|
220
225
|
{addedToCart && (
|
|
@@ -20,6 +20,10 @@ type BrandSlots = {
|
|
|
20
20
|
renderAddToPlaylist?: (track: StreamingTrack) => ReactNode
|
|
21
21
|
/** Name on the vendor hero's support-WhatsApp quote button ("WhatsApp <label> for a quote"). Defaults to "Artha". */
|
|
22
22
|
quoteWhatsappLabel?: string
|
|
23
|
+
/** Idle label of the product page's sample button ("Add sample" by default; e.g. "Order a sample"). */
|
|
24
|
+
sampleIdleLabel?: string
|
|
25
|
+
/** Copy for a product with no price in the region (e.g. "Price on request"). Unset keeps the regional "Not available in your region". */
|
|
26
|
+
unpricedLabel?: string
|
|
23
27
|
}
|
|
24
28
|
|
|
25
29
|
const BrandSlotsContext = createContext<BrandSlots>({})
|
|
@@ -44,3 +48,13 @@ export function useAddToPlaylistSlot() {
|
|
|
44
48
|
export function useQuoteWhatsappLabel() {
|
|
45
49
|
return useContext(BrandSlotsContext).quoteWhatsappLabel
|
|
46
50
|
}
|
|
51
|
+
|
|
52
|
+
/** The brand's idle label for the sample button, or undefined when the app registers none. */
|
|
53
|
+
export function useSampleIdleLabel() {
|
|
54
|
+
return useContext(BrandSlotsContext).sampleIdleLabel
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/** The brand's copy for an unpriced product, or undefined to keep the regional default. */
|
|
58
|
+
export function useUnpricedLabel() {
|
|
59
|
+
return useContext(BrandSlotsContext).unpricedLabel
|
|
60
|
+
}
|
|
@@ -34,7 +34,35 @@ export const blogPosts: BlogPost[] = [
|
|
|
34
34
|
},
|
|
35
35
|
]
|
|
36
36
|
|
|
37
|
-
|
|
37
|
+
/**
|
|
38
|
+
* Opt-in copy for the specialty-chemicals storefront (`<BlogSection posts=... />`).
|
|
39
|
+
* Unlinked and image-free, so the cards render as plain text.
|
|
40
|
+
*/
|
|
41
|
+
export const specialtyChemicalBlogPosts: BlogPost[] = [
|
|
42
|
+
{
|
|
43
|
+
id: 1,
|
|
44
|
+
title: "Verified Specialty Chemical Suppliers Across India",
|
|
45
|
+
excerpt:
|
|
46
|
+
"Connect with verified manufacturers and distributors of polymer additives, resins and specialty chemicals.",
|
|
47
|
+
category: "SUPPLIERS",
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
id: 2,
|
|
51
|
+
title: "Bulk Procurement Made Simple for Manufacturers",
|
|
52
|
+
excerpt:
|
|
53
|
+
"Source chemicals in bulk with transparent pricing, verified vendors and streamlined quote workflows.",
|
|
54
|
+
category: "PROCUREMENT",
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
id: 3,
|
|
58
|
+
title: "Quality-Controlled Chemicals With Technical Data",
|
|
59
|
+
excerpt:
|
|
60
|
+
"Ensure consistency and compliance with suppliers who publish technical data sheets and lab-tested grades.",
|
|
61
|
+
category: "QUALITY",
|
|
62
|
+
},
|
|
63
|
+
]
|
|
64
|
+
|
|
65
|
+
export default function BlogSection({ posts = blogPosts }: { posts?: BlogPost[] }) {
|
|
38
66
|
return (
|
|
39
67
|
<section className="w-full bg-black py-20">
|
|
40
68
|
<div className="content-container">
|
|
@@ -43,7 +71,7 @@ export default function BlogSection() {
|
|
|
43
71
|
</h2>
|
|
44
72
|
|
|
45
73
|
<div className="grid grid-cols-1 gap-6 md:grid-cols-3">
|
|
46
|
-
{
|
|
74
|
+
{posts.map((post, index) => (
|
|
47
75
|
<BlogCard key={post.id} post={post} index={index} />
|
|
48
76
|
))}
|
|
49
77
|
</div>
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { HttpTypes } from "@medusajs/types"
|
|
2
2
|
import { HomeProductsCarousel } from "../../organisms"
|
|
3
3
|
import LocalizedClientLink from "../../molecules/LocalizedLink/LocalizedLink"
|
|
4
|
-
import { listProducts } from "../../../lib/data/products"
|
|
4
|
+
import { listProducts, listProductsWithSort } from "../../../lib/data/products"
|
|
5
|
+
import { isNotFoundError } from "../../../lib/helpers/medusa-error"
|
|
5
6
|
import { HOME_FEATURED_PRODUCT_FIELDS, PRODUCT_CARD_FIELDS } from "../../../lib/data/product-fields"
|
|
6
7
|
import { SellerProps } from "../../../types/seller"
|
|
7
8
|
|
|
@@ -61,6 +62,28 @@ export const HomeProductSection = async ({
|
|
|
61
62
|
if (siblings.length === 0) return null
|
|
62
63
|
}
|
|
63
64
|
|
|
65
|
+
// Seller section: suppress the heading when the seller has no other product
|
|
66
|
+
// (this one is excluded), same orphan-heading guard as the type branch. Same
|
|
67
|
+
// fetch shape as the carousel so both dedupe in the Data Cache; a suspended
|
|
68
|
+
// seller (404) means "nothing to show", as in the carousel.
|
|
69
|
+
if (sellerHandle && !home && !typeId) {
|
|
70
|
+
const { response } = await listProductsWithSort({
|
|
71
|
+
countryCode: locale,
|
|
72
|
+
seller_handle: sellerHandle,
|
|
73
|
+
sortBy: "created_at",
|
|
74
|
+
queryParams: { limit: 20, fields: PRODUCT_CARD_FIELDS },
|
|
75
|
+
forceCache: true,
|
|
76
|
+
}).catch((error: unknown) => {
|
|
77
|
+
if (isNotFoundError(error)) return { response: { products: [], count: 0 } }
|
|
78
|
+
throw error
|
|
79
|
+
})
|
|
80
|
+
const excludeId = excludeProductId ? String(excludeProductId) : undefined
|
|
81
|
+
const others = excludeId
|
|
82
|
+
? response.products.filter((p) => String(p.id) !== excludeId)
|
|
83
|
+
: response.products
|
|
84
|
+
if (others.length === 0) return null
|
|
85
|
+
}
|
|
86
|
+
|
|
64
87
|
// Same probe for the paginated home sections (e.g. "Featured products" page
|
|
65
88
|
// 2): suppress the orphan heading when the carousel's fetch returns nothing.
|
|
66
89
|
// Identical arguments to the carousel's call, so the request is deduped.
|
package/src/data/footerLinks.ts
CHANGED
|
@@ -18,4 +18,10 @@ const links = {
|
|
|
18
18
|
],
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
+
/** Same links minus the "#" placeholders ("About us", "FAQs") that have no page yet. Opt-in. */
|
|
22
|
+
export const footerLinksWithoutPlaceholders = {
|
|
23
|
+
...links,
|
|
24
|
+
company: links.company.filter((link) => link.path !== "#"),
|
|
25
|
+
}
|
|
26
|
+
|
|
21
27
|
export default links
|
package/src/lib/data/bidding.ts
CHANGED
|
@@ -87,10 +87,19 @@ export const listAuctions = async ({
|
|
|
87
87
|
}
|
|
88
88
|
}
|
|
89
89
|
|
|
90
|
-
|
|
90
|
+
/**
|
|
91
|
+
* `throwOnError` is for a caller that must tell a missing auction (null, the
|
|
92
|
+
* backend answered 404) from a failed lookup (throws): the page uses it so a
|
|
93
|
+
* 5xx or a dropped connection reaches the error boundary instead of a 404.
|
|
94
|
+
*/
|
|
95
|
+
export const getAuction = async (
|
|
96
|
+
auctionId: string,
|
|
97
|
+
{ throwOnError = false }: { throwOnError?: boolean } = {}
|
|
98
|
+
): Promise<Auction | null> => {
|
|
99
|
+
let failedStatus: number | null = null
|
|
91
100
|
try {
|
|
92
101
|
const headers = await getAuthHeaders()
|
|
93
|
-
|
|
102
|
+
let response = await fetchQuery(`/store/auctions/${auctionId}`, {
|
|
94
103
|
method: "GET",
|
|
95
104
|
headers,
|
|
96
105
|
})
|
|
@@ -98,24 +107,24 @@ export const getAuction = async (auctionId: string): Promise<Auction | null> =>
|
|
|
98
107
|
// An expired or non-customer token triggers blockNonCustomerActors → 401.
|
|
99
108
|
// Retry without auth so guests (and stale sessions) still see the auction.
|
|
100
109
|
if (response.status === 401) {
|
|
101
|
-
|
|
110
|
+
response = await fetchQuery(`/store/auctions/${auctionId}`, {
|
|
102
111
|
method: "GET",
|
|
103
112
|
})
|
|
104
|
-
if (!guestResponse.ok || !guestResponse.data) return null
|
|
105
|
-
return mapSingleAuctionPayload(guestResponse.data)
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
if (!response.ok || !response.data) {
|
|
109
|
-
return null
|
|
110
113
|
}
|
|
111
114
|
|
|
112
|
-
|
|
115
|
+
// An ok response without a body is "not found", not a failed lookup.
|
|
116
|
+
if (response.ok) return response.data ? mapSingleAuctionPayload(response.data) : null
|
|
117
|
+
failedStatus = response.status
|
|
113
118
|
} catch (error) {
|
|
114
119
|
// AuctionDetailsPage already renders a "not found" state for a null
|
|
115
120
|
// auction, so this degrades gracefully — but it shouldn't be silent.
|
|
116
121
|
reportError(error)
|
|
122
|
+
if (throwOnError) throw error
|
|
117
123
|
return null
|
|
118
124
|
}
|
|
125
|
+
// Thrown outside the try so reportError never sees this synthetic error.
|
|
126
|
+
if (throwOnError && failedStatus !== 404) throw new Error(`Failed to load auction (HTTP ${failedStatus})`)
|
|
127
|
+
return null
|
|
119
128
|
}
|
|
120
129
|
|
|
121
130
|
export const getAuctionBids = async (
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Spec-table cells are authored upstream with LaTeX fragments (`\pm`, `~`,
|
|
3
|
+
* `^{*}`) and a unit that is also repeated in the value. Render them as plain
|
|
4
|
+
* text. A trailing repeat is only collapsed when it holds a letter, so a
|
|
5
|
+
* genuine "10 10" is left alone.
|
|
6
|
+
*/
|
|
7
|
+
export function formatSpecificationCell(text: string): string {
|
|
8
|
+
const cleaned = text
|
|
9
|
+
.replace(/\\pm/g, "±")
|
|
10
|
+
// Only a tilde glued between two characters is the LaTeX non-breaking space;
|
|
11
|
+
// a leading or standalone one ("~5 kg") means "approximately" and stays.
|
|
12
|
+
.replace(/(?<=\S)~(?=\S)/g, " ")
|
|
13
|
+
.replace(/\^\{([^}]*)\}/g, "$1")
|
|
14
|
+
.replace(/\s+/g, " ")
|
|
15
|
+
.trim()
|
|
16
|
+
// Whitespace is now single spaces, so the last two tokens are found by index
|
|
17
|
+
// (a backtracking regex here is quadratic on long vendor-authored cells).
|
|
18
|
+
const lastSpace = cleaned.lastIndexOf(" ")
|
|
19
|
+
if (lastSpace < 0) return cleaned
|
|
20
|
+
const last = cleaned.slice(lastSpace + 1)
|
|
21
|
+
const previous = cleaned.slice(cleaned.lastIndexOf(" ", lastSpace - 1) + 1, lastSpace)
|
|
22
|
+
return last === previous && /[A-Za-z]/.test(last) ? cleaned.slice(0, lastSpace) : cleaned
|
|
23
|
+
}
|
|
@@ -14,8 +14,11 @@ export function isHttpsRequest(request: Request): boolean {
|
|
|
14
14
|
return forwarded ? forwarded === "https" : new URL(request.url).protocol === "https:"
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
-
/**
|
|
18
|
-
|
|
17
|
+
/**
|
|
18
|
+
* `nonce` is empty for an apex login (no handoff to bind); `state` is the OAuth state Google was handed.
|
|
19
|
+
* `registered` is true when google-start accepted the host via SSO_HUB_RETURN_ORIGINS; cookies without it read as not registered.
|
|
20
|
+
*/
|
|
21
|
+
export type SsoHubState = { host: string; locale: string; nonce: string; state: string; registered?: boolean }
|
|
19
22
|
|
|
20
23
|
const MIN_SECRET_LENGTH = 32
|
|
21
24
|
const HOSTNAME_PATTERN = /^[a-z0-9]([a-z0-9.-]*[a-z0-9])?$/
|
|
@@ -38,7 +41,7 @@ export function sealSsoHubState(state: SsoHubState, now = Date.now()): string {
|
|
|
38
41
|
throw new Error("SSO_HUB_SECRET is not configured")
|
|
39
42
|
}
|
|
40
43
|
const payload = Buffer.from(
|
|
41
|
-
JSON.stringify({ host: state.host, locale: state.locale, nonce: state.nonce, state: state.state, exp: now + SSO_HUB_COOKIE_MAX_AGE_SECONDS * 1000 })
|
|
44
|
+
JSON.stringify({ host: state.host, locale: state.locale, nonce: state.nonce, state: state.state, ...(state.registered ? { registered: true } : {}), exp: now + SSO_HUB_COOKIE_MAX_AGE_SECONDS * 1000 })
|
|
42
45
|
).toString("base64url")
|
|
43
46
|
return `${payload}.${sign(payload)}`
|
|
44
47
|
}
|
|
@@ -53,11 +56,11 @@ export function openSsoHubState(value: string | undefined, now = Date.now()): Ss
|
|
|
53
56
|
const given = Buffer.from(signature)
|
|
54
57
|
if (expected.length !== given.length || !timingSafeEqual(expected, given)) return null
|
|
55
58
|
try {
|
|
56
|
-
const { host, locale, nonce, state, exp } = JSON.parse(Buffer.from(payload, "base64url").toString("utf-8")) as Record<string, unknown>
|
|
59
|
+
const { host, locale, nonce, state, exp, registered } = JSON.parse(Buffer.from(payload, "base64url").toString("utf-8")) as Record<string, unknown>
|
|
57
60
|
if (typeof host !== "string" || typeof locale !== "string" || typeof nonce !== "string" || typeof state !== "string" || typeof exp !== "number" || exp <= now) {
|
|
58
61
|
return null
|
|
59
62
|
}
|
|
60
|
-
return { host, locale, nonce, state }
|
|
63
|
+
return registered === true ? { host, locale, nonce, state, registered } : { host, locale, nonce, state }
|
|
61
64
|
} catch {
|
|
62
65
|
return null
|
|
63
66
|
}
|
|
@@ -86,6 +89,46 @@ export function originForHost(host: string): string {
|
|
|
86
89
|
return `${base.protocol}//${host}${base.port ? `:${base.port}` : ""}`
|
|
87
90
|
}
|
|
88
91
|
|
|
92
|
+
/** A bare origin (`scheme://host[:port]`, nothing else) whose hostname is a plain DNS name; `new URL` round-trip rejects every extra part. */
|
|
93
|
+
function bareOrigin(value: string): URL | null {
|
|
94
|
+
try {
|
|
95
|
+
const url = new URL(value)
|
|
96
|
+
return url.origin === value && isBareHostname(url.hostname) ? url : null
|
|
97
|
+
} catch {
|
|
98
|
+
return null
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/** https, or http only when this app's own base URL is http. */
|
|
103
|
+
const schemeAllowed = (url: URL): boolean =>
|
|
104
|
+
url.protocol === "https:" || (url.protocol === "http:" && new URL(getSiteBaseUrl()).protocol === "http:")
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* The origin configured in SSO_HUB_RETURN_ORIGINS (comma separated, apex env) for this exact hostname, else null.
|
|
108
|
+
* Re-read on every call; an entry that is not a bare https origin (http only under an http apex) on a hostname other
|
|
109
|
+
* than the apex is dropped.
|
|
110
|
+
*/
|
|
111
|
+
export function registeredReturnOrigin(host: string): string | null {
|
|
112
|
+
const apexUrl = new URL(getSiteBaseUrl())
|
|
113
|
+
for (const entry of (process.env.SSO_HUB_RETURN_ORIGINS ?? "").split(",").map((e) => e.trim()).filter(Boolean)) {
|
|
114
|
+
const url = bareOrigin(entry)
|
|
115
|
+
if (!url || !schemeAllowed(url) || url.hostname === apexUrl.hostname.toLowerCase()) {
|
|
116
|
+
console.warn("SSO_HUB_RETURN_ORIGINS: ignored an invalid entry")
|
|
117
|
+
continue
|
|
118
|
+
}
|
|
119
|
+
if (url.hostname === host) return entry
|
|
120
|
+
}
|
|
121
|
+
return null
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/** Hub-client mode: the apex origin this app logs in through (NEXT_PUBLIC_SSO_HUB_ORIGIN), or null when unset, invalid or this app's own host. */
|
|
125
|
+
export function ssoHubOrigin(): string | null {
|
|
126
|
+
const value = process.env.NEXT_PUBLIC_SSO_HUB_ORIGIN
|
|
127
|
+
if (!value) return null
|
|
128
|
+
const url = bareOrigin(value)
|
|
129
|
+
return url && schemeAllowed(url) && url.hostname !== apexHostname() ? value : null
|
|
130
|
+
}
|
|
131
|
+
|
|
89
132
|
export function readCookie(request: Request, name: string): string | undefined {
|
|
90
133
|
for (const part of (request.headers.get("cookie") ?? "").split(";")) {
|
|
91
134
|
const index = part.indexOf("=")
|
|
@@ -13,6 +13,7 @@ import {
|
|
|
13
13
|
resolveLocale,
|
|
14
14
|
sameSecret,
|
|
15
15
|
ssoHubNonceCookie,
|
|
16
|
+
ssoHubOrigin,
|
|
16
17
|
} from "../../../../lib/helpers/sso-hub"
|
|
17
18
|
import { getSiteBaseUrl } from "../../../../lib/helpers/get-site-base-url"
|
|
18
19
|
|
|
@@ -30,14 +31,16 @@ const CODE_PATTERN = /^[A-Za-z0-9_-]{43}$/
|
|
|
30
31
|
export async function GET(request: Request) {
|
|
31
32
|
const url = new URL(request.url)
|
|
32
33
|
const locale = resolveLocale(url.searchParams.get("locale"))
|
|
33
|
-
|
|
34
|
+
// A hub client redeems for its own configured host, never the Host header.
|
|
35
|
+
const hubOrigin = ssoHubOrigin()
|
|
36
|
+
const host = hubOrigin ? apexHostname() : hostnameOf(request.headers.get("host") ?? "")
|
|
34
37
|
|
|
35
38
|
// The apex has no tenant to hand off to; an unusable Host never builds an origin.
|
|
36
|
-
if (!isBareHostname(host) || host === apexHostname()) {
|
|
39
|
+
if (!isBareHostname(host) || (!hubOrigin && host === apexHostname())) {
|
|
37
40
|
return NextResponse.redirect(new URL(`/${locale}/login?error=google_auth_failed`, getSiteBaseUrl()))
|
|
38
41
|
}
|
|
39
42
|
|
|
40
|
-
const origin = originForHost(host)
|
|
43
|
+
const origin = hubOrigin ? getSiteBaseUrl() : originForHost(host)
|
|
41
44
|
const secure = isHttpsRequest(request)
|
|
42
45
|
const nonceCookie = ssoHubNonceCookie(secure)
|
|
43
46
|
const fail = () => {
|
|
@@ -9,10 +9,12 @@ import {
|
|
|
9
9
|
originForHost,
|
|
10
10
|
isHttpsRequest,
|
|
11
11
|
readCookie,
|
|
12
|
+
registeredReturnOrigin,
|
|
12
13
|
resolveLocale,
|
|
13
14
|
sameSecret,
|
|
14
15
|
SSO_HUB_COOKIE,
|
|
15
16
|
ssoHubEnabled,
|
|
17
|
+
ssoHubOrigin,
|
|
16
18
|
} from "../../../lib/helpers/sso-hub"
|
|
17
19
|
|
|
18
20
|
/**
|
|
@@ -40,13 +42,23 @@ export async function GET(request: Request) {
|
|
|
40
42
|
// missing, tampered or expired one is a failed login: the code could be anyone's (login CSRF). Unset, no cookie is
|
|
41
43
|
// today's apex flow.
|
|
42
44
|
const locale = resolveLocale(hub ? hub.locale : url.searchParams.get("locale"))
|
|
43
|
-
|
|
45
|
+
// A cookie issued for a registered host stays valid only while that host is still registered: removing it from
|
|
46
|
+
// SSO_HUB_RETURN_ORIGINS must stop in-flight handoffs, not fall back to the tenant path.
|
|
47
|
+
const registeredOrigin = hub ? registeredReturnOrigin(hub.host) : null
|
|
48
|
+
const revoked = Boolean(hub?.registered) && !registeredOrigin
|
|
49
|
+
const tenantOrigin = hub && !revoked && hub.host !== apexHostname() ? (registeredOrigin ?? originForHost(hub.host)) : null
|
|
44
50
|
const fail = () =>
|
|
45
51
|
withHubCookieCleared(
|
|
46
52
|
NextResponse.redirect(new URL(`/${locale}/login?error=google_auth_failed`, tenantOrigin ?? origin))
|
|
47
53
|
)
|
|
48
54
|
|
|
55
|
+
// A hub client never exchanges a Google code itself: without the hub secret it could not tell whose code this is.
|
|
56
|
+
if (ssoHubOrigin()) {
|
|
57
|
+
if (ssoHubEnabled()) console.error("google-callback: NEXT_PUBLIC_SSO_HUB_ORIGIN and SSO_HUB_SECRET are both set; Google login is refused")
|
|
58
|
+
return fail()
|
|
59
|
+
}
|
|
49
60
|
if ((rawHub !== undefined || ssoHubEnabled()) && !hub) return fail()
|
|
61
|
+
if (revoked) return fail()
|
|
50
62
|
if (url.searchParams.get("error")) return fail()
|
|
51
63
|
// The OAuth state must be the one google-start put in this browser's cookie, or the code is someone else's login.
|
|
52
64
|
if (hub && !sameSecret(url.searchParams.get("state") ?? "", hub.state)) return fail()
|
|
@@ -8,6 +8,7 @@ import {
|
|
|
8
8
|
isBareHostname,
|
|
9
9
|
isHttpsRequest,
|
|
10
10
|
isNonce,
|
|
11
|
+
registeredReturnOrigin,
|
|
11
12
|
resolveLocale,
|
|
12
13
|
sealSsoHubState,
|
|
13
14
|
SSO_HUB_COOKIE,
|
|
@@ -36,15 +37,16 @@ function throttled(request: Request, now = Date.now()): boolean {
|
|
|
36
37
|
return entry.count > MAX_STARTS_PER_WINDOW
|
|
37
38
|
}
|
|
38
39
|
|
|
39
|
-
/** The primary host of a live tenant (or the apex itself); null for anything else. No open redirect: only this answer ever reaches the cookie. */
|
|
40
|
-
async function trustedReturnHost(raw: string): Promise<string | null> {
|
|
40
|
+
/** The primary host of a live tenant (or the apex itself), flagged when it was accepted via SSO_HUB_RETURN_ORIGINS; null for anything else. No open redirect: only this answer ever reaches the cookie. */
|
|
41
|
+
async function trustedReturnHost(raw: string): Promise<{ host: string; registered: boolean } | null> {
|
|
41
42
|
const host = raw.trim().toLowerCase()
|
|
42
43
|
if (!isBareHostname(host)) return null
|
|
43
|
-
if (host === apexHostname()) return host
|
|
44
|
+
if (host === apexHostname()) return { host, registered: false }
|
|
45
|
+
if (registeredReturnOrigin(host)) return { host, registered: true }
|
|
44
46
|
try {
|
|
45
47
|
const sdk = await getOpticommSdk()
|
|
46
48
|
const { primary_host } = await sdk.store.opticomm.retrieveStoreDomainsResolve<{ primary_host: string }>({ host })
|
|
47
|
-
return isBareHostname(primary_host) ? primary_host : null
|
|
49
|
+
return isBareHostname(primary_host) ? { host: primary_host, registered: false } : null
|
|
48
50
|
} catch {
|
|
49
51
|
return null
|
|
50
52
|
}
|
|
@@ -70,8 +72,9 @@ export async function GET(request: Request) {
|
|
|
70
72
|
|
|
71
73
|
if (!ssoHubEnabled()) return reject()
|
|
72
74
|
|
|
73
|
-
const
|
|
74
|
-
if (!
|
|
75
|
+
const trusted = await trustedReturnHost(url.searchParams.get("return") ?? "")
|
|
76
|
+
if (!trusted) return reject()
|
|
77
|
+
const { host, registered } = trusted
|
|
75
78
|
|
|
76
79
|
// Only a tenant handoff is nonce-bound; the apex logs in on this very host.
|
|
77
80
|
const isApex = host === apexHostname()
|
|
@@ -89,7 +92,7 @@ export async function GET(request: Request) {
|
|
|
89
92
|
if (!state) return reject()
|
|
90
93
|
|
|
91
94
|
const response = NextResponse.redirect(location)
|
|
92
|
-
response.cookies.set(SSO_HUB_COOKIE, sealSsoHubState({ host, locale, nonce, state }), {
|
|
95
|
+
response.cookies.set(SSO_HUB_COOKIE, sealSsoHubState({ host, locale, nonce, state, registered }), {
|
|
93
96
|
httpOnly: true,
|
|
94
97
|
sameSite: "lax",
|
|
95
98
|
secure: isHttpsRequest(request),
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Metadata } from "next"
|
|
2
|
+
import { notFound } from "next/navigation"
|
|
2
3
|
import { AuctionDetailsPage } from "../../../../components/sections/AuctionDetailsPage/AuctionDetailsPage"
|
|
3
4
|
import { getAuction, getAuctionBids } from "../../../../lib/data/bidding"
|
|
4
5
|
import { retrieveCustomer } from "../../../../lib/data/customer"
|
|
@@ -36,12 +37,15 @@ export default async function AuctionPage({
|
|
|
36
37
|
const depositConfirmed = resolvedSearch["deposit"] === "confirmed"
|
|
37
38
|
|
|
38
39
|
const [auction, bidsData, customer, region] = await Promise.all([
|
|
39
|
-
getAuction(id),
|
|
40
|
+
getAuction(id, { throwOnError: true }),
|
|
40
41
|
getAuctionBids(id),
|
|
41
42
|
retrieveCustomer().catch(() => null),
|
|
42
43
|
getRegion(locale),
|
|
43
44
|
])
|
|
44
45
|
|
|
46
|
+
// A real 404 (not a 200 "not found" body) for an unknown auction; other failures threw above.
|
|
47
|
+
if (!auction) notFound()
|
|
48
|
+
|
|
45
49
|
return (
|
|
46
50
|
<AuctionDetailsPage
|
|
47
51
|
auctionId={id}
|
|
@@ -10,6 +10,7 @@ import { ArrowLeftIcon } from "../../../../../icons"
|
|
|
10
10
|
import { fetchOrderHandoffHistory } from "../../../../../lib/data/cart-handoff"
|
|
11
11
|
import { retrieveCustomer } from "../../../../../lib/data/customer"
|
|
12
12
|
import { retrieveOrderSet } from "../../../../../lib/data/orders"
|
|
13
|
+
import { isNotFoundError } from "../../../../../lib/helpers/medusa-error"
|
|
13
14
|
|
|
14
15
|
export default async function UserPage({
|
|
15
16
|
params,
|
|
@@ -19,9 +20,17 @@ export default async function UserPage({
|
|
|
19
20
|
const { id } = await params
|
|
20
21
|
|
|
21
22
|
const user = await retrieveCustomer()
|
|
22
|
-
|
|
23
|
-
|
|
23
|
+
// Before any order fetch: the backend rejects an unauthenticated read, which
|
|
24
|
+
// would otherwise surface as a 500 instead of the login redirect.
|
|
24
25
|
if (!user) return redirect("/login")
|
|
26
|
+
|
|
27
|
+
// An unknown (or not-yours) id is a 404 from the backend; show the orders
|
|
28
|
+
// list rather than letting the thrown error become a 500.
|
|
29
|
+
const orderSet = await retrieveOrderSet(id).catch((error: unknown) => {
|
|
30
|
+
if (isNotFoundError(error)) return null
|
|
31
|
+
throw error
|
|
32
|
+
})
|
|
33
|
+
|
|
25
34
|
if (!orderSet) return redirect("/user/orders")
|
|
26
35
|
|
|
27
36
|
// The hand-off history route is keyed by an individual order id, not the
|