@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.
- package/README.md +24 -2
- package/cdn/Banner.Zaqy93tl.js +183 -0
- package/cdn/ButtonShare.BnzCAsRy.js +1 -0
- package/cdn/ButtonWallet.DlzZbjCb.js +40 -0
- package/cdn/{GiftIcon.DcyE1R1V.js → GiftIcon.CPyeWQNR.js} +1 -1
- package/cdn/OpenInAppButton.d-omgD0k.js +1 -0
- package/cdn/PostPurchase._3t6CtvV.js +89 -0
- package/cdn/components.js +1 -1
- package/cdn/defaults.CmUvOlLQ.js +58 -0
- package/cdn/loader.js +124 -1
- package/cdn/replay-V6FXES7X.CgBxdfNp.js +1 -0
- package/cdn/rewards.0JylBHNY.js +1 -0
- package/cdn/useGlobalComponents.C7wnXWOg.js +1 -0
- package/cdn/useLightDomStyles.B7MVlVVJ.js +1 -0
- package/cdn/useReward.CaBorN5T.js +1 -0
- package/dist/{GiftIcon-BhL0bhVu.js → GiftIcon-BmGGodb2.js} +8 -8
- package/dist/banner.d.ts +12 -5
- package/dist/banner.js +16 -14
- package/dist/buttonShare.d.ts +28 -10
- package/dist/buttonShare.js +26 -20
- package/dist/buttonWallet.d.ts +7 -6
- package/dist/buttonWallet.js +37 -35
- package/dist/i18n/defaults.d.ts +2 -3
- package/dist/i18n/defaults.js +2 -2
- package/dist/openInApp.d.ts +4 -5
- package/dist/openInApp.js +6 -6
- package/dist/postPurchase.d.ts +11 -15
- package/dist/postPurchase.js +44 -19
- package/dist/rewards-DoVY1pWr.js +290 -0
- package/dist/{useGlobalComponents-Da9LDlRy.js → useGlobalComponents-BB6djMbu.js} +1 -1
- package/dist/{useLightDomStyles-DRkTVy4s.js → useLightDomStyles-0A0CeRlU.js} +1 -1
- package/dist/{usePlacement-NZOjZ6IR.js → usePlacement-BzMOjNe0.js} +14 -148
- package/dist/{useReward-B-yZ7nhY.js → useReward-k7RF3DhH.js} +10 -5
- package/package.json +32 -20
- 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,21 +105,28 @@ 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
|
+
export 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
|
/**
|
|
104
123
|
* Custom element interface for `<frak-button-share>`.
|
|
105
124
|
* Combines standard {@link HTMLElement} with {@link ButtonShareProps}.
|
|
106
125
|
*/
|
|
107
|
-
interface ButtonShareElement extends HTMLElement, ButtonShareProps {}
|
|
126
|
+
export interface ButtonShareElement extends HTMLElement, ButtonShareProps {}
|
|
108
127
|
declare global {
|
|
109
128
|
interface HTMLElementTagNameMap {
|
|
110
129
|
"frak-button-share": ButtonShareElement;
|
|
111
130
|
}
|
|
112
131
|
}
|
|
113
|
-
//#endregion
|
|
114
|
-
export { ButtonShare, ButtonShareElement };
|
|
132
|
+
//#endregion
|
package/dist/buttonShare.js
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { t as useGlobalComponents } from "./useGlobalComponents-
|
|
4
|
-
import { t as useLightDomStyles } from "./useLightDomStyles-
|
|
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-BzMOjNe0.js";
|
|
2
|
+
import { i as w } from "./rewards-DoVY1pWr.js";
|
|
3
|
+
import { t as useGlobalComponents } from "./useGlobalComponents-BB6djMbu.js";
|
|
4
|
+
import { t as useLightDomStyles } from "./useLightDomStyles-0A0CeRlU.js";
|
|
5
|
+
import { t as useReward } from "./useReward-k7RF3DhH.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,27 +49,36 @@ 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);
|
|
60
67
|
const globalComponents = useGlobalComponents();
|
|
61
68
|
const componentConfig = placement?.components?.buttonShare ?? globalComponents?.buttonShare;
|
|
62
69
|
useLightDomStyles("frak-button-share", placementId, componentConfig?.css);
|
|
63
|
-
const resolvedTargetInteraction =
|
|
70
|
+
const resolvedTargetInteraction = placement?.targetInteraction !== void 0 ? placement.targetInteraction : targetInteraction;
|
|
64
71
|
const resolvedText = componentConfig?.text ?? text ?? componentDefaults[lang].buttonShare.text;
|
|
65
72
|
const resolvedNoRewardText = componentConfig?.noRewardText ?? noRewardText;
|
|
66
|
-
const wantsReward =
|
|
67
|
-
const resolvedClickAction =
|
|
73
|
+
const wantsReward = resolvedText.includes("{REWARD}");
|
|
74
|
+
const resolvedClickAction = componentConfig?.clickAction ?? rawClickAction ?? "sharing-page";
|
|
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,9 @@ 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. The
|
|
27
|
+
* `frak-button-wallet` tag name is public API (merchant markup, Magento
|
|
28
|
+
* template), so it stays even though it no longer names the surface.
|
|
27
29
|
*
|
|
28
30
|
* @param args
|
|
29
31
|
* @returns The wallet button with `<button>` tag
|
|
@@ -60,21 +62,20 @@ type ButtonWalletProps = {
|
|
|
60
62
|
* <frak-button-wallet placement="hero-wallet"></frak-button-wallet>
|
|
61
63
|
* ```
|
|
62
64
|
*
|
|
63
|
-
* @see {@link @frak-labs/core-sdk!actions.
|
|
65
|
+
* @see {@link @frak-labs/core-sdk!actions.displaySharingPage | `displaySharingPage()`} for more info about the sharing page
|
|
64
66
|
* @see {@link @frak-labs/core-sdk!actions.getMerchantInformation | `getMerchantInformation()`} for more info about the estimated reward fetching
|
|
65
67
|
*/
|
|
66
|
-
declare function ButtonWallet({ placement: placementId, classname, useReward: rawUseReward, targetInteraction }: ButtonWalletProps): import("preact").JSX.Element | null;
|
|
68
|
+
export declare function ButtonWallet({ placement: placementId, classname, useReward: rawUseReward, targetInteraction }: ButtonWalletProps): import("preact").JSX.Element | null;
|
|
67
69
|
//#endregion
|
|
68
70
|
//#region src/components/ButtonWallet/index.d.ts
|
|
69
71
|
/**
|
|
70
72
|
* Custom element interface for `<frak-button-wallet>`.
|
|
71
73
|
* Combines standard {@link HTMLElement} with {@link ButtonWalletProps}.
|
|
72
74
|
*/
|
|
73
|
-
interface ButtonWalletElement extends HTMLElement, ButtonWalletProps {}
|
|
75
|
+
export interface ButtonWalletElement extends HTMLElement, ButtonWalletProps {}
|
|
74
76
|
declare global {
|
|
75
77
|
interface HTMLElementTagNameMap {
|
|
76
78
|
"frak-button-wallet": ButtonWalletElement;
|
|
77
79
|
}
|
|
78
80
|
}
|
|
79
|
-
//#endregion
|
|
80
|
-
export { ButtonWallet, ButtonWalletElement };
|
|
81
|
+
//#endregion
|
package/dist/buttonWallet.js
CHANGED
|
@@ -1,11 +1,19 @@
|
|
|
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-BzMOjNe0.js";
|
|
2
|
+
import { t as useReward } from "./useReward-k7RF3DhH.js";
|
|
4
3
|
import { componentDefaults } from "./i18n/defaults.js";
|
|
5
|
-
import {
|
|
4
|
+
import { trackEvent } from "@frak-labs/core-sdk";
|
|
5
|
+
import { useCallback } from "preact/hooks";
|
|
6
6
|
import { Fragment, jsx, jsxs } from "preact/jsx-runtime";
|
|
7
|
-
//#region src/
|
|
8
|
-
|
|
7
|
+
//#region src/utils/browser/safeVibrate.ts
|
|
8
|
+
/**
|
|
9
|
+
* Attempt to vibrate the device
|
|
10
|
+
*/
|
|
11
|
+
function safeVibrate() {
|
|
12
|
+
if ("vibrate" in navigator) navigator.vibrate(10);
|
|
13
|
+
}
|
|
14
|
+
//#endregion
|
|
15
|
+
//#region src/components/ButtonWallet/assets/WalletGiftIcon.tsx
|
|
16
|
+
function WalletGiftIcon(props) {
|
|
9
17
|
return /* @__PURE__ */ jsxs("svg", {
|
|
10
18
|
fill: "none",
|
|
11
19
|
height: "1em",
|
|
@@ -22,21 +30,6 @@ function GiftIcon(props) {
|
|
|
22
30
|
});
|
|
23
31
|
}
|
|
24
32
|
//#endregion
|
|
25
|
-
//#region src/utils/browser/safeVibrate.ts
|
|
26
|
-
/**
|
|
27
|
-
* Attempt to vibrate the device
|
|
28
|
-
*/
|
|
29
|
-
function safeVibrate() {
|
|
30
|
-
if ("vibrate" in navigator) navigator.vibrate(10);
|
|
31
|
-
else console.log("Vibration not supported");
|
|
32
|
-
}
|
|
33
|
-
//#endregion
|
|
34
|
-
//#region src/components/ButtonWallet/utils.ts
|
|
35
|
-
function openWalletModal(targetInteraction, placement) {
|
|
36
|
-
safeVibrate();
|
|
37
|
-
openEmbeddedWallet(targetInteraction, placement);
|
|
38
|
-
}
|
|
39
|
-
//#endregion
|
|
40
33
|
//#region src/components/ButtonWallet/ButtonWallet.tsx
|
|
41
34
|
const componentCss = `
|
|
42
35
|
.button {
|
|
@@ -79,7 +72,9 @@ const componentCss = `
|
|
|
79
72
|
}
|
|
80
73
|
`;
|
|
81
74
|
/**
|
|
82
|
-
*
|
|
75
|
+
* Floating circular button that opens the Frak sharing page. The
|
|
76
|
+
* `frak-button-wallet` tag name is public API (merchant markup, Magento
|
|
77
|
+
* template), so it stays even though it no longer names the surface.
|
|
83
78
|
*
|
|
84
79
|
* @param args
|
|
85
80
|
* @returns The wallet button with `<button>` tag
|
|
@@ -116,22 +111,31 @@ const componentCss = `
|
|
|
116
111
|
* <frak-button-wallet placement="hero-wallet"></frak-button-wallet>
|
|
117
112
|
* ```
|
|
118
113
|
*
|
|
119
|
-
* @see {@link @frak-labs/core-sdk!actions.
|
|
114
|
+
* @see {@link @frak-labs/core-sdk!actions.displaySharingPage | `displaySharingPage()`} for more info about the sharing page
|
|
120
115
|
* @see {@link @frak-labs/core-sdk!actions.getMerchantInformation | `getMerchantInformation()`} for more info about the estimated reward fetching
|
|
121
116
|
*/
|
|
122
117
|
function ButtonWallet({ placement: placementId, classname = "", useReward: rawUseReward, targetInteraction }) {
|
|
123
118
|
const lang = useLang();
|
|
124
119
|
const placement = usePlacement(placementId);
|
|
125
|
-
const resolvedTargetInteraction =
|
|
126
|
-
const shouldUseReward =
|
|
120
|
+
const resolvedTargetInteraction = placement?.targetInteraction !== void 0 ? placement.targetInteraction : targetInteraction;
|
|
121
|
+
const shouldUseReward = rawUseReward === true;
|
|
127
122
|
const { shouldRender, isHidden, isClientReady } = useClientReady();
|
|
128
123
|
const { reward } = useReward(shouldUseReward && isClientReady, resolvedTargetInteraction);
|
|
129
|
-
const
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
124
|
+
const position = placement?.components?.buttonWallet?.position ?? window.FrakSetup?.modalWalletConfig?.metadata?.position ?? "right";
|
|
125
|
+
const onClick = useCallback(() => {
|
|
126
|
+
trackEvent(window.FrakSetup.client, "share_button_clicked", {
|
|
127
|
+
placement: placementId,
|
|
128
|
+
target_interaction: resolvedTargetInteraction,
|
|
129
|
+
has_reward: Boolean(reward),
|
|
130
|
+
click_action: "sharing-page"
|
|
131
|
+
});
|
|
132
|
+
safeVibrate();
|
|
133
|
+
openSharingPage(resolvedTargetInteraction, placementId);
|
|
134
|
+
}, [
|
|
135
|
+
placementId,
|
|
136
|
+
resolvedTargetInteraction,
|
|
137
|
+
reward
|
|
138
|
+
]);
|
|
135
139
|
if (!shouldRender || isHidden) return null;
|
|
136
140
|
const buttonClass = [
|
|
137
141
|
"button",
|
|
@@ -145,10 +149,8 @@ function ButtonWallet({ placement: placementId, classname = "", useReward: rawUs
|
|
|
145
149
|
part: "button",
|
|
146
150
|
disabled: !isClientReady,
|
|
147
151
|
class: buttonClass,
|
|
148
|
-
onClick
|
|
149
|
-
|
|
150
|
-
},
|
|
151
|
-
children: [/* @__PURE__ */ jsx(GiftIcon, {}), reward && /* @__PURE__ */ jsx("span", {
|
|
152
|
+
onClick,
|
|
153
|
+
children: [/* @__PURE__ */ jsx(WalletGiftIcon, {}), reward && /* @__PURE__ */ jsx("span", {
|
|
152
154
|
class: "reward",
|
|
153
155
|
children: reward
|
|
154
156
|
})]
|
package/dist/i18n/defaults.d.ts
CHANGED
|
@@ -50,6 +50,5 @@ type ComponentCopy = {
|
|
|
50
50
|
* the `Language` union in `@frak-labs/core-sdk` — no new dependency, no
|
|
51
51
|
* merchant action, no SDK API change.
|
|
52
52
|
*/
|
|
53
|
-
declare const componentDefaults: Record<Language, ComponentCopy>;
|
|
54
|
-
//#endregion
|
|
55
|
-
export { componentDefaults };
|
|
53
|
+
export declare const componentDefaults: Record<Language, ComponentCopy>;
|
|
54
|
+
//#endregion
|
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.d.ts
CHANGED
|
@@ -40,23 +40,22 @@ type OpenInAppButtonProps = {
|
|
|
40
40
|
* ```
|
|
41
41
|
*
|
|
42
42
|
* @example
|
|
43
|
-
*
|
|
43
|
+
* Using a custom class:
|
|
44
44
|
* ```html
|
|
45
45
|
* <frak-open-in-app classname="button button-primary"></frak-open-in-app>
|
|
46
46
|
* ```
|
|
47
47
|
*/
|
|
48
|
-
declare function OpenInAppButton({ placement: placementId, text, classname }: OpenInAppButtonProps): import("preact").JSX.Element | null;
|
|
48
|
+
export declare function OpenInAppButton({ placement: placementId, text, classname }: OpenInAppButtonProps): import("preact").JSX.Element | null;
|
|
49
49
|
//#endregion
|
|
50
50
|
//#region src/components/OpenInAppButton/index.d.ts
|
|
51
51
|
/**
|
|
52
52
|
* Custom element interface for `<frak-open-in-app>`.
|
|
53
53
|
* Combines standard {@link HTMLElement} with {@link OpenInAppButtonProps}.
|
|
54
54
|
*/
|
|
55
|
-
interface OpenInAppButtonElement extends HTMLElement, OpenInAppButtonProps {}
|
|
55
|
+
export interface OpenInAppButtonElement extends HTMLElement, OpenInAppButtonProps {}
|
|
56
56
|
declare global {
|
|
57
57
|
interface HTMLElementTagNameMap {
|
|
58
58
|
"frak-open-in-app": OpenInAppButtonElement;
|
|
59
59
|
}
|
|
60
60
|
}
|
|
61
|
-
//#endregion
|
|
62
|
-
export { OpenInAppButton, OpenInAppButtonElement };
|
|
61
|
+
//#endregion
|
package/dist/openInApp.js
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
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-BzMOjNe0.js";
|
|
2
|
+
import { t as useLightDomStyles } from "./useLightDomStyles-0A0CeRlU.js";
|
|
3
3
|
import { componentDefaults } from "./i18n/defaults.js";
|
|
4
4
|
import { DEEP_LINK_SCHEME, isMobile, trackEvent, triggerDeepLinkWithFallback } from "@frak-labs/core-sdk";
|
|
5
|
-
import { useMemo } from "preact/hooks";
|
|
6
5
|
import { jsx } from "preact/jsx-runtime";
|
|
7
6
|
//#region src/actions/openInApp.ts
|
|
8
7
|
const DEFAULT_PATH = "wallet";
|
|
@@ -19,7 +18,8 @@ function openFrakWalletApp(path = DEFAULT_PATH, placement) {
|
|
|
19
18
|
path,
|
|
20
19
|
placement
|
|
21
20
|
});
|
|
22
|
-
|
|
21
|
+
const deepLink = `${DEEP_LINK_SCHEME}${path}`;
|
|
22
|
+
triggerDeepLinkWithFallback(deepLink, { onFallback: () => {
|
|
23
23
|
if (client) trackEvent(client, "app_not_installed", {
|
|
24
24
|
path,
|
|
25
25
|
placement
|
|
@@ -29,7 +29,7 @@ function openFrakWalletApp(path = DEFAULT_PATH, placement) {
|
|
|
29
29
|
//#endregion
|
|
30
30
|
//#region src/hooks/useIsMobile.ts
|
|
31
31
|
function useIsMobile() {
|
|
32
|
-
return { isMobile:
|
|
32
|
+
return { isMobile: isMobile() };
|
|
33
33
|
}
|
|
34
34
|
//#endregion
|
|
35
35
|
//#region src/components/OpenInAppButton/OpenInAppButton.tsx
|
|
@@ -54,7 +54,7 @@ function useIsMobile() {
|
|
|
54
54
|
* ```
|
|
55
55
|
*
|
|
56
56
|
* @example
|
|
57
|
-
*
|
|
57
|
+
* Using a custom class:
|
|
58
58
|
* ```html
|
|
59
59
|
* <frak-open-in-app classname="button button-primary"></frak-open-in-app>
|
|
60
60
|
* ```
|
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
|
/**
|
|
@@ -124,18 +121,17 @@ type PostPurchaseProps = {
|
|
|
124
121
|
* ></frak-post-purchase>
|
|
125
122
|
* ```
|
|
126
123
|
*/
|
|
127
|
-
declare function PostPurchase({ customerId, orderId, token, sharingUrl, merchantId, placement: placementId, classname, variant: forcedVariant, badgeText: propBadgeText, referrerText: propReferrerText, refereeText: propRefereeText, ctaText: propCtaText, preview, previewVariant, products, imageUrl: propImageUrl }: PostPurchaseProps): import("preact").JSX.Element | null;
|
|
124
|
+
export declare function PostPurchase({ customerId, orderId, token, sharingUrl, merchantId, placement: placementId, classname, variant: forcedVariant, badgeText: propBadgeText, referrerText: propReferrerText, refereeText: propRefereeText, ctaText: propCtaText, preview, previewVariant, products, imageUrl: propImageUrl }: PostPurchaseProps): import("preact").JSX.Element | null;
|
|
128
125
|
//#endregion
|
|
129
126
|
//#region src/components/PostPurchase/index.d.ts
|
|
130
127
|
/**
|
|
131
128
|
* Custom element interface for `<frak-post-purchase>`.
|
|
132
129
|
* Combines standard {@link HTMLElement} with {@link PostPurchaseProps}.
|
|
133
130
|
*/
|
|
134
|
-
interface PostPurchaseElement extends HTMLElement, PostPurchaseProps {}
|
|
131
|
+
export interface PostPurchaseElement extends HTMLElement, PostPurchaseProps {}
|
|
135
132
|
declare global {
|
|
136
133
|
interface HTMLElementTagNameMap {
|
|
137
134
|
"frak-post-purchase": PostPurchaseElement;
|
|
138
135
|
}
|
|
139
136
|
}
|
|
140
|
-
//#endregion
|
|
141
|
-
export { PostPurchase, PostPurchaseElement };
|
|
137
|
+
//#endregion
|
package/dist/postPurchase.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { c as
|
|
2
|
-
import { t as
|
|
3
|
-
import { t as
|
|
4
|
-
import {
|
|
1
|
+
import { c as openSharingPage, i as useLang, o as useClientReady, s as registerWebComponent, t as usePlacement } from "./usePlacement-BzMOjNe0.js";
|
|
2
|
+
import { i as w, n as K, t as C } from "./rewards-DoVY1pWr.js";
|
|
3
|
+
import { t as useGlobalComponents } from "./useGlobalComponents-BB6djMbu.js";
|
|
4
|
+
import { t as useLightDomStyles } from "./useLightDomStyles-0A0CeRlU.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-BmGGodb2.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";
|
|
@@ -114,15 +114,30 @@ 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
|
-
function resolvePostPurchaseContext(referralStatus, merchantInfo, currency) {
|
|
134
|
+
function resolvePostPurchaseContext(referralStatus, merchantInfo, currency, products) {
|
|
121
135
|
const audience = referralStatus?.isReferred ? "referee" : "referrer";
|
|
122
|
-
const selected =
|
|
136
|
+
const selected = K(merchantInfo.rewards, {
|
|
123
137
|
targetInteraction: "purchase",
|
|
124
138
|
currency,
|
|
125
|
-
audience
|
|
139
|
+
audience,
|
|
140
|
+
products
|
|
126
141
|
});
|
|
127
142
|
if (!selected) return null;
|
|
128
143
|
const { campaign } = selected;
|
|
@@ -166,8 +181,9 @@ function PostPurchase({ customerId, orderId, token, sharingUrl, merchantId, plac
|
|
|
166
181
|
const { shouldRender, isHidden, isClientReady } = useClientReady();
|
|
167
182
|
const placement = usePlacement(placementId);
|
|
168
183
|
const lang = useLang();
|
|
184
|
+
const parsedProducts = useMemo(() => sanitizeSharingProducts(products), [products]);
|
|
169
185
|
useLightDomStyles("frak-post-purchase", placementId, placement?.components?.postPurchase?.css, cssSource, cssSource$2);
|
|
170
|
-
const [
|
|
186
|
+
const [fetched, setFetched] = useState(null);
|
|
171
187
|
const [hasFetched, setHasFetched] = useState(false);
|
|
172
188
|
useEffect(() => {
|
|
173
189
|
if (isPreview) return;
|
|
@@ -193,7 +209,10 @@ function PostPurchase({ customerId, orderId, token, sharingUrl, merchantId, plac
|
|
|
193
209
|
if (!client) return;
|
|
194
210
|
Promise.all([getUserReferralStatus(client), getMerchantInformation(client)]).then(([referralStatus, merchantInfo]) => {
|
|
195
211
|
setHasFetched(true);
|
|
196
|
-
|
|
212
|
+
setFetched({
|
|
213
|
+
referralStatus,
|
|
214
|
+
merchantInfo
|
|
215
|
+
});
|
|
197
216
|
}).catch((e) => {
|
|
198
217
|
if (e instanceof FrakRpcError && e.code === RpcErrorCodes.configError) {
|
|
199
218
|
setHasFetched(true);
|
|
@@ -206,13 +225,17 @@ function PostPurchase({ customerId, orderId, token, sharingUrl, merchantId, plac
|
|
|
206
225
|
isClientReady,
|
|
207
226
|
hasFetched
|
|
208
227
|
]);
|
|
228
|
+
const context = useMemo(() => {
|
|
229
|
+
if (!fetched) return null;
|
|
230
|
+
return resolvePostPurchaseContext(fetched.referralStatus, fetched.merchantInfo, window.FrakSetup?.client?.config?.metadata?.currency, parsedProducts);
|
|
231
|
+
}, [fetched, parsedProducts]);
|
|
209
232
|
const trackedImpressionVariantRef = useRef(null);
|
|
210
233
|
const resolvedVariant = forcedVariant ?? context?.variant ?? (isPreview ? previewVariant ?? "referrer" : void 0);
|
|
211
|
-
const resolvedSharingUrl = sharingUrl ?? context?.merchantDomain;
|
|
234
|
+
const resolvedSharingUrl = resolveShareBaseUrl(sharingUrl ?? context?.merchantDomain);
|
|
212
235
|
const rewardText = useMemo(() => {
|
|
213
236
|
if (!context?.reward) return void 0;
|
|
214
237
|
const currency = window.FrakSetup?.client?.config?.metadata?.currency;
|
|
215
|
-
return
|
|
238
|
+
return C(context.reward, currency);
|
|
216
239
|
}, [context?.reward]);
|
|
217
240
|
const globalComponents = useGlobalComponents();
|
|
218
241
|
const postPurchaseConfig = placement?.components?.postPurchase ?? globalComponents?.postPurchase;
|
|
@@ -221,8 +244,8 @@ function PostPurchase({ customerId, orderId, token, sharingUrl, merchantId, plac
|
|
|
221
244
|
const texts = useMemo(() => {
|
|
222
245
|
const defaults = componentDefaults[lang].postPurchase;
|
|
223
246
|
return {
|
|
224
|
-
message: resolvedVariant === "referee" ? rewardText ?
|
|
225
|
-
cta: rewardText ?
|
|
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
|
|
226
249
|
};
|
|
227
250
|
}, [
|
|
228
251
|
lang,
|
|
@@ -253,7 +276,6 @@ function PostPurchase({ customerId, orderId, token, sharingUrl, merchantId, plac
|
|
|
253
276
|
placementId,
|
|
254
277
|
context?.reward
|
|
255
278
|
]);
|
|
256
|
-
const parsedProducts = useMemo(() => sanitizeProductList(products), [products]);
|
|
257
279
|
const handleClick = useCallback(() => {
|
|
258
280
|
if (!resolvedVariant) return;
|
|
259
281
|
trackEvent(window.FrakSetup?.client, "post_purchase_clicked", {
|
|
@@ -262,18 +284,21 @@ function PostPurchase({ customerId, orderId, token, sharingUrl, merchantId, plac
|
|
|
262
284
|
});
|
|
263
285
|
openSharingPage(void 0, placementId, {
|
|
264
286
|
link: resolvedSharingUrl,
|
|
265
|
-
products: parsedProducts
|
|
287
|
+
products: parsedProducts,
|
|
288
|
+
checkoutToken: token
|
|
266
289
|
});
|
|
267
290
|
}, [
|
|
268
291
|
resolvedVariant,
|
|
269
292
|
placementId,
|
|
270
293
|
resolvedSharingUrl,
|
|
271
|
-
parsedProducts
|
|
294
|
+
parsedProducts,
|
|
295
|
+
token
|
|
272
296
|
]);
|
|
273
297
|
if (!resolvedVariant) return null;
|
|
274
298
|
if (!isPreview && (!shouldRender || isHidden || !context)) return null;
|
|
299
|
+
const cardClass = [card, classname].filter(Boolean).join(" ");
|
|
275
300
|
return /* @__PURE__ */ jsx("div", {
|
|
276
|
-
className:
|
|
301
|
+
className: cardClass,
|
|
277
302
|
children: /* @__PURE__ */ jsxs("div", {
|
|
278
303
|
class: cardLayout,
|
|
279
304
|
children: [/* @__PURE__ */ jsxs("div", {
|