@frak-labs/components 1.0.13-beta.f4d2e52a → 1.1.0-beta.088da93e

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.
Files changed (37) hide show
  1. package/cdn/Banner.DGYexiiS.js +183 -0
  2. package/cdn/ButtonShare.DFg0XCDd.js +1 -0
  3. package/cdn/{ButtonWallet.Cwauxojx.js → ButtonWallet.sGDvcAXt.js} +1 -1
  4. package/cdn/{GiftIcon.CSjsnRQh.js → GiftIcon.C1uAOx7A.js} +1 -1
  5. package/cdn/{OpenInAppButton.G3VjbH1_.js → OpenInAppButton.CxLPpqFO.js} +1 -1
  6. package/cdn/PostPurchase.D6Mzbjtu.js +89 -0
  7. package/cdn/components.js +1 -1
  8. package/cdn/defaults.BEvoSiy5.js +58 -0
  9. package/cdn/{embeddedWallet.BR3BC6DE.js → embeddedWallet.BjQSXLkP.js} +1 -1
  10. package/cdn/loader.js +6 -6
  11. package/cdn/rewards.B2smvfIs.js +1 -0
  12. package/cdn/useGlobalComponents.CqTI84Mw.js +1 -0
  13. package/cdn/useLightDomStyles.CKtA4k-_.js +1 -0
  14. package/cdn/useReward.CXgeQcsH.js +1 -0
  15. package/dist/banner.d.ts +10 -2
  16. package/dist/banner.js +14 -12
  17. package/dist/buttonShare.d.ts +19 -2
  18. package/dist/buttonShare.js +23 -12
  19. package/dist/buttonWallet.js +2 -2
  20. package/dist/openInApp.js +2 -2
  21. package/dist/postPurchase.d.ts +5 -10
  22. package/dist/postPurchase.js +22 -14
  23. package/dist/rewards-Cxn-bgzC.js +293 -0
  24. package/dist/{useGlobalComponents-Da9LDlRy.js → useGlobalComponents-CeTO2xYs.js} +1 -1
  25. package/dist/{useLightDomStyles-DRkTVy4s.js → useLightDomStyles-B2U96tzU.js} +1 -1
  26. package/dist/{usePlacement-NZOjZ6IR.js → usePlacement-Bpo25qjA.js} +2 -108
  27. package/dist/{useReward-B-yZ7nhY.js → useReward-BMYSGY-o.js} +10 -5
  28. package/package.json +3 -3
  29. package/cdn/Banner.wcjTUyP1.js +0 -183
  30. package/cdn/ButtonShare.CMTO7zcA.js +0 -1
  31. package/cdn/PostPurchase.DFHeDsq_.js +0 -89
  32. package/cdn/defaults.DNO3nf63.js +0 -58
  33. package/cdn/rewards.usw1vliR.js +0 -1
  34. package/cdn/useGlobalComponents.CcNSI-MX.js +0 -1
  35. package/cdn/useLightDomStyles.mqw3cSdZ.js +0 -1
  36. package/cdn/useReward.BK8q8FQH.js +0 -1
  37. package/dist/rewards-BtPHdGcI.js +0 -149
@@ -1,4 +1,4 @@
1
- import { InteractionTypeKey } from "@frak-labs/core-sdk";
1
+ import { InteractionTypeKey, SharingPageProduct } from "@frak-labs/core-sdk";
2
2
  //#region src/components/ButtonShare/types.d.ts
3
3
  /**
4
4
  * The props type for {@link ButtonShare}.
@@ -33,6 +33,15 @@ type ButtonShareProps = {
33
33
  * Target interaction behind this sharing action (will be used to get the right reward to display)
34
34
  */
35
35
  targetInteraction?: InteractionTypeKey;
36
+ /**
37
+ * Products currently in view, used to prefer a campaign whose
38
+ * `productScope` matches one of them when picking the reward to advertise,
39
+ * and forwarded to the sharing page so it can render product cards.
40
+ *
41
+ * Accepts a {@link SharingPageProduct} array (JS property) or a
42
+ * JSON-stringified array (HTML attribute).
43
+ */
44
+ products?: SharingPageProduct[] | string;
36
45
  /**
37
46
  * Which UI to open on click.
38
47
  *
@@ -94,10 +103,18 @@ type ButtonShareProps = {
94
103
  * <frak-button-share text="Share and earn up to {REWARD}!" no-reward-text="Share and earn!" target-interaction="custom.customerMeeting"></frak-button-share>
95
104
  * ```
96
105
  *
106
+ * @example
107
+ * On a product page, pass the displayed product(s) so a matching
108
+ * `productScope`d campaign is preferred and the sharing page can render product
109
+ * cards:
110
+ * ```html
111
+ * <frak-button-share text="Share and earn up to {REWARD}!" products='[{"title":"Shoes","sku":"SHOE-42","unitPrice":79.90}]'></frak-button-share>
112
+ * ```
113
+ *
97
114
  * @see {@link @frak-labs/core-sdk!actions.displaySharingPage | `displaySharingPage()`} for more info about the sharing-page flow
98
115
  * @see {@link @frak-labs/core-sdk!actions.getMerchantInformation | `getMerchantInformation()`} for more info about the estimated reward fetching
99
116
  */
