@frak-labs/components 1.0.3-beta.9d4f564a → 1.0.3-beta.a0c06742
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.B1y3jwHv.js +178 -0
- package/cdn/ButtonShare.DNELNwqD.js +1 -0
- package/cdn/ButtonWallet.BUUPX0gO.js +40 -0
- package/cdn/GiftIcon.eRNTGQ_r.js +1 -0
- package/cdn/OpenInAppButton.Dgb-qhM8.js +1 -0
- package/cdn/PostPurchase.C3IH-LUy.js +89 -0
- package/cdn/components.js +1 -0
- package/cdn/formatReward.B1ZyoceC.js +1 -0
- package/cdn/loader.css +0 -0
- package/cdn/loader.js +154 -0
- package/cdn/replay-V6FXES7X.CNozpSRg.js +1 -0
- package/cdn/sharingPage.Dt8QZhlR.js +1 -0
- package/cdn/useGlobalComponents.TG9kIYSc.js +1 -0
- package/cdn/useLightDomStyles.tjNBKcOr.js +1 -0
- package/cdn/usePlacement.BgMXY5CX.js +58 -0
- package/cdn/useReward.B530suzR.js +1 -0
- package/dist/GiftIcon-BIp9FTJs.js +338 -0
- package/dist/banner.d.ts +124 -0
- package/dist/banner.js +494 -0
- package/dist/buttonShare.d.ts +118 -0
- package/dist/buttonShare.js +122 -0
- package/dist/buttonWallet.d.ts +87 -0
- package/dist/buttonWallet.js +148 -0
- package/dist/formatReward-Cf2KpA3x.js +33 -0
- package/dist/openInApp.d.ts +66 -0
- package/dist/openInApp.js +93 -0
- package/dist/postPurchase.d.ts +160 -0
- package/dist/postPurchase.js +411 -0
- package/dist/sharingPage-D6fQEXV9.js +15 -0
- package/dist/useGlobalComponents-mSs9unyN.js +21 -0
- package/dist/useLightDomStyles-DVe5UDg6.js +48 -0
- package/dist/usePlacement-DzEuVg_u.js +253 -0
- package/dist/useReward-ClVShg45.js +65 -0
- package/package.json +3 -3
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
import { SharingPageProduct } from "@frak-labs/core-sdk";
|
|
2
|
+
import * as _$preact from "preact";
|
|
3
|
+
|
|
4
|
+
//#region src/components/PostPurchase/types.d.ts
|
|
5
|
+
/**
|
|
6
|
+
* Props for the {@link PostPurchase} component.
|
|
7
|
+
* @inline
|
|
8
|
+
*/
|
|
9
|
+
type PostPurchaseProps = {
|
|
10
|
+
/**
|
|
11
|
+
* Merchant customer ID for purchase tracking fallback.
|
|
12
|
+
* All three tracking props (`customerId`, `orderId`, `token`) must be
|
|
13
|
+
* present for tracking to fire.
|
|
14
|
+
*/
|
|
15
|
+
customerId?: string;
|
|
16
|
+
/**
|
|
17
|
+
* Merchant order ID for purchase tracking fallback.
|
|
18
|
+
*/
|
|
19
|
+
orderId?: string;
|
|
20
|
+
/**
|
|
21
|
+
* Checkout token for purchase tracking fallback.
|
|
22
|
+
*/
|
|
23
|
+
token?: string;
|
|
24
|
+
/**
|
|
25
|
+
* Base URL to share. Falls back to the merchant domain returned by
|
|
26
|
+
* the backend when omitted.
|
|
27
|
+
*/
|
|
28
|
+
sharingUrl?: string;
|
|
29
|
+
/**
|
|
30
|
+
* Override the merchant ID resolved from the SDK config.
|
|
31
|
+
*/
|
|
32
|
+
merchantId?: string;
|
|
33
|
+
/**
|
|
34
|
+
* Placement ID for backend-driven CSS customization.
|
|
35
|
+
*/
|
|
36
|
+
placement?: string;
|
|
37
|
+
/**
|
|
38
|
+
* CSS class names passed through to the root element (Light DOM).
|
|
39
|
+
*/
|
|
40
|
+
classname?: string;
|
|
41
|
+
/**
|
|
42
|
+
* Force a display variant instead of relying on the backend evaluation.
|
|
43
|
+
*/
|
|
44
|
+
variant?: "referrer" | "referee";
|
|
45
|
+
/**
|
|
46
|
+
* Label for the pill badge displayed above the message.
|
|
47
|
+
* When omitted (and no placement config provides one), the badge is hidden.
|
|
48
|
+
*/
|
|
49
|
+
badgeText?: string;
|
|
50
|
+
/**
|
|
51
|
+
* Override the message shown to referrers.
|
|
52
|
+
* Use `{REWARD}` as placeholder for the reward amount.
|
|
53
|
+
*/
|
|
54
|
+
referrerText?: string;
|
|
55
|
+
/**
|
|
56
|
+
* Override the message shown to referees.
|
|
57
|
+
* Use `{REWARD}` as placeholder for the reward amount.
|
|
58
|
+
*/
|
|
59
|
+
refereeText?: string;
|
|
60
|
+
/**
|
|
61
|
+
* Override the CTA button text.
|
|
62
|
+
* Use `{REWARD}` as placeholder for the reward amount.
|
|
63
|
+
*/
|
|
64
|
+
ctaText?: string;
|
|
65
|
+
/**
|
|
66
|
+
* Override the image displayed on the left of the post-purchase card.
|
|
67
|
+
* Accepts an image URL. Falls back to the built-in gift icon when omitted.
|
|
68
|
+
* The image is constrained to the icon slot via `object-fit: contain`,
|
|
69
|
+
* so any aspect ratio renders correctly.
|
|
70
|
+
*/
|
|
71
|
+
imageUrl?: string;
|
|
72
|
+
/**
|
|
73
|
+
* Optional product cards forwarded to the sharing page when the user
|
|
74
|
+
* clicks the CTA. Accepts either a real {@link SharingPageProduct}
|
|
75
|
+
* array (when set imperatively via the JS property,
|
|
76
|
+
* `el.products = [...]`) or a JSON-stringified array (when set as an
|
|
77
|
+
* HTML attribute, `<frak-post-purchase products='[...]'>`). The HTML
|
|
78
|
+
* attribute path is required for server-rendered surfaces — e.g.
|
|
79
|
+
* WooCommerce / Magento plugins — because `preact-custom-element`
|
|
80
|
+
* delivers attribute values as raw strings.
|
|
81
|
+
*
|
|
82
|
+
* Empty arrays / unparseable strings are treated as "no products" so
|
|
83
|
+
* the sharing page renders without the product card section.
|
|
84
|
+
*/
|
|
85
|
+
products?: SharingPageProduct[] | string;
|
|
86
|
+
/**
|
|
87
|
+
* When set, renders the card in preview mode (e.g. Shopify/WP editor).
|
|
88
|
+
* Bypasses the client-ready / RPC gates that normally hide the card
|
|
89
|
+
* until the backend resolves, and no-ops the click handler so merchants
|
|
90
|
+
* can see the final layout with their configured copy.
|
|
91
|
+
*/
|
|
92
|
+
preview?: string;
|
|
93
|
+
/**
|
|
94
|
+
* Which variant to show when {@link preview} is set.
|
|
95
|
+
* Defaults to `"referrer"`.
|
|
96
|
+
*/
|
|
97
|
+
previewVariant?: "referrer" | "referee";
|
|
98
|
+
};
|
|
99
|
+
//#endregion
|
|
100
|
+
//#region src/components/PostPurchase/PostPurchase.d.ts
|
|
101
|
+
/**
|
|
102
|
+
* Post-purchase card component.
|
|
103
|
+
*
|
|
104
|
+
* Renders an inline card on the merchant's thank-you / order-status page
|
|
105
|
+
* that either congratulates a referee or invites a referrer to share.
|
|
106
|
+
*
|
|
107
|
+
* Fetches referral status and merchant information via two independent
|
|
108
|
+
* RPC calls, then computes the display variant locally.
|
|
109
|
+
*
|
|
110
|
+
* @group components
|
|
111
|
+
*
|
|
112
|
+
* @example
|
|
113
|
+
* Minimal — just show the card:
|
|
114
|
+
* ```html
|
|
115
|
+
* <frak-post-purchase></frak-post-purchase>
|
|
116
|
+
* ```
|
|
117
|
+
*
|
|
118
|
+
* @example
|
|
119
|
+
* With purchase tracking fallback and custom sharing URL:
|
|
120
|
+
* ```html
|
|
121
|
+
* <frak-post-purchase
|
|
122
|
+
* customer-id="cust_123"
|
|
123
|
+
* order-id="ord_456"
|
|
124
|
+
* token="checkout_abc"
|
|
125
|
+
* sharing-url="https://merchant.com/product/shoes"
|
|
126
|
+
* ></frak-post-purchase>
|
|
127
|
+
* ```
|
|
128
|
+
*/
|
|
129
|
+
declare function PostPurchase({
|
|
130
|
+
customerId,
|
|
131
|
+
orderId,
|
|
132
|
+
token,
|
|
133
|
+
sharingUrl,
|
|
134
|
+
merchantId,
|
|
135
|
+
placement: placementId,
|
|
136
|
+
classname,
|
|
137
|
+
variant: forcedVariant,
|
|
138
|
+
badgeText: propBadgeText,
|
|
139
|
+
referrerText: propReferrerText,
|
|
140
|
+
refereeText: propRefereeText,
|
|
141
|
+
ctaText: propCtaText,
|
|
142
|
+
preview,
|
|
143
|
+
previewVariant,
|
|
144
|
+
products,
|
|
145
|
+
imageUrl
|
|
146
|
+
}: PostPurchaseProps): _$preact.JSX.Element | null;
|
|
147
|
+
//#endregion
|
|
148
|
+
//#region src/components/PostPurchase/index.d.ts
|
|
149
|
+
/**
|
|
150
|
+
* Custom element interface for `<frak-post-purchase>`.
|
|
151
|
+
* Combines standard {@link HTMLElement} with {@link PostPurchaseProps}.
|
|
152
|
+
*/
|
|
153
|
+
interface PostPurchaseElement extends HTMLElement, PostPurchaseProps {}
|
|
154
|
+
declare global {
|
|
155
|
+
interface HTMLElementTagNameMap {
|
|
156
|
+
"frak-post-purchase": PostPurchaseElement;
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
//#endregion
|
|
160
|
+
export { PostPurchase, PostPurchaseElement };
|
|
@@ -0,0 +1,411 @@
|
|
|
1
|
+
import { a as registerWebComponent, i as useClientReady, t as usePlacement } from "./usePlacement-DzEuVg_u.js";
|
|
2
|
+
import { t as openSharingPage } from "./sharingPage-D6fQEXV9.js";
|
|
3
|
+
import { t as useGlobalComponents } from "./useGlobalComponents-mSs9unyN.js";
|
|
4
|
+
import { t as useLightDomStyles } from "./useLightDomStyles-DVe5UDg6.js";
|
|
5
|
+
import { n as formatEstimatedReward, t as applyRewardPlaceholder } from "./formatReward-Cf2KpA3x.js";
|
|
6
|
+
import { i as LogoFrakWithName, n as cssSource$2, t as GiftIcon } from "./GiftIcon-BIp9FTJs.js";
|
|
7
|
+
import { trackEvent } from "@frak-labs/core-sdk";
|
|
8
|
+
import { getMerchantInformation, getUserReferralStatus, trackPurchaseStatus } from "@frak-labs/core-sdk/actions";
|
|
9
|
+
import { useCallback, useEffect, useMemo, useRef, useState } from "preact/hooks";
|
|
10
|
+
import { jsx, jsxs } from "preact/jsx-runtime";
|
|
11
|
+
import { FrakRpcError, RpcErrorCodes } from "@frak-labs/frame-connector";
|
|
12
|
+
//#region \0ve-inline:src/components/PostPurchase/PostPurchase.css.ts.vanilla.js
|
|
13
|
+
const cssSource$1 = `.PostPurchase_card__5fv5lh0 {
|
|
14
|
+
padding: 16px;
|
|
15
|
+
border-radius: 12px;
|
|
16
|
+
background-color: var(--surface-background__pbq4akc);
|
|
17
|
+
border: 1px solid var(--border-default__pbq4akv);
|
|
18
|
+
}
|
|
19
|
+
.PostPurchase_cardLayout__5fv5lh1 {
|
|
20
|
+
display: flex;
|
|
21
|
+
flex-direction: row;
|
|
22
|
+
align-items: center;
|
|
23
|
+
gap: 32px;
|
|
24
|
+
}
|
|
25
|
+
.PostPurchase_cardLeft__5fv5lh2 {
|
|
26
|
+
flex-grow: 1;
|
|
27
|
+
min-width: 0;
|
|
28
|
+
display: flex;
|
|
29
|
+
flex-direction: column;
|
|
30
|
+
gap: 8px;
|
|
31
|
+
}
|
|
32
|
+
.PostPurchase_cardRight__5fv5lh3 {
|
|
33
|
+
flex-shrink: 0;
|
|
34
|
+
display: flex;
|
|
35
|
+
flex-direction: column;
|
|
36
|
+
align-items: flex-end;
|
|
37
|
+
gap: 8px;
|
|
38
|
+
text-align: right;
|
|
39
|
+
}
|
|
40
|
+
.PostPurchase_badge__5fv5lh4 {
|
|
41
|
+
align-self: flex-start;
|
|
42
|
+
background-color: #FFF534;
|
|
43
|
+
border-radius: 4px;
|
|
44
|
+
padding: 4px 8px;
|
|
45
|
+
font-size: 12px;
|
|
46
|
+
font-weight: 600;
|
|
47
|
+
line-height: 12px;
|
|
48
|
+
color: var(--text-primary__pbq4ak0);
|
|
49
|
+
}
|
|
50
|
+
.PostPurchase_message__5fv5lh5 {
|
|
51
|
+
margin: 0;
|
|
52
|
+
font-size: 16px;
|
|
53
|
+
line-height: 22px;
|
|
54
|
+
color: var(--text-primary__pbq4ak0);
|
|
55
|
+
font-weight: 600;
|
|
56
|
+
}
|
|
57
|
+
.PostPurchase_cta__5fv5lh6 {
|
|
58
|
+
display: inline-flex;
|
|
59
|
+
align-items: center;
|
|
60
|
+
justify-content: center;
|
|
61
|
+
gap: 4px;
|
|
62
|
+
padding: 12px 16px;
|
|
63
|
+
border-radius: 9999px;
|
|
64
|
+
background-color: var(--text-primary__pbq4ak0);
|
|
65
|
+
color: var(--text-onAction__pbq4ak6);
|
|
66
|
+
font-size: 12px;
|
|
67
|
+
font-weight: bold;
|
|
68
|
+
text-transform: uppercase;
|
|
69
|
+
}
|
|
70
|
+
.PostPurchase_cta__5fv5lh6:disabled {
|
|
71
|
+
opacity: 0.7;
|
|
72
|
+
cursor: default;
|
|
73
|
+
}
|
|
74
|
+
.PostPurchase_icon__5fv5lh7 {
|
|
75
|
+
margin: -2px 0;
|
|
76
|
+
}
|
|
77
|
+
.PostPurchase_giftIcon__5fv5lh8 {
|
|
78
|
+
display: block;
|
|
79
|
+
flex-shrink: 0;
|
|
80
|
+
}
|
|
81
|
+
.PostPurchase_imageWrapper__5fv5lh9 {
|
|
82
|
+
flex-shrink: 0;
|
|
83
|
+
display: flex;
|
|
84
|
+
align-items: center;
|
|
85
|
+
justify-content: center;
|
|
86
|
+
width: 80px;
|
|
87
|
+
height: 80px;
|
|
88
|
+
overflow: hidden;
|
|
89
|
+
}
|
|
90
|
+
.PostPurchase_customImage__5fv5lha {
|
|
91
|
+
max-width: 100%;
|
|
92
|
+
max-height: 100%;
|
|
93
|
+
width: auto;
|
|
94
|
+
height: auto;
|
|
95
|
+
object-fit: contain;
|
|
96
|
+
display: block;
|
|
97
|
+
}
|
|
98
|
+
.PostPurchase_frakLogo__5fv5lhb {
|
|
99
|
+
display: block;
|
|
100
|
+
margin-left: auto;
|
|
101
|
+
}`;
|
|
102
|
+
var card = "PostPurchase_card__5fv5lh0";
|
|
103
|
+
var cardLayout = "PostPurchase_cardLayout__5fv5lh1";
|
|
104
|
+
var cardLeft = "PostPurchase_cardLeft__5fv5lh2";
|
|
105
|
+
var cardRight = "PostPurchase_cardRight__5fv5lh3";
|
|
106
|
+
var cta = "PostPurchase_cta__5fv5lh6 sharedBaseCss_buttonReset__7cswil0";
|
|
107
|
+
var customImage = "PostPurchase_customImage__5fv5lha";
|
|
108
|
+
var frakLogo = "PostPurchase_frakLogo__5fv5lhb";
|
|
109
|
+
var giftIcon = "PostPurchase_giftIcon__5fv5lh8";
|
|
110
|
+
var icon = "PostPurchase_icon__5fv5lh7";
|
|
111
|
+
var imageWrapper = "PostPurchase_imageWrapper__5fv5lh9";
|
|
112
|
+
var message = "PostPurchase_message__5fv5lh5";
|
|
113
|
+
const cssSource = cssSource$1;
|
|
114
|
+
//#endregion
|
|
115
|
+
//#region src/components/PostPurchase/products.ts
|
|
116
|
+
/**
|
|
117
|
+
* Whether `value` is a syntactically valid URL with an `http(s):` scheme.
|
|
118
|
+
*
|
|
119
|
+
* Used to gate `imageUrl` / `link` fields coming from the public `products`
|
|
120
|
+
* prop — the listener-side sharing-page builder calls `new URL(...)` on the
|
|
121
|
+
* incoming product link, and a `javascript:` URL would be a XSS sink in any
|
|
122
|
+
* consumer that binds the value to an `href`.
|
|
123
|
+
*/
|
|
124
|
+
function isHttpUrl(value) {
|
|
125
|
+
try {
|
|
126
|
+
const parsed = new URL(value);
|
|
127
|
+
return parsed.protocol === "http:" || parsed.protocol === "https:";
|
|
128
|
+
} catch {
|
|
129
|
+
return false;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Coerce a raw `products` prop value into a candidate array suitable for
|
|
134
|
+
* per-item normalisation, or null when it cannot be reduced to one.
|
|
135
|
+
*
|
|
136
|
+
* Surfaces that set the prop via the JS property (`el.products = [...]`)
|
|
137
|
+
* deliver a real array; surfaces that bind it as an HTML attribute
|
|
138
|
+
* (WP / Magento server-render) deliver a JSON-stringified array. Anything
|
|
139
|
+
* else (truthy non-array non-string, JSON parse failure, JSON that decodes
|
|
140
|
+
* to a non-array) is treated as "no products" so the share still works
|
|
141
|
+
* without the product card section.
|
|
142
|
+
*/
|
|
143
|
+
function coerceProductCandidates(products) {
|
|
144
|
+
if (!products) return null;
|
|
145
|
+
if (Array.isArray(products)) return products;
|
|
146
|
+
if (typeof products !== "string") return null;
|
|
147
|
+
try {
|
|
148
|
+
const parsed = JSON.parse(products);
|
|
149
|
+
return Array.isArray(parsed) ? parsed : null;
|
|
150
|
+
} catch {
|
|
151
|
+
return null;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* Normalise one untrusted candidate into a {@link SharingPageProduct}, or
|
|
156
|
+
* return null when the candidate has no usable title.
|
|
157
|
+
*
|
|
158
|
+
* The `products` prop is a public API boundary (merchants can set it
|
|
159
|
+
* server-side via WP/Magento or imperatively from arbitrary JS). Each entry
|
|
160
|
+
* is validated structurally so a malformed `link` reaching `new URL(...)`
|
|
161
|
+
* downstream would not crash the sharing-page builder, and so a
|
|
162
|
+
* `javascript:` URL cannot slip through as `imageUrl` / `link`.
|
|
163
|
+
*/
|
|
164
|
+
function normalizeProductCandidate(candidate) {
|
|
165
|
+
if (!candidate || typeof candidate !== "object") return null;
|
|
166
|
+
const item = candidate;
|
|
167
|
+
const title = typeof item.title === "string" ? item.title.trim() : "";
|
|
168
|
+
if (title === "") return null;
|
|
169
|
+
const entry = { title };
|
|
170
|
+
if (typeof item.imageUrl === "string" && isHttpUrl(item.imageUrl)) entry.imageUrl = item.imageUrl;
|
|
171
|
+
if (typeof item.link === "string" && isHttpUrl(item.link)) entry.link = item.link;
|
|
172
|
+
if (typeof item.utmContent === "string" && item.utmContent !== "") entry.utmContent = item.utmContent;
|
|
173
|
+
return entry;
|
|
174
|
+
}
|
|
175
|
+
//#endregion
|
|
176
|
+
//#region src/components/PostPurchase/PostPurchase.tsx
|
|
177
|
+
/**
|
|
178
|
+
* Given referral status and merchant info, compute the display variant
|
|
179
|
+
* and pick the appropriate purchase reward.
|
|
180
|
+
*/
|
|
181
|
+
function resolvePostPurchaseContext(referralStatus, merchantInfo) {
|
|
182
|
+
const purchaseReward = merchantInfo.rewards.find((r) => r.interactionTypeKey === "purchase" && (r.referrer || r.referee));
|
|
183
|
+
if (!purchaseReward) return null;
|
|
184
|
+
const variant = referralStatus?.isReferred && purchaseReward.referee ? "referee" : "referrer";
|
|
185
|
+
return {
|
|
186
|
+
variant,
|
|
187
|
+
reward: variant === "referee" ? purchaseReward.referee : purchaseReward.referrer,
|
|
188
|
+
merchantDomain: merchantInfo.onChainMetadata.domain
|
|
189
|
+
};
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* Post-purchase card component.
|
|
193
|
+
*
|
|
194
|
+
* Renders an inline card on the merchant's thank-you / order-status page
|
|
195
|
+
* that either congratulates a referee or invites a referrer to share.
|
|
196
|
+
*
|
|
197
|
+
* Fetches referral status and merchant information via two independent
|
|
198
|
+
* RPC calls, then computes the display variant locally.
|
|
199
|
+
*
|
|
200
|
+
* @group components
|
|
201
|
+
*
|
|
202
|
+
* @example
|
|
203
|
+
* Minimal — just show the card:
|
|
204
|
+
* ```html
|
|
205
|
+
* <frak-post-purchase></frak-post-purchase>
|
|
206
|
+
* ```
|
|
207
|
+
*
|
|
208
|
+
* @example
|
|
209
|
+
* With purchase tracking fallback and custom sharing URL:
|
|
210
|
+
* ```html
|
|
211
|
+
* <frak-post-purchase
|
|
212
|
+
* customer-id="cust_123"
|
|
213
|
+
* order-id="ord_456"
|
|
214
|
+
* token="checkout_abc"
|
|
215
|
+
* sharing-url="https://merchant.com/product/shoes"
|
|
216
|
+
* ></frak-post-purchase>
|
|
217
|
+
* ```
|
|
218
|
+
*/
|
|
219
|
+
function PostPurchase({ customerId, orderId, token, sharingUrl, merchantId, placement: placementId, classname = "", variant: forcedVariant, badgeText: propBadgeText, referrerText: propReferrerText, refereeText: propRefereeText, ctaText: propCtaText, preview, previewVariant, products, imageUrl }) {
|
|
220
|
+
const isPreview = !!preview;
|
|
221
|
+
const { shouldRender, isHidden, isClientReady } = useClientReady();
|
|
222
|
+
const placement = usePlacement(placementId);
|
|
223
|
+
useLightDomStyles("frak-post-purchase", placementId, placement?.components?.postPurchase?.css, cssSource, cssSource$2);
|
|
224
|
+
const [context, setContext] = useState(null);
|
|
225
|
+
const [hasFetched, setHasFetched] = useState(false);
|
|
226
|
+
useEffect(() => {
|
|
227
|
+
if (isPreview) return;
|
|
228
|
+
if (!isClientReady || !customerId || !orderId || !token) return;
|
|
229
|
+
trackPurchaseStatus({
|
|
230
|
+
customerId,
|
|
231
|
+
orderId,
|
|
232
|
+
token,
|
|
233
|
+
merchantId
|
|
234
|
+
}).catch(() => {});
|
|
235
|
+
}, [
|
|
236
|
+
isPreview,
|
|
237
|
+
isClientReady,
|
|
238
|
+
customerId,
|
|
239
|
+
orderId,
|
|
240
|
+
token,
|
|
241
|
+
merchantId
|
|
242
|
+
]);
|
|
243
|
+
useEffect(() => {
|
|
244
|
+
if (isPreview) return;
|
|
245
|
+
if (!isClientReady || hasFetched) return;
|
|
246
|
+
const client = window.FrakSetup?.client;
|
|
247
|
+
if (!client) return;
|
|
248
|
+
Promise.all([getUserReferralStatus(client), getMerchantInformation(client)]).then(([referralStatus, merchantInfo]) => {
|
|
249
|
+
setHasFetched(true);
|
|
250
|
+
setContext(resolvePostPurchaseContext(referralStatus, merchantInfo));
|
|
251
|
+
}).catch((e) => {
|
|
252
|
+
if (e instanceof FrakRpcError && e.code === RpcErrorCodes.configError) {
|
|
253
|
+
setHasFetched(true);
|
|
254
|
+
return;
|
|
255
|
+
}
|
|
256
|
+
console.warn("[Frak] Post-purchase context error", e);
|
|
257
|
+
});
|
|
258
|
+
}, [
|
|
259
|
+
isPreview,
|
|
260
|
+
isClientReady,
|
|
261
|
+
hasFetched
|
|
262
|
+
]);
|
|
263
|
+
const trackedImpressionVariantRef = useRef(null);
|
|
264
|
+
const resolvedVariant = forcedVariant ?? context?.variant ?? (isPreview ? previewVariant ?? "referrer" : void 0);
|
|
265
|
+
const resolvedSharingUrl = sharingUrl ?? context?.merchantDomain;
|
|
266
|
+
const rewardText = useMemo(() => {
|
|
267
|
+
if (!context?.reward) return void 0;
|
|
268
|
+
const currency = window.FrakSetup?.client?.config?.metadata?.currency;
|
|
269
|
+
return formatEstimatedReward(context.reward, currency);
|
|
270
|
+
}, [context?.reward]);
|
|
271
|
+
const globalComponents = useGlobalComponents();
|
|
272
|
+
const postPurchaseConfig = placement?.components?.postPurchase ?? globalComponents?.postPurchase;
|
|
273
|
+
const resolvedBadgeText = propBadgeText ?? postPurchaseConfig?.badgeText;
|
|
274
|
+
const texts = useMemo(() => {
|
|
275
|
+
return {
|
|
276
|
+
message: resolvedVariant === "referee" ? rewardText ? applyRewardPlaceholder(propRefereeText ?? postPurchaseConfig?.refereeText ?? "You just earned {REWARD}! Share with friends to earn even more.", rewardText) : propRefereeText ?? postPurchaseConfig?.refereeNoRewardText ?? "You just earned a reward! Share with friends to earn even more." : rewardText ? applyRewardPlaceholder(propReferrerText ?? postPurchaseConfig?.referrerText ?? "Earn {REWARD} by sharing this with your friends!", rewardText) : propReferrerText ?? postPurchaseConfig?.referrerNoRewardText ?? "Share this with your friends and earn rewards!",
|
|
277
|
+
cta: rewardText ? applyRewardPlaceholder(propCtaText ?? postPurchaseConfig?.ctaText ?? "Share & earn {REWARD}", rewardText) : propCtaText ?? postPurchaseConfig?.ctaNoRewardText ?? "Share & earn"
|
|
278
|
+
};
|
|
279
|
+
}, [
|
|
280
|
+
resolvedVariant,
|
|
281
|
+
rewardText,
|
|
282
|
+
postPurchaseConfig,
|
|
283
|
+
propReferrerText,
|
|
284
|
+
propRefereeText,
|
|
285
|
+
propCtaText
|
|
286
|
+
]);
|
|
287
|
+
useEffect(() => {
|
|
288
|
+
if (!resolvedVariant) return;
|
|
289
|
+
if (trackedImpressionVariantRef.current === resolvedVariant) return;
|
|
290
|
+
if (!isPreview && (!shouldRender || isHidden || !isClientReady)) return;
|
|
291
|
+
trackEvent(window.FrakSetup?.client, "post_purchase_impression", {
|
|
292
|
+
placement: placementId,
|
|
293
|
+
variant: resolvedVariant,
|
|
294
|
+
has_reward: Boolean(context?.reward)
|
|
295
|
+
});
|
|
296
|
+
trackedImpressionVariantRef.current = resolvedVariant;
|
|
297
|
+
}, [
|
|
298
|
+
resolvedVariant,
|
|
299
|
+
shouldRender,
|
|
300
|
+
isHidden,
|
|
301
|
+
isClientReady,
|
|
302
|
+
isPreview,
|
|
303
|
+
placementId,
|
|
304
|
+
context?.reward
|
|
305
|
+
]);
|
|
306
|
+
const parsedProducts = useMemo(() => {
|
|
307
|
+
const candidates = coerceProductCandidates(products);
|
|
308
|
+
if (!candidates) return void 0;
|
|
309
|
+
const sanitized = [];
|
|
310
|
+
for (const candidate of candidates) {
|
|
311
|
+
const entry = normalizeProductCandidate(candidate);
|
|
312
|
+
if (entry) sanitized.push(entry);
|
|
313
|
+
}
|
|
314
|
+
return sanitized.length > 0 ? sanitized : void 0;
|
|
315
|
+
}, [products]);
|
|
316
|
+
const handleClick = useCallback(() => {
|
|
317
|
+
if (!resolvedVariant) return;
|
|
318
|
+
trackEvent(window.FrakSetup?.client, "post_purchase_clicked", {
|
|
319
|
+
placement: placementId,
|
|
320
|
+
variant: resolvedVariant
|
|
321
|
+
});
|
|
322
|
+
openSharingPage(void 0, placementId, {
|
|
323
|
+
link: resolvedSharingUrl,
|
|
324
|
+
products: parsedProducts
|
|
325
|
+
});
|
|
326
|
+
}, [
|
|
327
|
+
resolvedVariant,
|
|
328
|
+
placementId,
|
|
329
|
+
resolvedSharingUrl,
|
|
330
|
+
parsedProducts
|
|
331
|
+
]);
|
|
332
|
+
if (!resolvedVariant) return null;
|
|
333
|
+
if (!isPreview && (!shouldRender || isHidden || !context)) return null;
|
|
334
|
+
return /* @__PURE__ */ jsx("div", {
|
|
335
|
+
className: [card, classname].filter(Boolean).join(" "),
|
|
336
|
+
children: /* @__PURE__ */ jsxs("div", {
|
|
337
|
+
class: cardLayout,
|
|
338
|
+
children: [/* @__PURE__ */ jsxs("div", {
|
|
339
|
+
class: cardLeft,
|
|
340
|
+
children: [
|
|
341
|
+
resolvedBadgeText && /* @__PURE__ */ jsx("span", {
|
|
342
|
+
class: "PostPurchase_badge__5fv5lh4",
|
|
343
|
+
children: resolvedBadgeText
|
|
344
|
+
}),
|
|
345
|
+
/* @__PURE__ */ jsx("p", {
|
|
346
|
+
class: message,
|
|
347
|
+
children: texts.message
|
|
348
|
+
}),
|
|
349
|
+
/* @__PURE__ */ jsxs("button", {
|
|
350
|
+
type: "button",
|
|
351
|
+
className: `${cta} button`,
|
|
352
|
+
disabled: !isPreview && !isClientReady,
|
|
353
|
+
onClick: isPreview ? void 0 : handleClick,
|
|
354
|
+
children: [texts.cta, /* @__PURE__ */ jsx("svg", {
|
|
355
|
+
width: "16",
|
|
356
|
+
height: "16",
|
|
357
|
+
viewBox: "0 0 16 16",
|
|
358
|
+
fill: "none",
|
|
359
|
+
"aria-hidden": "true",
|
|
360
|
+
className: `${icon} button`,
|
|
361
|
+
children: /* @__PURE__ */ jsx("path", {
|
|
362
|
+
d: "M13.8984 11.144C13.9864 11.052 14.1543 11.1114 14.1543 11.2388V11.644C14.1543 13.0509 12.6288 14.1918 10.7471 14.1919C8.86523 14.1919 7.33984 13.051 7.33984 11.644V11.2388C7.33984 11.1114 7.50675 11.052 7.59473 11.144C8.3452 11.9295 9.47906 12.4292 10.7471 12.4292C12.0149 12.4291 13.148 11.9293 13.8984 11.144ZM1.8457 9.64795C1.8457 9.51169 2.01094 9.44452 2.10254 9.54053C2.85304 10.3238 3.98586 10.8247 5.25293 10.8247C5.52246 10.8247 5.78608 10.8026 6.04102 10.7593C6.25744 10.7225 6.46582 10.8816 6.46582 11.1011V12.1704C6.46564 12.319 6.36769 12.4507 6.22266 12.4829C5.91535 12.5512 5.58981 12.5874 5.25293 12.5874C3.3711 12.5874 1.8457 11.4469 1.8457 10.0396V9.64795ZM10.7471 6.20654C12.6288 6.20666 14.1543 7.3475 14.1543 8.75439C14.1541 10.1612 12.6287 11.3012 10.7471 11.3013C8.86535 11.3013 7.34004 10.1612 7.33984 8.75439C7.33984 7.34743 8.86523 6.20654 10.7471 6.20654ZM1.8457 6.8501C1.84597 6.71385 2.01208 6.64848 2.10352 6.74365C2.85393 7.52827 3.98602 8.0278 5.25293 8.02783C5.52282 8.02783 5.78667 8.00448 6.04199 7.96143C6.258 7.92499 6.46582 8.08514 6.46582 8.3042V9.37256C6.46582 9.52127 6.36783 9.65378 6.22266 9.68604C5.91537 9.75429 5.58979 9.79053 5.25293 9.79053C3.3711 9.79048 1.8457 8.64863 1.8457 7.24268V6.8501ZM5.25293 1.80811C7.13481 1.80811 8.66016 2.94856 8.66016 4.35596C8.66008 5.76331 7.13476 6.90381 5.25293 6.90381C3.37115 6.90376 1.84578 5.76328 1.8457 4.35596C1.8457 2.94858 3.3711 1.80815 5.25293 1.80811Z",
|
|
363
|
+
fill: "currentColor"
|
|
364
|
+
})
|
|
365
|
+
})]
|
|
366
|
+
})
|
|
367
|
+
]
|
|
368
|
+
}), /* @__PURE__ */ jsxs("div", {
|
|
369
|
+
class: cardRight,
|
|
370
|
+
children: [imageUrl ? /* @__PURE__ */ jsx("span", {
|
|
371
|
+
class: imageWrapper,
|
|
372
|
+
children: /* @__PURE__ */ jsx("img", {
|
|
373
|
+
src: imageUrl,
|
|
374
|
+
alt: "",
|
|
375
|
+
class: customImage
|
|
376
|
+
})
|
|
377
|
+
}) : /* @__PURE__ */ jsx(GiftIcon, {
|
|
378
|
+
className: giftIcon,
|
|
379
|
+
width: 80,
|
|
380
|
+
height: 80
|
|
381
|
+
}), /* @__PURE__ */ jsx(LogoFrakWithName, {
|
|
382
|
+
className: frakLogo,
|
|
383
|
+
width: 42,
|
|
384
|
+
height: 24
|
|
385
|
+
})]
|
|
386
|
+
})]
|
|
387
|
+
})
|
|
388
|
+
});
|
|
389
|
+
}
|
|
390
|
+
//#endregion
|
|
391
|
+
//#region src/components/PostPurchase/index.ts
|
|
392
|
+
registerWebComponent(PostPurchase, "frak-post-purchase", [
|
|
393
|
+
"customerId",
|
|
394
|
+
"orderId",
|
|
395
|
+
"token",
|
|
396
|
+
"sharingUrl",
|
|
397
|
+
"merchantId",
|
|
398
|
+
"placement",
|
|
399
|
+
"classname",
|
|
400
|
+
"variant",
|
|
401
|
+
"badgeText",
|
|
402
|
+
"referrerText",
|
|
403
|
+
"refereeText",
|
|
404
|
+
"ctaText",
|
|
405
|
+
"products",
|
|
406
|
+
"preview",
|
|
407
|
+
"previewVariant",
|
|
408
|
+
"imageUrl"
|
|
409
|
+
], { shadow: false });
|
|
410
|
+
//#endregion
|
|
411
|
+
export { PostPurchase };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { displaySharingPage } from "@frak-labs/core-sdk/actions";
|
|
2
|
+
//#region src/actions/sharingPage.ts
|
|
3
|
+
async function openSharingPage(targetInteraction, placement, options) {
|
|
4
|
+
if (!window.FrakSetup?.client) {
|
|
5
|
+
console.error("Frak client not found");
|
|
6
|
+
return;
|
|
7
|
+
}
|
|
8
|
+
await displaySharingPage(window.FrakSetup.client, {
|
|
9
|
+
...options?.link && { link: options.link },
|
|
10
|
+
...options?.products?.length && { products: options.products },
|
|
11
|
+
...targetInteraction && { metadata: { targetInteraction } }
|
|
12
|
+
}, placement);
|
|
13
|
+
}
|
|
14
|
+
//#endregion
|
|
15
|
+
export { openSharingPage as t };
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { sdkConfigStore } from "@frak-labs/core-sdk";
|
|
2
|
+
import { useEffect, useMemo, useState } from "preact/hooks";
|
|
3
|
+
//#region src/hooks/useGlobalComponents.ts
|
|
4
|
+
/**
|
|
5
|
+
* Subscribe to the global component defaults from the SDK config store.
|
|
6
|
+
* These serve as fallbacks when no placement-level override exists.
|
|
7
|
+
*/
|
|
8
|
+
function useGlobalComponents() {
|
|
9
|
+
const [configVersion, setConfigVersion] = useState(0);
|
|
10
|
+
useEffect(() => {
|
|
11
|
+
const onConfig = (_e) => {
|
|
12
|
+
setConfigVersion((v) => v + 1);
|
|
13
|
+
};
|
|
14
|
+
window.addEventListener("frak:config", onConfig);
|
|
15
|
+
setConfigVersion((v) => v + 1);
|
|
16
|
+
return () => window.removeEventListener("frak:config", onConfig);
|
|
17
|
+
}, []);
|
|
18
|
+
return useMemo(() => sdkConfigStore.getConfig().components, [configVersion]);
|
|
19
|
+
}
|
|
20
|
+
//#endregion
|
|
21
|
+
export { useGlobalComponents as t };
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { r as lightDomBaseCss } from "./usePlacement-DzEuVg_u.js";
|
|
2
|
+
import { useEffect } from "preact/hooks";
|
|
3
|
+
//#region src/styles/styleManager.ts
|
|
4
|
+
function ensureStyle(id, css) {
|
|
5
|
+
const existing = document.getElementById(id);
|
|
6
|
+
if (existing) {
|
|
7
|
+
if (existing.textContent !== css) existing.textContent = css;
|
|
8
|
+
return;
|
|
9
|
+
}
|
|
10
|
+
const style = document.createElement("style");
|
|
11
|
+
style.id = id;
|
|
12
|
+
style.textContent = css;
|
|
13
|
+
document.head.appendChild(style);
|
|
14
|
+
}
|
|
15
|
+
function injectBase(tag, css) {
|
|
16
|
+
const id = `frak-base-${tag}`;
|
|
17
|
+
if (document.getElementById(id)) return;
|
|
18
|
+
if (!css) return;
|
|
19
|
+
const style = document.createElement("style");
|
|
20
|
+
style.id = id;
|
|
21
|
+
style.textContent = css;
|
|
22
|
+
document.head.appendChild(style);
|
|
23
|
+
}
|
|
24
|
+
function injectPlacement(tag, placementId, scopedCss) {
|
|
25
|
+
ensureStyle(`frak-placement-${tag}-${placementId}`, scopedCss);
|
|
26
|
+
}
|
|
27
|
+
const styleManager = {
|
|
28
|
+
injectBase,
|
|
29
|
+
injectPlacement
|
|
30
|
+
};
|
|
31
|
+
//#endregion
|
|
32
|
+
//#region src/hooks/useLightDomStyles.ts
|
|
33
|
+
function useLightDomStyles(tag, placementId, placementCss, baseCss, sharedBaseCss) {
|
|
34
|
+
useEffect(() => {
|
|
35
|
+
if (sharedBaseCss) styleManager.injectBase("shared", sharedBaseCss);
|
|
36
|
+
styleManager.injectBase(tag, baseCss ?? lightDomBaseCss);
|
|
37
|
+
}, [tag]);
|
|
38
|
+
useEffect(() => {
|
|
39
|
+
if (!placementId || !placementCss) return;
|
|
40
|
+
styleManager.injectPlacement(tag, placementId, placementCss);
|
|
41
|
+
}, [
|
|
42
|
+
tag,
|
|
43
|
+
placementId,
|
|
44
|
+
placementCss
|
|
45
|
+
]);
|
|
46
|
+
}
|
|
47
|
+
//#endregion
|
|
48
|
+
export { useLightDomStyles as t };
|