@nosto/search-js 1.1.1 → 1.2.0
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 +6 -2
- package/dist/currencies/priceDecorator.d.ts +1 -0
- package/dist/search/types.d.ts +1 -1
- package/dist/thumbnails/shopifyThumbnailDecorator.d.ts +19 -3
- package/dist/thumbnails/thumbnailDecorator.d.ts +10 -0
- package/dist/thumbnails.cjs.js +1 -1
- package/dist/thumbnails.d.ts +1 -1
- package/dist/thumbnails.es.js +79 -54
- package/package.json +7 -7
package/README.md
CHANGED
|
@@ -32,6 +32,7 @@ The main export of this library is the `search` function. It is compatible with
|
|
|
32
32
|
```ts
|
|
33
33
|
import { search } from "@nosto/search-js"
|
|
34
34
|
import { priceDecorator } from "@nosto/search-js/currencies"
|
|
35
|
+
import { thumbnailDecorator } from "@nosto/search-js/thumbnails"
|
|
35
36
|
|
|
36
37
|
const response = await search({
|
|
37
38
|
query: 'my search',
|
|
@@ -41,13 +42,16 @@ const response = await search({
|
|
|
41
42
|
"name",
|
|
42
43
|
"price",
|
|
43
44
|
"listPrice",
|
|
44
|
-
"priceCurrencyCode"
|
|
45
|
+
"priceCurrencyCode",
|
|
46
|
+
"imageUrl",
|
|
47
|
+
"imageHash"
|
|
45
48
|
]
|
|
46
49
|
}
|
|
47
50
|
}, {
|
|
48
51
|
track: 'serp',
|
|
49
52
|
hitDecorators: [
|
|
50
|
-
priceDecorator()
|
|
53
|
+
priceDecorator(),
|
|
54
|
+
thumbnailDecorator()
|
|
51
55
|
]
|
|
52
56
|
})
|
|
53
57
|
|
|
@@ -10,5 +10,6 @@ export type Result = SearchProduct & FormattedPrices & {
|
|
|
10
10
|
/**
|
|
11
11
|
* Exposes currency formatting logic as a SearchProduct decorator
|
|
12
12
|
* Sets priceText and listPriceText fields on product and SKU level
|
|
13
|
+
* Requires price, listPrice and priceCurrencyCode fields to be present
|
|
13
14
|
*/
|
|
14
15
|
export declare function priceDecorator(config?: Partial<CurrencyConfig>): (hit: SearchProduct) => Result;
|
package/dist/search/types.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { SearchOptions, SearchProduct, SearchResult } from "@nosto/nosto-js/client";
|
|
2
|
-
export type Options<HD extends HitDecorator[]> = SearchOptions & {
|
|
2
|
+
export type Options<HD extends HitDecorator[] = HitDecorator[]> = SearchOptions & {
|
|
3
3
|
/**
|
|
4
4
|
* Hit decorators to apply to the search results.
|
|
5
5
|
*/
|
|
@@ -1,10 +1,26 @@
|
|
|
1
1
|
import { SearchProduct } from "@nosto/nosto-js/client";
|
|
2
2
|
import { ShopifySize } from "./types";
|
|
3
|
+
type NostoSize = keyof typeof sizeMappings;
|
|
3
4
|
export type Config = {
|
|
4
|
-
size: ShopifySize;
|
|
5
|
+
size: NostoSize | "orig" | ShopifySize;
|
|
6
|
+
fallback?: (hit: SearchProduct) => SearchProduct;
|
|
5
7
|
};
|
|
8
|
+
declare const sizeMappings: {
|
|
9
|
+
"1": string;
|
|
10
|
+
"2": string;
|
|
11
|
+
"3": string;
|
|
12
|
+
"4": string;
|
|
13
|
+
"5": string;
|
|
14
|
+
"6": string;
|
|
15
|
+
"7": string;
|
|
16
|
+
"8": string;
|
|
17
|
+
"9": string;
|
|
18
|
+
};
|
|
19
|
+
export declare function isSupportedNostoSize(size: string): size is NostoSize;
|
|
6
20
|
/**
|
|
7
|
-
* Replaces full size images with specified Shopify thumbnail size.
|
|
21
|
+
* Replaces full size images with specified Nosto or Shopify thumbnail size.
|
|
8
22
|
* This decorator will only affect the image URLs from Shopify CDN.
|
|
23
|
+
* Supports the Nosto size codes "1"-"9" and additionally Shopify specific sizes.
|
|
9
24
|
*/
|
|
10
|
-
export declare function shopifyThumbnailDecorator({ size }: Config): (hit: SearchProduct) => SearchProduct;
|
|
25
|
+
export declare function shopifyThumbnailDecorator({ size, fallback }: Config): (hit: SearchProduct) => SearchProduct;
|
|
26
|
+
export {};
|
|
@@ -5,5 +5,15 @@ export type Config = {
|
|
|
5
5
|
};
|
|
6
6
|
/**
|
|
7
7
|
* Replaces full size images with thumbnail sized versions.
|
|
8
|
+
* Performs the following replacements based on availability of hash fields:
|
|
9
|
+
* - imageHash -> imageUrl
|
|
10
|
+
* - thumbHash -> thumbUrl
|
|
11
|
+
* - alternateImageHashes -> alternateImageUrls
|
|
12
|
+
* - sku.imageHash -> sku.imageUrl
|
|
13
|
+
*/
|
|
14
|
+
export declare function nostoThumbnailDecorator({ size }: Config): (hit: SearchProduct) => SearchProduct;
|
|
15
|
+
/**
|
|
16
|
+
* Replaces full size images with thumbnail sized versions.
|
|
17
|
+
* Uses `shopifyThumbnailDecorator` and `nostoThumbnailDecorator` based on the platform.
|
|
8
18
|
*/
|
|
9
19
|
export declare function thumbnailDecorator({ size }: Config): (hit: SearchProduct) => SearchProduct;
|
package/dist/thumbnails.cjs.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const p=require("./index.es-D_7T9vdv.cjs");function s({size:e,productId:a,hash:i}){const c=p.i();if(!c)throw new Error("Client script settings are not yet available");return`https://${c.thumbnailHost}/${c.account}/${e}/${a}/${i}/A`}const g=/cdn\.shopify\.com/,l={1:"170x170_crop_center",2:"100x100_crop_center",3:"90x70_crop_center",4:"50x50_crop_center",5:"30x30_crop_center",6:"100x140_crop_center",7:"200x200_crop_center",8:"400x400",9:"750x750"};function d(e){return e in l}function f({size:e,fallback:a=i=>i}){if(e==="orig")return a;const i=l[e]||e;function c(n){return n?new URL(n).hostname.match(g):!1}function u(n){return n?c(n)?n.replace(/(\.jpg|\.png|\.jpeg|\.gif|\.webp)/,`_${i}$1`):n:""}function r(n){if(n)return n.map(o=>({...o,imageUrl:u(o.imageUrl)}))}function t(n){if(n)return n.map(o=>u(o))}return function(o){return c(o.imageUrl)?{...o,imageUrl:u(o.imageUrl),thumbUrl:u(o.thumbUrl),skus:r(o.skus),alternateImageUrls:t(o.alternateImageUrls)}:a(o)}}function U(){var e;return(e=window.Nosto)==null?void 0:e.shopifyScript}function m({size:e}){function a(u,r){if(r)return s({size:e,productId:u,hash:r})}function i(u,r){if(r)return r.map(t=>({...t,imageUrl:a(u,t.imageHash)??t.imageUrl}))}function c(u,r,t){if(!t)return r;if(r)return t.map(n=>s({size:e,productId:u,hash:n}))}return function(r){const t=r.productId;return t?{...r,imageUrl:a(t,r.imageHash)??r.imageUrl,thumbUrl:a(t,r.thumbHash)??r.thumbUrl,skus:i(t,r.skus),alternateImageUrls:c(t,r.alternateImageUrls,r.alternateImageHashes)}:r}}function b({size:e}){const a=m({size:e});return U()&&d(e)?f({size:e,fallback:a}):a}exports.generateThumbnailUrl=s;exports.nostoThumbnailDecorator=m;exports.shopifyThumbnailDecorator=f;exports.thumbnailDecorator=b;
|
package/dist/thumbnails.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/** @module thumbnails */
|
|
2
2
|
export { generateThumbnailUrl, type Props } from "./thumbnails/generateThumbnailUrl";
|
|
3
|
-
export { thumbnailDecorator, type Config } from "./thumbnails/thumbnailDecorator";
|
|
3
|
+
export { thumbnailDecorator, nostoThumbnailDecorator, type Config } from "./thumbnails/thumbnailDecorator";
|
|
4
4
|
export { shopifyThumbnailDecorator, type Config as ShopifyConfig } from "./thumbnails/shopifyThumbnailDecorator";
|
|
5
5
|
export type { ThumbnailSize, ShopifySize } from "./thumbnails/types";
|
package/dist/thumbnails.es.js
CHANGED
|
@@ -1,80 +1,105 @@
|
|
|
1
1
|
import { i as m } from "./index.es-Bcd5IQh9.js";
|
|
2
|
-
function
|
|
3
|
-
const
|
|
4
|
-
if (!
|
|
2
|
+
function f({ size: e, productId: u, hash: i }) {
|
|
3
|
+
const c = m();
|
|
4
|
+
if (!c)
|
|
5
5
|
throw new Error("Client script settings are not yet available");
|
|
6
|
-
return `https://${
|
|
6
|
+
return `https://${c.thumbnailHost}/${c.account}/${e}/${u}/${i}/A`;
|
|
7
7
|
}
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
const p = /cdn\.shopify\.com/, s = {
|
|
9
|
+
1: "170x170_crop_center",
|
|
10
|
+
2: "100x100_crop_center",
|
|
11
|
+
3: "90x70_crop_center",
|
|
12
|
+
4: "50x50_crop_center",
|
|
13
|
+
5: "30x30_crop_center",
|
|
14
|
+
6: "100x140_crop_center",
|
|
15
|
+
7: "200x200_crop_center",
|
|
16
|
+
8: "400x400",
|
|
17
|
+
9: "750x750"
|
|
18
|
+
};
|
|
19
|
+
function l(e) {
|
|
20
|
+
return e in s;
|
|
21
|
+
}
|
|
22
|
+
function g({ size: e, fallback: u = (i) => i }) {
|
|
23
|
+
if (e === "orig")
|
|
24
|
+
return u;
|
|
25
|
+
const i = s[e] || e;
|
|
26
|
+
function c(n) {
|
|
27
|
+
return n ? new URL(n).hostname.match(p) : !1;
|
|
28
|
+
}
|
|
29
|
+
function a(n) {
|
|
30
|
+
return n ? c(n) ? n.replace(/(\.jpg|\.png|\.jpeg|\.gif|\.webp)/, `_${i}$1`) : n : "";
|
|
31
|
+
}
|
|
32
|
+
function r(n) {
|
|
33
|
+
if (n)
|
|
34
|
+
return n.map((o) => ({
|
|
35
|
+
...o,
|
|
36
|
+
imageUrl: a(o.imageUrl)
|
|
37
|
+
}));
|
|
38
|
+
}
|
|
39
|
+
function t(n) {
|
|
40
|
+
if (n)
|
|
41
|
+
return n.map((o) => a(o));
|
|
42
|
+
}
|
|
43
|
+
return function(o) {
|
|
44
|
+
return c(o.imageUrl) ? {
|
|
45
|
+
...o,
|
|
46
|
+
imageUrl: a(o.imageUrl),
|
|
47
|
+
thumbUrl: a(o.thumbUrl),
|
|
48
|
+
skus: r(o.skus),
|
|
49
|
+
alternateImageUrls: t(o.alternateImageUrls)
|
|
50
|
+
} : u(o);
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
function U() {
|
|
54
|
+
var e;
|
|
55
|
+
return (e = window.Nosto) == null ? void 0 : e.shopifyScript;
|
|
56
|
+
}
|
|
57
|
+
function d({ size: e }) {
|
|
58
|
+
function u(a, r) {
|
|
10
59
|
if (r)
|
|
11
|
-
return
|
|
12
|
-
size:
|
|
60
|
+
return f({
|
|
61
|
+
size: e,
|
|
13
62
|
productId: a,
|
|
14
63
|
hash: r
|
|
15
64
|
});
|
|
16
65
|
}
|
|
17
|
-
function
|
|
66
|
+
function i(a, r) {
|
|
18
67
|
if (r)
|
|
19
|
-
return r.map((
|
|
20
|
-
...
|
|
21
|
-
imageUrl:
|
|
68
|
+
return r.map((t) => ({
|
|
69
|
+
...t,
|
|
70
|
+
imageUrl: u(a, t.imageHash) ?? t.imageUrl
|
|
22
71
|
}));
|
|
23
72
|
}
|
|
24
|
-
function
|
|
25
|
-
if (!
|
|
73
|
+
function c(a, r, t) {
|
|
74
|
+
if (!t)
|
|
26
75
|
return r;
|
|
27
76
|
if (r)
|
|
28
|
-
return
|
|
29
|
-
(
|
|
30
|
-
size:
|
|
77
|
+
return t.map(
|
|
78
|
+
(n) => f({
|
|
79
|
+
size: e,
|
|
31
80
|
productId: a,
|
|
32
|
-
hash:
|
|
81
|
+
hash: n
|
|
33
82
|
})
|
|
34
83
|
);
|
|
35
84
|
}
|
|
36
85
|
return function(r) {
|
|
37
|
-
const
|
|
38
|
-
return
|
|
86
|
+
const t = r.productId;
|
|
87
|
+
return t ? {
|
|
39
88
|
...r,
|
|
40
|
-
imageUrl:
|
|
41
|
-
thumbUrl:
|
|
42
|
-
skus: t
|
|
43
|
-
alternateImageUrls:
|
|
89
|
+
imageUrl: u(t, r.imageHash) ?? r.imageUrl,
|
|
90
|
+
thumbUrl: u(t, r.thumbHash) ?? r.thumbUrl,
|
|
91
|
+
skus: i(t, r.skus),
|
|
92
|
+
alternateImageUrls: c(t, r.alternateImageUrls, r.alternateImageHashes)
|
|
44
93
|
} : r;
|
|
45
94
|
};
|
|
46
95
|
}
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
return r ? new URL(r).hostname.match(l) : !1;
|
|
51
|
-
}
|
|
52
|
-
function t(r) {
|
|
53
|
-
return r ? n(r) ? r.replace(/(\.jpg|\.png|\.jpeg|\.gif|\.webp)/, `_${o}$1`) : r : "";
|
|
54
|
-
}
|
|
55
|
-
function u(r) {
|
|
56
|
-
if (r)
|
|
57
|
-
return r.map((e) => ({
|
|
58
|
-
...e,
|
|
59
|
-
imageUrl: t(e.imageUrl)
|
|
60
|
-
}));
|
|
61
|
-
}
|
|
62
|
-
function a(r) {
|
|
63
|
-
if (r)
|
|
64
|
-
return r.map((e) => t(e));
|
|
65
|
-
}
|
|
66
|
-
return function(e) {
|
|
67
|
-
return n(e.imageUrl) ? {
|
|
68
|
-
...e,
|
|
69
|
-
imageUrl: t(e.imageUrl),
|
|
70
|
-
thumbUrl: t(e.thumbUrl),
|
|
71
|
-
skus: u(e.skus),
|
|
72
|
-
alternateImageUrls: a(e.alternateImageUrls)
|
|
73
|
-
} : e;
|
|
74
|
-
};
|
|
96
|
+
function b({ size: e }) {
|
|
97
|
+
const u = d({ size: e });
|
|
98
|
+
return U() && l(e) ? g({ size: e, fallback: u }) : u;
|
|
75
99
|
}
|
|
76
100
|
export {
|
|
77
|
-
|
|
101
|
+
f as generateThumbnailUrl,
|
|
102
|
+
d as nostoThumbnailDecorator,
|
|
78
103
|
g as shopifyThumbnailDecorator,
|
|
79
|
-
|
|
104
|
+
b as thumbnailDecorator
|
|
80
105
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nosto/search-js",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"license": "ISC",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"files": [
|
|
@@ -45,18 +45,18 @@
|
|
|
45
45
|
"@nosto/nosto-js": "^1.4.4",
|
|
46
46
|
"@testing-library/dom": "^10.4.0",
|
|
47
47
|
"@types/eslint-config-prettier": "^6.11.3",
|
|
48
|
-
"@types/node": "^22.13.
|
|
48
|
+
"@types/node": "^22.13.1",
|
|
49
49
|
"copyfiles": "^2.4.1",
|
|
50
|
-
"eslint": "^9.
|
|
50
|
+
"eslint": "^9.20.0",
|
|
51
51
|
"eslint-config-prettier": "^10.0.1",
|
|
52
52
|
"eslint-plugin-barrel-files": "^2.1.0",
|
|
53
53
|
"eslint-plugin-prettier": "^5.2.3",
|
|
54
54
|
"jsdom": "^26.0.0",
|
|
55
|
-
"prettier": "^3.
|
|
56
|
-
"typedoc": "^0.27.
|
|
55
|
+
"prettier": "^3.5.0",
|
|
56
|
+
"typedoc": "^0.27.7",
|
|
57
57
|
"typescript": "^5.7.3",
|
|
58
|
-
"typescript-eslint": "^8.
|
|
59
|
-
"vite": "^6.0
|
|
58
|
+
"typescript-eslint": "^8.24.0",
|
|
59
|
+
"vite": "^6.1.0",
|
|
60
60
|
"vitest": "^3.0.5"
|
|
61
61
|
},
|
|
62
62
|
"publishConfig": {
|