@frak-labs/components 1.1.0 → 1.2.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.
Files changed (41) hide show
  1. package/cdn/{Banner.D-DIhGBs.js → Banner.DdAIrKFw.js} +2 -2
  2. package/cdn/ButtonShare.BMW4Spt5.js +1 -0
  3. package/cdn/ButtonWallet.DL64Gv3j.js +40 -0
  4. package/cdn/{GiftIcon.DabDdDcp.js → GiftIcon.CPyeWQNR.js} +1 -1
  5. package/cdn/OpenInAppButton.DYfr8q7L.js +1 -0
  6. package/cdn/PostPurchase.dHmBw1iX.js +89 -0
  7. package/cdn/components.js +1 -1
  8. package/cdn/defaults.CmUvOlLQ.js +58 -0
  9. package/cdn/loader.js +10 -6
  10. package/cdn/rewards.0JylBHNY.js +1 -0
  11. package/cdn/useGlobalComponents.C7wnXWOg.js +1 -0
  12. package/cdn/useLightDomStyles.BLyrWEBn.js +1 -0
  13. package/cdn/useReward.CaBorN5T.js +1 -0
  14. package/dist/{GiftIcon-BhL0bhVu.js → GiftIcon-DI0rUKHp.js} +7 -7
  15. package/dist/banner.js +10 -10
  16. package/dist/buttonShare.d.ts +7 -5
  17. package/dist/buttonShare.js +7 -12
  18. package/dist/buttonWallet.d.ts +7 -2
  19. package/dist/buttonWallet.js +34 -10
  20. package/dist/i18n/defaults.js +2 -2
  21. package/dist/openInApp.js +4 -3
  22. package/dist/postPurchase.d.ts +3 -1
  23. package/dist/postPurchase.js +30 -13
  24. package/dist/rewards-DoVY1pWr.js +290 -0
  25. package/dist/{useGlobalComponents-CeTO2xYs.js → useGlobalComponents-DFv33ujB.js} +1 -1
  26. package/dist/{useLightDomStyles-B2U96tzU.js → useLightDomStyles-B_IbOqJZ.js} +1 -1
  27. package/dist/{usePlacement-Bpo25qjA.js → usePlacement-DtwWaLHO.js} +3 -1
  28. package/dist/{useReward-Cg2wk8XI.js → useReward-k7RF3DhH.js} +2 -2
  29. package/package.json +1 -1
  30. package/cdn/ButtonShare.C1vuLCBH.js +0 -1
  31. package/cdn/ButtonWallet.Co2ZFqkb.js +0 -40
  32. package/cdn/OpenInAppButton.DAGgrKRg.js +0 -1
  33. package/cdn/PostPurchase.Cs1SrMme.js +0 -89
  34. package/cdn/defaults.DjBUlRT8.js +0 -58
  35. package/cdn/embeddedWallet.Bt2bp_-q.js +0 -1
  36. package/cdn/rewards.BaTam2j1.js +0 -1
  37. package/cdn/useGlobalComponents.4DaqvbCn.js +0 -1
  38. package/cdn/useLightDomStyles.DNP8gafA.js +0 -1
  39. package/cdn/useReward.Bi4Hs7kk.js +0 -1
  40. package/dist/embeddedWallet-CxgyuwtP.js +0 -18
  41. package/dist/rewards-CDS1CYlm.js +0 -241
