@frak-labs/components 1.1.0-beta.65694f73 → 1.1.0-beta.692dca6b

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (34) hide show
  1. package/README.md +24 -2
  2. package/cdn/{Banner.Dh-KYDLv.js → Banner.Zaqy93tl.js} +3 -3
  3. package/cdn/ButtonShare.rG47WQjf.js +1 -0
  4. package/cdn/ButtonWallet.C13UfI2G.js +40 -0
  5. package/cdn/OpenInAppButton.d-omgD0k.js +1 -0
  6. package/cdn/PostPurchase._3t6CtvV.js +89 -0
  7. package/cdn/components.js +1 -1
  8. package/cdn/loader.js +8 -52
  9. package/cdn/rewards.0JylBHNY.js +1 -0
  10. package/cdn/{useLightDomStyles.BLyrWEBn.js → useLightDomStyles.B7MVlVVJ.js} +1 -1
  11. package/cdn/{useReward.fvxtDVaA.js → useReward.CaBorN5T.js} +1 -1
  12. package/dist/{GiftIcon-DI0rUKHp.js → GiftIcon-BmGGodb2.js} +1 -1
  13. package/dist/banner.d.ts +3 -4
  14. package/dist/banner.js +7 -7
  15. package/dist/buttonShare.d.ts +3 -4
  16. package/dist/buttonShare.js +27 -9
  17. package/dist/buttonWallet.d.ts +6 -10
  18. package/dist/buttonWallet.js +39 -44
  19. package/dist/i18n/defaults.d.ts +2 -3
  20. package/dist/openInApp.d.ts +4 -5
  21. package/dist/openInApp.js +4 -5
  22. package/dist/postPurchase.d.ts +3 -4
  23. package/dist/postPurchase.js +20 -6
  24. package/dist/{rewards-CZkWSndn.js → rewards-DoVY1pWr.js} +4 -4
  25. package/dist/{useGlobalComponents-DFv33ujB.js → useGlobalComponents-Cj7uGBwD.js} +1 -1
  26. package/dist/{useLightDomStyles-B_IbOqJZ.js → useLightDomStyles-BW6DY5sC.js} +1 -1
  27. package/dist/{usePlacement-DtwWaLHO.js → usePlacement-iFDQqtJn.js} +14 -39
  28. package/dist/{useReward-D5zzFR11.js → useReward-k7RF3DhH.js} +1 -1
  29. package/package.json +14 -14
  30. package/cdn/ButtonShare.CiEtGubR.js +0 -1
  31. package/cdn/ButtonWallet.B-80TBVO.js +0 -40
  32. package/cdn/OpenInAppButton.DYfr8q7L.js +0 -1
  33. package/cdn/PostPurchase.CxEoeBs_.js +0 -89
  34. package/cdn/rewards.DjfrchZd.js +0 -1
package/package.json CHANGED
@@ -11,7 +11,7 @@
11
11
  "url": "https://twitter.com/QNivelais"
12
12
  }
13
13
  ],
14
- "version": "1.1.0-beta.65694f73",
14
+ "version": "1.1.0-beta.692dca6b",
15
15
  "description": "Frak Wallet components, helping any person to interact with the Frak wallet.",
16
16
  "repository": {
17
17
  "url": "https://github.com/frak-id/wallet",
@@ -103,33 +103,33 @@
103
103
  "publish": "echo 'Publishing components...'"
104
104
  },
105
105
  "dependencies": {
106
- "@frak-labs/core-sdk": "1.3.0-beta.65694f73",
107
- "@frak-labs/design-system": "0.0.0",
108
- "@frak-labs/frame-connector": "1.3.0-beta.65694f73",
109
- "preact": "^10.29.7",
106
+ "@frak-labs/core-sdk": "1.3.0-beta.692dca6b",
107
+ "@frak-labs/frame-connector": "1.3.0-beta.692dca6b",
108
+ "preact": "^10.29.8",
110
109
  "preact-custom-element": "^4.6.0"
111
110
  },
