@frak-labs/components 1.0.13 → 1.1.0-beta.0fcf93e6

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 (54) hide show
  1. package/README.md +24 -2
  2. package/cdn/Banner.Zaqy93tl.js +183 -0
  3. package/cdn/ButtonShare.BnzCAsRy.js +1 -0
  4. package/cdn/ButtonWallet.DlzZbjCb.js +40 -0
  5. package/cdn/{GiftIcon.DcyE1R1V.js → GiftIcon.CPyeWQNR.js} +1 -1
  6. package/cdn/OpenInAppButton.d-omgD0k.js +1 -0
  7. package/cdn/PostPurchase._3t6CtvV.js +89 -0
  8. package/cdn/components.js +1 -1
  9. package/cdn/defaults.CmUvOlLQ.js +58 -0
  10. package/cdn/loader.js +124 -1
  11. package/cdn/replay-V6FXES7X.CgBxdfNp.js +1 -0
  12. package/cdn/rewards.0JylBHNY.js +1 -0
  13. package/cdn/useGlobalComponents.C7wnXWOg.js +1 -0
  14. package/cdn/useLightDomStyles.B7MVlVVJ.js +1 -0
  15. package/cdn/useReward.CaBorN5T.js +1 -0
  16. package/dist/{GiftIcon-BhL0bhVu.js → GiftIcon-BmGGodb2.js} +8 -8
  17. package/dist/banner.d.ts +12 -5
  18. package/dist/banner.js +16 -14
  19. package/dist/buttonShare.d.ts +28 -10
  20. package/dist/buttonShare.js +26 -20
  21. package/dist/buttonWallet.d.ts +7 -6
  22. package/dist/buttonWallet.js +37 -35
  23. package/dist/i18n/defaults.d.ts +2 -3
  24. package/dist/i18n/defaults.js +2 -2
  25. package/dist/openInApp.d.ts +4 -5
  26. package/dist/openInApp.js +6 -6
  27. package/dist/postPurchase.d.ts +11 -15
  28. package/dist/postPurchase.js +44 -19
  29. package/dist/rewards-DoVY1pWr.js +290 -0
  30. package/dist/{useGlobalComponents-Da9LDlRy.js → useGlobalComponents-BB6djMbu.js} +1 -1
  31. package/dist/{useLightDomStyles-DRkTVy4s.js → useLightDomStyles-0A0CeRlU.js} +1 -1
  32. package/dist/{usePlacement-NZOjZ6IR.js → usePlacement-BzMOjNe0.js} +14 -148
  33. package/dist/{useReward-B-yZ7nhY.js → useReward-k7RF3DhH.js} +10 -5
  34. package/package.json +32 -20
  35. package/cdn/Banner.BM-XicfW.js +0 -183
  36. package/cdn/ButtonShare.DsCfkEG1.js +0 -1
  37. package/cdn/ButtonWallet.BQt3QmKr.js +0 -40
  38. package/cdn/OpenInAppButton.BIfTfSWS.js +0 -1
  39. package/cdn/PostPurchase.Bcnzehoo.js +0 -89
  40. package/cdn/actions-CMPlZ7CH.CJIqArwi.js +0 -1
  41. package/cdn/clientReady.ClcVd4_w.js +0 -1
  42. package/cdn/defaults.CIT5-NpH.js +0 -58
  43. package/cdn/embeddedWallet.BXl45f3Y.js +0 -1
  44. package/cdn/replay-V6FXES7X.efKsNT6s.js +0 -1
  45. package/cdn/rewards.CW3JGWuC.js +0 -1
  46. package/cdn/sharedBaseCss.css.BDzFcWnD.js +0 -154
  47. package/cdn/sharingPage.BjReoj_N.js +0 -1
  48. package/cdn/sharingPageProducts.BoDmfrdn.js +0 -1
  49. package/cdn/styleManager.Cun1-fKi.js +0 -1
  50. package/cdn/useGlobalComponents.DqV5lr6s.js +0 -1
  51. package/cdn/useLightDomStyles.BsQue5kI.js +0 -1
  52. package/cdn/useReward.CcsZ70zp.js +0 -1
  53. package/dist/embeddedWallet-CxgyuwtP.js +0 -18
  54. package/dist/rewards-BtPHdGcI.js +0 -149
