@frak-labs/components 1.0.13 → 1.1.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 (46) hide show
  1. package/cdn/Banner.D-DIhGBs.js +183 -0
  2. package/cdn/ButtonShare.C1vuLCBH.js +1 -0
  3. package/cdn/ButtonWallet.Co2ZFqkb.js +40 -0
  4. package/cdn/{GiftIcon.DcyE1R1V.js → GiftIcon.DabDdDcp.js} +1 -1
  5. package/cdn/OpenInAppButton.DAGgrKRg.js +1 -0
  6. package/cdn/PostPurchase.Cs1SrMme.js +89 -0
  7. package/cdn/components.js +1 -1
  8. package/cdn/defaults.DjBUlRT8.js +58 -0
  9. package/cdn/embeddedWallet.Bt2bp_-q.js +1 -0
  10. package/cdn/loader.js +164 -1
  11. package/cdn/rewards.BaTam2j1.js +1 -0
  12. package/cdn/useGlobalComponents.4DaqvbCn.js +1 -0
  13. package/cdn/useLightDomStyles.DNP8gafA.js +1 -0
  14. package/cdn/useReward.Bi4Hs7kk.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-CDS1CYlm.js +241 -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-Cg2wk8XI.js} +10 -5
  28. package/package.json +31 -19
  29. package/cdn/Banner.BM-XicfW.js +0 -183
  30. package/cdn/ButtonShare.DsCfkEG1.js +0 -1
  31. package/cdn/ButtonWallet.BQt3QmKr.js +0 -40
  32. package/cdn/OpenInAppButton.BIfTfSWS.js +0 -1
  33. package/cdn/PostPurchase.Bcnzehoo.js +0 -89
  34. package/cdn/actions-CMPlZ7CH.CJIqArwi.js +0 -1
  35. package/cdn/clientReady.ClcVd4_w.js +0 -1
  36. package/cdn/defaults.CIT5-NpH.js +0 -58
  37. package/cdn/embeddedWallet.BXl45f3Y.js +0 -1
  38. package/cdn/rewards.CW3JGWuC.js +0 -1
  39. package/cdn/sharedBaseCss.css.BDzFcWnD.js +0 -154
  40. package/cdn/sharingPage.BjReoj_N.js +0 -1
  41. package/cdn/sharingPageProducts.BoDmfrdn.js +0 -1
  42. package/cdn/styleManager.Cun1-fKi.js +0 -1
  43. package/cdn/useGlobalComponents.DqV5lr6s.js +0 -1
  44. package/cdn/useLightDomStyles.BsQue5kI.js +0 -1
  45. package/cdn/useReward.CcsZ70zp.js +0 -1
  46. package/dist/rewards-BtPHdGcI.js +0 -149
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 x, r as b, t as U } from "./rewards-CDS1CYlm.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 = U(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 b(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 ? 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
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,241 @@
1
+ //#region ../core/dist/getCurrencyAmountKey-C-1W-BRg.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$1(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$1(e) {
23
+ return e ? `${e}Amount` : `eurAmount`;
24
+ }
25
+ //#endregion
26
+ //#region ../core/dist/rewards.js
27
+ function r(e) {
28
+ return Array.isArray(e) ? e : e.conditions;
29
+ }
30
+ function i(e) {
31
+ if (typeof e == `number`) return e;
32
+ if (typeof e == `string` && e.trim() !== ``) {
33
+ let t = Number(e);
34
+ return Number.isFinite(t) ? t : void 0;
35
+ }
36
+ }
37
+ function a(e, t, n) {
38
+ let o = [];
39
+ for (let s of r(e)) {
40
+ if (`logic` in s) {
41
+ o.push(...a(s, t, n));
42
+ continue;
43
+ }
44
+ if (s.field === t && n.has(s.operator)) {
45
+ let e = i(s.value);
46
+ e != null && o.push(e);
47
+ }
48
+ }
49
+ return o;
50
+ }
51
+ const o = /* @__PURE__ */ new Set([
52
+ `gt`,
53
+ `gte`,
54
+ `between`
55
+ ]);
56
+ const s = /* @__PURE__ */ new Set([`gt`, `gte`]);
57
+ function c(e) {
58
+ let t = a(e, `purchase.amount`, o);
59
+ return t.length > 0 ? Math.min(...t) : void 0;
60
+ }
61
+ function l(e) {
62
+ let t = a(e, `time.timestamp`, s);
63
+ if (t.length !== 0) return /* @__PURE__ */ new Date(Math.min(...t) * 1e3);
64
+ }
65
+ function h(e, t) {
66
+ switch (e.payoutType) {
67
+ case `fixed`: return e.amount[t];
68
+ case `percentage`: return e.maxAmount?.[t] ?? 0;
69
+ case `tiered`: return e.tiers.reduce((e, n) => `amount` in n ? Math.max(e, n.amount[t]) : e, 0);
70
+ }
71
+ }
72
+ function g(e) {
73
+ 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;
74
+ }
75
+ function _(e, t) {
76
+ let n = h(e, t);
77
+ return n > 0 ? n : g(e) * 1e-6;
78
+ }
79
+ function y(r, i) {
80
+ let a = t(i), o = i$1(a);
81
+ switch (r.payoutType) {
82
+ case `fixed`: return r$1(Math.round(r.amount[o]), a);
83
+ case `percentage`: return `${r.percent} %`;
84
+ case `tiered`: {
85
+ let t = h(r, o);
86
+ if (t > 0) return r$1(Math.round(t), a);
87
+ let n = g(r);
88
+ return n > 0 ? `${n} %` : r$1(0, a);
89
+ }
90
+ }
91
+ }
92
+ function b(e, r) {
93
+ if (e && !(_(e, i$1(t(r))) <= 0)) return y(e, r);
94
+ }
95
+ function x(e, t) {
96
+ return t ? e.replaceAll(`{REWARD}`, t) : e.replaceAll(`{REWARD}`, ``);
97
+ }
98
+ const S = /* @__PURE__ */ new Set([
99
+ `eq`,
100
+ `neq`,
101
+ `gt`,
102
+ `gte`,
103
+ `lt`,
104
+ `lte`,
105
+ `between`
106
+ ]);
107
+ const w = /* @__PURE__ */ new Set([
108
+ `contains`,
109
+ `starts_with`,
110
+ `ends_with`
111
+ ]);
112
+ function D(e) {
113
+ return `logic` in e && `conditions` in e;
114
+ }
115
+ function O(e, t) {
116
+ return e[t];
117
+ }
118
+ function k(e) {
119
+ if (typeof e == `number`) return Number.isFinite(e) ? e : void 0;
120
+ if (typeof e == `string` && e.trim() !== ``) {
121
+ let t = Number(e);
122
+ return Number.isFinite(t) ? t : void 0;
123
+ }
124
+ }
125
+ function A(e, t) {
126
+ let n = k(e), r = k(t);
127
+ return n !== void 0 && r !== void 0 ? n - r : String(e).localeCompare(String(t));
128
+ }
129
+ function j(e, t, n) {
130
+ if (!Array.isArray(n)) return e === `not_in`;
131
+ if (t === void 0) return;
132
+ let r = n.includes(t);
133
+ return e === `in` ? r : !r;
134
+ }
135
+ function M(e, t, n, r) {
136
+ switch (e) {
137
+ case `eq`: return t === n;
138
+ case `neq`: return t !== n;
139
+ case `gt`: return A(t, n) > 0;
140
+ case `gte`: return A(t, n) >= 0;
141
+ case `lt`: return A(t, n) < 0;
142
+ case `lte`: return A(t, n) <= 0;
143
+ case `between`: return r == null || Array.isArray(r) ? void 0 : A(t, n) >= 0 && A(t, r) <= 0;
144
+ }
145
+ }
146
+ function N(e, t, n) {
147
+ if (typeof t == `string` && typeof n == `string`) return e === `contains` ? t.includes(n) : e === `starts_with` ? t.startsWith(n) : t.endsWith(n);
148
+ }
149
+ function P(e, t) {
150
+ let n = O(t, e.field), { operator: r, value: i, valueTo: a } = e;
151
+ if (r === `exists`) return n !== void 0;
152
+ if (r === `not_exists`) return n === void 0;
153
+ if (r === `in` || r === `not_in`) return j(r, n, i);
154
+ if (!(Array.isArray(i) || n === void 0 || i === null)) {
155
+ if (S.has(r)) return M(r, n, i, a);
156
+ if (w.has(r)) return N(r, n, i);
157
+ }
158
+ }
159
+ function F(e, t) {
160
+ if (D(e)) {
161
+ let n = e.conditions.map((e) => F(e, t));
162
+ return e.logic === `all` ? n.every(Boolean) : e.logic === `any` ? n.some(Boolean) : e.logic !== `none` || !n.some(Boolean);
163
+ }
164
+ return P(e, t) ?? !0;
165
+ }
166
+ function I(e, t) {
167
+ return e ? Array.isArray(e) ? e.every((e) => F(e, t)) : F(e, t) : !0;
168
+ }
169
+ function L(e, t) {
170
+ return e.expiresAt != null && new Date(e.expiresAt).getTime() <= t;
171
+ }
172
+ function R(e, t) {
173
+ let n = l(e.conditions);
174
+ return n == null || n.getTime() <= t;
175
+ }
176
+ function z(e, t) {
177
+ return t === `referee` ? e.referee : e.referrer;
178
+ }
179
+ function B(e, t, n) {
180
+ let r = z(e, n);
181
+ return r ? _(r, t) : 0;
182
+ }
183
+ function V(e, t) {
184
+ if (!t || t.length === 0 || !e.productScope) return;
185
+ let n = t.filter((t) => I(e.productScope, t));
186
+ return n.length > 0 ? n : void 0;
187
+ }
188
+ function H(e, t) {
189
+ return !t || t.length === 0 || !e.productScope || t.some((t) => I(e.productScope, t));
190
+ }
191
+ function U(e, r = {}) {
192
+ let i = (r.now ?? /* @__PURE__ */ new Date()).getTime(), a = r.audience ?? `referrer`, o = i$1(t(r.currency)), s = (r.targetInteraction ? e.filter((e) => e.interactionTypeKey === r.targetInteraction) : e).filter((e) => !L(e, i)), c = s.filter((e) => R(e, i));
193
+ if (c.length > 0) {
194
+ let e = c.reduce((e, t) => {
195
+ let n = H(e, r.products), i = H(t, r.products);
196
+ return n === i ? B(t, o, a) > B(e, o, a) ? t : e : i ? t : e;
197
+ });
198
+ return {
199
+ campaign: e,
200
+ status: `live`,
201
+ matchedProducts: V(e, r.products)
202
+ };
203
+ }
204
+ let u = s.map((e) => ({
205
+ campaign: e,
206
+ startsAt: l(e.conditions)
207
+ })).filter((e) => e.startsAt != null);
208
+ if (u.length === 0) return;
209
+ let d = u.reduce((e, t) => {
210
+ let n = H(e.campaign, r.products), i = H(t.campaign, r.products);
211
+ return n === i ? t.startsAt.getTime() < e.startsAt.getTime() ? t : e : i ? t : e;
212
+ });
213
+ return {
214
+ campaign: d.campaign,
215
+ status: `upcoming`,
216
+ startsAt: d.startsAt,
217
+ matchedProducts: V(d.campaign, r.products)
218
+ };
219
+ }
220
+ function W(t, n = {}) {
221
+ let r = U(t, n);
222
+ if (!r) return;
223
+ let i = z(r.campaign, n.audience ?? `referrer`);
224
+ if (!i) return;
225
+ let a = b(i, n.currency);
226
+ if (!a) return;
227
+ let o = c(r.campaign.conditions), s = o == null ? void 0 : r$1(o, n.currency), l = r.campaign.defaultLockupSeconds, u = l && l > 0 ? Math.round(l / 86400) : void 0;
228
+ return {
229
+ formatted: a,
230
+ payoutType: i.payoutType,
231
+ minPurchaseAmount: s,
232
+ lockupDurationDays: u,
233
+ referrerReward: r.campaign.referrer,
234
+ refereeReward: r.campaign.referee,
235
+ minPurchaseValue: o ?? void 0,
236
+ isProductScoped: r.campaign.productScope != null,
237
+ matchedProducts: r.matchedProducts
238
+ };
239
+ }
240
+ //#endregion
241
+ export { x as i, W as n, b as r, U 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) {
@@ -1,6 +1,6 @@
1
1
  import register from "preact-custom-element";
2
2
  import * as coreSdkIndex from "@frak-labs/core-sdk";
3
- import { decompressJsonFromB64, deleteQueryParamCaseInsensitive, detectPageLanguage, getQueryParamCaseInsensitive, sdkConfigStore, setupClient, trackEvent, withCache } from "@frak-labs/core-sdk";
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, sanitizeProductList as c, useLang as i, openSharingPage as l, buildStyleContent as n, useClientReady as o, lightDomBaseCss as r, registerWebComponent as s, usePlacement as t };
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 { t as E } from "./rewards-BtPHdGcI.js";
1
+ import { n as W } from "./rewards-CDS1CYlm.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 = E(merchantInfo.rewards, {
27
+ const best = W(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
  }
