@frak-labs/components 1.0.13 → 1.1.0-beta.41fca73f
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/cdn/Banner.DGYexiiS.js +183 -0
- package/cdn/ButtonShare.DFg0XCDd.js +1 -0
- package/cdn/ButtonWallet.sGDvcAXt.js +40 -0
- package/cdn/{GiftIcon.DcyE1R1V.js → GiftIcon.C1uAOx7A.js} +1 -1
- package/cdn/OpenInAppButton.CxLPpqFO.js +1 -0
- package/cdn/PostPurchase.D6Mzbjtu.js +89 -0
- package/cdn/components.js +1 -1
- package/cdn/defaults.BEvoSiy5.js +58 -0
- package/cdn/embeddedWallet.BjQSXLkP.js +1 -0
- package/cdn/loader.js +164 -1
- package/cdn/replay-V6FXES7X.CgBxdfNp.js +1 -0
- package/cdn/rewards.B2smvfIs.js +1 -0
- package/cdn/useGlobalComponents.CqTI84Mw.js +1 -0
- package/cdn/useLightDomStyles.CKtA4k-_.js +1 -0
- package/cdn/useReward.CXgeQcsH.js +1 -0
- package/dist/banner.d.ts +10 -2
- package/dist/banner.js +14 -12
- package/dist/buttonShare.d.ts +19 -2
- package/dist/buttonShare.js +23 -12
- package/dist/buttonWallet.js +2 -2
- package/dist/openInApp.js +2 -2
- package/dist/postPurchase.d.ts +5 -10
- package/dist/postPurchase.js +22 -14
- package/dist/rewards-Cxn-bgzC.js +293 -0
- package/dist/{useGlobalComponents-Da9LDlRy.js → useGlobalComponents-CeTO2xYs.js} +1 -1
- package/dist/{useLightDomStyles-DRkTVy4s.js → useLightDomStyles-B2U96tzU.js} +1 -1
- package/dist/{usePlacement-NZOjZ6IR.js → usePlacement-Bpo25qjA.js} +2 -108
- package/dist/{useReward-B-yZ7nhY.js → useReward-BMYSGY-o.js} +10 -5
- package/package.json +31 -19
- package/cdn/Banner.BM-XicfW.js +0 -183
- package/cdn/ButtonShare.DsCfkEG1.js +0 -1
- package/cdn/ButtonWallet.BQt3QmKr.js +0 -40
- package/cdn/OpenInAppButton.BIfTfSWS.js +0 -1
- package/cdn/PostPurchase.Bcnzehoo.js +0 -89
- package/cdn/actions-CMPlZ7CH.CJIqArwi.js +0 -1
- package/cdn/clientReady.ClcVd4_w.js +0 -1
- package/cdn/defaults.CIT5-NpH.js +0 -58
- package/cdn/embeddedWallet.BXl45f3Y.js +0 -1
- package/cdn/replay-V6FXES7X.efKsNT6s.js +0 -1
- package/cdn/rewards.CW3JGWuC.js +0 -1
- package/cdn/sharedBaseCss.css.BDzFcWnD.js +0 -154
- package/cdn/sharingPage.BjReoj_N.js +0 -1
- package/cdn/sharingPageProducts.BoDmfrdn.js +0 -1
- package/cdn/styleManager.Cun1-fKi.js +0 -1
- package/cdn/useGlobalComponents.DqV5lr6s.js +0 -1
- package/cdn/useLightDomStyles.BsQue5kI.js +0 -1
- package/cdn/useReward.CcsZ70zp.js +0 -1
- package/dist/rewards-BtPHdGcI.js +0 -149
package/dist/buttonWallet.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { i as useLang, n as buildStyleContent, o as useClientReady, s as registerWebComponent, t as usePlacement } from "./usePlacement-
|
|
1
|
+
import { i as useLang, n as buildStyleContent, o as useClientReady, s as registerWebComponent, t as usePlacement } from "./usePlacement-Bpo25qjA.js";
|
|
2
2
|
import { t as openEmbeddedWallet } from "./embeddedWallet-CxgyuwtP.js";
|
|
3
|
-
import { t as useReward } from "./useReward-
|
|
3
|
+
import { t as useReward } from "./useReward-BMYSGY-o.js";
|
|
4
4
|
import { componentDefaults } from "./i18n/defaults.js";
|
|
5
5
|
import { useEffect, useMemo, useState } from "preact/hooks";
|
|
6
6
|
import { Fragment, jsx, jsxs } from "preact/jsx-runtime";
|
package/dist/openInApp.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { i as useLang, o as useClientReady, s as registerWebComponent, t as usePlacement } from "./usePlacement-
|
|
2
|
-
import { t as useLightDomStyles } from "./useLightDomStyles-
|
|
1
|
+
import { i as useLang, o as useClientReady, s as registerWebComponent, t as usePlacement } from "./usePlacement-Bpo25qjA.js";
|
|
2
|
+
import { t as useLightDomStyles } from "./useLightDomStyles-B2U96tzU.js";
|
|
3
3
|
import { componentDefaults } from "./i18n/defaults.js";
|
|
4
4
|
import { DEEP_LINK_SCHEME, isMobile, trackEvent, triggerDeepLinkWithFallback } from "@frak-labs/core-sdk";
|
|
5
5
|
import { useMemo } from "preact/hooks";
|
package/dist/postPurchase.d.ts
CHANGED
|
@@ -68,17 +68,12 @@ type PostPurchaseProps = {
|
|
|
68
68
|
*/
|
|
69
69
|
imageUrl?: string;
|
|
70
70
|
/**
|
|
71
|
-
*
|
|
72
|
-
*
|
|
73
|
-
*
|
|
74
|
-
* `el.products = [...]`) or a JSON-stringified array (when set as an
|
|
75
|
-
* HTML attribute, `<frak-post-purchase products='[...]'>`). The HTML
|
|
76
|
-
* attribute path is required for server-rendered surfaces — e.g.
|
|
77
|
-
* WooCommerce / Magento plugins — because `preact-custom-element`
|
|
78
|
-
* delivers attribute values as raw strings.
|
|
71
|
+
* Order line items, forwarded to the sharing page as product cards on CTA
|
|
72
|
+
* click, and used to prefer a campaign whose `productScope` matches one of
|
|
73
|
+
* the purchased items when picking the reward to advertise.
|
|
79
74
|
*
|
|
80
|
-
*
|
|
81
|
-
*
|
|
75
|
+
* Accepts a {@link SharingPageProduct} array (JS property) or a
|
|
76
|
+
* JSON-stringified array (HTML attribute, used by server-rendered plugins).
|
|
82
77
|
*/
|
|
83
78
|
products?: SharingPageProduct[] | string;
|
|
84
79
|
/**
|
package/dist/postPurchase.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { c as
|
|
2
|
-
import { t as useGlobalComponents } from "./useGlobalComponents-
|
|
3
|
-
import { t as useLightDomStyles } from "./useLightDomStyles-
|
|
4
|
-
import { i as
|
|
1
|
+
import { c as openSharingPage, i as useLang, o as useClientReady, s as registerWebComponent, t as usePlacement } from "./usePlacement-Bpo25qjA.js";
|
|
2
|
+
import { t as useGlobalComponents } from "./useGlobalComponents-CeTO2xYs.js";
|
|
3
|
+
import { t as useLightDomStyles } from "./useLightDomStyles-B2U96tzU.js";
|
|
4
|
+
import { i as w, n as K, t as C } from "./rewards-Cxn-bgzC.js";
|
|
5
5
|
import { componentDefaults } from "./i18n/defaults.js";
|
|
6
6
|
import { i as LogoFrakWithName, n as cssSource$2, t as GiftIcon } from "./GiftIcon-BhL0bhVu.js";
|
|
7
|
-
import { trackEvent } from "@frak-labs/core-sdk";
|
|
7
|
+
import { sanitizeSharingProducts, trackEvent } from "@frak-labs/core-sdk";
|
|
8
8
|
import { getMerchantInformation, getUserReferralStatus, trackPurchaseStatus } from "@frak-labs/core-sdk/actions";
|
|
9
9
|
import { useCallback, useEffect, useMemo, useRef, useState } from "preact/hooks";
|
|
10
10
|
import { jsx, jsxs } from "preact/jsx-runtime";
|
|
@@ -117,12 +117,13 @@ const cssSource = cssSource$1;
|
|
|
117
117
|
* Given referral status and merchant info, compute the display variant
|
|
118
118
|
* and pick the appropriate purchase reward.
|
|
119
119
|
*/
|
|
120
|
-
function resolvePostPurchaseContext(referralStatus, merchantInfo, currency) {
|
|
120
|
+
function resolvePostPurchaseContext(referralStatus, merchantInfo, currency, products) {
|
|
121
121
|
const audience = referralStatus?.isReferred ? "referee" : "referrer";
|
|
122
|
-
const selected =
|
|
122
|
+
const selected = K(merchantInfo.rewards, {
|
|
123
123
|
targetInteraction: "purchase",
|
|
124
124
|
currency,
|
|
125
|
-
audience
|
|
125
|
+
audience,
|
|
126
|
+
products
|
|
126
127
|
});
|
|
127
128
|
if (!selected) return null;
|
|
128
129
|
const { campaign } = selected;
|
|
@@ -166,8 +167,9 @@ function PostPurchase({ customerId, orderId, token, sharingUrl, merchantId, plac
|
|
|
166
167
|
const { shouldRender, isHidden, isClientReady } = useClientReady();
|
|
167
168
|
const placement = usePlacement(placementId);
|
|
168
169
|
const lang = useLang();
|
|
170
|
+
const parsedProducts = useMemo(() => sanitizeSharingProducts(products), [products]);
|
|
169
171
|
useLightDomStyles("frak-post-purchase", placementId, placement?.components?.postPurchase?.css, cssSource, cssSource$2);
|
|
170
|
-
const [
|
|
172
|
+
const [fetched, setFetched] = useState(null);
|
|
171
173
|
const [hasFetched, setHasFetched] = useState(false);
|
|
172
174
|
useEffect(() => {
|
|
173
175
|
if (isPreview) return;
|
|
@@ -193,7 +195,10 @@ function PostPurchase({ customerId, orderId, token, sharingUrl, merchantId, plac
|
|
|
193
195
|
if (!client) return;
|
|
194
196
|
Promise.all([getUserReferralStatus(client), getMerchantInformation(client)]).then(([referralStatus, merchantInfo]) => {
|
|
195
197
|
setHasFetched(true);
|
|
196
|
-
|
|
198
|
+
setFetched({
|
|
199
|
+
referralStatus,
|
|
200
|
+
merchantInfo
|
|
201
|
+
});
|
|
197
202
|
}).catch((e) => {
|
|
198
203
|
if (e instanceof FrakRpcError && e.code === RpcErrorCodes.configError) {
|
|
199
204
|
setHasFetched(true);
|
|
@@ -206,13 +211,17 @@ function PostPurchase({ customerId, orderId, token, sharingUrl, merchantId, plac
|
|
|
206
211
|
isClientReady,
|
|
207
212
|
hasFetched
|
|
208
213
|
]);
|
|
214
|
+
const context = useMemo(() => {
|
|
215
|
+
if (!fetched) return null;
|
|
216
|
+
return resolvePostPurchaseContext(fetched.referralStatus, fetched.merchantInfo, window.FrakSetup?.client?.config?.metadata?.currency, parsedProducts);
|
|
217
|
+
}, [fetched, parsedProducts]);
|
|
209
218
|
const trackedImpressionVariantRef = useRef(null);
|
|
210
219
|
const resolvedVariant = forcedVariant ?? context?.variant ?? (isPreview ? previewVariant ?? "referrer" : void 0);
|
|
211
220
|
const resolvedSharingUrl = sharingUrl ?? context?.merchantDomain;
|
|
212
221
|
const rewardText = useMemo(() => {
|
|
213
222
|
if (!context?.reward) return void 0;
|
|
214
223
|
const currency = window.FrakSetup?.client?.config?.metadata?.currency;
|
|
215
|
-
return
|
|
224
|
+
return C(context.reward, currency);
|
|
216
225
|
}, [context?.reward]);
|
|
217
226
|
const globalComponents = useGlobalComponents();
|
|
218
227
|
const postPurchaseConfig = placement?.components?.postPurchase ?? globalComponents?.postPurchase;
|
|
@@ -221,8 +230,8 @@ function PostPurchase({ customerId, orderId, token, sharingUrl, merchantId, plac
|
|
|
221
230
|
const texts = useMemo(() => {
|
|
222
231
|
const defaults = componentDefaults[lang].postPurchase;
|
|
223
232
|
return {
|
|
224
|
-
message: resolvedVariant === "referee" ? rewardText ?
|
|
225
|
-
cta: rewardText ?
|
|
233
|
+
message: resolvedVariant === "referee" ? rewardText ? w(propRefereeText ?? postPurchaseConfig?.refereeText ?? defaults.refereeText, rewardText) : propRefereeText ?? postPurchaseConfig?.refereeNoRewardText ?? defaults.refereeNoRewardText : rewardText ? w(propReferrerText ?? postPurchaseConfig?.referrerText ?? defaults.referrerText, rewardText) : propReferrerText ?? postPurchaseConfig?.referrerNoRewardText ?? defaults.referrerNoRewardText,
|
|
234
|
+
cta: rewardText ? w(propCtaText ?? postPurchaseConfig?.ctaText ?? defaults.ctaText, rewardText) : propCtaText ?? postPurchaseConfig?.ctaNoRewardText ?? defaults.ctaNoRewardText
|
|
226
235
|
};
|
|
227
236
|
}, [
|
|
228
237
|
lang,
|
|
@@ -253,7 +262,6 @@ function PostPurchase({ customerId, orderId, token, sharingUrl, merchantId, plac
|
|
|
253
262
|
placementId,
|
|
254
263
|
context?.reward
|
|
255
264
|
]);
|
|
256
|
-
const parsedProducts = useMemo(() => sanitizeProductList(products), [products]);
|
|
257
265
|
const handleClick = useCallback(() => {
|
|
258
266
|
if (!resolvedVariant) return;
|
|
259
267
|
trackEvent(window.FrakSetup?.client, "post_purchase_clicked", {
|
|
@@ -0,0 +1,293 @@
|
|
|
1
|
+
//#region ../core/dist/getCurrencyAmountKey-hkn17KxN.js
|
|
2
|
+
const e = {
|
|
3
|
+
eur: `fr-FR`,
|
|
4
|
+
usd: `en-US`,
|
|
5
|
+
gbp: `en-GB`
|
|
6
|
+
};
|
|
7
|
+
function t(t) {
|
|
8
|
+
return t && t in e ? t : `eur`;
|
|
9
|
+
}
|
|
10
|
+
function n(t) {
|
|
11
|
+
return t ? e[t] ?? e.eur : e.eur;
|
|
12
|
+
}
|
|
13
|
+
function r(e, r) {
|
|
14
|
+
let i = n(r), a = t(r);
|
|
15
|
+
return e.toLocaleString(i, {
|
|
16
|
+
style: `currency`,
|
|
17
|
+
currency: a,
|
|
18
|
+
minimumFractionDigits: 0,
|
|
19
|
+
maximumFractionDigits: 2
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
function i(e) {
|
|
23
|
+
return e.formatToParts(1.1).find((e) => e.type === `decimal`)?.value ?? `.`;
|
|
24
|
+
}
|
|
25
|
+
function a$1(e, r) {
|
|
26
|
+
let a = n(r), o = t(r), s = new Intl.NumberFormat(a, {
|
|
27
|
+
style: `currency`,
|
|
28
|
+
currency: o,
|
|
29
|
+
minimumFractionDigits: 0,
|
|
30
|
+
maximumFractionDigits: 2
|
|
31
|
+
}), c = s.formatToParts(e), l = ``, u = ``, d = ``, f = `suffix`, p = !1;
|
|
32
|
+
for (let e of c) switch (e.type) {
|
|
33
|
+
case `integer`:
|
|
34
|
+
case `group`:
|
|
35
|
+
l += e.value, p = !0;
|
|
36
|
+
break;
|
|
37
|
+
case `decimal`:
|
|
38
|
+
case `fraction`:
|
|
39
|
+
u += e.value;
|
|
40
|
+
break;
|
|
41
|
+
case `currency`:
|
|
42
|
+
d = e.value, f = p ? `suffix` : `prefix`;
|
|
43
|
+
break;
|
|
44
|
+
default: break;
|
|
45
|
+
}
|
|
46
|
+
return {
|
|
47
|
+
integer: l,
|
|
48
|
+
decimals: u || `${i(s)}00`,
|
|
49
|
+
unit: d,
|
|
50
|
+
unitPosition: f
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
function o$1(e) {
|
|
54
|
+
return {
|
|
55
|
+
integer: String(e),
|
|
56
|
+
unit: `%`,
|
|
57
|
+
unitPosition: `suffix`
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
function s$1(e) {
|
|
61
|
+
return e ? `${e}Amount` : `eurAmount`;
|
|
62
|
+
}
|
|
63
|
+
//#endregion
|
|
64
|
+
//#region ../core/dist/rewards.js
|
|
65
|
+
function a(e) {
|
|
66
|
+
return Array.isArray(e) ? e : e.conditions;
|
|
67
|
+
}
|
|
68
|
+
function o(e) {
|
|
69
|
+
if (typeof e == `number`) return e;
|
|
70
|
+
if (typeof e == `string` && e.trim() !== ``) {
|
|
71
|
+
let t = Number(e);
|
|
72
|
+
return Number.isFinite(t) ? t : void 0;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
function s(e, t, n) {
|
|
76
|
+
let r = [];
|
|
77
|
+
for (let i of a(e)) {
|
|
78
|
+
if (`logic` in i) {
|
|
79
|
+
r.push(...s(i, t, n));
|
|
80
|
+
continue;
|
|
81
|
+
}
|
|
82
|
+
if (i.field === t && n.has(i.operator)) {
|
|
83
|
+
let e = o(i.value);
|
|
84
|
+
e != null && r.push(e);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
return r;
|
|
88
|
+
}
|
|
89
|
+
const c = /* @__PURE__ */ new Set([
|
|
90
|
+
`gt`,
|
|
91
|
+
`gte`,
|
|
92
|
+
`between`
|
|
93
|
+
]);
|
|
94
|
+
const l = /* @__PURE__ */ new Set([`gt`, `gte`]);
|
|
95
|
+
function u(e) {
|
|
96
|
+
let t = s(e, `purchase.amount`, c);
|
|
97
|
+
return t.length > 0 ? Math.min(...t) : void 0;
|
|
98
|
+
}
|
|
99
|
+
function d(e) {
|
|
100
|
+
let t = s(e, `time.timestamp`, l);
|
|
101
|
+
if (t.length !== 0) return /* @__PURE__ */ new Date(Math.min(...t) * 1e3);
|
|
102
|
+
}
|
|
103
|
+
function _(e, t) {
|
|
104
|
+
switch (e.payoutType) {
|
|
105
|
+
case `fixed`: return e.amount[t];
|
|
106
|
+
case `percentage`: return e.maxAmount?.[t] ?? 0;
|
|
107
|
+
case `tiered`: return e.tiers.reduce((e, n) => `amount` in n ? Math.max(e, n.amount[t]) : e, 0);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
function v(e) {
|
|
111
|
+
return e.payoutType === `percentage` ? e.percent : e.payoutType === `tiered` ? e.tiers.reduce((e, t) => `percent` in t ? Math.max(e, t.percent) : e, 0) : 0;
|
|
112
|
+
}
|
|
113
|
+
function y(e, t) {
|
|
114
|
+
let n = _(e, t);
|
|
115
|
+
return n > 0 ? n : v(e) * 1e-6;
|
|
116
|
+
}
|
|
117
|
+
function x(n, r$1) {
|
|
118
|
+
let a = t(r$1), o = s$1(a);
|
|
119
|
+
switch (n.payoutType) {
|
|
120
|
+
case `fixed`: return r(Math.round(n.amount[o]), a);
|
|
121
|
+
case `percentage`: return `${n.percent} %`;
|
|
122
|
+
case `tiered`: {
|
|
123
|
+
let e = _(n, o);
|
|
124
|
+
if (e > 0) return r(Math.round(e), a);
|
|
125
|
+
let r$2 = v(n);
|
|
126
|
+
return r$2 > 0 ? `${r$2} %` : r(0, a);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
function S(t$1, a) {
|
|
131
|
+
let o = t(a), s = s$1(o);
|
|
132
|
+
switch (t$1.payoutType) {
|
|
133
|
+
case `fixed`: return a$1(Math.round(t$1.amount[s]), o);
|
|
134
|
+
case `percentage`: return o$1(t$1.percent);
|
|
135
|
+
case `tiered`: {
|
|
136
|
+
let e = _(t$1, s);
|
|
137
|
+
if (e > 0) return a$1(Math.round(e), o);
|
|
138
|
+
let i = v(t$1);
|
|
139
|
+
return i > 0 ? o$1(i) : a$1(0, o);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
function C(t$2, n) {
|
|
144
|
+
if (t$2 && !(y(t$2, s$1(t(n))) <= 0)) return x(t$2, n);
|
|
145
|
+
}
|
|
146
|
+
function w(e, t) {
|
|
147
|
+
return t ? e.replaceAll(`{REWARD}`, t) : e.replaceAll(`{REWARD}`, ``);
|
|
148
|
+
}
|
|
149
|
+
const T = /* @__PURE__ */ new Set([
|
|
150
|
+
`eq`,
|
|
151
|
+
`neq`,
|
|
152
|
+
`gt`,
|
|
153
|
+
`gte`,
|
|
154
|
+
`lt`,
|
|
155
|
+
`lte`,
|
|
156
|
+
`between`
|
|
157
|
+
]);
|
|
158
|
+
const D = /* @__PURE__ */ new Set([
|
|
159
|
+
`contains`,
|
|
160
|
+
`starts_with`,
|
|
161
|
+
`ends_with`
|
|
162
|
+
]);
|
|
163
|
+
function A(e) {
|
|
164
|
+
return `logic` in e && `conditions` in e;
|
|
165
|
+
}
|
|
166
|
+
function j(e, t) {
|
|
167
|
+
return e[t];
|
|
168
|
+
}
|
|
169
|
+
function M(e) {
|
|
170
|
+
if (typeof e == `number`) return Number.isFinite(e) ? e : void 0;
|
|
171
|
+
if (typeof e == `string` && e.trim() !== ``) {
|
|
172
|
+
let t = Number(e);
|
|
173
|
+
return Number.isFinite(t) ? t : void 0;
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
function N(e, t) {
|
|
177
|
+
let n = M(e), r = M(t);
|
|
178
|
+
return n !== void 0 && r !== void 0 ? n - r : String(e).localeCompare(String(t));
|
|
179
|
+
}
|
|
180
|
+
function P(e, t, n) {
|
|
181
|
+
if (!Array.isArray(n)) return e === `not_in`;
|
|
182
|
+
if (t === void 0) return;
|
|
183
|
+
let r = n.includes(t);
|
|
184
|
+
return e === `in` ? r : !r;
|
|
185
|
+
}
|
|
186
|
+
function F(e, t, n, r) {
|
|
187
|
+
switch (e) {
|
|
188
|
+
case `eq`: return t === n;
|
|
189
|
+
case `neq`: return t !== n;
|
|
190
|
+
case `gt`: return N(t, n) > 0;
|
|
191
|
+
case `gte`: return N(t, n) >= 0;
|
|
192
|
+
case `lt`: return N(t, n) < 0;
|
|
193
|
+
case `lte`: return N(t, n) <= 0;
|
|
194
|
+
case `between`: return r == null || Array.isArray(r) ? void 0 : N(t, n) >= 0 && N(t, r) <= 0;
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
function I(e, t, n) {
|
|
198
|
+
if (typeof t == `string` && typeof n == `string`) return e === `contains` ? t.includes(n) : e === `starts_with` ? t.startsWith(n) : t.endsWith(n);
|
|
199
|
+
}
|
|
200
|
+
function L(e, t) {
|
|
201
|
+
let n = j(t, e.field), { operator: r, value: i, valueTo: a } = e;
|
|
202
|
+
if (r === `exists`) return n !== void 0;
|
|
203
|
+
if (r === `not_exists`) return n === void 0;
|
|
204
|
+
if (r === `in` || r === `not_in`) return P(r, n, i);
|
|
205
|
+
if (!(Array.isArray(i) || n === void 0 || i === null)) {
|
|
206
|
+
if (T.has(r)) return F(r, n, i, a);
|
|
207
|
+
if (D.has(r)) return I(r, n, i);
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
function R(e, t) {
|
|
211
|
+
if (A(e)) {
|
|
212
|
+
let n = e.conditions.map((e) => R(e, t));
|
|
213
|
+
return e.logic === `all` ? n.every(Boolean) : e.logic === `any` ? n.some(Boolean) : e.logic !== `none` || !n.some(Boolean);
|
|
214
|
+
}
|
|
215
|
+
return L(e, t) ?? !0;
|
|
216
|
+
}
|
|
217
|
+
function z(e, t) {
|
|
218
|
+
return e ? Array.isArray(e) ? e.every((e) => R(e, t)) : R(e, t) : !0;
|
|
219
|
+
}
|
|
220
|
+
function B(e, t) {
|
|
221
|
+
return e.expiresAt != null && new Date(e.expiresAt).getTime() <= t;
|
|
222
|
+
}
|
|
223
|
+
function V(e, t) {
|
|
224
|
+
let n = d(e.conditions);
|
|
225
|
+
return n == null || n.getTime() <= t;
|
|
226
|
+
}
|
|
227
|
+
function H(e, t) {
|
|
228
|
+
return t === `referee` ? e.referee : e.referrer;
|
|
229
|
+
}
|
|
230
|
+
function U(e, t, n) {
|
|
231
|
+
let r = H(e, n);
|
|
232
|
+
return r ? y(r, t) : 0;
|
|
233
|
+
}
|
|
234
|
+
function W(e, t) {
|
|
235
|
+
if (!t || t.length === 0 || !e.productScope) return;
|
|
236
|
+
let n = t.filter((t) => z(e.productScope, t));
|
|
237
|
+
return n.length > 0 ? n : void 0;
|
|
238
|
+
}
|
|
239
|
+
function G(e, t) {
|
|
240
|
+
return !t || t.length === 0 || !e.productScope || t.some((t) => z(e.productScope, t));
|
|
241
|
+
}
|
|
242
|
+
function K(t$3, n = {}) {
|
|
243
|
+
let r = (n.now ?? /* @__PURE__ */ new Date()).getTime(), a = n.audience ?? `referrer`, o = s$1(t(n.currency)), s = (n.targetInteraction ? t$3.filter((e) => e.interactionTypeKey === n.targetInteraction) : t$3).filter((e) => !B(e, r)), c = s.filter((e) => V(e, r));
|
|
244
|
+
if (c.length > 0) {
|
|
245
|
+
let e = c.reduce((e, t) => {
|
|
246
|
+
let r = G(e, n.products), i = G(t, n.products);
|
|
247
|
+
return r === i ? U(t, o, a) > U(e, o, a) ? t : e : i ? t : e;
|
|
248
|
+
});
|
|
249
|
+
return {
|
|
250
|
+
campaign: e,
|
|
251
|
+
status: `live`,
|
|
252
|
+
matchedProducts: W(e, n.products)
|
|
253
|
+
};
|
|
254
|
+
}
|
|
255
|
+
let l = s.map((e) => ({
|
|
256
|
+
campaign: e,
|
|
257
|
+
startsAt: d(e.conditions)
|
|
258
|
+
})).filter((e) => e.startsAt != null);
|
|
259
|
+
if (l.length === 0) return;
|
|
260
|
+
let u = l.reduce((e, t) => {
|
|
261
|
+
let r = G(e.campaign, n.products), i = G(t.campaign, n.products);
|
|
262
|
+
return r === i ? t.startsAt.getTime() < e.startsAt.getTime() ? t : e : i ? t : e;
|
|
263
|
+
});
|
|
264
|
+
return {
|
|
265
|
+
campaign: u.campaign,
|
|
266
|
+
status: `upcoming`,
|
|
267
|
+
startsAt: u.startsAt,
|
|
268
|
+
matchedProducts: W(u.campaign, n.products)
|
|
269
|
+
};
|
|
270
|
+
}
|
|
271
|
+
function q(e, n = {}) {
|
|
272
|
+
let r$3 = K(e, n);
|
|
273
|
+
if (!r$3) return;
|
|
274
|
+
let i = H(r$3.campaign, n.audience ?? `referrer`);
|
|
275
|
+
if (!i) return;
|
|
276
|
+
let a = C(i, n.currency);
|
|
277
|
+
if (!a) return;
|
|
278
|
+
let o = u(r$3.campaign.conditions), s = o == null ? void 0 : r(o, n.currency), c = r$3.campaign.defaultLockupSeconds, l = c && c > 0 ? Math.round(c / 86400) : void 0;
|
|
279
|
+
return {
|
|
280
|
+
formatted: a,
|
|
281
|
+
parts: S(i, n.currency),
|
|
282
|
+
payoutType: i.payoutType,
|
|
283
|
+
minPurchaseAmount: s,
|
|
284
|
+
lockupDurationDays: l,
|
|
285
|
+
referrerReward: r$3.campaign.referrer,
|
|
286
|
+
refereeReward: r$3.campaign.referee,
|
|
287
|
+
minPurchaseValue: o ?? void 0,
|
|
288
|
+
isProductScoped: r$3.campaign.productScope != null,
|
|
289
|
+
matchedProducts: r$3.matchedProducts
|
|
290
|
+
};
|
|
291
|
+
}
|
|
292
|
+
//#endregion
|
|
293
|
+
export { w as i, K as n, q as r, C as t };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as subscribeSdkConfig } from "./usePlacement-
|
|
1
|
+
import { a as subscribeSdkConfig } from "./usePlacement-Bpo25qjA.js";
|
|
2
2
|
import { sdkConfigStore } from "@frak-labs/core-sdk";
|
|
3
3
|
import { useSyncExternalStore } from "preact/compat";
|
|
4
4
|
//#region src/hooks/useGlobalComponents.ts
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import register from "preact-custom-element";
|
|
2
2
|
import * as coreSdkIndex from "@frak-labs/core-sdk";
|
|
3
|
-
import {
|
|
3
|
+
import { decodeProductsParam, deleteQueryParamCaseInsensitive, detectPageLanguage, getQueryParamCaseInsensitive, sdkConfigStore, setupClient, trackEvent, withCache } from "@frak-labs/core-sdk";
|
|
4
4
|
import * as coreSdkActions from "@frak-labs/core-sdk/actions";
|
|
5
5
|
import { displaySharingPage } from "@frak-labs/core-sdk/actions";
|
|
6
6
|
import { useCallback, useEffect, useState } from "preact/hooks";
|
|
@@ -55,112 +55,6 @@ function detectListenerPreloads() {
|
|
|
55
55
|
return document.querySelector(FRAK_COMPONENT_SELECTOR) !== null ? ["sharing"] : [];
|
|
56
56
|
}
|
|
57
57
|
//#endregion
|
|
58
|
-
//#region src/utils/sharingPageProducts.ts
|
|
59
|
-
/**
|
|
60
|
-
* Whether `value` is a syntactically valid URL with an `http(s):` scheme.
|
|
61
|
-
*
|
|
62
|
-
* Used to gate `imageUrl` / `link` fields coming from untrusted inputs (the
|
|
63
|
-
* public `products` prop on `<frak-post-purchase>`, decoded query params for
|
|
64
|
-
* Klaviyo / email share links, etc.) — the listener-side sharing-page builder
|
|
65
|
-
* calls `new URL(...)` on the incoming product link, and a `javascript:` URL
|
|
66
|
-
* would be a XSS sink in any consumer that binds the value to an `href`.
|
|
67
|
-
*/
|
|
68
|
-
function isHttpUrl(value) {
|
|
69
|
-
try {
|
|
70
|
-
const parsed = new URL(value);
|
|
71
|
-
return parsed.protocol === "http:" || parsed.protocol === "https:";
|
|
72
|
-
} catch {
|
|
73
|
-
return false;
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
/**
|
|
77
|
-
* Coerce a raw `products` value into a candidate array suitable for
|
|
78
|
-
* per-item normalisation, or null when it cannot be reduced to one.
|
|
79
|
-
*
|
|
80
|
-
* Accepts:
|
|
81
|
-
* - Real arrays (JS-property surface, decompressed query payloads).
|
|
82
|
-
* - JSON-stringified arrays (HTML-attribute surface — WP / Magento
|
|
83
|
-
* server-render delivers attribute values as raw strings).
|
|
84
|
-
*
|
|
85
|
-
* Anything else (non-array non-string, JSON parse failure, JSON that
|
|
86
|
-
* decodes to a non-array) is treated as "no products" so the share still
|
|
87
|
-
* works without the product card section.
|
|
88
|
-
*/
|
|
89
|
-
function coerceProductCandidates(products) {
|
|
90
|
-
if (!products) return null;
|
|
91
|
-
if (Array.isArray(products)) return products;
|
|
92
|
-
if (typeof products !== "string") return null;
|
|
93
|
-
try {
|
|
94
|
-
const parsed = JSON.parse(products);
|
|
95
|
-
return Array.isArray(parsed) ? parsed : null;
|
|
96
|
-
} catch {
|
|
97
|
-
return null;
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
/**
|
|
101
|
-
* Normalise one untrusted candidate into a {@link SharingPageProduct}, or
|
|
102
|
-
* return null when the candidate has no usable title.
|
|
103
|
-
*
|
|
104
|
-
* The `products` payload is a public API boundary — merchants can set it
|
|
105
|
-
* server-side via WP / Magento, imperatively from arbitrary JS, or via
|
|
106
|
-
* email-template query params built by Klaviyo. Each entry is validated
|
|
107
|
-
* structurally so a malformed `link` reaching `new URL(...)` downstream
|
|
108
|
-
* would not crash the sharing-page builder, and so a `javascript:` URL
|
|
109
|
-
* cannot slip through as `imageUrl` / `link`.
|
|
110
|
-
*/
|
|
111
|
-
function normalizeProductCandidate(candidate) {
|
|
112
|
-
if (!candidate || typeof candidate !== "object") return null;
|
|
113
|
-
const item = candidate;
|
|
114
|
-
const title = typeof item.title === "string" ? item.title.trim() : "";
|
|
115
|
-
if (title === "") return null;
|
|
116
|
-
const entry = { title };
|
|
117
|
-
if (typeof item.imageUrl === "string" && isHttpUrl(item.imageUrl)) entry.imageUrl = item.imageUrl;
|
|
118
|
-
if (typeof item.link === "string" && isHttpUrl(item.link)) entry.link = item.link;
|
|
119
|
-
if (typeof item.utmContent === "string" && item.utmContent !== "") entry.utmContent = item.utmContent;
|
|
120
|
-
return entry;
|
|
121
|
-
}
|
|
122
|
-
/**
|
|
123
|
-
* Pipe `coerceProductCandidates` + `normalizeProductCandidate` over an
|
|
124
|
-
* untrusted value and return a non-empty {@link SharingPageProduct}[] or
|
|
125
|
-
* `undefined` when nothing usable came out.
|
|
126
|
-
*
|
|
127
|
-
* The undefined sentinel is what `openSharingPage` / `displaySharingPage`
|
|
128
|
-
* expect when the caller has no products to show — the sharing page just
|
|
129
|
-
* skips the product card section.
|
|
130
|
-
*/
|
|
131
|
-
function sanitizeProductList(input) {
|
|
132
|
-
const candidates = coerceProductCandidates(input);
|
|
133
|
-
if (!candidates) return void 0;
|
|
134
|
-
const sanitized = [];
|
|
135
|
-
for (const candidate of candidates) {
|
|
136
|
-
const entry = normalizeProductCandidate(candidate);
|
|
137
|
-
if (entry) sanitized.push(entry);
|
|
138
|
-
}
|
|
139
|
-
return sanitized.length > 0 ? sanitized : void 0;
|
|
140
|
-
}
|
|
141
|
-
/**
|
|
142
|
-
* Decode a `products` URL query param produced by
|
|
143
|
-
* `compressJsonToB64(productsArray)` — the encoding Klaviyo (and any
|
|
144
|
-
* other email tool) uses when embedding the product list of an order
|
|
145
|
-
* confirmation into a Frak share CTA.
|
|
146
|
-
*
|
|
147
|
-
* The result is run through `sanitizeProductList` so every link / image
|
|
148
|
-
* URL is structurally validated before reaching `new URL(...)` downstream.
|
|
149
|
-
* Malformed / tampered payloads degrade gracefully to `undefined` — the
|
|
150
|
-
* share still works, just without the product card section.
|
|
151
|
-
*/
|
|
152
|
-
function decodeProductsParam(value) {
|
|
153
|
-
if (!value) return void 0;
|
|
154
|
-
let decoded;
|
|
155
|
-
try {
|
|
156
|
-
decoded = decompressJsonFromB64(value);
|
|
157
|
-
} catch {
|
|
158
|
-
return;
|
|
159
|
-
}
|
|
160
|
-
if (decoded === null) return void 0;
|
|
161
|
-
return sanitizeProductList(decoded);
|
|
162
|
-
}
|
|
163
|
-
//#endregion
|
|
164
58
|
//#region src/bootstrap/clientReady.ts
|
|
165
59
|
const CUSTOM_EVENT_NAME = "frak:client";
|
|
166
60
|
/**
|
|
@@ -456,4 +350,4 @@ function usePlacement(placementId) {
|
|
|
456
350
|
return useSyncExternalStore(subscribeSdkConfig, useCallback(() => placementId ? getPlacement(placementId) : void 0, [placementId]));
|
|
457
351
|
}
|
|
458
352
|
//#endregion
|
|
459
|
-
export { subscribeSdkConfig as a,
|
|
353
|
+
export { subscribeSdkConfig as a, openSharingPage as c, useLang as i, buildStyleContent as n, useClientReady as o, lightDomBaseCss as r, registerWebComponent as s, usePlacement as t };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { r as q } from "./rewards-Cxn-bgzC.js";
|
|
2
2
|
import { getMerchantInformation } from "@frak-labs/core-sdk/actions";
|
|
3
3
|
import { useEffect, useState } from "preact/hooks";
|
|
4
4
|
//#region src/hooks/useReward.ts
|
|
@@ -12,26 +12,31 @@ import { useEffect, useState } from "preact/hooks";
|
|
|
12
12
|
* @param shouldUseReward - Whether to fetch the reward at all
|
|
13
13
|
* @param targetInteraction - Optional filter by interaction type (e.g. "purchase")
|
|
14
14
|
* @param audience - Reward side to display: `"referrer"` (default) or `"referee"`
|
|
15
|
+
* @param products - The products currently in view, when known. Purely
|
|
16
|
+
* advisory (see `matchesProductScope`): deprioritizes campaigns matching none
|
|
17
|
+
* of them, and changes nothing when omitted.
|
|
15
18
|
* @returns Object containing the formatted reward string, or undefined if unavailable
|
|
16
19
|
*/
|
|
17
|
-
function useReward(shouldUseReward, targetInteraction, audience) {
|
|
20
|
+
function useReward(shouldUseReward, targetInteraction, audience, products) {
|
|
18
21
|
const [reward, setReward] = useState(void 0);
|
|
19
22
|
useEffect(() => {
|
|
20
23
|
if (!shouldUseReward) return;
|
|
21
24
|
const client = window.FrakSetup?.client;
|
|
22
25
|
if (!client) return;
|
|
23
26
|
getMerchantInformation(client).then((merchantInfo) => {
|
|
24
|
-
const best =
|
|
27
|
+
const best = q(merchantInfo.rewards, {
|
|
25
28
|
currency: client.config.metadata?.currency,
|
|
26
29
|
targetInteraction,
|
|
27
|
-
audience
|
|
30
|
+
audience,
|
|
31
|
+
products
|
|
28
32
|
});
|
|
29
33
|
if (best && best.payoutType !== "percentage") setReward(best.formatted);
|
|
30
34
|
}).catch(() => {});
|
|
31
35
|
}, [
|
|
32
36
|
shouldUseReward,
|
|
33
37
|
targetInteraction,
|
|
34
|
-
audience
|
|
38
|
+
audience,
|
|
39
|
+
products
|
|
35
40
|
]);
|
|
36
41
|
return { reward };
|
|
37
42
|
}
|