@nosto/search-js 1.2.0 → 1.3.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 +1 -1
- package/dist/core/core.cjs.js +1 -0
- package/dist/core/core.es.js +54 -0
- package/dist/core/index.d.ts +3 -0
- package/dist/{search → core/src}/searchWithRetries.d.ts +1 -1
- package/dist/currencies/currencies.cjs.js +1 -0
- package/dist/currencies/currencies.es.js +79 -0
- package/dist/currencies/index.d.ts +3 -0
- package/dist/preact/index.d.ts +2 -0
- package/dist/preact/preact.cjs.js +1 -0
- package/dist/preact/preact.es.js +28 -0
- package/dist/preact/src/hooks/usePersonalization.d.ts +41 -0
- package/dist/thumbnails/index.d.ts +6 -0
- package/dist/thumbnails/{generateThumbnailUrl.d.ts → src/generateThumbnailUrl.d.ts} +4 -4
- package/dist/thumbnails/{thumbnailDecorator.d.ts → src/nostoThumbnailDecorator.d.ts} +2 -7
- package/dist/thumbnails/{shopifyThumbnailDecorator.d.ts → src/shopifyThumbnailDecorator.d.ts} +3 -16
- package/dist/thumbnails/src/thumbnailDecorator.d.ts +9 -0
- package/dist/thumbnails/{types.d.ts → src/types.d.ts} +17 -1
- package/dist/thumbnails/thumbnails.cjs.js +1 -0
- package/dist/thumbnails/thumbnails.es.js +120 -0
- package/package.json +35 -27
- package/dist/currencies.cjs.js +0 -1
- package/dist/currencies.d.ts +0 -3
- package/dist/currencies.es.js +0 -68
- package/dist/index.es-Bcd5IQh9.js +0 -20
- package/dist/index.es-D_7T9vdv.cjs +0 -1
- package/dist/search.cjs.js +0 -1
- package/dist/search.d.ts +0 -3
- package/dist/search.es.js +0 -43
- package/dist/thumbnails.cjs.js +0 -1
- package/dist/thumbnails.d.ts +0 -5
- package/dist/thumbnails.es.js +0 -105
- /package/dist/{search → core/src}/applyDecorators.d.ts +0 -0
- /package/dist/{search → core/src}/search.d.ts +0 -0
- /package/dist/{search → core/src}/types.d.ts +0 -0
- /package/dist/{search → core/src}/utils/delay.d.ts +0 -0
- /package/dist/currencies/{getCurrencyFormatting.d.ts → src/getCurrencyFormatting.d.ts} +0 -0
- /package/dist/currencies/{priceDecorator.d.ts → src/priceDecorator.d.ts} +0 -0
package/README.md
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function s(){window.nostojs=window.nostojs??function(t){(window.nostojs.q=window.nostojs.q??[]).push(t)}}async function c(t){return window.nostojs(t)}typeof window<"u"&&(s(),c(t=>{t.internal.getSettings()}));typeof window<"u"&&s();function a(t,n){if(!t.products||!(n!=null&&n.length))return t;const e=o=>n.reduce((r,i)=>i(r),o);return{...t,products:{...t.products,hits:t.products.hits.map(e)}}}function w(t){return new Promise(n=>setTimeout(n,t))}async function f(t,n,e){const{maxRetries:o=0,retryInterval:r=1e3}=e;let i=0;for(;;)try{return await t.search(n,e)}catch(u){if(!l(u))throw console.info("Skipping retry logic for",u),u;if(i>=o)throw u;i++,await w(r)}}function l(t){return!t||typeof t!="object"?!1:!("status"in t)||h(t.status)}function h(t){return typeof t=="number"&&(t<400||t>=500)}async function y(t,n={}){const{hitDecorators:e,...o}=n,r=await new Promise(c),i=await f(r,t,o);return a(i,e)}exports.search=y;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
function s() {
|
|
2
|
+
window.nostojs = window.nostojs ?? function(t) {
|
|
3
|
+
(window.nostojs.q = window.nostojs.q ?? []).push(t);
|
|
4
|
+
};
|
|
5
|
+
}
|
|
6
|
+
async function c(t) {
|
|
7
|
+
return window.nostojs(t);
|
|
8
|
+
}
|
|
9
|
+
typeof window < "u" && (s(), c((t) => {
|
|
10
|
+
t.internal.getSettings();
|
|
11
|
+
}));
|
|
12
|
+
typeof window < "u" && s();
|
|
13
|
+
function a(t, n) {
|
|
14
|
+
if (!t.products || !(n != null && n.length))
|
|
15
|
+
return t;
|
|
16
|
+
const i = (o) => n.reduce((r, e) => e(r), o);
|
|
17
|
+
return {
|
|
18
|
+
...t,
|
|
19
|
+
products: {
|
|
20
|
+
...t.products,
|
|
21
|
+
hits: t.products.hits.map(i)
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
function w(t) {
|
|
26
|
+
return new Promise((n) => setTimeout(n, t));
|
|
27
|
+
}
|
|
28
|
+
async function f(t, n, i) {
|
|
29
|
+
const { maxRetries: o = 0, retryInterval: r = 1e3 } = i;
|
|
30
|
+
let e = 0;
|
|
31
|
+
for (; ; )
|
|
32
|
+
try {
|
|
33
|
+
return await t.search(n, i);
|
|
34
|
+
} catch (u) {
|
|
35
|
+
if (!h(u))
|
|
36
|
+
throw console.info("Skipping retry logic for", u), u;
|
|
37
|
+
if (e >= o)
|
|
38
|
+
throw u;
|
|
39
|
+
e++, await w(r);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
function h(t) {
|
|
43
|
+
return !t || typeof t != "object" ? !1 : !("status" in t) || l(t.status);
|
|
44
|
+
}
|
|
45
|
+
function l(t) {
|
|
46
|
+
return typeof t == "number" && (t < 400 || t >= 500);
|
|
47
|
+
}
|
|
48
|
+
async function y(t, n = {}) {
|
|
49
|
+
const { hitDecorators: i, ...o } = n, r = await new Promise(c), e = await f(r, t, o);
|
|
50
|
+
return a(e, i);
|
|
51
|
+
}
|
|
52
|
+
export {
|
|
53
|
+
y as search
|
|
54
|
+
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { API, SearchQuery, SearchResult } from "@nosto/nosto-js/client";
|
|
1
|
+
import type { API, SearchQuery, SearchResult } from "@nosto/nosto-js/client";
|
|
2
2
|
import { Options } from "./types";
|
|
3
3
|
export declare function searchWithRetries(api: API, query: SearchQuery, options: Options<[]>): Promise<SearchResult>;
|
|
4
4
|
/**
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function d(){window.nostojs=window.nostojs??function(t){(window.nostojs.q=window.nostojs.q??[]).push(t)}}async function y(t){return window.nostojs(t)}typeof window<"u"&&(d(),y(t=>{t.internal.getSettings()}));typeof window<"u"&&d();const p={defaultCurrency:"EUR",defaultLocale:"en-US",currencySettings:{}},w={EUR:"de-DE",GBP:"en-GB",USD:"en-US",AUD:"en-AU",CAD:"en-CA",INR:"en-IN",AFN:"en-IN",BDT:"en-IN",BTN:"en-IN",MMK:"en-IN",NPR:"en-IN",PKR:"en-IN"};function g(t={}){const i={...p,...t};t.currencySettings||y(o=>{i.currencySettings=o.internal.getSettings().currencySettings??{}});function s(o,n){const{defaultCurrency:c,currencySettings:e,defaultLocale:u}=i,a=n??c,m=w[a]??u;if(a in e){const r=e[a],l=new Intl.NumberFormat(m,{useGrouping:!!r.groupingSeparator,minimumFractionDigits:r.decimalPlaces,maximumFractionDigits:r.decimalPlaces}).formatToParts(o).map(f=>f.type==="group"?r.groupingSeparator:f.type==="decimal"?r.decimalCharacter:f.value).join("");return r!=null&&r.currencyBeforeAmount?`${r.currencyToken}${l}`:`${l}${r==null?void 0:r.currencyToken}`}return new Intl.NumberFormat(m,{style:"currency",currency:a}).format(o)}return{formatCurrency:s}}function C(t){const{formatCurrency:i}=g(t);function s(n,c){const e={};return n.price!==void 0&&(e.priceText=i(n.price,c)),n.listPrice!==void 0&&(e.listPriceText=i(n.listPrice,c)),Object.assign({},n,e)}function o(n){return n.price!==void 0||n.listPrice!==void 0}return function(c){if(!o(c))return c;const e=s(c,c.priceCurrencyCode);return e.skus&&e.skus.some(o)&&(e.skus=e.skus.map(u=>o(u)?s(u,c.priceCurrencyCode):u)),e}}exports.getCurrencyFormatting=g;exports.priceDecorator=C;
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
function d() {
|
|
2
|
+
window.nostojs = window.nostojs ?? function(t) {
|
|
3
|
+
(window.nostojs.q = window.nostojs.q ?? []).push(t);
|
|
4
|
+
};
|
|
5
|
+
}
|
|
6
|
+
async function y(t) {
|
|
7
|
+
return window.nostojs(t);
|
|
8
|
+
}
|
|
9
|
+
typeof window < "u" && (d(), y((t) => {
|
|
10
|
+
t.internal.getSettings();
|
|
11
|
+
}));
|
|
12
|
+
typeof window < "u" && d();
|
|
13
|
+
const p = {
|
|
14
|
+
defaultCurrency: "EUR",
|
|
15
|
+
defaultLocale: "en-US",
|
|
16
|
+
/** @hidden */
|
|
17
|
+
currencySettings: {}
|
|
18
|
+
}, g = {
|
|
19
|
+
EUR: "de-DE",
|
|
20
|
+
GBP: "en-GB",
|
|
21
|
+
USD: "en-US",
|
|
22
|
+
AUD: "en-AU",
|
|
23
|
+
CAD: "en-CA",
|
|
24
|
+
//India, Afghanistan, Bangladesh, Bhutan, Myanmar, Nepal, and Pakistan uses lakhs and crores notation
|
|
25
|
+
INR: "en-IN",
|
|
26
|
+
AFN: "en-IN",
|
|
27
|
+
BDT: "en-IN",
|
|
28
|
+
BTN: "en-IN",
|
|
29
|
+
MMK: "en-IN",
|
|
30
|
+
NPR: "en-IN",
|
|
31
|
+
PKR: "en-IN"
|
|
32
|
+
};
|
|
33
|
+
function w(t = {}) {
|
|
34
|
+
const i = {
|
|
35
|
+
...p,
|
|
36
|
+
...t
|
|
37
|
+
};
|
|
38
|
+
t.currencySettings || y((o) => {
|
|
39
|
+
i.currencySettings = o.internal.getSettings().currencySettings ?? {};
|
|
40
|
+
});
|
|
41
|
+
function s(o, e) {
|
|
42
|
+
const { defaultCurrency: c, currencySettings: n, defaultLocale: u } = i, a = e ?? c, m = g[a] ?? u;
|
|
43
|
+
if (a in n) {
|
|
44
|
+
const r = n[a], l = new Intl.NumberFormat(m, {
|
|
45
|
+
useGrouping: !!r.groupingSeparator,
|
|
46
|
+
minimumFractionDigits: r.decimalPlaces,
|
|
47
|
+
maximumFractionDigits: r.decimalPlaces
|
|
48
|
+
}).formatToParts(o).map((f) => f.type === "group" ? r.groupingSeparator : f.type === "decimal" ? r.decimalCharacter : f.value).join("");
|
|
49
|
+
return r != null && r.currencyBeforeAmount ? `${r.currencyToken}${l}` : `${l}${r == null ? void 0 : r.currencyToken}`;
|
|
50
|
+
}
|
|
51
|
+
return new Intl.NumberFormat(m, {
|
|
52
|
+
style: "currency",
|
|
53
|
+
currency: a
|
|
54
|
+
}).format(o);
|
|
55
|
+
}
|
|
56
|
+
return {
|
|
57
|
+
formatCurrency: s
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
function P(t) {
|
|
61
|
+
const { formatCurrency: i } = w(t);
|
|
62
|
+
function s(e, c) {
|
|
63
|
+
const n = {};
|
|
64
|
+
return e.price !== void 0 && (n.priceText = i(e.price, c)), e.listPrice !== void 0 && (n.listPriceText = i(e.listPrice, c)), Object.assign({}, e, n);
|
|
65
|
+
}
|
|
66
|
+
function o(e) {
|
|
67
|
+
return e.price !== void 0 || e.listPrice !== void 0;
|
|
68
|
+
}
|
|
69
|
+
return function(c) {
|
|
70
|
+
if (!o(c))
|
|
71
|
+
return c;
|
|
72
|
+
const n = s(c, c.priceCurrencyCode);
|
|
73
|
+
return n.skus && n.skus.some(o) && (n.skus = n.skus.map((u) => o(u) ? s(u, c.priceCurrencyCode) : u)), n;
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
export {
|
|
77
|
+
w as getCurrencyFormatting,
|
|
78
|
+
P as priceDecorator
|
|
79
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("preact/hooks");function s(){window.nostojs=window.nostojs??function(o){(window.nostojs.q=window.nostojs.q??[]).push(o)}}async function e(o){return window.nostojs(o)}typeof window<"u"&&(s(),e(o=>{o.internal.getSettings()}));typeof window<"u"&&s();function c(){const[o,i]=n.useState([]),[a,u]=n.useState([]);return n.useEffect(()=>{e(async r=>{const{products:t,segments:w}=await r.getSearchSessionParams();i(w??[]),u((t==null?void 0:t.personalizationBoost)??[])})},[]),{segments:o,boost:a}}exports.usePersonalization=c;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { useState as s, useEffect as c } from "preact/hooks";
|
|
2
|
+
function t() {
|
|
3
|
+
window.nostojs = window.nostojs ?? function(o) {
|
|
4
|
+
(window.nostojs.q = window.nostojs.q ?? []).push(o);
|
|
5
|
+
};
|
|
6
|
+
}
|
|
7
|
+
async function e(o) {
|
|
8
|
+
return window.nostojs(o);
|
|
9
|
+
}
|
|
10
|
+
typeof window < "u" && (t(), e((o) => {
|
|
11
|
+
o.internal.getSettings();
|
|
12
|
+
}));
|
|
13
|
+
typeof window < "u" && t();
|
|
14
|
+
function g() {
|
|
15
|
+
const [o, i] = s([]), [w, a] = s([]);
|
|
16
|
+
return c(() => {
|
|
17
|
+
e(async (r) => {
|
|
18
|
+
const { products: n, segments: u } = await r.getSearchSessionParams();
|
|
19
|
+
i(u ?? []), a((n == null ? void 0 : n.personalizationBoost) ?? []);
|
|
20
|
+
});
|
|
21
|
+
}, []), {
|
|
22
|
+
segments: o,
|
|
23
|
+
boost: w
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
export {
|
|
27
|
+
g as usePersonalization
|
|
28
|
+
};
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type { PersonalizationBoost } from "@nosto/nosto-js/client";
|
|
2
|
+
/**
|
|
3
|
+
* Custom hook to fetch personalization data such as segments and boost.
|
|
4
|
+
*
|
|
5
|
+
* This hook uses the `nostojs` library to fetch search session parameters and updates
|
|
6
|
+
* the state with the fetched segments and personalization boost.
|
|
7
|
+
*
|
|
8
|
+
* @returns An object containing:
|
|
9
|
+
* - `segments`: An array of strings representing the personalization segments.
|
|
10
|
+
* - `boost`: An array of `PersonalizationBoost` objects representing the personalization boost.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```jsx
|
|
14
|
+
* import { usePersonalization } from '@nosto/preact'
|
|
15
|
+
*
|
|
16
|
+
* export default () => {
|
|
17
|
+
* const { segments, boost } = usePersonalization()
|
|
18
|
+
*
|
|
19
|
+
* return (
|
|
20
|
+
* <div>
|
|
21
|
+
* <h1>Personalization Segments</h1>
|
|
22
|
+
* <ul>
|
|
23
|
+
* {segments.map(segment => (
|
|
24
|
+
* <li key={segment}>{segment}</li>
|
|
25
|
+
* ))}
|
|
26
|
+
* </ul>
|
|
27
|
+
* <h1>Personalization Boost</h1>
|
|
28
|
+
* <ul>
|
|
29
|
+
* {boost.map(item => (
|
|
30
|
+
* <li key={item.id}>{item.name}</li>
|
|
31
|
+
* ))}
|
|
32
|
+
* </ul>
|
|
33
|
+
* </div>
|
|
34
|
+
* )
|
|
35
|
+
* }
|
|
36
|
+
* ```
|
|
37
|
+
*/
|
|
38
|
+
export declare function usePersonalization(): {
|
|
39
|
+
segments: string[];
|
|
40
|
+
boost: PersonalizationBoost[];
|
|
41
|
+
};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/** @module thumbnails */
|
|
2
|
+
export { generateThumbnailUrl, type Config as GenerateThumbnailUrlConfig } from "./src/generateThumbnailUrl";
|
|
3
|
+
export { thumbnailDecorator, type Config as ThumbnailDecoratorConfig } from "./src/thumbnailDecorator";
|
|
4
|
+
export { nostoThumbnailDecorator, type Config as NostoThumbnailDecoratorConfig } from "./src/nostoThumbnailDecorator";
|
|
5
|
+
export { shopifyThumbnailDecorator, type Config as ShopifyThumbnailDecoratorConfig } from "./src/shopifyThumbnailDecorator";
|
|
6
|
+
export type { NostoSize, ShopifySize, NostoShopifySize } from "./src/types";
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export type
|
|
3
|
-
size:
|
|
1
|
+
import { NostoSize } from "./types";
|
|
2
|
+
export type Config = {
|
|
3
|
+
size: NostoSize;
|
|
4
4
|
productId: string;
|
|
5
5
|
hash: string;
|
|
6
6
|
};
|
|
7
7
|
/**
|
|
8
8
|
* Generates a thumbnail URL for a given product and size
|
|
9
9
|
*/
|
|
10
|
-
export declare function generateThumbnailUrl({ size, productId, hash }:
|
|
10
|
+
export declare function generateThumbnailUrl({ size, productId, hash }: Config): string;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { SearchProduct } from "@nosto/nosto-js/client";
|
|
2
|
-
import {
|
|
2
|
+
import { NostoSize } from "./types";
|
|
3
3
|
export type Config = {
|
|
4
|
-
size:
|
|
4
|
+
size: NostoSize;
|
|
5
5
|
};
|
|
6
6
|
/**
|
|
7
7
|
* Replaces full size images with thumbnail sized versions.
|
|
@@ -12,8 +12,3 @@ export type Config = {
|
|
|
12
12
|
* - sku.imageHash -> sku.imageUrl
|
|
13
13
|
*/
|
|
14
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.
|
|
18
|
-
*/
|
|
19
|
-
export declare function thumbnailDecorator({ size }: Config): (hit: SearchProduct) => SearchProduct;
|
package/dist/thumbnails/{shopifyThumbnailDecorator.d.ts → src/shopifyThumbnailDecorator.d.ts}
RENAMED
|
@@ -1,26 +1,13 @@
|
|
|
1
1
|
import { SearchProduct } from "@nosto/nosto-js/client";
|
|
2
|
-
import { ShopifySize } from "./types";
|
|
3
|
-
type NostoSize = keyof typeof sizeMappings;
|
|
2
|
+
import { NostoShopifySize, ShopifySize } from "./types";
|
|
4
3
|
export type Config = {
|
|
5
|
-
size:
|
|
4
|
+
size: ShopifySize | NostoShopifySize | "orig";
|
|
6
5
|
fallback?: (hit: SearchProduct) => SearchProduct;
|
|
7
6
|
};
|
|
8
|
-
declare
|
|
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;
|
|
7
|
+
export declare function isSupportedNostoSize(size: string): size is NostoShopifySize;
|
|
20
8
|
/**
|
|
21
9
|
* Replaces full size images with specified Nosto or Shopify thumbnail size.
|
|
22
10
|
* This decorator will only affect the image URLs from Shopify CDN.
|
|
23
11
|
* Supports the Nosto size codes "1"-"9" and additionally Shopify specific sizes.
|
|
24
12
|
*/
|
|
25
13
|
export declare function shopifyThumbnailDecorator({ size, fallback }: Config): (hit: SearchProduct) => SearchProduct;
|
|
26
|
-
export {};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { NostoSize } from "./types";
|
|
2
|
+
export type Config = {
|
|
3
|
+
size: NostoSize;
|
|
4
|
+
};
|
|
5
|
+
/**
|
|
6
|
+
* Replaces full size images with thumbnail sized versions.
|
|
7
|
+
* Uses `shopifyThumbnailDecorator` and `nostoThumbnailDecorator` based on the platform.
|
|
8
|
+
*/
|
|
9
|
+
export declare function thumbnailDecorator({ size }: Config): (hit: import("@nosto/nosto-js/client").SearchProduct) => import("@nosto/nosto-js/client").SearchProduct;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Nosto thumbnail size code.
|
|
3
|
+
* Sometimes referred to as `imageVersion`.
|
|
3
4
|
*
|
|
4
5
|
* * 1: 170x170 px
|
|
5
6
|
* * 2: 100x100 px
|
|
@@ -15,7 +16,7 @@
|
|
|
15
16
|
* * 12: 400x400 px (Square)
|
|
16
17
|
* * 13: 750x750 px (Square)
|
|
17
18
|
*/
|
|
18
|
-
export type
|
|
19
|
+
export type NostoSize = "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9" | "10" | "11" | "12" | "13" | "orig";
|
|
19
20
|
/**
|
|
20
21
|
* Shopify thumbnail size code.
|
|
21
22
|
*
|
|
@@ -31,3 +32,18 @@ export type ThumbnailSize = "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9"
|
|
|
31
32
|
* * Master (full size)
|
|
32
33
|
*/
|
|
33
34
|
export type ShopifySize = "pico" | "icon" | "thumb" | "small" | "compact" | "medium" | "large" | "grande" | "original" | "master";
|
|
35
|
+
/**
|
|
36
|
+
* Shopify compatible Nosto thumbnail size code.
|
|
37
|
+
* This is a subset of {@link NostoSize} that is compatible with Shopify CDN.
|
|
38
|
+
*
|
|
39
|
+
* * 1: 170x170 px
|
|
40
|
+
* * 2: 100x100 px
|
|
41
|
+
* * 3: 90x70 px
|
|
42
|
+
* * 4: 50x50 px
|
|
43
|
+
* * 5: 30x30 px
|
|
44
|
+
* * 6: 100x140 px
|
|
45
|
+
* * 7: 200x200 px
|
|
46
|
+
* * 8: 400x400 px
|
|
47
|
+
* * 9: 750x750 px
|
|
48
|
+
*/
|
|
49
|
+
export type NostoShopifySize = "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function l(){window.nostojs=window.nostojs??function(r){(window.nostojs.q=window.nostojs.q??[]).push(r)}}async function d(r){return window.nostojs(r)}let f=null;typeof window<"u"&&(l(),d(r=>{f=r.internal.getSettings()}));function U(){return f}typeof window<"u"&&l();function s({size:r,productId:i,hash:c}){const a=U();if(!a)throw new Error("Client script settings are not yet available");return`https://${a.thumbnailHost}/${a.account}/${r}/${i}/${c}/A`}const w=/cdn\.shopify\.com/,m={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 b(r){return r in m}function p({size:r,fallback:i=c=>c}){if(r==="orig")return i;const c=m[r]||r;function a(e){return e?new URL(e).hostname.match(w):!1}function u(e){return e?a(e)?e.replace(/(\.jpg|\.png|\.jpeg|\.gif|\.webp)/,`_${c}$1`):e:""}function n(e){if(e)return e.map(o=>({...o,imageUrl:u(o.imageUrl)}))}function t(e){if(e)return e.map(o=>u(o))}return function(o){return a(o.imageUrl)?{...o,imageUrl:u(o.imageUrl),thumbUrl:u(o.thumbUrl),skus:n(o.skus),alternateImageUrls:t(o.alternateImageUrls)}:i(o)}}function g({size:r}){function i(u,n){if(n)return s({size:r,productId:u,hash:n})}function c(u,n){if(n)return n.map(t=>({...t,imageUrl:i(u,t.imageHash)??t.imageUrl}))}function a(u,n,t){if(!t)return n;if(n)return t.map(e=>s({size:r,productId:u,hash:e}))}return function(n){const t=n.productId;return t?{...n,imageUrl:i(t,n.imageHash)??n.imageUrl,thumbUrl:i(t,n.thumbHash)??n.thumbUrl,skus:c(t,n.skus),alternateImageUrls:a(t,n.alternateImageUrls,n.alternateImageHashes)}:n}}function _(){var r;return(r=window.Nosto)==null?void 0:r.shopifyScript}function h({size:r}){const i=g({size:r});return _()&&b(r)?p({size:r,fallback:i}):i}exports.generateThumbnailUrl=s;exports.nostoThumbnailDecorator=g;exports.shopifyThumbnailDecorator=p;exports.thumbnailDecorator=h;
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
function f() {
|
|
2
|
+
window.nostojs = window.nostojs ?? function(r) {
|
|
3
|
+
(window.nostojs.q = window.nostojs.q ?? []).push(r);
|
|
4
|
+
};
|
|
5
|
+
}
|
|
6
|
+
async function m(r) {
|
|
7
|
+
return window.nostojs(r);
|
|
8
|
+
}
|
|
9
|
+
let l = null;
|
|
10
|
+
typeof window < "u" && (f(), m((r) => {
|
|
11
|
+
l = r.internal.getSettings();
|
|
12
|
+
}));
|
|
13
|
+
function g() {
|
|
14
|
+
return l;
|
|
15
|
+
}
|
|
16
|
+
typeof window < "u" && f();
|
|
17
|
+
function s({ size: r, productId: i, hash: a }) {
|
|
18
|
+
const c = g();
|
|
19
|
+
if (!c)
|
|
20
|
+
throw new Error("Client script settings are not yet available");
|
|
21
|
+
return `https://${c.thumbnailHost}/${c.account}/${r}/${i}/${a}/A`;
|
|
22
|
+
}
|
|
23
|
+
const d = /cdn\.shopify\.com/, p = {
|
|
24
|
+
1: "170x170_crop_center",
|
|
25
|
+
2: "100x100_crop_center",
|
|
26
|
+
3: "90x70_crop_center",
|
|
27
|
+
4: "50x50_crop_center",
|
|
28
|
+
5: "30x30_crop_center",
|
|
29
|
+
6: "100x140_crop_center",
|
|
30
|
+
7: "200x200_crop_center",
|
|
31
|
+
8: "400x400",
|
|
32
|
+
9: "750x750"
|
|
33
|
+
};
|
|
34
|
+
function U(r) {
|
|
35
|
+
return r in p;
|
|
36
|
+
}
|
|
37
|
+
function w({ size: r, fallback: i = (a) => a }) {
|
|
38
|
+
if (r === "orig")
|
|
39
|
+
return i;
|
|
40
|
+
const a = p[r] || r;
|
|
41
|
+
function c(t) {
|
|
42
|
+
return t ? new URL(t).hostname.match(d) : !1;
|
|
43
|
+
}
|
|
44
|
+
function u(t) {
|
|
45
|
+
return t ? c(t) ? t.replace(/(\.jpg|\.png|\.jpeg|\.gif|\.webp)/, `_${a}$1`) : t : "";
|
|
46
|
+
}
|
|
47
|
+
function n(t) {
|
|
48
|
+
if (t)
|
|
49
|
+
return t.map((o) => ({
|
|
50
|
+
...o,
|
|
51
|
+
imageUrl: u(o.imageUrl)
|
|
52
|
+
}));
|
|
53
|
+
}
|
|
54
|
+
function e(t) {
|
|
55
|
+
if (t)
|
|
56
|
+
return t.map((o) => u(o));
|
|
57
|
+
}
|
|
58
|
+
return function(o) {
|
|
59
|
+
return c(o.imageUrl) ? {
|
|
60
|
+
...o,
|
|
61
|
+
imageUrl: u(o.imageUrl),
|
|
62
|
+
thumbUrl: u(o.thumbUrl),
|
|
63
|
+
skus: n(o.skus),
|
|
64
|
+
alternateImageUrls: e(o.alternateImageUrls)
|
|
65
|
+
} : i(o);
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
function _({ size: r }) {
|
|
69
|
+
function i(u, n) {
|
|
70
|
+
if (n)
|
|
71
|
+
return s({
|
|
72
|
+
size: r,
|
|
73
|
+
productId: u,
|
|
74
|
+
hash: n
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
function a(u, n) {
|
|
78
|
+
if (n)
|
|
79
|
+
return n.map((e) => ({
|
|
80
|
+
...e,
|
|
81
|
+
imageUrl: i(u, e.imageHash) ?? e.imageUrl
|
|
82
|
+
}));
|
|
83
|
+
}
|
|
84
|
+
function c(u, n, e) {
|
|
85
|
+
if (!e)
|
|
86
|
+
return n;
|
|
87
|
+
if (n)
|
|
88
|
+
return e.map(
|
|
89
|
+
(t) => s({
|
|
90
|
+
size: r,
|
|
91
|
+
productId: u,
|
|
92
|
+
hash: t
|
|
93
|
+
})
|
|
94
|
+
);
|
|
95
|
+
}
|
|
96
|
+
return function(n) {
|
|
97
|
+
const e = n.productId;
|
|
98
|
+
return e ? {
|
|
99
|
+
...n,
|
|
100
|
+
imageUrl: i(e, n.imageHash) ?? n.imageUrl,
|
|
101
|
+
thumbUrl: i(e, n.thumbHash) ?? n.thumbUrl,
|
|
102
|
+
skus: a(e, n.skus),
|
|
103
|
+
alternateImageUrls: c(e, n.alternateImageUrls, n.alternateImageHashes)
|
|
104
|
+
} : n;
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
function b() {
|
|
108
|
+
var r;
|
|
109
|
+
return (r = window.Nosto) == null ? void 0 : r.shopifyScript;
|
|
110
|
+
}
|
|
111
|
+
function x({ size: r }) {
|
|
112
|
+
const i = _({ size: r });
|
|
113
|
+
return b() && U(r) ? w({ size: r, fallback: i }) : i;
|
|
114
|
+
}
|
|
115
|
+
export {
|
|
116
|
+
s as generateThumbnailUrl,
|
|
117
|
+
_ as nostoThumbnailDecorator,
|
|
118
|
+
w as shopifyThumbnailDecorator,
|
|
119
|
+
x as thumbnailDecorator
|
|
120
|
+
};
|
package/package.json
CHANGED
|
@@ -1,63 +1,71 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nosto/search-js",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.0",
|
|
4
4
|
"license": "ISC",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"files": [
|
|
7
7
|
"dist"
|
|
8
8
|
],
|
|
9
|
-
"
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
"workspaces": [
|
|
10
|
+
"packages/*"
|
|
11
|
+
],
|
|
12
|
+
"main": "./dist/core/search.cjs.js",
|
|
13
|
+
"module": "./dist/core/search.es.js",
|
|
14
|
+
"types": "./dist/core/src/search.d.ts",
|
|
12
15
|
"directories": {
|
|
13
16
|
"doc": "docs",
|
|
14
17
|
"test": "test"
|
|
15
18
|
},
|
|
16
19
|
"exports": {
|
|
17
20
|
".": {
|
|
18
|
-
"types": "./dist/
|
|
19
|
-
"import": "./dist/
|
|
20
|
-
"require": "./dist/
|
|
21
|
+
"types": "./dist/core/index.d.ts",
|
|
22
|
+
"import": "./dist/core/core.es.js",
|
|
23
|
+
"require": "./dist/core/core.cjs.js"
|
|
21
24
|
},
|
|
22
25
|
"./currencies": {
|
|
23
|
-
"types": "./dist/currencies.d.ts",
|
|
24
|
-
"import": "./dist/currencies.es.js",
|
|
25
|
-
"require": "./dist/currencies.cjs.js"
|
|
26
|
+
"types": "./dist/currencies/index.d.ts",
|
|
27
|
+
"import": "./dist/currencies/currencies.es.js",
|
|
28
|
+
"require": "./dist/currencies/currencies.cjs.js"
|
|
26
29
|
},
|
|
27
30
|
"./thumbnails": {
|
|
28
|
-
"types": "./dist/thumbnails.d.ts",
|
|
29
|
-
"import": "./dist/thumbnails.es.js",
|
|
30
|
-
"require": "./dist/thumbnails.cjs.js"
|
|
31
|
+
"types": "./dist/thumbnails/index.d.ts",
|
|
32
|
+
"import": "./dist/thumbnails/thumbnails.es.js",
|
|
33
|
+
"require": "./dist/thumbnails/thumbnails.cjs.js"
|
|
34
|
+
},
|
|
35
|
+
"./preact": {
|
|
36
|
+
"types": "./dist/preact/index.d.ts",
|
|
37
|
+
"import": "./dist/preact/preact.es.js",
|
|
38
|
+
"require": "./dist/preact/preact.cjs.js"
|
|
31
39
|
}
|
|
32
40
|
},
|
|
33
41
|
"keywords": [],
|
|
34
42
|
"author": "Nosto",
|
|
35
43
|
"scripts": {
|
|
36
|
-
"
|
|
37
|
-
"build": "
|
|
44
|
+
"build": "tsc && npm run build-packages && npm run build-dts && npm run typedoc",
|
|
45
|
+
"build-packages": "npm run build --ws",
|
|
38
46
|
"build-dts": "tsc --noEmit false --emitDeclarationOnly",
|
|
47
|
+
"typedoc": "typedoc",
|
|
39
48
|
"test": "vitest --run",
|
|
40
|
-
"
|
|
41
|
-
"
|
|
42
|
-
"typedoc": "typedoc src/search.ts src/currencies.ts src/thumbnails.ts"
|
|
49
|
+
"test:watch": "vitest",
|
|
50
|
+
"lint": "eslint"
|
|
43
51
|
},
|
|
44
52
|
"devDependencies": {
|
|
45
|
-
"@nosto/nosto-js": "^1.
|
|
53
|
+
"@nosto/nosto-js": "^1.5.0",
|
|
46
54
|
"@testing-library/dom": "^10.4.0",
|
|
47
55
|
"@types/eslint-config-prettier": "^6.11.3",
|
|
48
|
-
"@types/node": "^22.13.
|
|
56
|
+
"@types/node": "^22.13.5",
|
|
49
57
|
"copyfiles": "^2.4.1",
|
|
50
|
-
"eslint": "^9.
|
|
58
|
+
"eslint": "^9.21.0",
|
|
51
59
|
"eslint-config-prettier": "^10.0.1",
|
|
52
|
-
"eslint-plugin-barrel-files": "^
|
|
60
|
+
"eslint-plugin-barrel-files": "^3.0.1",
|
|
53
61
|
"eslint-plugin-prettier": "^5.2.3",
|
|
54
62
|
"jsdom": "^26.0.0",
|
|
55
|
-
"prettier": "^3.5.
|
|
56
|
-
"typedoc": "^0.27.
|
|
63
|
+
"prettier": "^3.5.2",
|
|
64
|
+
"typedoc": "^0.27.8",
|
|
57
65
|
"typescript": "^5.7.3",
|
|
58
|
-
"typescript-eslint": "^8.
|
|
59
|
-
"vite": "^6.
|
|
60
|
-
"vitest": "^3.0.
|
|
66
|
+
"typescript-eslint": "^8.25.0",
|
|
67
|
+
"vite": "^6.2.0",
|
|
68
|
+
"vitest": "^3.0.7"
|
|
61
69
|
},
|
|
62
70
|
"publishConfig": {
|
|
63
71
|
"access": "public"
|
package/dist/currencies.cjs.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const y=require("./index.es-D_7T9vdv.cjs"),g={defaultCurrency:"EUR",defaultLocale:"en-US",currencySettings:{}},p={EUR:"de-DE",GBP:"en-GB",USD:"en-US",AUD:"en-AU",CAD:"en-CA",INR:"en-IN",AFN:"en-IN",BDT:"en-IN",BTN:"en-IN",MMK:"en-IN",NPR:"en-IN",PKR:"en-IN"};function d(o={}){const u={...g,...o};o.currencySettings||y.s(c=>{u.currencySettings=c.internal.getSettings().currencySettings??{}});function a(c,n){const{defaultCurrency:t,currencySettings:e,defaultLocale:i}=u,s=n??t,m=p[s]??i;if(s in e){const r=e[s],l=new Intl.NumberFormat(m,{useGrouping:!!r.groupingSeparator,minimumFractionDigits:r.decimalPlaces,maximumFractionDigits:r.decimalPlaces}).formatToParts(c).map(f=>f.type==="group"?r.groupingSeparator:f.type==="decimal"?r.decimalCharacter:f.value).join("");return r!=null&&r.currencyBeforeAmount?`${r.currencyToken}${l}`:`${l}${r==null?void 0:r.currencyToken}`}return new Intl.NumberFormat(m,{style:"currency",currency:s}).format(c)}return{formatCurrency:a}}function C(o){const{formatCurrency:u}=d(o);function a(n,t){const e={};return n.price!==void 0&&(e.priceText=u(n.price,t)),n.listPrice!==void 0&&(e.listPriceText=u(n.listPrice,t)),Object.assign({},n,e)}function c(n){return n.price!==void 0||n.listPrice!==void 0}return function(t){if(!c(t))return t;const e=a(t,t.priceCurrencyCode);return e.skus&&e.skus.some(c)&&(e.skus=e.skus.map(i=>c(i)?a(i,t.priceCurrencyCode):i)),e}}exports.getCurrencyFormatting=d;exports.priceDecorator=C;
|
package/dist/currencies.d.ts
DELETED
package/dist/currencies.es.js
DELETED
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
import { s as d } from "./index.es-Bcd5IQh9.js";
|
|
2
|
-
const y = {
|
|
3
|
-
defaultCurrency: "EUR",
|
|
4
|
-
defaultLocale: "en-US",
|
|
5
|
-
/** @hidden */
|
|
6
|
-
currencySettings: {}
|
|
7
|
-
}, p = {
|
|
8
|
-
EUR: "de-DE",
|
|
9
|
-
GBP: "en-GB",
|
|
10
|
-
USD: "en-US",
|
|
11
|
-
AUD: "en-AU",
|
|
12
|
-
CAD: "en-CA",
|
|
13
|
-
//India, Afghanistan, Bangladesh, Bhutan, Myanmar, Nepal, and Pakistan uses lakhs and crores notation
|
|
14
|
-
INR: "en-IN",
|
|
15
|
-
AFN: "en-IN",
|
|
16
|
-
BDT: "en-IN",
|
|
17
|
-
BTN: "en-IN",
|
|
18
|
-
MMK: "en-IN",
|
|
19
|
-
NPR: "en-IN",
|
|
20
|
-
PKR: "en-IN"
|
|
21
|
-
};
|
|
22
|
-
function g(o = {}) {
|
|
23
|
-
const u = {
|
|
24
|
-
...y,
|
|
25
|
-
...o
|
|
26
|
-
};
|
|
27
|
-
o.currencySettings || d((c) => {
|
|
28
|
-
u.currencySettings = c.internal.getSettings().currencySettings ?? {};
|
|
29
|
-
});
|
|
30
|
-
function a(c, n) {
|
|
31
|
-
const { defaultCurrency: t, currencySettings: e, defaultLocale: i } = u, s = n ?? t, m = p[s] ?? i;
|
|
32
|
-
if (s in e) {
|
|
33
|
-
const r = e[s], l = new Intl.NumberFormat(m, {
|
|
34
|
-
useGrouping: !!r.groupingSeparator,
|
|
35
|
-
minimumFractionDigits: r.decimalPlaces,
|
|
36
|
-
maximumFractionDigits: r.decimalPlaces
|
|
37
|
-
}).formatToParts(c).map((f) => f.type === "group" ? r.groupingSeparator : f.type === "decimal" ? r.decimalCharacter : f.value).join("");
|
|
38
|
-
return r != null && r.currencyBeforeAmount ? `${r.currencyToken}${l}` : `${l}${r == null ? void 0 : r.currencyToken}`;
|
|
39
|
-
}
|
|
40
|
-
return new Intl.NumberFormat(m, {
|
|
41
|
-
style: "currency",
|
|
42
|
-
currency: s
|
|
43
|
-
}).format(c);
|
|
44
|
-
}
|
|
45
|
-
return {
|
|
46
|
-
formatCurrency: a
|
|
47
|
-
};
|
|
48
|
-
}
|
|
49
|
-
function S(o) {
|
|
50
|
-
const { formatCurrency: u } = g(o);
|
|
51
|
-
function a(n, t) {
|
|
52
|
-
const e = {};
|
|
53
|
-
return n.price !== void 0 && (e.priceText = u(n.price, t)), n.listPrice !== void 0 && (e.listPriceText = u(n.listPrice, t)), Object.assign({}, n, e);
|
|
54
|
-
}
|
|
55
|
-
function c(n) {
|
|
56
|
-
return n.price !== void 0 || n.listPrice !== void 0;
|
|
57
|
-
}
|
|
58
|
-
return function(t) {
|
|
59
|
-
if (!c(t))
|
|
60
|
-
return t;
|
|
61
|
-
const e = a(t, t.priceCurrencyCode);
|
|
62
|
-
return e.skus && e.skus.some(c) && (e.skus = e.skus.map((i) => c(i) ? a(i, t.priceCurrencyCode) : i)), e;
|
|
63
|
-
};
|
|
64
|
-
}
|
|
65
|
-
export {
|
|
66
|
-
g as getCurrencyFormatting,
|
|
67
|
-
S as priceDecorator
|
|
68
|
-
};
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
function o() {
|
|
2
|
-
window.nostojs = window.nostojs ?? function(n) {
|
|
3
|
-
(window.nostojs.q = window.nostojs.q ?? []).push(n);
|
|
4
|
-
};
|
|
5
|
-
}
|
|
6
|
-
async function i(n) {
|
|
7
|
-
return window.nostojs(n);
|
|
8
|
-
}
|
|
9
|
-
let t = null;
|
|
10
|
-
typeof window < "u" && (o(), i((n) => {
|
|
11
|
-
t = n.internal.getSettings();
|
|
12
|
-
}));
|
|
13
|
-
function s() {
|
|
14
|
-
return t;
|
|
15
|
-
}
|
|
16
|
-
typeof window < "u" && o();
|
|
17
|
-
export {
|
|
18
|
-
s as i,
|
|
19
|
-
i as s
|
|
20
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";function o(){window.nostojs=window.nostojs??function(n){(window.nostojs.q=window.nostojs.q??[]).push(n)}}async function t(n){return window.nostojs(n)}let s=null;typeof window<"u"&&(o(),t(n=>{s=n.internal.getSettings()}));function i(){return s}typeof window<"u"&&o();exports.i=i;exports.s=t;
|
package/dist/search.cjs.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("./index.es-D_7T9vdv.cjs");function a(t,e){if(!t.products||!(e!=null&&e.length))return t;const r=i=>e.reduce((u,n)=>n(u),i);return{...t,products:{...t.products,hits:t.products.hits.map(r)}}}function o(t){return new Promise(e=>setTimeout(e,t))}async function l(t,e,r){const{maxRetries:i=0,retryInterval:u=1e3}=r;let n=0;for(;;)try{return await t.search(e,r)}catch(c){if(!f(c))throw console.info("Skipping retry logic for",c),c;if(n>=i)throw c;n++,await o(u)}}function f(t){return!t||typeof t!="object"?!1:!("status"in t)||h(t.status)}function h(t){return typeof t=="number"&&(t<400||t>=500)}async function y(t,e={}){const{hitDecorators:r,...i}=e,u=await new Promise(s.s),n=await l(u,t,i);return a(n,r)}exports.search=y;
|
package/dist/search.d.ts
DELETED
package/dist/search.es.js
DELETED
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import { s as a } from "./index.es-Bcd5IQh9.js";
|
|
2
|
-
function s(t, r) {
|
|
3
|
-
if (!t.products || !(r != null && r.length))
|
|
4
|
-
return t;
|
|
5
|
-
const e = (i) => r.reduce((u, n) => n(u), i);
|
|
6
|
-
return {
|
|
7
|
-
...t,
|
|
8
|
-
products: {
|
|
9
|
-
...t.products,
|
|
10
|
-
hits: t.products.hits.map(e)
|
|
11
|
-
}
|
|
12
|
-
};
|
|
13
|
-
}
|
|
14
|
-
function o(t) {
|
|
15
|
-
return new Promise((r) => setTimeout(r, t));
|
|
16
|
-
}
|
|
17
|
-
async function f(t, r, e) {
|
|
18
|
-
const { maxRetries: i = 0, retryInterval: u = 1e3 } = e;
|
|
19
|
-
let n = 0;
|
|
20
|
-
for (; ; )
|
|
21
|
-
try {
|
|
22
|
-
return await t.search(r, e);
|
|
23
|
-
} catch (c) {
|
|
24
|
-
if (!h(c))
|
|
25
|
-
throw console.info("Skipping retry logic for", c), c;
|
|
26
|
-
if (n >= i)
|
|
27
|
-
throw c;
|
|
28
|
-
n++, await o(u);
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
function h(t) {
|
|
32
|
-
return !t || typeof t != "object" ? !1 : !("status" in t) || l(t.status);
|
|
33
|
-
}
|
|
34
|
-
function l(t) {
|
|
35
|
-
return typeof t == "number" && (t < 400 || t >= 500);
|
|
36
|
-
}
|
|
37
|
-
async function p(t, r = {}) {
|
|
38
|
-
const { hitDecorators: e, ...i } = r, u = await new Promise(a), n = await f(u, t, i);
|
|
39
|
-
return s(n, e);
|
|
40
|
-
}
|
|
41
|
-
export {
|
|
42
|
-
p as search
|
|
43
|
-
};
|
package/dist/thumbnails.cjs.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
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
DELETED
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
/** @module thumbnails */
|
|
2
|
-
export { generateThumbnailUrl, type Props } from "./thumbnails/generateThumbnailUrl";
|
|
3
|
-
export { thumbnailDecorator, nostoThumbnailDecorator, type Config } from "./thumbnails/thumbnailDecorator";
|
|
4
|
-
export { shopifyThumbnailDecorator, type Config as ShopifyConfig } from "./thumbnails/shopifyThumbnailDecorator";
|
|
5
|
-
export type { ThumbnailSize, ShopifySize } from "./thumbnails/types";
|
package/dist/thumbnails.es.js
DELETED
|
@@ -1,105 +0,0 @@
|
|
|
1
|
-
import { i as m } from "./index.es-Bcd5IQh9.js";
|
|
2
|
-
function f({ size: e, productId: u, hash: i }) {
|
|
3
|
-
const c = m();
|
|
4
|
-
if (!c)
|
|
5
|
-
throw new Error("Client script settings are not yet available");
|
|
6
|
-
return `https://${c.thumbnailHost}/${c.account}/${e}/${u}/${i}/A`;
|
|
7
|
-
}
|
|
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) {
|
|
59
|
-
if (r)
|
|
60
|
-
return f({
|
|
61
|
-
size: e,
|
|
62
|
-
productId: a,
|
|
63
|
-
hash: r
|
|
64
|
-
});
|
|
65
|
-
}
|
|
66
|
-
function i(a, r) {
|
|
67
|
-
if (r)
|
|
68
|
-
return r.map((t) => ({
|
|
69
|
-
...t,
|
|
70
|
-
imageUrl: u(a, t.imageHash) ?? t.imageUrl
|
|
71
|
-
}));
|
|
72
|
-
}
|
|
73
|
-
function c(a, r, t) {
|
|
74
|
-
if (!t)
|
|
75
|
-
return r;
|
|
76
|
-
if (r)
|
|
77
|
-
return t.map(
|
|
78
|
-
(n) => f({
|
|
79
|
-
size: e,
|
|
80
|
-
productId: a,
|
|
81
|
-
hash: n
|
|
82
|
-
})
|
|
83
|
-
);
|
|
84
|
-
}
|
|
85
|
-
return function(r) {
|
|
86
|
-
const t = r.productId;
|
|
87
|
-
return t ? {
|
|
88
|
-
...r,
|
|
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)
|
|
93
|
-
} : r;
|
|
94
|
-
};
|
|
95
|
-
}
|
|
96
|
-
function b({ size: e }) {
|
|
97
|
-
const u = d({ size: e });
|
|
98
|
-
return U() && l(e) ? g({ size: e, fallback: u }) : u;
|
|
99
|
-
}
|
|
100
|
-
export {
|
|
101
|
-
f as generateThumbnailUrl,
|
|
102
|
-
d as nostoThumbnailDecorator,
|
|
103
|
-
g as shopifyThumbnailDecorator,
|
|
104
|
-
b as thumbnailDecorator
|
|
105
|
-
};
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|