@sgflabs/storefront-core 0.1.12 → 0.1.14
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/organisms/AiChatWidget/AiChatWidget.tsx +14 -2
- package/src/components/organisms/ProductSidebar/CertificationFilter.tsx +5 -2
- package/src/components/organisms/ProductSidebar/ProductSidebar.tsx +7 -5
- package/src/components/sections/ProductListing/ProductListing.tsx +3 -2
- package/src/lib/data/industry-certifications.ts +34 -0
- package/src/lib/runtime/public-storefront-runtime-env.ts +0 -14
- package/src/lib/storefront/industry-certifications.ts +0 -32
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sgflabs/storefront-core",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.14",
|
|
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.3.0",
|
|
58
|
-
"@sgflabs/gstin": "^0.1.
|
|
59
|
-
"@sgflabs/page-spec": "^0.1.
|
|
60
|
-
"@sgflabs/storefront-core-common": "^0.1.
|
|
58
|
+
"@sgflabs/gstin": "^0.1.14",
|
|
59
|
+
"@sgflabs/page-spec": "^0.1.14",
|
|
60
|
+
"@sgflabs/storefront-core-common": "^0.1.14",
|
|
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.3.0",
|
|
76
|
-
"@sgflabs/gstin": "^0.1.
|
|
77
|
-
"@sgflabs/page-spec": "^0.1.
|
|
78
|
-
"@sgflabs/storefront-core-common": "^0.1.
|
|
76
|
+
"@sgflabs/gstin": "^0.1.14",
|
|
77
|
+
"@sgflabs/page-spec": "^0.1.14",
|
|
78
|
+
"@sgflabs/storefront-core-common": "^0.1.14",
|
|
79
79
|
"next": "15.5.27",
|
|
80
80
|
"react": "^19.2.3",
|
|
81
81
|
"react-dom": "^19.2.3"
|
|
@@ -153,8 +153,20 @@ function ChatPanel({ baseUrl, onClose }: { baseUrl: string; onClose: () => void
|
|
|
153
153
|
messages.map((m) => <MessageBubble key={m.id} message={m} />)
|
|
154
154
|
)}
|
|
155
155
|
{isLoading && (
|
|
156
|
-
<p
|
|
157
|
-
|
|
156
|
+
<p
|
|
157
|
+
role="status"
|
|
158
|
+
className="flex items-center gap-1 py-2 text-secondary"
|
|
159
|
+
data-testid="ai-chat-typing"
|
|
160
|
+
>
|
|
161
|
+
<span className="sr-only">Assistant is typing…</span>
|
|
162
|
+
{[0, 150, 300].map((delay) => (
|
|
163
|
+
<span
|
|
164
|
+
key={delay}
|
|
165
|
+
aria-hidden="true"
|
|
166
|
+
style={{ animationDelay: `${delay}ms` }}
|
|
167
|
+
className="size-1.5 rounded-full bg-current motion-safe:animate-bounce"
|
|
168
|
+
/>
|
|
169
|
+
))}
|
|
158
170
|
</p>
|
|
159
171
|
)}
|
|
160
172
|
</div>
|
|
@@ -25,14 +25,17 @@ export function CertificationFilter({
|
|
|
25
25
|
certificationCounts,
|
|
26
26
|
searchTerm = "",
|
|
27
27
|
}: {
|
|
28
|
-
/** The industry's options
|
|
28
|
+
/** The industry's options, derived by the backend from the publishable key (`getIndustryCertificationTypes`). */
|
|
29
29
|
certificationTypes: readonly CertificationType[]
|
|
30
30
|
certificationCounts?: Partial<Record<CertificationType, number>>
|
|
31
31
|
/** "Find a filter" substring match over certification labels, lifted from the sidebar. */
|
|
32
32
|
searchTerm?: string
|
|
33
33
|
}) {
|
|
34
34
|
const { isFilterActive, updateFilters } = useFilters("certification_type")
|
|
35
|
-
|
|
35
|
+
// Open when something is already selected: the listing remounts (a <Suspense key> over the
|
|
36
|
+
// selected filters) after every pick, so a dropdown that came back closed would make the
|
|
37
|
+
// shopper reopen it for each option of a multi-select. Same rule as the Application filter.
|
|
38
|
+
const [open, setOpen] = useState(() => certificationTypes.some((type) => isFilterActive(type)))
|
|
36
39
|
const containerRef = useRef<HTMLDivElement>(null)
|
|
37
40
|
const triggerRef = useRef<HTMLButtonElement>(null)
|
|
38
41
|
|
|
@@ -19,7 +19,7 @@ import { categoriesMirrorApplications } from '../../../lib/helpers/categories-mi
|
|
|
19
19
|
import { type FlatCategoryLike } from '../../../lib/helpers/category-tree';
|
|
20
20
|
import { registerFilterSection } from '../../../lib/helpers/filter-section-registry';
|
|
21
21
|
import { isCategoriesCollectionsBrowseMode } from '../../../lib/storefront/browse-nav-flags';
|
|
22
|
-
import {
|
|
22
|
+
import { type CertificationType } from '../../../lib/helpers/parse-listing-controls';
|
|
23
23
|
import { cn } from '../../../lib/utils';
|
|
24
24
|
|
|
25
25
|
interface ProductSidebarProps {
|
|
@@ -37,6 +37,11 @@ interface ProductSidebarProps {
|
|
|
37
37
|
* showing zeros it never measured.
|
|
38
38
|
*/
|
|
39
39
|
facetCounts?: ListingFacetCounts
|
|
40
|
+
/**
|
|
41
|
+
* The certifications this storefront's industry offers (derived by the backend from the
|
|
42
|
+
* publishable key). None, the default, hides the Certification filter.
|
|
43
|
+
*/
|
|
44
|
+
certificationTypes?: readonly CertificationType[]
|
|
40
45
|
}
|
|
41
46
|
|
|
42
47
|
export const ProductSidebar = ({
|
|
@@ -48,6 +53,7 @@ export const ProductSidebar = ({
|
|
|
48
53
|
applications = [],
|
|
49
54
|
valueLabels,
|
|
50
55
|
facetCounts,
|
|
56
|
+
certificationTypes = [],
|
|
51
57
|
}: ProductSidebarProps) => {
|
|
52
58
|
const [filterModal, setFilterModal] = useState(false);
|
|
53
59
|
const [findFilterTerm, setFindFilterTerm] = useState('');
|
|
@@ -66,12 +72,8 @@ export const ProductSidebar = ({
|
|
|
66
72
|
// In categories-collections browse mode there is no Application filter, so
|
|
67
73
|
// never hide Category on that basis.
|
|
68
74
|
// Davison (categories-collections) is apparel: Size replaces Certification.
|
|
69
|
-
// Which certifications show (if any) is decided by the storefront's industry,
|
|
70
|
-
// not hardcoded -- FSSAI/Halal are food facets, ISO/GMP/BRC are polymer ones.
|
|
71
75
|
const hideApplicationFilter = isCategoriesCollectionsBrowseMode()
|
|
72
76
|
const showApparelSizeFilter = hideApplicationFilter
|
|
73
|
-
// categories-collections (apparel) never shows them, even if the industry env is unset.
|
|
74
|
-
const certificationTypes = hideApplicationFilter ? [] : getIndustryCertificationTypes()
|
|
75
77
|
const hideCategoryFilter =
|
|
76
78
|
!hideApplicationFilter &&
|
|
77
79
|
categoriesMirrorApplications(
|
|
@@ -20,6 +20,7 @@ const LISTING_FACETS_NO_CERTIFICATION = ["has_price", "has_sample"] as const
|
|
|
20
20
|
import { listApplicationCategories, listApplications, listSellerApplications } from "../../../lib/data/applications"
|
|
21
21
|
import { getCategoryNamesByIds, listCategoryTreePage } from "../../../lib/data/categories"
|
|
22
22
|
import { getMusicCategoryIds } from "../../../lib/data/music-categories"
|
|
23
|
+
import { getIndustryCertificationTypes } from "../../../lib/data/industry-certifications"
|
|
23
24
|
import {
|
|
24
25
|
listApplicationFilteredProducts,
|
|
25
26
|
listProductsSortedByPrice,
|
|
@@ -27,7 +28,6 @@ import {
|
|
|
27
28
|
} from "../../../lib/data/products"
|
|
28
29
|
import { CERTIFICATION_TYPE_LABELS } from "../../../lib/helpers/certification-label"
|
|
29
30
|
import { isCategoriesCollectionsBrowseMode } from "../../../lib/storefront/browse-nav-flags"
|
|
30
|
-
import { getIndustryCertificationTypes } from "../../../lib/storefront/industry-certifications"
|
|
31
31
|
import { isMusicOnlyCatalogEnabled } from "../../../lib/streaming/streaming-feature-flags"
|
|
32
32
|
import type { SortOptions } from "../../../types/product"
|
|
33
33
|
|
|
@@ -128,7 +128,7 @@ export const ProductListing = async ({
|
|
|
128
128
|
// here, so the results, the chips and the dropdown always agree. Apparel
|
|
129
129
|
// (categories-collections) offers none.
|
|
130
130
|
const isApparelBrowse = isCategoriesCollectionsBrowseMode()
|
|
131
|
-
const industryCertificationTypes = isApparelBrowse ? [] : getIndustryCertificationTypes()
|
|
131
|
+
const industryCertificationTypes = isApparelBrowse ? [] : await getIndustryCertificationTypes()
|
|
132
132
|
const effectiveCertificationTypes =
|
|
133
133
|
industryCertificationTypes.length === 0
|
|
134
134
|
? undefined
|
|
@@ -335,6 +335,7 @@ export const ProductListing = async ({
|
|
|
335
335
|
fixedCategoryId={fixedCategoryId}
|
|
336
336
|
applications={applicationsResult.applications ?? []}
|
|
337
337
|
valueLabels={valueLabels}
|
|
338
|
+
certificationTypes={industryCertificationTypes}
|
|
338
339
|
facetCounts={'facets' in response ? response.facets : undefined}
|
|
339
340
|
/>
|
|
340
341
|
)}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import * as React from "react"
|
|
2
|
+
|
|
3
|
+
import { getOpticommSdk } from "../config"
|
|
4
|
+
import { reportError } from "../helpers/report-error"
|
|
5
|
+
import { CERTIFICATION_TYPES, type CertificationType } from "../helpers/parse-listing-controls"
|
|
6
|
+
|
|
7
|
+
// `cache` is a server-render API; plain React (unit tests) has none, and a single call needs no dedupe.
|
|
8
|
+
const perRequest: <T>(fn: () => Promise<T>) => () => Promise<T> = React.cache ?? ((fn) => fn)
|
|
9
|
+
|
|
10
|
+
const KNOWN: ReadonlySet<string> = new Set(CERTIFICATION_TYPES)
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* The certification filter options for this storefront, derived by the backend from the request's
|
|
14
|
+
* publishable key (its sales channels -> industries -> certifications), so they cannot drift from
|
|
15
|
+
* the key. Fails closed: any failure, or an answer that is not the expected shape, returns none, so
|
|
16
|
+
* the Certification filter and its facet are hidden rather than showing another industry's options.
|
|
17
|
+
* A type this storefront's parser does not know is dropped (it could not filter anyway).
|
|
18
|
+
*/
|
|
19
|
+
export const getIndustryCertificationTypes = perRequest(async (): Promise<readonly CertificationType[]> => {
|
|
20
|
+
try {
|
|
21
|
+
const { certification_types } = await (await getOpticommSdk()).store.opticomm.listIndustries()
|
|
22
|
+
if (!Array.isArray(certification_types)) {
|
|
23
|
+
return []
|
|
24
|
+
}
|
|
25
|
+
return certification_types.filter((type): type is CertificationType => KNOWN.has(type))
|
|
26
|
+
} catch (error) {
|
|
27
|
+
// Next's control-flow signals (static bailouts) must propagate, not be read as a failed fetch.
|
|
28
|
+
if ((error as { digest?: string } | null)?.digest) {
|
|
29
|
+
throw error
|
|
30
|
+
}
|
|
31
|
+
reportError(error)
|
|
32
|
+
return []
|
|
33
|
+
}
|
|
34
|
+
})
|
|
@@ -16,8 +16,6 @@ export type StorefrontPublicRuntimeSnapshot = {
|
|
|
16
16
|
NEXT_PUBLIC_ENABLE_COOKIE_CONSENT?: string
|
|
17
17
|
/** Browse panel vocabulary: `applications` (default) or `categories-collections` (Davison). */
|
|
18
18
|
NEXT_PUBLIC_BROWSE_NAV_MODE?: string
|
|
19
|
-
/** Industry sales-channel slug (e.g. `food_ingredients`); decides which certification filters show. */
|
|
20
|
-
NEXT_PUBLIC_STOREFRONT_INDUSTRY?: string
|
|
21
19
|
/** artha-go ai-interface base URL; the AI chat widget renders nothing when unset. */
|
|
22
20
|
NEXT_PUBLIC_AI_INTERFACE_URL?: string
|
|
23
21
|
}
|
|
@@ -82,12 +80,6 @@ export function buildStorefrontRuntimeEnvSnapshot(): StorefrontPublicRuntimeSnap
|
|
|
82
80
|
if (browseNavMode !== undefined) {
|
|
83
81
|
snapshot.NEXT_PUBLIC_BROWSE_NAV_MODE = browseNavMode
|
|
84
82
|
}
|
|
85
|
-
const storefrontIndustry =
|
|
86
|
-
optionalTrim(process.env.STOREFRONT_INDUSTRY) ??
|
|
87
|
-
optionalTrim(process.env.NEXT_PUBLIC_STOREFRONT_INDUSTRY)
|
|
88
|
-
if (storefrontIndustry !== undefined) {
|
|
89
|
-
snapshot.NEXT_PUBLIC_STOREFRONT_INDUSTRY = storefrontIndustry
|
|
90
|
-
}
|
|
91
83
|
const aiInterfaceUrl =
|
|
92
84
|
optionalTrim(process.env.AI_INTERFACE_URL) ??
|
|
93
85
|
optionalTrim(process.env.NEXT_PUBLIC_AI_INTERFACE_URL)
|
|
@@ -159,12 +151,6 @@ export function readStorefrontRuntimePublic(
|
|
|
159
151
|
optionalTrim(process.env.NEXT_PUBLIC_BROWSE_NAV_MODE)
|
|
160
152
|
)
|
|
161
153
|
}
|
|
162
|
-
if (publicKey === "NEXT_PUBLIC_STOREFRONT_INDUSTRY") {
|
|
163
|
-
return (
|
|
164
|
-
optionalTrim(process.env.STOREFRONT_INDUSTRY) ??
|
|
165
|
-
optionalTrim(process.env.NEXT_PUBLIC_STOREFRONT_INDUSTRY)
|
|
166
|
-
)
|
|
167
|
-
}
|
|
168
154
|
if (publicKey === "NEXT_PUBLIC_AI_INTERFACE_URL") {
|
|
169
155
|
return (
|
|
170
156
|
optionalTrim(process.env.AI_INTERFACE_URL) ??
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import type { CertificationType } from "../helpers/parse-listing-controls"
|
|
2
|
-
import { readStorefrontRuntimePublic } from "../runtime/public-storefront-runtime-env"
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Industry slugs match the platform's sales-channel slugs
|
|
6
|
-
* (INDUSTRY_SLUG_BY_CHANNEL_NAME in @sgftech/framework, e.g. "Food Ingredients"
|
|
7
|
-
* -> "food_ingredients"). Restated rather than imported: storefront-core does
|
|
8
|
-
* not depend on the backend framework package.
|
|
9
|
-
*/
|
|
10
|
-
const DEFAULT_INDUSTRY = "food_ingredients"
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Certifications that make sense for an industry's products. An industry not
|
|
14
|
-
* listed here (apparel, digital media, ...) has none, so the filter is hidden
|
|
15
|
-
* rather than showing food facets (FSSAI/Halal/...) on a store that cannot have
|
|
16
|
-
* them.
|
|
17
|
-
*/
|
|
18
|
-
const CERTIFICATION_TYPES_BY_INDUSTRY: Record<string, readonly CertificationType[]> = {
|
|
19
|
-
food_ingredients: ["fssai", "halal", "kosher", "organic", "vegan"],
|
|
20
|
-
polymer_specialities: ["iso", "gmp", "brc"],
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* The certification filter options for this storefront's industry, from
|
|
25
|
-
* `NEXT_PUBLIC_STOREFRONT_INDUSTRY` (an industry sales-channel slug). Unset
|
|
26
|
-
* keeps the original food behaviour; an unrecognised industry gets none.
|
|
27
|
-
*/
|
|
28
|
-
export function getIndustryCertificationTypes(): readonly CertificationType[] {
|
|
29
|
-
const raw = readStorefrontRuntimePublic("NEXT_PUBLIC_STOREFRONT_INDUSTRY")
|
|
30
|
-
const industry = raw ? raw.trim().toLowerCase() : DEFAULT_INDUSTRY
|
|
31
|
-
return CERTIFICATION_TYPES_BY_INDUSTRY[industry] ?? []
|
|
32
|
-
}
|