@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
package/dist/buttonShare.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { InteractionTypeKey } from "@frak-labs/core-sdk";
|
|
1
|
+
import { InteractionTypeKey, SharingPageProduct } from "@frak-labs/core-sdk";
|
|
2
2
|
//#region src/components/ButtonShare/types.d.ts
|
|
3
3
|
/**
|
|
4
4
|
* The props type for {@link ButtonShare}.
|
|
@@ -34,15 +34,26 @@ type ButtonShareProps = {
|
|
|
34
34
|
*/
|
|
35
35
|
targetInteraction?: InteractionTypeKey;
|
|
36
36
|
/**
|
|
37
|
-
*
|
|
37
|
+
* Products currently in view, used to prefer a campaign whose
|
|
38
|
+
* `productScope` matches one of them when picking the reward to advertise,
|
|
39
|
+
* and forwarded to the sharing page so it can render product cards.
|
|
38
40
|
*
|
|
39
|
-
*
|
|
40
|
-
*
|
|
41
|
-
|
|
41
|
+
* Accepts a {@link SharingPageProduct} array (JS property) or a
|
|
42
|
+
* JSON-stringified array (HTML attribute).
|
|
43
|
+
*/
|
|
44
|
+
products?: SharingPageProduct[] | string;
|
|
45
|
+
/**
|
|
46
|
+
* Reported on the `share_button_clicked` event.
|
|
47
|
+
*
|
|
48
|
+
* It no longer selects anything: every click opens the full-page sharing
|
|
49
|
+
* UI. Retired values (`"share-modal"`, `"embedded-wallet"`) stay accepted
|
|
50
|
+
* because merchant configs and saved plugin markup still carry them, and
|
|
51
|
+
* the resolved value is reported as-is so a legacy config stays visible in
|
|
52
|
+
* analytics.
|
|
42
53
|
*
|
|
43
54
|
* @defaultValue `"sharing-page"`
|
|
44
55
|
*/
|
|
45
|
-
clickAction?: "
|
|
56
|
+
clickAction?: "sharing-page" | (string & {});
|
|
46
57
|
/**
|
|
47
58
|
* When set, renders the button in preview mode (e.g. Shopify/WP editor).
|
|
48
59
|
* Skips the client-ready gating so the button is always enabled visually,
|
|
@@ -94,10 +105,18 @@ type ButtonShareProps = {
|
|
|
94
105
|
* <frak-button-share text="Share and earn up to {REWARD}!" no-reward-text="Share and earn!" target-interaction="custom.customerMeeting"></frak-button-share>
|
|
95
106
|
* ```
|
|
96
107
|
*
|
|
108
|
+
* @example
|
|
109
|
+
* On a product page, pass the displayed product(s) so a matching
|
|
110
|
+
* `productScope`d campaign is preferred and the sharing page can render product
|
|
111
|
+
* cards:
|
|
112
|
+
* ```html
|
|
113
|
+
* <frak-button-share text="Share and earn up to {REWARD}!" products='[{"title":"Shoes","sku":"SHOE-42","unitPrice":79.90}]'></frak-button-share>
|
|
114
|
+
* ```
|
|
115
|
+
*
|
|
97
116
|
* @see {@link @frak-labs/core-sdk!actions.displaySharingPage | `displaySharingPage()`} for more info about the sharing-page flow
|
|
98
117
|
* @see {@link @frak-labs/core-sdk!actions.getMerchantInformation | `getMerchantInformation()`} for more info about the estimated reward fetching
|
|
99
118
|
*/
|
|
100
|
-
declare function ButtonShare({ placement: placementId, text, classname, noRewardText, targetInteraction, clickAction: rawClickAction, preview }: ButtonShareProps): import("preact").JSX.Element | null;
|
|
119
|
+
declare function ButtonShare({ placement: placementId, text, classname, noRewardText, targetInteraction, products, clickAction: rawClickAction, preview }: ButtonShareProps): import("preact").JSX.Element | null;
|
|
101
120
|
//#endregion
|
|
102
121
|
//#region src/components/ButtonShare/index.d.ts
|
|
103
122
|
/**
|
package/dist/buttonShare.js
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { t as
|
|
3
|
-
import { t as
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import { t as useReward } from "./useReward-B-yZ7nhY.js";
|
|
1
|
+
import { c as openSharingPage, i as useLang, o as useClientReady, s as registerWebComponent, t as usePlacement } from "./usePlacement-DtwWaLHO.js";
|
|
2
|
+
import { t as useGlobalComponents } from "./useGlobalComponents-DFv33ujB.js";
|
|
3
|
+
import { t as useLightDomStyles } from "./useLightDomStyles-B_IbOqJZ.js";
|
|
4
|
+
import { i as w } from "./rewards-CZkWSndn.js";
|
|
5
|
+
import { t as useReward } from "./useReward-D5zzFR11.js";
|
|
7
6
|
import { componentDefaults } from "./i18n/defaults.js";
|
|
8
|
-
import { trackEvent } from "@frak-labs/core-sdk";
|
|
7
|
+
import { sanitizeSharingProducts, trackEvent } from "@frak-labs/core-sdk";
|
|
9
8
|
import { useCallback, useMemo } from "preact/hooks";
|
|
10
9
|
import { jsx } from "preact/jsx-runtime";
|
|
11
10
|
//#region src/components/ButtonShare/ButtonShare.tsx
|
|
@@ -50,10 +49,18 @@ import { jsx } from "preact/jsx-runtime";
|
|
|
50
49
|
* <frak-button-share text="Share and earn up to {REWARD}!" no-reward-text="Share and earn!" target-interaction="custom.customerMeeting"></frak-button-share>
|
|
51
50
|
* ```
|
|
52
51
|
*
|
|
52
|
+
* @example
|
|
53
|
+
* On a product page, pass the displayed product(s) so a matching
|
|
54
|
+
* `productScope`d campaign is preferred and the sharing page can render product
|
|
55
|
+
* cards:
|
|
56
|
+
* ```html
|
|
57
|
+
* <frak-button-share text="Share and earn up to {REWARD}!" products='[{"title":"Shoes","sku":"SHOE-42","unitPrice":79.90}]'></frak-button-share>
|
|
58
|
+
* ```
|
|
59
|
+
*
|
|
53
60
|
* @see {@link @frak-labs/core-sdk!actions.displaySharingPage | `displaySharingPage()`} for more info about the sharing-page flow
|
|
54
61
|
* @see {@link @frak-labs/core-sdk!actions.getMerchantInformation | `getMerchantInformation()`} for more info about the estimated reward fetching
|
|
55
62
|
*/
|
|
56
|
-
function ButtonShare({ placement: placementId, text, classname = "", noRewardText, targetInteraction, clickAction: rawClickAction, preview }) {
|
|
63
|
+
function ButtonShare({ placement: placementId, text, classname = "", noRewardText, targetInteraction, products, clickAction: rawClickAction, preview }) {
|
|
57
64
|
const isPreview = !!preview;
|
|
58
65
|
const lang = useLang();
|
|
59
66
|
const placement = usePlacement(placementId);
|
|
@@ -66,11 +73,12 @@ function ButtonShare({ placement: placementId, text, classname = "", noRewardTex
|
|
|
66
73
|
const wantsReward = useMemo(() => resolvedText.includes("{REWARD}"), [resolvedText]);
|
|
67
74
|
const resolvedClickAction = useMemo(() => componentConfig?.clickAction ?? rawClickAction ?? "sharing-page", [componentConfig?.clickAction, rawClickAction]);
|
|
68
75
|
const { shouldRender, isHidden, isClientReady } = useClientReady();
|
|
69
|
-
const
|
|
76
|
+
const parsedProducts = useMemo(() => sanitizeSharingProducts(products), [products]);
|
|
77
|
+
const { reward } = useReward(wantsReward && isClientReady, resolvedTargetInteraction, void 0, parsedProducts);
|
|
70
78
|
const btnText = useMemo(() => {
|
|
71
79
|
if (!wantsReward) return resolvedText;
|
|
72
|
-
if (reward) return
|
|
73
|
-
return resolvedNoRewardText ??
|
|
80
|
+
if (reward) return w(resolvedText, reward);
|
|
81
|
+
return resolvedNoRewardText ?? w(resolvedText, void 0);
|
|
74
82
|
}, [
|
|
75
83
|
wantsReward,
|
|
76
84
|
resolvedText,
|
|
@@ -85,17 +93,14 @@ function ButtonShare({ placement: placementId, text, classname = "", noRewardTex
|
|
|
85
93
|
has_reward: Boolean(reward),
|
|
86
94
|
click_action: resolvedClickAction
|
|
87
95
|
});
|
|
88
|
-
|
|
89
|
-
openEmbeddedWallet(resolvedTargetInteraction, placementId);
|
|
90
|
-
return;
|
|
91
|
-
}
|
|
92
|
-
openSharingPage(resolvedTargetInteraction, placementId);
|
|
96
|
+
openSharingPage(resolvedTargetInteraction, placementId, { products: parsedProducts });
|
|
93
97
|
}, [
|
|
94
98
|
isPreview,
|
|
95
99
|
resolvedClickAction,
|
|
96
100
|
resolvedTargetInteraction,
|
|
97
101
|
placementId,
|
|
98
|
-
reward
|
|
102
|
+
reward,
|
|
103
|
+
parsedProducts
|
|
99
104
|
]);
|
|
100
105
|
if (!isPreview && (!shouldRender || isHidden)) return null;
|
|
101
106
|
const buttonClass = [
|
|
@@ -120,6 +125,7 @@ registerWebComponent(ButtonShare, "frak-button-share", [
|
|
|
120
125
|
"clickAction",
|
|
121
126
|
"noRewardText",
|
|
122
127
|
"targetInteraction",
|
|
128
|
+
"products",
|
|
123
129
|
"preview"
|
|
124
130
|
], { shadow: false });
|
|
125
131
|
//#endregion
|
package/dist/buttonWallet.d.ts
CHANGED
|
@@ -23,7 +23,12 @@ type ButtonWalletProps = {
|
|
|
23
23
|
//#endregion
|
|
24
24
|
//#region src/components/ButtonWallet/ButtonWallet.d.ts
|
|
25
25
|
/**
|
|
26
|
-
*
|
|
26
|
+
* Floating circular button that opens the Frak sharing page.
|
|
27
|
+
*
|
|
28
|
+
* Historically this opened the embedded wallet drawer; that surface was
|
|
29
|
+
* retired, so the button now routes to the full-page sharing UI like every
|
|
30
|
+
* other share CTA. The `frak-button-wallet` tag name is kept because it is
|
|
31
|
+
* public API (merchant markup, Magento template).
|
|
27
32
|
*
|
|
28
33
|
* @param args
|
|
29
34
|
* @returns The wallet button with `<button>` tag
|
|
@@ -60,7 +65,7 @@ type ButtonWalletProps = {
|
|
|
60
65
|
* <frak-button-wallet placement="hero-wallet"></frak-button-wallet>
|
|
61
66
|
* ```
|
|
62
67
|
*
|
|
63
|
-
* @see {@link @frak-labs/core-sdk!actions.
|
|
68
|
+
* @see {@link @frak-labs/core-sdk!actions.displaySharingPage | `displaySharingPage()`} for more info about the sharing page
|
|
64
69
|
* @see {@link @frak-labs/core-sdk!actions.getMerchantInformation | `getMerchantInformation()`} for more info about the estimated reward fetching
|
|
65
70
|
*/
|
|
66
71
|
declare function ButtonWallet({ placement: placementId, classname, useReward: rawUseReward, targetInteraction }: ButtonWalletProps): import("preact").JSX.Element | null;
|
package/dist/buttonWallet.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { i as useLang, n as buildStyleContent, o as useClientReady, s as registerWebComponent, t as usePlacement } from "./usePlacement-
|
|
2
|
-
import { t as
|
|
3
|
-
import { t as useReward } from "./useReward-B-yZ7nhY.js";
|
|
1
|
+
import { c as openSharingPage, i as useLang, n as buildStyleContent, o as useClientReady, s as registerWebComponent, t as usePlacement } from "./usePlacement-DtwWaLHO.js";
|
|
2
|
+
import { t as useReward } from "./useReward-D5zzFR11.js";
|
|
4
3
|
import { componentDefaults } from "./i18n/defaults.js";
|
|
5
|
-
import {
|
|
4
|
+
import { trackEvent } from "@frak-labs/core-sdk";
|
|
5
|
+
import { useCallback, useEffect, useMemo, useState } from "preact/hooks";
|
|
6
6
|
import { Fragment, jsx, jsxs } from "preact/jsx-runtime";
|
|
7
7
|
//#region src/components/ButtonWallet/assets/GiftIcon.tsx
|
|
8
8
|
function GiftIcon(props) {
|
|
@@ -32,9 +32,17 @@ function safeVibrate() {
|
|
|
32
32
|
}
|
|
33
33
|
//#endregion
|
|
34
34
|
//#region src/components/ButtonWallet/utils.ts
|
|
35
|
+
/**
|
|
36
|
+
* Open the sharing surface behind `<frak-button-wallet>`.
|
|
37
|
+
*
|
|
38
|
+
* The button used to open the embedded wallet drawer; that surface was
|
|
39
|
+
* retired in favour of the full-page sharing UI, so the tag now routes
|
|
40
|
+
* there like every other share CTA. The tag name is kept because it is
|
|
41
|
+
* public API (merchant markup, Magento template).
|
|
42
|
+
*/
|
|
35
43
|
function openWalletModal(targetInteraction, placement) {
|
|
36
44
|
safeVibrate();
|
|
37
|
-
|
|
45
|
+
openSharingPage(targetInteraction, placement);
|
|
38
46
|
}
|
|
39
47
|
//#endregion
|
|
40
48
|
//#region src/components/ButtonWallet/ButtonWallet.tsx
|
|
@@ -79,7 +87,12 @@ const componentCss = `
|
|
|
79
87
|
}
|
|
80
88
|
`;
|
|
81
89
|
/**
|
|
82
|
-
*
|
|
90
|
+
* Floating circular button that opens the Frak sharing page.
|
|
91
|
+
*
|
|
92
|
+
* Historically this opened the embedded wallet drawer; that surface was
|
|
93
|
+
* retired, so the button now routes to the full-page sharing UI like every
|
|
94
|
+
* other share CTA. The `frak-button-wallet` tag name is kept because it is
|
|
95
|
+
* public API (merchant markup, Magento template).
|
|
83
96
|
*
|
|
84
97
|
* @param args
|
|
85
98
|
* @returns The wallet button with `<button>` tag
|
|
@@ -116,7 +129,7 @@ const componentCss = `
|
|
|
116
129
|
* <frak-button-wallet placement="hero-wallet"></frak-button-wallet>
|
|
117
130
|
* ```
|
|
118
131
|
*
|
|
119
|
-
* @see {@link @frak-labs/core-sdk!actions.
|
|
132
|
+
* @see {@link @frak-labs/core-sdk!actions.displaySharingPage | `displaySharingPage()`} for more info about the sharing page
|
|
120
133
|
* @see {@link @frak-labs/core-sdk!actions.getMerchantInformation | `getMerchantInformation()`} for more info about the estimated reward fetching
|
|
121
134
|
*/
|
|
122
135
|
function ButtonWallet({ placement: placementId, classname = "", useReward: rawUseReward, targetInteraction }) {
|
|
@@ -127,6 +140,19 @@ function ButtonWallet({ placement: placementId, classname = "", useReward: rawUs
|
|
|
127
140
|
const { shouldRender, isHidden, isClientReady } = useClientReady();
|
|
128
141
|
const { reward } = useReward(shouldUseReward && isClientReady, resolvedTargetInteraction);
|
|
129
142
|
const [position, setPosition] = useState("right");
|
|
143
|
+
const onClick = useCallback(() => {
|
|
144
|
+
trackEvent(window.FrakSetup.client, "share_button_clicked", {
|
|
145
|
+
placement: placementId,
|
|
146
|
+
target_interaction: resolvedTargetInteraction,
|
|
147
|
+
has_reward: Boolean(reward),
|
|
148
|
+
click_action: "sharing-page"
|
|
149
|
+
});
|
|
150
|
+
openWalletModal(resolvedTargetInteraction, placementId);
|
|
151
|
+
}, [
|
|
152
|
+
placementId,
|
|
153
|
+
resolvedTargetInteraction,
|
|
154
|
+
reward
|
|
155
|
+
]);
|
|
130
156
|
useEffect(() => {
|
|
131
157
|
const placementPosition = placement?.components?.buttonWallet?.position;
|
|
132
158
|
const configPosition = window.FrakSetup?.modalWalletConfig?.metadata?.position;
|
|
@@ -145,9 +171,7 @@ function ButtonWallet({ placement: placementId, classname = "", useReward: rawUs
|
|
|
145
171
|
part: "button",
|
|
146
172
|
disabled: !isClientReady,
|
|
147
173
|
class: buttonClass,
|
|
148
|
-
onClick
|
|
149
|
-
openWalletModal(resolvedTargetInteraction, placementId);
|
|
150
|
-
},
|
|
174
|
+
onClick,
|
|
151
175
|
children: [/* @__PURE__ */ jsx(GiftIcon, {}), reward && /* @__PURE__ */ jsx("span", {
|
|
152
176
|
class: "reward",
|
|
153
177
|
children: reward
|
package/dist/i18n/defaults.js
CHANGED
|
@@ -27,7 +27,7 @@ const componentDefaults = {
|
|
|
27
27
|
text: "Open in App",
|
|
28
28
|
ariaLabel: "Open in Frak Wallet app"
|
|
29
29
|
},
|
|
30
|
-
buttonWallet: { ariaLabel: "
|
|
30
|
+
buttonWallet: { ariaLabel: "Share and earn rewards" },
|
|
31
31
|
banner: {
|
|
32
32
|
referralTitleReward: "Earn {REWARD} on purchases",
|
|
33
33
|
referralTitle: "You've been referred!",
|
|
@@ -53,7 +53,7 @@ const componentDefaults = {
|
|
|
53
53
|
text: "Ouvrir dans l'app",
|
|
54
54
|
ariaLabel: "Ouvrir dans l'app Frak Wallet"
|
|
55
55
|
},
|
|
56
|
-
buttonWallet: { ariaLabel: "
|
|
56
|
+
buttonWallet: { ariaLabel: "Partagez et gagnez des récompenses" },
|
|
57
57
|
banner: {
|
|
58
58
|
referralTitleReward: "Gagnez {REWARD} sur vos achats",
|
|
59
59
|
referralTitle: "Vous avez été parrainé !",
|
package/dist/openInApp.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { i as useLang, o as useClientReady, s as registerWebComponent, t as usePlacement } from "./usePlacement-
|
|
2
|
-
import { t as useLightDomStyles } from "./useLightDomStyles-
|
|
1
|
+
import { i as useLang, o as useClientReady, s as registerWebComponent, t as usePlacement } from "./usePlacement-DtwWaLHO.js";
|
|
2
|
+
import { t as useLightDomStyles } from "./useLightDomStyles-B_IbOqJZ.js";
|
|
3
3
|
import { componentDefaults } from "./i18n/defaults.js";
|
|
4
4
|
import { DEEP_LINK_SCHEME, isMobile, trackEvent, triggerDeepLinkWithFallback } from "@frak-labs/core-sdk";
|
|
5
5
|
import { useMemo } from "preact/hooks";
|
|
@@ -19,7 +19,8 @@ function openFrakWalletApp(path = DEFAULT_PATH, placement) {
|
|
|
19
19
|
path,
|
|
20
20
|
placement
|
|
21
21
|
});
|
|
22
|
-
|
|
22
|
+
const deepLink = `${DEEP_LINK_SCHEME}${path}`;
|
|
23
|
+
triggerDeepLinkWithFallback(deepLink, { onFallback: () => {
|
|
23
24
|
if (client) trackEvent(client, "app_not_installed", {
|
|
24
25
|
path,
|
|
25
26
|
placement
|
package/dist/postPurchase.d.ts
CHANGED
|
@@ -16,7 +16,9 @@ type PostPurchaseProps = {
|
|
|
16
16
|
*/
|
|
17
17
|
orderId?: string;
|
|
18
18
|
/**
|
|
19
|
-
*
|
|
19
|
+
* Opaque per-order token. Feeds purchase tracking, and travels to the
|
|
20
|
+
* sharing page so the install CTA still carries a credential when the
|
|
21
|
+
* anonymous id is unavailable.
|
|
20
22
|
*/
|
|
21
23
|
token?: string;
|
|
22
24
|
/**
|
|
@@ -68,17 +70,12 @@ type PostPurchaseProps = {
|
|
|
68
70
|
*/
|
|
69
71
|
imageUrl?: string;
|
|
70
72
|
/**
|
|
71
|
-
*
|
|
72
|
-
*
|
|
73
|
-
*
|
|
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.
|
|
73
|
+
* Order line items, forwarded to the sharing page as product cards on CTA
|
|
74
|
+
* click, and used to prefer a campaign whose `productScope` matches one of
|
|
75
|
+
* the purchased items when picking the reward to advertise.
|
|
79
76
|
*
|
|
80
|
-
*
|
|
81
|
-
*
|
|
77
|
+
* Accepts a {@link SharingPageProduct} array (JS property) or a
|
|
78
|
+
* JSON-stringified array (HTML attribute, used by server-rendered plugins).
|
|
82
79
|
*/
|
|
83
80
|
products?: SharingPageProduct[] | string;
|
|
84
81
|
/**
|
package/dist/postPurchase.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { c as
|
|
2
|
-
import { t as useGlobalComponents } from "./useGlobalComponents-
|
|
3
|
-
import { t as useLightDomStyles } from "./useLightDomStyles-
|
|
4
|
-
import { i as
|
|
1
|
+
import { c as openSharingPage, i as useLang, o as useClientReady, s as registerWebComponent, t as usePlacement } from "./usePlacement-DtwWaLHO.js";
|
|
2
|
+
import { t as useGlobalComponents } from "./useGlobalComponents-DFv33ujB.js";
|
|
3
|
+
import { t as useLightDomStyles } from "./useLightDomStyles-B_IbOqJZ.js";
|
|
4
|
+
import { i as w, n as K, t as C } from "./rewards-CZkWSndn.js";
|
|
5
5
|
import { componentDefaults } from "./i18n/defaults.js";
|
|
6
|
-
import { i as LogoFrakWithName, n as cssSource$2, t as GiftIcon } from "./GiftIcon-
|
|
7
|
-
import { trackEvent } from "@frak-labs/core-sdk";
|
|
6
|
+
import { i as LogoFrakWithName, n as cssSource$2, t as GiftIcon } from "./GiftIcon-DI0rUKHp.js";
|
|
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 =
|
|
122
|
+
const selected = K(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 [
|
|
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
|
-
|
|
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
|
|
224
|
+
return C(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 ?
|
|
225
|
-
cta: rewardText ?
|
|
233
|
+
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,
|
|
234
|
+
cta: rewardText ? w(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", {
|
|
@@ -262,18 +270,21 @@ function PostPurchase({ customerId, orderId, token, sharingUrl, merchantId, plac
|
|
|
262
270
|
});
|
|
263
271
|
openSharingPage(void 0, placementId, {
|
|
264
272
|
link: resolvedSharingUrl,
|
|
265
|
-
products: parsedProducts
|
|
273
|
+
products: parsedProducts,
|
|
274
|
+
checkoutToken: token
|
|
266
275
|
});
|
|
267
276
|
}, [
|
|
268
277
|
resolvedVariant,
|
|
269
278
|
placementId,
|
|
270
279
|
resolvedSharingUrl,
|
|
271
|
-
parsedProducts
|
|
280
|
+
parsedProducts,
|
|
281
|
+
token
|
|
272
282
|
]);
|
|
273
283
|
if (!resolvedVariant) return null;
|
|
274
284
|
if (!isPreview && (!shouldRender || isHidden || !context)) return null;
|
|
285
|
+
const cardClass = [card, classname].filter(Boolean).join(" ");
|
|
275
286
|
return /* @__PURE__ */ jsx("div", {
|
|
276
|
-
className:
|
|
287
|
+
className: cardClass,
|
|
277
288
|
children: /* @__PURE__ */ jsxs("div", {
|
|
278
289
|
class: cardLayout,
|
|
279
290
|
children: [/* @__PURE__ */ jsxs("div", {
|