@behio/storefront-sdk 0.37.0 → 0.41.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-QKEW2EU5.js → chunk-3TPJG2WV.js} +589 -145
- package/dist/{chunk-5C6MNGGB.mjs → chunk-QOZYQMK2.mjs} +587 -143
- package/dist/{client-BgYibdTK.d.mts → client-sN7fZvjG.d.mts} +363 -7
- package/dist/{client-BgYibdTK.d.ts → client-sN7fZvjG.d.ts} +363 -7
- package/dist/index.d.mts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +142 -40
- package/dist/index.mjs +111 -9
- 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 +3026 -4
- package/dist/react.d.ts +3026 -4
- package/dist/react.js +2612 -467
- package/dist/react.mjs +2128 -86
- package/package.json +2 -2
- package/dist/chunk-CZRSJULD.js +0 -118
- package/dist/chunk-QUU76QUB.mjs +0 -118
package/dist/index.js
CHANGED
|
@@ -1,40 +1,142 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
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
|
+
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
var _chunk3TPJG2WVjs = require('./chunk-3TPJG2WV.js');
|
|
14
|
+
|
|
15
|
+
// src/react/utils/format-price.ts
|
|
16
|
+
function formatPrice(amount, currency, locale) {
|
|
17
|
+
const resolvedLocale = _nullishCoalesce(locale, () => ( "cs"));
|
|
18
|
+
try {
|
|
19
|
+
return new Intl.NumberFormat(resolvedLocale, {
|
|
20
|
+
style: "currency",
|
|
21
|
+
currency,
|
|
22
|
+
minimumFractionDigits: Number.isInteger(amount) ? 0 : 2,
|
|
23
|
+
maximumFractionDigits: 2
|
|
24
|
+
}).format(amount);
|
|
25
|
+
} catch (e) {
|
|
26
|
+
return `${amount} ${currency}`;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// src/analytics.ts
|
|
31
|
+
var GA4_NAME_MAP = {
|
|
32
|
+
newsletter_signup: "generate_lead"
|
|
33
|
+
};
|
|
34
|
+
function trackEcommerceEvent(event, payload) {
|
|
35
|
+
if (typeof window === "undefined") return;
|
|
36
|
+
const w = window;
|
|
37
|
+
try {
|
|
38
|
+
_optionalChain([w, 'access', _ => _.__behioEcommerceSink, 'optionalCall', _2 => _2(event, payload)]);
|
|
39
|
+
} catch (e2) {
|
|
40
|
+
}
|
|
41
|
+
const gaName = _nullishCoalesce(GA4_NAME_MAP[event], () => ( event));
|
|
42
|
+
try {
|
|
43
|
+
if (typeof w.gtag === "function") {
|
|
44
|
+
w.gtag("event", gaName, payload);
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
if (Array.isArray(w.dataLayer)) {
|
|
48
|
+
w.dataLayer.push({ ecommerce: null });
|
|
49
|
+
w.dataLayer.push({ event: gaName, ecommerce: payload });
|
|
50
|
+
}
|
|
51
|
+
} catch (e3) {
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// src/consent-visitor.ts
|
|
56
|
+
var VISITOR_KEY = "behio_visitor_id";
|
|
57
|
+
var COOKIE_MAX_AGE = 60 * 60 * 24 * 365;
|
|
58
|
+
function getStoredVisitorId() {
|
|
59
|
+
if (typeof window === "undefined") return null;
|
|
60
|
+
try {
|
|
61
|
+
const ls = localStorage.getItem(VISITOR_KEY);
|
|
62
|
+
if (ls) return ls;
|
|
63
|
+
} catch (e4) {
|
|
64
|
+
}
|
|
65
|
+
return readCookie(VISITOR_KEY);
|
|
66
|
+
}
|
|
67
|
+
function generateVisitorId() {
|
|
68
|
+
const bytes = new Uint8Array(18);
|
|
69
|
+
try {
|
|
70
|
+
_optionalChain([globalThis, 'access', _3 => _3.crypto, 'optionalAccess', _4 => _4.getRandomValues, 'optionalCall', _5 => _5(bytes)]);
|
|
71
|
+
} catch (e5) {
|
|
72
|
+
}
|
|
73
|
+
let filled = false;
|
|
74
|
+
for (const b of bytes) if (b !== 0) filled = true;
|
|
75
|
+
if (!filled) for (let i = 0; i < bytes.length; i++) bytes[i] = Math.floor(Math.random() * 256);
|
|
76
|
+
let bin = "";
|
|
77
|
+
for (const b of bytes) bin += String.fromCharCode(b);
|
|
78
|
+
const b64 = typeof btoa === "function" ? btoa(bin) : Buffer.from(bytes).toString("base64");
|
|
79
|
+
return `v${b64.replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "")}`.slice(0, 40);
|
|
80
|
+
}
|
|
81
|
+
function writeVisitorId(id) {
|
|
82
|
+
if (typeof window === "undefined") return;
|
|
83
|
+
try {
|
|
84
|
+
localStorage.setItem(VISITOR_KEY, id);
|
|
85
|
+
} catch (e6) {
|
|
86
|
+
}
|
|
87
|
+
try {
|
|
88
|
+
document.cookie = `${VISITOR_KEY}=${encodeURIComponent(id)}; path=/; max-age=${COOKIE_MAX_AGE}; SameSite=Lax`;
|
|
89
|
+
} catch (e7) {
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
function readCookie(name) {
|
|
93
|
+
if (typeof document === "undefined") return null;
|
|
94
|
+
const match = document.cookie.match(new RegExp(`(?:^|; )${name}=([^;]*)`));
|
|
95
|
+
return match ? decodeURIComponent(match[1]) : null;
|
|
96
|
+
}
|
|
97
|
+
function emitConsentChanged() {
|
|
98
|
+
if (typeof window === "undefined") return;
|
|
99
|
+
try {
|
|
100
|
+
window.dispatchEvent(new Event("behio:consent-changed"));
|
|
101
|
+
} catch (e8) {
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
async function grantAnalyticsConsent(client, categories) {
|
|
105
|
+
const id = _nullishCoalesce(getStoredVisitorId(), () => ( generateVisitorId()));
|
|
106
|
+
writeVisitorId(id);
|
|
107
|
+
client.setAnalyticsVisitorId(id);
|
|
108
|
+
const res = await client.consent.record({
|
|
109
|
+
visitorId: id,
|
|
110
|
+
analytics: true,
|
|
111
|
+
marketing: _nullishCoalesce(_optionalChain([categories, 'optionalAccess', _6 => _6.marketing]), () => ( false)),
|
|
112
|
+
preferences: _nullishCoalesce(_optionalChain([categories, 'optionalAccess', _7 => _7.preferences]), () => ( false))
|
|
113
|
+
});
|
|
114
|
+
emitConsentChanged();
|
|
115
|
+
return res;
|
|
116
|
+
}
|
|
117
|
+
async function revokeAnalyticsConsent(client) {
|
|
118
|
+
const id = getStoredVisitorId();
|
|
119
|
+
client.setAnalyticsVisitorId(null);
|
|
120
|
+
emitConsentChanged();
|
|
121
|
+
if (!id) return { data: { success: true }, error: null };
|
|
122
|
+
return client.consent.revoke(id);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
exports.AddressTypes = _chunk3TPJG2WVjs.AddressTypes; exports.BehioApiError = _chunk3TPJG2WVjs.BehioApiError; exports.BehioNetworkError = _chunk3TPJG2WVjs.BehioNetworkError; exports.BehioStorefront = _chunk3TPJG2WVjs.BehioStorefront; exports.FulfillmentStatuses = _chunk3TPJG2WVjs.FulfillmentStatuses; exports.OrderStatuses = _chunk3TPJG2WVjs.OrderStatuses; exports.PaymentStatuses = _chunk3TPJG2WVjs.PaymentStatuses; exports.ProductSort = _chunk3TPJG2WVjs.ProductSort; exports.err = _chunk3TPJG2WVjs.err; exports.formatPrice = formatPrice; exports.generateVisitorId = generateVisitorId; exports.getStoredVisitorId = getStoredVisitorId; exports.grantAnalyticsConsent = grantAnalyticsConsent; exports.ok = _chunk3TPJG2WVjs.ok; exports.revokeAnalyticsConsent = revokeAnalyticsConsent; exports.toSdkError = _chunk3TPJG2WVjs.toSdkError; exports.trackEcommerceEvent = trackEcommerceEvent;
|
package/dist/index.mjs
CHANGED
|
@@ -1,11 +1,3 @@
|
|
|
1
|
-
import {
|
|
2
|
-
formatPrice,
|
|
3
|
-
generateVisitorId,
|
|
4
|
-
getStoredVisitorId,
|
|
5
|
-
grantAnalyticsConsent,
|
|
6
|
-
revokeAnalyticsConsent,
|
|
7
|
-
trackEcommerceEvent
|
|
8
|
-
} from "./chunk-QUU76QUB.mjs";
|
|
9
1
|
import {
|
|
10
2
|
AddressTypes,
|
|
11
3
|
BehioApiError,
|
|
@@ -18,7 +10,117 @@ import {
|
|
|
18
10
|
err,
|
|
19
11
|
ok,
|
|
20
12
|
toSdkError
|
|
21
|
-
} from "./chunk-
|
|
13
|
+
} from "./chunk-QOZYQMK2.mjs";
|
|
14
|
+
|
|
15
|
+
// src/react/utils/format-price.ts
|
|
16
|
+
function formatPrice(amount, currency, locale) {
|
|
17
|
+
const resolvedLocale = locale ?? "cs";
|
|
18
|
+
try {
|
|
19
|
+
return new Intl.NumberFormat(resolvedLocale, {
|
|
20
|
+
style: "currency",
|
|
21
|
+
currency,
|
|
22
|
+
minimumFractionDigits: Number.isInteger(amount) ? 0 : 2,
|
|
23
|
+
maximumFractionDigits: 2
|
|
24
|
+
}).format(amount);
|
|
25
|
+
} catch {
|
|
26
|
+
return `${amount} ${currency}`;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// src/analytics.ts
|
|
31
|
+
var GA4_NAME_MAP = {
|
|
32
|
+
newsletter_signup: "generate_lead"
|
|
33
|
+
};
|
|
34
|
+
function trackEcommerceEvent(event, payload) {
|
|
35
|
+
if (typeof window === "undefined") return;
|
|
36
|
+
const w = window;
|
|
37
|
+
try {
|
|
38
|
+
w.__behioEcommerceSink?.(event, payload);
|
|
39
|
+
} catch {
|
|
40
|
+
}
|
|
41
|
+
const gaName = GA4_NAME_MAP[event] ?? event;
|
|
42
|
+
try {
|
|
43
|
+
if (typeof w.gtag === "function") {
|
|
44
|
+
w.gtag("event", gaName, payload);
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
if (Array.isArray(w.dataLayer)) {
|
|
48
|
+
w.dataLayer.push({ ecommerce: null });
|
|
49
|
+
w.dataLayer.push({ event: gaName, ecommerce: payload });
|
|
50
|
+
}
|
|
51
|
+
} catch {
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// src/consent-visitor.ts
|
|
56
|
+
var VISITOR_KEY = "behio_visitor_id";
|
|
57
|
+
var COOKIE_MAX_AGE = 60 * 60 * 24 * 365;
|
|
58
|
+
function getStoredVisitorId() {
|
|
59
|
+
if (typeof window === "undefined") return null;
|
|
60
|
+
try {
|
|
61
|
+
const ls = localStorage.getItem(VISITOR_KEY);
|
|
62
|
+
if (ls) return ls;
|
|
63
|
+
} catch {
|
|
64
|
+
}
|
|
65
|
+
return readCookie(VISITOR_KEY);
|
|
66
|
+
}
|
|
67
|
+
function generateVisitorId() {
|
|
68
|
+
const bytes = new Uint8Array(18);
|
|
69
|
+
try {
|
|
70
|
+
globalThis.crypto?.getRandomValues?.(bytes);
|
|
71
|
+
} catch {
|
|
72
|
+
}
|
|
73
|
+
let filled = false;
|
|
74
|
+
for (const b of bytes) if (b !== 0) filled = true;
|
|
75
|
+
if (!filled) for (let i = 0; i < bytes.length; i++) bytes[i] = Math.floor(Math.random() * 256);
|
|
76
|
+
let bin = "";
|
|
77
|
+
for (const b of bytes) bin += String.fromCharCode(b);
|
|
78
|
+
const b64 = typeof btoa === "function" ? btoa(bin) : Buffer.from(bytes).toString("base64");
|
|
79
|
+
return `v${b64.replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "")}`.slice(0, 40);
|
|
80
|
+
}
|
|
81
|
+
function writeVisitorId(id) {
|
|
82
|
+
if (typeof window === "undefined") return;
|
|
83
|
+
try {
|
|
84
|
+
localStorage.setItem(VISITOR_KEY, id);
|
|
85
|
+
} catch {
|
|
86
|
+
}
|
|
87
|
+
try {
|
|
88
|
+
document.cookie = `${VISITOR_KEY}=${encodeURIComponent(id)}; path=/; max-age=${COOKIE_MAX_AGE}; SameSite=Lax`;
|
|
89
|
+
} catch {
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
function readCookie(name) {
|
|
93
|
+
if (typeof document === "undefined") return null;
|
|
94
|
+
const match = document.cookie.match(new RegExp(`(?:^|; )${name}=([^;]*)`));
|
|
95
|
+
return match ? decodeURIComponent(match[1]) : null;
|
|
96
|
+
}
|
|
97
|
+
function emitConsentChanged() {
|
|
98
|
+
if (typeof window === "undefined") return;
|
|
99
|
+
try {
|
|
100
|
+
window.dispatchEvent(new Event("behio:consent-changed"));
|
|
101
|
+
} catch {
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
async function grantAnalyticsConsent(client, categories) {
|
|
105
|
+
const id = getStoredVisitorId() ?? generateVisitorId();
|
|
106
|
+
writeVisitorId(id);
|
|
107
|
+
client.setAnalyticsVisitorId(id);
|
|
108
|
+
const res = await client.consent.record({
|
|
109
|
+
visitorId: id,
|
|
110
|
+
analytics: true,
|
|
111
|
+
marketing: categories?.marketing ?? false,
|
|
112
|
+
preferences: categories?.preferences ?? false
|
|
113
|
+
});
|
|
114
|
+
emitConsentChanged();
|
|
115
|
+
return res;
|
|
116
|
+
}
|
|
117
|
+
async function revokeAnalyticsConsent(client) {
|
|
118
|
+
const id = getStoredVisitorId();
|
|
119
|
+
client.setAnalyticsVisitorId(null);
|
|
120
|
+
emitConsentChanged();
|
|
121
|
+
if (!id) return { data: { success: true }, error: null };
|
|
122
|
+
return client.consent.revoke(id);
|
|
123
|
+
}
|
|
22
124
|
export {
|
|
23
125
|
AddressTypes,
|
|
24
126
|
BehioApiError,
|
package/dist/next.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { n as BehioStorefrontConfig, B as BehioStorefront } from './client-sN7fZvjG.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 { n as BehioStorefrontConfig, B as BehioStorefront } from './client-sN7fZvjG.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 _chunk3TPJG2WVjs = require('./chunk-3TPJG2WV.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, _chunk3TPJG2WVjs.BehioStorefront)({
|
|
22
22
|
apiKey,
|
|
23
23
|
...baseUrl ? { baseUrl } : {},
|
|
24
24
|
...locale ? { locale } : {},
|