112
111
  "devDependencies": {
112
+ "@frak-labs/design-system": "0.0.0",
113
113
  "@frak-labs/test-foundation": "0.1.0",
114
114
  "@preact/preset-vite": "^2.10.6",
115
115
  "@rolldown/plugin-node-polyfills": "^1.0.3",
116
- "@testing-library/jest-dom": "^7.0.0",
116
+ "@testing-library/jest-dom": "^7.0.1",
117
117
  "@testing-library/preact": "^3.2.4",
118
- "@testing-library/user-event": "^14.6.1",
119
- "@types/jsdom": "^28.0.3",
118
+ "@testing-library/user-event": "^14.6.7",
119
+ "@types/jsdom": "^30.0.0",
120
120
  "@types/node": "^25.9.5",
121
121
  "@types/preact-custom-element": "^4.0.4",
122
122
  "@typescript/native": "npm:typescript@^7.0.2",
123
123
  "@vanilla-extract/css": "^1.21.2",
124
124
  "@vanilla-extract/integration": "^8.0.10",
125
- "@vanilla-extract/sprinkles": "^1.7.0",
125
+ "@vanilla-extract/sprinkles": "^1.7.1",
126
126
  "@vanilla-extract/vite-plugin": "^5.2.6",
127
- "@vitest/coverage-v8": "^4.1.10",
128
- "@vitest/ui": "^4.1.10",
129
- "jsdom": "^29.1.1",
127
+ "@vitest/coverage-v8": "^5.0.0",
128
+ "@vitest/ui": "^5.0.0",
129
+ "jsdom": "^30.0.1",
130
130
  "rolldown": "~1.2.0",
131
- "tsdown": "^0.22.14",
131
+ "tsdown": "^0.23.0",
132
132
  "typescript": "^6.0.3",
133
- "vitest": "^4.1.10"
133
+ "vitest": "^5.0.0"
134
134
  }
135
135
  }