package/package.json CHANGED
@@ -11,7 +11,7 @@
11
11
  "url": "https://twitter.com/QNivelais"
12
12
  }
13
13
  ],
14
- "version": "1.0.13",
14
+ "version": "1.1.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",
@@ -28,7 +28,18 @@
28
28
  "web-components"
29
29
  ],
30
30
  "license": "GNU GPL 3.0",
31
- "sideEffects": false,
31
+ "sideEffects": [
32
+ "**/*.css",
33
+ "**/*.css.ts",
34
+ "**/components/*/index.ts",
35
+ "**/bootstrap/loader.ts",
36
+ "**/components.ts",
37
+ "./dist/buttonShare.js",
38
+ "./dist/buttonWallet.js",
39
+ "./dist/openInApp.js",
40
+ "./dist/postPurchase.js",
41
+ "./dist/banner.js"
42
+ ],
32
43
  "private": false,
33
44
  "publishConfig": {
34
45
  "access": "public"
@@ -92,32 +103,33 @@
92
103
  "publish": "echo 'Publishing components...'"
93
104
  },
94
105
  "dependencies": {
95
- "@frak-labs/core-sdk": "1.2.1",
96
- "@frak-labs/frame-connector": "0.2.0",
97
- "preact": "^10.29.0",
98
- "preact-custom-element": "^4.6.0",
99
- "@frak-labs/design-system": "0.0.0"
106
+ "@frak-labs/core-sdk": "1.3.0",
107
+ "@frak-labs/design-system": "0.0.0",
108
+ "@frak-labs/frame-connector": "1.3.0",
109
+ "preact": "^10.29.7",
110
+ "preact-custom-element": "^4.6.0"
100
111
  },
