@shopware/helpers 1.7.1 → 1.7.2
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 +23 -28
- package/dist/index.d.mts +13 -1
- package/dist/index.d.ts +13 -1
- package/dist/index.mjs +17 -1
- package/package.json +8 -9
package/README.md
CHANGED
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
Welcome to `@shopware/helpers` package.
|
|
4
4
|
|
|
5
|
-
For getting started documentation visit [https://
|
|
5
|
+
For getting started documentation visit [https://developer.shopware.com/frontends/](https://developer.shopware.com/frontends/)
|
|
6
6
|
|
|
7
|
-
Documentation specific for this package: [helpers](https://
|
|
7
|
+
Documentation specific for this package: [helpers](https://developer.shopware.com/frontends/packages/helpers.html)
|
|
8
8
|
|
|
9
9
|
## Reusable classes
|
|
10
10
|
|
|
@@ -49,11 +49,11 @@ const optimizedUrl = getBackgroundImageUrl(
|
|
|
49
49
|
|
|
50
50
|
### Parameters
|
|
51
51
|
|
|
52
|
-
| Parameter | Type
|
|
53
|
-
|
|
54
|
-
| `url`
|
|
55
|
-
| `element` | `{ backgroundMedia?: { metaData?: { width?: number; height?: number } } }` | CMS section or block object with media metadata
|
|
56
|
-
| `options` | `BackgroundImageOptions` (optional)
|
|
52
|
+
| Parameter | Type | Description |
|
|
53
|
+
| --------- | -------------------------------------------------------------------------- | ------------------------------------------------------ |
|
|
54
|
+
| `url` | `string` | CSS `url()` string containing the background image URL |
|
|
55
|
+
| `element` | `{ backgroundMedia?: { metaData?: { width?: number; height?: number } } }` | CMS section or block object with media metadata |
|
|
56
|
+
| `options` | `BackgroundImageOptions` (optional) | Format and quality settings |
|
|
57
57
|
|
|
58
58
|
### `BackgroundImageOptions`
|
|
59
59
|
|
|
@@ -85,11 +85,11 @@ const srcset = generateCdnSrcSet(
|
|
|
85
85
|
|
|
86
86
|
### Parameters
|
|
87
87
|
|
|
88
|
-
| Parameter | Type
|
|
89
|
-
|
|
90
|
-
| `src`
|
|
91
|
-
| `widths`
|
|
92
|
-
| `options` | `{ format?: string; quality?: number }` (optional) | Format and quality settings
|
|
88
|
+
| Parameter | Type | Description |
|
|
89
|
+
| --------- | -------------------------------------------------- | --------------------------------------------------------------- |
|
|
90
|
+
| `src` | `string \| undefined` | Base image URL |
|
|
91
|
+
| `widths` | `number[]` (optional) | Array of widths to generate (default: `[400, 800, 1200, 1600]`) |
|
|
92
|
+
| `options` | `{ format?: string; quality?: number }` (optional) | Format and quality settings |
|
|
93
93
|
|
|
94
94
|
Returns `undefined` if `src` is falsy or URL parsing fails.
|
|
95
95
|
|
|
@@ -102,20 +102,20 @@ Builds an optimized CDN image URL with size parameters based on rendered element
|
|
|
102
102
|
```ts
|
|
103
103
|
import { buildCdnImageUrl } from "@shopware/helpers";
|
|
104
104
|
|
|
105
|
-
const url = buildCdnImageUrl(
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
);
|
|
105
|
+
const url = buildCdnImageUrl("https://cdn.shopware.store/.../image.jpg", {
|
|
106
|
+
width: 724,
|
|
107
|
+
height: 760,
|
|
108
|
+
});
|
|
109
109
|
// => "https://cdn.shopware.store/.../image.jpg?height=800&fit=crop,smart"
|
|
110
110
|
```
|
|
111
111
|
|
|
112
112
|
### Parameters
|
|
113
113
|
|
|
114
|
-
| Parameter
|
|
115
|
-
|
|
116
|
-
| `src`
|
|
117
|
-
| `dimensions` | `{ width: number; height: number }`
|
|
118
|
-
| `options`
|
|
114
|
+
| Parameter | Type | Description |
|
|
115
|
+
| ------------ | -------------------------------------------------- | ------------------------------------- |
|
|
116
|
+
| `src` | `string \| undefined` | Base image URL |
|
|
117
|
+
| `dimensions` | `{ width: number; height: number }` | Rendered element dimensions in pixels |
|
|
118
|
+
| `options` | `{ format?: string; quality?: number }` (optional) | Format and quality settings |
|
|
119
119
|
|
|
120
120
|
Returns an empty string if `src` is falsy. Returns the original `src` if URL parsing fails.
|
|
121
121
|
|
|
@@ -125,13 +125,8 @@ Returns an empty string if `src` is falsy. Returns the original `src` if URL par
|
|
|
125
125
|
|
|
126
126
|
Full changelog for stable version is available [here](https://github.com/shopware/frontends/blob/main/packages/helpers/CHANGELOG.md)
|
|
127
127
|
|
|
128
|
-
### Latest changes: 1.7.
|
|
128
|
+
### Latest changes: 1.7.2
|
|
129
129
|
|
|
130
130
|
### Patch Changes
|
|
131
131
|
|
|
132
|
-
- [#
|
|
133
|
-
|
|
134
|
-
This adds helpers to detect and normalize technical Shopware paths and updates
|
|
135
|
-
`useNavigationSearch` to resolve `/navigation/*`, `/detail/*`, and
|
|
136
|
-
`/landingPage/*` routes more reliably, including fallback behavior when no SEO
|
|
137
|
-
mapping row is returned.
|
|
132
|
+
- [#2594](https://github.com/shopware/frontends/pull/2594) [`f16c5a0`](https://github.com/shopware/frontends/commit/f16c5a0785d6187b73c3edcf37feab7c90bd7988) Thanks [@patzick](https://github.com/patzick)! - Add helpers for resolving canonical SEO paths and detecting technical Shopware URLs.
|
package/dist/index.d.mts
CHANGED
|
@@ -538,7 +538,19 @@ type RouteInfoFromPathInfo = {
|
|
|
538
538
|
};
|
|
539
539
|
declare function normalizePath(path: string): string;
|
|
540
540
|
declare function isTechnicalPath(path: string): boolean;
|
|
541
|
+
/**
|
|
542
|
+
* Check whether an absolute or relative URL points to a technical Shopware
|
|
543
|
+
* route. Query parameters and fragments are ignored.
|
|
544
|
+
*/
|
|
545
|
+
declare function isTechnicalUrl(url: string, baseUrl?: string): boolean;
|
|
541
546
|
declare function getRouteFromPathInfo(path: string): RouteInfoFromPathInfo | null;
|
|
547
|
+
/**
|
|
548
|
+
* Get the canonical path for a mapped technical Shopware URL.
|
|
549
|
+
*
|
|
550
|
+
* Returns `null` for SEO URLs, synthetic technical fallbacks without an SEO
|
|
551
|
+
* mapping, and invalid mappings that would redirect to another technical URL.
|
|
552
|
+
*/
|
|
553
|
+
declare function getCanonicalPathForTechnicalPath(path: string, seoUrl?: object | null): string | null;
|
|
542
554
|
|
|
543
555
|
/**
|
|
544
556
|
* Get translated property from the given object.
|
|
@@ -769,5 +781,5 @@ declare function canUseQuoteActions<T extends {
|
|
|
769
781
|
};
|
|
770
782
|
}>(quote: T): boolean;
|
|
771
783
|
|
|
772
|
-
export { buildCdnImageUrl, buildUrlPrefix, canUseQuoteActions, downloadFile, encodeUrlPath, generateCdnSrcSet, getBackgroundImageUrl, getBiggestThumbnailUrl, getCategoryBreadcrumbs, getCategoryImageUrl, getCategoryRoute, getCategoryUrl, getCmsBreadcrumbs, getCmsEntityObject, getCmsLayoutConfiguration, getCmsTranslate, getFormattedPrice, getLanguageName, getListingFilters, getMainImageUrl, getMedia, getPaymentMethodIcon, getProductCalculatedListingPrice, getProductFreeShipping, getProductFromPrice, getProductListingFromCmsPage, getProductManufacturerName, getProductName, getProductRatingAverage, getProductReviews, getProductRoute, getProductTierPrices, getProductUrl, getRouteFromPathInfo, getShippingMethodDeliveryTime, getShippingMethodIcon, getSmallestThumbnailUrl, getSrcSetForMedia, getTranslatedProperty, helpersCssClasses, isCategory, isLandingPage, isMaintenanceMode, isProduct, isProductOnSale, isProductTopSeller, isTechnicalPath, normalizePath, relativeUrlSlash, urlIsAbsolute };
|
|
784
|
+
export { buildCdnImageUrl, buildUrlPrefix, canUseQuoteActions, downloadFile, encodeUrlPath, generateCdnSrcSet, getBackgroundImageUrl, getBiggestThumbnailUrl, getCanonicalPathForTechnicalPath, getCategoryBreadcrumbs, getCategoryImageUrl, getCategoryRoute, getCategoryUrl, getCmsBreadcrumbs, getCmsEntityObject, getCmsLayoutConfiguration, getCmsTranslate, getFormattedPrice, getLanguageName, getListingFilters, getMainImageUrl, getMedia, getPaymentMethodIcon, getProductCalculatedListingPrice, getProductFreeShipping, getProductFromPrice, getProductListingFromCmsPage, getProductManufacturerName, getProductName, getProductRatingAverage, getProductReviews, getProductRoute, getProductTierPrices, getProductUrl, getRouteFromPathInfo, getShippingMethodDeliveryTime, getShippingMethodIcon, getSmallestThumbnailUrl, getSrcSetForMedia, getTranslatedProperty, helpersCssClasses, isCategory, isLandingPage, isMaintenanceMode, isProduct, isProductOnSale, isProductTopSeller, isTechnicalPath, isTechnicalUrl, normalizePath, relativeUrlSlash, urlIsAbsolute };
|
|
773
785
|
export type { BackgroundImageOptions, HelpersCssClasses, LayoutConfiguration, RouteInfoFromPathInfo, RouteNameFromPathInfo, TierPrice, UiMediaGalleryItem, UiMediaGalleryItemUrl, UiProductOption, UiProductProperty, UiProductReview, UrlRouteOutput };
|
package/dist/index.d.ts
CHANGED
|
@@ -538,7 +538,19 @@ type RouteInfoFromPathInfo = {
|
|
|
538
538
|
};
|
|
539
539
|
declare function normalizePath(path: string): string;
|
|
540
540
|
declare function isTechnicalPath(path: string): boolean;
|
|
541
|
+
/**
|
|
542
|
+
* Check whether an absolute or relative URL points to a technical Shopware
|
|
543
|
+
* route. Query parameters and fragments are ignored.
|
|
544
|
+
*/
|
|
545
|
+
declare function isTechnicalUrl(url: string, baseUrl?: string): boolean;
|
|
541
546
|
declare function getRouteFromPathInfo(path: string): RouteInfoFromPathInfo | null;
|
|
547
|
+
/**
|
|
548
|
+
* Get the canonical path for a mapped technical Shopware URL.
|
|
549
|
+
*
|
|
550
|
+
* Returns `null` for SEO URLs, synthetic technical fallbacks without an SEO
|
|
551
|
+
* mapping, and invalid mappings that would redirect to another technical URL.
|
|
552
|
+
*/
|
|
553
|
+
declare function getCanonicalPathForTechnicalPath(path: string, seoUrl?: object | null): string | null;
|
|
542
554
|
|
|
543
555
|
/**
|
|
544
556
|
* Get translated property from the given object.
|
|
@@ -769,5 +781,5 @@ declare function canUseQuoteActions<T extends {
|
|
|
769
781
|
};
|
|
770
782
|
}>(quote: T): boolean;
|
|
771
783
|
|
|
772
|
-
export { buildCdnImageUrl, buildUrlPrefix, canUseQuoteActions, downloadFile, encodeUrlPath, generateCdnSrcSet, getBackgroundImageUrl, getBiggestThumbnailUrl, getCategoryBreadcrumbs, getCategoryImageUrl, getCategoryRoute, getCategoryUrl, getCmsBreadcrumbs, getCmsEntityObject, getCmsLayoutConfiguration, getCmsTranslate, getFormattedPrice, getLanguageName, getListingFilters, getMainImageUrl, getMedia, getPaymentMethodIcon, getProductCalculatedListingPrice, getProductFreeShipping, getProductFromPrice, getProductListingFromCmsPage, getProductManufacturerName, getProductName, getProductRatingAverage, getProductReviews, getProductRoute, getProductTierPrices, getProductUrl, getRouteFromPathInfo, getShippingMethodDeliveryTime, getShippingMethodIcon, getSmallestThumbnailUrl, getSrcSetForMedia, getTranslatedProperty, helpersCssClasses, isCategory, isLandingPage, isMaintenanceMode, isProduct, isProductOnSale, isProductTopSeller, isTechnicalPath, normalizePath, relativeUrlSlash, urlIsAbsolute };
|
|
784
|
+
export { buildCdnImageUrl, buildUrlPrefix, canUseQuoteActions, downloadFile, encodeUrlPath, generateCdnSrcSet, getBackgroundImageUrl, getBiggestThumbnailUrl, getCanonicalPathForTechnicalPath, getCategoryBreadcrumbs, getCategoryImageUrl, getCategoryRoute, getCategoryUrl, getCmsBreadcrumbs, getCmsEntityObject, getCmsLayoutConfiguration, getCmsTranslate, getFormattedPrice, getLanguageName, getListingFilters, getMainImageUrl, getMedia, getPaymentMethodIcon, getProductCalculatedListingPrice, getProductFreeShipping, getProductFromPrice, getProductListingFromCmsPage, getProductManufacturerName, getProductName, getProductRatingAverage, getProductReviews, getProductRoute, getProductTierPrices, getProductUrl, getRouteFromPathInfo, getShippingMethodDeliveryTime, getShippingMethodIcon, getSmallestThumbnailUrl, getSrcSetForMedia, getTranslatedProperty, helpersCssClasses, isCategory, isLandingPage, isMaintenanceMode, isProduct, isProductOnSale, isProductTopSeller, isTechnicalPath, isTechnicalUrl, normalizePath, relativeUrlSlash, urlIsAbsolute };
|
|
773
785
|
export type { BackgroundImageOptions, HelpersCssClasses, LayoutConfiguration, RouteInfoFromPathInfo, RouteNameFromPathInfo, TierPrice, UiMediaGalleryItem, UiMediaGalleryItemUrl, UiProductOption, UiProductProperty, UiProductReview, UrlRouteOutput };
|
package/dist/index.mjs
CHANGED
|
@@ -366,6 +366,13 @@ function isTechnicalPath(path) {
|
|
|
366
366
|
(prefix) => normalizedPath.startsWith(prefix)
|
|
367
367
|
);
|
|
368
368
|
}
|
|
369
|
+
function isTechnicalUrl(url, baseUrl = "http://localhost") {
|
|
370
|
+
try {
|
|
371
|
+
return isTechnicalPath(new URL(url, baseUrl).pathname);
|
|
372
|
+
} catch {
|
|
373
|
+
return false;
|
|
374
|
+
}
|
|
375
|
+
}
|
|
369
376
|
function getRouteFromPathInfo(path) {
|
|
370
377
|
const normalizedPath = normalizePath(path);
|
|
371
378
|
for (const [prefix, routeName] of Object.entries(TECHNICAL_ROUTE_MAP)) {
|
|
@@ -379,6 +386,15 @@ function getRouteFromPathInfo(path) {
|
|
|
379
386
|
}
|
|
380
387
|
return null;
|
|
381
388
|
}
|
|
389
|
+
function getCanonicalPathForTechnicalPath(path, seoUrl) {
|
|
390
|
+
if (!isTechnicalPath(path) || !seoUrl || !("seoPathInfo" in seoUrl) || typeof seoUrl.seoPathInfo !== "string") {
|
|
391
|
+
return null;
|
|
392
|
+
}
|
|
393
|
+
const seoPathInfo = seoUrl.seoPathInfo.replace(/^\/+/, "");
|
|
394
|
+
const canonicalPath = seoPathInfo ? normalizePath(`/${seoPathInfo}`) : "/";
|
|
395
|
+
if (isTechnicalPath(canonicalPath)) return null;
|
|
396
|
+
return canonicalPath;
|
|
397
|
+
}
|
|
382
398
|
|
|
383
399
|
const getFilter = (code, aggregation) => {
|
|
384
400
|
return {
|
|
@@ -564,4 +580,4 @@ function canUseQuoteActions(quote) {
|
|
|
564
580
|
return ["replied"].includes(quote.stateMachineState?.technicalName ?? "");
|
|
565
581
|
}
|
|
566
582
|
|
|
567
|
-
export { buildCdnImageUrl, buildUrlPrefix, canUseQuoteActions, downloadFile, encodeUrlPath, generateCdnSrcSet, getBackgroundImageUrl, getBiggestThumbnailUrl, getCategoryBreadcrumbs, getCategoryImageUrl, getCategoryRoute, getCategoryUrl, getCmsBreadcrumbs, getCmsEntityObject, getCmsLayoutConfiguration, getCmsTranslate, getFormattedPrice, getLanguageName, getListingFilters, getMainImageUrl, getMedia, getPaymentMethodIcon, getProductCalculatedListingPrice, getProductFreeShipping, getProductFromPrice, getProductListingFromCmsPage, getProductManufacturerName, getProductName, getProductRatingAverage, getProductReviews, getProductRoute, getProductTierPrices, getProductUrl, getRouteFromPathInfo, getShippingMethodDeliveryTime, getShippingMethodIcon, getSmallestThumbnailUrl, getSrcSetForMedia, getTranslatedProperty, helpersCssClasses, isCategory, isLandingPage, isMaintenanceMode, isProduct, isProductOnSale, isProductTopSeller, isTechnicalPath, normalizePath, relativeUrlSlash, urlIsAbsolute };
|
|
583
|
+
export { buildCdnImageUrl, buildUrlPrefix, canUseQuoteActions, downloadFile, encodeUrlPath, generateCdnSrcSet, getBackgroundImageUrl, getBiggestThumbnailUrl, getCanonicalPathForTechnicalPath, getCategoryBreadcrumbs, getCategoryImageUrl, getCategoryRoute, getCategoryUrl, getCmsBreadcrumbs, getCmsEntityObject, getCmsLayoutConfiguration, getCmsTranslate, getFormattedPrice, getLanguageName, getListingFilters, getMainImageUrl, getMedia, getPaymentMethodIcon, getProductCalculatedListingPrice, getProductFreeShipping, getProductFromPrice, getProductListingFromCmsPage, getProductManufacturerName, getProductName, getProductRatingAverage, getProductReviews, getProductRoute, getProductTierPrices, getProductUrl, getRouteFromPathInfo, getShippingMethodDeliveryTime, getShippingMethodIcon, getSmallestThumbnailUrl, getSrcSetForMedia, getTranslatedProperty, helpersCssClasses, isCategory, isLandingPage, isMaintenanceMode, isProduct, isProductOnSale, isProductTopSeller, isTechnicalPath, isTechnicalUrl, normalizePath, relativeUrlSlash, urlIsAbsolute };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shopware/helpers",
|
|
3
|
-
"version": "1.7.
|
|
3
|
+
"version": "1.7.2",
|
|
4
4
|
"description": "Shopware helpers for accessing API data",
|
|
5
5
|
"author": "Shopware",
|
|
6
6
|
"type": "module",
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
"type": "git",
|
|
9
9
|
"url": "git+https://github.com/shopware/frontends.git"
|
|
10
10
|
},
|
|
11
|
-
"homepage": "https://
|
|
11
|
+
"homepage": "https://developer.shopware.com/frontends/packages/helpers.html",
|
|
12
12
|
"keywords": [
|
|
13
13
|
"shopware",
|
|
14
14
|
"api",
|
|
@@ -32,20 +32,19 @@
|
|
|
32
32
|
}
|
|
33
33
|
},
|
|
34
34
|
"devDependencies": {
|
|
35
|
-
"@biomejs/biome": "1.8.3",
|
|
36
35
|
"@typescript/native-preview": "7.0.0-dev.20260205.1",
|
|
37
|
-
"@vitest/coverage-v8": "4.1.
|
|
38
|
-
"happy-dom": "20.
|
|
39
|
-
"unbuild": "
|
|
40
|
-
"vitest": "4.1.
|
|
36
|
+
"@vitest/coverage-v8": "4.1.10",
|
|
37
|
+
"happy-dom": "20.10.6",
|
|
38
|
+
"unbuild": "3.6.1",
|
|
39
|
+
"vitest": "4.1.10",
|
|
41
40
|
"tsconfig": "0.0.0"
|
|
42
41
|
},
|
|
43
42
|
"scripts": {
|
|
44
43
|
"build": "unbuild && pnpm build:types",
|
|
45
44
|
"build:types": "tsgo ./src/*.ts --ignoreConfig --declaration --allowJs --emitDeclarationOnly --outDir ./temp --skipLibCheck",
|
|
46
45
|
"dev": "unbuild --stub",
|
|
47
|
-
"lint": "
|
|
48
|
-
"lint:fix": "
|
|
46
|
+
"lint": "oxlint . && oxfmt --check .",
|
|
47
|
+
"lint:fix": "oxlint --fix . && oxfmt --write . && pnpm run typecheck",
|
|
49
48
|
"typecheck": "tsgo --noEmit",
|
|
50
49
|
"test": "vitest run",
|
|
51
50
|
"test:watch": "vitest"
|