100
- declare function ButtonShare({ placement: placementId, text, classname, noRewardText, targetInteraction, clickAction: rawClickAction, preview }: ButtonShareProps): import("preact").JSX.Element | null;
117
+ declare function ButtonShare({ placement: placementId, text, classname, noRewardText, targetInteraction, products, clickAction: rawClickAction, preview }: ButtonShareProps): import("preact").JSX.Element | null;
101
118
  //#endregion
102
119
  //#region src/components/ButtonShare/index.d.ts
103
120
  /**
@@ -1,11 +1,11 @@
1
- import { i as useLang, l as openSharingPage, o as useClientReady, s as registerWebComponent, t as usePlacement } from "./usePlacement-NZOjZ6IR.js";
1
+ import { c as openSharingPage, i as useLang, 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 useGlobalComponents } from "./useGlobalComponents-Da9LDlRy.js";
4
- import { t as useLightDomStyles } from "./useLightDomStyles-DRkTVy4s.js";
5
- import { r as b } from "./rewards-BtPHdGcI.js";
6
- import { t as useReward } from "./useReward-B-yZ7nhY.js";
3
+ import { t as useGlobalComponents } from "./useGlobalComponents-CeTO2xYs.js";
4
+ import { t as useLightDomStyles } from "./useLightDomStyles-B2U96tzU.js";
5
+ import { i as w } from "./rewards-Cxn-bgzC.js";
6
+ import { t as useReward } from "./useReward-BMYSGY-o.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 { reward } = useReward(wantsReward && isClientReady, resolvedTargetInteraction);
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 b(resolvedText, reward);
73
- return resolvedNoRewardText ?? b(resolvedText, void 0);
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
@@ -1,6 +1,6 @@
1
- import { i as useLang, n as buildStyleContent, o as useClientReady, s as registerWebComponent, t as usePlacement } from "./usePlacement-NZOjZ6IR.js";
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-B-yZ7nhY.js";
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-NZOjZ6IR.js";
2
- import { t as useLightDomStyles } from "./useLightDomStyles-DRkTVy4s.js";
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";
@@ -68,17 +68,12 @@ type PostPurchaseProps = {
68
68
  */
69
69
  imageUrl?: string;
70
70
  /**
71
- * Optional product cards forwarded to the sharing page when the user
72
- * clicks the CTA. Accepts either a real {@link SharingPageProduct}
73
- * array (when set imperatively via the JS property,
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
- * Empty arrays / unparseable strings are treated as "no products" so
81
- * the sharing page renders without the product card section.
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
  /**
@@ -1,10 +1,10 @@
1
- import { c as sanitizeProductList, i as useLang, l as openSharingPage, o as useClientReady, s as registerWebComponent, t as usePlacement } from "./usePlacement-NZOjZ6IR.js";
2
- import { t as useGlobalComponents } from "./useGlobalComponents-Da9LDlRy.js";
3
- import { t as useLightDomStyles } from "./useLightDomStyles-DRkTVy4s.js";
4
- import { i as y, n as T, r as b } from "./rewards-BtPHdGcI.js";
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 = T(merchantInfo.rewards, {
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 [context, setContext] = useState(null);
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
- setContext(resolvePostPurchaseContext(referralStatus, merchantInfo, client.config.metadata?.currency));
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 y(context.reward, currency);
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 ? b(propRefereeText ?? postPurchaseConfig?.refereeText ?? defaults.refereeText, rewardText) : propRefereeText ?? postPurchaseConfig?.refereeNoRewardText ?? defaults.refereeNoRewardText : rewardText ? b(propReferrerText ?? postPurchaseConfig?.referrerText ?? defaults.referrerText, rewardText) : propReferrerText ?? postPurchaseConfig?.referrerNoRewardText ?? defaults.referrerNoRewardText,
225
- cta: rewardText ? b(propCtaText ?? postPurchaseConfig?.ctaText ?? defaults.ctaText, rewardText) : propCtaText ?? postPurchaseConfig?.ctaNoRewardText ?? defaults.ctaNoRewardText
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-NZOjZ6IR.js";
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,4 +1,4 @@
1
- import { r as lightDomBaseCss } from "./usePlacement-NZOjZ6IR.js";
1
+ import { r as lightDomBaseCss } from "./usePlacement-Bpo25qjA.js";
2
2
  import { useEffect } from "preact/hooks";
3
3
  //#region src/styles/styleManager.ts
4
4
  function ensureStyle(id, css) {