@@ -43,15 +43,17 @@ type ButtonShareProps = {
43
43
  */
44
44
  products?: SharingPageProduct[] | string;
45
45
  /**
46
- * Which UI to open on click.
46
+ * Reported on the `share_button_clicked` event.
47
47
  *
48
- * Legacy values (e.g. `"share-modal"`) are accepted at runtime and
49
- * gracefully route to the full-page sharing UI — the modal-flow
50
- * share path was retired in favour of `displaySharingPage`.
48
+ * It no longer selects anything: every click opens the full-page sharing
49
+ * UI. Retired values (`"share-modal"`, `"embedded-wallet"`) stay accepted
50
+ * because merchant configs and saved plugin markup still carry them, and
51
+ * the resolved value is reported as-is so a legacy config stays visible in
52
+ * analytics.
51
53
  *
52
54
  * @defaultValue `"sharing-page"`
53
55
  */
54
- clickAction?: "embedded-wallet" | "sharing-page";
56
+ clickAction?: "sharing-page" | (string & {});
55
57
  /**
56
58
  * When set, renders the button in preview mode (e.g. Shopify/WP editor).
57
59
  * Skips the client-ready gating so the button is always enabled visually,
@@ -1,9 +1,8 @@
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 openEmbeddedWallet } from "./embeddedWallet-CxgyuwtP.js";
3
- import { t as useGlobalComponents } from "./useGlobalComponents-CeTO2xYs.js";
4
- import { t as useLightDomStyles } from "./useLightDomStyles-B2U96tzU.js";
5
- import { i as x } from "./rewards-CDS1CYlm.js";
6
- import { t as useReward } from "./useReward-Cg2wk8XI.js";
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 } from "./rewards-DoVY1pWr.js";
5
+ import { t as useReward } from "./useReward-k7RF3DhH.js";
7
6
  import { componentDefaults } from "./i18n/defaults.js";
8
7
  import { sanitizeSharingProducts, trackEvent } from "@frak-labs/core-sdk";
9
8
  import { useCallback, useMemo } from "preact/hooks";
@@ -78,8 +77,8 @@ function ButtonShare({ placement: placementId, text, classname = "", noRewardTex
78
77
  const { reward } = useReward(wantsReward && isClientReady, resolvedTargetInteraction, void 0, parsedProducts);
79
78
  const btnText = useMemo(() => {
80
79
  if (!wantsReward) return resolvedText;
81
- if (reward) return x(resolvedText, reward);
82
- return resolvedNoRewardText ?? x(resolvedText, void 0);
80
+ if (reward) return w(resolvedText, reward);
81
+ return resolvedNoRewardText ?? w(resolvedText, void 0);
83
82
  }, [
84
83
  wantsReward,
85
84
  resolvedText,
@@ -94,10 +93,6 @@ function ButtonShare({ placement: placementId, text, classname = "", noRewardTex
94
93
  has_reward: Boolean(reward),
95
94
  click_action: resolvedClickAction
96
95
  });
97
- if (resolvedClickAction === "embedded-wallet") {
98
- openEmbeddedWallet(resolvedTargetInteraction, placementId);
99
- return;
100
- }
101
96
  openSharingPage(resolvedTargetInteraction, placementId, { products: parsedProducts });
102
97
  }, [
103
98
  isPreview,
@@ -23,7 +23,12 @@ type ButtonWalletProps = {
23
23
  //#endregion
24
24
  //#region src/components/ButtonWallet/ButtonWallet.d.ts
25
25
  /**
26
- * Button to open wallet modal
26
+ * Floating circular button that opens the Frak sharing page.
27
+ *
28
+ * Historically this opened the embedded wallet drawer; that surface was
29
+ * retired, so the button now routes to the full-page sharing UI like every
30
+ * other share CTA. The `frak-button-wallet` tag name is kept because it is
31
+ * public API (merchant markup, Magento template).
27
32
  *
28
33
  * @param args
29
34
  * @returns The wallet button with `<button>` tag
@@ -60,7 +65,7 @@ type ButtonWalletProps = {
60
65
  * <frak-button-wallet placement="hero-wallet"></frak-button-wallet>
61
66
  * ```
62
67
  *
63
- * @see {@link @frak-labs/core-sdk!actions.modalBuilder | `modalBuilder()`} for more info about the modal display
68
+ * @see {@link @frak-labs/core-sdk!actions.displaySharingPage | `displaySharingPage()`} for more info about the sharing page
64
69
  * @see {@link @frak-labs/core-sdk!actions.getMerchantInformation | `getMerchantInformation()`} for more info about the estimated reward fetching
65
70
  */
66
71
  declare function ButtonWallet({ placement: placementId, classname, useReward: rawUseReward, targetInteraction }: ButtonWalletProps): import("preact").JSX.Element | null;
@@ -1,8 +1,8 @@
1
- import { i as useLang, n as buildStyleContent, o as useClientReady, s as registerWebComponent, t as usePlacement } from "./usePlacement-Bpo25qjA.js";
2
- import { t as openEmbeddedWallet } from "./embeddedWallet-CxgyuwtP.js";
3
- import { t as useReward } from "./useReward-Cg2wk8XI.js";
1
+ import { c as openSharingPage, i as useLang, n as buildStyleContent, o as useClientReady, s as registerWebComponent, t as usePlacement } from "./usePlacement-DtwWaLHO.js";
2
+ import { t as useReward } from "./useReward-k7RF3DhH.js";
4
3
  import { componentDefaults } from "./i18n/defaults.js";
5
- import { useEffect, useMemo, useState } from "preact/hooks";
4
+ import { trackEvent } from "@frak-labs/core-sdk";
5
+ import { useCallback, useEffect, useMemo, useState } from "preact/hooks";
6
6
  import { Fragment, jsx, jsxs } from "preact/jsx-runtime";
7
7
  //#region src/components/ButtonWallet/assets/GiftIcon.tsx
8
8
  function GiftIcon(props) {
@@ -32,9 +32,17 @@ function safeVibrate() {
32
32
  }
33
33
  //#endregion
34
34
  //#region src/components/ButtonWallet/utils.ts
35
+ /**
36
+ * Open the sharing surface behind `<frak-button-wallet>`.
37
+ *
38
+ * The button used to open the embedded wallet drawer; that surface was
39
+ * retired in favour of the full-page sharing UI, so the tag now routes
40
+ * there like every other share CTA. The tag name is kept because it is
41
+ * public API (merchant markup, Magento template).
42
+ */
35
43
  function openWalletModal(targetInteraction, placement) {
36
44
  safeVibrate();
37
- openEmbeddedWallet(targetInteraction, placement);
45
+ openSharingPage(targetInteraction, placement);
38
46
  }
39
47
  //#endregion
40
48
  //#region src/components/ButtonWallet/ButtonWallet.tsx
@@ -79,7 +87,12 @@ const componentCss = `
79
87
  }
80
88
  `;
81
89
  /**
82
- * Button to open wallet modal
90
+ * Floating circular button that opens the Frak sharing page.
91
+ *
92
+ * Historically this opened the embedded wallet drawer; that surface was
93
+ * retired, so the button now routes to the full-page sharing UI like every
94
+ * other share CTA. The `frak-button-wallet` tag name is kept because it is
95
+ * public API (merchant markup, Magento template).
83
96
  *
84
97
  * @param args
85
98
  * @returns The wallet button with `<button>` tag
@@ -116,7 +129,7 @@ const componentCss = `
116
129
  * <frak-button-wallet placement="hero-wallet"></frak-button-wallet>
117
130
  * ```
118
131
  *
119
- * @see {@link @frak-labs/core-sdk!actions.modalBuilder | `modalBuilder()`} for more info about the modal display
132
+ * @see {@link @frak-labs/core-sdk!actions.displaySharingPage | `displaySharingPage()`} for more info about the sharing page
120
133
  * @see {@link @frak-labs/core-sdk!actions.getMerchantInformation | `getMerchantInformation()`} for more info about the estimated reward fetching
121
134
  */
122
135
  function ButtonWallet({ placement: placementId, classname = "", useReward: rawUseReward, targetInteraction }) {
@@ -127,6 +140,19 @@ function ButtonWallet({ placement: placementId, classname = "", useReward: rawUs
127
140
  const { shouldRender, isHidden, isClientReady } = useClientReady();
128
141
  const { reward } = useReward(shouldUseReward && isClientReady, resolvedTargetInteraction);
129
142
  const [position, setPosition] = useState("right");
143
+ const onClick = useCallback(() => {
144
+ trackEvent(window.FrakSetup.client, "share_button_clicked", {
145
+ placement: placementId,
146
+ target_interaction: resolvedTargetInteraction,
147
+ has_reward: Boolean(reward),
148
+ click_action: "sharing-page"
149
+ });
150
+ openWalletModal(resolvedTargetInteraction, placementId);
151
+ }, [
152
+ placementId,
153
+ resolvedTargetInteraction,
154
+ reward
155
+ ]);
130
156
  useEffect(() => {
131
157
  const placementPosition = placement?.components?.buttonWallet?.position;
132
158
  const configPosition = window.FrakSetup?.modalWalletConfig?.metadata?.position;
@@ -145,9 +171,7 @@ function ButtonWallet({ placement: placementId, classname = "", useReward: rawUs
145
171
  part: "button",
146
172
  disabled: !isClientReady,
147
173
  class: buttonClass,
148
- onClick: () => {
149
- openWalletModal(resolvedTargetInteraction, placementId);
150
- },
174
+ onClick,
151
175
  children: [/* @__PURE__ */ jsx(GiftIcon, {}), reward && /* @__PURE__ */ jsx("span", {
152
176
  class: "reward",
153
177
  children: reward
@@ -27,7 +27,7 @@ const componentDefaults = {
27
27
  text: "Open in App",
28
28
  ariaLabel: "Open in Frak Wallet app"
29
29
  },
30
- buttonWallet: { ariaLabel: "Open wallet" },
30
+ buttonWallet: { ariaLabel: "Share and earn rewards" },
31
31
  banner: {
32
32
  referralTitleReward: "Earn {REWARD} on purchases",
33
33
  referralTitle: "You've been referred!",
@@ -53,7 +53,7 @@ const componentDefaults = {
53
53
  text: "Ouvrir dans l'app",
54
54
  ariaLabel: "Ouvrir dans l'app Frak Wallet"
55
55
  },
56
- buttonWallet: { ariaLabel: "Ouvrir le porte-monnaie" },
56
+ buttonWallet: { ariaLabel: "Partagez et gagnez des récompenses" },
57
57
  banner: {
58
58
  referralTitleReward: "Gagnez {REWARD} sur vos achats",
59
59
  referralTitle: "Vous avez été parrainé !",
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-Bpo25qjA.js";
2
- import { t as useLightDomStyles } from "./useLightDomStyles-B2U96tzU.js";
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
- triggerDeepLinkWithFallback(`${DEEP_LINK_SCHEME}${path}`, { onFallback: () => {
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
@@ -16,7 +16,9 @@ type PostPurchaseProps = {
16
16
  */
17
17
  orderId?: string;
18
18
  /**
19
- * Checkout token for purchase tracking fallback.
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
  /**
@@ -1,9 +1,9 @@
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 x, r as b, t as U } from "./rewards-CDS1CYlm.js";
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-DoVY1pWr.js";
5
5
  import { componentDefaults } from "./i18n/defaults.js";
6
- import { i as LogoFrakWithName, n as cssSource$2, t as GiftIcon } from "./GiftIcon-BhL0bhVu.js";
6
+ import { i as LogoFrakWithName, n as cssSource$2, t as GiftIcon } from "./GiftIcon-DI0rUKHp.js";
7
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";
@@ -114,12 +114,26 @@ const cssSource = cssSource$1;
114
114
  //#endregion
115
115
  //#region src/components/PostPurchase/PostPurchase.tsx
116
116
  /**
117
+ * `onChainMetadata.domain` is a bare host and `sharing-url` defaults to `""` in
118
+ * the WordPress shortcode; both would throw inside `FrakContextManager.update`.
119
+ */
120
+ function resolveShareBaseUrl(value) {
121
+ const trimmed = value?.trim();
122
+ if (!trimmed) return void 0;
123
+ const candidate = /^https?:\/\//i.test(trimmed) ? trimmed : `https://${trimmed}`;
124
+ try {
125
+ return new URL(candidate).toString();
126
+ } catch {
127
+ return;
128
+ }
129
+ }
130
+ /**
117
131
  * Given referral status and merchant info, compute the display variant
118
132
  * and pick the appropriate purchase reward.
119
133
  */
120
134
  function resolvePostPurchaseContext(referralStatus, merchantInfo, currency, products) {
121
135
  const audience = referralStatus?.isReferred ? "referee" : "referrer";
122
- const selected = U(merchantInfo.rewards, {
136
+ const selected = K(merchantInfo.rewards, {
123
137
  targetInteraction: "purchase",
124
138
  currency,
125
139
  audience,
@@ -217,11 +231,11 @@ function PostPurchase({ customerId, orderId, token, sharingUrl, merchantId, plac
217
231
  }, [fetched, parsedProducts]);
218
232
  const trackedImpressionVariantRef = useRef(null);
219
233
  const resolvedVariant = forcedVariant ?? context?.variant ?? (isPreview ? previewVariant ?? "referrer" : void 0);
220
- const resolvedSharingUrl = sharingUrl ?? context?.merchantDomain;
234
+ const resolvedSharingUrl = resolveShareBaseUrl(sharingUrl ?? context?.merchantDomain);
221
235
  const rewardText = useMemo(() => {
222
236
  if (!context?.reward) return void 0;
223
237
  const currency = window.FrakSetup?.client?.config?.metadata?.currency;
224
- return b(context.reward, currency);
238
+ return C(context.reward, currency);
225
239
  }, [context?.reward]);
226
240
  const globalComponents = useGlobalComponents();
227
241
  const postPurchaseConfig = placement?.components?.postPurchase ?? globalComponents?.postPurchase;
@@ -230,8 +244,8 @@ function PostPurchase({ customerId, orderId, token, sharingUrl, merchantId, plac
230
244
  const texts = useMemo(() => {
231
245
  const defaults = componentDefaults[lang].postPurchase;
232
246
  return {
233
- message: resolvedVariant === "referee" ? rewardText ? x(propRefereeText ?? postPurchaseConfig?.refereeText ?? defaults.refereeText, rewardText) : propRefereeText ?? postPurchaseConfig?.refereeNoRewardText ?? defaults.refereeNoRewardText : rewardText ? x(propReferrerText ?? postPurchaseConfig?.referrerText ?? defaults.referrerText, rewardText) : propReferrerText ?? postPurchaseConfig?.referrerNoRewardText ?? defaults.referrerNoRewardText,
234
- cta: rewardText ? x(propCtaText ?? postPurchaseConfig?.ctaText ?? defaults.ctaText, rewardText) : propCtaText ?? postPurchaseConfig?.ctaNoRewardText ?? defaults.ctaNoRewardText
247
+ 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,
248
+ cta: rewardText ? w(propCtaText ?? postPurchaseConfig?.ctaText ?? defaults.ctaText, rewardText) : propCtaText ?? postPurchaseConfig?.ctaNoRewardText ?? defaults.ctaNoRewardText
235
249
  };
236
250
  }, [
237
251
  lang,
@@ -270,18 +284,21 @@ function PostPurchase({ customerId, orderId, token, sharingUrl, merchantId, plac
270
284
  });
271
285
  openSharingPage(void 0, placementId, {
272
286
  link: resolvedSharingUrl,
273
- products: parsedProducts
287
+ products: parsedProducts,
288
+ checkoutToken: token
274
289
  });
275
290
  }, [
276
291
  resolvedVariant,
277
292
  placementId,
278
293
  resolvedSharingUrl,
279
- parsedProducts
294
+ parsedProducts,
295
+ token
280
296
  ]);
281
297
  if (!resolvedVariant) return null;
282
298
  if (!isPreview && (!shouldRender || isHidden || !context)) return null;
299
+ const cardClass = [card, classname].filter(Boolean).join(" ");
283
300
  return /* @__PURE__ */ jsx("div", {
284
- className: [card, classname].filter(Boolean).join(" "),
301
+ className: cardClass,
285
302
  children: /* @__PURE__ */ jsxs("div", {
286
303
  class: cardLayout,
287
304
  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 == null) 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 != null;
200
+ if (r === `not_exists`) return n == null;
201
+ if (r === `in` || r === `not_in`) return P(r, n, i);
202
+ if (!(Array.isArray(i) || n == null || 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-Bpo25qjA.js";
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
@@ -1,4 +1,4 @@
1
- import { r as lightDomBaseCss } from "./usePlacement-Bpo25qjA.js";
1
+ import { r as lightDomBaseCss } from "./usePlacement-DtwWaLHO.js";
2
2
  import { useEffect } from "preact/hooks";
3
3
  //#region src/styles/styleManager.ts
4
4
  function ensureStyle(id, css) {
@@ -14,6 +14,7 @@ async function openSharingPage(targetInteraction, placement, options) {
14
14
  await displaySharingPage(window.FrakSetup.client, {
15
15
  ...options?.link && { link: options.link },
16
16
  ...options?.products?.length && { products: options.products },
17
+ ...options?.checkoutToken && { checkoutToken: options.checkoutToken },
17
18
  ...targetInteraction && { metadata: { targetInteraction } }
18
19
  }, placement);
19
20
  }
@@ -347,7 +348,8 @@ function getPlacement(id) {
347
348
  * only re-renders when that placement actually changes.
348
349
  */
349
350
  function usePlacement(placementId) {
350
- return useSyncExternalStore(subscribeSdkConfig, useCallback(() => placementId ? getPlacement(placementId) : void 0, [placementId]));
351
+ const getSnapshot = useCallback(() => placementId ? getPlacement(placementId) : void 0, [placementId]);
352
+ return useSyncExternalStore(subscribeSdkConfig, getSnapshot);
351
353
  }
352
354
  //#endregion
353
355
  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 { n as W } from "./rewards-CDS1CYlm.js";
1
+ import { r as q } from "./rewards-DoVY1pWr.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
@@ -24,7 +24,7 @@ function useReward(shouldUseReward, targetInteraction, audience, products) {
24
24
  const client = window.FrakSetup?.client;
25
25
  if (!client) return;
26
26
  getMerchantInformation(client).then((merchantInfo) => {
27
- const best = W(merchantInfo.rewards, {
27
+ const best = q(merchantInfo.rewards, {
28
28
  currency: client.config.metadata?.currency,
29
29
  targetInteraction,
30
30
  audience,
package/package.json CHANGED
@@ -11,7 +11,7 @@
11
11
  "url": "https://twitter.com/QNivelais"
12
12
  }
13
13
  ],
14
- "version": "1.1.0",
14
+ "version": "1.2.0",
15
15
  "description": "Frak Wallet components, helping any person to interact with the Frak wallet.",
16
16
  "repository": {
17
17
  "url": "https://github.com/frak-id/wallet",
@@ -1 +0,0 @@
1
- import{S as e,d as t,r as n}from"./loader.js";import{a as r,h as i,m as a,n as o,p as s,s as c,t as l,u}from"./defaults.DjBUlRT8.js";import{t as d}from"./useGlobalComponents.4DaqvbCn.js";import{t as f}from"./useLightDomStyles.DNP8gafA.js";import{i as p}from"./rewards.BaTam2j1.js";import{t as m}from"./useReward.Bi4Hs7kk.js";import{t as h}from"./embeddedWallet.Bt2bp_-q.js";function g({placement:i,text:g,classname:_=``,noRewardText:v,targetInteraction:y,products:b,clickAction:x,preview:S}){let C=!!S,w=r(),T=o(i),E=d(),D=T?.components?.buttonShare??E?.buttonShare;f(`frak-button-share`,i,D?.css);let O=u(()=>T?.targetInteraction===void 0?y:T.targetInteraction,[T?.targetInteraction,y]),k=D?.text??g??l[w].buttonShare.text,A=D?.noRewardText??v,j=u(()=>k.includes(`{REWARD}`),[k]),M=u(()=>D?.clickAction??x??`sharing-page`,[D?.clickAction,x]),{shouldRender:N,isHidden:P,isClientReady:F}=c(),I=u(()=>t(b),[b]),{reward:L}=m(j&&F,O,void 0,I),R=u(()=>j?L?p(k,L):A??p(k,void 0):k,[j,k,A,L]),z=s(()=>{if(!C){if(e(window.FrakSetup.client,`share_button_clicked`,{placement:i,target_interaction:O,has_reward:!!L,click_action:M}),M===`embedded-wallet`){h(O,i);return}n(O,i,{products:I})}},[C,M,O,i,L,I]);if(!C&&(!N||P))return null;let B=[`button`,`button__fadeIn`,_].filter(Boolean).join(` `);return a(`button`,{type:`button`,disabled:!C&&!F,class:B,onClick:z,children:R})}i(g,`frak-button-share`,[`text`,`placement`,`classname`,`clickAction`,`noRewardText`,`targetInteraction`,`products`,`preview`],{shadow:!1});export{g as ButtonShare};