@frak-labs/components 1.1.0-beta.d76e66ff → 1.1.0-beta.e946ef0d

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 (45) hide show
  1. package/README.md +24 -2
  2. package/cdn/{Banner.D-DIhGBs.js → Banner.Zaqy93tl.js} +3 -3
  3. package/cdn/ButtonShare.rG47WQjf.js +1 -0
  4. package/cdn/ButtonWallet.C13UfI2G.js +40 -0
  5. package/cdn/{GiftIcon.DabDdDcp.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 +10 -50
  11. package/cdn/rewards.0JylBHNY.js +1 -0
  12. package/cdn/useGlobalComponents.C7wnXWOg.js +1 -0
  13. package/cdn/useLightDomStyles.B7MVlVVJ.js +1 -0
  14. package/cdn/useReward.CaBorN5T.js +1 -0
  15. package/dist/{GiftIcon-BhL0bhVu.js → GiftIcon-BmGGodb2.js} +8 -8
  16. package/dist/banner.d.ts +3 -4
  17. package/dist/banner.js +11 -11
  18. package/dist/buttonShare.d.ts +10 -9
  19. package/dist/buttonShare.js +29 -16
  20. package/dist/buttonWallet.d.ts +7 -6
  21. package/dist/buttonWallet.js +53 -34
  22. package/dist/i18n/defaults.d.ts +2 -3
  23. package/dist/i18n/defaults.js +2 -2
  24. package/dist/openInApp.d.ts +4 -5
  25. package/dist/openInApp.js +6 -6
  26. package/dist/postPurchase.d.ts +6 -5
  27. package/dist/postPurchase.js +30 -13
  28. package/dist/rewards-DoVY1pWr.js +290 -0
  29. package/dist/{useGlobalComponents-CeTO2xYs.js → useGlobalComponents-Cj7uGBwD.js} +1 -1
  30. package/dist/{useLightDomStyles-B2U96tzU.js → useLightDomStyles-BW6DY5sC.js} +1 -1
  31. package/dist/{usePlacement-Bpo25qjA.js → usePlacement-iFDQqtJn.js} +17 -40
  32. package/dist/{useReward-Cg2wk8XI.js → useReward-k7RF3DhH.js} +2 -2
  33. package/package.json +14 -14
  34. package/cdn/ButtonShare.BXBkl-NK.js +0 -1
  35. package/cdn/ButtonWallet.BWpTwDnw.js +0 -40
  36. package/cdn/OpenInAppButton.DAGgrKRg.js +0 -1
  37. package/cdn/PostPurchase.Cp4JWG5x.js +0 -89
  38. package/cdn/defaults.DjBUlRT8.js +0 -58
  39. package/cdn/embeddedWallet.BjQSXLkP.js +0 -1
  40. package/cdn/rewards.BaTam2j1.js +0 -1
  41. package/cdn/useGlobalComponents.4DaqvbCn.js +0 -1
  42. package/cdn/useLightDomStyles.DNP8gafA.js +0 -1
  43. package/cdn/useReward.Bi4Hs7kk.js +0 -1
  44. package/dist/embeddedWallet-CxgyuwtP.js +0 -18
  45. package/dist/rewards-CDS1CYlm.js +0 -241
@@ -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-iFDQqtJn.js";
2
+ import { i as w, n as K, t as C } from "./rewards-DoVY1pWr.js";
3
+ import { t as useGlobalComponents } from "./useGlobalComponents-Cj7uGBwD.js";
4
+ import { t as useLightDomStyles } from "./useLightDomStyles-BW6DY5sC.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-BmGGodb2.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-iFDQqtJn.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-iFDQqtJn.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
  }
@@ -65,9 +66,8 @@ function dispatchClientReadyEvent() {
65
66
  window.dispatchEvent(event);
66
67
  }
67
68
  /**
68
- * Add or remove an event listener for when the Frak client is ready
69
- * @param action
70
- * @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.
71
71
  */