@@ -1 +0,0 @@
1
- import{S as e,l as t,r as n}from"./loader.js";import{a as r,h as i,m as a,n as o,p as s,s as c,t as l,u}from"./defaults.CmUvOlLQ.js";import{t as d}from"./useGlobalComponents.C7wnXWOg.js";import{t as f}from"./useLightDomStyles.BLyrWEBn.js";import{i as p}from"./rewards.DjfrchZd.js";import{t as m}from"./useReward.fvxtDVaA.js";function h({placement:i,text:h,classname:g=``,noRewardText:_,targetInteraction:v,products:y,clickAction:b,preview:x}){let S=!!x,C=r(),w=o(i),T=d(),E=w?.components?.buttonShare??T?.buttonShare;f(`frak-button-share`,i,E?.css);let D=u(()=>w?.targetInteraction===void 0?v:w.targetInteraction,[w?.targetInteraction,v]),O=E?.text??h??l[C].buttonShare.text,k=E?.noRewardText??_,A=u(()=>O.includes(`{REWARD}`),[O]),j=u(()=>E?.clickAction??b??`sharing-page`,[E?.clickAction,b]),{shouldRender:M,isHidden:N,isClientReady:P}=c(),F=u(()=>t(y),[y]),{reward:I}=m(A&&P,D,void 0,F),L=u(()=>A?I?p(O,I):k??p(O,void 0):O,[A,O,k,I]),R=s(()=>{S||(e(window.FrakSetup.client,`share_button_clicked`,{placement:i,target_interaction:D,has_reward:!!I,click_action:j}),n(D,i,{products:F}))},[S,j,D,i,I,F]);if(!S&&(!M||N))return null;let z=[`button`,`button__fadeIn`,g].filter(Boolean).join(` `);return a(`button`,{type:`button`,disabled:!S&&!P,class:z,onClick:R,children:L})}i(h,`frak-button-share`,[`text`,`placement`,`classname`,`clickAction`,`noRewardText`,`targetInteraction`,`products`,`preview`],{shadow:!1});export{h as ButtonShare};
@@ -1,40 +0,0 @@
1
- import{S as e,r as t}from"./loader.js";import{a as n,d as r,f as i,g as a,h as o,m as s,n as c,p as l,r as u,s as d,t as f,u as p}from"./defaults.CmUvOlLQ.js";import{t as m}from"./useReward.fvxtDVaA.js";function h(e){return s(`svg`,{fill:`none`,height:`1em`,viewBox:`0 0 28 28`,width:`1em`,xmlns:`http://www.w3.org/2000/svg`,...e,children:[s(`title`,{children:`Gift icon`}),s(`path`,{d:`m23.14 14v11.43h-18.29v-11.43m9.14 11.43v-17.14m0 0h-5.14c-0.76 0-1.48-0.3-2.02-0.84s-0.84-1.26-0.84-2.020.3-1.480.84-2.02 1.26-0.84 2.02-0.84c4 0 5.14 5.71 5.14 5.71zm0 0h5.14c0.76 0 1.48-0.3 2.02-0.84s0.84-1.260.84-2.02-0.3-1.48-0.84-2.02-1.26-0.84-2.02-0.84c-4 0-5.14 5.71-5.14 5.71zm-11.43 0h22.86v5.71h-22.86z`,stroke:`#fff`,"stroke-linecap":`round`,"stroke-linejoin":`round`})]})}function g(){`vibrate`in navigator?navigator.vibrate(10):console.log(`Vibration not supported`)}function _(e,n){g(),t(e,n)}function v({placement:t,classname:o=``,useReward:g,targetInteraction:v}){let y=n(),b=c(t),x=p(()=>b?.targetInteraction===void 0?v:b.targetInteraction,[b?.targetInteraction,v]),S=p(()=>g===!0,[g]),{shouldRender:C,isHidden:w,isClientReady:T}=d(),{reward:E}=m(S&&T,x),[D,O]=r(`right`),k=l(()=>{e(window.FrakSetup.client,`share_button_clicked`,{placement:t,target_interaction:x,has_reward:!!E,click_action:`sharing-page`}),_(x,t)},[t,x,E]);if(i(()=>{let e=b?.components?.buttonWallet?.position,t=window.FrakSetup?.modalWalletConfig?.metadata?.position;O(e??t??`right`)},[b?.components?.buttonWallet?.position]),!C||w)return null;let A=[`button`,`button__fadeIn`,D===`left`?`button__left`:`button__right`,o].filter(Boolean).join(` `);return s(a,{children:[s(`style`,{children:u(`
2
- .button {
3
- all: unset;
4
- position: fixed;
5
- bottom: 20px;
6
- z-index: 2000000;
7
- display: flex;
8
- justify-content: center;
9
- align-items: center;
10
- background-color: #3e557e;
11
- width: 45px;
12
- height: 45px;
13
- border-radius: 50%;
14
- cursor: pointer;
15
- text-align: center;
16
- font-size: 24px;
17
- }
18
-
19
- .button__left {
20
- left: 20px;
21
- }
22
-
23
- .button__right {
24
- right: 20px;
25
- }
26
-
27
- .reward {
28
- position: absolute;
29
- top: -4px;
30
- right: 27px;
31
- padding: 2px 3px;
32
- border-radius: 5px;
33
- background: #ff3f3f;
34
- font-size: 9px;
35
- color: #fff;
36
- font-weight: 600;
37
- white-space: nowrap;
38
- line-height: 9px;
39
- }
40
- `,b?.components?.buttonWallet?.css)}),s(`button`,{type:`button`,"aria-label":f[y].buttonWallet.ariaLabel,part:`button`,disabled:!T,class:A,onClick:k,children:[s(h,{}),E&&s(`span`,{class:`reward`,children:E})]})]})}o(v,`frak-button-wallet`,[`placement`,`classname`,`useReward`,`targetInteraction`],{shadow:!0});export{v as ButtonWallet};
@@ -1 +0,0 @@
1
- import{S as e,g as t,h as n,u as r}from"./loader.js";import{a as i,h as a,m as o,n as s,s as c,t as l,u}from"./defaults.CmUvOlLQ.js";import{t as d}from"./useLightDomStyles.BLyrWEBn.js";function f(n=`wallet`,i){let a=window.FrakSetup?.client;a&&e(a,`open_in_app_clicked`,{path:n,placement:i});let o=`${t}${n}`;r(o,{onFallback:()=>{a&&e(a,`app_not_installed`,{path:n,placement:i})}})}function p(){return{isMobile:u(()=>n(),[])}}function m({placement:e,text:t,classname:n=``}){let r=i(),a=s(e),{shouldRender:u,isHidden:m,isClientReady:h}=c(),{isMobile:g}=p();d(`frak-open-in-app`,e,a?.components?.openInApp?.css);let _=a?.components?.openInApp?.text??t??l[r].openInApp.text;if(!g||!u||m)return null;let v=()=>{f(void 0,e)},y=[`button`,`button__fadeIn`,n].filter(Boolean).join(` `);return o(`button`,{type:`button`,"aria-label":l[r].openInApp.ariaLabel,disabled:!h,class:y,onClick:v,children:_})}a(m,`frak-open-in-app`,[`text`,`placement`,`classname`],{shadow:!1});export{m as OpenInAppButton};
@@ -1,89 +0,0 @@
1
- import{O as e,S as t,T as n,c as r,i,l as a,o,r as s,w as ee}from"./loader.js";import{a as te,d as c,f as l,h as u,l as d,m as f,n as p,p as m,s as h,t as ne,u as g}from"./defaults.CmUvOlLQ.js";import{r as re,t as ie}from"./GiftIcon.CPyeWQNR.js";import{t as ae}from"./useGlobalComponents.C7wnXWOg.js";import{t as oe}from"./useLightDomStyles.BLyrWEBn.js";import{i as _,n as v,t as se}from"./rewards.DjfrchZd.js";var ce=`PostPurchase_card__5fv5lh0`,le=`PostPurchase_cardLayout__5fv5lh1`,ue=`PostPurchase_cardLeft__5fv5lh2`,de=`PostPurchase_cardRight__5fv5lh3`,fe=`PostPurchase_cta__5fv5lh6 sharedBaseCss_buttonReset__7cswil0`,y=`PostPurchase_customImage__5fv5lha`,b=`PostPurchase_frakLogo__5fv5lhb`,pe=`PostPurchase_giftIcon__5fv5lh8`,me=`PostPurchase_icon__5fv5lh7`,he=`PostPurchase_imageWrapper__5fv5lh9`,ge=`PostPurchase_message__5fv5lh5`;function _e(e,t,n,r){let i=e?.isReferred?`referee`:`referrer`,a=v(t.rewards,{targetInteraction:`purchase`,currency:n,audience:i,products:r});if(!a)return null;let{campaign:o}=a,s=e?.isReferred&&o.referee?`referee`:`referrer`;return{variant:s,reward:s===`referee`?o.referee:o.referrer,merchantDomain:t.onChainMetadata.domain}}function x({customerId:u,orderId:v,token:x,sharingUrl:ve,merchantId:S,placement:C,classname:w=``,variant:T,badgeText:E,referrerText:D,refereeText:O,ctaText:k,preview:A,previewVariant:j,products:M,imageUrl:N}){let P=!!A,{shouldRender:F,isHidden:I,isClientReady:L}=h(),R=p(C),z=te(),B=g(()=>a(M),[M]);oe(`frak-post-purchase`,C,R?.components?.postPurchase?.css,`.PostPurchase_card__5fv5lh0 {
2
- padding: 16px;
3
- border-radius: 12px;
4
- background-color: var(--surface-background__pbq4akc);
5
- border: 1px solid var(--border-default__pbq4akv);
6
- }
7
- .PostPurchase_cardLayout__5fv5lh1 {
8
- display: flex;
9
- flex-direction: row;
10
- align-items: center;
11
- gap: 32px;
12
- }
13
- .PostPurchase_cardLeft__5fv5lh2 {
14
- flex-grow: 1;
15
- min-width: 0;
16
- display: flex;
17
- flex-direction: column;
18
- gap: 8px;
19
- }
20
- .PostPurchase_cardRight__5fv5lh3 {
21
- flex-shrink: 0;
22
- display: flex;
23
- flex-direction: column;
24
- align-items: flex-end;
25
- gap: 8px;
26
- text-align: right;
27
- }
28
- .PostPurchase_badge__5fv5lh4 {
29
- align-self: flex-start;
30
- background-color: #FFF534;
31
- border-radius: 4px;
32
- padding: 4px 8px;
33
- font-size: 12px;
34
- font-weight: 600;
35
- line-height: 12px;
36
- color: var(--text-primary__pbq4ak0);
37
- }
38
- .PostPurchase_message__5fv5lh5 {
39
- margin: 0;
40
- font-size: 16px;
41
- line-height: 22px;
42
- color: var(--text-primary__pbq4ak0);
43
- font-weight: 600;
44
- }
45
- .PostPurchase_cta__5fv5lh6 {
46
- display: inline-flex;
47
- align-items: center;
48
- justify-content: center;
49
- gap: 4px;
50
- padding: 12px 16px;
51
- border-radius: 9999px;
52
- background-color: var(--text-primary__pbq4ak0);
53
- color: var(--text-onAction__pbq4ak6);
54
- font-size: 12px;
55
- font-weight: bold;
56
- text-transform: uppercase;
57
- }
58
- .PostPurchase_cta__5fv5lh6:disabled {
59
- opacity: 0.7;
60
- cursor: default;
61
- }
62
- .PostPurchase_icon__5fv5lh7 {
63
- margin: -2px 0;
64
- }
65
- .PostPurchase_giftIcon__5fv5lh8 {
66
- display: block;
67
- flex-shrink: 0;
68
- }
69
- .PostPurchase_imageWrapper__5fv5lh9 {
70
- flex-shrink: 0;
71
- display: flex;
72
- align-items: center;
73
- justify-content: center;
74
- width: 80px;
75
- height: 80px;
76
- overflow: hidden;
77
- }
78
- .PostPurchase_customImage__5fv5lha {
79
- max-width: 100%;
80
- max-height: 100%;
81
- width: auto;
82
- height: auto;
83
- object-fit: contain;
84
- display: block;
85
- }
86
- .PostPurchase_frakLogo__5fv5lhb {
87
- display: block;
88
- margin-left: auto;
89
- }`,e);let[V,ye]=c(null),[H,U]=c(!1);l(()=>{P||!L||!u||!v||!x||i({customerId:u,orderId:v,token:x,merchantId:S}).catch(()=>{})},[P,L,u,v,x,S]),l(()=>{if(P||!L||H)return;let e=window.FrakSetup?.client;e&&Promise.all([o(e),r(e)]).then(([e,t])=>{U(!0),ye({referralStatus:e,merchantInfo:t})}).catch(e=>{if(e instanceof n&&e.code===ee.configError){U(!0);return}console.warn(`[Frak] Post-purchase context error`,e)})},[P,L,H]);let W=g(()=>V?_e(V.referralStatus,V.merchantInfo,window.FrakSetup?.client?.config?.metadata?.currency,B):null,[V,B]),G=d(null),K=T??W?.variant??(P?j??`referrer`:void 0),q=ve??W?.merchantDomain,J=g(()=>{if(!W?.reward)return;let e=window.FrakSetup?.client?.config?.metadata?.currency;return se(W.reward,e)},[W?.reward]),Y=ae(),X=R?.components?.postPurchase??Y?.postPurchase,Z=E??X?.badgeText,Q=N??X?.imageUrl,$=g(()=>{let e=ne[z].postPurchase;return{message:K===`referee`?J?_(O??X?.refereeText??e.refereeText,J):O??X?.refereeNoRewardText??e.refereeNoRewardText:J?_(D??X?.referrerText??e.referrerText,J):D??X?.referrerNoRewardText??e.referrerNoRewardText,cta:J?_(k??X?.ctaText??e.ctaText,J):k??X?.ctaNoRewardText??e.ctaNoRewardText}},[z,K,J,X,D,O,k]);l(()=>{K&&G.current!==K&&L&&(!P&&(!F||I)||(t(window.FrakSetup?.client,`post_purchase_impression`,{placement:C,variant:K,has_reward:!!W?.reward}),G.current=K))},[K,F,I,L,P,C,W?.reward]);let be=m(()=>{K&&(t(window.FrakSetup?.client,`post_purchase_clicked`,{placement:C,variant:K}),s(void 0,C,{link:q,products:B,checkoutToken:x}))},[K,C,q,B,x]);if(!K||!P&&(!F||I||!W))return null;let xe=[ce,w].filter(Boolean).join(` `);return f(`div`,{className:xe,children:f(`div`,{class:le,children:[f(`div`,{class:ue,children:[Z&&f(`span`,{class:`PostPurchase_badge__5fv5lh4`,children:Z}),f(`p`,{class:ge,children:$.message}),f(`button`,{type:`button`,className:`${fe} button`,disabled:!P&&!L,onClick:P?void 0:be,children:[$.cta,f(`svg`,{width:`16`,height:`16`,viewBox:`0 0 16 16`,fill:`none`,"aria-hidden":`true`,className:`${me} button`,children:f(`path`,{d:`M13.9 11.14C13.99 11.05 14.15 11.11 14.15 11.24V11.64C14.15 13.05 12.63 14.19 10.75 14.19C8.87 14.19 7.34 13.05 7.34 11.64V11.24C7.34 11.11 7.51 11.05 7.59 11.14C8.35 11.93 9.48 12.43 10.75 12.43C12.01 12.43 13.15 11.93 13.9 11.14ZM1.85 9.65C1.85 9.51 2.01 9.44 2.1 9.54C2.85 10.32 3.99 10.82 5.25 10.82C5.52 10.82 5.79 10.8 6.04 10.76C6.26 10.72 6.47 10.88 6.47 11.1V12.17C6.47 12.32 6.37 12.45 6.22 12.48C5.92 12.55 5.59 12.59 5.25 12.59C3.37 12.59 1.85 11.45 1.85 10.04V9.65ZM10.75 6.21C12.63 6.21 14.15 7.35 14.15 8.75C14.15 10.16 12.63 11.3 10.75 11.3C8.87 11.3 7.34 10.16 7.34 8.75C7.34 7.35 8.87 6.21 10.75 6.21ZM1.85 6.85C1.85 6.71 2.01 6.65 2.1 6.74C2.85 7.53 3.99 8.03 5.25 8.03C5.52 8.03 5.79 8 6.04 7.96C6.26 7.92 6.47 8.09 6.47 8.3V9.37C6.47 9.52 6.37 9.65 6.22 9.69C5.92 9.75 5.59 9.79 5.25 9.79C3.37 9.79 1.85 8.65 1.85 7.24V6.85ZM5.25 1.81C7.13 1.81 8.66 2.95 8.66 4.36C8.66 5.76 7.13 6.9 5.25 6.9C3.37 6.9 1.85 5.76 1.85 4.36C1.85 2.95 3.37 1.81 5.25 1.81Z`,fill:`currentColor`})})]})]}),f(`div`,{class:de,children:[Q?f(`span`,{class:he,children:f(`img`,{src:Q,alt:``,class:y})}):f(ie,{className:pe,width:80,height:80}),f(re,{className:b,width:42,height:24})]})]})})}u(x,`frak-post-purchase`,[`customerId`,`orderId`,`token`,`sharingUrl`,`merchantId`,`placement`,`classname`,`variant`,`badgeText`,`referrerText`,`refereeText`,`ctaText`,`products`,`preview`,`previewVariant`,`imageUrl`],{shadow:!1});export{x as PostPurchase};
@@ -1 +0,0 @@
1
- import{_ as e,b as t,v as n,x as r,y as i}from"./loader.js";function a(e){return Array.isArray(e)?e:e.conditions}function o(e){if(typeof e==`number`)return e;if(typeof e==`string`&&e.trim()!==``){let t=Number(e);return Number.isFinite(t)?t:void 0}}function s(e,t,n){let r=[];for(let i of a(e)){if(`logic`in i){r.push(...s(i,t,n));continue}if(i.field===t&&n.has(i.operator)){let e=o(i.value);e!=null&&r.push(e)}}return r}const c=new Set([`gt`,`gte`,`between`]),l=new Set([`gt`,`gte`]);function u(e){let t=s(e,`purchase.amount`,c);return t.length>0?Math.min(...t):void 0}function d(e){let t=s(e,`time.timestamp`,l);if(t.length!==0)return new Date(Math.min(...t)*1e3)}function f(e,t){switch(e.payoutType){case`fixed`:return e.amount[t];case`percentage`:return e.maxAmount?.[t]??0;case`tiered`:return e.tiers.reduce((e,n)=>`amount`in n?Math.max(e,n.amount[t]):e,0)}}function p(e){return e.payoutType===`percentage`?e.percent:e.payoutType===`tiered`?e.tiers.reduce((e,t)=>`percent`in t?Math.max(e,t.percent):e,0):0}function m(e,t){let n=f(e,t);return n>0?n:p(e)*1e-6}function h(e,n){let a=r(n),o=t(a);switch(e.payoutType){case`fixed`:return i(Math.round(e.amount[o]),a);case`percentage`:return`${e.percent} %`;case`tiered`:{let t=f(e,o);if(t>0)return i(Math.round(t),a);let n=p(e);return n>0?`${n} %`:i(0,a)}}}function g(i,a){let o=r(a),s=t(o);switch(i.payoutType){case`fixed`:return e(Math.round(i.amount[s]),o);case`percentage`:return n(i.percent);case`tiered`:{let t=f(i,s);if(t>0)return e(Math.round(t),o);let r=p(i);return r>0?n(r):e(0,o)}}}function _(e,n){if(!(!e||m(e,t(r(n)))<=0))return h(e,n)}function v(e,t){return t?e.replaceAll(`{REWARD}`,t):e.replaceAll(`{REWARD}`,``)}const y=new Set([`eq`,`neq`,`gt`,`gte`,`lt`,`lte`,`between`]),b=new Set([`contains`,`starts_with`,`ends_with`]);function x(e){return`logic`in e&&`conditions`in e}function S(e,t){return e[t]}function C(e){if(typeof e==`number`)return Number.isFinite(e)?e:void 0;if(typeof e==`string`&&e.trim()!==``){let t=Number(e);return Number.isFinite(t)?t:void 0}}function w(e,t){let n=C(e),r=C(t);return n!==void 0&&r!==void 0?n-r:String(e).localeCompare(String(t))}function T(e,t,n){if(!Array.isArray(n))return e===`not_in`;if(t===void 0)return;let r=n.includes(t);return e===`in`?r:!r}function E(e,t,n,r){switch(e){case`eq`:return t===n;case`neq`:return t!==n;case`gt`:return w(t,n)>0;case`gte`:return w(t,n)>=0;case`lt`:return w(t,n)<0;case`lte`:return w(t,n)<=0;case`between`:return r==null||Array.isArray(r)?void 0:w(t,n)>=0&&w(t,r)<=0}}function D(e,t,n){if(typeof t==`string`&&typeof n==`string`)return e===`contains`?t.includes(n):e===`starts_with`?t.startsWith(n):t.endsWith(n)}function O(e,t){let n=S(t,e.field),{operator:r,value:i,valueTo:a}=e;if(r===`exists`)return n!==void 0;if(r===`not_exists`)return n===void 0;if(r===`in`||r===`not_in`)return T(r,n,i);if(!(Array.isArray(i)||n===void 0||i===null)){if(y.has(r))return E(r,n,i,a);if(b.has(r))return D(r,n,i)}}function k(e,t){if(x(e)){let n=e.conditions.map(e=>k(e,t));return e.logic===`all`?n.every(Boolean):e.logic===`any`?n.some(Boolean):e.logic!==`none`||!n.some(Boolean)}return O(e,t)??!0}function A(e,t){return e?Array.isArray(e)?e.every(e=>k(e,t)):k(e,t):!0}function j(e,t){return e.expiresAt!=null&&new Date(e.expiresAt).getTime()<=t}function M(e,t){let n=d(e.conditions);return n==null||n.getTime()<=t}function N(e,t){return t===`referee`?e.referee:e.referrer}function P(e,t,n){let r=N(e,n);return r?m(r,t):0}function F(e,t){if(!t||t.length===0||!e.productScope)return;let n=t.filter(t=>A(e.productScope,t));return n.length>0?n:void 0}function I(e,t){return!t||t.length===0||!e.productScope||t.some(t=>A(e.productScope,t))}function L(e,n={}){let i=(n.now??new Date).getTime(),a=n.audience??`referrer`,o=t(r(n.currency)),s=(n.targetInteraction?e.filter(e=>e.interactionTypeKey===n.targetInteraction):e).filter(e=>!j(e,i)),c=s.filter(e=>M(e,i));if(c.length>0){let e=c.reduce((e,t)=>{let r=I(e,n.products),i=I(t,n.products);return r===i?P(t,o,a)>P(e,o,a)?t:e:i?t:e});return{campaign:e,status:`live`,matchedProducts:F(e,n.products)}}let l=s.map(e=>({campaign:e,startsAt:d(e.conditions)})).filter(e=>e.startsAt!=null);if(l.length===0)return;let u=l.reduce((e,t)=>{let r=I(e.campaign,n.products),i=I(t.campaign,n.products);return r===i?t.startsAt.getTime()<e.startsAt.getTime()?t:e:i?t:e});return{campaign:u.campaign,status:`upcoming`,startsAt:u.startsAt,matchedProducts:F(u.campaign,n.products)}}function R(e,t={}){let n=L(e,t);if(!n)return;let r=N(n.campaign,t.audience??`referrer`);if(!r)return;let a=_(r,t.currency);if(!a)return;let o=u(n.campaign.conditions),s=o==null?void 0:i(o,t.currency),c=n.campaign.defaultLockupSeconds,l=c&&c>0?Math.round(c/86400):void 0;return{formatted:a,parts:g(r,t.currency),payoutType:r.payoutType,minPurchaseAmount:s,lockupDurationDays:l,referrerReward:n.campaign.referrer,refereeReward:n.campaign.referee,minPurchaseValue:o??void 0,isProductScoped:n.campaign.productScope!=null,matchedProducts:n.matchedProducts}}export{v as i,L as n,R as r,_ as t};