@crossmint/client-sdk-base
Advanced tools
Comparing version 0.2.6-alpha.3 to 0.2.7-alpha.0
@@ -21,5 +21,5 @@ declare function generateClientId(): string; | ||
type theme = "light" | "dark"; | ||
type paymentMethods = "fiat" | "ETH" | "SOL"; | ||
declare const paymentMethodIsEth: (paymentMethod?: paymentMethods) => boolean; | ||
declare const paymentMethodIsSol: (paymentMethod?: paymentMethods) => boolean; | ||
type PaymentMethod = "fiat" | "ETH" | "SOL"; | ||
declare const paymentMethodIsEth: (paymentMethod?: PaymentMethod) => boolean; | ||
declare const paymentMethodIsSol: (paymentMethod?: PaymentMethod) => boolean; | ||
type SigninMethods = "metamask" | "solana"; | ||
@@ -69,3 +69,3 @@ declare enum mintingContractTypes { | ||
whPassThroughArgs?: any; | ||
paymentMethod?: paymentMethods; | ||
paymentMethod?: PaymentMethod; | ||
preferredSigninMethod?: SigninMethods; | ||
@@ -130,2 +130,95 @@ prepay?: boolean; | ||
interface CrossmintEventErrorPayload { | ||
error: { | ||
message: string; | ||
code: string; | ||
}; | ||
} | ||
declare enum PaymentEvents { | ||
PAYMENT_READY = "payment:ready", | ||
PAYMENT_QUOTE_CHANGED = "payment:quote-changed", | ||
PAYMENT_STARTED = "payment:started", | ||
PAYMENT_FAILED = "payment:failed", | ||
PAYMENT_COMPLETED = "payment:completed", | ||
PAYMENT_CANCELED = "payment:canceled", | ||
PAYMENT_REJECTED = "payment:rejected" | ||
} | ||
declare enum MintingEvents { | ||
MINTING_STARTED = "minting:started", | ||
MINTING_COMPLETED = "minting:completed", | ||
MINTING_FAILED = "minting:failed" | ||
} | ||
declare const CheckoutEvents: { | ||
MINTING_STARTED: MintingEvents.MINTING_STARTED; | ||
MINTING_COMPLETED: MintingEvents.MINTING_COMPLETED; | ||
MINTING_FAILED: MintingEvents.MINTING_FAILED; | ||
PAYMENT_READY: PaymentEvents.PAYMENT_READY; | ||
PAYMENT_QUOTE_CHANGED: PaymentEvents.PAYMENT_QUOTE_CHANGED; | ||
PAYMENT_STARTED: PaymentEvents.PAYMENT_STARTED; | ||
PAYMENT_FAILED: PaymentEvents.PAYMENT_FAILED; | ||
PAYMENT_COMPLETED: PaymentEvents.PAYMENT_COMPLETED; | ||
PAYMENT_CANCELED: PaymentEvents.PAYMENT_CANCELED; | ||
PAYMENT_REJECTED: PaymentEvents.PAYMENT_REJECTED; | ||
}; | ||
type CheckoutEvents = typeof CheckoutEvents; | ||
declare enum PaymentElementSDKEvents { | ||
PARAMS_UPDATE = "params-update" | ||
} | ||
type Recipient = { | ||
email?: string; | ||
wallet?: string; | ||
}; | ||
interface CrossmintCheckoutEvent<K extends keyof CheckoutEventMap> { | ||
type: K; | ||
payload: CheckoutEventMap[K]; | ||
} | ||
interface PaymentElement { | ||
clientId: string; | ||
mintArgs?: Record<string, any>; | ||
recipient?: Recipient; | ||
paymentMethod?: PaymentMethod; | ||
currency?: Currency; | ||
locale?: Locale; | ||
uiConfig?: UIConfig; | ||
environment?: string; | ||
onEvent?<K extends keyof CheckoutEventMap>(event: CrossmintCheckoutEvent<K>): this; | ||
} | ||
interface FiatPrice { | ||
amount: number; | ||
currency: Currency; | ||
} | ||
interface QuoteBreakdown { | ||
unitPrice: FiatPrice; | ||
totalGasFees?: FiatPrice; | ||
totalCrossmintFees: FiatPrice; | ||
} | ||
interface Quote { | ||
totalPrice: FiatPrice; | ||
priceBreakdown: QuoteBreakdown; | ||
} | ||
interface OrderItem { | ||
quoute: Quote; | ||
} | ||
interface PaymentPricePayload { | ||
items: OrderItem[]; | ||
totalQuote: Quote; | ||
} | ||
interface PaymentRejectedPayload extends CrossmintEventErrorPayload { | ||
orderIdentifier: string; | ||
} | ||
type PaymentStartedPayload = Record<string, never>; | ||
interface PaymentCompletedPayload { | ||
orderIdentifier: string; | ||
} | ||
type PaymentEventMap = { | ||
[CheckoutEvents.PAYMENT_READY]: PaymentPricePayload; | ||
[CheckoutEvents.PAYMENT_QUOTE_CHANGED]: PaymentPricePayload; | ||
[CheckoutEvents.PAYMENT_STARTED]: PaymentStartedPayload; | ||
[CheckoutEvents.PAYMENT_FAILED]: CrossmintEventErrorPayload; | ||
[CheckoutEvents.PAYMENT_COMPLETED]: PaymentCompletedPayload; | ||
[CheckoutEvents.PAYMENT_REJECTED]: PaymentRejectedPayload; | ||
}; | ||
type CheckoutEventMap = PaymentEventMap; | ||
interface CrossmintModalServiceParams { | ||
@@ -145,5 +238,5 @@ clientId: string; | ||
interface CrossmintModalServiceReturn { | ||
connect: (mintConfig: PayButtonConfig, mintTo?: string, emailTo?: string, listingId?: string, whPassThroughArgs?: any, paymentMethod?: paymentMethods, preferredSigninMethod?: SigninMethods, prepay?: boolean) => void; | ||
connect: (mintConfig: PayButtonConfig | PayButtonConfig[], mintTo?: string, emailTo?: string, listingId?: string, whPassThroughArgs?: any, paymentMethod?: PaymentMethod, preferredSigninMethod?: SigninMethods, prepay?: boolean) => void; | ||
} | ||
declare function crossmintModalService({ clientId, libVersion, showOverlay, dismissOverlayOnClick, setConnecting, environment, clientName, locale, currency, successCallbackURL, failureCallbackURL }: CrossmintModalServiceParams): CrossmintModalServiceReturn; | ||
declare function crossmintModalService({ clientId, libVersion, showOverlay, dismissOverlayOnClick, setConnecting, environment, clientName, locale, currency, successCallbackURL, failureCallbackURL, }: CrossmintModalServiceParams): CrossmintModalServiceReturn; | ||
@@ -153,3 +246,3 @@ interface IProps { | ||
connecting: boolean; | ||
paymentMethod?: paymentMethods; | ||
paymentMethod?: PaymentMethod; | ||
locale: Locale; | ||
@@ -188,2 +281,8 @@ } | ||
export { ALL_CHAINS, BaseButtonProps, Blockchain, CardanoNFT, CrossmintModalServiceReturn, CrossmintPayButtonProps, Currency, EVMChain, EVMNFT, EVM_CHAINS, Locale, NFT, NFTCollectionViewProps, NFTDetailProps, NFTLocator, OnboardingQueryParams, PayButtonConfig, SigninMethods, SolanaNFT, Wallet, assertValidNFTCollectionViewProps, assertValidValidateNFTDetailProps, baseUrls, clientNames, crossmintModalService, crossmintPayButtonService, crossmintStatusButtonService, crossmintStatusService, customHeaders, generateClientId, getEnvironmentBaseUrl, getNFTCollectionViewSrc, getNFTDetailSrc, mintingContractTypes, onboardingRequestStatusResponse, paymentMethodIsEth, paymentMethodIsSol, paymentMethods }; | ||
declare function crossmintPaymentService({ clientId, uiConfig, recipient, environment, mintArgs }: PaymentElement): { | ||
getIframeUrl: () => string; | ||
listenToEvents: (cb: <K extends keyof PaymentEventMap>(event: MessageEvent<CrossmintCheckoutEvent<K>>) => void) => void; | ||
emitQueryParams: (payload: Partial<Record<keyof Omit<PaymentElement, "onEvent" | "environment">, any>>) => void; | ||
}; | ||
export { ALL_CHAINS, BaseButtonProps, Blockchain, CardanoNFT, CheckoutEventMap, CheckoutEvents, CrossmintCheckoutEvent, CrossmintEventErrorPayload, CrossmintModalServiceReturn, CrossmintPayButtonProps, Currency, EVMChain, EVMNFT, EVM_CHAINS, FiatPrice, Locale, MintingEvents, NFT, NFTCollectionViewProps, NFTDetailProps, NFTLocator, OnboardingQueryParams, PayButtonConfig, PaymentElement, PaymentElementSDKEvents, PaymentEventMap, PaymentEvents, PaymentMethod, Recipient, SigninMethods, SolanaNFT, UIConfig, Wallet, assertValidNFTCollectionViewProps, assertValidValidateNFTDetailProps, baseUrls, clientNames, crossmintModalService, crossmintPayButtonService, crossmintPaymentService, crossmintStatusButtonService, crossmintStatusService, customHeaders, generateClientId, getEnvironmentBaseUrl, getNFTCollectionViewSrc, getNFTDetailSrc, mintingContractTypes, onboardingRequestStatusResponse, paymentMethodIsEth, paymentMethodIsSol }; |
@@ -1,1 +0,1 @@ | ||
import{v4 as O}from"uuid";function et(){return O()}function ot({wallets:t}){if(t.length===0)throw new Error("wallets prop is empty. Please provide at least one wallet.")}function rt({nft:t}){if(t==null)throw new Error("nft prop is empty. Please provide a valid nft.")}var _=["ethereum","polygon","bsc"],st=["solana","cardano",..._],A=(o=>(o.reactUi="client-sdk-react-ui",o.vanillaUi="client-sdk-vanilla-ui",o))(A||{}),X=(n=>(n.prod="https://www.crossmint.com",n.staging="https://staging.crossmint.com",n.dev="http://localhost:3001",n))(X||{}),k=(o=>(o.clientVersion="X-Client-Version",o.clientName="X-Client-Name",o))(k||{}),at=t=>t==="ETH",ct=t=>t==="SOL",F=(n=>(n.CANDY_MACHINE="candy-machine",n.SOLANA_AUCTION="solana-auction",n.ERC_721="erc-721",n))(F||{}),V=(r=>(r.WAITING_SUBMISSION="waiting-submission",r.PENDING="pending",r.REJECTED="rejected",r.ACCEPTED="accepted",r.INVALID="invalid",r))(V||{});var g=(t="")=>{let e=["prod","production"];return t==="staging"?"https://staging.crossmint.com":e.includes(t)||!t?"https://www.crossmint.com":t};function R(t){if(typeof t=="string")return t;switch(t.chain){case"solana":return`${t.chain}:${t.mintHash}`;case"polygon":case"ethereum":case"bsc":return`${t.chain}:${t.contractAddress}:${t.tokenId}`;case"cardano":return`${t.chain}:${t.assetId}`;default:throw new Error(`Invalid chain type ${JSON.stringify(t)}`)}}function ut(t,e){let o=g(t.environment),{wallets:n}=t,i=JSON.stringify(n),r=new URLSearchParams({wallets:i,clientVersion:e,...t.uiConfig!=null?{uiConfig:JSON.stringify(t.uiConfig)}:{}});return`${o}/sdk/wallets/collection?${r.toString()}`}function dt(t,e){let o=g(t.environment),n=new URLSearchParams({clientVersion:e,...t.uiConfig!=null?{uiConfig:JSON.stringify(t.uiConfig)}:{}}),i=R(t.nft);return`${o}/sdk/wallets/tokens/${i}?${n.toString()}`}var M="__crossmint-overlay__",H=400,$=750,W=()=>{let t=navigator.userAgent.match(/Chrom(e|ium)\/([0-9]+)\./);return t?parseInt(t[2]):null};function G(t,e){function o(){return(window==null?void 0:window.top)!=null?window.top.outerWidth/2+window.top.screenX-t/2:window.outerWidth/2+window.screenX-t/2}function n(){return(window==null?void 0:window.top)!=null?window.top.outerHeight/2+window.top.screenY-e/2:window.outerHeight/2+window.screenY-e/2}let i=W();return`${i&&i>99?"popup=true,":""}height=${e},width=${t},left=${o()},top=${n()},resizable=yes,scrollbars=yes,toolbar=yes,menubar=true,location=no,directories=no, status=yes`}var Y=t=>{let e=document.createElement("div");e.setAttribute("id",M);let o={width:"100vw",height:"100vh","background-color":"rgba(0, 0, 0, 0.5)",position:"fixed","z-index":"99999999",top:"0",left:"0"};Object.assign(e.style,o),document.body.appendChild(e),t&&e.addEventListener("click",()=>{U()})},U=()=>{let t=document.getElementById(M);t&&t.remove()};function gt({clientId:t,libVersion:e,showOverlay:o,dismissOverlayOnClick:n,setConnecting:i,environment:r,clientName:p,locale:s,currency:m,successCallbackURL:C,failureCallbackURL:S}){let c=(y,f,I,N,T,P,w,E)=>{let B=g(r),D=encodeURIComponent(`${B}/checkout/mint?${(()=>{let l={clientId:t,clientName:p,clientVersion:e,mintConfig:JSON.stringify(y),locale:s,currency:m};return f&&(l.mintTo=f),I&&(l.emailTo=I),N&&(l.listingId=N),T&&(l.whPassThroughArgs=JSON.stringify(T)),P&&(l.paymentMethod=P.toLowerCase()),w&&(l.preferredSigninMethod=w),E&&(l.prepay="true"),C&&(l.successCallbackURL=C),S&&(l.failureCallbackURL=S),new URLSearchParams(l).toString()})()}`),x=`${B}/signin?callbackUrl=${D}&locale=${s}¤cy=${m}`,L=window.open(x,"popUpWindow",G(H,$));if(L){v(L),o&&Y(n);return}i(!1),window.open(x,"_blank")||console.error("Failed to open popup window and new tab")},h=(y,f,I,N,T,P,w,E)=>{i(!0),c(y,f,I,N,T,P,w,E)};function v(y){let f=setInterval(function(){y.closed&&(clearInterval(f),i(!1),o&&U())},500)}return{connect:h}}var J={crossmintPayButtonService:{CONNECTING:"Connecting...",BUY_WITH_ETH:"Buy with ETH",BUY_WITH_SOL:"Buy with SOL",BUY_WITH_CREDIT_CARD:"Buy with credit card"},crossmintStatusButtonService:{INVALID:"Invalid clientId",WAITING_SUBMISSION:"Click here to setup Crossmint",PENDING:"Your application is under review",ACCEPTED:"You're good to go!",REJECTED:"Your application was rejected"}},Q={crossmintPayButtonService:{CONNECTING:"Conectando...",BUY_WITH_ETH:"Comprar con ETH",BUY_WITH_SOL:"Comprar con SOL",BUY_WITH_CREDIT_CARD:"Comprar con tarjeta de cr\xE9dito"},crossmintStatusButtonService:{INVALID:"clientId inv\xE1lido",WAITING_SUBMISSION:"Haga clic aqu\xED para configurar Crossmint",PENDING:"Su solicitud est\xE1 en revisi\xF3n",ACCEPTED:"\xA1Est\xE1 listo para usar Crossmint!",REJECTED:"Su solicitud fue rechazada"}},q={"en-US":J,"es-ES":Q};function a(t,e){let o=q[e];return t.split(".").reduce((n,i)=>n[i],o)}function St({onClick:t,connecting:e,paymentMethod:o,locale:n}){return{getButtonText:s=>{if(s)return a("crossmintPayButtonService.CONNECTING",n);switch(o){case"ETH":return a("crossmintPayButtonService.BUY_WITH_ETH",n);case"SOL":return a("crossmintPayButtonService.BUY_WITH_SOL",n);default:return a("crossmintPayButtonService.BUY_WITH_CREDIT_CARD",n)}},shouldHideButton:({hideMintOnInactiveClient:s,status:m})=>s&&m!=="accepted",handleClick:(s,m)=>{t&&t(s),!e&&(s.defaultPrevented||m())}}}var K=/^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000)$/i;function b(t){return typeof t=="string"&&K.test(t)}var j=t=>{try{return b(t)}catch(e){return console.error(e),!1}};function Pt({libVersion:t,clientId:e,platformId:o,auctionId:n,mintConfig:i,setStatus:r,environment:p,clientName:s}){async function m(){if(!e||e===""||e==="<YOUR_CLIENT_ID>"){console.error("You must enter your own Crossmint client ID in <CrossmintPayButton clientId=XXX>");return}if(!j(e)){console.error("The clientId passed to is invalid. Make sure to pass the clientId obtained from the crossmint team, with format XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXX");return}let c=g(p),h=await fetch(`${c}/api/crossmint/onboardingRequests/${e}/status`,{headers:{["X-Client-Version"]:t,["X-Client-Name"]:s}});if(h.status===200){let v=await h.json();r(v.status)}else r("invalid")}let C=()=>{let c=g(p);window.open(`${c}/developers/onboarding?${S()}`,"_blank")},S=()=>{let c={clientId:e};return o&&(c.platformId=o),n&&(c.auctionId=n),i&&(c.mintConfig=JSON.stringify(i)),new URLSearchParams(c).toString()};return{fetchClientIntegration:m,goToOnboarding:C}}function Et({onClick:t,locale:e}){return{getButtonText:r=>{switch(r){case"invalid":return a("crossmintStatusButtonService.INVALID",e);case"waiting-submission":return a("crossmintStatusButtonService.WAITING_SUBMISSION",e);case"pending":return a("crossmintStatusButtonService.PENDING",e);case"accepted":return a("crossmintStatusButtonService.ACCEPTED",e);case"rejected":return a("crossmintStatusButtonService.REJECTED",e)}},isButtonDisabled:r=>r!=="waiting-submission",handleClick:(r,p,s)=>{t&&t(r),p==="waiting-submission"&&s()}}}export{st as ALL_CHAINS,_ as EVM_CHAINS,ot as assertValidNFTCollectionViewProps,rt as assertValidValidateNFTDetailProps,X as baseUrls,A as clientNames,gt as crossmintModalService,St as crossmintPayButtonService,Et as crossmintStatusButtonService,Pt as crossmintStatusService,k as customHeaders,et as generateClientId,g as getEnvironmentBaseUrl,ut as getNFTCollectionViewSrc,dt as getNFTDetailSrc,F as mintingContractTypes,V as onboardingRequestStatusResponse,at as paymentMethodIsEth,ct as paymentMethodIsSol}; | ||
import{v4 as O}from"uuid";function rt(){return O()}function st({wallets:t}){if(t.length===0)throw new Error("wallets prop is empty. Please provide at least one wallet.")}function at({nft:t}){if(t==null)throw new Error("nft prop is empty. Please provide a valid nft.")}var k=["ethereum","polygon","bsc"],lt=["solana","cardano",...k],R=(o=>(o.reactUi="client-sdk-react-ui",o.vanillaUi="client-sdk-vanilla-ui",o))(R||{}),F=(n=>(n.prod="https://www.crossmint.com",n.staging="https://staging.crossmint.com",n.dev="http://localhost:3001",n))(F||{}),X=(o=>(o.clientVersion="X-Client-Version",o.clientName="X-Client-Name",o))(X||{}),ut=t=>t==="ETH",mt=t=>t==="SOL",H=(n=>(n.CANDY_MACHINE="candy-machine",n.SOLANA_AUCTION="solana-auction",n.ERC_721="erc-721",n))(H||{}),V=(r=>(r.WAITING_SUBMISSION="waiting-submission",r.PENDING="pending",r.REJECTED="rejected",r.ACCEPTED="accepted",r.INVALID="invalid",r))(V||{});var y=(t="")=>{let e=["prod","production"];return t==="staging"?"https://staging.crossmint.com":e.includes(t)||!t?"https://www.crossmint.com":t};function $(t){if(typeof t=="string")return t;switch(t.chain){case"solana":return`${t.chain}:${t.mintHash}`;case"polygon":case"ethereum":case"bsc":return`${t.chain}:${t.contractAddress}:${t.tokenId}`;case"cardano":return`${t.chain}:${t.assetId}`;default:throw new Error(`Invalid chain type ${JSON.stringify(t)}`)}}function pt(t,e){let o=y(t.environment),{wallets:n}=t,s=JSON.stringify(n),r=new URLSearchParams({wallets:s,clientVersion:e,...t.uiConfig!=null?{uiConfig:JSON.stringify(t.uiConfig)}:{}});return`${o}/sdk/wallets/collection?${r.toString()}`}function gt(t,e){let o=y(t.environment),n=new URLSearchParams({clientVersion:e,...t.uiConfig!=null?{uiConfig:JSON.stringify(t.uiConfig)}:{}}),s=$(t.nft);return`${o}/sdk/wallets/tokens/${s}?${n.toString()}`}var L=(i=>(i.PAYMENT_READY="payment:ready",i.PAYMENT_QUOTE_CHANGED="payment:quote-changed",i.PAYMENT_STARTED="payment:started",i.PAYMENT_FAILED="payment:failed",i.PAYMENT_COMPLETED="payment:completed",i.PAYMENT_CANCELED="payment:canceled",i.PAYMENT_REJECTED="payment:rejected",i))(L||{}),A=(n=>(n.MINTING_STARTED="minting:started",n.MINTING_COMPLETED="minting:completed",n.MINTING_FAILED="minting:failed",n))(A||{}),yt={...L,...A},Y=(e=>(e.PARAMS_UPDATE="params-update",e))(Y||{});var D="__crossmint-overlay__",W=400,G=750,J=()=>{let t=navigator.userAgent.match(/Chrom(e|ium)\/([0-9]+)\./);return t?parseInt(t[2]):null};function Q(t,e){function o(){return(window==null?void 0:window.top)!=null?window.top.outerWidth/2+window.top.screenX-t/2:window.outerWidth/2+window.screenX-t/2}function n(){return(window==null?void 0:window.top)!=null?window.top.outerHeight/2+window.top.screenY-e/2:window.outerHeight/2+window.screenY-e/2}let s=J();return`${s&&s>99?"popup=true,":""}height=${e},width=${t},left=${o()},top=${n()},resizable=yes,scrollbars=yes,toolbar=yes,menubar=true,location=no,directories=no, status=yes`}var K=t=>{let e=document.createElement("div");e.setAttribute("id",D);let o={width:"100vw",height:"100vh","background-color":"rgba(0, 0, 0, 0.5)",position:"fixed","z-index":"99999999",top:"0",left:"0"};Object.assign(e.style,o),document.body.appendChild(e),t&&e.addEventListener("click",()=>{U()})},U=()=>{let t=document.getElementById(D);t&&t.remove()};function ht({clientId:t,libVersion:e,showOverlay:o,dismissOverlayOnClick:n,setConnecting:s,environment:r,clientName:p,locale:i,currency:g,successCallbackURL:a,failureCallbackURL:m}){let c=(I,C,S,h,N,P,E,w)=>{let B=y(r),_=encodeURIComponent(`${B}/checkout/mint?${(()=>{let f={clientId:t,clientName:p,clientVersion:e,mintConfig:JSON.stringify(I),locale:i,currency:g};return C&&(f.mintTo=C),S&&(f.emailTo=S),h&&(f.listingId=h),N&&(f.whPassThroughArgs=JSON.stringify(N)),P&&(f.paymentMethod=P.toLowerCase()),E&&(f.preferredSigninMethod=E),w&&(f.prepay="true"),a&&(f.successCallbackURL=a),m&&(f.failureCallbackURL=m),new URLSearchParams(f).toString()})()}`),M=`${B}/signin?callbackUrl=${_}&locale=${i}¤cy=${g}`,b=window.open(M,"popUpWindow",Q(W,G));if(b){v(b),o&&K(n);return}s(!1),window.open(M,"_blank")||console.error("Failed to open popup window and new tab")},T=(I,C,S,h,N,P,E,w)=>{s(!0),c(I,C,S,h,N,P,E,w)};function v(I){function C(h){h.origin,y(r)}let S=setInterval(function(){I.closed&&(clearInterval(S),s(!1),o&&U(),window.removeEventListener("message",C))},500);window.addEventListener("message",C)}return{connect:T}}var q={crossmintPayButtonService:{CONNECTING:"Connecting...",BUY_WITH_ETH:"Buy with ETH",BUY_WITH_SOL:"Buy with SOL",BUY_WITH_CREDIT_CARD:"Buy with credit card"},crossmintStatusButtonService:{INVALID:"Invalid clientId",WAITING_SUBMISSION:"Click here to setup Crossmint",PENDING:"Your application is under review",ACCEPTED:"You're good to go!",REJECTED:"Your application was rejected"}},j={crossmintPayButtonService:{CONNECTING:"Conectando...",BUY_WITH_ETH:"Comprar con ETH",BUY_WITH_SOL:"Comprar con SOL",BUY_WITH_CREDIT_CARD:"Comprar con tarjeta de cr\xE9dito"},crossmintStatusButtonService:{INVALID:"clientId inv\xE1lido",WAITING_SUBMISSION:"Haga clic aqu\xED para configurar Crossmint",PENDING:"Su solicitud est\xE1 en revisi\xF3n",ACCEPTED:"\xA1Est\xE1 listo para usar Crossmint!",REJECTED:"Su solicitud fue rechazada"}},z={"en-US":q,"es-ES":j};function d(t,e){let o=z[e];return t.split(".").reduce((n,s)=>n[s],o)}function Pt({onClick:t,connecting:e,paymentMethod:o,locale:n}){return{getButtonText:i=>{if(i)return d("crossmintPayButtonService.CONNECTING",n);switch(o){case"ETH":return d("crossmintPayButtonService.BUY_WITH_ETH",n);case"SOL":return d("crossmintPayButtonService.BUY_WITH_SOL",n);default:return d("crossmintPayButtonService.BUY_WITH_CREDIT_CARD",n)}},shouldHideButton:({hideMintOnInactiveClient:i,status:g})=>i&&g!=="accepted",handleClick:(i,g)=>{t&&t(i),!e&&(i.defaultPrevented||g())}}}var Z=/^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000)$/i;function x(t){return typeof t=="string"&&Z.test(t)}var tt=t=>{try{return x(t)}catch(e){return console.error(e),!1}};function Bt({libVersion:t,clientId:e,platformId:o,auctionId:n,mintConfig:s,setStatus:r,environment:p,clientName:i}){async function g(){if(!e||e===""||e==="<YOUR_CLIENT_ID>"){console.error("You must enter your own Crossmint client ID in <CrossmintPayButton clientId=XXX>");return}if(!tt(e)){console.error("The clientId passed to is invalid. Make sure to pass the clientId obtained from the crossmint team, with format XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXX");return}let c=y(p),T=await fetch(`${c}/api/crossmint/onboardingRequests/${e}/status`,{headers:{["X-Client-Version"]:t,["X-Client-Name"]:i}});if(T.status===200){let v=await T.json();r(v.status)}else r("invalid")}let a=()=>{let c=y(p);window.open(`${c}/developers/onboarding?${m()}`,"_blank")},m=()=>{let c={clientId:e};return o&&(c.platformId=o),n&&(c.auctionId=n),s&&(c.mintConfig=JSON.stringify(s)),new URLSearchParams(c).toString()};return{fetchClientIntegration:g,goToOnboarding:a}}function Lt({onClick:t,locale:e}){return{getButtonText:r=>{switch(r){case"invalid":return d("crossmintStatusButtonService.INVALID",e);case"waiting-submission":return d("crossmintStatusButtonService.WAITING_SUBMISSION",e);case"pending":return d("crossmintStatusButtonService.PENDING",e);case"accepted":return d("crossmintStatusButtonService.ACCEPTED",e);case"rejected":return d("crossmintStatusButtonService.REJECTED",e)}},isButtonDisabled:r=>r!=="waiting-submission",handleClick:(r,p,i)=>{t&&t(r),p==="waiting-submission"&&i()}}}function Ut({clientId:t,uiConfig:e,recipient:o,environment:n,mintArgs:s}){let r=y(n);function p(){let a=new URLSearchParams({clientId:t});return e!=null&&a.append("uiConfig",JSON.stringify(e)),o!=null&&a.append("recipient",JSON.stringify(o)),s!=null&&a.append("mintArgs",JSON.stringify(s)),`${r}/sdk/paymentElement?${a.toString()}`}function i(a){window.addEventListener("message",m=>{m.origin===r&&a(m)})}function g(a){var c;let m=document.getElementById("iframe-crossmint-payment-element");(c=m==null?void 0:m.contentWindow)==null||c.postMessage({type:"params-update",payload:a},r)}return{getIframeUrl:p,listenToEvents:i,emitQueryParams:g}}export{lt as ALL_CHAINS,yt as CheckoutEvents,k as EVM_CHAINS,A as MintingEvents,Y as PaymentElementSDKEvents,L as PaymentEvents,st as assertValidNFTCollectionViewProps,at as assertValidValidateNFTDetailProps,F as baseUrls,R as clientNames,ht as crossmintModalService,Pt as crossmintPayButtonService,Ut as crossmintPaymentService,Lt as crossmintStatusButtonService,Bt as crossmintStatusService,X as customHeaders,rt as generateClientId,y as getEnvironmentBaseUrl,pt as getNFTCollectionViewSrc,gt as getNFTDetailSrc,H as mintingContractTypes,V as onboardingRequestStatusResponse,ut as paymentMethodIsEth,mt as paymentMethodIsSol}; |
{ | ||
"name": "@crossmint/client-sdk-base", | ||
"version": "0.2.6-alpha.3", | ||
"version": "0.2.7-alpha.0", | ||
"author": "Paella Labs Inc", | ||
@@ -34,3 +34,3 @@ "license": "Apache-2.0", | ||
}, | ||
"gitHead": "f272561d0f5611a07a0cc97f53419e0bd23d6ac9" | ||
"gitHead": "9782fa54edd6122df1737eb3f6d36ab65dec4186" | ||
} |
export * from "./utils/index"; | ||
export * from "./models/types"; | ||
export * from "./models/paymentElement"; | ||
export * from "./models/events"; | ||
export * from "./services/crossmintModalService"; | ||
@@ -7,1 +9,2 @@ export * from "./services/crossmintPayButtonService"; | ||
export * from "./services/crossmintStatusButtonService"; | ||
export * from "./services/crossmintPaymentService"; |
@@ -0,1 +1,3 @@ | ||
import { CheckoutEvents } from "./events"; | ||
export const EVM_CHAINS = ["ethereum", "polygon", "bsc"] as const; | ||
@@ -24,5 +26,5 @@ export const ALL_CHAINS = ["solana", "cardano", ...EVM_CHAINS] as const; | ||
export type paymentMethods = "fiat" | "ETH" | "SOL"; | ||
export const paymentMethodIsEth = (paymentMethod?: paymentMethods) => paymentMethod === "ETH"; | ||
export const paymentMethodIsSol = (paymentMethod?: paymentMethods) => paymentMethod === "SOL"; | ||
export type PaymentMethod = "fiat" | "ETH" | "SOL"; | ||
export const paymentMethodIsEth = (paymentMethod?: PaymentMethod) => paymentMethod === "ETH"; | ||
export const paymentMethodIsSol = (paymentMethod?: PaymentMethod) => paymentMethod === "SOL"; | ||
@@ -56,3 +58,3 @@ export type SigninMethods = "metamask" | "solana"; | ||
export type Locale = "en-US" | "es-ES"; | ||
export type Currency = "USD" | "EUR" | "GBP" | "AUD" | "SGD" | "HKD" | "CAD" | "CHF" | "CNY" | "JPY" | "KRW" | "NZD" | ||
export type Currency = "USD" | "EUR" | "GBP" | "AUD" | "SGD" | "HKD" | "CAD" | "CHF" | "CNY" | "JPY" | "KRW" | "NZD"; | ||
@@ -82,3 +84,3 @@ export interface BaseButtonProps { | ||
whPassThroughArgs?: any; | ||
paymentMethod?: paymentMethods; | ||
paymentMethod?: PaymentMethod; | ||
preferredSigninMethod?: SigninMethods; | ||
@@ -88,2 +90,4 @@ prepay?: boolean; | ||
failureCallbackURL?: string; | ||
// TODO: Enable when events are ready in crossbit-main and docs are updated | ||
// onEvent?: (event: CheckoutEvents, metadata?: Record<string, any>) => void; | ||
} | ||
@@ -112,3 +116,3 @@ | ||
interface UIConfig { | ||
export interface UIConfig { | ||
colors?: Colors; | ||
@@ -115,0 +119,0 @@ } |
@@ -1,2 +0,3 @@ | ||
import { PayButtonConfig, SigninMethods, clientNames, paymentMethods, Locale, Currency } from "../models/types"; | ||
import { CheckoutEvents } from "../models/events"; | ||
import { Currency, Locale, PayButtonConfig, PaymentMethod, SigninMethods, clientNames } from "../models/types"; | ||
import { getEnvironmentBaseUrl } from "../utils/ui"; | ||
@@ -13,3 +14,3 @@ | ||
whPassThroughArgs?: string; | ||
paymentMethod?: paymentMethods; | ||
paymentMethod?: PaymentMethod; | ||
preferredSigninMethod?: SigninMethods; | ||
@@ -19,3 +20,3 @@ prepay?: string; | ||
currency: Currency; | ||
successCallbackURL? : string; | ||
successCallbackURL?: string; | ||
failureCallbackURL?: string; | ||
@@ -92,4 +93,6 @@ }; | ||
currency: Currency; | ||
successCallbackURL? : string; | ||
successCallbackURL?: string; | ||
failureCallbackURL?: string; | ||
// TODO: Enable when events are ready in crossbit-main and docs are updated | ||
// onEvent?: (event: CheckoutEvents, metadata?: any) => void; | ||
} | ||
@@ -99,3 +102,3 @@ | ||
connect: ( | ||
mintConfig: PayButtonConfig, | ||
mintConfig: PayButtonConfig | PayButtonConfig[], | ||
mintTo?: string, | ||
@@ -105,5 +108,5 @@ emailTo?: string, | ||
whPassThroughArgs?: any, | ||
paymentMethod?: paymentMethods, | ||
paymentMethod?: PaymentMethod, | ||
preferredSigninMethod?: SigninMethods, | ||
prepay?: boolean, | ||
prepay?: boolean | ||
) => void; | ||
@@ -113,16 +116,16 @@ } | ||
export function crossmintModalService({ | ||
clientId, | ||
libVersion, | ||
showOverlay, | ||
dismissOverlayOnClick, | ||
setConnecting, | ||
environment, | ||
clientName, | ||
locale, | ||
currency, | ||
successCallbackURL, | ||
failureCallbackURL | ||
}: CrossmintModalServiceParams): CrossmintModalServiceReturn { | ||
clientId, | ||
libVersion, | ||
showOverlay, | ||
dismissOverlayOnClick, | ||
setConnecting, | ||
environment, | ||
clientName, | ||
locale, | ||
currency, | ||
successCallbackURL, | ||
failureCallbackURL, | ||
}: CrossmintModalServiceParams): CrossmintModalServiceReturn { | ||
const createPopup = ( | ||
mintConfig: PayButtonConfig, | ||
mintConfig: PayButtonConfig | PayButtonConfig[], | ||
mintTo?: string, | ||
@@ -132,5 +135,5 @@ emailTo?: string, | ||
whPassThroughArgs?: any, | ||
paymentMethod?: paymentMethods, | ||
paymentMethod?: PaymentMethod, | ||
preferredSigninMethod?: SigninMethods, | ||
prepay?: boolean, | ||
prepay?: boolean | ||
) => { | ||
@@ -152,3 +155,3 @@ const urlOrigin = getEnvironmentBaseUrl(environment); | ||
if (whPassThroughArgs) mintQueryParams.whPassThroughArgs = JSON.stringify(whPassThroughArgs); | ||
if (paymentMethod) mintQueryParams.paymentMethod = paymentMethod.toLowerCase() as paymentMethods; | ||
if (paymentMethod) mintQueryParams.paymentMethod = paymentMethod.toLowerCase() as PaymentMethod; | ||
if (preferredSigninMethod) mintQueryParams.preferredSigninMethod = preferredSigninMethod; | ||
@@ -180,3 +183,3 @@ if (prepay) mintQueryParams.prepay = "true"; | ||
const connect = ( | ||
mintConfig: PayButtonConfig, | ||
mintConfig: PayButtonConfig | PayButtonConfig[], | ||
mintTo?: string, | ||
@@ -186,5 +189,5 @@ emailTo?: string, | ||
whPassThroughArgs?: any, | ||
paymentMethod?: paymentMethods, | ||
paymentMethod?: PaymentMethod, | ||
preferredSigninMethod?: SigninMethods, | ||
prepay?: boolean, | ||
prepay?: boolean | ||
) => { | ||
@@ -201,3 +204,3 @@ setConnecting(true); | ||
preferredSigninMethod, | ||
prepay, | ||
prepay | ||
); | ||
@@ -207,3 +210,14 @@ }; | ||
function registerListeners(pop: Window) { | ||
const timer = setInterval(function() { | ||
function messageEventListener(message: MessageEvent<any>) { | ||
if (message.origin !== getEnvironmentBaseUrl(environment)) { | ||
return; | ||
} | ||
// TODO: Enable when events are ready in crossbit-main and docs are updated | ||
/* if (onEvent != null) { | ||
onEvent(message.data.name, message.data); | ||
} */ | ||
} | ||
const timer = setInterval(function () { | ||
if (pop.closed) { | ||
@@ -215,4 +229,7 @@ clearInterval(timer); | ||
} | ||
window.removeEventListener("message", messageEventListener); | ||
} | ||
}, 500); | ||
window.addEventListener("message", messageEventListener); | ||
} | ||
@@ -219,0 +236,0 @@ |
@@ -1,2 +0,2 @@ | ||
import { Locale, onboardingRequestStatusResponse, paymentMethods } from "../models/types"; | ||
import { Locale, PaymentMethod, onboardingRequestStatusResponse } from "../models/types"; | ||
import { t } from "../utils/i18n"; | ||
@@ -7,3 +7,3 @@ | ||
connecting: boolean; | ||
paymentMethod?: paymentMethods; | ||
paymentMethod?: PaymentMethod; | ||
locale: Locale; | ||
@@ -10,0 +10,0 @@ } |
Sorry, the diff of this file is not supported yet
68391
21
1120