@formspree/react
Advanced tools
Comparing version 2.4.0 to 2.4.1
@@ -25,3 +25,3 @@ import React from 'react'; | ||
*/ | ||
declare type ExtraDataValue = string | (() => string) | (() => Promise<string>) | (() => undefined) | (() => Promise<undefined>); | ||
declare type ExtraDataValue = undefined | string | (() => string) | (() => Promise<string>) | (() => undefined) | (() => Promise<undefined>); | ||
declare type ExtraData = { | ||
@@ -28,0 +28,0 @@ [key: string]: ExtraDataValue; |
@@ -1,1 +0,1 @@ | ||
var W=Object.create;var P=Object.defineProperty;var X=Object.getOwnPropertyDescriptor;var ee=Object.getOwnPropertyNames;var te=Object.getPrototypeOf,re=Object.prototype.hasOwnProperty;var oe=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),se=(e,t)=>{for(var r in t)P(e,r,{get:t[r],enumerable:!0})},N=(e,t,r,s)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of ee(t))!re.call(e,o)&&o!==r&&P(e,o,{get:()=>t[o],enumerable:!(s=X(t,o))||s.enumerable});return e};var b=(e,t,r)=>(r=e!=null?W(te(e)):{},N(t||!e||!e.__esModule?P(r,"default",{value:e,enumerable:!0}):r,e)),ne=e=>N(P({},"__esModule",{value:!0}),e);var T=oe((Re,K)=>{"use strict";var j=Object.defineProperty,ie=Object.getOwnPropertyDescriptor,ae=Object.getOwnPropertyNames,de=Object.prototype.hasOwnProperty,pe=(e,t)=>{for(var r in t)j(e,r,{get:t[r],enumerable:!0})},me=(e,t,r,s)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of ae(t))!de.call(e,o)&&o!==r&&j(e,o,{get:()=>t[o],enumerable:!(s=ie(t,o))||s.enumerable});return e},le=e=>me(j({},"__esModule",{value:!0}),e),V={};pe(V,{Client:()=>L,createClient:()=>k,getDefaultClient:()=>Pe,isFieldError:()=>Se});K.exports=le(V);var h="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",ce=/^(?:[A-Za-z\d+\/]{4})*?(?:[A-Za-z\d+\/]{2}(?:==)?|[A-Za-z\d+\/]{3}=?)?$/;function ue(e){e=String(e);for(var t,r,s,o,a="",c=0,l=e.length%3;c<e.length;){if((r=e.charCodeAt(c++))>255||(s=e.charCodeAt(c++))>255||(o=e.charCodeAt(c++))>255)throw new TypeError("Failed to execute 'btoa' on 'Window': The string to be encoded contains characters outside of the Latin1 range.");t=r<<16|s<<8|o,a+=h.charAt(t>>18&63)+h.charAt(t>>12&63)+h.charAt(t>>6&63)+h.charAt(t&63)}return l?a.slice(0,l-3)+"===".substring(l):a}function fe(e){if(e=String(e).replace(/[\t\n\f\r ]+/g,""),!ce.test(e))throw new TypeError("Failed to execute 'atob' on 'Window': The string to be decoded is not correctly encoded.");e+="==".slice(2-(e.length&3));for(var t,r="",s,o,a=0;a<e.length;)t=h.indexOf(e.charAt(a++))<<18|h.indexOf(e.charAt(a++))<<12|(s=h.indexOf(e.charAt(a++)))<<6|(o=h.indexOf(e.charAt(a++))),r+=s===64?String.fromCharCode(t>>16&255):o===64?String.fromCharCode(t>>16&255,t>>8&255):String.fromCharCode(t>>16&255,t>>8&255,t&255);return r}var ye="2.8.0",he=e=>ue(JSON.stringify(e)),Ee=e=>{let t=`@formspree/core@${ye}`;return e?`${e} ${t}`:t},ge=()=>1*new Date,S=(e,t,r)=>{e instanceof FormData?e.append(t,r):e=Object.assign(e,{[t]:r})},be=async({stripePromise:e,response:t,responseData:r,payload:s,data:o,fetchImpl:a,request:c,url:l})=>{let f=await e.handleCardAction(r.stripe.paymentIntentClientSecret);if(f.error)return{response:t,body:{errors:[{code:"STRIPE_CLIENT_ERROR",message:"Stripe SCA error",field:"paymentMethod"}]}};{s.paymentMethod.id||S(o,"paymentMethod",s.paymentMethod.id),S(o,"paymentIntent",f.paymentIntent.id),S(o,"resubmitKey",r.resubmitKey);let p=await a(l,{...c,body:JSON.stringify({paymentIntent:f.paymentIntent.id,resubmitKey:r.resubmitKey})}),u=await p.json();return{response:p,body:u}}},Fe=()=>navigator.webdriver||!!document.documentElement.getAttribute(fe("d2ViZHJpdmVy"))||!!window.callPhantom||!!window._phantom,xe=class{constructor(){this.loadedAt=ge(),this.webdriver=Fe()}teardown(){}data(){return{loadedAt:this.loadedAt,webdriver:this.webdriver}}},L=class{constructor(e={}){this.project=e.project,this.stripePromise=e.stripePromise,typeof window<"u"&&this.startBrowserSession()}startBrowserSession(){this.session||(this.session=new xe)}teardown(){this.session&&this.session.teardown()}async submitForm(e,t,r={}){let s=r.endpoint||"https://formspree.io",o=r.fetchImpl||fetch,a=this.project?`${s}/p/${this.project}/f/${e}`:`${s}/f/${e}`,c=p=>p instanceof FormData?p:JSON.stringify(p),l={Accept:"application/json","Formspree-Client":Ee(r.clientName)};this.session&&(l["Formspree-Session-Data"]=he(this.session.data())),t instanceof FormData||(l["Content-Type"]="application/json");let f={method:"POST",mode:"cors",body:c(t),headers:l};if(this.stripePromise&&r.createPaymentMethod){let p=await r.createPaymentMethod();if(p.error)return{response:null,body:{errors:[{code:"STRIPE_CLIENT_ERROR",message:"Error creating payment method",field:"paymentMethod"}]}};S(t,"paymentMethod",p.paymentMethod.id);let u=await o(a,{...f,body:t}),y=await u.json();return y&&y.stripe&&y.stripe.requiresAction&&y.resubmitKey?await be({stripePromise:this.stripePromise,responseData:y,response:u,payload:p,data:t,fetchImpl:o,request:f,url:a}):{response:u,body:y}}else return o(a,f).then(p=>p.json().then(u=>({body:u,response:p})))}},k=e=>new L(e),Pe=()=>(_||(_=k()),_),_,U=(e=>(e.REQUIRED_FIELD_MISSING="REQUIRED_FIELD_MISSING",e.REQUIRED_FIELD_EMPTY="REQUIRED_FIELD_EMPTY",e.TYPE_EMAIL="TYPE_EMAIL",e.TYPE_NUMERIC="TYPE_NUMERIC",e.TYPE_TEXT="TYPE_TEXT",e))(U||{});function Se(e){return e.code in U&&e.field!==void 0}});var _e={};se(_e,{CardElement:()=>E.CardElement,FormspreeProvider:()=>z,ValidationError:()=>Q,isFieldError:()=>Z.isFieldError,useForm:()=>H,useFormspree:()=>v});module.exports=ne(_e);var i=b(require("react")),w=b(T()),$=require("@stripe/stripe-js/pure.js"),we=(0,i.lazy)(()=>import("@stripe/react-stripe-js").then(e=>({default:e.Elements}))),R=i.default.createContext({client:void 0});R.displayName="Formspree";var I,ve=e=>(I||(I=(0,$.loadStripe)(e)),I),Y=(e,t)=>{let r={};return e&&(r.stripePromise=e),t&&(r.project=t),(0,w.createClient)(r)},z=e=>{let[t,r]=(0,i.useState)(void 0),[s,o]=(0,i.useState)(Y(t,e.project));return(0,i.useEffect)(()=>(s.startBrowserSession(),()=>{s.teardown()}),[]),(0,i.useEffect)(()=>{let a=async()=>{let c=await ve(e.stripePK);r(c)};e.stripePK&&a()},[e.stripePK]),(0,i.useEffect)(()=>{t&&o(Y(t,e.project))},[t]),i.default.createElement(R.Provider,{value:{client:s}},e.stripePK?i.default.createElement(i.default.Fragment,null,t&&i.default.createElement(i.Suspense,{fallback:i.default.createElement("p",null,"....")},i.default.createElement(we,{stripe:t},i.default.createElement(i.default.Fragment,null,e.children)))):i.default.createElement(i.default.Fragment,null,e.children))};function v(){let e=(0,i.useContext)(R);return e.client?e:{client:(0,w.getDefaultClient)()}}var F=require("react"),E=require("@stripe/react-stripe-js");var B="2.4.0";var De=e=>e.preventDefault!==void 0,H=(e,t={})=>{let[r,s]=(0,F.useState)(null),[o,a]=(0,F.useState)(!1),[c,l]=(0,F.useState)(!1),[f,p]=(0,F.useState)([]),u=v(),y=t.client||u,M,A;if(!y)throw new Error("You must provide a Formspree client");if(!e)throw new Error('You must provide a form key or hashid (e.g. useForm("myForm") or useForm("123xyz")');u.client&&u.client.stripePromise&&(M=(0,E.useStripe)(),A=(0,E.useElements)());let x=!!t.debug,g=t.data;return[{result:r,submitting:o,succeeded:c,errors:f},async C=>{let q=async n=>{n.preventDefault();let m=n.target;if(m.tagName!="FORM")throw new Error("submit was triggered for a non-form element");return new FormData(m)},d=De(C)?await q(C):C,O=(n,m)=>{d instanceof FormData?d.append(n,m):d=Object.assign(d,{[n]:m})};if(typeof g=="object")for(let n in g)if(typeof g[n]=="function"){let m=g[n].call(null);m instanceof Promise&&(m=await m),m!==void 0&&O(n,m)}else O(n,g[n]);let G=async()=>{let n={...d.address_line1&&{line1:d.address_line1},...d.address_line2&&{line2:d.address_line2},...d.address_city&&{city:d.address_city},...d.address_country&&{country:d.address_country},...d.address_state&&{state:d.address_state},...d.address_postal_code&&{postal_code:d.address_postal_code}};return await M.createPaymentMethod({type:"card",card:A.getElement(E.CardElement),billing_details:{...d.name&&{name:d.name},...d.email&&{email:d.email},...d.phone&&{phone:d.phone},...n&&{address:n}}})};return a(!0),u.client.submitForm(e,d,{endpoint:t.endpoint,clientName:`@formspree/react@${B}`,createPaymentMethod:u.client&&u.client.stripePromise?G:void 0}).then(n=>{let m=n.response.status,D;return m===200?(x&&console.log("Form submitted",n),l(!0),s(n),p([])):m>=400&&m<500?(D=n.body,D.errors&&p(D.errors),x&&console.log("Validation error",n),l(!1)):(x&&console.log("Unexpected error",n),l(!1)),n}).catch(n=>{throw x&&console.log("Unexpected error",n),l(!1),n}).finally(()=>{a(!1)})},()=>{a(!1),l(!1),p([])}]};var J=b(require("react")),Q=e=>{let{prefix:t,field:r,errors:s,...o}=e,a=(s||[]).find(c=>c.field===r);return a?J.default.createElement("div",{...o},t," ",a.message):null};var Z=b(T());0&&(module.exports={CardElement,FormspreeProvider,ValidationError,isFieldError,useForm,useFormspree}); | ||
var X=Object.create;var P=Object.defineProperty;var ee=Object.getOwnPropertyDescriptor;var te=Object.getOwnPropertyNames;var re=Object.getPrototypeOf,oe=Object.prototype.hasOwnProperty;var se=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),ne=(e,t)=>{for(var r in t)P(e,r,{get:t[r],enumerable:!0})},O=(e,t,r,s)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of te(t))!oe.call(e,o)&&o!==r&&P(e,o,{get:()=>t[o],enumerable:!(s=ee(t,o))||s.enumerable});return e};var b=(e,t,r)=>(r=e!=null?X(re(e)):{},O(t||!e||!e.__esModule?P(r,"default",{value:e,enumerable:!0}):r,e)),ie=e=>O(P({},"__esModule",{value:!0}),e);var T=se((Ae,K)=>{"use strict";var j=Object.defineProperty,ae=Object.getOwnPropertyDescriptor,de=Object.getOwnPropertyNames,pe=Object.prototype.hasOwnProperty,me=(e,t)=>{for(var r in t)j(e,r,{get:t[r],enumerable:!0})},le=(e,t,r,s)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of de(t))!pe.call(e,o)&&o!==r&&j(e,o,{get:()=>t[o],enumerable:!(s=ae(t,o))||s.enumerable});return e},ce=e=>le(j({},"__esModule",{value:!0}),e),U={};me(U,{Client:()=>Y,createClient:()=>k,getDefaultClient:()=>we,isFieldError:()=>Ee});K.exports=ce(U);var h="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",ue=/^(?:[A-Za-z\d+\/]{4})*?(?:[A-Za-z\d+\/]{2}(?:==)?|[A-Za-z\d+\/]{3}=?)?$/;function fe(e){e=String(e);for(var t,r,s,o,i="",l=0,c=e.length%3;l<e.length;){if((r=e.charCodeAt(l++))>255||(s=e.charCodeAt(l++))>255||(o=e.charCodeAt(l++))>255)throw new TypeError("Failed to execute 'btoa' on 'Window': The string to be encoded contains characters outside of the Latin1 range.");t=r<<16|s<<8|o,i+=h.charAt(t>>18&63)+h.charAt(t>>12&63)+h.charAt(t>>6&63)+h.charAt(t&63)}return c?i.slice(0,c-3)+"===".substring(c):i}function ye(e){if(e=String(e).replace(/[\t\n\f\r ]+/g,""),!ue.test(e))throw new TypeError("Failed to execute 'atob' on 'Window': The string to be decoded is not correctly encoded.");e+="==".slice(2-(e.length&3));for(var t,r="",s,o,i=0;i<e.length;)t=h.indexOf(e.charAt(i++))<<18|h.indexOf(e.charAt(i++))<<12|(s=h.indexOf(e.charAt(i++)))<<6|(o=h.indexOf(e.charAt(i++))),r+=s===64?String.fromCharCode(t>>16&255):o===64?String.fromCharCode(t>>16&255,t>>8&255):String.fromCharCode(t>>16&255,t>>8&255,t&255);return r}var he="2.8.1",L=(e=>(e.REQUIRED_FIELD_MISSING="REQUIRED_FIELD_MISSING",e.REQUIRED_FIELD_EMPTY="REQUIRED_FIELD_EMPTY",e.TYPE_EMAIL="TYPE_EMAIL",e.TYPE_NUMERIC="TYPE_NUMERIC",e.TYPE_TEXT="TYPE_TEXT",e))(L||{});function Ee(e){return e.code in L&&e.field!==void 0}function ge(e){return e.errors!==void 0}var be=e=>fe(JSON.stringify(e)),Fe=e=>{let t=`@formspree/core@${he}`;return e?`${e} ${t}`:t},xe=()=>1*new Date,S=(e,t,r)=>{e instanceof FormData?e.append(t,r):e=Object.assign(e,{[t]:r})},Pe=async({stripePromise:e,response:t,responseData:r,payload:s,data:o,fetchImpl:i,request:l,url:c})=>{let f=await e.handleCardAction(r.stripe.paymentIntentClientSecret);if(f.error)return{response:t,body:{errors:[{code:"STRIPE_CLIENT_ERROR",message:"Stripe SCA error",field:"paymentMethod"}]}};{s.paymentMethod.id||S(o,"paymentMethod",s.paymentMethod.id),S(o,"paymentIntent",f.paymentIntent.id),S(o,"resubmitKey",r.resubmitKey);let m=await i(c,{...l,body:JSON.stringify({paymentIntent:f.paymentIntent.id,resubmitKey:r.resubmitKey})}),u=await m.json();return{response:m,body:u}}};function N({body:e,response:t}){return!ge(e)&&(e==null?void 0:e.error)&&(e={errors:[{message:e.error}]}),{body:e,response:t}}var Se=()=>navigator.webdriver||!!document.documentElement.getAttribute(ye("d2ViZHJpdmVy"))||!!window.callPhantom||!!window._phantom,ve=class{constructor(){this.loadedAt=xe(),this.webdriver=Se()}teardown(){}data(){return{loadedAt:this.loadedAt,webdriver:this.webdriver}}},Y=class{constructor(e={}){this.project=e.project,this.stripePromise=e.stripePromise,typeof window<"u"&&this.startBrowserSession()}startBrowserSession(){this.session||(this.session=new ve)}teardown(){this.session&&this.session.teardown()}async submitForm(e,t,r={}){let s=r.endpoint||"https://formspree.io",o=r.fetchImpl||fetch,i=this.project?`${s}/p/${this.project}/f/${e}`:`${s}/f/${e}`,l=m=>m instanceof FormData?m:JSON.stringify(m),c={Accept:"application/json","Formspree-Client":Fe(r.clientName)};this.session&&(c["Formspree-Session-Data"]=be(this.session.data())),t instanceof FormData||(c["Content-Type"]="application/json");let f={method:"POST",mode:"cors",body:l(t),headers:c};if(this.stripePromise&&r.createPaymentMethod){let m=await r.createPaymentMethod();if(m.error)return{response:null,body:{errors:[{code:"STRIPE_CLIENT_ERROR",message:"Error creating payment method",field:"paymentMethod"}]}};S(t,"paymentMethod",m.paymentMethod.id);let u=await o(i,{...f,body:t}),y=await u.json();return y&&y.stripe&&y.stripe.requiresAction&&y.resubmitKey?await Pe({stripePromise:this.stripePromise,responseData:y,response:u,payload:m,data:t,fetchImpl:o,request:f,url:i}):N({response:u,body:y})}else return o(i,f).then(m=>m.json().then(u=>N({body:u,response:m}))).catch()}},k=e=>new Y(e),we=()=>(_||(_=k()),_),_});var Te={};ne(Te,{CardElement:()=>E.CardElement,FormspreeProvider:()=>z,ValidationError:()=>Q,isFieldError:()=>Z.isFieldError,useForm:()=>H,useFormspree:()=>w});module.exports=ie(Te);var n=b(require("react")),v=b(T()),$=require("@stripe/stripe-js/pure.js"),Ce=(0,n.lazy)(()=>import("@stripe/react-stripe-js").then(e=>({default:e.Elements}))),R=n.default.createContext({client:void 0});R.displayName="Formspree";var I,De=e=>(I||(I=(0,$.loadStripe)(e)),I),V=(e,t)=>{let r={};return e&&(r.stripePromise=e),t&&(r.project=t),(0,v.createClient)(r)},z=e=>{let[t,r]=(0,n.useState)(void 0),[s,o]=(0,n.useState)(V(t,e.project));return(0,n.useEffect)(()=>(s.startBrowserSession(),()=>{s.teardown()}),[]),(0,n.useEffect)(()=>{let i=async()=>{let l=await De(e.stripePK);r(l)};e.stripePK&&i()},[e.stripePK]),(0,n.useEffect)(()=>{t&&o(V(t,e.project))},[t]),n.default.createElement(R.Provider,{value:{client:s}},e.stripePK?n.default.createElement(n.default.Fragment,null,t&&n.default.createElement(n.Suspense,{fallback:n.default.createElement("p",null,"....")},n.default.createElement(Ce,{stripe:t},n.default.createElement(n.default.Fragment,null,e.children)))):n.default.createElement(n.default.Fragment,null,e.children))};function w(){let e=(0,n.useContext)(R);return e.client?e:{client:(0,v.getDefaultClient)()}}var F=require("react"),E=require("@stripe/react-stripe-js");var B="2.4.1";var je=e=>e.preventDefault!==void 0,H=(e,t={})=>{let[r,s]=(0,F.useState)(null),[o,i]=(0,F.useState)(!1),[l,c]=(0,F.useState)(!1),[f,m]=(0,F.useState)([]),u=w(),y=t.client||u,M,A;if(!y)throw new Error("You must provide a Formspree client");if(!e)throw new Error('You must provide a form key or hashid (e.g. useForm("myForm") or useForm("123xyz")');u.client&&u.client.stripePromise&&(M=(0,E.useStripe)(),A=(0,E.useElements)());let x=!!t.debug,g=t.data;return[{result:r,submitting:o,succeeded:l,errors:f},async C=>{let q=async a=>{a.preventDefault();let p=a.target;if(p.tagName!="FORM")throw new Error("submit was triggered for a non-form element");return new FormData(p)},d=je(C)?await q(C):C,G=(a,p)=>{d instanceof FormData?d.append(a,p):d=Object.assign(d,{[a]:p})};if(typeof g=="object")for(let a in g){let p;typeof g[a]=="function"?(p=g[a].call(null),typeof(p==null?void 0:p.then)=="function"&&(p=await p)):p=g[a],p!==void 0&&G(a,p)}let W=async()=>{let a={...d.address_line1&&{line1:d.address_line1},...d.address_line2&&{line2:d.address_line2},...d.address_city&&{city:d.address_city},...d.address_country&&{country:d.address_country},...d.address_state&&{state:d.address_state},...d.address_postal_code&&{postal_code:d.address_postal_code}};return await M.createPaymentMethod({type:"card",card:A.getElement(E.CardElement),billing_details:{...d.name&&{name:d.name},...d.email&&{email:d.email},...d.phone&&{phone:d.phone},...a&&{address:a}}})};return i(!0),u.client.submitForm(e,d,{endpoint:t.endpoint,clientName:`@formspree/react@${B}`,createPaymentMethod:u.client&&u.client.stripePromise?W:void 0}).then(a=>{let p=a.response.status,D;return p===200?(x&&console.log("Form submitted",a),c(!0),s(a),m([])):p>=400&&(D=a.body,D.errors?(m(D.errors),x&&console.log("Error",a)):(m([{message:"Unexpected error"}]),x&&console.log("Unexpected error",a)),c(!1)),a}).catch(a=>{throw x&&console.log("Unexpected error",a),c(!1),a}).finally(()=>{i(!1)})},()=>{i(!1),c(!1),m([])}]};var J=b(require("react")),Q=e=>{let{prefix:t,field:r,errors:s,...o}=e,i=(s||[]).find(l=>l.field===r);return i?J.default.createElement("div",{...o},t," ",i.message):null};var Z=b(T());0&&(module.exports={CardElement,FormspreeProvider,ValidationError,isFieldError,useForm,useFormspree}); |
{ | ||
"name": "@formspree/react", | ||
"version": "2.4.0", | ||
"version": "2.4.1", | ||
"description": "The React component library for Formspree", | ||
@@ -28,3 +28,3 @@ "private": false, | ||
"build": "tsup src/index.ts --format esm,cjs --dts --external react --minify", | ||
"dev": "tsup src/index.ts --format esm,cjs --watch --dts --external react --minify", | ||
"dev": "tsup src/index.ts --format esm,cjs --dts --external react --sourcemap", | ||
"clean": "rm -rf dist && rm -rf node_modules", | ||
@@ -31,0 +31,0 @@ "lint": "eslint src/*.ts*", |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
91767
8
120