1import{as as pe,an as ve,r as O,c1 as ue,c3 as he,af as n,aJ as $,cd as _e,ba as ge}from"./vendor-B2oIjyY4.js";import{b as xe,p as ye,se as fe,rV as Se,sh as je,si as Ee,sj as Te,sk as Ce,sl as we,sm as be,aT as De,rB as j,e1 as Me,w as Ne,li as Pe,aU as ke,C as M,eM as W,dE as Fe,fb as Ie,R as d,H as Ue,l as z,e5 as Be,T as x,n as H,o as Q,eF as Ve,f8 as Ae,f9 as Je,bR as Le,ad as Oe,c4 as $e,aj as N,y as We}from"./main-CJK8sxkW.js";import{d as ze,e as He,f as Qe,g as qe}from"./types-3TI9bhGX.js";import{d as Re,c as P,v as Ge,g as Ke}from"./utils-Cex3K4B7.js";import{N as Xe,D as Ye}from"./new-version-modal-OlHRNVCD.js";import{u as Ze,f as et,a as tt,T as nt,N as st,E as at,g as it}from"./use-cross-domain-conflict-checker-CT5w5VAk.js";import{a as ot,J as rt,D as ct}from"./description-field-pzhqUyMq.js";import{E as dt}from"./event-type-badge-CeXOx8N9.js";import{e as q}from"./utils-DnDWukUz.js";import"./bounded-range-fetch-CggGfMWc.js";import"./vendor-charts-BqgCVUWx.js";import"./use-domain-attached-sources-DoE7VT40.js";import"./property-suggestions-BI-lsJWT.js";import"./eventSlugs-DR2eMql0.js";import"./slugify-CdzPlCd1.js";import"./index-tMcD_ZuD.js";const R="/events/domains",bt=()=>{var B,V,A,J;const u=xe(),{toast:l}=We(),{workspace:E}=ye(),{event_type_and_name:G,event_version:T}=pe(),{contract:s}=fe(),{getSlug:K}=Se(),{eventContractContextFiltering:h}=ve(),{checkConflict:X,isLoading:k}=Ze(s.id),[Y,C]=O.useState(!1),[Z,F]=O.useState(!1),{eventType:i,eventName:_}=Re(G),y=je(),ee=Ee(),te=Te(),ne=Ce(),I=we({event_plan_id:s.id,name:_,event_type:i??""},{enabled:!!i,keepPreviousData:!0,select:t=>t.event_schemas}),U=be({event_plan_id:s.id,name:_,event_type:i??"",event_version:T??""},{enabled:!!(i&&T),select:t=>{var a;return((a=t.event_schemas)==null?void 0:a[0])??null}}),se=I.isLoading||U.isLoading,w=U.data,e=w&&ze(w),ae=(e==null?void 0:e.event_version)===s.default_schema_version,f=((B=I.data)==null?void 0:B.map(t=>({...t,isDefault:t.event_version===s.default_schema_version})))??[],S=e!=null&&e.schema?ue(e.schema,"description"):null,m=S&&(e!=null&&e.event_type)?He(S,e.event_type,!0):null,c=De({values:{name:e==null?void 0:e.event_name,description:e==null?void 0:e.schema.description,eventType:e==null?void 0:e.event_type,editorState:{isJson:e!=null&&e.schema&&(e!=null&&e.schema.properties)?!qe(S,e==null?void 0:e.event_type,!0).canConvert:!1,json:e!=null&&e.schema?JSON.stringify(S,null,4):"",properties:(m==null?void 0:m.properties)??[Ke()],context:(m==null?void 0:m.context)??[]},onSchemaViolation:e==null?void 0:e.on_schema_violation,onUndeclaredFields:e==null?void 0:e.on_undeclared_fields,includeBuiltInContext:(e==null?void 0:e.include_built_in_context)??!0},resolver:Ge,onError:t=>{if(!t.message)return;if(t.message.includes("already exists in")){c.setError(g===j.Track?"name":"eventType",{message:t.message});return}const a=t.message.includes("Uniqueness violation");g===j.Track&&a?c.setError("name",{message:"Event name must be unique"}):a?c.setError("eventType",{message:`Domain already contains a schema for event type "${g}"`}):c.setError("editorState.json",{message:t.message})},error:"Failed to update event",success:"Event updated",onSubmit:async t=>{var L;if(!(e!=null&&e.id))return;const a=t.editorState.isJson;let p;if(a){const r=t.editorState.json;p=he.parse(r)}else{const r=t.editorState.properties,me=t.editorState.context;p=Qe(r,t.eventType,me)}const o=t.eventType===j.Track?t.name:null;if(o!==e.event_name||t.eventType!==e.event_type){const r=X(o??null,t.eventType);if(r)throw new Error(et(r))}const le=o!==e.event_name||t.eventType!==e.event_type||t.onSchemaViolation!==e.on_schema_violation||t.onUndeclaredFields!==e.on_undeclared_fields||h&&t.includeBuiltInContext!==e.include_built_in_context?f.map(r=>r.id):[],{updateEventSchemaV2:v}=await ee.mutateAsync({input:{id:e.id,workspace_id:E==null?void 0:E.id.toString(),schema:{schema:{...p,description:t.description},...h?{include_built_in_context:t.includeBuiltInContext}:{}},updatesToPropagateAcrossVersions:{event_name:o,event_type:t.eventType,on_schema_violation:t.onSchemaViolation,on_undeclared_fields:t.onUndeclaredFields,...h?{include_built_in_context:t.includeBuiltInContext}:{}},eventSchemaVersionIdsToUpdate:le}});if(v.errors.length>0||!v.schema)throw new Error(((L=v.errors[0])==null?void 0:L.message)||"Unexpected error creating event schema.");u(`../${P({eventName:v.schema.event_name,eventType:v.schema.event_type,eventVersion:v.schema.event_version})}`)}}),g=c.watch("eventType"),ie=c.watch("name"),oe=tt({domainId:s.id,eventType:g,eventName:ie});if(se)return n.jsx(Me,{});const re=async t=>{var a,p;if(!e){N(new Error("No event to create a new version of.")),l({id:"create-event-schema-version",title:"Internal error",message:"Please try again later.",variant:"error"});return}try{const o=await it(K,{slug:s.slug},{event_name:e.event_name||void 0,event_type:e.event_type,event_version:t}),{createEventSchemaV2:D}=await y.mutateAsync({input:{event_name:e.event_name,event_plan_id:e.event_plan_id,event_type:e.event_type,event_version:t,slug:o,schema:e.schema,on_schema_violation:e.on_schema_violation,on_undeclared_fields:e.on_undeclared_fields,...h?{include_built_in_context:e.include_built_in_context}:{}}});l({id:"create-event-schema-version",title:"Event was updated with a new version",variant:"success"}),C(!1),(a=D.schema)!=null&&a.event_version?u(`../${P({eventName:e==null?void 0:e.event_name,eventType:e.event_type,eventVersion:(p=D.schema)==null?void 0:p.event_version})}`):u("../")}catch(o){N(o),l({id:"create-event-schema-version",title:"Failed to create a new event version",message:o.message,variant:"error"})}},ce=async(t=!1)=>
1{if(!t&&f.length>1&&(e==null?void 0:e.event_version)===s.default_schema_version){l({id:"delete-event-schema-version",title:"Cannot delete default version",message:"The default version cannot be deleted ",variant:"error"});return}try{t?await ne.mutateAsync({input:{event_name:e==null?void 0:e.event_name,event_plan_id:(e==null?void 0:e.event_plan_id)??"",event_type:(e==null?void 0:e.event_type)??""}}):await te.mutateAsync({input:{event_name:e==null?void 0:e.event_name,event_plan_id:(e==null?void 0:e.event_plan_id)??"",event_type:(e==null?void 0:e.event_type)??"",event_version:(e==null?void 0:e.event_version)??""}}),l({id:"delete-event-schema-version",title:t?"Event deleted":"Event version deleted",variant:"success"}),u("..")}catch(a){N(a),l({id:"delete-event-schema-version",title:"Failed to delete event version",message:a.message,variant:"error"})}},de=q[i]??q.track,b=((V=e==null?void 0:e.updated_by_user)==null?void 0:V.name)??((A=e==null?void 0:e.created_by_user)==null?void 0:A.name);return n.jsxs(Ne,{variant:"card",title:`Edit event contract | ${s.name}`,crumbs:[{label:"Contracts",link:R},{label:s.name,link:`${R}/${s.id}`},{label:_||$(i??void 0)||"Event"}],header:n.jsxs(M,{flex:1,minWidth:0,gap:2,children:[n.jsxs(d,{flex:1,minWidth:0,align:"center",justify:"space-between",children:[n.jsxs(d,{gap:2,align:"center",children:[n.jsx(Ue,{size:"lg",children:_??n.jsxs(d,{align:"center",gap:2,children:[n.jsx(de,{}),$(i??void 0)]})}),!!i&&!!_&&n.jsx(dt,{eventType:i})]}),n.jsxs(d,{align:"center",gap:2,children:[n.jsxs(z,{children:[n.jsx(Be,{children:n.jsxs(d,{align:"center",gap:1,children:[n.jsx(x,{color:"text.secondary",children:"Version:"}),n.jsx(x,{fontWeight:"semibold",children:T})]})}),n.jsxs(H,{children:[f.map(t=>n.jsx(Q,{onClick:()=>u(`../${P({eventName:e==null?void 0:e.event_name,eventType:(e==null?void 0:e.event_type)??"",eventVersion:t.event_version})}`),disabled:y.isLoading,children:n.jsxs(M,{gap:1,children:[n.jsx(x,{fontWeight:"semibold",children:t.event_version}),n.jsxs(x,{color:"text.secondary",size:"sm",children:["Updated"," ",_e(ge(t.updated_at),{addSuffix:!0})]})]})},t.id)),n.jsx(Ve,{}),n.jsx(Q,{onClick:()=>C(!0),children:"Add version"})]})]}),n.jsxs(z,{children:[n.jsx(Ae,{variant:"secondary"}),n.jsx(H,{children:n.jsx(Je,{permission:{v2:{resource:"event_plan",grant:"can_update",id:s.id}},variant:"danger",icon:Le,isDisabled:y.isLoading,onClick:()=>F(!0),children:"Delete"})})]})]})]}),n.jsx(d,{align:"center",gap:3,children:n.jsxs(d,{align:"center",gap:2,children:[n.jsxs(x,{color:"text.secondary",children:["Last updated:"," ",Oe((e==null?void 0:e.updated_at)??(e==null?void 0:e.created_at)??"")," ",b&&"by"]}),b&&n.jsx($e,{size:"sm",name:b})]})})]}),children:[n.jsx(Pe,{name:"Edit Event Page"}),n.jsx(ke,{form:c,children:n.jsxs(M,{gap:6,children:[n.jsxs(W,{heading:"Configuration",rightContent:n.jsx(Fe,{name:"Event schemas",href:"events/contracts/management"}),children:[n.jsx(nt,{}),g===j.Track&&n.jsx(st,{})]}),n.jsx(W,{heading:"Schema",subheading:n.jsx(ct,{}),rightContent:h?n.jsx(rt,{allowComponentType:!0}):null,children:n.jsx(ot,{allowComponentType:!0,suggestionProps:oe})}),n.jsx(at,{}),n.jsx(Ie,{permission:{v2:{resource:"event_plan",grant:"can_update",id:s.id}},isDisabled:k,tooltip:k?"Checking other domains for conflicting eventsâ¦":void 0}),n.jsx(Xe,{error:(J=y.error)==null?void 0:J.message,invalidNames:f.map(t=>t.event_version),isOpen:Y,onClose:()=>C(!1),onSubmit:re}),n.jsx(Ye,{isDefaultVersion:ae,isOpen:Z,versionName:(e==null?void 0:e.event_version)??"",onClose:()=>F(!1),onSubmit:ce})]})})]})};export{bt as EventSchema}; 2//# sourceMappingURL=event-schema-CHOYJ71P.js.map
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.