@@ -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-NZOjZ6IR.js";
1
+ import { a as subscribeSdkConfig } from "./usePlacement-BzMOjNe0.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-BzMOjNe0.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";
@@ -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
  }
@@ -55,112 +56,6 @@ function detectListenerPreloads() {
55
56
  return document.querySelector(FRAK_COMPONENT_SELECTOR) !== null ? ["sharing"] : [];
56
57
  }
57
58
  //#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
59
  //#region src/bootstrap/clientReady.ts
165
60
  const CUSTOM_EVENT_NAME = "frak:client";
166
61
  /**
@@ -171,9 +66,8 @@ function dispatchClientReadyEvent() {
171
66
  window.dispatchEvent(event);
172
67
  }
173
68
  /**
174
- * Add or remove an event listener for when the Frak client is ready
175
- * @param action
176
- * @param callback
69
+ * Add or remove an event listener for when the Frak client is ready.
70
+ * An `add` on an already-ready client runs the callback immediately.
177
71
  */
178
72
  function onClientReady(action, callback) {
179
73
  if (window.FrakSetup?.client && action === "add") {
@@ -188,8 +82,6 @@ function onClientReady(action, callback) {
188
82
  * Initializes the Frak SDK client and sets up necessary configurations.
189
83
  * Uses withCache for inflight dedup — concurrent callers share the same promise.
190
84
  * Failures are not cached, allowing retry on next call.
191
- *
192
- * @returns {Promise<void>}
193
85
  */
194
86
  function initFrakSdk() {
195
87
  window.FrakSetup.core = {
@@ -213,24 +105,17 @@ function initFrakSdk() {
213
105
  */
214
106
  async function doInit() {
215
107
  if (!window.FrakSetup?.config) throw new Error("[Frak SDK] Configuration not found. Please ensure window.FrakSetup.config is set.");
216
- console.log("[Frak SDK] Starting initialization");
217
108
  const client = await setupClient({ config: withDynamicPreload(window.FrakSetup.config) });
218
109
  if (!client) throw new Error("[Frak SDK] Failed to create client");
219
110
  window.FrakSetup.client = client;
220
- console.log("[Frak SDK] Client initialized successfully");
221
111
  dispatchClientReadyEvent();
222
112
  coreSdkActions.setupReferral(client);
223
113
  handleActionQueryParam();
224
114
  }
225
115
  /**
226
- * Inject a dynamically-computed `preload` list when the caller hasn't set
227
- * one explicitly.
228
- *
229
- * Rationale: the listener iframe warms Ring 1/Ring 2 chunks based on the
230
- * `#preload=...` hash. The components CDN entry can detect which Frak
231
- * components are actually on the page and avoid the warm-up cost when none
232
- * are mounted. An explicit `config.preload` (including `[]`) is respected
233
- * as an escape hatch.
116
+ * Inject a dynamically-computed `preload` list, so the listener only warms the
117
+ * chunks the mounted components need. An explicit `config.preload` (including
118
+ * `[]`) is respected as an escape hatch.
234
119
  */
235
120
  function withDynamicPreload(config) {
236
121
  if (config.preload !== void 0) return config;
@@ -240,33 +125,14 @@ function withDynamicPreload(config) {
240
125
  };
241
126
  }
242
127
  /**
243
- * Check the query param for an auto-opening of the Frak sharing page.
244
- *
245
- * Supported params (all optional except `frakAction`):
246
- * - `frakAction=share` triggers the auto-open.
247
- * - `link` overrides the URL the sharing page generates outbound shares for.
248
- * When omitted, the listener falls back to the merchant domain.
249
- * - `products` is a base64-encoded compressed JSON payload of
250
- * `SharingPageProduct[]` — produced by `compressJsonToB64(productsArray)`
251
- * on the sender side (e.g. a Klaviyo email template). Used by
252
- * post-purchase emails to surface the items the customer just bought as
253
- * product cards on the sharing page.
254
- * - `placement` lets the caller scope backend-driven CSS / config to a
255
- * specific placement (mirrors the prop on the components).
256
- *
257
- * The four params are stripped from the URL via `history.replaceState` as
258
- * soon as they are read, so refreshes / shares of the current URL do not
259
- * re-trigger the auto-open. Matches the `fmt` (merge token) and `sso`
260
- * cleanup patterns elsewhere in the SDK.
261
- *
262
- * Param keys and the `frakAction` keyword value are matched case-insensitively
263
- * because some email tools and browsers lowercase the whole URL in transit
264
- * (e.g. `?FrakAction=Share` → `?frakaction=share`).
128
+ * Auto-open the sharing page from `?frakAction=share`, optionally scoped by
129
+ * `link`, `placement` and a `compressJsonToB64` `products` payload. Keys and
130
+ * the keyword value are matched case-insensitively: email tools and browsers
131
+ * lowercase the whole URL in transit (`?FrakAction=Share`).
265
132
  */
266
133
  function handleActionQueryParam() {
267
134
  const url = new URL(window.location.href);
268
135
  if (getQueryParamCaseInsensitive(url.searchParams, "frakAction")?.toLowerCase() !== "share") return;
269
- console.log("[Frak SDK] Auto open share via query param");
270
136
  const link = getQueryParamCaseInsensitive(url.searchParams, "link") ?? void 0;
271
137
  const placement = getQueryParamCaseInsensitive(url.searchParams, "placement") ?? void 0;
272
138
  const products = decodeProductsParam(getQueryParamCaseInsensitive(url.searchParams, "products"));
@@ -284,7 +150,6 @@ function handleActionQueryParam() {
284
150
  //#region src/utils/browser/onDocumentReady.ts
285
151
  /**
286
152
  * When the document is ready, run the callback
287
- * @param callback
288
153
  */
289
154
  function onDocumentReady(callback) {
290
155
  if (document.readyState === "complete" || document.readyState === "interactive") setTimeout(callback, 1);
@@ -453,7 +318,8 @@ function getPlacement(id) {
453
318
  * only re-renders when that placement actually changes.
454
319
  */
455
320
  function usePlacement(placementId) {
456
- return useSyncExternalStore(subscribeSdkConfig, useCallback(() => placementId ? getPlacement(placementId) : void 0, [placementId]));
321
+ const getSnapshot = useCallback(() => placementId ? getPlacement(placementId) : void 0, [placementId]);
322
+ return useSyncExternalStore(subscribeSdkConfig, getSnapshot);
457
323
  }
458
324
  //#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 };
325
+ 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 { 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
@@ -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 = q(merchantInfo.rewards, {
25
28
  currency: client.config.metadata?.currency,
26
29
  targetInteraction,
27
- audience
30
+ audience,
31
+ products
28
32
  });
29
33
  if (best && best.payoutType !== "percentage") setReward(best.formatted);
30
34
  }).catch(() => {});
31
35
  }, [
32
36
  shouldUseReward,
33
37
  targetInteraction,
34
- audience
38
+ audience,
39
+ products
35
40
  ]);
36
41
  return { reward };
37
42
  }
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-beta.0fcf93e6",
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-beta.0fcf93e6",
107
+ "@frak-labs/frame-connector": "1.3.0-beta.0fcf93e6",
108
+ "preact": "^10.29.8",
109
+ "preact-custom-element": "^4.6.0"
100
110
  },
101
111
  "devDependencies": {
112
+ "@frak-labs/design-system": "0.0.0",
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.1",
106
117
  "@testing-library/preact": "^3.2.4",
107
- "@testing-library/user-event": "^14.6.1",
108
- "@types/jsdom": "^28.0.0",
109
- "@types/node": "^25.6.0",
118
+ "@testing-library/user-event": "^14.6.7",
119
+ "@types/jsdom": "^30.0.0",
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.1",
126
+ "@vanilla-extract/vite-plugin": "^5.2.6",
127
+ "@vitest/coverage-v8": "^5.0.0",
128
+ "@vitest/ui": "^5.0.0",
129
+ "jsdom": "^30.0.1",
130
+ "rolldown": "~1.2.0",
131
+ "tsdown": "^0.23.0",
120
132
  "typescript": "^6.0.3",
121
- "vitest": "^4.1.4"
133
+ "vitest": "^5.0.0"
122
134
  }
123
135
  }