@frak-labs/components 1.0.13 → 1.1.0-beta.144a334c
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.
- package/cdn/Banner.Dh-KYDLv.js +183 -0
- package/cdn/ButtonShare.CiEtGubR.js +1 -0
- package/cdn/ButtonWallet.B-80TBVO.js +40 -0
- package/cdn/{GiftIcon.DcyE1R1V.js → GiftIcon.CPyeWQNR.js} +1 -1
- package/cdn/OpenInAppButton.DYfr8q7L.js +1 -0
- package/cdn/PostPurchase.CxEoeBs_.js +89 -0
- package/cdn/components.js +1 -1
- package/cdn/defaults.CmUvOlLQ.js +58 -0
- package/cdn/loader.js +168 -1
- package/cdn/replay-V6FXES7X.CgBxdfNp.js +1 -0
- package/cdn/rewards.DjfrchZd.js +1 -0
- package/cdn/useGlobalComponents.C7wnXWOg.js +1 -0
- package/cdn/useLightDomStyles.BLyrWEBn.js +1 -0
- package/cdn/useReward.fvxtDVaA.js +1 -0
- package/dist/{GiftIcon-BhL0bhVu.js → GiftIcon-DI0rUKHp.js} +7 -7
- package/dist/banner.d.ts +10 -2
- package/dist/banner.js +15 -13
- package/dist/buttonShare.d.ts +26 -7
- package/dist/buttonShare.js +23 -17
- package/dist/buttonWallet.d.ts +7 -2
- package/dist/buttonWallet.js +34 -10
- package/dist/i18n/defaults.js +2 -2
- package/dist/openInApp.js +4 -3
- package/dist/postPurchase.d.ts +8 -11
- package/dist/postPurchase.js +29 -18
- package/dist/rewards-CZkWSndn.js +290 -0
- package/dist/{useGlobalComponents-Da9LDlRy.js → useGlobalComponents-DFv33ujB.js} +1 -1
- package/dist/{useLightDomStyles-DRkTVy4s.js → useLightDomStyles-B_IbOqJZ.js} +1 -1
- package/dist/{usePlacement-NZOjZ6IR.js → usePlacement-DtwWaLHO.js} +5 -109
- package/dist/{useReward-B-yZ7nhY.js → useReward-D5zzFR11.js} +10 -5
- package/package.json +31 -19
- package/cdn/Banner.BM-XicfW.js +0 -183
- package/cdn/ButtonShare.DsCfkEG1.js +0 -1
- package/cdn/ButtonWallet.BQt3QmKr.js +0 -40
- package/cdn/OpenInAppButton.BIfTfSWS.js +0 -1
- package/cdn/PostPurchase.Bcnzehoo.js +0 -89
- package/cdn/actions-CMPlZ7CH.CJIqArwi.js +0 -1
- package/cdn/clientReady.ClcVd4_w.js +0 -1
- package/cdn/defaults.CIT5-NpH.js +0 -58
- package/cdn/embeddedWallet.BXl45f3Y.js +0 -1
- package/cdn/replay-V6FXES7X.efKsNT6s.js +0 -1
- package/cdn/rewards.CW3JGWuC.js +0 -1
- package/cdn/sharedBaseCss.css.BDzFcWnD.js +0 -154
- package/cdn/sharingPage.BjReoj_N.js +0 -1
- package/cdn/sharingPageProducts.BoDmfrdn.js +0 -1
- package/cdn/styleManager.Cun1-fKi.js +0 -1
- package/cdn/useGlobalComponents.DqV5lr6s.js +0 -1
- package/cdn/useLightDomStyles.BsQue5kI.js +0 -1
- package/cdn/useReward.CcsZ70zp.js +0 -1
- package/dist/embeddedWallet-CxgyuwtP.js +0 -18
- 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 === void 0) 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 !== void 0;
|
|
200
|
+
if (r === `not_exists`) return n === void 0;
|
|
201
|
+
if (r === `in` || r === `not_in`) return P(r, n, i);
|
|
202
|
+
if (!(Array.isArray(i) || n === void 0 || 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-
|
|
1
|
+
import { a as subscribeSdkConfig } from "./usePlacement-DtwWaLHO.js";
|
|
2
2
|
import { sdkConfigStore } from "@frak-labs/core-sdk";
|
|
3
3
|
import { useSyncExternalStore } from "preact/compat";
|
|
4
4
|
//#region src/hooks/useGlobalComponents.ts
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import register from "preact-custom-element";
|
|
2
2
|
import * as coreSdkIndex from "@frak-labs/core-sdk";
|
|
3
|
-
import {
|
|
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
|
/**
|
|
@@ -453,7 +348,8 @@ function getPlacement(id) {
|
|
|
453
348
|
* only re-renders when that placement actually changes.
|
|
454
349
|
*/
|
|
455
350
|
function usePlacement(placementId) {
|
|
456
|
-
|
|
351
|
+
const getSnapshot = useCallback(() => placementId ? getPlacement(placementId) : void 0, [placementId]);
|
|
352
|
+
return useSyncExternalStore(subscribeSdkConfig, getSnapshot);
|
|
457
353
|
}
|
|
458
354
|
//#endregion
|
|
459
|
-
export { subscribeSdkConfig as a,
|
|
355
|
+
export { subscribeSdkConfig as a, openSharingPage as c, useLang as i, buildStyleContent as n, useClientReady as o, lightDomBaseCss as r, registerWebComponent as s, usePlacement as t };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { r as q } from "./rewards-CZkWSndn.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 =
|
|
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.
|
|
14
|
+
"version": "1.1.0-beta.144a334c",
|
|
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":
|
|
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.
|
|
96
|
-
"@frak-labs/
|
|
97
|
-
"
|
|
98
|
-
"preact
|
|
99
|
-
"
|
|
106
|
+
"@frak-labs/core-sdk": "1.3.0-beta.144a334c",
|
|
107
|
+
"@frak-labs/design-system": "0.0.0",
|
|
108
|
+
"@frak-labs/frame-connector": "1.3.0-beta.144a334c",
|
|
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.
|
|
114
|
+
"@preact/preset-vite": "^2.10.6",
|
|
104
115
|
"@rolldown/plugin-node-polyfills": "^1.0.3",
|
|
105
|
-
"@testing-library/jest-dom": "^
|
|
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.
|
|
109
|
-
"@types/node": "^25.
|
|
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.
|
|
123
|
+
"@vanilla-extract/css": "^1.21.2",
|
|
113
124
|
"@vanilla-extract/integration": "^8.0.10",
|
|
114
|
-
"@vanilla-extract/sprinkles": "^1.
|
|
115
|
-
"@vanilla-extract/vite-plugin": "^5.2.
|
|
116
|
-
"@vitest/coverage-v8": "^4.1.
|
|
117
|
-
"@vitest/ui": "^4.1.
|
|
118
|
-
"jsdom": "^29.
|
|
119
|
-
"
|
|
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.
|
|
133
|
+
"vitest": "^4.1.10"
|
|
122
134
|
}
|
|
123
135
|
}
|