72
72
  function onClientReady(action, callback) {
73
73
  if (window.FrakSetup?.client && action === "add") {
@@ -82,8 +82,6 @@ function onClientReady(action, callback) {
82
82
  * Initializes the Frak SDK client and sets up necessary configurations.
83
83
  * Uses withCache for inflight dedup — concurrent callers share the same promise.
84
84
  * Failures are not cached, allowing retry on next call.
85
- *
86
- * @returns {Promise<void>}
87
85
  */
88
86
  function initFrakSdk() {
89
87
  window.FrakSetup.core = {
@@ -107,24 +105,17 @@ function initFrakSdk() {
107
105
  */
108
106
  async function doInit() {
109
107
  if (!window.FrakSetup?.config) throw new Error("[Frak SDK] Configuration not found. Please ensure window.FrakSetup.config is set.");
110
- console.log("[Frak SDK] Starting initialization");
111
108
  const client = await setupClient({ config: withDynamicPreload(window.FrakSetup.config) });
112
109
  if (!client) throw new Error("[Frak SDK] Failed to create client");
113
110
  window.FrakSetup.client = client;
114
- console.log("[Frak SDK] Client initialized successfully");
115
111
  dispatchClientReadyEvent();
116
112
  coreSdkActions.setupReferral(client);
117
113
  handleActionQueryParam();
118
114
  }
119
115
  /**
120
- * Inject a dynamically-computed `preload` list when the caller hasn't set
121
- * one explicitly.
122
- *
123
- * Rationale: the listener iframe warms Ring 1/Ring 2 chunks based on the
124
- * `#preload=...` hash. The components CDN entry can detect which Frak
125
- * components are actually on the page and avoid the warm-up cost when none
126
- * are mounted. An explicit `config.preload` (including `[]`) is respected
127
- * 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.
128
119
  */
129
120
  function withDynamicPreload(config) {
130
121
  if (config.preload !== void 0) return config;
@@ -134,33 +125,14 @@ function withDynamicPreload(config) {
134
125
  };
135
126
  }
136
127
  /**
137
- * Check the query param for an auto-opening of the Frak sharing page.
138
- *
139
- * Supported params (all optional except `frakAction`):
140
- * - `frakAction=share` triggers the auto-open.
141
- * - `link` overrides the URL the sharing page generates outbound shares for.
142
- * When omitted, the listener falls back to the merchant domain.
143
- * - `products` is a base64-encoded compressed JSON payload of
144
- * `SharingPageProduct[]` — produced by `compressJsonToB64(productsArray)`
145
- * on the sender side (e.g. a Klaviyo email template). Used by
146
- * post-purchase emails to surface the items the customer just bought as
147
- * product cards on the sharing page.
148
- * - `placement` lets the caller scope backend-driven CSS / config to a
149
- * specific placement (mirrors the prop on the components).
150
- *
151
- * The four params are stripped from the URL via `history.replaceState` as
152
- * soon as they are read, so refreshes / shares of the current URL do not
153
- * re-trigger the auto-open. Matches the `fmt` (merge token) and `sso`
154
- * cleanup patterns elsewhere in the SDK.
155
- *
156
- * Param keys and the `frakAction` keyword value are matched case-insensitively
157
- * because some email tools and browsers lowercase the whole URL in transit
158
- * (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`).
159
132
  */
160
133
  function handleActionQueryParam() {
161
134
  const url = new URL(window.location.href);
162
135
  if (getQueryParamCaseInsensitive(url.searchParams, "frakAction")?.toLowerCase() !== "share") return;
163
- console.log("[Frak SDK] Auto open share via query param");
164
136
  const link = getQueryParamCaseInsensitive(url.searchParams, "link") ?? void 0;
165
137
  const placement = getQueryParamCaseInsensitive(url.searchParams, "placement") ?? void 0;
166
138
  const products = decodeProductsParam(getQueryParamCaseInsensitive(url.searchParams, "products"));
@@ -169,6 +141,11 @@ function handleActionQueryParam() {
169
141
  deleteQueryParamCaseInsensitive(url.searchParams, "placement");
170
142
  deleteQueryParamCaseInsensitive(url.searchParams, "products");
171
143
  window.history.replaceState({}, "", url.toString());
144
+ trackEvent(window.FrakSetup?.client, "sharing_page_auto_opened", {
145
+ placement,
146
+ has_link: Boolean(link),
147
+ has_products: Boolean(products?.length)
148
+ });
172
149
  openSharingPage(void 0, placement, {
173
150
  link,
174
151
  products
@@ -178,7 +155,6 @@ function handleActionQueryParam() {
178
155
  //#region src/utils/browser/onDocumentReady.ts
179
156
  /**
180
157
  * When the document is ready, run the callback
181
- * @param callback
182
158
  */
183
159
  function onDocumentReady(callback) {
184
160
  if (document.readyState === "complete" || document.readyState === "interactive") setTimeout(callback, 1);
@@ -347,7 +323,8 @@ function getPlacement(id) {
347
323
  * only re-renders when that placement actually changes.
348
324
  */
349
325
  function usePlacement(placementId) {
350
- return useSyncExternalStore(subscribeSdkConfig, useCallback(() => placementId ? getPlacement(placementId) : void 0, [placementId]));
326
+ const getSnapshot = useCallback(() => placementId ? getPlacement(placementId) : void 0, [placementId]);
327
+ return useSyncExternalStore(subscribeSdkConfig, getSnapshot);
351
328
  }
352
329
  //#endregion
353
330
  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-beta.d76e66ff",
14
+ "version": "1.1.0-beta.e946ef0d",
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",
@@ -103,33 +103,33 @@
103
103
  "publish": "echo 'Publishing components...'"
104
104
  },
105
105
  "dependencies": {
106
- "@frak-labs/core-sdk": "1.3.0-beta.d76e66ff",
107
- "@frak-labs/design-system": "0.0.0",
108
- "@frak-labs/frame-connector": "1.3.0-beta.d76e66ff",
109
- "preact": "^10.29.7",
106
+ "@frak-labs/core-sdk": "1.3.0-beta.e946ef0d",
107
+ "@frak-labs/frame-connector": "1.3.0-beta.e946ef0d",
108
+ "preact": "^10.29.8",
110
109
  "preact-custom-element": "^4.6.0"
111
110
  },
112
111
  "devDependencies": {
112
+ "@frak-labs/design-system": "0.0.0",
113
113
  "@frak-labs/test-foundation": "0.1.0",
114
114
  "@preact/preset-vite": "^2.10.6",
115
115
  "@rolldown/plugin-node-polyfills": "^1.0.3",
116
- "@testing-library/jest-dom": "^7.0.0",
116
+ "@testing-library/jest-dom": "^7.0.1",
117
117
  "@testing-library/preact": "^3.2.4",
118
- "@testing-library/user-event": "^14.6.1",
119
- "@types/jsdom": "^28.0.3",
118
+ "@testing-library/user-event": "^14.6.7",
119
+ "@types/jsdom": "^30.0.0",
120
120
  "@types/node": "^25.9.5",
121
121
  "@types/preact-custom-element": "^4.0.4",
122
122
  "@typescript/native": "npm:typescript@^7.0.2",
123
123
  "@vanilla-extract/css": "^1.21.2",
124
124
  "@vanilla-extract/integration": "^8.0.10",
125
- "@vanilla-extract/sprinkles": "^1.7.0",
125
+ "@vanilla-extract/sprinkles": "^1.7.1",
126
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",
127
+ "@vitest/coverage-v8": "^5.0.0",
128
+ "@vitest/ui": "^5.0.0",
129
+ "jsdom": "^30.0.1",
130
130
  "rolldown": "~1.2.0",
131
- "tsdown": "^0.22.14",
131
+ "tsdown": "^0.23.0",
132
132
  "typescript": "^6.0.3",
133
- "vitest": "^4.1.10"
133
+ "vitest": "^5.0.0"
134
134
  }
135
135
  }
@@ -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.BjQSXLkP.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};
@@ -1,40 +0,0 @@
1
- import{a as e,d as t,f as n,g as r,h as i,m as a,n as o,r as s,s as c,t as l,u}from"./defaults.DjBUlRT8.js";import{t as d}from"./useReward.Bi4Hs7kk.js";import{t as f}from"./embeddedWallet.BjQSXLkP.js";function p(e){return a(`svg`,{fill:`none`,height:`1em`,viewBox:`0 0 28 28`,width:`1em`,xmlns:`http://www.w3.org/2000/svg`,...e,children:[a(`title`,{children:`Gift icon`}),a(`path`,{d:`m23.14 14v11.43h-18.29v-11.43m9.14 11.43v-17.14m0 0h-5.14c-0.76 0-1.48-0.3-2.02-0.84s-0.84-1.26-0.84-2.020.3-1.480.84-2.02 1.26-0.84 2.02-0.84c4 0 5.14 5.71 5.14 5.71zm0 0h5.14c0.76 0 1.48-0.3 2.02-0.84s0.84-1.260.84-2.02-0.3-1.48-0.84-2.02-1.26-0.84-2.02-0.84c-4 0-5.14 5.71-5.14 5.71zm-11.43 0h22.86v5.71h-22.86z`,stroke:`#fff`,"stroke-linecap":`round`,"stroke-linejoin":`round`})]})}function m(){`vibrate`in navigator?navigator.vibrate(10):console.log(`Vibration not supported`)}function h(e,t){m(),f(e,t)}function g({placement:i,classname:f=``,useReward:m,targetInteraction:g}){let _=e(),v=o(i),y=u(()=>v?.targetInteraction===void 0?g:v.targetInteraction,[v?.targetInteraction,g]),b=u(()=>m===!0,[m]),{shouldRender:x,isHidden:S,isClientReady:C}=c(),{reward:w}=d(b&&C,y),[T,E]=t(`right`);if(n(()=>{let e=v?.components?.buttonWallet?.position,t=window.FrakSetup?.modalWalletConfig?.metadata?.position;E(e??t??`right`)},[v?.components?.buttonWallet?.position]),!x||S)return null;let D=[`button`,`button__fadeIn`,T===`left`?`button__left`:`button__right`,f].filter(Boolean).join(` `);return a(r,{children:[a(`style`,{children:s(`
2
- .button {
3
- all: unset;
4
- position: fixed;
5
- bottom: 20px;
6
- z-index: 2000000;
7
- display: flex;
8
- justify-content: center;
9
- align-items: center;
10
- background-color: #3e557e;
11
- width: 45px;
12
- height: 45px;
13
- border-radius: 50%;
14
- cursor: pointer;
15
- text-align: center;
16
- font-size: 24px;
17
- }
18
-
19
- .button__left {
20
- left: 20px;
21
- }
22
-
23
- .button__right {
24
- right: 20px;
25
- }
26
-
27
- .reward {
28
- position: absolute;
29
- top: -4px;
30
- right: 27px;
31
- padding: 2px 3px;
32
- border-radius: 5px;
33
- background: #ff3f3f;
34
- font-size: 9px;
35
- color: #fff;
36
- font-weight: 600;
37
- white-space: nowrap;
38
- line-height: 9px;
39
- }
40
- `,v?.components?.buttonWallet?.css)}),a(`button`,{type:`button`,"aria-label":l[_].buttonWallet.ariaLabel,part:`button`,disabled:!C,class:D,onClick:()=>{h(y,i)},children:[a(p,{}),w&&a(`span`,{class:`reward`,children:w})]})]})}i(g,`frak-button-wallet`,[`placement`,`classname`,`useReward`,`targetInteraction`],{shadow:!0});export{g as ButtonWallet};
@@ -1 +0,0 @@
1
- import{S as e,f as t,h as n,m as r}from"./loader.js";import{a as i,h as a,m as o,n as s,s as c,t as l,u}from"./defaults.DjBUlRT8.js";import{t as d}from"./useLightDomStyles.DNP8gafA.js";function f(r=`wallet`,i){let a=window.FrakSetup?.client;a&&e(a,`open_in_app_clicked`,{path:r,placement:i}),t(`${n}${r}`,{onFallback:()=>{a&&e(a,`app_not_installed`,{path:r,placement:i})}})}function p(){return{isMobile:u(()=>r(),[])}}function m({placement:e,text:t,classname:n=``}){let r=i(),a=s(e),{shouldRender:u,isHidden:m,isClientReady:h}=c(),{isMobile:g}=p();d(`frak-open-in-app`,e,a?.components?.openInApp?.css);let _=a?.components?.openInApp?.text??t??l[r].openInApp.text;if(!g||!u||m)return null;let v=()=>{f(void 0,e)},y=[`button`,`button__fadeIn`,n].filter(Boolean).join(` `);return o(`button`,{type:`button`,"aria-label":l[r].openInApp.ariaLabel,disabled:!h,class:y,onClick:v,children:_})}a(m,`frak-open-in-app`,[`text`,`placement`,`classname`],{shadow:!1});export{m as OpenInAppButton};