101
112
  "devDependencies": {
102
113
  "@frak-labs/test-foundation": "0.1.0",
103
- "@preact/preset-vite": "^2.10.4",
114
+ "@preact/preset-vite": "^2.10.6",
104
115
  "@rolldown/plugin-node-polyfills": "^1.0.3",
105
- "@testing-library/jest-dom": "^6.9.1",
116
+ "@testing-library/jest-dom": "^7.0.0",
106
117
  "@testing-library/preact": "^3.2.4",
107
118
  "@testing-library/user-event": "^14.6.1",
108
- "@types/jsdom": "^28.0.0",
109
- "@types/node": "^25.6.0",
119
+ "@types/jsdom": "^28.0.3",
120
+ "@types/node": "^25.9.5",
110
121
  "@types/preact-custom-element": "^4.0.4",
111
122
  "@typescript/native": "npm:typescript@^7.0.2",
112
- "@vanilla-extract/css": "^1.21.1",
123
+ "@vanilla-extract/css": "^1.21.2",
113
124
  "@vanilla-extract/integration": "^8.0.10",
114
- "@vanilla-extract/sprinkles": "^1.6.5",
115
- "@vanilla-extract/vite-plugin": "^5.2.4",
116
- "@vitest/coverage-v8": "^4.1.0",
117
- "@vitest/ui": "^4.1.0",
118
- "jsdom": "^29.0.0",
119
- "tsdown": "^0.22.0",
125
+ "@vanilla-extract/sprinkles": "^1.7.0",
126
+ "@vanilla-extract/vite-plugin": "^5.2.6",
127
+ "@vitest/coverage-v8": "^4.1.10",
128
+ "@vitest/ui": "^4.1.10",
129
+ "jsdom": "^29.1.1",
130
+ "rolldown": "~1.2.0",
131
+ "tsdown": "^0.22.14",
120
132
  "typescript": "^6.0.3",
121
- "vitest": "^4.1.4"
133
+ "vitest": "^4.1.10"
122
134
  }
123
135
  }