@frak-labs/components 1.0.13 → 1.1.0-beta.316053a3
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.wHYQSyz3.js +183 -0
- package/cdn/ButtonShare.DIyDUgaT.js +1 -0
- package/cdn/ButtonWallet.DNxaFMHH.js +40 -0
- package/cdn/{GiftIcon.DcyE1R1V.js → GiftIcon.DV54EwfG.js} +1 -1
- package/cdn/OpenInAppButton.X1noMnvq.js +1 -0
- package/cdn/PostPurchase._SYhdjOf.js +89 -0
- package/cdn/components.js +1 -1
- package/cdn/defaults.CT8FNvot.js +58 -0
- package/cdn/embeddedWallet.BjQSXLkP.js +1 -0
- package/cdn/loader.js +168 -1
- package/cdn/replay-V6FXES7X.CgBxdfNp.js +1 -0
- package/cdn/rewards.D3nh4aTd.js +1 -0
- package/cdn/useGlobalComponents.BT0loDl8.js +1 -0
- package/cdn/useLightDomStyles.CZ1iTaa9.js +1 -0
- package/cdn/useReward.DWHEt1Zs.js +1 -0
- package/dist/{GiftIcon-BhL0bhVu.js → GiftIcon-DI0rUKHp.js} +7 -7
- package/dist/banner.d.ts +10 -2
- package/dist/banner.js +15 -13
- package/dist/buttonShare.d.ts +19 -2
- package/dist/buttonShare.js +23 -12
- package/dist/buttonWallet.js +2 -2
- package/dist/openInApp.js +4 -3
- package/dist/postPurchase.d.ts +8 -11
- package/dist/postPurchase.js +29 -18
- package/dist/rewards-CZkWSndn.js +290 -0
- package/dist/{useGlobalComponents-Da9LDlRy.js → useGlobalComponents-DFv33ujB.js} +1 -1
- package/dist/{useLightDomStyles-DRkTVy4s.js → useLightDomStyles-B_IbOqJZ.js} +1 -1
- package/dist/{usePlacement-NZOjZ6IR.js → usePlacement-DtwWaLHO.js} +5 -109
- package/dist/{useReward-B-yZ7nhY.js → useReward-D5zzFR11.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/buttonShare.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { c as openSharingPage, i as useLang, o as useClientReady, s as registerWebComponent, t as usePlacement } from "./usePlacement-DtwWaLHO.js";
|
|
2
2
|
import { t as openEmbeddedWallet } from "./embeddedWallet-CxgyuwtP.js";
|
|
3
|
-
import { t as useGlobalComponents } from "./useGlobalComponents-
|
|
4
|
-
import { t as useLightDomStyles } from "./useLightDomStyles-
|
|
5
|
-
import {
|
|
6
|
-
import { t as useReward } from "./useReward-
|
|
3
|
+
import { t as useGlobalComponents } from "./useGlobalComponents-DFv33ujB.js";
|
|
4
|
+
import { t as useLightDomStyles } from "./useLightDomStyles-B_IbOqJZ.js";
|
|
5
|
+
import { i as w } from "./rewards-CZkWSndn.js";
|
|
6
|
+
import { t as useReward } from "./useReward-D5zzFR11.js";
|
|
7
7
|
import { componentDefaults } from "./i18n/defaults.js";
|
|
8
|
-
import { trackEvent } from "@frak-labs/core-sdk";
|
|
8
|
+
import { sanitizeSharingProducts, trackEvent } from "@frak-labs/core-sdk";
|
|
9
9
|
import { useCallback, useMemo } from "preact/hooks";
|
|
10
10
|
import { jsx } from "preact/jsx-runtime";
|
|
11
11
|
//#region src/components/ButtonShare/ButtonShare.tsx
|
|
@@ -50,10 +50,18 @@ import { jsx } from "preact/jsx-runtime";
|
|
|
50
50
|
* <frak-button-share text="Share and earn up to {REWARD}!" no-reward-text="Share and earn!" target-interaction="custom.customerMeeting"></frak-button-share>
|
|
51
51
|
* ```
|
|
52
52
|
*
|
|
53
|
+
* @example
|
|
54
|
+
* On a product page, pass the displayed product(s) so a matching
|
|
55
|
+
* `productScope`d campaign is preferred and the sharing page can render product
|
|
56
|
+
* cards:
|
|
57
|
+
* ```html
|
|
58
|
+
* <frak-button-share text="Share and earn up to {REWARD}!" products='[{"title":"Shoes","sku":"SHOE-42","unitPrice":79.90}]'></frak-button-share>
|
|
59
|
+
* ```
|
|
60
|
+
*
|
|
53
61
|
* @see {@link @frak-labs/core-sdk!actions.displaySharingPage | `displaySharingPage()`} for more info about the sharing-page flow
|
|
54
62
|
* @see {@link @frak-labs/core-sdk!actions.getMerchantInformation | `getMerchantInformation()`} for more info about the estimated reward fetching
|
|
55
63
|
*/
|
|
56
|
-
function ButtonShare({ placement: placementId, text, classname = "", noRewardText, targetInteraction, clickAction: rawClickAction, preview }) {
|
|
64
|
+
function ButtonShare({ placement: placementId, text, classname = "", noRewardText, targetInteraction, products, clickAction: rawClickAction, preview }) {
|
|
57
65
|
const isPreview = !!preview;
|
|
58
66
|
const lang = useLang();
|
|
59
67
|
const placement = usePlacement(placementId);
|
|
@@ -66,11 +74,12 @@ function ButtonShare({ placement: placementId, text, classname = "", noRewardTex
|
|
|
66
74
|
const wantsReward = useMemo(() => resolvedText.includes("{REWARD}"), [resolvedText]);
|
|
67
75
|
const resolvedClickAction = useMemo(() => componentConfig?.clickAction ?? rawClickAction ?? "sharing-page", [componentConfig?.clickAction, rawClickAction]);
|
|
68
76
|
const { shouldRender, isHidden, isClientReady } = useClientReady();
|
|
69
|
-
const
|
|
77
|
+
const parsedProducts = useMemo(() => sanitizeSharingProducts(products), [products]);
|
|
78
|
+
const { reward } = useReward(wantsReward && isClientReady, resolvedTargetInteraction, void 0, parsedProducts);
|
|
70
79
|
const btnText = useMemo(() => {
|
|
71
80
|
if (!wantsReward) return resolvedText;
|
|
72
|
-
if (reward) return
|
|
73
|
-
return resolvedNoRewardText ??
|
|
81
|
+
if (reward) return w(resolvedText, reward);
|
|
82
|
+
return resolvedNoRewardText ?? w(resolvedText, void 0);
|
|
74
83
|
}, [
|
|
75
84
|
wantsReward,
|
|
76
85
|
resolvedText,
|
|
@@ -89,13 +98,14 @@ function ButtonShare({ placement: placementId, text, classname = "", noRewardTex
|
|
|
89
98
|
openEmbeddedWallet(resolvedTargetInteraction, placementId);
|
|
90
99
|
return;
|
|
91
100
|
}
|
|
92
|
-
openSharingPage(resolvedTargetInteraction, placementId);
|
|
101
|
+
openSharingPage(resolvedTargetInteraction, placementId, { products: parsedProducts });
|
|
93
102
|
}, [
|
|
94
103
|
isPreview,
|
|
95
104
|
resolvedClickAction,
|
|
96
105
|
resolvedTargetInteraction,
|
|
97
106
|
placementId,
|
|
98
|
-
reward
|
|
107
|
+
reward,
|
|
108
|
+
parsedProducts
|
|
99
109
|
]);
|
|
100
110
|
if (!isPreview && (!shouldRender || isHidden)) return null;
|
|
101
111
|
const buttonClass = [
|
|
@@ -120,6 +130,7 @@ registerWebComponent(ButtonShare, "frak-button-share", [
|
|
|
120
130
|
"clickAction",
|
|
121
131
|
"noRewardText",
|
|
122
132
|
"targetInteraction",
|
|
133
|
+
"products",
|
|
123
134
|
"preview"
|
|
124
135
|
], { shadow: false });
|
|
125
136
|
//#endregion
|
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-DtwWaLHO.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-D5zzFR11.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-DtwWaLHO.js";
|
|
2
|
+
import { t as useLightDomStyles } from "./useLightDomStyles-B_IbOqJZ.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";
|
|
@@ -19,7 +19,8 @@ function openFrakWalletApp(path = DEFAULT_PATH, placement) {
|
|
|
19
19
|
path,
|
|
20
20
|
placement
|
|
21
21
|
});
|
|
22
|
-
|
|
22
|
+
const deepLink = `${DEEP_LINK_SCHEME}${path}`;
|
|
23
|
+
triggerDeepLinkWithFallback(deepLink, { onFallback: () => {
|
|
23
24
|
if (client) trackEvent(client, "app_not_installed", {
|
|
24
25
|
path,
|
|
25
26
|
placement
|
package/dist/postPurchase.d.ts
CHANGED
|
@@ -16,7 +16,9 @@ type PostPurchaseProps = {
|
|
|
16
16
|
*/
|
|
17
17
|
orderId?: string;
|
|
18
18
|
/**
|
|
19
|
-
*
|
|
19
|
+
* Opaque per-order token. Feeds purchase tracking, and travels to the
|
|
20
|
+
* sharing page so the install CTA still carries a credential when the
|
|
21
|
+
* anonymous id is unavailable.
|
|
20
22
|
*/
|
|
21
23
|
token?: string;
|
|
22
24
|
/**
|
|
@@ -68,17 +70,12 @@ type PostPurchaseProps = {
|
|
|
68
70
|
*/
|
|
69
71
|
imageUrl?: string;
|
|
70
72
|
/**
|
|
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.
|
|
73
|
+
* Order line items, forwarded to the sharing page as product cards on CTA
|
|
74
|
+
* click, and used to prefer a campaign whose `productScope` matches one of
|
|
75
|
+
* the purchased items when picking the reward to advertise.
|
|
79
76
|
*
|
|
80
|
-
*
|
|
81
|
-
*
|
|
77
|
+
* Accepts a {@link SharingPageProduct} array (JS property) or a
|
|
78
|
+
* JSON-stringified array (HTML attribute, used by server-rendered plugins).
|
|
82
79
|
*/
|
|
83
80
|
products?: SharingPageProduct[] | string;
|
|
84
81
|
/**
|
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-DtwWaLHO.js";
|
|
2
|
+
import { t as useGlobalComponents } from "./useGlobalComponents-DFv33ujB.js";
|
|
3
|
+
import { t as useLightDomStyles } from "./useLightDomStyles-B_IbOqJZ.js";
|
|
4
|
+
import { i as w, n as K, t as C } from "./rewards-CZkWSndn.js";
|
|
5
5
|
import { componentDefaults } from "./i18n/defaults.js";
|
|
6
|
-
import { i as LogoFrakWithName, n as cssSource$2, t as GiftIcon } from "./GiftIcon-
|
|
7
|
-
import { trackEvent } from "@frak-labs/core-sdk";
|
|
6
|
+
import { i as LogoFrakWithName, n as cssSource$2, t as GiftIcon } from "./GiftIcon-DI0rUKHp.js";
|
|
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", {
|
|
@@ -262,18 +270,21 @@ function PostPurchase({ customerId, orderId, token, sharingUrl, merchantId, plac
|
|
|
262
270
|
});
|
|
263
271
|
openSharingPage(void 0, placementId, {
|
|
264
272
|
link: resolvedSharingUrl,
|
|
265
|
-
products: parsedProducts
|
|
273
|
+
products: parsedProducts,
|
|
274
|
+
checkoutToken: token
|
|
266
275
|
});
|
|
267
276
|
}, [
|
|
268
277
|
resolvedVariant,
|
|
269
278
|
placementId,
|
|
270
279
|
resolvedSharingUrl,
|
|
271
|
-
parsedProducts
|
|
280
|
+
parsedProducts,
|
|
281
|
+
token
|
|
272
282
|
]);
|
|
273
283
|
if (!resolvedVariant) return null;
|
|
274
284
|
if (!isPreview && (!shouldRender || isHidden || !context)) return null;
|
|
285
|
+
const cardClass = [card, classname].filter(Boolean).join(" ");
|
|
275
286
|
return /* @__PURE__ */ jsx("div", {
|
|
276
|
-
className:
|
|
287
|
+
className: cardClass,
|
|
277
288
|
children: /* @__PURE__ */ jsxs("div", {
|
|
278
289
|
class: cardLayout,
|
|
279
290
|
children: [/* @__PURE__ */ jsxs("div", {
|
|
@@ -0,0 +1,290 @@
|
|
|
1
|
+
//#region ../core/dist/getCurrencyAmountKey-mJ3_Eamt.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`: d = e.value, f = p ? `suffix` : `prefix`;
|
|
42
|
+
}
|
|
43
|
+
return {
|
|
44
|
+
integer: l,
|
|
45
|
+
decimals: u || `${i(s)}00`,
|
|
46
|
+
unit: d,
|
|
47
|
+
unitPosition: f
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
function o$1(e) {
|
|
51
|
+
return {
|
|
52
|
+
integer: String(e),
|
|
53
|
+
unit: `%`,
|
|
54
|
+
unitPosition: `suffix`
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
function s$1(e) {
|
|
58
|
+
return e ? `${e}Amount` : `eurAmount`;
|
|
59
|
+
}
|
|
60
|
+
//#endregion
|
|
61
|
+
//#region ../core/dist/rewards.js
|
|
62
|
+
function a(e) {
|
|
63
|
+
return Array.isArray(e) ? e : e.conditions;
|
|
64
|
+
}
|
|
65
|
+
function o(e) {
|
|
66
|
+
if (typeof e == `number`) return e;
|
|
67
|
+
if (typeof e == `string` && e.trim() !== ``) {
|
|
68
|
+
let t = Number(e);
|
|
69
|
+
return Number.isFinite(t) ? t : void 0;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
function s(e, t, n) {
|
|
73
|
+
let r = [];
|
|
74
|
+
for (let i of a(e)) {
|
|
75
|
+
if (`logic` in i) {
|
|
76
|
+
r.push(...s(i, t, n));
|
|
77
|
+
continue;
|
|
78
|
+
}
|
|
79
|
+
if (i.field === t && n.has(i.operator)) {
|
|
80
|
+
let e = o(i.value);
|
|
81
|
+
e != null && r.push(e);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
return r;
|
|
85
|
+
}
|
|
86
|
+
const c = /* @__PURE__ */ new Set([
|
|
87
|
+
`gt`,
|
|
88
|
+
`gte`,
|
|
89
|
+
`between`
|
|
90
|
+
]);
|
|
91
|
+
const l = /* @__PURE__ */ new Set([`gt`, `gte`]);
|
|
92
|
+
function u(e) {
|
|
93
|
+
let t = s(e, `purchase.amount`, c);
|
|
94
|
+
return t.length > 0 ? Math.min(...t) : void 0;
|
|
95
|
+
}
|
|
96
|
+
function d(e) {
|
|
97
|
+
let t = s(e, `time.timestamp`, l);
|
|
98
|
+
if (t.length !== 0) return /* @__PURE__ */ new Date(Math.min(...t) * 1e3);
|
|
99
|
+
}
|
|
100
|
+
function _(e, t) {
|
|
101
|
+
switch (e.payoutType) {
|
|
102
|
+
case `fixed`: return e.amount[t];
|
|
103
|
+
case `percentage`: return e.maxAmount?.[t] ?? 0;
|
|
104
|
+
case `tiered`: return e.tiers.reduce((e, n) => `amount` in n ? Math.max(e, n.amount[t]) : e, 0);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
function v(e) {
|
|
108
|
+
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;
|
|
109
|
+
}
|
|
110
|
+
function y(e, t) {
|
|
111
|
+
let n = _(e, t);
|
|
112
|
+
return n > 0 ? n : v(e) * 1e-6;
|
|
113
|
+
}
|
|
114
|
+
function x(n, r$1) {
|
|
115
|
+
let a = t(r$1), o = s$1(a);
|
|
116
|
+
switch (n.payoutType) {
|
|
117
|
+
case `fixed`: return r(Math.round(n.amount[o]), a);
|
|
118
|
+
case `percentage`: return `${n.percent} %`;
|
|
119
|
+
case `tiered`: {
|
|
120
|
+
let e = _(n, o);
|
|
121
|
+
if (e > 0) return r(Math.round(e), a);
|
|
122
|
+
let r$2 = v(n);
|
|
123
|
+
return r$2 > 0 ? `${r$2} %` : r(0, a);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
function S(t$1, a) {
|
|
128
|
+
let o = t(a), s = s$1(o);
|
|
129
|
+
switch (t$1.payoutType) {
|
|
130
|
+
case `fixed`: return a$1(Math.round(t$1.amount[s]), o);
|
|
131
|
+
case `percentage`: return o$1(t$1.percent);
|
|
132
|
+
case `tiered`: {
|
|
133
|
+
let e = _(t$1, s);
|
|
134
|
+
if (e > 0) return a$1(Math.round(e), o);
|
|
135
|
+
let i = v(t$1);
|
|
136
|
+
return i > 0 ? o$1(i) : a$1(0, o);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
function C(t$2, n) {
|
|
141
|
+
if (!(!t$2 || y(t$2, s$1(t(n))) <= 0)) return x(t$2, n);
|
|
142
|
+
}
|
|
143
|
+
function w(e, t) {
|
|
144
|
+
return t ? e.replaceAll(`{REWARD}`, t) : e.replaceAll(`{REWARD}`, ``);
|
|
145
|
+
}
|
|
146
|
+
const T = /* @__PURE__ */ new Set([
|
|
147
|
+
`eq`,
|
|
148
|
+
`neq`,
|
|
149
|
+
`gt`,
|
|
150
|
+
`gte`,
|
|
151
|
+
`lt`,
|
|
152
|
+
`lte`,
|
|
153
|
+
`between`
|
|
154
|
+
]);
|
|
155
|
+
const D = /* @__PURE__ */ new Set([
|
|
156
|
+
`contains`,
|
|
157
|
+
`starts_with`,
|
|
158
|
+
`ends_with`
|
|
159
|
+
]);
|
|
160
|
+
function A(e) {
|
|
161
|
+
return `logic` in e && `conditions` in e;
|
|
162
|
+
}
|
|
163
|
+
function j(e, t) {
|
|
164
|
+
return e[t];
|
|
165
|
+
}
|
|
166
|
+
function M(e) {
|
|
167
|
+
if (typeof e == `number`) return Number.isFinite(e) ? e : void 0;
|
|
168
|
+
if (typeof e == `string` && e.trim() !== ``) {
|
|
169
|
+
let t = Number(e);
|
|
170
|
+
return Number.isFinite(t) ? t : void 0;
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
function N(e, t) {
|
|
174
|
+
let n = M(e), r = M(t);
|
|
175
|
+
return n !== void 0 && r !== void 0 ? n - r : String(e).localeCompare(String(t));
|
|
176
|
+
}
|
|
177
|
+
function P(e, t, n) {
|
|
178
|
+
if (!Array.isArray(n)) return e === `not_in`;
|
|
179
|
+
if (t === void 0) return;
|
|
180
|
+
let r = n.includes(t);
|
|
181
|
+
return e === `in` ? r : !r;
|
|
182
|
+
}
|
|
183
|
+
function F(e, t, n, r) {
|
|
184
|
+
switch (e) {
|
|
185
|
+
case `eq`: return t === n;
|
|
186
|
+
case `neq`: return t !== n;
|
|
187
|
+
case `gt`: return N(t, n) > 0;
|
|
188
|
+
case `gte`: return N(t, n) >= 0;
|
|
189
|
+
case `lt`: return N(t, n) < 0;
|
|
190
|
+
case `lte`: return N(t, n) <= 0;
|
|
191
|
+
case `between`: return r == null || Array.isArray(r) ? void 0 : N(t, n) >= 0 && N(t, r) <= 0;
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
function I(e, t, n) {
|
|
195
|
+
if (typeof t == `string` && typeof n == `string`) return e === `contains` ? t.includes(n) : e === `starts_with` ? t.startsWith(n) : t.endsWith(n);
|
|
196
|
+
}
|
|
197
|
+
function L(e, t) {
|
|
198
|
+
let n = j(t, e.field), { operator: r, value: i, valueTo: a } = e;
|
|
199
|
+
if (r === `exists`) return n !== void 0;
|
|
200
|
+
if (r === `not_exists`) return n === void 0;
|
|
201
|
+
if (r === `in` || r === `not_in`) return P(r, n, i);
|
|
202
|
+
if (!(Array.isArray(i) || n === void 0 || i === null)) {
|
|
203
|
+
if (T.has(r)) return F(r, n, i, a);
|
|
204
|
+
if (D.has(r)) return I(r, n, i);
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
function R(e, t) {
|
|
208
|
+
if (A(e)) {
|
|
209
|
+
let n = e.conditions.map((e) => R(e, t));
|
|
210
|
+
return e.logic === `all` ? n.every(Boolean) : e.logic === `any` ? n.some(Boolean) : e.logic !== `none` || !n.some(Boolean);
|
|
211
|
+
}
|
|
212
|
+
return L(e, t) ?? !0;
|
|
213
|
+
}
|
|
214
|
+
function z(e, t) {
|
|
215
|
+
return e ? Array.isArray(e) ? e.every((e) => R(e, t)) : R(e, t) : !0;
|
|
216
|
+
}
|
|
217
|
+
function B(e, t) {
|
|
218
|
+
return e.expiresAt != null && new Date(e.expiresAt).getTime() <= t;
|
|
219
|
+
}
|
|
220
|
+
function V(e, t) {
|
|
221
|
+
let n = d(e.conditions);
|
|
222
|
+
return n == null || n.getTime() <= t;
|
|
223
|
+
}
|
|
224
|
+
function H(e, t) {
|
|
225
|
+
return t === `referee` ? e.referee : e.referrer;
|
|
226
|
+
}
|
|
227
|
+
function U(e, t, n) {
|
|
228
|
+
let r = H(e, n);
|
|
229
|
+
return r ? y(r, t) : 0;
|
|
230
|
+
}
|
|
231
|
+
function W(e, t) {
|
|
232
|
+
if (!t || t.length === 0 || !e.productScope) return;
|
|
233
|
+
let n = t.filter((t) => z(e.productScope, t));
|
|
234
|
+
return n.length > 0 ? n : void 0;
|
|
235
|
+
}
|
|
236
|
+
function G(e, t) {
|
|
237
|
+
return !t || t.length === 0 || !e.productScope || t.some((t) => z(e.productScope, t));
|
|
238
|
+
}
|
|
239
|
+
function K(t$3, n = {}) {
|
|
240
|
+
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));
|
|
241
|
+
if (c.length > 0) {
|
|
242
|
+
let e = c.reduce((e, t) => {
|
|
243
|
+
let r = G(e, n.products), i = G(t, n.products);
|
|
244
|
+
return r === i ? U(t, o, a) > U(e, o, a) ? t : e : i ? t : e;
|
|
245
|
+
});
|
|
246
|
+
return {
|
|
247
|
+
campaign: e,
|
|
248
|
+
status: `live`,
|
|
249
|
+
matchedProducts: W(e, n.products)
|
|
250
|
+
};
|
|
251
|
+
}
|
|
252
|
+
let l = s.map((e) => ({
|
|
253
|
+
campaign: e,
|
|
254
|
+
startsAt: d(e.conditions)
|
|
255
|
+
})).filter((e) => e.startsAt != null);
|
|
256
|
+
if (l.length === 0) return;
|
|
257
|
+
let u = l.reduce((e, t) => {
|
|
258
|
+
let r = G(e.campaign, n.products), i = G(t.campaign, n.products);
|
|
259
|
+
return r === i ? t.startsAt.getTime() < e.startsAt.getTime() ? t : e : i ? t : e;
|
|
260
|
+
});
|
|
261
|
+
return {
|
|
262
|
+
campaign: u.campaign,
|
|
263
|
+
status: `upcoming`,
|
|
264
|
+
startsAt: u.startsAt,
|
|
265
|
+
matchedProducts: W(u.campaign, n.products)
|
|
266
|
+
};
|
|
267
|
+
}
|
|
268
|
+
function q(e, n = {}) {
|
|
269
|
+
let r$3 = K(e, n);
|
|
270
|
+
if (!r$3) return;
|
|
271
|
+
let i = H(r$3.campaign, n.audience ?? `referrer`);
|
|
272
|
+
if (!i) return;
|
|
273
|
+
let a = C(i, n.currency);
|
|
274
|
+
if (!a) return;
|
|
275
|
+
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;
|
|
276
|
+
return {
|
|
277
|
+
formatted: a,
|
|
278
|
+
parts: S(i, n.currency),
|
|
279
|
+
payoutType: i.payoutType,
|
|
280
|
+
minPurchaseAmount: s,
|
|
281
|
+
lockupDurationDays: l,
|
|
282
|
+
referrerReward: r$3.campaign.referrer,
|
|
283
|
+
refereeReward: r$3.campaign.referee,
|
|
284
|
+
minPurchaseValue: o ?? void 0,
|
|
285
|
+
isProductScoped: r$3.campaign.productScope != null,
|
|
286
|
+
matchedProducts: r$3.matchedProducts
|
|
287
|
+
};
|
|
288
|
+
}
|
|
289
|
+
//#endregion
|
|
290
|
+
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-DtwWaLHO.js";
|
|
2
2
|
import { sdkConfigStore } from "@frak-labs/core-sdk";
|
|
3
3
|
import { useSyncExternalStore } from "preact/compat";
|
|
4
4
|
//#region src/hooks/useGlobalComponents.ts
|