sanity-plugin-dashboard-widget-vercel 2.0.1 → 3.0.0
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/LICENSE +1 -1
- package/lib/index.d.ts +6 -0
- package/lib/index.js +980 -1
- package/lib/index.js.map +1 -1
- package/lib/index.mjs +980 -0
- package/lib/index.mjs.map +1 -0
- package/package.json +26 -27
- package/src/app.tsx +1 -2
- package/src/components/Deployments/index.tsx +1 -1
- package/src/components/DialogForm/index.tsx +2 -0
- package/src/components/FormFieldInputLabel/index.tsx +2 -1
- package/src/components/FormFieldInputText/index.tsx +1 -0
- package/lib/index.esm.js +0 -2
- package/lib/index.esm.js.map +0 -1
- /package/lib/{src/index.d.ts → index.d.mts} +0 -0
package/lib/index.js
CHANGED
|
@@ -1,2 +1,981 @@
|
|
|
1
|
-
"use strict";var e;function t(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function r(e){for(var r=1;r<arguments.length;r++){var o=null!=arguments[r]?arguments[r]:{};r%2?t(Object(o),!0).forEach((function(t){n(e,t,o[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(o)):t(Object(o)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(o,t))}))}return e}function n(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}Object.defineProperty(exports,"__esModule",{value:!0});var o=require("react/jsx-runtime"),a=require("@sanity/icons"),s=require("@sanity/ui"),i=require("@xstate/react"),l=require("groq"),c=require("react-query"),d=require("xstate"),u=require("react"),p=require("use-deep-compare-effect"),h=require("object-hash"),m=require("unfetch"),x=require("react-time-ago"),g=require("@hookform/resolvers/yup"),y=require("@sanity/uuid"),f=require("react-hook-form"),j=require("yup"),b=require("styled-components"),v=require("sanity"),D=require("javascript-time-ago"),E=require("javascript-time-ago/locale/en");function w(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}function T(e){if(e&&e.__esModule)return e;var t=Object.create(null);return e&&Object.keys(e).forEach((function(r){if("default"!==r){var n=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(t,r,n.get?n:{enumerable:!0,get:function(){return e[r]}})}})),t.default=e,Object.freeze(t)}var k=w(l),R=w(p),S=w(h),O=w(m),C=w(x),P=T(j),L=w(b),B=w(D),I=w(E);const q={BUILDING:"#f5a623",CANCELED:"#ff0000",ERROR:"#ff0000",READY:"#50e3c2",QUEUED:"#333"},z=e=>null,F=e=>e.sort(((e,t)=>e.name>t.name?1:e.name<t.name?-1:0)),A=()=>d.Machine({context:{message:"",results:[]},initial:"pending",states:{pending:{invoke:{src:"fetchDataService",onDone:{actions:["setResults"],target:"ready"},onError:{actions:["setMessage"],target:"failed"}}},ready:{initial:"unknown",on:{CREATE:{actions:["targetCreate"]},DELETE:{actions:["targetDelete"]},UPDATE:{actions:["targetUpdate"]}},states:{unknown:{always:[{cond:"hasData",target:"withData"},{cond:"hasNoData",target:"withoutData"}]},withData:{always:[{cond:"hasNoData",target:"withoutData"}]},withoutData:{always:[{cond:"hasData",target:"withData"}]}}},failed:{type:"final"}}},{actions:{setMessage:d.assign(((e,t)=>({message:t.data.details.description}))),setResults:d.assign(((e,t)=>({results:t.data}))),targetCreate:d.assign(((e,t)=>({results:F([...e.results,t.deploymentTarget])}))),targetDelete:d.assign(((e,t)=>({results:e.results.filter((e=>e._id!==t.id))}))),targetUpdate:d.assign(((e,t)=>{const{deploymentTarget:r}=t,n=e.results.findIndex((e=>e._id===r._id)),o=Object.assign([],e.results,{[n]:t.deploymentTarget});return{results:F(o)}}))},guards:{hasData:e=>{var t;return(null==(t=null==e?void 0:e.results)?void 0:t.length)>0},hasNoData:e=>{var t;return 0===(null==(t=null==e?void 0:e.results)?void 0:t.length)}}}),U=(e,t)=>{var n,o;const a=(e=>async(t,r)=>{const n=new URLSearchParams;if(n.set("projectId",e.projectId),e.teamId&&n.set("teamId",e.teamId),r)for(const[e,t]of r.entries())n.append(e,t);const o=await O.default("".concat(t,"?").concat(n.toString()),{headers:{Authorization:"Bearer ".concat(e.token)}});if(!o.ok)throw new Error("Response not OK");try{return o.json()}catch(e){throw new Error(e)}})(e),s=new URLSearchParams;s.set("limit",String(null==e?void 0:e.deployLimit));const{data:i,isFetching:l,isSuccess:d,error:u,refetch:p}=c.useQuery(S.default(e),(()=>a("https://api.vercel.com/v5/now/deployments",s)),{enabled:null==(n=null==t?void 0:t.enabled)||n,refetchInterval:2e4,refetchIntervalInBackground:!1,refetchOnMount:!0,refetchOnReconnect:"always",refetchOnWindowFocus:!1,retry:!1}),h=new URLSearchParams;h.set("limit","20");const{data:m,isFetching:x,isSuccess:g,error:y}=c.useQuery("".concat(S.default(e),"-aliases"),(()=>a("https://api.vercel.com/v3/now/aliases",h)),{enabled:!!i,refetchOnMount:!1,refetchOnReconnect:!1,refetchOnWindowFocus:!1,retry:!1}),f=null==m?void 0:m.aliases;let j;return f&&(j=null==(o=null==i?void 0:i.deployments)?void 0:o.map((e=>{const t=f.find((t=>t.deploymentId===e.uid));return r(r({},e),{},{alias:null==t?void 0:t.alias})}))),{deployments:j,error:y||u,isFetching:x||l,isSuccess:g&&d,refetch:p}},M=d.Machine({initial:"idle",states:{idle:{on:{REFRESH:"refreshing"}},refreshing:{on:{ERROR:"error",REFRESHED:"refreshed"}},refreshed:{on:{REFRESH:"refreshing"}},error:{on:{REFRESH:"refreshing"}}}});function H(){return s.useTheme().sanity.color.card.enabled}const V=e=>{const{children:t,colSpan:r,header:n,variant:a}=e;let i="table-cell",l="auto";switch(a){case"age":l="50px";break;case"branch":l="300px",i=["none","none","none","table-cell"];break;case"creator":l="80px";break;case"state":l="110px",i=["none","none","none","none","table-cell"]}const{border:c}=H();return n?o.jsx(s.Box,{as:"th",colSpan:r,display:i,paddingX:3,paddingY:2,style:{maxWidth:l,position:"relative",textAlign:"left",width:l},children:o.jsx(s.Label,{size:0,children:t})}):o.jsx(s.Box,{as:"td",colSpan:r,display:i,paddingX:3,paddingY:[2,2,3],style:{borderTop:"1px solid ".concat(c),maxWidth:l,position:"relative",textAlign:"left",width:l},children:t})},N=e=>{let{state:t}=e;return o.jsx(s.Box,{style:{backgroundColor:"".concat(q[t]),borderRadius:"20px",height:"9px",width:"9px"}})},_=e=>{var t,r,n,i;const{deployment:l}=e,c=u.useRef(new Date(l.created)),d=null==(t=null==l?void 0:l.meta)?void 0:t.githubCommitMessage,p=null==(r=null==l?void 0:l.meta)?void 0:r.githubCommitRef,h=null!=(n=l.alias)?n:l.url;return o.jsxs("tr",{children:[o.jsx(V,{children:o.jsxs(s.Flex,{align:"center",children:[o.jsx(s.Box,{display:["block","block","block","block","none"],marginRight:3,style:{flexShrink:0},children:o.jsx(N,{state:l.state})}),h?o.jsxs(o.Fragment,{children:[l.alias&&o.jsx(a.LinkIcon,{}),o.jsx(s.Box,{marginLeft:l.alias?1:0,children:o.jsx(s.Text,{muted:!("READY"===l.state),size:1,style:{textDecoration:"CANCELED"===l.state||"ERROR"===l.state?"line-through":"normal"},textOverflow:"ellipsis",children:"READY"===l.state?o.jsx("a",{href:"https://".concat(h),rel:"noopener noreferrer",target:"_blank",children:h}):h})})]}):o.jsx(s.Text,{size:1,children:"Uploading..."})]})}),o.jsx(V,{variant:"state",children:o.jsxs(s.Flex,{align:"center",children:[o.jsx(N,{state:l.state}),o.jsx(s.Box,{marginLeft:2,children:o.jsx(s.Text,{size:1,children:l.state.trim().toLowerCase().replace(/^[a-z]/i,(e=>e.toUpperCase()))})})]})}),o.jsx(V,{variant:"branch",children:o.jsxs(s.Stack,{space:2,children:[o.jsx(s.Text,{size:1,textOverflow:"ellipsis",children:p}),d&&o.jsx(s.Text,{muted:!0,size:1,textOverflow:"ellipsis",children:d})]})}),o.jsx(V,{variant:"age",children:o.jsx(s.Flex,{align:"center",children:o.jsx(s.Text,{size:1,children:o.jsx(C.default,{date:c.current,locale:"en-US",timeStyle:"mini"})})})}),o.jsx(V,{variant:"creator",children:o.jsx(s.Flex,{align:"center",justify:"center",children:o.jsx("img",{draggable:!1,src:"https://vercel.com/api/www/avatar/".concat(null==(i=null==l?void 0:l.creator)?void 0:i.uid,"?&s=48"),style:{borderRadius:"20px",height:"20px",width:"20px"}})})})]})},Y=e=>{const{deployHook:t,onDeploySuccess:r,targetName:n}=e,l=u.useMemo((()=>(e=>d.Machine({id:"deploy",initial:"idle",context:{disabled:!1,feedback:void 0,label:void 0,error:void 0},states:{idle:{entry:d.assign({feedback:()=>{},label:()=>"Deploy"}),on:{DEPLOY:"deploying"}},deploying:{entry:d.assign({disabled:()=>!0,label:()=>"Deploying"}),exit:d.assign({disabled:()=>!1,label:()=>"Deploy"}),invoke:{onDone:{target:"success"},onError:{target:"error",actions:d.assign({error:(e,t)=>t.data})},src:"deploy"}},success:{entry:[d.assign({feedback:()=>"Succesfully started!"})],exit:d.assign({feedback:()=>{}}),on:{DEPLOY:"deploying"}},error:{on:{DEPLOY:"deploying"}}}},{services:{deploy:()=>new Promise((async(t,r)=>{try{if(!e)return r(new Error("No deployHook URL defined"));const n=await O.default(e,{method:"POST"}),o=await n.json();return n.ok?t():r((null==o?void 0:o.error).message||n.statusText)}catch(e){return console.error("Unable to deploy with error:",e),r(new Error("Please check the developer console for more information"))}}))}}))(t)),[t]),[c,p,h]=i.useMachine(l),m=s.useToast(),x=c.matches("error"),g=c.matches("success");return u.useEffect((()=>{x&&m.push({closable:!0,description:"Unable to queue deploy for ".concat(n,": ").concat(c.context.error),duration:8e3,status:"error",title:"Vercel (dashboard)"}),g&&m.push({closable:!0,description:"Deploy queued for ".concat(n),duration:8e3,status:"success",title:"Vercel (dashboard)"})}),[x,g,m,n,c.context.error]),u.useEffect((()=>{h.onTransition((e=>{"success"===e.value&&r&&r()}))}),[h,r]),o.jsxs(s.Box,{padding:3,style:{position:"relative"},children:[o.jsx(z,{name:"Deploy",state:c}),o.jsx(s.Button,{disabled:c.context.disabled,fontSize:1,icon:a.UploadIcon,mode:"ghost",onClick:()=>{p({type:"DEPLOY"})},padding:3,text:"".concat(c.context.label," ").concat(n),tone:"default"})]})},X=()=>{const{border:e}=H();return o.jsx(s.Box,{style:{backgroundColor:e,borderRadius:"20px",height:"20px",userSelect:"none",width:"20px"}})},Q=e=>{const{rows:t}=e,{border:r}=H();return o.jsx(s.Box,{style:{backgroundColor:r,borderRadius:"3px",userSelect:"none",width:"100%"},children:o.jsx(s.Stack,{space:2,children:new Array(t).fill(void 0).map(((e,t)=>o.jsx(s.Text,{size:1,children:" "},t)))})})},W=()=>o.jsxs("tr",{children:[o.jsx(V,{children:o.jsx(Q,{rows:1})}),o.jsx(V,{variant:"state",children:o.jsx(Q,{rows:1})}),o.jsx(V,{variant:"branch",children:o.jsx(Q,{rows:2})}),o.jsx(V,{variant:"age",children:o.jsx(Q,{rows:1})}),o.jsx(V,{variant:"creator",children:o.jsx(s.Flex,{justify:"center",children:o.jsx(X,{})})})]}),J=e=>{const{deploymentTarget:t}=e,r=u.useRef(),[n,a]=i.useMachine(M),{deployments:l,error:c,isFetching:d,isSuccess:p,refetch:h}=U(t,{enabled:!n.matches("error")}),m=s.useToast(),x=n.matches("error");u.useEffect((()=>()=>{r.current&&clearTimeout(r.current)}),[]),u.useEffect((()=>{c&&a({type:"ERROR"}),d&&a({type:"REFRESH"}),!d&&p&&a({type:"REFRESHED"})}),[c,d,p,a]),R.default((()=>{n.matches("refreshing")||a({type:"REFRESH"})}),[t]),R.default((()=>{x&&m.push({closable:!0,description:"Unable to fetch deployments for ".concat(t.name),duration:8e3,status:"error",title:"Vercel (dashboard)"})}),[t,x]);const g=void 0!==l,y=l&&l.length>0,{border:f}=H();return o.jsxs(s.Box,{marginTop:3,style:{position:"relative"},children:[o.jsx(z,{name:"Refresh",state:n}),!n.matches("error")&&o.jsxs(o.Fragment,{children:[o.jsxs(s.Box,{as:"table",style:{borderBottom:"1px solid ".concat(f),borderCollapse:"collapse",display:"table",tableLayout:"fixed",width:"100%"},children:[o.jsx(s.Box,{as:"thead",style:{display:"table-header-group"},children:o.jsxs("tr",{children:[o.jsx(V,{header:!0,children:"Deployment"}),o.jsx(V,{header:!0,variant:"state",children:"State"}),o.jsx(V,{header:!0,variant:"branch",children:"Branch"}),o.jsx(V,{header:!0,variant:"age",children:"Age"}),o.jsx(V,{header:!0,variant:"age",children:"Creator"})]})}),o.jsxs(s.Box,{as:"tbody",style:{display:"table-header-group"},children:[!l&&new Array(null==t?void 0:t.deployLimit).fill(void 0).map(((e,t)=>o.jsx(W,{},t))),y&&(null==l?void 0:l.map((e=>o.jsx(_,{deployment:e},e.uid))))]})]}),g&&!y&&o.jsx(s.Box,{padding:3,style:{width:"100%"},children:o.jsx(s.Text,{muted:!0,size:1,children:"No deployments found. Don't forget to specify a valid team ID if your project belongs to a team."})})]}),n.matches("error")&&o.jsx(s.Box,{padding:3,children:o.jsx(s.Text,{muted:!0,size:1,children:"Unable to fetch recent deployments. Please check your network and deployment settings."})}),!n.matches("error")&&t.deployHook&&o.jsx(s.Box,{children:o.jsx(Y,{deployHook:t.deployHook,onDeploySuccess:()=>{r.current&&clearTimeout(r.current),r.current=setTimeout((()=>{h({cancelRefetch:!0,throwOnError:!0})}),4e3)},targetName:t.name})})]})},G=e=>{const{item:t,onDialogEdit:r}=e,n={deployHook:t.deployHook,deployLimit:t.deployLimit,name:t.name,projectId:t.projectId,teamId:t.teamId,token:t.token};return o.jsxs(s.Box,{style:{position:"relative"},children:[o.jsxs(s.Flex,{align:"center",justify:"space-between",marginTop:2,paddingX:3,children:[o.jsx(s.Text,{size:2,children:t.name}),o.jsx(s.Tooltip,{content:o.jsx(s.Box,{padding:2,children:o.jsx(s.Text,{muted:!0,size:1,children:"Edit deployment target"})}),placement:"left",children:o.jsx(s.Button,{fontSize:1,icon:a.EditIcon,mode:"bleed",onClick:()=>r(t)})})]}),o.jsx(J,{deploymentTarget:n})]})},K=e=>{const{items:t,onDialogEdit:r}=e;return o.jsx(s.Stack,{space:5,children:null==t?void 0:t.map((e=>o.jsx(G,{item:e,onDialogEdit:r},e._id)))})},Z=d.Machine({context:{formData:{},message:""},initial:"idle",states:{idle:{on:{CREATE:{actions:["createDocument"],target:"creating"},DELETE:{actions:["deleteDocument"],target:"deleting"},UPDATE:{actions:["updateDocument"],target:"updating"}}},creating:{invoke:{src:"createDocumentService",onDone:{target:"success"},onError:{actions:["setMessage"],target:"error"}},on:{RESOLVE:"success",REJECT:"error"}},updating:{invoke:{src:"updateDocumentService",onDone:{target:"success"},onError:{actions:["setMessage"],target:"error"}},on:{RESOLVE:"success",REJECT:"error"}},deleting:{invoke:{src:"deleteDocumentService",onDone:{target:"success"},onError:{actions:["setMessage"],target:"error"}},on:{RESOLVE:"success",REJECT:"error"}},success:{invoke:{src:"formSubmittedService"}},error:{}}},{actions:{setMessage:d.assign(((e,t)=>({message:t.data.details.description}))),createDocument:d.assign(((e,t)=>({formData:t.formData}))),deleteDocument:d.assign((()=>({}))),updateDocument:d.assign(((e,t)=>({formData:t.formData})))}}),$=e=>Object.keys(e).reduce(((t,r)=>{const n=e[r];return"object"==typeof n&&null!==n&&n.constructor!==Array?t[r]=$(n):""===n||void 0===n||0===(null==n?void 0:n.length)?t[r]=null:t[r]="string"==typeof n&&n?e[r].trim():e[r],t}),{}),ee=L.default(a.ErrorOutlineIcon)((e=>{let{theme:t}=e;return{color:t.sanity.color.spot.red}})),te=e=>{const{description:t,error:r,label:n,name:a}=e;return o.jsxs(s.Box,{marginBottom:3,children:[o.jsxs(s.Inline,{space:2,children:[o.jsx(s.Text,{as:"label",htmlFor:a,size:1,weight:"semibold",children:n}),r&&o.jsx(s.Text,{size:1,children:o.jsx(s.Tooltip,{content:o.jsx(s.Box,{padding:2,children:o.jsxs(s.Text,{muted:!0,size:1,children:[o.jsx(ee,{style:{marginRight:"0.1em"}}),r.message]})}),fallbackPlacements:["top","left"],placement:"right",portal:!0,children:o.jsx(ee,{})})})]}),t&&o.jsx(s.Box,{marginY:3,children:o.jsx(s.Text,{htmlFor:a,muted:!0,size:1,children:t})})]})},re=u.forwardRef(((e,t)=>{const{description:r,disabled:n,error:a,label:i,name:l,placeholder:c,value:d}=e;return o.jsxs(s.Box,{children:[o.jsx(te,{description:r,error:a,label:i,name:l}),o.jsx(s.TextInput,{autoComplete:"off",autoFocus:!0,defaultValue:d,disabled:n,id:l,name:l,placeholder:c,ref:t})]})}));function ne(){return v.useClient({apiVersion:"1"})}const oe=P.object().shape({deployHook:P.string().url("Deploy hook must be a valid URL"),deployLimit:P.number().positive().integer().min(1,"Deploy limit must no less than 1").max(15,"Deploy limit must no higher than 15").typeError("Deploy limit must be a number").required("Deploy limit must be a positive integer between 1 and 15"),name:P.string().required("Name cannot be empty"),projectId:P.string().required("Vercel Project ID cannot be empty"),teamId:P.string(),token:P.string().required("Vercel Account Token cannot be empty")}),ae=e=>{const{deploymentTarget:t,onClose:n,onCreate:a,onDelete:l,onUpdate:c}=e,d=ne(),[u,p]=i.useMachine(Z,{services:{formSubmittedService:async()=>{n()},createDocumentService:async(e,t)=>{let n;try{return n=await d.create(r({_id:"vercel.".concat(y.uuid()),_type:"vercel.deploymentTarget"},t.formData)),a&&a(n),Promise.resolve()}catch(e){return Promise.reject(e)}},deleteDocumentService:async()=>{if(t)try{return await d.delete(t._id),l&&l(t._id),Promise.resolve()}catch(e){return Promise.reject(e)}return Promise.resolve()},updateDocumentService:async(e,r)=>{let n;if(t)try{return n=await d.patch(t._id).set(r.formData).commit(),c&&c(n),Promise.resolve()}catch(e){return Promise.reject(e)}return Promise.resolve()}}}),h=u.matches("creating")||u.matches("deleting")||u.matches("updating"),{formState:{errors:m,isDirty:x,isValid:j},handleSubmit:b,register:v}=f.useForm({defaultValues:{deployHook:(null==t?void 0:t.deployHook)||"",deployLimit:(null==t?void 0:t.deployLimit)||5,name:null==t?void 0:t.name,projectId:null==t?void 0:t.projectId,teamId:(null==t?void 0:t.teamId)||"",token:null==t?void 0:t.token},mode:"onChange",resolver:g.yupResolver(oe)}),D=async e=>{const r=$(e);await p(t?"UPDATE":"CREATE",{formData:r})},E=()=>{p("DELETE",{id:null==t?void 0:t._id})},w=()=>o.jsx(s.Box,{padding:3,children:o.jsxs(s.Flex,{justify:t?"space-between":"flex-end",children:[t&&o.jsx(s.Button,{disabled:h,fontSize:1,mode:"bleed",onClick:E,text:"Delete",tone:"critical"}),o.jsx(s.Button,{disabled:h||!x||!j,fontSize:1,onClick:b(D),text:t?"Update and close":"Create",tone:"primary"})]})});return o.jsx(s.Dialog,{footer:o.jsx(w,{}),header:"".concat(t?"Edit":"Create"," deployment target"),id:"create",onClose:n,width:1,zOffset:600001,children:o.jsxs(s.Box,{as:"form",padding:4,onSubmit:b(D),children:[o.jsx("button",{style:{display:"none"},tabIndex:-1,type:"submit"}),o.jsxs(s.Stack,{space:5,children:[o.jsx(re,{disabled:h,description:"Name displayed in this plugin (e.g. production, staging)",error:null==m?void 0:m.name,label:"Name",name:"name",ref:v}),o.jsx(re,{disabled:h,error:null==m?void 0:m.token,label:"Vercel Account Token",name:"token",ref:v}),o.jsx(re,{disabled:h,error:null==m?void 0:m.projectId,label:"Vercel Project ID",name:"projectId",ref:v}),o.jsx(re,{description:"Required only if your project is owned by a team account",disabled:h,error:null==m?void 0:m.teamId,label:"Vercel Team ID (optional)",name:"teamId",ref:v}),o.jsx(re,{description:"Enter a valid deploy hook URL to enable manual deploys",disabled:h,error:null==m?void 0:m.deployHook,label:"Vercel Deploy Hook (optional)",name:"deployHook",ref:v}),o.jsx(re,{disabled:h,error:null==m?void 0:m.deployLimit,label:"Number of deploys to display",name:"deployLimit",ref:v({valueAsNumber:!0})})]})]})})},se=()=>d.Machine({context:{editDeploymentTarget:void 0},initial:"idle",states:{idle:{entry:d.assign({editDeploymentTarget:()=>{}}),on:{CREATE:"create",EDIT:{actions:["setEditDeploymentTarget"],target:"edit"}}},edit:{on:{CLOSE:"idle"}},create:{on:{CLOSE:"idle"}}}},{actions:{setEditDeploymentTarget:d.assign(((e,t)=>({editDeploymentTarget:t.deploymentTarget})))}}),ie=()=>{const t=ne(),[r,n]=i.useMachine(A,{services:{fetchDataService:()=>{return t.fetch(k.default(e||(r=['*[_type == "','"] | order(name asc)'],n||(n=r.slice(0)),e=Object.freeze(Object.defineProperties(r,{raw:{value:Object.freeze(n)}}))),"vercel.deploymentTarget")).then((e=>e));var r,n}}}),[l,d]=i.useMachine(se),u=new c.QueryClient({defaultOptions:{queries:{cacheTime:0,staleTime:0}}}),p=()=>{d("CLOSE")},h=()=>{d("CREATE")};return o.jsx(s.ToastProvider,{zOffset:600002,children:o.jsxs(c.QueryClientProvider,{client:u,children:[o.jsxs(s.Card,{radius:2,style:{overflow:"hidden "},children:[o.jsx(z,{name:"List",state:r}),o.jsxs(s.Flex,{align:"center",justify:"space-between",paddingX:3,paddingY:2,children:[o.jsx(s.Text,{size:5,weight:"semibold",children:"Vercel deployments"}),o.jsx(s.Tooltip,{content:o.jsx(s.Box,{padding:2,children:o.jsx(s.Text,{muted:!0,size:1,children:"Create new deployment target"})}),placement:"left",children:o.jsx(s.Button,{fontSize:1,icon:a.AddIcon,onClick:h,mode:"bleed"})})]}),o.jsxs(s.Box,{children:[r.matches("pending")&&o.jsx(s.Box,{paddingX:3,paddingY:4,children:o.jsx(s.Text,{children:"Loading..."})}),r.matches("ready.withoutData")&&o.jsx(s.Box,{paddingX:3,paddingY:4,children:o.jsxs(s.Text,{children:["No deployment targets found."," ",o.jsx("a",{onClick:h,style:{cursor:"pointer"},children:"Create a new target?"})]})}),r.matches("ready.withData")&&o.jsx(K,{items:r.context.results,onDialogEdit:e=>{d("EDIT",{deploymentTarget:e})}}),r.matches("failed")&&o.jsx(s.Box,{paddingX:3,paddingY:4,children:o.jsx(s.Text,{children:"Failed to retrieve deployment targets. Please check the developer console log for more information."})})]})]}),l.matches("create")&&o.jsx(ae,{onClose:p,onCreate:e=>{n("CREATE",{deploymentTarget:e})}}),l.matches("edit")&&o.jsx(ae,{deploymentTarget:l.context.editDeploymentTarget,onClose:p,onDelete:e=>{n("DELETE",{id:e})},onUpdate:e=>{n("UPDATE",{deploymentTarget:e})}})]})})};B.default.addDefaultLocale(I.default),exports.vercelWidget=function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};var t;return{name:"vercel",component:ie,layout:null!=(t=e.layout)?t:{width:"full"}}};
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: !0 });
|
|
3
|
+
var jsxRuntime = require("react/jsx-runtime"), icons = require("@sanity/icons"), ui = require("@sanity/ui"), react$1 = require("@xstate/react"), reactQuery = require("react-query"), xstate = require("xstate"), react = require("react"), useDeepCompareEffect = require("use-deep-compare-effect"), hash = require("object-hash"), fetch = require("unfetch"), ReactTimeAgo = require("react-time-ago"), yup$1 = require("@hookform/resolvers/yup"), uuid = require("@sanity/uuid"), reactHookForm = require("react-hook-form"), yup = require("yup"), styledComponents = require("styled-components"), sanity = require("sanity"), TimeAgo = require("javascript-time-ago"), en = require("javascript-time-ago/locale/en");
|
|
4
|
+
function _interopDefaultCompat(e) {
|
|
5
|
+
return e && typeof e == "object" && "default" in e ? e : { default: e };
|
|
6
|
+
}
|
|
7
|
+
function _interopNamespaceCompat(e) {
|
|
8
|
+
if (e && typeof e == "object" && "default" in e) return e;
|
|
9
|
+
var n = /* @__PURE__ */ Object.create(null);
|
|
10
|
+
return e && Object.keys(e).forEach(function(k) {
|
|
11
|
+
if (k !== "default") {
|
|
12
|
+
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
13
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
14
|
+
enumerable: !0,
|
|
15
|
+
get: function() {
|
|
16
|
+
return e[k];
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
}), n.default = e, Object.freeze(n);
|
|
21
|
+
}
|
|
22
|
+
var useDeepCompareEffect__default = /* @__PURE__ */ _interopDefaultCompat(useDeepCompareEffect), hash__default = /* @__PURE__ */ _interopDefaultCompat(hash), fetch__default = /* @__PURE__ */ _interopDefaultCompat(fetch), ReactTimeAgo__default = /* @__PURE__ */ _interopDefaultCompat(ReactTimeAgo), yup__namespace = /* @__PURE__ */ _interopNamespaceCompat(yup), TimeAgo__default = /* @__PURE__ */ _interopDefaultCompat(TimeAgo), en__default = /* @__PURE__ */ _interopDefaultCompat(en);
|
|
23
|
+
const API_ENDPOINT_DEPLOYMENTS = "https://api.vercel.com/v5/now/deployments", API_ENDPOINT_ALIASES = "https://api.vercel.com/v3/now/aliases", API_VERSION = "1", DEPLOYMENT_TARGET_DOCUMENT_TYPE = "vercel.deploymentTarget", VERCEL_STATUS_COLORS = {
|
|
24
|
+
BUILDING: "#f5a623",
|
|
25
|
+
CANCELED: "#ff0000",
|
|
26
|
+
ERROR: "#ff0000",
|
|
27
|
+
READY: "#50e3c2",
|
|
28
|
+
QUEUED: "#333"
|
|
29
|
+
}, WIDGET_NAME = "Vercel (dashboard)", Z_INDEX_DIALOG = 600001, Z_INDEX_TOAST_PROVIDER = 600002, StateDebug = (props) => null, sortByTargetName = (items) => items.sort((a, b) => a.name > b.name ? 1 : a.name < b.name ? -1 : 0), deploymentTargetListMachine = () => xstate.Machine(
|
|
30
|
+
{
|
|
31
|
+
context: {
|
|
32
|
+
message: "",
|
|
33
|
+
results: []
|
|
34
|
+
},
|
|
35
|
+
initial: "pending",
|
|
36
|
+
states: {
|
|
37
|
+
pending: {
|
|
38
|
+
invoke: {
|
|
39
|
+
src: "fetchDataService",
|
|
40
|
+
onDone: { actions: ["setResults"], target: "ready" },
|
|
41
|
+
onError: { actions: ["setMessage"], target: "failed" }
|
|
42
|
+
}
|
|
43
|
+
},
|
|
44
|
+
ready: {
|
|
45
|
+
initial: "unknown",
|
|
46
|
+
on: {
|
|
47
|
+
CREATE: { actions: ["targetCreate"] },
|
|
48
|
+
DELETE: { actions: ["targetDelete"] },
|
|
49
|
+
UPDATE: { actions: ["targetUpdate"] }
|
|
50
|
+
},
|
|
51
|
+
states: {
|
|
52
|
+
unknown: {
|
|
53
|
+
always: [
|
|
54
|
+
{ cond: "hasData", target: "withData" },
|
|
55
|
+
{ cond: "hasNoData", target: "withoutData" }
|
|
56
|
+
]
|
|
57
|
+
},
|
|
58
|
+
withData: {
|
|
59
|
+
always: [{ cond: "hasNoData", target: "withoutData" }]
|
|
60
|
+
},
|
|
61
|
+
withoutData: {
|
|
62
|
+
always: [{ cond: "hasData", target: "withData" }]
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
},
|
|
66
|
+
failed: {
|
|
67
|
+
type: "final"
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
},
|
|
71
|
+
{
|
|
72
|
+
actions: {
|
|
73
|
+
setMessage: xstate.assign((_context, event) => ({
|
|
74
|
+
message: event.data.details.description
|
|
75
|
+
})),
|
|
76
|
+
setResults: xstate.assign((_context, event) => ({
|
|
77
|
+
results: event.data
|
|
78
|
+
})),
|
|
79
|
+
targetCreate: xstate.assign((context, event) => ({
|
|
80
|
+
results: sortByTargetName([...context.results, event.deploymentTarget])
|
|
81
|
+
})),
|
|
82
|
+
targetDelete: xstate.assign((context, event) => ({
|
|
83
|
+
results: context.results.filter((target) => target._id !== event.id)
|
|
84
|
+
})),
|
|
85
|
+
targetUpdate: xstate.assign((context, event) => {
|
|
86
|
+
const { deploymentTarget } = event, index = context.results.findIndex((target) => target._id === deploymentTarget._id), updatedResults = Object.assign([], context.results, {
|
|
87
|
+
[index]: event.deploymentTarget
|
|
88
|
+
});
|
|
89
|
+
return {
|
|
90
|
+
results: sortByTargetName(updatedResults)
|
|
91
|
+
};
|
|
92
|
+
})
|
|
93
|
+
},
|
|
94
|
+
guards: {
|
|
95
|
+
hasData: (context) => context?.results?.length > 0,
|
|
96
|
+
hasNoData: (context) => context?.results?.length === 0
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
), fetcher = (deploymentTarget) => async (url, extraParams) => {
|
|
100
|
+
const params = new URLSearchParams();
|
|
101
|
+
if (params.set("projectId", deploymentTarget.projectId), deploymentTarget.teamId && params.set("teamId", deploymentTarget.teamId), extraParams)
|
|
102
|
+
for (const [k, v] of extraParams.entries())
|
|
103
|
+
params.append(k, v);
|
|
104
|
+
const response = await fetch__default.default(`${url}?${params.toString()}`, {
|
|
105
|
+
headers: {
|
|
106
|
+
Authorization: `Bearer ${deploymentTarget.token}`
|
|
107
|
+
}
|
|
108
|
+
});
|
|
109
|
+
if (!response.ok)
|
|
110
|
+
throw new Error("Response not OK");
|
|
111
|
+
try {
|
|
112
|
+
return response.json();
|
|
113
|
+
} catch (err) {
|
|
114
|
+
throw new Error(err);
|
|
115
|
+
}
|
|
116
|
+
}, useDeployments = (deploymentTarget, options) => {
|
|
117
|
+
const fetchUrl = fetcher(deploymentTarget), deployParams = new URLSearchParams();
|
|
118
|
+
deployParams.set("limit", String(deploymentTarget?.deployLimit));
|
|
119
|
+
const {
|
|
120
|
+
data: deploymentsData,
|
|
121
|
+
isFetching: deploymentsIsFetching,
|
|
122
|
+
isSuccess: deploymentsIsSuccess,
|
|
123
|
+
error: deploymentsError,
|
|
124
|
+
refetch
|
|
125
|
+
} = reactQuery.useQuery(
|
|
126
|
+
hash__default.default(deploymentTarget),
|
|
127
|
+
// key
|
|
128
|
+
() => fetchUrl(API_ENDPOINT_DEPLOYMENTS, deployParams),
|
|
129
|
+
{
|
|
130
|
+
enabled: options?.enabled ?? !0,
|
|
131
|
+
refetchInterval: 2e4,
|
|
132
|
+
// ms
|
|
133
|
+
refetchIntervalInBackground: !1,
|
|
134
|
+
refetchOnMount: !0,
|
|
135
|
+
refetchOnReconnect: "always",
|
|
136
|
+
refetchOnWindowFocus: !1,
|
|
137
|
+
retry: !1
|
|
138
|
+
}
|
|
139
|
+
), aliasParams = new URLSearchParams();
|
|
140
|
+
aliasParams.set("limit", "20");
|
|
141
|
+
const {
|
|
142
|
+
data: aliasesData,
|
|
143
|
+
isFetching: aliasesIsFetching,
|
|
144
|
+
isSuccess: aliasesIsSuccess,
|
|
145
|
+
error: aliasesError
|
|
146
|
+
} = reactQuery.useQuery(
|
|
147
|
+
`${hash__default.default(deploymentTarget)}-aliases`,
|
|
148
|
+
// key
|
|
149
|
+
() => fetchUrl(API_ENDPOINT_ALIASES, aliasParams),
|
|
150
|
+
{
|
|
151
|
+
enabled: !!deploymentsData,
|
|
152
|
+
refetchOnMount: !1,
|
|
153
|
+
refetchOnReconnect: !1,
|
|
154
|
+
refetchOnWindowFocus: !1,
|
|
155
|
+
retry: !1
|
|
156
|
+
}
|
|
157
|
+
), aliases = aliasesData?.aliases;
|
|
158
|
+
let deploymentsWithAlias;
|
|
159
|
+
return aliases && (deploymentsWithAlias = deploymentsData?.deployments?.map((val) => {
|
|
160
|
+
const alias = aliases.find((a) => a.deploymentId === val.uid);
|
|
161
|
+
return {
|
|
162
|
+
...val,
|
|
163
|
+
alias: alias?.alias
|
|
164
|
+
};
|
|
165
|
+
})), {
|
|
166
|
+
deployments: deploymentsWithAlias,
|
|
167
|
+
error: aliasesError || deploymentsError,
|
|
168
|
+
isFetching: aliasesIsFetching || deploymentsIsFetching,
|
|
169
|
+
isSuccess: aliasesIsSuccess && deploymentsIsSuccess,
|
|
170
|
+
refetch
|
|
171
|
+
};
|
|
172
|
+
}, refreshMachine = xstate.Machine({
|
|
173
|
+
initial: "idle",
|
|
174
|
+
states: {
|
|
175
|
+
idle: {
|
|
176
|
+
on: {
|
|
177
|
+
REFRESH: "refreshing"
|
|
178
|
+
}
|
|
179
|
+
},
|
|
180
|
+
refreshing: {
|
|
181
|
+
on: {
|
|
182
|
+
ERROR: "error",
|
|
183
|
+
REFRESHED: "refreshed"
|
|
184
|
+
}
|
|
185
|
+
},
|
|
186
|
+
refreshed: {
|
|
187
|
+
on: {
|
|
188
|
+
REFRESH: "refreshing"
|
|
189
|
+
}
|
|
190
|
+
},
|
|
191
|
+
error: {
|
|
192
|
+
on: {
|
|
193
|
+
REFRESH: "refreshing"
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
});
|
|
198
|
+
function useCardColor() {
|
|
199
|
+
return ui.useTheme().sanity.color.card.enabled;
|
|
200
|
+
}
|
|
201
|
+
const TableCell = (props) => {
|
|
202
|
+
const { children, colSpan, header, variant } = props;
|
|
203
|
+
let display = "table-cell", cellWidth = "auto";
|
|
204
|
+
switch (variant) {
|
|
205
|
+
case "age":
|
|
206
|
+
cellWidth = "50px";
|
|
207
|
+
break;
|
|
208
|
+
case "branch":
|
|
209
|
+
cellWidth = "300px", display = ["none", "none", "none", "table-cell"];
|
|
210
|
+
break;
|
|
211
|
+
case "creator":
|
|
212
|
+
cellWidth = "80px";
|
|
213
|
+
break;
|
|
214
|
+
case "state":
|
|
215
|
+
cellWidth = "110px", display = ["none", "none", "none", "none", "table-cell"];
|
|
216
|
+
break;
|
|
217
|
+
}
|
|
218
|
+
const { border } = useCardColor();
|
|
219
|
+
return header ? /* @__PURE__ */ jsxRuntime.jsx(
|
|
220
|
+
ui.Box,
|
|
221
|
+
{
|
|
222
|
+
as: "th",
|
|
223
|
+
colSpan,
|
|
224
|
+
display,
|
|
225
|
+
paddingX: 3,
|
|
226
|
+
paddingY: 2,
|
|
227
|
+
style: {
|
|
228
|
+
maxWidth: cellWidth,
|
|
229
|
+
position: "relative",
|
|
230
|
+
textAlign: "left",
|
|
231
|
+
width: cellWidth
|
|
232
|
+
},
|
|
233
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(ui.Label, { size: 0, children })
|
|
234
|
+
}
|
|
235
|
+
) : /* @__PURE__ */ jsxRuntime.jsx(
|
|
236
|
+
ui.Box,
|
|
237
|
+
{
|
|
238
|
+
as: "td",
|
|
239
|
+
colSpan,
|
|
240
|
+
display,
|
|
241
|
+
paddingX: 3,
|
|
242
|
+
paddingY: [2, 2, 3],
|
|
243
|
+
style: {
|
|
244
|
+
borderTop: `1px solid ${border}`,
|
|
245
|
+
maxWidth: cellWidth,
|
|
246
|
+
position: "relative",
|
|
247
|
+
textAlign: "left",
|
|
248
|
+
width: cellWidth
|
|
249
|
+
},
|
|
250
|
+
children
|
|
251
|
+
}
|
|
252
|
+
);
|
|
253
|
+
}, StatusDot = ({ state }) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
254
|
+
ui.Box,
|
|
255
|
+
{
|
|
256
|
+
style: {
|
|
257
|
+
backgroundColor: `${VERCEL_STATUS_COLORS[state]}`,
|
|
258
|
+
borderRadius: "20px",
|
|
259
|
+
height: "9px",
|
|
260
|
+
width: "9px"
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
), Deployment = (props) => {
|
|
264
|
+
const { deployment } = props, date = react.useRef(new Date(deployment.created)), commitMessage = deployment?.meta?.githubCommitMessage, commitRef = deployment?.meta?.githubCommitRef, targetUrl = deployment.alias ?? deployment.url;
|
|
265
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("tr", { children: [
|
|
266
|
+
/* @__PURE__ */ jsxRuntime.jsx(TableCell, { children: /* @__PURE__ */ jsxRuntime.jsxs(ui.Flex, { align: "center", children: [
|
|
267
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
268
|
+
ui.Box,
|
|
269
|
+
{
|
|
270
|
+
display: ["block", "block", "block", "block", "none"],
|
|
271
|
+
marginRight: 3,
|
|
272
|
+
style: { flexShrink: 0 },
|
|
273
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(StatusDot, { state: deployment.state })
|
|
274
|
+
}
|
|
275
|
+
),
|
|
276
|
+
targetUrl ? /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
277
|
+
deployment.alias && /* @__PURE__ */ jsxRuntime.jsx(icons.LinkIcon, {}),
|
|
278
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Box, { marginLeft: deployment.alias ? 1 : 0, children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
279
|
+
ui.Text,
|
|
280
|
+
{
|
|
281
|
+
muted: deployment.state !== "READY",
|
|
282
|
+
size: 1,
|
|
283
|
+
style: {
|
|
284
|
+
textDecoration: deployment.state === "CANCELED" || deployment.state === "ERROR" ? "line-through" : "normal"
|
|
285
|
+
},
|
|
286
|
+
textOverflow: "ellipsis",
|
|
287
|
+
children: deployment.state === "READY" ? /* @__PURE__ */ jsxRuntime.jsx("a", { href: `https://${targetUrl}`, rel: "noopener noreferrer", target: "_blank", children: targetUrl }) : targetUrl
|
|
288
|
+
}
|
|
289
|
+
) })
|
|
290
|
+
] }) : /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: 1, children: "Uploading..." })
|
|
291
|
+
] }) }),
|
|
292
|
+
/* @__PURE__ */ jsxRuntime.jsx(TableCell, { variant: "state", children: /* @__PURE__ */ jsxRuntime.jsxs(ui.Flex, { align: "center", children: [
|
|
293
|
+
/* @__PURE__ */ jsxRuntime.jsx(StatusDot, { state: deployment.state }),
|
|
294
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Box, { marginLeft: 2, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: 1, children: deployment.state.trim().toLowerCase().replace(/^[a-z]/i, (t) => t.toUpperCase()) }) })
|
|
295
|
+
] }) }),
|
|
296
|
+
/* @__PURE__ */ jsxRuntime.jsx(TableCell, { variant: "branch", children: /* @__PURE__ */ jsxRuntime.jsxs(ui.Stack, { space: 2, children: [
|
|
297
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: 1, textOverflow: "ellipsis", children: commitRef }),
|
|
298
|
+
commitMessage && /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { muted: !0, size: 1, textOverflow: "ellipsis", children: commitMessage })
|
|
299
|
+
] }) }),
|
|
300
|
+
/* @__PURE__ */ jsxRuntime.jsx(TableCell, { variant: "age", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Flex, { align: "center", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: 1, children: /* @__PURE__ */ jsxRuntime.jsx(ReactTimeAgo__default.default, { date: date.current, locale: "en-US", timeStyle: "mini" }) }) }) }),
|
|
301
|
+
/* @__PURE__ */ jsxRuntime.jsx(TableCell, { variant: "creator", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Flex, { align: "center", justify: "center", children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
302
|
+
"img",
|
|
303
|
+
{
|
|
304
|
+
draggable: !1,
|
|
305
|
+
src: `https://vercel.com/api/www/avatar/${deployment?.creator?.uid}?&s=48`,
|
|
306
|
+
style: {
|
|
307
|
+
borderRadius: "20px",
|
|
308
|
+
height: "20px",
|
|
309
|
+
width: "20px"
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
) }) })
|
|
313
|
+
] });
|
|
314
|
+
}, deployMachine = (deployHook) => xstate.Machine(
|
|
315
|
+
// Machine
|
|
316
|
+
{
|
|
317
|
+
id: "deploy",
|
|
318
|
+
initial: "idle",
|
|
319
|
+
context: {
|
|
320
|
+
disabled: !1,
|
|
321
|
+
feedback: void 0,
|
|
322
|
+
label: void 0,
|
|
323
|
+
error: void 0
|
|
324
|
+
},
|
|
325
|
+
states: {
|
|
326
|
+
idle: {
|
|
327
|
+
entry: xstate.assign({
|
|
328
|
+
feedback: () => {
|
|
329
|
+
},
|
|
330
|
+
label: () => "Deploy"
|
|
331
|
+
}),
|
|
332
|
+
on: {
|
|
333
|
+
DEPLOY: "deploying"
|
|
334
|
+
}
|
|
335
|
+
},
|
|
336
|
+
deploying: {
|
|
337
|
+
entry: xstate.assign({
|
|
338
|
+
disabled: () => !0,
|
|
339
|
+
label: () => "Deploying"
|
|
340
|
+
}),
|
|
341
|
+
exit: xstate.assign({
|
|
342
|
+
disabled: () => !1,
|
|
343
|
+
label: () => "Deploy"
|
|
344
|
+
}),
|
|
345
|
+
invoke: {
|
|
346
|
+
onDone: {
|
|
347
|
+
target: "success"
|
|
348
|
+
},
|
|
349
|
+
onError: {
|
|
350
|
+
target: "error",
|
|
351
|
+
actions: xstate.assign({
|
|
352
|
+
error: (_context, event) => event.data
|
|
353
|
+
})
|
|
354
|
+
},
|
|
355
|
+
src: "deploy"
|
|
356
|
+
}
|
|
357
|
+
},
|
|
358
|
+
success: {
|
|
359
|
+
entry: [xstate.assign({ feedback: () => "Succesfully started!" })],
|
|
360
|
+
exit: xstate.assign({
|
|
361
|
+
feedback: () => {
|
|
362
|
+
}
|
|
363
|
+
}),
|
|
364
|
+
on: {
|
|
365
|
+
DEPLOY: "deploying"
|
|
366
|
+
}
|
|
367
|
+
},
|
|
368
|
+
error: {
|
|
369
|
+
on: {
|
|
370
|
+
DEPLOY: "deploying"
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
},
|
|
375
|
+
// Config
|
|
376
|
+
{
|
|
377
|
+
services: {
|
|
378
|
+
deploy: () => new Promise(async (resolve, reject) => {
|
|
379
|
+
try {
|
|
380
|
+
if (!deployHook)
|
|
381
|
+
return reject(new Error("No deployHook URL defined"));
|
|
382
|
+
const res = await fetch__default.default(deployHook, { method: "POST" }), data = await res.json();
|
|
383
|
+
if (!res.ok) {
|
|
384
|
+
const errorMessage = (data?.error).message || res.statusText;
|
|
385
|
+
return reject(errorMessage);
|
|
386
|
+
}
|
|
387
|
+
return resolve();
|
|
388
|
+
} catch (err) {
|
|
389
|
+
return console.error("Unable to deploy with error:", err), reject(new Error("Please check the developer console for more information"));
|
|
390
|
+
}
|
|
391
|
+
})
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
), DeployButton = (props) => {
|
|
395
|
+
const { deployHook, onDeploySuccess, targetName } = props, machine = react.useMemo(() => deployMachine(deployHook), [deployHook]), [deployState, deployStateTransition, deployStateInterpreter] = react$1.useMachine(machine), toast = ui.useToast(), isError = deployState.matches("error"), isSuccess = deployState.matches("success"), handleDeploy = () => {
|
|
396
|
+
deployStateTransition({ type: "DEPLOY" });
|
|
397
|
+
};
|
|
398
|
+
return react.useEffect(() => {
|
|
399
|
+
isError && toast.push({
|
|
400
|
+
closable: !0,
|
|
401
|
+
description: `Unable to queue deploy for ${targetName}: ${deployState.context.error}`,
|
|
402
|
+
duration: 8e3,
|
|
403
|
+
status: "error",
|
|
404
|
+
title: WIDGET_NAME
|
|
405
|
+
}), isSuccess && toast.push({
|
|
406
|
+
closable: !0,
|
|
407
|
+
description: `Deploy queued for ${targetName}`,
|
|
408
|
+
duration: 8e3,
|
|
409
|
+
status: "success",
|
|
410
|
+
title: WIDGET_NAME
|
|
411
|
+
});
|
|
412
|
+
}, [isError, isSuccess, toast, targetName, deployState.context.error]), react.useEffect(() => {
|
|
413
|
+
deployStateInterpreter.onTransition((state) => {
|
|
414
|
+
state.value === "success" && onDeploySuccess && onDeploySuccess();
|
|
415
|
+
});
|
|
416
|
+
}, [deployStateInterpreter, onDeploySuccess]), /* @__PURE__ */ jsxRuntime.jsxs(ui.Box, { padding: 3, style: { position: "relative" }, children: [
|
|
417
|
+
/* @__PURE__ */ jsxRuntime.jsx(StateDebug, { name: "Deploy", state: deployState }),
|
|
418
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
419
|
+
ui.Button,
|
|
420
|
+
{
|
|
421
|
+
disabled: deployState.context.disabled,
|
|
422
|
+
fontSize: 1,
|
|
423
|
+
icon: icons.UploadIcon,
|
|
424
|
+
mode: "ghost",
|
|
425
|
+
onClick: handleDeploy,
|
|
426
|
+
padding: 3,
|
|
427
|
+
text: `${deployState.context.label} ${targetName}`,
|
|
428
|
+
tone: "default"
|
|
429
|
+
}
|
|
430
|
+
)
|
|
431
|
+
] });
|
|
432
|
+
}, PlaceholderAvatar = () => {
|
|
433
|
+
const { border } = useCardColor();
|
|
434
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
435
|
+
ui.Box,
|
|
436
|
+
{
|
|
437
|
+
style: {
|
|
438
|
+
backgroundColor: border,
|
|
439
|
+
borderRadius: "20px",
|
|
440
|
+
height: "20px",
|
|
441
|
+
userSelect: "none",
|
|
442
|
+
width: "20px"
|
|
443
|
+
}
|
|
444
|
+
}
|
|
445
|
+
);
|
|
446
|
+
}, PlaceholderText = (props) => {
|
|
447
|
+
const { rows } = props, { border } = useCardColor();
|
|
448
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
449
|
+
ui.Box,
|
|
450
|
+
{
|
|
451
|
+
style: {
|
|
452
|
+
backgroundColor: border,
|
|
453
|
+
borderRadius: "3px",
|
|
454
|
+
userSelect: "none",
|
|
455
|
+
width: "100%"
|
|
456
|
+
},
|
|
457
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(ui.Stack, { space: 2, children: new Array(rows).fill(void 0).map((_, index) => /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: 1, children: "\xA0" }, index)) })
|
|
458
|
+
}
|
|
459
|
+
);
|
|
460
|
+
}, DeploymentPlaceholder = () => /* @__PURE__ */ jsxRuntime.jsxs("tr", { children: [
|
|
461
|
+
/* @__PURE__ */ jsxRuntime.jsx(TableCell, { children: /* @__PURE__ */ jsxRuntime.jsx(PlaceholderText, { rows: 1 }) }),
|
|
462
|
+
/* @__PURE__ */ jsxRuntime.jsx(TableCell, { variant: "state", children: /* @__PURE__ */ jsxRuntime.jsx(PlaceholderText, { rows: 1 }) }),
|
|
463
|
+
/* @__PURE__ */ jsxRuntime.jsx(TableCell, { variant: "branch", children: /* @__PURE__ */ jsxRuntime.jsx(PlaceholderText, { rows: 2 }) }),
|
|
464
|
+
/* @__PURE__ */ jsxRuntime.jsx(TableCell, { variant: "age", children: /* @__PURE__ */ jsxRuntime.jsx(PlaceholderText, { rows: 1 }) }),
|
|
465
|
+
/* @__PURE__ */ jsxRuntime.jsx(TableCell, { variant: "creator", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Flex, { justify: "center", children: /* @__PURE__ */ jsxRuntime.jsx(PlaceholderAvatar, {}) }) })
|
|
466
|
+
] }), Deployments = (props) => {
|
|
467
|
+
const { deploymentTarget } = props, refTimeout = react.useRef(null), [refreshState, refreshStateTransition] = react$1.useMachine(refreshMachine), { deployments, error, isFetching, isSuccess, refetch } = useDeployments(deploymentTarget, {
|
|
468
|
+
enabled: !refreshState.matches("error")
|
|
469
|
+
}), toast = ui.useToast(), isError = refreshState.matches("error"), handleDeploySuccess = () => {
|
|
470
|
+
refTimeout.current && clearTimeout(refTimeout.current), refTimeout.current = setTimeout(() => {
|
|
471
|
+
refetch({
|
|
472
|
+
cancelRefetch: !0,
|
|
473
|
+
throwOnError: !0
|
|
474
|
+
});
|
|
475
|
+
}, 4e3);
|
|
476
|
+
};
|
|
477
|
+
react.useEffect(() => () => {
|
|
478
|
+
refTimeout.current && clearTimeout(refTimeout.current);
|
|
479
|
+
}, []), react.useEffect(() => {
|
|
480
|
+
error && refreshStateTransition({ type: "ERROR" }), isFetching && refreshStateTransition({ type: "REFRESH" }), !isFetching && isSuccess && refreshStateTransition({ type: "REFRESHED" });
|
|
481
|
+
}, [error, isFetching, isSuccess, refreshStateTransition]), useDeepCompareEffect__default.default(() => {
|
|
482
|
+
refreshState.matches("refreshing") || refreshStateTransition({ type: "REFRESH" });
|
|
483
|
+
}, [deploymentTarget]), useDeepCompareEffect__default.default(() => {
|
|
484
|
+
isError && toast.push({
|
|
485
|
+
closable: !0,
|
|
486
|
+
description: `Unable to fetch deployments for ${deploymentTarget.name}`,
|
|
487
|
+
duration: 8e3,
|
|
488
|
+
status: "error",
|
|
489
|
+
title: WIDGET_NAME
|
|
490
|
+
});
|
|
491
|
+
}, [deploymentTarget, isError]);
|
|
492
|
+
const hasFetched = typeof deployments < "u", hasDeployments = deployments && deployments.length > 0, { border } = useCardColor();
|
|
493
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(ui.Box, { marginTop: 3, style: { position: "relative" }, children: [
|
|
494
|
+
/* @__PURE__ */ jsxRuntime.jsx(StateDebug, { name: "Refresh", state: refreshState }),
|
|
495
|
+
!refreshState.matches("error") && /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
496
|
+
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
497
|
+
ui.Box,
|
|
498
|
+
{
|
|
499
|
+
as: "table",
|
|
500
|
+
style: {
|
|
501
|
+
borderBottom: `1px solid ${border}`,
|
|
502
|
+
borderCollapse: "collapse",
|
|
503
|
+
display: "table",
|
|
504
|
+
tableLayout: "fixed",
|
|
505
|
+
width: "100%"
|
|
506
|
+
},
|
|
507
|
+
children: [
|
|
508
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Box, { as: "thead", style: { display: "table-header-group" }, children: /* @__PURE__ */ jsxRuntime.jsxs("tr", { children: [
|
|
509
|
+
/* @__PURE__ */ jsxRuntime.jsx(TableCell, { header: !0, children: "Deployment" }),
|
|
510
|
+
/* @__PURE__ */ jsxRuntime.jsx(TableCell, { header: !0, variant: "state", children: "State" }),
|
|
511
|
+
/* @__PURE__ */ jsxRuntime.jsx(TableCell, { header: !0, variant: "branch", children: "Branch" }),
|
|
512
|
+
/* @__PURE__ */ jsxRuntime.jsx(TableCell, { header: !0, variant: "age", children: "Age" }),
|
|
513
|
+
/* @__PURE__ */ jsxRuntime.jsx(TableCell, { header: !0, variant: "age", children: "Creator" })
|
|
514
|
+
] }) }),
|
|
515
|
+
/* @__PURE__ */ jsxRuntime.jsxs(ui.Box, { as: "tbody", style: { display: "table-header-group" }, children: [
|
|
516
|
+
!deployments && new Array(deploymentTarget?.deployLimit).fill(void 0).map((_, index) => /* @__PURE__ */ jsxRuntime.jsx(DeploymentPlaceholder, {}, index)),
|
|
517
|
+
hasDeployments && deployments?.map((deployment) => /* @__PURE__ */ jsxRuntime.jsx(Deployment, { deployment }, deployment.uid))
|
|
518
|
+
] })
|
|
519
|
+
]
|
|
520
|
+
}
|
|
521
|
+
),
|
|
522
|
+
hasFetched && !hasDeployments && /* @__PURE__ */ jsxRuntime.jsx(ui.Box, { padding: 3, style: { width: "100%" }, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { muted: !0, size: 1, children: "No deployments found. Don't forget to specify a valid team ID if your project belongs to a team." }) })
|
|
523
|
+
] }),
|
|
524
|
+
refreshState.matches("error") && /* @__PURE__ */ jsxRuntime.jsx(ui.Box, { padding: 3, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { muted: !0, size: 1, children: "Unable to fetch recent deployments. Please check your network and deployment settings." }) }),
|
|
525
|
+
!refreshState.matches("error") && deploymentTarget.deployHook && /* @__PURE__ */ jsxRuntime.jsx(ui.Box, { children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
526
|
+
DeployButton,
|
|
527
|
+
{
|
|
528
|
+
deployHook: deploymentTarget.deployHook,
|
|
529
|
+
onDeploySuccess: handleDeploySuccess,
|
|
530
|
+
targetName: deploymentTarget.name
|
|
531
|
+
}
|
|
532
|
+
) })
|
|
533
|
+
] });
|
|
534
|
+
}, DeploymentTarget = (props) => {
|
|
535
|
+
const { item, onDialogEdit } = props, deploymentTarget = {
|
|
536
|
+
deployHook: item.deployHook,
|
|
537
|
+
deployLimit: item.deployLimit,
|
|
538
|
+
name: item.name,
|
|
539
|
+
projectId: item.projectId,
|
|
540
|
+
teamId: item.teamId,
|
|
541
|
+
token: item.token
|
|
542
|
+
};
|
|
543
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(ui.Box, { style: { position: "relative" }, children: [
|
|
544
|
+
/* @__PURE__ */ jsxRuntime.jsxs(ui.Flex, { align: "center", justify: "space-between", marginTop: 2, paddingX: 3, children: [
|
|
545
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: 2, children: item.name }),
|
|
546
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
547
|
+
ui.Tooltip,
|
|
548
|
+
{
|
|
549
|
+
content: /* @__PURE__ */ jsxRuntime.jsx(ui.Box, { padding: 2, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { muted: !0, size: 1, children: "Edit deployment target" }) }),
|
|
550
|
+
placement: "left",
|
|
551
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { fontSize: 1, icon: icons.EditIcon, mode: "bleed", onClick: () => onDialogEdit(item) })
|
|
552
|
+
}
|
|
553
|
+
)
|
|
554
|
+
] }),
|
|
555
|
+
/* @__PURE__ */ jsxRuntime.jsx(Deployments, { deploymentTarget })
|
|
556
|
+
] });
|
|
557
|
+
}, DeploymentTargets = (props) => {
|
|
558
|
+
const { items, onDialogEdit } = props;
|
|
559
|
+
return /* @__PURE__ */ jsxRuntime.jsx(ui.Stack, { space: 5, children: items?.map((item) => /* @__PURE__ */ jsxRuntime.jsx(DeploymentTarget, { item, onDialogEdit }, item._id)) });
|
|
560
|
+
}, formMachine = xstate.Machine(
|
|
561
|
+
{
|
|
562
|
+
context: {
|
|
563
|
+
formData: {},
|
|
564
|
+
message: ""
|
|
565
|
+
},
|
|
566
|
+
initial: "idle",
|
|
567
|
+
states: {
|
|
568
|
+
idle: {
|
|
569
|
+
on: {
|
|
570
|
+
CREATE: {
|
|
571
|
+
actions: ["createDocument"],
|
|
572
|
+
target: "creating"
|
|
573
|
+
},
|
|
574
|
+
DELETE: {
|
|
575
|
+
actions: ["deleteDocument"],
|
|
576
|
+
target: "deleting"
|
|
577
|
+
},
|
|
578
|
+
UPDATE: {
|
|
579
|
+
actions: ["updateDocument"],
|
|
580
|
+
target: "updating"
|
|
581
|
+
}
|
|
582
|
+
}
|
|
583
|
+
},
|
|
584
|
+
creating: {
|
|
585
|
+
invoke: {
|
|
586
|
+
src: "createDocumentService",
|
|
587
|
+
onDone: { target: "success" },
|
|
588
|
+
onError: { actions: ["setMessage"], target: "error" }
|
|
589
|
+
},
|
|
590
|
+
on: {
|
|
591
|
+
RESOLVE: "success",
|
|
592
|
+
REJECT: "error"
|
|
593
|
+
}
|
|
594
|
+
},
|
|
595
|
+
updating: {
|
|
596
|
+
invoke: {
|
|
597
|
+
src: "updateDocumentService",
|
|
598
|
+
onDone: { target: "success" },
|
|
599
|
+
onError: { actions: ["setMessage"], target: "error" }
|
|
600
|
+
},
|
|
601
|
+
on: {
|
|
602
|
+
RESOLVE: "success",
|
|
603
|
+
REJECT: "error"
|
|
604
|
+
}
|
|
605
|
+
},
|
|
606
|
+
deleting: {
|
|
607
|
+
invoke: {
|
|
608
|
+
src: "deleteDocumentService",
|
|
609
|
+
onDone: { target: "success" },
|
|
610
|
+
onError: { actions: ["setMessage"], target: "error" }
|
|
611
|
+
},
|
|
612
|
+
on: {
|
|
613
|
+
RESOLVE: "success",
|
|
614
|
+
REJECT: "error"
|
|
615
|
+
}
|
|
616
|
+
},
|
|
617
|
+
success: {
|
|
618
|
+
invoke: {
|
|
619
|
+
src: "formSubmittedService"
|
|
620
|
+
}
|
|
621
|
+
},
|
|
622
|
+
error: {}
|
|
623
|
+
}
|
|
624
|
+
},
|
|
625
|
+
{
|
|
626
|
+
actions: {
|
|
627
|
+
setMessage: xstate.assign((_context, event) => ({
|
|
628
|
+
message: event.data.details.description
|
|
629
|
+
})),
|
|
630
|
+
createDocument: xstate.assign((_context, event) => ({
|
|
631
|
+
formData: event.formData
|
|
632
|
+
})),
|
|
633
|
+
deleteDocument: xstate.assign(() => ({
|
|
634
|
+
// id: event.id,
|
|
635
|
+
})),
|
|
636
|
+
updateDocument: xstate.assign((_context, event) => ({
|
|
637
|
+
formData: event.formData
|
|
638
|
+
}))
|
|
639
|
+
}
|
|
640
|
+
}
|
|
641
|
+
), sanitizeFormData = (formData) => Object.keys(formData).reduce((acc, key) => {
|
|
642
|
+
const val = formData[key];
|
|
643
|
+
return typeof val == "object" && val !== null && val.constructor !== Array ? acc[key] = sanitizeFormData(val) : val === "" || typeof val > "u" || val?.length === 0 ? acc[key] = null : typeof val == "string" && val ? acc[key] = formData[key].trim() : acc[key] = formData[key], acc;
|
|
644
|
+
}, {}), StyledErrorOutlineIcon = styledComponents.styled(icons.ErrorOutlineIcon)(({ theme }) => ({
|
|
645
|
+
color: theme.sanity.color.spot.red
|
|
646
|
+
})), FormFieldInputLabel = (props) => {
|
|
647
|
+
const { description, error, label, name } = props;
|
|
648
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(ui.Box, { marginBottom: 3, children: [
|
|
649
|
+
/* @__PURE__ */ jsxRuntime.jsxs(ui.Inline, { space: 2, children: [
|
|
650
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Text, { as: "label", htmlFor: name, size: 1, weight: "semibold", children: label }),
|
|
651
|
+
error && /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: 1, children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
652
|
+
ui.Tooltip,
|
|
653
|
+
{
|
|
654
|
+
content: /* @__PURE__ */ jsxRuntime.jsx(ui.Box, { padding: 2, children: /* @__PURE__ */ jsxRuntime.jsxs(ui.Text, { muted: !0, size: 1, children: [
|
|
655
|
+
/* @__PURE__ */ jsxRuntime.jsx(StyledErrorOutlineIcon, { style: { marginRight: "0.1em" } }),
|
|
656
|
+
error.message
|
|
657
|
+
] }) }),
|
|
658
|
+
fallbackPlacements: ["top", "left"],
|
|
659
|
+
placement: "right",
|
|
660
|
+
portal: !0,
|
|
661
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(StyledErrorOutlineIcon, {})
|
|
662
|
+
}
|
|
663
|
+
) })
|
|
664
|
+
] }),
|
|
665
|
+
description && /* @__PURE__ */ jsxRuntime.jsx(ui.Box, { marginY: 3, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { htmlFor: name, muted: !0, size: 1, children: description }) })
|
|
666
|
+
] });
|
|
667
|
+
}, FormFieldInputText = react.forwardRef((props, ref) => {
|
|
668
|
+
const { description, disabled, error, label, name, placeholder, value } = props;
|
|
669
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(ui.Box, { children: [
|
|
670
|
+
/* @__PURE__ */ jsxRuntime.jsx(FormFieldInputLabel, { description, error, label, name }),
|
|
671
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
672
|
+
ui.TextInput,
|
|
673
|
+
{
|
|
674
|
+
autoComplete: "off",
|
|
675
|
+
autoFocus: !0,
|
|
676
|
+
defaultValue: value,
|
|
677
|
+
disabled,
|
|
678
|
+
id: name,
|
|
679
|
+
name,
|
|
680
|
+
placeholder,
|
|
681
|
+
ref
|
|
682
|
+
}
|
|
683
|
+
)
|
|
684
|
+
] });
|
|
685
|
+
});
|
|
686
|
+
function useSanityClient() {
|
|
687
|
+
return sanity.useClient({ apiVersion: API_VERSION });
|
|
688
|
+
}
|
|
689
|
+
const formSchema = yup__namespace.object().shape({
|
|
690
|
+
deployHook: yup__namespace.string().url("Deploy hook must be a valid URL"),
|
|
691
|
+
deployLimit: yup__namespace.number().positive().integer().min(1, "Deploy limit must no less than 1").max(15, "Deploy limit must no higher than 15").typeError("Deploy limit must be a number").required("Deploy limit must be a positive integer between 1 and 15"),
|
|
692
|
+
name: yup__namespace.string().required("Name cannot be empty"),
|
|
693
|
+
projectId: yup__namespace.string().required("Vercel Project ID cannot be empty"),
|
|
694
|
+
teamId: yup__namespace.string(),
|
|
695
|
+
token: yup__namespace.string().required("Vercel Account Token cannot be empty")
|
|
696
|
+
}), DialogForm = (props) => {
|
|
697
|
+
const { deploymentTarget, onClose, onCreate, onDelete, onUpdate } = props, client = useSanityClient(), [formState, formStateTransition] = react$1.useMachine(formMachine, {
|
|
698
|
+
services: {
|
|
699
|
+
formSubmittedService: async () => {
|
|
700
|
+
onClose();
|
|
701
|
+
},
|
|
702
|
+
// TODO: refactor
|
|
703
|
+
createDocumentService: async (_context, event) => {
|
|
704
|
+
let document;
|
|
705
|
+
try {
|
|
706
|
+
return document = await client.create({
|
|
707
|
+
_id: `vercel.${uuid.uuid()}`,
|
|
708
|
+
_type: DEPLOYMENT_TARGET_DOCUMENT_TYPE,
|
|
709
|
+
...event.formData
|
|
710
|
+
}), onCreate && onCreate(document), Promise.resolve();
|
|
711
|
+
} catch (e) {
|
|
712
|
+
return Promise.reject(e);
|
|
713
|
+
}
|
|
714
|
+
},
|
|
715
|
+
// TODO: refactor
|
|
716
|
+
deleteDocumentService: async () => {
|
|
717
|
+
if (deploymentTarget)
|
|
718
|
+
try {
|
|
719
|
+
return await client.delete(deploymentTarget._id), onDelete && onDelete(deploymentTarget._id), Promise.resolve();
|
|
720
|
+
} catch (e) {
|
|
721
|
+
return Promise.reject(e);
|
|
722
|
+
}
|
|
723
|
+
return Promise.resolve();
|
|
724
|
+
},
|
|
725
|
+
// TODO: refactor
|
|
726
|
+
updateDocumentService: async (_context, event) => {
|
|
727
|
+
let document;
|
|
728
|
+
if (deploymentTarget)
|
|
729
|
+
try {
|
|
730
|
+
return document = await client.patch(deploymentTarget._id).set(event.formData).commit(), onUpdate && onUpdate(document), Promise.resolve();
|
|
731
|
+
} catch (e) {
|
|
732
|
+
return Promise.reject(e);
|
|
733
|
+
}
|
|
734
|
+
return Promise.resolve();
|
|
735
|
+
}
|
|
736
|
+
}
|
|
737
|
+
}), formUpdating = formState.matches("creating") || formState.matches("deleting") || formState.matches("updating"), {
|
|
738
|
+
// Read the formState before render to subscribe the form state through Proxy
|
|
739
|
+
formState: { errors, isDirty, isValid },
|
|
740
|
+
handleSubmit,
|
|
741
|
+
register
|
|
742
|
+
} = reactHookForm.useForm({
|
|
743
|
+
defaultValues: {
|
|
744
|
+
deployHook: deploymentTarget?.deployHook || "",
|
|
745
|
+
deployLimit: deploymentTarget?.deployLimit || 5,
|
|
746
|
+
name: deploymentTarget?.name,
|
|
747
|
+
projectId: deploymentTarget?.projectId,
|
|
748
|
+
teamId: deploymentTarget?.teamId || "",
|
|
749
|
+
token: deploymentTarget?.token
|
|
750
|
+
},
|
|
751
|
+
mode: "onChange",
|
|
752
|
+
resolver: yup$1.yupResolver(formSchema)
|
|
753
|
+
}), onSubmit = async (formData) => {
|
|
754
|
+
const sanitizedFormData = sanitizeFormData(formData);
|
|
755
|
+
await formStateTransition(deploymentTarget ? "UPDATE" : "CREATE", {
|
|
756
|
+
formData: sanitizedFormData
|
|
757
|
+
});
|
|
758
|
+
}, handleDelete = () => {
|
|
759
|
+
formStateTransition("DELETE", { id: deploymentTarget?._id });
|
|
760
|
+
};
|
|
761
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
762
|
+
ui.Dialog,
|
|
763
|
+
{
|
|
764
|
+
footer: /* @__PURE__ */ jsxRuntime.jsx(() => /* @__PURE__ */ jsxRuntime.jsx(ui.Box, { padding: 3, children: /* @__PURE__ */ jsxRuntime.jsxs(ui.Flex, { justify: deploymentTarget ? "space-between" : "flex-end", children: [
|
|
765
|
+
deploymentTarget && /* @__PURE__ */ jsxRuntime.jsx(
|
|
766
|
+
ui.Button,
|
|
767
|
+
{
|
|
768
|
+
disabled: formUpdating,
|
|
769
|
+
fontSize: 1,
|
|
770
|
+
mode: "bleed",
|
|
771
|
+
onClick: handleDelete,
|
|
772
|
+
text: "Delete",
|
|
773
|
+
tone: "critical"
|
|
774
|
+
}
|
|
775
|
+
),
|
|
776
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
777
|
+
ui.Button,
|
|
778
|
+
{
|
|
779
|
+
disabled: formUpdating || !isDirty || !isValid,
|
|
780
|
+
fontSize: 1,
|
|
781
|
+
onClick: handleSubmit(onSubmit),
|
|
782
|
+
text: deploymentTarget ? "Update and close" : "Create",
|
|
783
|
+
tone: "primary"
|
|
784
|
+
}
|
|
785
|
+
)
|
|
786
|
+
] }) }), {}),
|
|
787
|
+
header: `${deploymentTarget ? "Edit" : "Create"} deployment target`,
|
|
788
|
+
id: "create",
|
|
789
|
+
onClose,
|
|
790
|
+
width: 1,
|
|
791
|
+
zOffset: Z_INDEX_DIALOG,
|
|
792
|
+
children: /* @__PURE__ */ jsxRuntime.jsxs(ui.Box, { as: "form", padding: 4, onSubmit: handleSubmit(onSubmit), children: [
|
|
793
|
+
/* @__PURE__ */ jsxRuntime.jsx("button", { style: { display: "none" }, tabIndex: -1, type: "submit" }),
|
|
794
|
+
/* @__PURE__ */ jsxRuntime.jsxs(ui.Stack, { space: 5, children: [
|
|
795
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
796
|
+
FormFieldInputText,
|
|
797
|
+
{
|
|
798
|
+
disabled: formUpdating,
|
|
799
|
+
description: "Name displayed in this plugin (e.g. production, staging)",
|
|
800
|
+
error: errors?.name,
|
|
801
|
+
label: "Name",
|
|
802
|
+
name: "name",
|
|
803
|
+
ref: register
|
|
804
|
+
}
|
|
805
|
+
),
|
|
806
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
807
|
+
FormFieldInputText,
|
|
808
|
+
{
|
|
809
|
+
disabled: formUpdating,
|
|
810
|
+
error: errors?.token,
|
|
811
|
+
label: "Vercel Account Token",
|
|
812
|
+
name: "token",
|
|
813
|
+
ref: register
|
|
814
|
+
}
|
|
815
|
+
),
|
|
816
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
817
|
+
FormFieldInputText,
|
|
818
|
+
{
|
|
819
|
+
disabled: formUpdating,
|
|
820
|
+
error: errors?.projectId,
|
|
821
|
+
label: "Vercel Project ID",
|
|
822
|
+
name: "projectId",
|
|
823
|
+
ref: register
|
|
824
|
+
}
|
|
825
|
+
),
|
|
826
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
827
|
+
FormFieldInputText,
|
|
828
|
+
{
|
|
829
|
+
description: "Required only if your project is owned by a team account",
|
|
830
|
+
disabled: formUpdating,
|
|
831
|
+
error: errors?.teamId,
|
|
832
|
+
label: "Vercel Team ID (optional)",
|
|
833
|
+
name: "teamId",
|
|
834
|
+
ref: register
|
|
835
|
+
}
|
|
836
|
+
),
|
|
837
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
838
|
+
FormFieldInputText,
|
|
839
|
+
{
|
|
840
|
+
description: "Enter a valid deploy hook URL to enable manual deploys",
|
|
841
|
+
disabled: formUpdating,
|
|
842
|
+
error: errors?.deployHook,
|
|
843
|
+
label: "Vercel Deploy Hook (optional)",
|
|
844
|
+
name: "deployHook",
|
|
845
|
+
ref: register
|
|
846
|
+
}
|
|
847
|
+
),
|
|
848
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
849
|
+
FormFieldInputText,
|
|
850
|
+
{
|
|
851
|
+
disabled: formUpdating,
|
|
852
|
+
error: errors?.deployLimit,
|
|
853
|
+
label: "Number of deploys to display",
|
|
854
|
+
name: "deployLimit",
|
|
855
|
+
ref: register({ valueAsNumber: !0 })
|
|
856
|
+
}
|
|
857
|
+
)
|
|
858
|
+
] })
|
|
859
|
+
] })
|
|
860
|
+
}
|
|
861
|
+
);
|
|
862
|
+
}, dialogMachine = () => xstate.Machine(
|
|
863
|
+
{
|
|
864
|
+
context: {
|
|
865
|
+
editDeploymentTarget: void 0
|
|
866
|
+
},
|
|
867
|
+
initial: "idle",
|
|
868
|
+
states: {
|
|
869
|
+
idle: {
|
|
870
|
+
entry: xstate.assign({
|
|
871
|
+
editDeploymentTarget: () => {
|
|
872
|
+
}
|
|
873
|
+
}),
|
|
874
|
+
on: {
|
|
875
|
+
CREATE: "create",
|
|
876
|
+
EDIT: {
|
|
877
|
+
actions: ["setEditDeploymentTarget"],
|
|
878
|
+
target: "edit"
|
|
879
|
+
}
|
|
880
|
+
}
|
|
881
|
+
},
|
|
882
|
+
edit: {
|
|
883
|
+
on: {
|
|
884
|
+
CLOSE: "idle"
|
|
885
|
+
}
|
|
886
|
+
},
|
|
887
|
+
create: {
|
|
888
|
+
on: {
|
|
889
|
+
CLOSE: "idle"
|
|
890
|
+
}
|
|
891
|
+
}
|
|
892
|
+
}
|
|
893
|
+
},
|
|
894
|
+
{
|
|
895
|
+
actions: {
|
|
896
|
+
setEditDeploymentTarget: xstate.assign((_context, event) => ({
|
|
897
|
+
editDeploymentTarget: event.deploymentTarget
|
|
898
|
+
}))
|
|
899
|
+
}
|
|
900
|
+
}
|
|
901
|
+
), Widget = () => {
|
|
902
|
+
const client = useSanityClient(), [deploymentTargetListState, deploymentTargetListStateTransition] = react$1.useMachine(
|
|
903
|
+
deploymentTargetListMachine,
|
|
904
|
+
{
|
|
905
|
+
services: {
|
|
906
|
+
fetchDataService: () => client.fetch(`*[_type == "${DEPLOYMENT_TARGET_DOCUMENT_TYPE}"] | order(name asc)`).then((result) => result)
|
|
907
|
+
}
|
|
908
|
+
}
|
|
909
|
+
), [dialogState, dialogStateTransition] = react$1.useMachine(dialogMachine), queryClient = new reactQuery.QueryClient({
|
|
910
|
+
defaultOptions: {
|
|
911
|
+
queries: {
|
|
912
|
+
cacheTime: 0,
|
|
913
|
+
staleTime: 0
|
|
914
|
+
}
|
|
915
|
+
}
|
|
916
|
+
}), handleDialogClose = () => {
|
|
917
|
+
dialogStateTransition("CLOSE");
|
|
918
|
+
}, handleDialogShowCreate = () => {
|
|
919
|
+
dialogStateTransition("CREATE");
|
|
920
|
+
}, handleDialogShowEdit = (deploymentTarget) => {
|
|
921
|
+
dialogStateTransition("EDIT", { deploymentTarget });
|
|
922
|
+
}, handleTargetCreate = (deploymentTarget) => {
|
|
923
|
+
deploymentTargetListStateTransition("CREATE", { deploymentTarget });
|
|
924
|
+
}, handleTargetDelete = (id) => {
|
|
925
|
+
deploymentTargetListStateTransition("DELETE", { id });
|
|
926
|
+
}, handleTargetUpdate = (deploymentTarget) => {
|
|
927
|
+
deploymentTargetListStateTransition("UPDATE", { deploymentTarget });
|
|
928
|
+
};
|
|
929
|
+
return /* @__PURE__ */ jsxRuntime.jsx(ui.ToastProvider, { zOffset: Z_INDEX_TOAST_PROVIDER, children: /* @__PURE__ */ jsxRuntime.jsxs(reactQuery.QueryClientProvider, { client: queryClient, children: [
|
|
930
|
+
/* @__PURE__ */ jsxRuntime.jsxs(ui.Card, { radius: 2, style: { overflow: "hidden " }, children: [
|
|
931
|
+
/* @__PURE__ */ jsxRuntime.jsx(StateDebug, { name: "List", state: deploymentTargetListState }),
|
|
932
|
+
/* @__PURE__ */ jsxRuntime.jsxs(ui.Flex, { align: "center", justify: "space-between", paddingX: 3, paddingY: 2, children: [
|
|
933
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: 5, weight: "semibold", children: "Vercel deployments" }),
|
|
934
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
935
|
+
ui.Tooltip,
|
|
936
|
+
{
|
|
937
|
+
content: /* @__PURE__ */ jsxRuntime.jsx(ui.Box, { padding: 2, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { muted: !0, size: 1, children: "Create new deployment target" }) }),
|
|
938
|
+
placement: "left",
|
|
939
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { fontSize: 1, icon: icons.AddIcon, onClick: handleDialogShowCreate, mode: "bleed" })
|
|
940
|
+
}
|
|
941
|
+
)
|
|
942
|
+
] }),
|
|
943
|
+
/* @__PURE__ */ jsxRuntime.jsxs(ui.Box, { children: [
|
|
944
|
+
deploymentTargetListState.matches("pending") && /* @__PURE__ */ jsxRuntime.jsx(ui.Box, { paddingX: 3, paddingY: 4, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { children: "Loading..." }) }),
|
|
945
|
+
deploymentTargetListState.matches("ready.withoutData") && /* @__PURE__ */ jsxRuntime.jsx(ui.Box, { paddingX: 3, paddingY: 4, children: /* @__PURE__ */ jsxRuntime.jsxs(ui.Text, { children: [
|
|
946
|
+
"No deployment targets found.",
|
|
947
|
+
" ",
|
|
948
|
+
/* @__PURE__ */ jsxRuntime.jsx("a", { onClick: handleDialogShowCreate, style: { cursor: "pointer" }, children: "Create a new target?" })
|
|
949
|
+
] }) }),
|
|
950
|
+
deploymentTargetListState.matches("ready.withData") && /* @__PURE__ */ jsxRuntime.jsx(
|
|
951
|
+
DeploymentTargets,
|
|
952
|
+
{
|
|
953
|
+
items: deploymentTargetListState.context.results,
|
|
954
|
+
onDialogEdit: handleDialogShowEdit
|
|
955
|
+
}
|
|
956
|
+
),
|
|
957
|
+
deploymentTargetListState.matches("failed") && /* @__PURE__ */ jsxRuntime.jsx(ui.Box, { paddingX: 3, paddingY: 4, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { children: "Failed to retrieve deployment targets. Please check the developer console log for more information." }) })
|
|
958
|
+
] })
|
|
959
|
+
] }),
|
|
960
|
+
dialogState.matches("create") && /* @__PURE__ */ jsxRuntime.jsx(DialogForm, { onClose: handleDialogClose, onCreate: handleTargetCreate }),
|
|
961
|
+
dialogState.matches("edit") && /* @__PURE__ */ jsxRuntime.jsx(
|
|
962
|
+
DialogForm,
|
|
963
|
+
{
|
|
964
|
+
deploymentTarget: dialogState.context.editDeploymentTarget,
|
|
965
|
+
onClose: handleDialogClose,
|
|
966
|
+
onDelete: handleTargetDelete,
|
|
967
|
+
onUpdate: handleTargetUpdate
|
|
968
|
+
}
|
|
969
|
+
)
|
|
970
|
+
] }) });
|
|
971
|
+
};
|
|
972
|
+
TimeAgo__default.default.addDefaultLocale(en__default.default);
|
|
973
|
+
function vercelWidget(config = {}) {
|
|
974
|
+
return {
|
|
975
|
+
name: "vercel",
|
|
976
|
+
component: Widget,
|
|
977
|
+
layout: config.layout ?? { width: "full" }
|
|
978
|
+
};
|
|
979
|
+
}
|
|
980
|
+
exports.vercelWidget = vercelWidget;
|
|
2
981
|
//# sourceMappingURL=index.js.map
|