@behio/storefront-sdk 0.42.0 → 1.1.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/dist/{chunk-3TPJG2WV.js → chunk-ODAMBLGY.js} +52 -20
- package/dist/{chunk-QOZYQMK2.mjs → chunk-WMZH72WS.mjs} +43 -11
- package/dist/{client-B0vlHxB1.d.mts → client-CiowRIBp.d.mts} +185 -46
- package/dist/{client-B0vlHxB1.d.ts → client-CiowRIBp.d.ts} +185 -46
- package/dist/index.d.mts +103 -3
- package/dist/index.d.ts +103 -3
- package/dist/index.js +113 -9
- package/dist/index.mjs +109 -5
- package/dist/next.d.mts +1 -1
- package/dist/next.d.ts +1 -1
- package/dist/next.js +2 -2
- package/dist/next.mjs +1 -1
- package/dist/react.d.mts +203 -46
- package/dist/react.d.ts +203 -46
- package/dist/react.js +215 -151
- package/dist/react.mjs +149 -86
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
|
|
11
11
|
|
|
12
12
|
|
|
13
|
-
var
|
|
13
|
+
var _chunkODAMBLGYjs = require('./chunk-ODAMBLGY.js');
|
|
14
14
|
|
|
15
15
|
// src/react/utils/format-price.ts
|
|
16
16
|
function formatPrice(amount, currency, locale) {
|
|
@@ -27,6 +27,103 @@ function formatPrice(amount, currency, locale) {
|
|
|
27
27
|
}
|
|
28
28
|
}
|
|
29
29
|
|
|
30
|
+
// src/variants.ts
|
|
31
|
+
var VARIANT_QUERY_PARAM = "variant";
|
|
32
|
+
var filled = (value) => {
|
|
33
|
+
const trimmed = _optionalChain([value, 'optionalAccess', _ => _.trim, 'call', _2 => _2()]);
|
|
34
|
+
return trimmed ? trimmed : null;
|
|
35
|
+
};
|
|
36
|
+
function resolveVariantContent(product, variant) {
|
|
37
|
+
const name = filled(_optionalChain([variant, 'optionalAccess', _3 => _3.name]));
|
|
38
|
+
const short = filled(_optionalChain([variant, 'optionalAccess', _4 => _4.shortDescription]));
|
|
39
|
+
const long = filled(_optionalChain([variant, 'optionalAccess', _5 => _5.longDescription]));
|
|
40
|
+
const images = _optionalChain([variant, 'optionalAccess', _6 => _6.images, 'optionalAccess', _7 => _7.length]) ? variant.images : null;
|
|
41
|
+
return {
|
|
42
|
+
name: _nullishCoalesce(name, () => ( product.name)),
|
|
43
|
+
shortDescription: _nullishCoalesce(_nullishCoalesce(short, () => ( product.shortDescription)), () => ( null)),
|
|
44
|
+
longDescription: _nullishCoalesce(_nullishCoalesce(long, () => ( product.longDescription)), () => ( null)),
|
|
45
|
+
images: _nullishCoalesce(images, () => ( product.images)),
|
|
46
|
+
overrides: {
|
|
47
|
+
name: !!name && name !== product.name,
|
|
48
|
+
shortDescription: !!short,
|
|
49
|
+
longDescription: !!long,
|
|
50
|
+
images: !!images
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
function variantFromQuery(product, value) {
|
|
55
|
+
const token = Array.isArray(value) ? value[0] : value;
|
|
56
|
+
if (!token) return null;
|
|
57
|
+
return _nullishCoalesce(product.variants.find((v) => v.variantSlug === token || v.id === token), () => ( null));
|
|
58
|
+
}
|
|
59
|
+
function variantHref(productSlug, variant, basePath = "/product") {
|
|
60
|
+
const base = `${basePath}/${productSlug}`;
|
|
61
|
+
if (!_optionalChain([variant, 'optionalAccess', _8 => _8.variantSlug])) return base;
|
|
62
|
+
return `${base}?${VARIANT_QUERY_PARAM}=${encodeURIComponent(variant.variantSlug)}`;
|
|
63
|
+
}
|
|
64
|
+
function findVariantByAttributes(product, selection) {
|
|
65
|
+
const axes = Object.keys(selection);
|
|
66
|
+
if (axes.length === 0) return null;
|
|
67
|
+
return _nullishCoalesce(product.variants.find(
|
|
68
|
+
(variant) => axes.every((axis) => variant.attributes.some((a) => a.name === axis && a.value === selection[axis]))
|
|
69
|
+
), () => ( null));
|
|
70
|
+
}
|
|
71
|
+
function availableAxisValues(product, axisName, selection) {
|
|
72
|
+
const others = Object.entries(selection).filter(([name]) => name !== axisName);
|
|
73
|
+
const values = /* @__PURE__ */ new Set();
|
|
74
|
+
for (const variant of product.variants) {
|
|
75
|
+
const matchesOthers = others.every(
|
|
76
|
+
([name, value]) => variant.attributes.some((a) => a.name === name && a.value === value)
|
|
77
|
+
);
|
|
78
|
+
if (!matchesOthers) continue;
|
|
79
|
+
const own = variant.attributes.find((a) => a.name === axisName);
|
|
80
|
+
if (own) values.add(own.value);
|
|
81
|
+
}
|
|
82
|
+
return [...values];
|
|
83
|
+
}
|
|
84
|
+
function buildVariantComparison(product, labels, formatPriceValue) {
|
|
85
|
+
const rows = [];
|
|
86
|
+
const axisNames = /* @__PURE__ */ new Set();
|
|
87
|
+
for (const variant of product.variants) {
|
|
88
|
+
for (const attribute of variant.attributes) axisNames.add(attribute.name);
|
|
89
|
+
}
|
|
90
|
+
for (const axis of axisNames) {
|
|
91
|
+
const values = product.variants.map(
|
|
92
|
+
(v) => _nullishCoalesce(_optionalChain([v, 'access', _9 => _9.attributes, 'access', _10 => _10.find, 'call', _11 => _11((a) => a.name === axis), 'optionalAccess', _12 => _12.value]), () => ( "-"))
|
|
93
|
+
);
|
|
94
|
+
if (new Set(values).size <= 1) continue;
|
|
95
|
+
rows.push({ label: axis, values });
|
|
96
|
+
}
|
|
97
|
+
rows.push({
|
|
98
|
+
label: labels.price,
|
|
99
|
+
values: product.variants.map((v) => formatPriceValue(v))
|
|
100
|
+
});
|
|
101
|
+
rows.push({
|
|
102
|
+
label: labels.availability,
|
|
103
|
+
values: product.variants.map((v) => v.inStock ? labels.inStock : labels.soldOut)
|
|
104
|
+
});
|
|
105
|
+
const parameterLabels = /* @__PURE__ */ new Set();
|
|
106
|
+
for (const variant of product.variants) {
|
|
107
|
+
for (const group of _nullishCoalesce(variant.parameterGroups, () => ( []))) {
|
|
108
|
+
for (const parameter of _nullishCoalesce(group.parameters, () => ( []))) parameterLabels.add(parameter.label);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
for (const label of parameterLabels) {
|
|
112
|
+
const values = product.variants.map((variant) => {
|
|
113
|
+
for (const group of _nullishCoalesce(variant.parameterGroups, () => ( []))) {
|
|
114
|
+
const hit = _optionalChain([group, 'access', _13 => _13.parameters, 'optionalAccess', _14 => _14.find, 'call', _15 => _15((p) => p.label === label)]);
|
|
115
|
+
if (!hit) continue;
|
|
116
|
+
if (hit.value) return [hit.value, hit.unit].filter(Boolean).join(" ");
|
|
117
|
+
if (hit.booleanValue !== null) return hit.booleanValue ? "\u2713" : "-";
|
|
118
|
+
}
|
|
119
|
+
return "-";
|
|
120
|
+
});
|
|
121
|
+
if (new Set(values).size <= 1) continue;
|
|
122
|
+
rows.push({ label, values });
|
|
123
|
+
}
|
|
124
|
+
return rows;
|
|
125
|
+
}
|
|
126
|
+
|
|
30
127
|
// src/analytics.ts
|
|
31
128
|
var GA4_NAME_MAP = {
|
|
32
129
|
newsletter_signup: "generate_lead"
|
|
@@ -35,7 +132,7 @@ function trackEcommerceEvent(event, payload) {
|
|
|
35
132
|
if (typeof window === "undefined") return;
|
|
36
133
|
const w = window;
|
|
37
134
|
try {
|
|
38
|
-
_optionalChain([w, 'access',
|
|
135
|
+
_optionalChain([w, 'access', _16 => _16.__behioEcommerceSink, 'optionalCall', _17 => _17(event, payload)]);
|
|
39
136
|
} catch (e2) {
|
|
40
137
|
}
|
|
41
138
|
const gaName = _nullishCoalesce(GA4_NAME_MAP[event], () => ( event));
|
|
@@ -67,12 +164,12 @@ function getStoredVisitorId() {
|
|
|
67
164
|
function generateVisitorId() {
|
|
68
165
|
const bytes = new Uint8Array(18);
|
|
69
166
|
try {
|
|
70
|
-
_optionalChain([globalThis, 'access',
|
|
167
|
+
_optionalChain([globalThis, 'access', _18 => _18.crypto, 'optionalAccess', _19 => _19.getRandomValues, 'optionalCall', _20 => _20(bytes)]);
|
|
71
168
|
} catch (e5) {
|
|
72
169
|
}
|
|
73
|
-
let
|
|
74
|
-
for (const b of bytes) if (b !== 0)
|
|
75
|
-
if (!
|
|
170
|
+
let filled2 = false;
|
|
171
|
+
for (const b of bytes) if (b !== 0) filled2 = true;
|
|
172
|
+
if (!filled2) for (let i = 0; i < bytes.length; i++) bytes[i] = Math.floor(Math.random() * 256);
|
|
76
173
|
let bin = "";
|
|
77
174
|
for (const b of bytes) bin += String.fromCharCode(b);
|
|
78
175
|
const b64 = typeof btoa === "function" ? btoa(bin) : Buffer.from(bytes).toString("base64");
|
|
@@ -108,8 +205,8 @@ async function grantAnalyticsConsent(client, categories) {
|
|
|
108
205
|
const res = await client.consent.record({
|
|
109
206
|
visitorId: id,
|
|
110
207
|
analytics: true,
|
|
111
|
-
marketing: _nullishCoalesce(_optionalChain([categories, 'optionalAccess',
|
|
112
|
-
preferences: _nullishCoalesce(_optionalChain([categories, 'optionalAccess',
|
|
208
|
+
marketing: _nullishCoalesce(_optionalChain([categories, 'optionalAccess', _21 => _21.marketing]), () => ( false)),
|
|
209
|
+
preferences: _nullishCoalesce(_optionalChain([categories, 'optionalAccess', _22 => _22.preferences]), () => ( false))
|
|
113
210
|
});
|
|
114
211
|
emitConsentChanged();
|
|
115
212
|
return res;
|
|
@@ -139,4 +236,11 @@ async function revokeAnalyticsConsent(client) {
|
|
|
139
236
|
|
|
140
237
|
|
|
141
238
|
|
|
142
|
-
|
|
239
|
+
|
|
240
|
+
|
|
241
|
+
|
|
242
|
+
|
|
243
|
+
|
|
244
|
+
|
|
245
|
+
|
|
246
|
+
exports.AddressTypes = _chunkODAMBLGYjs.AddressTypes; exports.BehioApiError = _chunkODAMBLGYjs.BehioApiError; exports.BehioNetworkError = _chunkODAMBLGYjs.BehioNetworkError; exports.BehioStorefront = _chunkODAMBLGYjs.BehioStorefront; exports.FulfillmentStatuses = _chunkODAMBLGYjs.FulfillmentStatuses; exports.OrderStatuses = _chunkODAMBLGYjs.OrderStatuses; exports.PaymentStatuses = _chunkODAMBLGYjs.PaymentStatuses; exports.ProductSort = _chunkODAMBLGYjs.ProductSort; exports.VARIANT_QUERY_PARAM = VARIANT_QUERY_PARAM; exports.availableAxisValues = availableAxisValues; exports.buildVariantComparison = buildVariantComparison; exports.err = _chunkODAMBLGYjs.err; exports.findVariantByAttributes = findVariantByAttributes; exports.formatPrice = formatPrice; exports.generateVisitorId = generateVisitorId; exports.getStoredVisitorId = getStoredVisitorId; exports.grantAnalyticsConsent = grantAnalyticsConsent; exports.ok = _chunkODAMBLGYjs.ok; exports.resolveVariantContent = resolveVariantContent; exports.revokeAnalyticsConsent = revokeAnalyticsConsent; exports.toSdkError = _chunkODAMBLGYjs.toSdkError; exports.trackEcommerceEvent = trackEcommerceEvent; exports.variantFromQuery = variantFromQuery; exports.variantHref = variantHref;
|
package/dist/index.mjs
CHANGED
|
@@ -10,7 +10,7 @@ import {
|
|
|
10
10
|
err,
|
|
11
11
|
ok,
|
|
12
12
|
toSdkError
|
|
13
|
-
} from "./chunk-
|
|
13
|
+
} from "./chunk-WMZH72WS.mjs";
|
|
14
14
|
|
|
15
15
|
// src/react/utils/format-price.ts
|
|
16
16
|
function formatPrice(amount, currency, locale) {
|
|
@@ -27,6 +27,103 @@ function formatPrice(amount, currency, locale) {
|
|
|
27
27
|
}
|
|
28
28
|
}
|
|
29
29
|
|
|
30
|
+
// src/variants.ts
|
|
31
|
+
var VARIANT_QUERY_PARAM = "variant";
|
|
32
|
+
var filled = (value) => {
|
|
33
|
+
const trimmed = value?.trim();
|
|
34
|
+
return trimmed ? trimmed : null;
|
|
35
|
+
};
|
|
36
|
+
function resolveVariantContent(product, variant) {
|
|
37
|
+
const name = filled(variant?.name);
|
|
38
|
+
const short = filled(variant?.shortDescription);
|
|
39
|
+
const long = filled(variant?.longDescription);
|
|
40
|
+
const images = variant?.images?.length ? variant.images : null;
|
|
41
|
+
return {
|
|
42
|
+
name: name ?? product.name,
|
|
43
|
+
shortDescription: short ?? product.shortDescription ?? null,
|
|
44
|
+
longDescription: long ?? product.longDescription ?? null,
|
|
45
|
+
images: images ?? product.images,
|
|
46
|
+
overrides: {
|
|
47
|
+
name: !!name && name !== product.name,
|
|
48
|
+
shortDescription: !!short,
|
|
49
|
+
longDescription: !!long,
|
|
50
|
+
images: !!images
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
function variantFromQuery(product, value) {
|
|
55
|
+
const token = Array.isArray(value) ? value[0] : value;
|
|
56
|
+
if (!token) return null;
|
|
57
|
+
return product.variants.find((v) => v.variantSlug === token || v.id === token) ?? null;
|
|
58
|
+
}
|
|
59
|
+
function variantHref(productSlug, variant, basePath = "/product") {
|
|
60
|
+
const base = `${basePath}/${productSlug}`;
|
|
61
|
+
if (!variant?.variantSlug) return base;
|
|
62
|
+
return `${base}?${VARIANT_QUERY_PARAM}=${encodeURIComponent(variant.variantSlug)}`;
|
|
63
|
+
}
|
|
64
|
+
function findVariantByAttributes(product, selection) {
|
|
65
|
+
const axes = Object.keys(selection);
|
|
66
|
+
if (axes.length === 0) return null;
|
|
67
|
+
return product.variants.find(
|
|
68
|
+
(variant) => axes.every((axis) => variant.attributes.some((a) => a.name === axis && a.value === selection[axis]))
|
|
69
|
+
) ?? null;
|
|
70
|
+
}
|
|
71
|
+
function availableAxisValues(product, axisName, selection) {
|
|
72
|
+
const others = Object.entries(selection).filter(([name]) => name !== axisName);
|
|
73
|
+
const values = /* @__PURE__ */ new Set();
|
|
74
|
+
for (const variant of product.variants) {
|
|
75
|
+
const matchesOthers = others.every(
|
|
76
|
+
([name, value]) => variant.attributes.some((a) => a.name === name && a.value === value)
|
|
77
|
+
);
|
|
78
|
+
if (!matchesOthers) continue;
|
|
79
|
+
const own = variant.attributes.find((a) => a.name === axisName);
|
|
80
|
+
if (own) values.add(own.value);
|
|
81
|
+
}
|
|
82
|
+
return [...values];
|
|
83
|
+
}
|
|
84
|
+
function buildVariantComparison(product, labels, formatPriceValue) {
|
|
85
|
+
const rows = [];
|
|
86
|
+
const axisNames = /* @__PURE__ */ new Set();
|
|
87
|
+
for (const variant of product.variants) {
|
|
88
|
+
for (const attribute of variant.attributes) axisNames.add(attribute.name);
|
|
89
|
+
}
|
|
90
|
+
for (const axis of axisNames) {
|
|
91
|
+
const values = product.variants.map(
|
|
92
|
+
(v) => v.attributes.find((a) => a.name === axis)?.value ?? "-"
|
|
93
|
+
);
|
|
94
|
+
if (new Set(values).size <= 1) continue;
|
|
95
|
+
rows.push({ label: axis, values });
|
|
96
|
+
}
|
|
97
|
+
rows.push({
|
|
98
|
+
label: labels.price,
|
|
99
|
+
values: product.variants.map((v) => formatPriceValue(v))
|
|
100
|
+
});
|
|
101
|
+
rows.push({
|
|
102
|
+
label: labels.availability,
|
|
103
|
+
values: product.variants.map((v) => v.inStock ? labels.inStock : labels.soldOut)
|
|
104
|
+
});
|
|
105
|
+
const parameterLabels = /* @__PURE__ */ new Set();
|
|
106
|
+
for (const variant of product.variants) {
|
|
107
|
+
for (const group of variant.parameterGroups ?? []) {
|
|
108
|
+
for (const parameter of group.parameters ?? []) parameterLabels.add(parameter.label);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
for (const label of parameterLabels) {
|
|
112
|
+
const values = product.variants.map((variant) => {
|
|
113
|
+
for (const group of variant.parameterGroups ?? []) {
|
|
114
|
+
const hit = group.parameters?.find((p) => p.label === label);
|
|
115
|
+
if (!hit) continue;
|
|
116
|
+
if (hit.value) return [hit.value, hit.unit].filter(Boolean).join(" ");
|
|
117
|
+
if (hit.booleanValue !== null) return hit.booleanValue ? "\u2713" : "-";
|
|
118
|
+
}
|
|
119
|
+
return "-";
|
|
120
|
+
});
|
|
121
|
+
if (new Set(values).size <= 1) continue;
|
|
122
|
+
rows.push({ label, values });
|
|
123
|
+
}
|
|
124
|
+
return rows;
|
|
125
|
+
}
|
|
126
|
+
|
|
30
127
|
// src/analytics.ts
|
|
31
128
|
var GA4_NAME_MAP = {
|
|
32
129
|
newsletter_signup: "generate_lead"
|
|
@@ -70,9 +167,9 @@ function generateVisitorId() {
|
|
|
70
167
|
globalThis.crypto?.getRandomValues?.(bytes);
|
|
71
168
|
} catch {
|
|
72
169
|
}
|
|
73
|
-
let
|
|
74
|
-
for (const b of bytes) if (b !== 0)
|
|
75
|
-
if (!
|
|
170
|
+
let filled2 = false;
|
|
171
|
+
for (const b of bytes) if (b !== 0) filled2 = true;
|
|
172
|
+
if (!filled2) for (let i = 0; i < bytes.length; i++) bytes[i] = Math.floor(Math.random() * 256);
|
|
76
173
|
let bin = "";
|
|
77
174
|
for (const b of bytes) bin += String.fromCharCode(b);
|
|
78
175
|
const b64 = typeof btoa === "function" ? btoa(bin) : Buffer.from(bytes).toString("base64");
|
|
@@ -130,13 +227,20 @@ export {
|
|
|
130
227
|
OrderStatuses,
|
|
131
228
|
PaymentStatuses,
|
|
132
229
|
ProductSort,
|
|
230
|
+
VARIANT_QUERY_PARAM,
|
|
231
|
+
availableAxisValues,
|
|
232
|
+
buildVariantComparison,
|
|
133
233
|
err,
|
|
234
|
+
findVariantByAttributes,
|
|
134
235
|
formatPrice,
|
|
135
236
|
generateVisitorId,
|
|
136
237
|
getStoredVisitorId,
|
|
137
238
|
grantAnalyticsConsent,
|
|
138
239
|
ok,
|
|
240
|
+
resolveVariantContent,
|
|
139
241
|
revokeAnalyticsConsent,
|
|
140
242
|
toSdkError,
|
|
141
|
-
trackEcommerceEvent
|
|
243
|
+
trackEcommerceEvent,
|
|
244
|
+
variantFromQuery,
|
|
245
|
+
variantHref
|
|
142
246
|
};
|
package/dist/next.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { o as BehioStorefrontConfig, B as BehioStorefront } from './client-CiowRIBp.mjs';
|
|
2
2
|
|
|
3
3
|
interface GetBehioOptions extends Partial<BehioStorefrontConfig> {
|
|
4
4
|
/** Override the cart session cookie name (default: "behio_cart_session"). */
|
package/dist/next.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { o as BehioStorefrontConfig, B as BehioStorefront } from './client-CiowRIBp.js';
|
|
2
2
|
|
|
3
3
|
interface GetBehioOptions extends Partial<BehioStorefrontConfig> {
|
|
4
4
|
/** Override the cart session cookie name (default: "behio_cart_session"). */
|
package/dist/next.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var _chunkODAMBLGYjs = require('./chunk-ODAMBLGY.js');
|
|
4
4
|
|
|
5
5
|
// src/next.ts
|
|
6
6
|
var _headers = require('next/headers');
|
|
@@ -18,7 +18,7 @@ async function getBehio(options = {}) {
|
|
|
18
18
|
const locale = _nullishCoalesce(options.locale, () => ( process.env.BEHIO_LOCALE));
|
|
19
19
|
const currency = _nullishCoalesce(options.currency, () => ( process.env.BEHIO_CURRENCY));
|
|
20
20
|
const cookieName = _nullishCoalesce(options.cartCookieName, () => ( CART_COOKIE_NAME));
|
|
21
|
-
const client = new (0,
|
|
21
|
+
const client = new (0, _chunkODAMBLGYjs.BehioStorefront)({
|
|
22
22
|
apiKey,
|
|
23
23
|
...baseUrl ? { baseUrl } : {},
|
|
24
24
|
...locale ? { locale } : {},
|