@shopware/helpers 1.7.0 → 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 -27
- package/dist/index.d.mts +28 -1
- package/dist/index.d.ts +28 -1
- package/dist/index.mjs +45 -1
- package/package.json +9 -10
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,12 +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.
|
|
129
|
-
|
|
130
|
-
### Minor Changes
|
|
131
|
-
|
|
132
|
-
- [#2287](https://github.com/shopware/frontends/pull/2287) [`c9bde38`](https://github.com/shopware/frontends/commit/c9bde38d497d5c6c2fbd97700a362eb44ce8881f) Thanks [@mkucmus](https://github.com/mkucmus)! - Add generateCdnSrcSet and buildCdnImageUrl helpers for synthetic responsive image srcset generation via CDN query params
|
|
128
|
+
### Latest changes: 1.7.2
|
|
133
129
|
|
|
134
130
|
### Patch Changes
|
|
135
131
|
|
|
136
|
-
- [#
|
|
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
|
@@ -526,6 +526,32 @@ declare function isLandingPage<T extends {
|
|
|
526
526
|
apiAlias: string;
|
|
527
527
|
}>(entity: T | LandingPage): entity is LandingPage;
|
|
528
528
|
|
|
529
|
+
declare const TECHNICAL_ROUTE_MAP: {
|
|
530
|
+
readonly "/navigation/": "frontend.navigation.page";
|
|
531
|
+
readonly "/detail/": "frontend.detail.page";
|
|
532
|
+
readonly "/landingPage/": "frontend.landing.page";
|
|
533
|
+
};
|
|
534
|
+
type RouteNameFromPathInfo = (typeof TECHNICAL_ROUTE_MAP)[keyof typeof TECHNICAL_ROUTE_MAP];
|
|
535
|
+
type RouteInfoFromPathInfo = {
|
|
536
|
+
routeName: RouteNameFromPathInfo;
|
|
537
|
+
foreignKey: string;
|
|
538
|
+
};
|
|
539
|
+
declare function normalizePath(path: string): string;
|
|
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;
|
|
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;
|
|
554
|
+
|
|
529
555
|
/**
|
|
530
556
|
* Get translated property from the given object.
|
|
531
557
|
*
|
|
@@ -755,4 +781,5 @@ declare function canUseQuoteActions<T extends {
|
|
|
755
781
|
};
|
|
756
782
|
}>(quote: T): boolean;
|
|
757
783
|
|
|
758
|
-
export {
|
|
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 };
|
|
785
|
+
export type { BackgroundImageOptions, HelpersCssClasses, LayoutConfiguration, RouteInfoFromPathInfo, RouteNameFromPathInfo, TierPrice, UiMediaGalleryItem, UiMediaGalleryItemUrl, UiProductOption, UiProductProperty, UiProductReview, UrlRouteOutput };
|
package/dist/index.d.ts
CHANGED
|
@@ -526,6 +526,32 @@ declare function isLandingPage<T extends {
|
|
|
526
526
|
apiAlias: string;
|
|
527
527
|
}>(entity: T | LandingPage): entity is LandingPage;
|
|
528
528
|
|
|
529
|
+
declare const TECHNICAL_ROUTE_MAP: {
|
|
530
|
+
readonly "/navigation/": "frontend.navigation.page";
|
|
531
|
+
readonly "/detail/": "frontend.detail.page";
|
|
532
|
+
readonly "/landingPage/": "frontend.landing.page";
|
|
533
|
+
};
|
|
534
|
+
type RouteNameFromPathInfo = (typeof TECHNICAL_ROUTE_MAP)[keyof typeof TECHNICAL_ROUTE_MAP];
|
|
535
|
+
type RouteInfoFromPathInfo = {
|
|
536
|
+
routeName: RouteNameFromPathInfo;
|
|
537
|
+
foreignKey: string;
|
|
538
|
+
};
|
|
539
|
+
declare function normalizePath(path: string): string;
|
|
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;
|
|
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;
|
|
554
|
+
|
|
529
555
|
/**
|
|
530
556
|
* Get translated property from the given object.
|
|
531
557
|
*
|
|
@@ -755,4 +781,5 @@ declare function canUseQuoteActions<T extends {
|
|
|
755
781
|
};
|
|
756
782
|
}>(quote: T): boolean;
|
|
757
783
|
|
|
758
|
-
export {
|
|
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 };
|
|
785
|
+
export type { BackgroundImageOptions, HelpersCssClasses, LayoutConfiguration, RouteInfoFromPathInfo, RouteNameFromPathInfo, TierPrice, UiMediaGalleryItem, UiMediaGalleryItemUrl, UiProductOption, UiProductProperty, UiProductReview, UrlRouteOutput };
|
package/dist/index.mjs
CHANGED
|
@@ -352,6 +352,50 @@ function isLandingPage(entity) {
|
|
|
352
352
|
return entity.apiAlias === "landing_page";
|
|
353
353
|
}
|
|
354
354
|
|
|
355
|
+
const TECHNICAL_ROUTE_MAP = {
|
|
356
|
+
"/navigation/": "frontend.navigation.page",
|
|
357
|
+
"/detail/": "frontend.detail.page",
|
|
358
|
+
"/landingPage/": "frontend.landing.page"
|
|
359
|
+
};
|
|
360
|
+
function normalizePath(path) {
|
|
361
|
+
return path.endsWith("/") && path !== "/" ? path.slice(0, -1) : path;
|
|
362
|
+
}
|
|
363
|
+
function isTechnicalPath(path) {
|
|
364
|
+
const normalizedPath = normalizePath(path);
|
|
365
|
+
return Object.keys(TECHNICAL_ROUTE_MAP).some(
|
|
366
|
+
(prefix) => normalizedPath.startsWith(prefix)
|
|
367
|
+
);
|
|
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
|
+
}
|
|
376
|
+
function getRouteFromPathInfo(path) {
|
|
377
|
+
const normalizedPath = normalizePath(path);
|
|
378
|
+
for (const [prefix, routeName] of Object.entries(TECHNICAL_ROUTE_MAP)) {
|
|
379
|
+
if (!normalizedPath.startsWith(prefix)) continue;
|
|
380
|
+
const foreignKey = normalizedPath.slice(prefix.length);
|
|
381
|
+
if (!foreignKey || foreignKey.includes("/")) return null;
|
|
382
|
+
return {
|
|
383
|
+
routeName,
|
|
384
|
+
foreignKey
|
|
385
|
+
};
|
|
386
|
+
}
|
|
387
|
+
return null;
|
|
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
|
+
}
|
|
398
|
+
|
|
355
399
|
const getFilter = (code, aggregation) => {
|
|
356
400
|
return {
|
|
357
401
|
label: getTranslatedProperty(aggregation, "name") || code,
|
|
@@ -536,4 +580,4 @@ function canUseQuoteActions(quote) {
|
|
|
536
580
|
return ["replied"].includes(quote.stateMachineState?.technicalName ?? "");
|
|
537
581
|
}
|
|
538
582
|
|
|
539
|
-
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, getShippingMethodDeliveryTime, getShippingMethodIcon, getSmallestThumbnailUrl, getSrcSetForMedia, getTranslatedProperty, helpersCssClasses, isCategory, isLandingPage, isMaintenanceMode, isProduct, isProductOnSale, isProductTopSeller, 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
|
-
"@
|
|
36
|
-
"@
|
|
37
|
-
"
|
|
38
|
-
"
|
|
39
|
-
"
|
|
40
|
-
"vitest": "4.0.18",
|
|
35
|
+
"@typescript/native-preview": "7.0.0-dev.20260205.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"
|