1import{aN as B,r as v,aJ as o}from"./@ui-core-DKdciH1Z.js";import{aA as J,F as V,G,H as Z,J as X,bu as Y,bw as K,bx as Q,D as ee,B as D,m as te,bM as re,r as ne,a1 as oe,a2 as se,a3 as ae,c as R,bX as ie,a5 as ce,x as le,E as ue,e as pe,c6 as de,bC as me,k as N}from"./index-C2G-YIep.js";import{S as fe}from"./clock-DcaJYqTc.js";import{C as I}from"./CodeSnippet-Bk-28Z8h.js";import{I as he}from"./Infobox-CRd1iwHS.js";import{T as ye}from"./Tick-DFuGl4nS.js";import{E as ve}from"./react-error-boundary.esm-C5jb-Sjt.js";import{L as Te}from"./@react-router-DaIuhn3X.js";import"./@reactflow-CJzATMj6.js";import"./@zod-ddIhTJP1.js";import"./@monaco-editor-CSMpaClf.js";import"./alert-triangle-DWngjzfY.js";import"./check-tR7EFZ1z.js";async function xe({params:t}){const n=J(t).toString(),s=Z(X.apiToken+(n?`?${n}`:"")),r=await V(s,{credentials:"include",headers:{"Content-Type":"application/json"}});if(!r.ok){const e=await r.json().then(a=>Array.isArray(a.detail)?a.detail[1]:a.detail).catch(()=>"Error while creating API Token");throw new G({status:r.status,statusText:r.statusText,message:e})}return r.json()}function ge(t){return B({mutationFn:async n=>xe(n),...t})}class x extends Error{}x.prototype.name="InvalidTokenError";function be(t){return decodeURIComponent(atob(t).replace(/(.)/g,(n,s)=>{let r=s.charCodeAt(0).toString(16).toUpperCase();return r.length<2&&(r="0"+r),"%"+r}))}function Se(t){let n=t.replace(/-/g,"+").replace(/_/g,"/");switch(n.length%4){case 0:break;case 2:n+="==";break;case 3:n+="=";break;default:throw new Error("base64 string is not of the correct length")}try{return be(n)}catch{return atob(n)}}function je(t,n){if(typeof t!="string")throw new x("Invalid token specified: must be a string");n||(n={});const s=n.header===!0?0:1,r=t.split(".")[s];if(typeof r!="string")throw new x(`Invalid token specified: missing part #${s+1}`);let e;try{e=Se(r)}catch(a){throw new x(`Invalid token specified: invalid base64 for part #${s+1} (${a.message})`)}try{return JSON.parse(e)}catch(a){throw new x(`Invalid token specified: invalid json for part #${s+1} (${a.message})`)}}var b={exports:{}},S,_;function we(){if(_)return S;_=1;var t="SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED";return S=t,S}var j,E;function Pe(){if(E)return j;E=1;var t=we();function n(){}function s(){}return s.resetWarningCache=n,j=function(){function r(i,c,u,m,h,p){if(p!==t){var f=new Error("Calling PropTypes validators directly is not supported by the `prop-types` package. Use PropTypes.checkPropTypes() to call them. Read more at http://fb.me/use-check-prop-types");throw f.name="Invariant Violation",f}}r.isRequired=r;function e(){return r}var a={array:r,bigint:r,bool:r,func:r,number:r,object:r,string:r,symbol:r,any:r,arrayOf:e,element:r,elementType:r,instanceOf:e,node:r,objectOf:e,oneOf:e,oneOfType:e,shape:e,exact:e,checkPropTypes:s,resetWarningCache:n};return a.PropTypes=a,a},j}var A;function ke(){return A||(A=1,b.exports=Pe()()),b.exports}var l=ke();function M(t,n){if(!(t instanceof n))throw new TypeError("Cannot call a class as a function")}function De(t,n){for(var s=0;s<n.length;s++){var r=n[s];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,r.key,r)}}function z(t,n,s){return n&&De(t.prototype,n),t}function $(t,n){if(typeof n!="function"&&n!==null)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(n&&n.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),n&&w(t,n)}function g(t){return g=Object.setPrototypeOf?Object.getPrototypeOf:function(s){return s.__proto__||Object.getPrototypeOf(s)},g(t)}function w(t,n){return w=Object.setPrototypeOf||function(r,e){return r.__proto__=e,r},w(t,n)}function Ce(){if(typeof Reflect>"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],function(){})),!0}catch{return!1}}function Oe(t){if(t===void 0)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}function Ne(t,n){return n&&(typeof n=="object"||typeof n=="function")?n:Oe(t)}function U(t){var n=Ce();return function(){var r=g(t),e;if(n){var a=g(this).constructor;e=Reflect.construct(r,arguments,a)}else e=r.apply(this,arguments);return Ne(this,e)}}function Ie(t){return _e(t)||Ee(t)||Ae(t)||Re()}function _e(t){if(Array.isArray(t))return P(t)}function Ee(t){if(typeof Symbol<"u"&&Symbol.iterator in Object(t))return Array.from(t)}function Ae(t,n){if(t){if(typeof t=="string")return P(t,n);var s=Object.prototype.toString.call(t).slice(8,-1);if(s==="Object"&&t.constructor&&(s=t.constructor.name),s==="Map"||s==="Set")return Array.from(t);if(s==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(s))return P(t,n)}}function P(t,n){(n==null||n>t.length)&&(n=t.length);for(var s=0,r=new Array(n);s<n;s++)r[s]=t[s];return r}function Re(){throw new TypeError(`Invalid attempt to spread non-iterable instance. 2In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}function T(t){var n=arguments.length>1&&arguments[1]!==void 0?arguments[1]:2,s=String(t);if(n===0)return s;var r=s.match(/(.*?)([0-9]+)(.*)/),e=r?r[1]:"",a=r?r[3]:"",i=r?r[2]:s,c=i.length>=n?i:(Ie(Array(n)).map(function(){return"0"}).join("")+i).slice(n*-1);return"".concat(e).concat(c).concat(a)}var F={daysInHours:!1,zeroPadTime:2};function Me(t){var n=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},s=n.now,r=s===void 0?Date.now:s,e=n.precision,a=e===void 0?0:e,i=n.controlled,c=n.offsetTime,u=c===void 0?0:c,m=n.overt
2ime,h;typeof t=="string"?h=new Date(t).getTime():t instanceof Date?h=t.getTime():h=t,i||(h+=u);var p=i?h:h-r(),f=Math.min(20,Math.max(0,a)),d=Math.round(parseFloat(((m?p:Math.max(0,p))/1e3).toFixed(f))*1e3),y=Math.abs(d)/1e3;return{total:d,days:Math.floor(y/(3600*24)),hours:Math.floor(y/3600%24),minutes:Math.floor(y/60%60),seconds:Math.floor(y%60),milliseconds:Number((y%1*1e3).toFixed()),completed:d<=0}}function ze(t,n){var s=t.days,r=t.hours,e=t.minutes,a=t.seconds,i=Object.assign(Object.assign({},F),n),c=i.daysInHours,u=i.zeroPadTime,m=i.zeroPadDays,h=m===void 0?u:m,p=Math.min(2,u),f=c?T(r+s*24,u):T(r,p);return{days:c?"":T(s,h),hours:f,minutes:T(e,p),seconds:T(a,p)}}var H=(function(t){$(s,t);var n=U(s);function s(){var r;return M(this,s),r=n.apply(this,arguments),r.state={count:r.props.count||3},r.startCountdown=function(){r.interval=window.setInterval(function(){var e=r.state.count-1;e===0?(r.stopCountdown(),r.props.onComplete&&r.props.onComplete()):r.setState(function(a){return{count:a.count-1}})},1e3)},r.stopCountdown=function(){clearInterval(r.interval)},r.addTime=function(e){r.stopCountdown(),r.setState(function(a){return{count:a.count+e}},r.startCountdown)},r}return z(s,[{key:"componentDidMount",value:function(){this.startCountdown()}},{key:"componentWillUnmount",value:function(){clearInterval(this.interval)}},{key:"render",value:function(){return this.props.children?v.cloneElement(this.props.children,{count:this.state.count}):null}}]),s})(v.Component);H.propTypes={count:l.number,children:l.element,onComplete:l.func};var C=(function(t){$(s,t);var n=U(s);function s(r){var e;if(M(this,s),e=n.call(this,r),e.mounted=!1,e.initialTimestamp=e.calcOffsetStartTimestamp(),e.offsetStartTimestamp=e.props.autoStart?0:e.initialTimestamp,e.offsetTime=0,e.legacyMode=!1,e.legacyCountdownRef=null,e.tick=function(){var i=e.calcTimeDelta(),c=i.completed&&!e.props.overtime?void 0:e.props.onTick;e.setTimeDeltaState(i,void 0,c)},e.setLegacyCountdownRef=function(i){e.legacyCountdownRef=i},e.start=function(){if(!e.isStarted()){var i=e.offsetStartTimestamp;e.offsetStartTimestamp=0,e.offsetTime+=i?e.calcOffsetStartTimestamp()-i:0;var c=e.calcTimeDelta();e.setTimeDeltaState(c,"STARTED",e.props.onStart),!e.props.controlled&&(!c.completed||e.props.overtime)&&(e.clearTimer(),e.interval=window.setInterval(e.tick,e.props.intervalDelay))}},e.pause=function(){e.isPaused()||(e.clearTimer(),e.offsetStartTimestamp=e.calcOffsetStartTimestamp(),e.setTimeDeltaState(e.state.timeDelta,"PAUSED",e.props.onPause))},e.stop=function(){e.isStopped()||(e.clearTimer(),e.offsetStartTimestamp=e.calcOffsetStartTimestamp(),e.offsetTime=e.offsetStartTimestamp-e.initialTimestamp,e.setTimeDeltaState(e.calcTimeDelta(),"STOPPED",e.props.onStop))},e.isStarted=function(){return e.isStatus("STARTED")},e.isPaused=function(){return e.isStatus("PAUSED")},e.isStopped=function(){return e.isStatus("STOPPED")},e.isCompleted=function(){return e.isStatus("COMPLETED")},r.date){var a=e.calcTimeDelta();e.state={timeDelta:a,status:a.completed?"COMPLETED":"STOPPED"}}else e.legacyMode=!0;return e}return z(s,[{key:"componentDidMount",value:function(){this.legacyMode||(this.mounted=!0,this.props.onMount&&this.props.onMount(this.calcTimeDelta()),this.props.autoStart&&this.start())}},{key:"componentDidUpdate",value:function(e){this.legacyMode||this.props.date!==e.date&&(this.initialTimestamp=this.calcOffsetStartTimestamp(),this.offsetStartTimestamp=this.initialTimestamp,this.offsetTime=0,this.setTimeDeltaState(this.calcTimeDelta()))}},{key:"componentWillUnmount",value:function(){this.legacyMode||(this.mounted=!1,this.clearTimer())}},{key:"calcTimeDelta",value:function(){var e=this.props,a=e.date,i=e.now,c=e.precision,u=e.controlled,m=e.overtime;return Me(a,{now:i,precision:c,controlled:u,offsetTime:this.offsetTime,overtime:m})}},{key:"calcOffsetStartTimestamp",value:function(){return Date.now()}},{key:"addTime",value:function(e){this.legacyCountdownRef.addTime(e)}},{key:"clearTimer",value:function(){window.clearInterval(this.interval)}},{key:"isStatus",value:function(e){return this.state.status===e}},{key:"setTimeDeltaState",value:function(e,a,i){var c=this;
2if(this.mounted){var u=e.completed&&!this.state.timeDelta.completed,m=e.completed&&a==="STARTED";u&&!this.props.overtime&&this.clearTimer();var h=function(){i&&i(c.state.timeDelta),c.props.onComplete&&(u||m)&&c.props.onComplete(e,m)};return this.setState(function(p){var f=a||p.status;return e.completed&&!c.props.overtime?f="COMPLETED":!a&&f==="COMPLETED"&&(f="STOPPED"),{timeDelta:e,status:f}},h)}}},{key:"getApi",value:function(){return this.api=this.api||{start:this.start,pause:this.pause,stop:this.stop,isStarted:this.isStarted,isPaused:this.isPaused,isStopped:this.isStopped,isCompleted:this.isCompleted}}},{key:"getRenderProps",value:function(){var e=this.props,a=e.daysInHours,i=e.zeroPadTime,c=e.zeroPadDays,u=this.state.timeDelta;return Object.assign(Object.assign({},u),{api:this.getApi(),props:this.props,formatted:ze(u,{daysInHours:a,zeroPadTime:i,zeroPadDays:c})})}},{key:"render",value:function(){if(this.legacyMode){var e=this.props,a=e.count,i=e.children,c=e.onComplete;return v.createElement(H,{ref:this.setLegacyCountdownRef,count:a,onComplete:c},i)}var u=this.props,m=u.className,h=u.overtime,p=u.children,f=u.renderer,d=this.getRenderProps();if(f)return f(d);if(p&&this.state.timeDelta.completed&&!h)return v.cloneElement(p,{countdown:d});var y=d.formatted,O=y.days,L=y.hours,W=y.minutes,q=y.seconds;return v.createElement("span",{className:m},d.total<0?"-":"",O,O?":":"",L,":",W,":",q)}}]),s})(v.Component);C.defaultProps=Object.assign(Object.assign({},F),{controlled:!1,intervalDelay:1e3,precision:0,autoStart:!0});C.propTypes={date:l.oneOfType([l.instanceOf(Date),l.string,l.number]),daysInHours:l.bool,zeroPadTime:l.number,zeroPadDays:l.number,controlled:l.bool,intervalDelay:l.number,precision:l.number,autoStart:l.bool,overtime:l.bool,className:l.string,children:l.element,renderer:l.func,now:l.func,onMount:l.func,onStart:l.func,onPause:l.func,onStop:l.func,onTick:l.func,onComplete:l.func};function $e({token:t,open:n,setOpen:s}){return o.jsx(Y,{open:n,onOpenChange:s,children:o.jsxs(K,{className:"max-w-[700px]",children:[o.jsx(Q,{children:o.jsx(ee,{children:"API Token Created Successfully"})}),o.jsxs("div",{className:"space-y-3 overflow-hidden px-7 py-5",children:[o.jsx(Ue,{}),o.jsx(Fe,{}),o.jsx(He,{token:t}),o.jsx(ve,{fallbackRender:()=>null,children:o.jsx(We,{token:t})}),o.jsx("div",{role:"separator","aria-hidden":"true",className:"h-[1px] bg-theme-border-moderate"}),o.jsx(qe,{token:t}),o.jsx(Be,{}),o.jsx("div",{role:"separator","aria-hidden":"true",className:"h-[1px] bg-theme-border-moderate"}),o.jsx(Je,{})]})]})})}function Ue(){return o.jsxs("section",{children:[o.jsx("p",{className:"font-semibold",children:"Here is your new API Token"}),o.jsx("p",{className:"text-theme-text-secondary",children:"This token provides temporary access to your ZenML Server"})]})}function Fe(){return o.jsx(he,{children:"Important: This token expires in 1 hour and cannot be retrieved later. Please, copy it now."})}function He({token:t}){const[n,s]=v.useState(!1);function r(e){navigator.clipboard&&(navigator.clipboard.writeText(e),s(!0),setTimeout(()=>{s(!1)},2e3))}return o.jsxs("section",{className:"flex items-center gap-5 py-5",children:[o.jsx("code",{className:"block overflow-x-auto whitespace-nowrap font-sans text-display-xs",children:t}),n?o.jsxs("div",{className:"flex h-7 items-center",children:[o.jsx(ye,{className:"h-5 w-5 shrink-0 fill-theme-text-tertiary"}),o.jsx("p",{className:"sr-only",children:"copied successfully"})]}):o.jsxs(D,{onClick:()=>r(t),size:"md",intent:"secondary",className:"flex items-center gap-1",emphasis:"subtle",children:[o.jsx(te,{className:"size-4 shrink-0 fill-inherit"}),"Copy"]})]})}const Le=({days:t,hours:n,minutes:s,seconds:r,completed:e})=>{if(e)return o.jsx("span",{className:"font-semibold text-theme-text-error",children:"Expired"});const a=c=>String(c).padStart(2,"0"),i=[];return t>0&&i.push(`${t}`),(t>0||n>0)&&i.push(`${a(n)}
2`),(t>0||n>0||s>0)&&i.push(`${a(s)}`),i.push(`${a(r)}`),o.jsx("span",{className:"font-semibold",children:i.join(":")})};function We({token:t}){if(!t)return null;const n=je(t);return n.exp?o.jsxs("div",{className:"flex flex-wrap items-center justify-center gap-3 rounded-sm border border-theme-border-moderate bg-theme-surface-tertiary py-1 text-center",children:[o.jsx(fe,{className:"size-5 shrink-0 fill-theme-text-secondary"}),o.jsxs("div",{children:["Expires in:"," ",o.jsx(C,{daysInHours:!0,renderer:Le,zeroPadTime:2,date:new Date(n.exp*1e3)})]})]}):null}function qe({token:t}){const n=`${window.location.origin}/api/v1/current-user`;return o.jsxs("section",{className:"space-y-1",children:[o.jsx("div",{className:"font-semibold",children:"Using your API Token"}),o.jsxs("div",{className:"space-y-2",children:[o.jsx("p",{className:"text-theme-text-secondary",children:"To use the API token to run queries against the Server API, you can run the following commands:"}),o.jsx(I,{code:Ve(t,n)}),o.jsx(I,{code:Ge(t,n)})]})]})}function Be(){const t=`${window.location.origin}/docs`;return o.jsxs("section",{className:"space-y-2",children:[o.jsx("p",{className:"font-semibold",children:"API Documentation"}),o.jsx("p",{className:"text-theme-text-secondary",children:"Access our OpenAPI dashboard for comprehensive documentation on all available REST API endpoints:"}),o.jsx(D,{asChild:!0,size:"md",intent:"secondary",className:"flex w-fit items-center gap-1",emphasis:"subtle",children:o.jsxs("a",{target:"_blank",rel:"noopener noreferrer",href:t,children:[o.jsx("span",{children:"Open the documentation"}),o.jsx(re,{className:"size-5 shrink-0 fill-inherit"})]})})]})}function Je(){return o.jsxs("p",{children:["For long-term programmatic access, consider"," ",o.jsx(Te,{className:"link text-theme-text-brand",to:ne.settings.service_accounts.overview,children:"setting up a service account instead."})]})}function Ve(t,n){return`curl -H "Authorization: Bearer ${t}" "${encodeURI(n)}"`}function Ge(t,n){return`wget -qO- --header="Authorization: Bearer ${t}" "${encodeURI(n)}"`}function Ze({size:t}){return o.jsx("div",{className:"flex flex-wrap items-center justify-end gap-2",children:o.jsx(oe,{children:o.jsxs(se,{children:[o.jsx(ae,{className:"z-10",children:o.jsx("div",{className:R(ie({size:t}),"pointer-events-none bg-primary-50"),children:"Create new token"})}),o.jsx(ce,{children:"API-Tokens are not available for local deployments"})]})})})}const k=v.forwardRef(({className:t,onClick:n,...s},r)=>{const{toast:e}=le(),[a,i]=v.useState(""),[c,u]=v.useState(!1),m=ue(),{mutate:h,isPending:p}=ge({onError:d=>{me(d)&&e({title:"Error",emphasis:"subtle",rounded:!0,status:"error",description:d.message}),console.log(d)},onSuccess:d=>{i(d),u(!0)}});function f(d){u(d),d||i("")}return m.isPending?o.jsx(pe,{className:"h-7 w-10"}):m.isError?null:de(m.data.auth_scheme||"other")?o.jsx(Ze,{size:s.size}):o.jsxs(o.Fragment,{children:[o.jsxs(D,{disabled:p,ref:r,...s,onClick:()=>h({params:{token_type:"generic"}}),className:R(t),children:[p&&o.jsx("div",{role:"alert","aria-busy":"true",className:"full h-[20px] w-[20px] animate-spin rounded-rounded border-2 border-theme-text-negative border-b-theme-text-brand"}),"Create new token"]}),o.jsx($e,{open:c,setOpen:f,token:a})]})});k.displayName="CreateTokenButton";function lt(){return o.jsxs(N,{className:"flex flex-col gap-5 p-5",children:[o.jsx("h1",{className:"text-text-xl font-semibold",children:"API Tokens"}),o.jsx("div",{className:"flex items-center justify-end",children:o.jsx(k,{size:"sm"})}),o.jsxs(N,{className:"flex w-full flex-col items-center justify-center space-y-5 p-9 text-center",children:[o.jsxs("div",{className:"space-y-2",children:[o.jsx("h2",{className:"text-display-xs font-semibold",children:"Create a new API Token"}),o.jsx("p",{className:"text-text-xl text-theme-text-secondary",children:"Generate a temporary access key for quick, secure automation tasks in your Tenant. An API Token is temporary (max. 1 hour) and won't be stored anywhere."})]}),o.jsx(k,{size:"md"})]})]})}export{lt as default};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.