openxiangda-contracts 2.16.2 → 2.17.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.
@@ -1,8 +1,8 @@
1
- import{createHash as jn}from"node:crypto";function Wn(e){if(!e||typeof e!="object")return!1;let t=Object.getPrototypeOf(e);return t===Object.prototype||t===null}function et(e,t){if(e===null)return"null";if(typeof e=="string"||typeof e=="boolean")return JSON.stringify(e);if(typeof e=="number"){if(!Number.isFinite(e))throw new TypeError(`JSON number must be finite: ${t}`);return JSON.stringify(e)}if(Array.isArray(e))return`[${e.map((n,i)=>et(n,`${t}[${i}]`)).join(",")}]`;if(Wn(e))return`{${Object.keys(e).filter(i=>e[i]!==void 0).sort((i,r)=>i===r?0:i<r?-1:1).map(i=>`${JSON.stringify(i)}:${et(e[i],`${t}.${i}`)}`).join(",")}}`;let o=e instanceof Date?"Date":e?.constructor?.name||typeof e;throw new TypeError(`Value is not JSON serializable: ${t} (${o})`)}function H(e){return et(e,"$")}function X(e){return jn("sha256").update(H(e)).digest("hex")}var vt=/^[A-Za-z][A-Za-z0-9_]{0,62}$/,nt=/^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/,Bn=["text.short","text.long","text.rich","number.integer","number.decimal","boolean","date","time","datetime","date-range","datetime-range","option.single","option.multiple","cascade.single","cascade.multiple","user.single","user.multiple","department.single","department.multiple","resource-ref.single","resource-ref.multiple","image","signature","address","location","uuid","json","file","serial-number","subtable"],Jn=new Set(Bn),Lt=new Set(["option.multiple","cascade.multiple","user.multiple","department.multiple","resource-ref.multiple","file","image","subtable"]),Vt=new Set(["option.single","option.multiple","cascade.single","cascade.multiple"]),wt=new Set(["resource-ref.single","resource-ref.multiple"]),ot=[{code:"id",type:"uuid",nullable:!1},{code:"revision",type:"number.integer",nullable:!1},{code:"created_by",type:"text.short",nullable:!1},{code:"updated_by",type:"text.short",nullable:!1},{code:"created_at",type:"datetime",nullable:!1},{code:"updated_at",type:"datetime",nullable:!1}],ns=new Map(ot.map(e=>[e.code,e])),ue=class extends Error{constructor(o,n){super(o);this.code=o;this.pointer=n;this.name="NativeDataFieldContractV2Error"}code;pointer};function je(e){return Lt.has(e)}function We(e,t={}){return e.type!=="serial-number"&&t.system!==!0&&e.nullable===!1&&(!je(e.type)||t.requiredHint===!0)}function it(e,t,o=500){Array.isArray(e)||R("NATIVE_ARRAY_REQUIRED",t),e.length===0&&R("NATIVE_DATA_FIELDS_REQUIRED",t),e.length>o&&R("NATIVE_ARRAY_LIMIT_EXCEEDED",t);let n=new Set;return e.map((i,r)=>{let a=`${t}/${r}`,s=oe(i,a);re(s,["code","type","nullable","indexed","options","source","maxLength","precision","scale","min","max","rangeBoundary","timePrecision","file","serial","subtable"],a);let l=ae(s.code,`${a}/code`,63);vt.test(l)||R("NATIVE_FIELD_CODE_INVALID",`${a}/code`),n.has(l)&&R("NATIVE_DATA_FIELD_DUPLICATE",`${a}/code`),n.add(l);let p=ae(s.type,`${a}/type`,32);Jn.has(p)||R("NATIVE_DATA_FIELD_TYPE_INVALID",`${a}/type`);let _=p,d=Pt(s.nullable,`${a}/nullable`),c=Pt(s.indexed,`${a}/indexed`);d===!0&&Lt.has(_)&&R("NATIVE_DATA_MULTI_FIELD_NULLABLE_INVALID",`${a}/nullable`);let A=Yn(s.options,_,a),f=Hn(s.source,_,a),E=qn(s,_,a),N=Gn(s.rangeBoundary,_,a),m=Xn(s.file,_,a),g=Qn(s.serial,_,a),T=Zn(s.subtable,_,a);return{code:l,type:_,...d===void 0?{}:{nullable:d},...c===void 0?{}:{indexed:c},...A?{options:A}:{},...f?{source:f}:{},...E,...N?{rangeBoundary:N}:{},...m?{file:m}:{},...g?{serial:g}:{},...T?{subtable:T}:{}}})}function Gn(e,t,o){let n=`${o}/rangeBoundary`;if(!(t==="date-range"||t==="datetime-range")){e!==void 0&&R("NATIVE_DATA_FIELD_RANGE_BOUNDARY_TYPE_INVALID",n);return}return e!=="closed"&&e!=="half-open"&&R("NATIVE_DATA_FIELD_RANGE_BOUNDARY_REQUIRED",n),e}function kt(e,t){Array.isArray(e)||R("NATIVE_ARRAY_REQUIRED",t);let o=new Map;e.forEach((n,i)=>{let r=`${t}/${i}`,a=oe(n,r),s=ae(a.code,`${r}/code`,64);(!nt.test(s)||o.has(s))&&R("NATIVE_RESOURCE_CODE_INVALID",`${r}/code`);let l=oe(a.schema,`${r}/schema`);o.set(s,{pointer:r,fields:it(l.fields,`${r}/schema/fields`)})});for(let[n,i]of o){let r=new Map(i.fields.map(s=>[s.code,s]));i.fields.filter(s=>s.type==="subtable").reduce((s,l)=>s+(l.subtable?.maxRows??20),0)>49&&R("NATIVE_DATA_FIELD_SUBTABLE_AGGREGATE_MAX_ROWS_EXCEEDED",`${i.pointer}/schema/fields`),i.fields.forEach((s,l)=>{let p=`${i.pointer}/schema/fields/${l}`;if(s.source&&zn(s.source,r,o,`${p}/source`),s.subtable){let _=o.get(s.subtable.resourceCode);(!_||s.subtable.resourceCode===n)&&R("NATIVE_DATA_FIELD_SUBTABLE_TARGET_MISSING",`${p}/subtable/resourceCode`);let d=_.fields.find(A=>A.code===s.subtable?.foreignKey);(!d||d.type!=="uuid"||d.nullable!==!1)&&R("NATIVE_DATA_FIELD_SUBTABLE_FOREIGN_KEY_INVALID",`${p}/subtable/foreignKey`);let c=_.fields.find(A=>A.code===s.subtable?.orderField);(!c||c.type!=="number.integer"||c.nullable!==!1)&&R("NATIVE_DATA_FIELD_SUBTABLE_ORDER_FIELD_INVALID",`${p}/subtable/orderField`)}})}}function xt(e,t,o){if(e===void 0)return[];(!Array.isArray(e)||e.length>20)&&R("NATIVE_DATA_RESOURCE_INVARIANTS_INVALID",o);let n=new Map(t.map(r=>[r.code,r])),i=new Set;return e.map((r,a)=>{let s=`${o}/${a}`,l=oe(r,s);re(l,["code","message","expression"],s);let p=ae(l.code,`${s}/code`,128);(!/^[a-z][a-z0-9]*(?:[._-][a-z0-9]+)*$/.test(p)||i.has(p))&&R("NATIVE_DATA_RESOURCE_INVARIANT_CODE_INVALID",`${s}/code`),i.add(p);let _=Me(l.message,`${s}/message`,500);_!==void 0&&_.length===0&&R("NATIVE_DATA_RESOURCE_INVARIANT_MESSAGE_INVALID",`${s}/message`);let d=oe(l.expression,`${s}/expression`);re(d,["leftField","operator","rightField"],`${s}/expression`);let c=fe(d.leftField,`${s}/expression/leftField`),A=fe(d.rightField,`${s}/expression/rightField`),f=n.get(c),E=n.get(A);(!f||!E)&&R("NATIVE_DATA_RESOURCE_INVARIANT_FIELD_UNKNOWN",`${s}/expression`),f.type===E.type||["number.integer","number.decimal"].includes(f.type)&&["number.integer","number.decimal"].includes(E.type)||R("NATIVE_DATA_RESOURCE_INVARIANT_FIELD_TYPES_INVALID",`${s}/expression`);let m=String(d.operator);return["eq","neq","gt","gte","lt","lte"].includes(m)||R("NATIVE_DATA_RESOURCE_INVARIANT_OPERATOR_INVALID",`${s}/expression/operator`),!["eq","neq"].includes(m)&&!["number.integer","number.decimal","date","time","datetime","text.short","text.long","text.rich","serial-number","uuid"].includes(f.type)&&R("NATIVE_DATA_RESOURCE_INVARIANT_FIELD_TYPES_INVALID",`${s}/expression`),{code:p,..._===void 0?{}:{message:_},expression:{leftField:c,operator:m,rightField:A}}})}function zn(e,t,o,n){let i=o.get(e.resourceCode);i||R("NATIVE_DATA_FIELD_SOURCE_TARGET_MISSING",`${n}/resourceCode`);let r=new Map(i.fields.map(s=>[s.code,s])),a=r.get(e.labelField);(!a||!["text.short","text.long"].includes(a.type))&&R("NATIVE_DATA_FIELD_SOURCE_LABEL_INVALID",`${n}/labelField`);for(let s of["searchFields","descriptionFields","snapshotFields"])for(let l of e[s]||[])r.has(l)||R("NATIVE_DATA_FIELD_SOURCE_FIELD_MISSING",`${n}/${s}`);for(let[s,l]of(e.filters||[]).entries())r.has(l.field)||R("NATIVE_DATA_FIELD_SOURCE_FILTER_FIELD_MISSING",`${n}/filters/${s}/field`),"binding"in l&&!t.has(l.binding.field)&&R("NATIVE_DATA_FIELD_SOURCE_BINDING_FIELD_MISSING",`${n}/filters/${s}/binding/field`)}function Yn(e,t,o){let n=`${o}/options`;if(e===void 0){Vt.has(t)&&R("NATIVE_DATA_FIELD_OPTIONS_REQUIRED",n);return}(!Vt.has(t)||!Array.isArray(e))&&R("NATIVE_DATA_FIELD_OPTIONS_TYPE_INVALID",n),(e.length<1||e.length>100)&&R("NATIVE_DATA_FIELD_OPTIONS_INVALID",n);let i=0,r=(a,s,l)=>{l>5&&R("NATIVE_DATA_FIELD_OPTIONS_DEPTH_EXCEEDED",s);let p=new Set;return a.map((_,d)=>{i+=1,i>1e3&&R("NATIVE_DATA_FIELD_OPTIONS_COUNT_EXCEEDED",n);let c=`${s}/${d}`,A=oe(_,c);re(A,["label","value","description","color","children"],c);let f=ae(A.label,`${c}/label`,500),E=ae(A.value,`${c}/value`,500);p.has(E)&&R("NATIVE_DATA_FIELD_OPTION_VALUE_DUPLICATE",`${c}/value`),p.add(E);let N=Me(A.description,`${c}/description`,2e3),m=Me(A.color,`${c}/color`,64),g;return A.children!==void 0&&((!t.startsWith("cascade.")||!Array.isArray(A.children))&&R("NATIVE_DATA_FIELD_OPTION_CHILDREN_INVALID",`${c}/children`),(A.children.length<1||A.children.length>100)&&R("NATIVE_DATA_FIELD_OPTION_CHILDREN_INVALID",`${c}/children`),g=r(A.children,`${c}/children`,l+1)),{label:f,value:E,...N===void 0?{}:{description:N},...m===void 0?{}:{color:m},...g?{children:g}:{}}})};return r(e,n,1)}function Hn(e,t,o){let n=`${o}/source`;if(e===void 0){wt.has(t)&&R("NATIVE_DATA_FIELD_SOURCE_REQUIRED",n);return}wt.has(t)||R("NATIVE_DATA_FIELD_SOURCE_TYPE_INVALID",n);let i=oe(e,n);re(i,["kind","resourceCode","labelField","searchFields","descriptionFields","snapshotFields","filters","pageSize","loadMode"],n),i.kind!=="resource"&&R("NATIVE_DATA_FIELD_SOURCE_KIND_INVALID",`${n}/kind`);let r=ae(i.resourceCode,`${n}/resourceCode`,64);nt.test(r)||R("NATIVE_RESOURCE_CODE_INVALID",`${n}/resourceCode`);let a=fe(i.labelField,`${n}/labelField`),s=tt(i.searchFields,`${n}/searchFields`,10),l=tt(i.descriptionFields,`${n}/descriptionFields`,10),p=tt(i.snapshotFields,`${n}/snapshotFields`,50),_=be(i.pageSize,`${n}/pageSize`,1,100),d;i.loadMode!==void 0&&(["search","all"].includes(String(i.loadMode))||R("NATIVE_DATA_FIELD_SOURCE_LOAD_MODE_INVALID",`${n}/loadMode`),d=i.loadMode);let c=Kn(i.filters,`${n}/filters`);return{kind:"resource",resourceCode:r,labelField:a,...s?{searchFields:s}:{},...l?{descriptionFields:l}:{},...p?{snapshotFields:p}:{},...c?{filters:c}:{},..._===void 0?{}:{pageSize:_},...d?{loadMode:d}:{}}}function Kn(e,t){if(e!==void 0)return(!Array.isArray(e)||e.length>20)&&R("NATIVE_DATA_FIELD_SOURCE_FILTERS_INVALID",t),e.map((o,n)=>{let i=`${t}/${n}`,r=oe(o,i),a=Object.prototype.hasOwnProperty.call(r,"value"),s=Object.prototype.hasOwnProperty.call(r,"binding");re(r,a?["field","operator","value"]:["field","operator","binding"],i),a===s&&R("NATIVE_DATA_FIELD_SOURCE_FILTER_VALUE_INVALID",i);let l=fe(r.field,`${i}/field`);["eq","in"].includes(String(r.operator))||R("NATIVE_DATA_FIELD_SOURCE_FILTER_OPERATOR_INVALID",`${i}/operator`);let p=r.operator;if(a)return{field:l,operator:p,value:r.value};let _=oe(r.binding,`${i}/binding`);return re(_,["kind","field"],`${i}/binding`),_.kind!=="field"&&R("NATIVE_DATA_FIELD_SOURCE_BINDING_KIND_INVALID",`${i}/binding/kind`),{field:l,operator:p,binding:{kind:"field",field:fe(_.field,`${i}/binding/field`)}}})}function qn(e,t,o){let n={};if(e.maxLength!==void 0&&(["text.short","text.long","text.rich"].includes(t)||R("NATIVE_DATA_FIELD_MAX_LENGTH_TYPE_INVALID",`${o}/maxLength`),n.maxLength=Ue(e.maxLength,`${o}/maxLength`,1,1e6)),(e.precision!==void 0||e.scale!==void 0)&&((t!=="number.decimal"||e.precision===void 0)&&R("NATIVE_DATA_FIELD_DECIMAL_CONFIG_INVALID",o),n.precision=Ue(e.precision,`${o}/precision`,1,1e3),n.scale=e.scale===void 0?0:Ue(e.scale,`${o}/scale`,0,n.precision)),e.min!==void 0||e.max!==void 0){["number.integer","number.decimal"].includes(t)||R("NATIVE_DATA_FIELD_NUMERIC_BOUNDS_TYPE_INVALID",o);let i=Ft(e.min,`${o}/min`),r=Ft(e.max,`${o}/max`);t==="number.integer"&&[i,r].some(a=>a!==void 0&&!Number.isSafeInteger(a))&&R("NATIVE_DATA_FIELD_NUMERIC_BOUNDS_INVALID",o),i!==void 0&&r!==void 0&&i>r&&R("NATIVE_DATA_FIELD_NUMERIC_BOUNDS_INVALID",o),i!==void 0&&(n.min=i),r!==void 0&&(n.max=r)}return e.timePrecision!==void 0&&((t!=="time"||!["minute","second"].includes(e.timePrecision))&&R("NATIVE_DATA_FIELD_TIME_PRECISION_INVALID",`${o}/timePrecision`),n.timePrecision=e.timePrecision),n}function Xn(e,t,o){if(e===void 0)return;let n=`${o}/file`;["file","image","signature"].includes(t)||R("NATIVE_DATA_FIELD_FILE_TYPE_INVALID",n);let i=oe(e,n);re(i,["maxCount","maxSizeMb","accept"],n);let r=be(i.maxCount,`${n}/maxCount`,1,100);t==="signature"&&r!==void 0&&r!==1&&R("NATIVE_DATA_FIELD_SIGNATURE_COUNT_INVALID",`${n}/maxCount`);let a=be(i.maxSizeMb,`${n}/maxSizeMb`,1,1024),s;return i.accept!==void 0&&((!Array.isArray(i.accept)||i.accept.length>50)&&R("NATIVE_DATA_FIELD_FILE_ACCEPT_INVALID",`${n}/accept`),s=i.accept.map((l,p)=>ae(l,`${n}/accept/${p}`,255)),new Set(s).size!==s.length&&R("NATIVE_DATA_FIELD_FILE_ACCEPT_INVALID",`${n}/accept`)),{...r===void 0?{}:{maxCount:r},...a===void 0?{}:{maxSizeMb:a},...s===void 0?{}:{accept:s}}}function Qn(e,t,o){let n=`${o}/serial`;if(e===void 0){t==="serial-number"&&R("NATIVE_DATA_FIELD_SERIAL_REQUIRED",n);return}t!=="serial-number"&&R("NATIVE_DATA_FIELD_SERIAL_TYPE_INVALID",n);let i=oe(e,n);re(i,["prefix","digits","start"],n);let r=Me(i.prefix,`${n}/prefix`,64),a=be(i.digits,`${n}/digits`,1,32),s=be(i.start,`${n}/start`,0,Number.MAX_SAFE_INTEGER);return{...r===void 0?{}:{prefix:r},...a===void 0?{}:{digits:a},...s===void 0?{}:{start:s}}}function Zn(e,t,o){let n=`${o}/subtable`;if(e===void 0){t==="subtable"&&R("NATIVE_DATA_FIELD_SUBTABLE_REQUIRED",n);return}t!=="subtable"&&R("NATIVE_DATA_FIELD_SUBTABLE_TYPE_INVALID",n);let i=oe(e,n);re(i,["resourceCode","foreignKey","orderField","maxRows"],n);let r=ae(i.resourceCode,`${n}/resourceCode`,64);nt.test(r)||R("NATIVE_RESOURCE_CODE_INVALID",`${n}/resourceCode`);let a=fe(i.foreignKey,`${n}/foreignKey`),s=fe(i.orderField,`${n}/orderField`);s===a&&R("NATIVE_DATA_FIELD_SUBTABLE_ORDER_FIELD_INVALID",`${n}/orderField`);let l=be(i.maxRows,`${n}/maxRows`,1,49);return{resourceCode:r,foreignKey:a,orderField:s,...l===void 0?{}:{maxRows:l}}}function tt(e,t,o){if(e===void 0)return;(!Array.isArray(e)||e.length>o)&&R("NATIVE_DATA_FIELD_SOURCE_FIELDS_INVALID",t);let n=e.map((i,r)=>fe(i,`${t}/${r}`));return new Set(n).size!==n.length&&R("NATIVE_DATA_FIELD_SOURCE_FIELDS_INVALID",t),n}function fe(e,t){let o=ae(e,t,63);return vt.test(o)||R("NATIVE_FIELD_CODE_INVALID",t),o}function oe(e,t){return(!e||typeof e!="object"||Array.isArray(e))&&R("NATIVE_OBJECT_REQUIRED",t),e}function re(e,t,o){let n=new Set(t);for(let i of Object.keys(e))n.has(i)||R("NATIVE_PROPERTY_UNKNOWN",`${o}/${i}`)}function ae(e,t,o){return(typeof e!="string"||e.length===0||e.length>o)&&R("NATIVE_STRING_INVALID",t),e}function Me(e,t,o){if(e!==void 0)return(typeof e!="string"||e.length>o)&&R("NATIVE_STRING_INVALID",t),e}function Pt(e,t){if(e!==void 0)return typeof e!="boolean"&&R("NATIVE_BOOLEAN_REQUIRED",t),e}function be(e,t,o,n){if(e!==void 0)return Ue(e,t,o,n)}function Ft(e,t){if(e!==void 0)return(typeof e!="number"||!Number.isFinite(e))&&R("NATIVE_NUMBER_REQUIRED",t),e}function Ue(e,t,o,n){return(!Number.isSafeInteger(e)||Number(e)<o||Number(e)>n)&&R("NATIVE_INTEGER_OUT_OF_RANGE",t),Number(e)}function R(e,t){throw new ue(e,t)}var Ut=["created_by","updated_by","created_at","updated_at"];function Se(e){return Ut.includes(e)}function Mt(e){return Ut.some(t=>Object.prototype.hasOwnProperty.call(e.fieldPolicies||{},t))}var eo=ot.map(e=>e.code);function jt(e){return eo.includes(e)}var to=["eq","neq","gt","gte","lt","lte","contains","startsWith","endsWith","in","between","has","hasAny","hasAll","overlaps","containedBy","jsonContains","isEmpty","isNotEmpty"],no=new Set(to);function rs(e){return no.has(String(e))}var st=["eq","neq","contains","startsWith","endsWith","in","isEmpty","isNotEmpty"],ye=["eq","neq","gt","gte","lt","lte","between","in","isEmpty"],oo=["eq","neq","in","isEmpty"],Be=["eq","neq","in","isEmpty","isNotEmpty"],Oe=["has","hasAny","hasAll","isEmpty","isNotEmpty"],Wt=["overlaps","contains","containedBy","isEmpty"],rt=["jsonContains","isEmpty","isNotEmpty"],at=["isEmpty","isNotEmpty"],io={"text.short":st,"text.long":st,"text.rich":st,"number.integer":ye,"number.decimal":ye,boolean:oo,date:ye,time:ye,datetime:ye,"date-range":Wt,"datetime-range":Wt,"option.single":Be,"option.multiple":Oe,"cascade.single":Oe,"cascade.multiple":Oe,"user.single":Be,"user.multiple":Oe,"department.single":Be,"department.multiple":Oe,"resource-ref.single":Be,"resource-ref.multiple":Oe,file:at,image:at,signature:at,address:rt,location:rt,uuid:["eq","neq","in","isEmpty"],json:rt,"serial-number":["eq","neq","in","contains","startsWith"],subtable:[]},so=new Set(["text.short","text.long","text.rich","option.single","user.single","department.single","resource-ref.single","serial-number"]),ro=new Set(["option.multiple","cascade.single","cascade.multiple","user.multiple","department.multiple","resource-ref.multiple","file","image","signature","address","location","json","subtable"]);function Jt(e){return io[e]}function as(e,t){return Jt(e).includes(t)}function ct(e){return so.has(e)}function dt(e){return!ro.has(e)}function Gt(e){return Jt(e).length>0}var Bt=new Set(["number.integer","number.decimal"]),zt=new Set(["text.short","text.long","number.integer","number.decimal","date","time","datetime","serial-number"]),ao=new Set([...zt,"boolean","uuid"]),co=new Set(["option.single","user.single","department.single","resource-ref.single"]);function cs(e,t){return t==="sum"||t==="avg"?Bt.has(e)?{valueExpression:"column",numericResult:!0}:null:t==="min"||t==="max"?zt.has(e)?{valueExpression:"column",numericResult:Bt.has(e)}:null:co.has(e)?{valueExpression:"snapshot-value",numericResult:!0}:ao.has(e)?{valueExpression:"column",numericResult:!0}:null}var lo=500,pe={surface:["mutationOwner","generated","fields","list","form","detail","mobile","views"],generated:["list","detail","create","update","delete"],field:["label","type","widget","section","requiredHint","system","hidden","readCapabilities","createCapabilities","updateCapabilities","maxLength","precision","scale","min","max","rangeBoundary","maxCount","maxSizeMb","accept","options","list","searchable","sortable","source","timePrecision","serial","subtable"],list:["actions","fieldOrder","defaultPageSize","searchableFields","filterFields","defaultSort"],defaultSort:["field","order"],layout:["layout","fieldOrder"],mobile:["enabled"]},uo={"text.short":["text","email","phone"],"text.long":["textarea"],"text.rich":["rich-text"],"number.integer":["number","rating"],"number.decimal":["number","money","percent"],boolean:["switch"],date:["date"],time:["time"],datetime:["datetime"],"date-range":["date-range"],"datetime-range":["datetime-range"],"option.single":["select","radio"],"option.multiple":["multi-select","checkbox"],"cascade.single":["cascade"],"cascade.multiple":["cascade"],"user.single":["directory-user"],"user.multiple":["directory-user"],"department.single":["directory-department","scope"],"department.multiple":["directory-department","scope"],"resource-ref.single":["select","radio","resource"],"resource-ref.multiple":["multi-select","checkbox","resource"],file:["attachment"],image:["image"],signature:["signature"],address:["address"],location:["location"],uuid:["readonly"],json:["json"],"serial-number":["readonly"],subtable:["subtable"]};function ft(e,t,o){if(e===void 0)return;let n=Q(e,o);ce(n,pe.surface,o);let i=n.mutationOwner===void 0?"native":le(n.mutationOwner,`${o}/mutationOwner`,16);["native","action","readonly","workflow"].includes(i)||P("NATIVE_DATA_SURFACE_MUTATION_OWNER_INVALID",`${o}/mutationOwner`);let r=n.generated===void 0?{}:Q(n.generated,`${o}/generated`);ce(r,pe.generated,`${o}/generated`);for(let l of pe.generated)ut(r[l],`${o}/generated/${l}`);if(i!=="native")for(let l of["create","update","delete"])r[l]===!0&&P("NATIVE_DATA_SURFACE_MUTATION_OWNER_CONFLICT",`${o}/generated/${l}`);let a=new Map(t.map(l=>[l.code,l])),s=Q(n.fields,`${o}/fields`);for(let l of Object.keys(s))a.has(l)||P("NATIVE_DATA_SURFACE_FIELD_MISSING",`${o}/fields/${l}`);for(let l of t)Object.prototype.hasOwnProperty.call(s,l.code)||P("NATIVE_DATA_SURFACE_FIELD_REQUIRED",`${o}/fields/${l.code}`),po(s[l.code],l,`${o}/fields/${l.code}`);for(let l of["create","update"]){let p=r[l]??i==="native",_=t.some(d=>{let c=Q(s[d.code],`${o}/fields/${d.code}`);return Ht(d,c,l)});p&&!_&&P("NATIVE_DATA_SURFACE_WRITABLE_FIELDS_REQUIRED",`${o}/generated/${l}`)}if(_o(n.list,a,`${o}/list`),Yt(n.form,a,`${o}/form`),Yt(n.detail,a,`${o}/detail`),n.mobile!==void 0){let l=Q(n.mobile,`${o}/mobile`);ce(l,pe.mobile,`${o}/mobile`),ut(l.enabled,`${o}/mobile/enabled`)}fo(n,t,o)}function pt(e,t){let o=e.views?.find(i=>i.code===t);o||P("NATIVE_DATA_VIEW_NOT_FOUND",`/surface/views/${t}`);let n=new Map((o.sections||[]).flatMap(i=>i.fields.map(r=>[r,i.title])));return{mutationOwner:e.mutationOwner||"native",generated:o.generated,list:o.list,form:o.form,detail:o.detail,mobile:o.mobile,fields:Object.fromEntries(Object.entries(e.fields).map(([i,r])=>{let a={...r};delete a.section;let s=n.get(i);return[i,{...a,...s?{section:s}:{},list:o.list.fieldOrder.includes(i)}]}))}}function fo(e,t,o){if(e.views===void 0)return;(!Array.isArray(e.views)||e.views.length>20)&&P("NATIVE_DATA_VIEWS_LIMIT_INVALID",`${o}/views`);let n=new Set;e.views.forEach((i,r)=>{let a=`${o}/views/${r}`,s=Q(i,a);ce(s,["code","name","generated","list","form","detail","mobile","sections"],a);let l=le(s.code,`${a}/code`,64);(!/^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/.test(l)||n.has(l))&&P("NATIVE_DATA_VIEW_CODE_INVALID",`${a}/code`),n.add(l),le(s.name,`${a}/name`,255),Q(s.generated,`${a}/generated`),Q(s.mobile,`${a}/mobile`);for(let _ of["list","detail","create","update","delete"])typeof s.generated[_]!="boolean"&&P("NATIVE_DATA_VIEW_OPERATION_INVALID",`${a}/generated/${_}`);typeof s.mobile.enabled!="boolean"&&P("NATIVE_DATA_VIEW_MOBILE_INVALID",`${a}/mobile/enabled`);for(let _ of["list","form","detail"]){let d=Q(s[_],`${a}/${_}`),c=$e(d.fieldOrder,`${a}/${_}/fieldOrder`,500,!0);for(let A of c){let f=e.fields[A];(!f||(f.hidden??f.system)===!0)&&P("NATIVE_DATA_VIEW_FIELD_INVALID",`${a}/${_}/fieldOrder`)}}if(s.sections!==void 0){(!Array.isArray(s.sections)||s.sections.length>100)&&P("NATIVE_DATA_VIEW_SECTIONS_INVALID",`${a}/sections`);let _=new Set;s.sections.forEach((d,c)=>{let A=`${a}/sections/${c}`,f=Q(d,A);ce(f,["title","fields"],A),le(f.title,`${A}/title`,255);for(let E of $e(f.fields,`${A}/fields`,100,!0)){let N=e.fields[E];(!N||(N.hidden??N.system)===!0||_.has(E))&&P("NATIVE_DATA_VIEW_FIELD_INVALID",`${A}/fields`),_.add(E)}})}let p=pt(e,l);if(ft(p,t,a),s.generated.create!==!1&&(e.mutationOwner||"native")==="native")for(let _ of t)We(_,e.fields[_.code])&&Ht(_,e.fields[_.code],"create")&&!s.form.fieldOrder.includes(_.code)&&P("NATIVE_DATA_VIEW_CREATE_REQUIRED_FIELD_MISSING",`${a}/form/fieldOrder`)})}function Ht(e,t,o){if(e.type==="serial-number"||t.system===!0)return!1;let n=t[`${o}Capabilities`];return Array.isArray(n)&&n.length>0}function po(e,t,o){let n=Q(e,o);ce(n,pe.field,o),le(n.label,`${o}/label`,500),n.type!==t.type&&P("NATIVE_DATA_SURFACE_FIELD_TYPE_MISMATCH",`${o}/type`);let i=le(n.widget,`${o}/widget`,64);uo[t.type].includes(i)||P("NATIVE_DATA_SURFACE_WIDGET_INCOMPATIBLE",`${o}/widget`),Io(n.section,`${o}/section`,255);for(let r of["requiredHint","system","hidden","list","searchable","sortable"])ut(n[r],`${o}/${r}`);n.searchable===!0&&!ct(t.type)&&P("NATIVE_DATA_SURFACE_SEARCH_UNSUPPORTED",`${o}/searchable`),n.sortable===!0&&!dt(t.type)&&P("NATIVE_DATA_SURFACE_SORT_UNSUPPORTED",`${o}/sortable`);for(let r of["readCapabilities","createCapabilities","updateCapabilities"])$e(n[r],`${o}/${r}`,100,!0);if(n.maxCount!==void 0&&(!Number.isSafeInteger(n.maxCount)||Number(n.maxCount)<1||Number(n.maxCount)>100)&&P("NATIVE_DATA_SURFACE_MAX_COUNT_INVALID",`${o}/maxCount`),n.maxSizeMb!==void 0&&(!Number.isSafeInteger(n.maxSizeMb)||Number(n.maxSizeMb)<1||Number(n.maxSizeMb)>1024)&&P("NATIVE_DATA_SURFACE_MAX_SIZE_INVALID",`${o}/maxSizeMb`),n.accept!==void 0){let r=Array.isArray(n.accept)?n.accept:[n.accept];$e(r,`${o}/accept`,50,!1)}for(let r of["maxLength","precision","scale","min","max","rangeBoundary","options","source","timePrecision","serial","subtable"])Eo(n,t,r,o);Ao(n,t,o)}function _o(e,t,o){if(e===void 0)return;let n=Q(e,o);if(ce(n,pe.list,o),n.actions!==void 0){let i=Q(n.actions,`${o}/actions`);ce(i,["import","export"],`${o}/actions`);for(let r of["import","export"])i[r]!==void 0&&typeof i[r]!="boolean"&&P("NATIVE_DATA_SURFACE_LIST_ACTION_INVALID",`${o}/actions/${r}`)}if(n.fieldOrder!==void 0)for(let i of $e(n.fieldOrder,`${o}/fieldOrder`,500,!0))t.has(i)||P("NATIVE_DATA_SURFACE_LIST_FIELD_INVALID",`${o}/fieldOrder`);n.defaultPageSize!==void 0&&(!Number.isSafeInteger(n.defaultPageSize)||Number(n.defaultPageSize)<1||Number(n.defaultPageSize)>200)&&P("NATIVE_DATA_SURFACE_PAGE_SIZE_INVALID",`${o}/defaultPageSize`);for(let[i,r]of[["searchableFields",ct],["filterFields",Gt]]){if(n[i]===void 0)continue;let a=$e(n[i],`${o}/${i}`,100,!0);for(let s of a){let l=t.get(s);(!l||!r(l.type))&&P("NATIVE_DATA_SURFACE_LIST_FIELD_INVALID",`${o}/${i}`)}}if(n.defaultSort!==void 0){let i=Q(n.defaultSort,`${o}/defaultSort`);ce(i,pe.defaultSort,`${o}/defaultSort`);let r=le(i.field,`${o}/defaultSort/field`,63),a=t.get(r);!jt(r)&&(!a||!dt(a.type))&&P("NATIVE_DATA_SURFACE_SORT_UNSUPPORTED",`${o}/defaultSort/field`),i.order!==void 0&&!["asc","desc"].includes(i.order)&&P("NATIVE_DATA_SURFACE_SORT_ORDER_INVALID",`${o}/defaultSort/order`)}}function Yt(e,t,o){if(e===void 0)return;let n=Q(e,o);if(ce(n,pe.layout,o),n.layout!==void 0&&!["flat","sections"].includes(n.layout)&&P("NATIVE_DATA_SURFACE_LAYOUT_INVALID",`${o}/layout`),n.fieldOrder!==void 0){let i=`${o}/fieldOrder`;(!Array.isArray(n.fieldOrder)||n.fieldOrder.length>t.size||n.fieldOrder.length>lo)&&P("NATIVE_DATA_SURFACE_FIELD_ORDER_INVALID",i);let r=n.fieldOrder.map((a,s)=>le(a,`${i}/${s}`,63));new Set(r).size!==r.length&&P("NATIVE_DATA_SURFACE_FIELD_ORDER_INVALID",i),r.forEach((a,s)=>{t.has(a)||P("NATIVE_DATA_SURFACE_FIELD_ORDER_FIELD_MISSING",`${i}/${s}`)})}}function Eo(e,t,o,n){e[o]===void 0&&t[o]===void 0||((e[o]===void 0||t[o]===void 0)&&P("NATIVE_DATA_SURFACE_FIELD_PROJECTION_MISMATCH",`${n}/${o}`),H(e[o])!==H(t[o])&&P("NATIVE_DATA_SURFACE_FIELD_PROJECTION_MISMATCH",`${n}/${o}`))}function Ao(e,t,o){let n=t.file||{},i={...e.maxCount===void 0?{}:{maxCount:e.maxCount},...e.maxSizeMb===void 0?{}:{maxSizeMb:e.maxSizeMb},...e.accept===void 0?{}:{accept:lt(e.accept)}};for(let r of["maxCount","maxSizeMb","accept"]){if(i[r]===void 0&&n[r]===void 0)continue;(i[r]===void 0||n[r]===void 0)&&P("NATIVE_DATA_SURFACE_FIELD_PROJECTION_MISMATCH",`${o}/${r}`);let a=r==="accept"?lt(i[r]):i[r],s=r==="accept"?lt(n[r]):n[r];H(a)!==H(s)&&P("NATIVE_DATA_SURFACE_FIELD_PROJECTION_MISMATCH",`${o}/${r}`)}}function lt(e){return(Array.isArray(e)?[...e]:[e]).sort((t,o)=>{let n=String(t),i=String(o);return n===i?0:n<i?-1:1})}function $e(e,t,o,n){(!Array.isArray(e)||!n&&e.length===0||e.length>o)&&P("NATIVE_DATA_SURFACE_STRING_ARRAY_INVALID",t);let i=e.map((r,a)=>le(r,`${t}/${a}`,255));return new Set(i).size!==i.length&&P("NATIVE_DATA_SURFACE_STRING_ARRAY_INVALID",t),i}function Q(e,t){return(!e||typeof e!="object"||Array.isArray(e))&&P("NATIVE_OBJECT_REQUIRED",t),e}function ce(e,t,o){let n=new Set(t);for(let i of Object.keys(e))n.has(i)||P("NATIVE_PROPERTY_UNKNOWN",`${o}/${i}`)}function le(e,t,o){return(typeof e!="string"||e.length===0||e.length>o)&&P("NATIVE_STRING_INVALID",t),e}function Io(e,t,o){e!==void 0&&(typeof e!="string"||e.length>o)&&P("NATIVE_STRING_INVALID",t)}function ut(e,t){e!==void 0&&typeof e!="boolean"&&P("NATIVE_BOOLEAN_REQUIRED",t)}function P(e,t){throw new ue(e,t)}import{createHash as mo}from"crypto";var _t=new Set(["option.single","user.single","department.single","resource-ref.single"]),No=new Set(["option.multiple","cascade.single","cascade.multiple","user.multiple","department.multiple","resource-ref.multiple","address","location","json"]),qt=new Set(["option.multiple","cascade.single","cascade.multiple","user.multiple","department.multiple","resource-ref.multiple","file","image"]),go=new Set(["option.single","user.single","department.single","resource-ref.single","signature","address","location"]),To=new Set([..._t,...qt,"signature","address","location","json"]);function Ts(e,t){let o=new Set([...Array.isArray(t?.list?.searchableFields)?t.list.searchableFields:[],...Object.entries(t?.fields||{}).filter(([,n])=>n?.searchable===!0).map(([n])=>n)]);return e.map(n=>Co(n,o.has(n.code))).sort((n,i)=>n.code.localeCompare(i.code))}function Co(e,t=!1){let o=e.type==="date-range"||e.type==="datetime-range";if(o&&e.rangeBoundary!=="closed"&&e.rangeBoundary!=="half-open")throw new Error("OPENXIANGDA_NATIVE_DATA_RANGE_BOUNDARY_INVALID");return{code:e.code,type:e.type,nullable:!0,indexed:e.indexed===!0,storage:$o(e),index:Oo(e,t),...o?{rangeBoundary:e.rangeBoundary}:{},...e.type==="serial-number"?{serial:{prefix:e.serial?.prefix||"",digits:e.serial?.digits??6,start:e.serial?.start??1}}:{},...e.type==="subtable"&&e.subtable?{subtable:{resourceCode:e.subtable.resourceCode,foreignKey:e.subtable.foreignKey,orderField:e.subtable.orderField,maxRows:e.subtable.maxRows??20}}:{}}}function Cs(e,t){if(t.type==="subtable")return null;let o=te(t.code),n=Xt(e,t),i=[n?` DEFAULT ${n}`:"",ho(o,t),bo(o,t)].join("");return`${o} ${t.storage}${i}`}function bs(e,t){return Xt(e,t)}function bo(e,t){if(t.type!=="date-range"&&t.type!=="datetime-range")return"";if(t.rangeBoundary!=="closed"&&t.rangeBoundary!=="half-open")throw new Error("OPENXIANGDA_NATIVE_DATA_RANGE_BOUNDARY_INVALID");let o=t.type==="datetime-range"&&t.rangeBoundary==="closed";return` CHECK (${e} IS NULL OR (NOT isempty(${e}) AND lower(${e}) IS NOT NULL AND upper(${e}) IS NOT NULL AND lower_inc(${e}) AND ${o?"":"NOT "}upper_inc(${e})))`}function Os(e){return e.type==="serial-number"||je(e.type)&&e.type!=="subtable"}function $s(e,t){return t.filter(o=>o.type==="serial-number").map(o=>{let n=Ge(e,o.code),i=o.serial?.start??1;return`CREATE SEQUENCE IF NOT EXISTS ${n} AS bigint MINVALUE ${i} START WITH ${i} CACHE 1`})}function hs(e,t){let o=Je(e);return t.filter(n=>n.type==="serial-number").map(n=>`ALTER SEQUENCE ${Ge(e,n.code)} OWNED BY ${o}.${te(n.code)}`)}function Rs(e,t){return t.filter(o=>o.type==="serial-number").map(o=>`GRANT USAGE, SELECT ON SEQUENCE ${Ge(e,o.code)} TO "openxiangda_data_api"`)}function Ds(e,t){let o=Je(e),n=[];for(let i of t){if(i.type==="subtable")continue;let r=te(i.code),a=te(_e("idx",e,i.code,i.index));switch(i.index){case"btree":n.push(`CREATE INDEX IF NOT EXISTS ${a} ON ${o} (${r})`);break;case"btree-snapshot-expressions":{let s=te(_e("idx",e,i.code,"snapshot-value")),l=te(_e("idx",e,i.code,"snapshot-label"));n.push(`CREATE INDEX IF NOT EXISTS ${s} ON ${o} ((${r} ->> 'value'))`,`CREATE INDEX IF NOT EXISTS ${l} ON ${o} ((${r} ->> 'label'))`);break}case"gin-jsonb-path":n.push(`CREATE INDEX IF NOT EXISTS ${a} ON ${o} USING GIN (${r} jsonb_path_ops)`);break;case"gist-range":n.push(`CREATE INDEX IF NOT EXISTS ${a} ON ${o} USING GIST (${r})`);break;case"gin-trigram":{let s=_t.has(i.type)?`((${r} ->> 'label')) gin_trgm_ops`:`${r} gin_trgm_ops`;n.push(`CREATE INDEX IF NOT EXISTS ${a} ON ${o} USING GIN (${s})`);break}case"none":break}if(i.type==="serial-number"){let s=te(_e("uidx",e,i.code,"serial"));n.push(`CREATE UNIQUE INDEX IF NOT EXISTS ${s} ON ${o} (${r})`)}}return n}function Ss(e,t,o,n){let i=Je(e),r=Je(t),a=te(_e("uidx",e,"environment_id","subtable-parent")),s=te(_e("idx",t,o,n,"subtable-child")),l=te(_e("fk",t,o,e)),p=te(o),_=te(n);return[`CREATE UNIQUE INDEX IF NOT EXISTS ${a} ON ${i} ("tenant_id", "app_code", "environment_key", "id")`,`CREATE INDEX IF NOT EXISTS ${s} ON ${r} ("tenant_id", "app_code", "environment_key", ${p}, ${_}, "id")`,`DO $native_subtable$ BEGIN
1
+ import{createHash as Bn}from"node:crypto";function Jn(e){if(!e||typeof e!="object")return!1;let t=Object.getPrototypeOf(e);return t===Object.prototype||t===null}function tt(e,t){if(e===null)return"null";if(typeof e=="string"||typeof e=="boolean")return JSON.stringify(e);if(typeof e=="number"){if(!Number.isFinite(e))throw new TypeError(`JSON number must be finite: ${t}`);return JSON.stringify(e)}if(Array.isArray(e))return`[${e.map((n,s)=>tt(n,`${t}[${s}]`)).join(",")}]`;if(Jn(e))return`{${Object.keys(e).filter(s=>e[s]!==void 0).sort((s,r)=>s===r?0:s<r?-1:1).map(s=>`${JSON.stringify(s)}:${tt(e[s],`${t}.${s}`)}`).join(",")}}`;let o=e instanceof Date?"Date":e?.constructor?.name||typeof e;throw new TypeError(`Value is not JSON serializable: ${t} (${o})`)}function Q(e){return tt(e,"$")}function ee(e){return Bn("sha256").update(Q(e)).digest("hex")}var Lt=/^[A-Za-z][A-Za-z0-9_]{0,62}$/,ot=/^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/,Wn=["text.short","text.long","text.rich","number.integer","number.decimal","boolean","date","time","datetime","date-range","datetime-range","option.single","option.multiple","cascade.single","cascade.multiple","user.single","user.multiple","department.single","department.multiple","resource-ref.single","resource-ref.multiple","image","signature","address","location","uuid","json","file","serial-number","subtable"],Gn=new Set(Wn),vt=new Set(["option.multiple","cascade.multiple","user.multiple","department.multiple","resource-ref.multiple","file","image","subtable"]),Vt=new Set(["option.single","option.multiple","cascade.single","cascade.multiple"]),wt=new Set(["resource-ref.single","resource-ref.multiple"]),st=[{code:"id",type:"uuid",nullable:!1},{code:"revision",type:"number.integer",nullable:!1},{code:"created_by",type:"text.short",nullable:!1},{code:"updated_by",type:"text.short",nullable:!1},{code:"created_at",type:"datetime",nullable:!1},{code:"updated_at",type:"datetime",nullable:!1}],ii=new Map(st.map(e=>[e.code,e])),Ae=class extends Error{constructor(o,n){super(o);this.code=o;this.pointer=n;this.name="NativeDataFieldContractV2Error"}code;pointer};function Be(e){return vt.has(e)}function Je(e,t={}){return e.type!=="serial-number"&&t.system!==!0&&e.nullable===!1&&(!Be(e.type)||t.requiredHint===!0)}function it(e,t,o=500){Array.isArray(e)||S("NATIVE_ARRAY_REQUIRED",t),e.length===0&&S("NATIVE_DATA_FIELDS_REQUIRED",t),e.length>o&&S("NATIVE_ARRAY_LIMIT_EXCEEDED",t);let n=new Set;return e.map((s,r)=>{let a=`${t}/${r}`,i=se(s,a);de(i,["code","type","nullable","indexed","options","source","maxLength","precision","scale","min","max","rangeBoundary","timePrecision","file","serial","subtable"],a);let c=le(i.code,`${a}/code`,63);Lt.test(c)||S("NATIVE_FIELD_CODE_INVALID",`${a}/code`),n.has(c)&&S("NATIVE_DATA_FIELD_DUPLICATE",`${a}/code`),n.add(c);let f=le(i.type,`${a}/type`,32);Gn.has(f)||S("NATIVE_DATA_FIELD_TYPE_INVALID",`${a}/type`);let p=f,l=Ft(i.nullable,`${a}/nullable`),u=Ft(i.indexed,`${a}/indexed`);l===!0&&vt.has(p)&&S("NATIVE_DATA_MULTI_FIELD_NULLABLE_INVALID",`${a}/nullable`);let E=qn(i.options,p,a),_=Kn(i.source,p,a),A=Xn(i,p,a),N=zn(i.rangeBoundary,p,a),m=Qn(i.file,p,a),T=Zn(i.serial,p,a),C=eo(i.subtable,p,a);return{code:c,type:p,...l===void 0?{}:{nullable:l},...u===void 0?{}:{indexed:u},...E?{options:E}:{},..._?{source:_}:{},...A,...N?{rangeBoundary:N}:{},...m?{file:m}:{},...T?{serial:T}:{},...C?{subtable:C}:{}}})}function zn(e,t,o){let n=`${o}/rangeBoundary`;if(!(t==="date-range"||t==="datetime-range")){e!==void 0&&S("NATIVE_DATA_FIELD_RANGE_BOUNDARY_TYPE_INVALID",n);return}return e!=="closed"&&e!=="half-open"&&S("NATIVE_DATA_FIELD_RANGE_BOUNDARY_REQUIRED",n),e}function kt(e,t){Array.isArray(e)||S("NATIVE_ARRAY_REQUIRED",t);let o=new Map;e.forEach((n,s)=>{let r=`${t}/${s}`,a=se(n,r),i=le(a.code,`${r}/code`,64);(!ot.test(i)||o.has(i))&&S("NATIVE_RESOURCE_CODE_INVALID",`${r}/code`);let c=se(a.schema,`${r}/schema`);o.set(i,{pointer:r,fields:it(c.fields,`${r}/schema/fields`)})});for(let[n,s]of o){let r=new Map(s.fields.map(i=>[i.code,i]));s.fields.filter(i=>i.type==="subtable").reduce((i,c)=>i+(c.subtable?.maxRows??20),0)>49&&S("NATIVE_DATA_FIELD_SUBTABLE_AGGREGATE_MAX_ROWS_EXCEEDED",`${s.pointer}/schema/fields`),s.fields.forEach((i,c)=>{let f=`${s.pointer}/schema/fields/${c}`;if(i.source&&Yn(i.source,r,o,`${f}/source`),i.subtable){let p=o.get(i.subtable.resourceCode);(!p||i.subtable.resourceCode===n)&&S("NATIVE_DATA_FIELD_SUBTABLE_TARGET_MISSING",`${f}/subtable/resourceCode`);let l=p.fields.find(E=>E.code===i.subtable?.foreignKey);(!l||l.type!=="uuid"||l.nullable!==!1)&&S("NATIVE_DATA_FIELD_SUBTABLE_FOREIGN_KEY_INVALID",`${f}/subtable/foreignKey`);let u=p.fields.find(E=>E.code===i.subtable?.orderField);(!u||u.type!=="number.integer"||u.nullable!==!1)&&S("NATIVE_DATA_FIELD_SUBTABLE_ORDER_FIELD_INVALID",`${f}/subtable/orderField`)}})}}function Ut(e,t,o){if(e===void 0)return[];(!Array.isArray(e)||e.length>20)&&S("NATIVE_DATA_RESOURCE_INVARIANTS_INVALID",o);let n=new Map(t.map(r=>[r.code,r])),s=new Set;return e.map((r,a)=>{let i=`${o}/${a}`,c=se(r,i);de(c,["code","message","expression"],i);let f=le(c.code,`${i}/code`,128);(!/^[a-z][a-z0-9]*(?:[._-][a-z0-9]+)*$/.test(f)||s.has(f))&&S("NATIVE_DATA_RESOURCE_INVARIANT_CODE_INVALID",`${i}/code`),s.add(f);let p=je(c.message,`${i}/message`,500);p!==void 0&&p.length===0&&S("NATIVE_DATA_RESOURCE_INVARIANT_MESSAGE_INVALID",`${i}/message`);let l=se(c.expression,`${i}/expression`);de(l,["leftField","operator","rightField"],`${i}/expression`);let u=Ie(l.leftField,`${i}/expression/leftField`),E=Ie(l.rightField,`${i}/expression/rightField`),_=n.get(u),A=n.get(E);(!_||!A)&&S("NATIVE_DATA_RESOURCE_INVARIANT_FIELD_UNKNOWN",`${i}/expression`),_.type===A.type||["number.integer","number.decimal"].includes(_.type)&&["number.integer","number.decimal"].includes(A.type)||S("NATIVE_DATA_RESOURCE_INVARIANT_FIELD_TYPES_INVALID",`${i}/expression`);let m=String(l.operator);return["eq","neq","gt","gte","lt","lte"].includes(m)||S("NATIVE_DATA_RESOURCE_INVARIANT_OPERATOR_INVALID",`${i}/expression/operator`),!["eq","neq"].includes(m)&&!["number.integer","number.decimal","date","time","datetime","text.short","text.long","text.rich","serial-number","uuid"].includes(_.type)&&S("NATIVE_DATA_RESOURCE_INVARIANT_FIELD_TYPES_INVALID",`${i}/expression`),{code:f,...p===void 0?{}:{message:p},expression:{leftField:u,operator:m,rightField:E}}})}function Yn(e,t,o,n){let s=o.get(e.resourceCode);s||S("NATIVE_DATA_FIELD_SOURCE_TARGET_MISSING",`${n}/resourceCode`);let r=new Map(s.fields.map(i=>[i.code,i])),a=r.get(e.labelField);(!a||!["text.short","text.long"].includes(a.type))&&S("NATIVE_DATA_FIELD_SOURCE_LABEL_INVALID",`${n}/labelField`);for(let i of["searchFields","descriptionFields","snapshotFields"])for(let c of e[i]||[])r.has(c)||S("NATIVE_DATA_FIELD_SOURCE_FIELD_MISSING",`${n}/${i}`);for(let[i,c]of(e.filters||[]).entries())r.has(c.field)||S("NATIVE_DATA_FIELD_SOURCE_FILTER_FIELD_MISSING",`${n}/filters/${i}/field`),"binding"in c&&!t.has(c.binding.field)&&S("NATIVE_DATA_FIELD_SOURCE_BINDING_FIELD_MISSING",`${n}/filters/${i}/binding/field`)}function qn(e,t,o){let n=`${o}/options`;if(e===void 0){Vt.has(t)&&S("NATIVE_DATA_FIELD_OPTIONS_REQUIRED",n);return}(!Vt.has(t)||!Array.isArray(e))&&S("NATIVE_DATA_FIELD_OPTIONS_TYPE_INVALID",n),(e.length<1||e.length>100)&&S("NATIVE_DATA_FIELD_OPTIONS_INVALID",n);let s=0,r=(a,i,c)=>{c>5&&S("NATIVE_DATA_FIELD_OPTIONS_DEPTH_EXCEEDED",i);let f=new Set;return a.map((p,l)=>{s+=1,s>1e3&&S("NATIVE_DATA_FIELD_OPTIONS_COUNT_EXCEEDED",n);let u=`${i}/${l}`,E=se(p,u);de(E,["label","value","description","color","children"],u);let _=le(E.label,`${u}/label`,500),A=le(E.value,`${u}/value`,500);f.has(A)&&S("NATIVE_DATA_FIELD_OPTION_VALUE_DUPLICATE",`${u}/value`),f.add(A);let N=je(E.description,`${u}/description`,2e3),m=je(E.color,`${u}/color`,64),T;return E.children!==void 0&&((!t.startsWith("cascade.")||!Array.isArray(E.children))&&S("NATIVE_DATA_FIELD_OPTION_CHILDREN_INVALID",`${u}/children`),(E.children.length<1||E.children.length>100)&&S("NATIVE_DATA_FIELD_OPTION_CHILDREN_INVALID",`${u}/children`),T=r(E.children,`${u}/children`,c+1)),{label:_,value:A,...N===void 0?{}:{description:N},...m===void 0?{}:{color:m},...T?{children:T}:{}}})};return r(e,n,1)}function Kn(e,t,o){let n=`${o}/source`;if(e===void 0){wt.has(t)&&S("NATIVE_DATA_FIELD_SOURCE_REQUIRED",n);return}wt.has(t)||S("NATIVE_DATA_FIELD_SOURCE_TYPE_INVALID",n);let s=se(e,n);de(s,["kind","resourceCode","labelField","searchFields","descriptionFields","snapshotFields","filters","pageSize","loadMode"],n),s.kind!=="resource"&&S("NATIVE_DATA_FIELD_SOURCE_KIND_INVALID",`${n}/kind`);let r=le(s.resourceCode,`${n}/resourceCode`,64);ot.test(r)||S("NATIVE_RESOURCE_CODE_INVALID",`${n}/resourceCode`);let a=Ie(s.labelField,`${n}/labelField`),i=nt(s.searchFields,`${n}/searchFields`,10),c=nt(s.descriptionFields,`${n}/descriptionFields`,10),f=nt(s.snapshotFields,`${n}/snapshotFields`,50),p=Oe(s.pageSize,`${n}/pageSize`,1,100),l;s.loadMode!==void 0&&(["search","all"].includes(String(s.loadMode))||S("NATIVE_DATA_FIELD_SOURCE_LOAD_MODE_INVALID",`${n}/loadMode`),l=s.loadMode);let u=Hn(s.filters,`${n}/filters`);return{kind:"resource",resourceCode:r,labelField:a,...i?{searchFields:i}:{},...c?{descriptionFields:c}:{},...f?{snapshotFields:f}:{},...u?{filters:u}:{},...p===void 0?{}:{pageSize:p},...l?{loadMode:l}:{}}}function Hn(e,t){if(e!==void 0)return(!Array.isArray(e)||e.length>20)&&S("NATIVE_DATA_FIELD_SOURCE_FILTERS_INVALID",t),e.map((o,n)=>{let s=`${t}/${n}`,r=se(o,s),a=Object.prototype.hasOwnProperty.call(r,"value"),i=Object.prototype.hasOwnProperty.call(r,"binding");de(r,a?["field","operator","value"]:["field","operator","binding"],s),a===i&&S("NATIVE_DATA_FIELD_SOURCE_FILTER_VALUE_INVALID",s);let c=Ie(r.field,`${s}/field`);["eq","in"].includes(String(r.operator))||S("NATIVE_DATA_FIELD_SOURCE_FILTER_OPERATOR_INVALID",`${s}/operator`);let f=r.operator;if(a)return{field:c,operator:f,value:r.value};let p=se(r.binding,`${s}/binding`);return de(p,["kind","field"],`${s}/binding`),p.kind!=="field"&&S("NATIVE_DATA_FIELD_SOURCE_BINDING_KIND_INVALID",`${s}/binding/kind`),{field:c,operator:f,binding:{kind:"field",field:Ie(p.field,`${s}/binding/field`)}}})}function Xn(e,t,o){let n={};if(e.maxLength!==void 0&&(["text.short","text.long","text.rich"].includes(t)||S("NATIVE_DATA_FIELD_MAX_LENGTH_TYPE_INVALID",`${o}/maxLength`),n.maxLength=Me(e.maxLength,`${o}/maxLength`,1,1e6)),(e.precision!==void 0||e.scale!==void 0)&&((t!=="number.decimal"||e.precision===void 0)&&S("NATIVE_DATA_FIELD_DECIMAL_CONFIG_INVALID",o),n.precision=Me(e.precision,`${o}/precision`,1,1e3),n.scale=e.scale===void 0?0:Me(e.scale,`${o}/scale`,0,n.precision)),e.min!==void 0||e.max!==void 0){["number.integer","number.decimal"].includes(t)||S("NATIVE_DATA_FIELD_NUMERIC_BOUNDS_TYPE_INVALID",o);let s=Pt(e.min,`${o}/min`),r=Pt(e.max,`${o}/max`);t==="number.integer"&&[s,r].some(a=>a!==void 0&&!Number.isSafeInteger(a))&&S("NATIVE_DATA_FIELD_NUMERIC_BOUNDS_INVALID",o),s!==void 0&&r!==void 0&&s>r&&S("NATIVE_DATA_FIELD_NUMERIC_BOUNDS_INVALID",o),s!==void 0&&(n.min=s),r!==void 0&&(n.max=r)}return e.timePrecision!==void 0&&((t!=="time"||!["minute","second"].includes(e.timePrecision))&&S("NATIVE_DATA_FIELD_TIME_PRECISION_INVALID",`${o}/timePrecision`),n.timePrecision=e.timePrecision),n}function Qn(e,t,o){if(e===void 0)return;let n=`${o}/file`;["file","image","signature"].includes(t)||S("NATIVE_DATA_FIELD_FILE_TYPE_INVALID",n);let s=se(e,n);de(s,["maxCount","maxSizeMb","accept"],n);let r=Oe(s.maxCount,`${n}/maxCount`,1,100);t==="signature"&&r!==void 0&&r!==1&&S("NATIVE_DATA_FIELD_SIGNATURE_COUNT_INVALID",`${n}/maxCount`);let a=Oe(s.maxSizeMb,`${n}/maxSizeMb`,1,1024),i;return s.accept!==void 0&&((!Array.isArray(s.accept)||s.accept.length>50)&&S("NATIVE_DATA_FIELD_FILE_ACCEPT_INVALID",`${n}/accept`),i=s.accept.map((c,f)=>le(c,`${n}/accept/${f}`,255)),new Set(i).size!==i.length&&S("NATIVE_DATA_FIELD_FILE_ACCEPT_INVALID",`${n}/accept`)),{...r===void 0?{}:{maxCount:r},...a===void 0?{}:{maxSizeMb:a},...i===void 0?{}:{accept:i}}}function Zn(e,t,o){let n=`${o}/serial`;if(e===void 0){t==="serial-number"&&S("NATIVE_DATA_FIELD_SERIAL_REQUIRED",n);return}t!=="serial-number"&&S("NATIVE_DATA_FIELD_SERIAL_TYPE_INVALID",n);let s=se(e,n);de(s,["prefix","digits","start"],n);let r=je(s.prefix,`${n}/prefix`,64),a=Oe(s.digits,`${n}/digits`,1,32),i=Oe(s.start,`${n}/start`,0,Number.MAX_SAFE_INTEGER);return{...r===void 0?{}:{prefix:r},...a===void 0?{}:{digits:a},...i===void 0?{}:{start:i}}}function eo(e,t,o){let n=`${o}/subtable`;if(e===void 0){t==="subtable"&&S("NATIVE_DATA_FIELD_SUBTABLE_REQUIRED",n);return}t!=="subtable"&&S("NATIVE_DATA_FIELD_SUBTABLE_TYPE_INVALID",n);let s=se(e,n);de(s,["resourceCode","foreignKey","orderField","maxRows"],n);let r=le(s.resourceCode,`${n}/resourceCode`,64);ot.test(r)||S("NATIVE_RESOURCE_CODE_INVALID",`${n}/resourceCode`);let a=Ie(s.foreignKey,`${n}/foreignKey`),i=Ie(s.orderField,`${n}/orderField`);i===a&&S("NATIVE_DATA_FIELD_SUBTABLE_ORDER_FIELD_INVALID",`${n}/orderField`);let c=Oe(s.maxRows,`${n}/maxRows`,1,49);return{resourceCode:r,foreignKey:a,orderField:i,...c===void 0?{}:{maxRows:c}}}function nt(e,t,o){if(e===void 0)return;(!Array.isArray(e)||e.length>o)&&S("NATIVE_DATA_FIELD_SOURCE_FIELDS_INVALID",t);let n=e.map((s,r)=>Ie(s,`${t}/${r}`));return new Set(n).size!==n.length&&S("NATIVE_DATA_FIELD_SOURCE_FIELDS_INVALID",t),n}function Ie(e,t){let o=le(e,t,63);return Lt.test(o)||S("NATIVE_FIELD_CODE_INVALID",t),o}function se(e,t){return(!e||typeof e!="object"||Array.isArray(e))&&S("NATIVE_OBJECT_REQUIRED",t),e}function de(e,t,o){let n=new Set(t);for(let s of Object.keys(e))n.has(s)||S("NATIVE_PROPERTY_UNKNOWN",`${o}/${s}`)}function le(e,t,o){return(typeof e!="string"||e.length===0||e.length>o)&&S("NATIVE_STRING_INVALID",t),e}function je(e,t,o){if(e!==void 0)return(typeof e!="string"||e.length>o)&&S("NATIVE_STRING_INVALID",t),e}function Ft(e,t){if(e!==void 0)return typeof e!="boolean"&&S("NATIVE_BOOLEAN_REQUIRED",t),e}function Oe(e,t,o,n){if(e!==void 0)return Me(e,t,o,n)}function Pt(e,t){if(e!==void 0)return(typeof e!="number"||!Number.isFinite(e))&&S("NATIVE_NUMBER_REQUIRED",t),e}function Me(e,t,o,n){return(!Number.isSafeInteger(e)||Number(e)<o||Number(e)>n)&&S("NATIVE_INTEGER_OUT_OF_RANGE",t),Number(e)}function S(e,t){throw new Ae(e,t)}var xt=["created_by","updated_by","created_at","updated_at"];function ye(e){return xt.includes(e)}function Mt(e){return xt.some(t=>Object.prototype.hasOwnProperty.call(e.fieldPolicies||{},t))}var to=st.map(e=>e.code);function jt(e){return to.includes(e)}var no=["eq","neq","gt","gte","lt","lte","contains","startsWith","endsWith","in","between","has","hasAny","hasAll","overlaps","containedBy","jsonContains","isEmpty","isNotEmpty"],oo=new Set(no);function di(e){return oo.has(String(e))}var rt=["eq","neq","contains","startsWith","endsWith","in","isEmpty","isNotEmpty"],Ve=["eq","neq","gt","gte","lt","lte","between","in","isEmpty"],so=["eq","neq","in","isEmpty"],We=["eq","neq","in","isEmpty","isNotEmpty"],$e=["has","hasAny","hasAll","isEmpty","isNotEmpty"],Bt=["overlaps","contains","containedBy","isEmpty"],at=["jsonContains","isEmpty","isNotEmpty"],ct=["isEmpty","isNotEmpty"],io={"text.short":rt,"text.long":rt,"text.rich":rt,"number.integer":Ve,"number.decimal":Ve,boolean:so,date:Ve,time:Ve,datetime:Ve,"date-range":Bt,"datetime-range":Bt,"option.single":We,"option.multiple":$e,"cascade.single":$e,"cascade.multiple":$e,"user.single":We,"user.multiple":$e,"department.single":We,"department.multiple":$e,"resource-ref.single":We,"resource-ref.multiple":$e,file:ct,image:ct,signature:ct,address:at,location:at,uuid:["eq","neq","in","isEmpty"],json:at,"serial-number":["eq","neq","in","contains","startsWith"],subtable:[]},ro=new Set(["text.short","text.long","text.rich","option.single","user.single","department.single","resource-ref.single","serial-number"]),ao=new Set(["option.multiple","cascade.single","cascade.multiple","user.multiple","department.multiple","resource-ref.multiple","file","image","signature","address","location","json","subtable"]);function Wt(e){return io[e]}function li(e,t){return Wt(e).includes(t)}function dt(e){return ro.has(e)}function we(e){return!ao.has(e)}function Gt(e){return Wt(e).length>0}var Jt=new Set(["number.integer","number.decimal"]),zt=new Set(["text.short","text.long","number.integer","number.decimal","date","time","datetime","serial-number"]),co=new Set([...zt,"boolean","uuid"]),lo=new Set(["option.single","user.single","department.single","resource-ref.single"]);function ui(e,t){return t==="sum"||t==="avg"?Jt.has(e)?{valueExpression:"column",numericResult:!0}:null:t==="min"||t==="max"?zt.has(e)?{valueExpression:"column",numericResult:Jt.has(e)}:null:lo.has(e)?{valueExpression:"snapshot-value",numericResult:!0}:co.has(e)?{valueExpression:"column",numericResult:!0}:null}var uo=500,me={surface:["mutationOwner","generated","fields","list","form","detail","mobile","views"],generated:["list","detail","create","update","delete"],field:["label","type","widget","section","requiredHint","system","hidden","readCapabilities","createCapabilities","updateCapabilities","maxLength","precision","scale","min","max","rangeBoundary","maxCount","maxSizeMb","accept","options","list","searchable","sortable","source","timePrecision","serial","subtable"],list:["actions","fieldOrder","defaultPageSize","searchableFields","filterFields","defaultSort"],defaultSort:["field","order"],layout:["layout","fieldOrder"],mobile:["enabled"]},fo={"text.short":["text","email","phone"],"text.long":["textarea"],"text.rich":["rich-text"],"number.integer":["number","rating"],"number.decimal":["number","money","percent"],boolean:["switch"],date:["date"],time:["time"],datetime:["datetime"],"date-range":["date-range"],"datetime-range":["datetime-range"],"option.single":["select","radio"],"option.multiple":["multi-select","checkbox"],"cascade.single":["cascade"],"cascade.multiple":["cascade"],"user.single":["directory-user"],"user.multiple":["directory-user"],"department.single":["directory-department","scope"],"department.multiple":["directory-department","scope"],"resource-ref.single":["select","radio","resource"],"resource-ref.multiple":["multi-select","checkbox","resource"],file:["attachment"],image:["image"],signature:["signature"],address:["address"],location:["location"],uuid:["readonly"],json:["json"],"serial-number":["readonly"],subtable:["subtable"]};function ft(e,t,o){if(e===void 0)return;let n=te(e,o);ue(n,me.surface,o);let s=n.mutationOwner===void 0?"native":pe(n.mutationOwner,`${o}/mutationOwner`,16);["native","action","readonly","workflow"].includes(s)||L("NATIVE_DATA_SURFACE_MUTATION_OWNER_INVALID",`${o}/mutationOwner`);let r=n.generated===void 0?{}:te(n.generated,`${o}/generated`);ue(r,me.generated,`${o}/generated`);for(let c of me.generated)ut(r[c],`${o}/generated/${c}`);if(s!=="native")for(let c of["create","update","delete"])r[c]===!0&&L("NATIVE_DATA_SURFACE_MUTATION_OWNER_CONFLICT",`${o}/generated/${c}`);let a=new Map(t.map(c=>[c.code,c])),i=te(n.fields,`${o}/fields`);for(let c of Object.keys(i))a.has(c)||L("NATIVE_DATA_SURFACE_FIELD_MISSING",`${o}/fields/${c}`);for(let c of t)Object.prototype.hasOwnProperty.call(i,c.code)||L("NATIVE_DATA_SURFACE_FIELD_REQUIRED",`${o}/fields/${c.code}`),po(i[c.code],c,`${o}/fields/${c.code}`);for(let c of["create","update"]){let f=r[c]??s==="native",p=t.some(l=>{let u=te(i[l.code],`${o}/fields/${l.code}`);return qt(l,u,c)});f&&!p&&L("NATIVE_DATA_SURFACE_WRITABLE_FIELDS_REQUIRED",`${o}/generated/${c}`)}if(Eo(n.list,a,`${o}/list`),Yt(n.form,a,`${o}/form`),Yt(n.detail,a,`${o}/detail`),n.mobile!==void 0){let c=te(n.mobile,`${o}/mobile`);ue(c,me.mobile,`${o}/mobile`),ut(c.enabled,`${o}/mobile/enabled`)}_o(n,t,o)}function _t(e,t){let o=e.views?.find(s=>s.code===t);o||L("NATIVE_DATA_VIEW_NOT_FOUND",`/surface/views/${t}`);let n=new Map((o.sections||[]).flatMap(s=>s.fields.map(r=>[r,s.title])));return{mutationOwner:e.mutationOwner||"native",generated:o.generated,list:o.list,form:o.form,detail:o.detail,mobile:o.mobile,fields:Object.fromEntries(Object.entries(e.fields).map(([s,r])=>{let a={...r};delete a.section;let i=n.get(s);return[s,{...a,...i?{section:i}:{},list:o.list.fieldOrder.includes(s)}]}))}}function _o(e,t,o){if(e.views===void 0)return;(!Array.isArray(e.views)||e.views.length>20)&&L("NATIVE_DATA_VIEWS_LIMIT_INVALID",`${o}/views`);let n=new Set;e.views.forEach((s,r)=>{let a=`${o}/views/${r}`,i=te(s,a);ue(i,["code","name","generated","list","form","detail","mobile","sections"],a);let c=pe(i.code,`${a}/code`,64);(!/^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/.test(c)||n.has(c))&&L("NATIVE_DATA_VIEW_CODE_INVALID",`${a}/code`),n.add(c),pe(i.name,`${a}/name`,255),te(i.generated,`${a}/generated`),te(i.mobile,`${a}/mobile`);for(let p of["list","detail","create","update","delete"])typeof i.generated[p]!="boolean"&&L("NATIVE_DATA_VIEW_OPERATION_INVALID",`${a}/generated/${p}`);typeof i.mobile.enabled!="boolean"&&L("NATIVE_DATA_VIEW_MOBILE_INVALID",`${a}/mobile/enabled`);for(let p of["list","form","detail"]){let l=te(i[p],`${a}/${p}`),u=Re(l.fieldOrder,`${a}/${p}/fieldOrder`,500,!0);for(let E of u){let _=e.fields[E];(!_||(_.hidden??_.system)===!0)&&L("NATIVE_DATA_VIEW_FIELD_INVALID",`${a}/${p}/fieldOrder`)}}if(i.sections!==void 0){(!Array.isArray(i.sections)||i.sections.length>100)&&L("NATIVE_DATA_VIEW_SECTIONS_INVALID",`${a}/sections`);let p=new Set;i.sections.forEach((l,u)=>{let E=`${a}/sections/${u}`,_=te(l,E);ue(_,["title","fields"],E),pe(_.title,`${E}/title`,255);for(let A of Re(_.fields,`${E}/fields`,100,!0)){let N=e.fields[A];(!N||(N.hidden??N.system)===!0||p.has(A))&&L("NATIVE_DATA_VIEW_FIELD_INVALID",`${E}/fields`),p.add(A)}})}let f=_t(e,c);if(ft(f,t,a),i.generated.create!==!1&&(e.mutationOwner||"native")==="native")for(let p of t)Je(p,e.fields[p.code])&&qt(p,e.fields[p.code],"create")&&!i.form.fieldOrder.includes(p.code)&&L("NATIVE_DATA_VIEW_CREATE_REQUIRED_FIELD_MISSING",`${a}/form/fieldOrder`)})}function qt(e,t,o){if(e.type==="serial-number"||t.system===!0)return!1;let n=t[`${o}Capabilities`];return Array.isArray(n)&&n.length>0}function po(e,t,o){let n=te(e,o);ue(n,me.field,o),pe(n.label,`${o}/label`,500),n.type!==t.type&&L("NATIVE_DATA_SURFACE_FIELD_TYPE_MISMATCH",`${o}/type`);let s=pe(n.widget,`${o}/widget`,64);fo[t.type].includes(s)||L("NATIVE_DATA_SURFACE_WIDGET_INCOMPATIBLE",`${o}/widget`),mo(n.section,`${o}/section`,255);for(let r of["requiredHint","system","hidden","list","searchable","sortable"])ut(n[r],`${o}/${r}`);n.searchable===!0&&!dt(t.type)&&L("NATIVE_DATA_SURFACE_SEARCH_UNSUPPORTED",`${o}/searchable`),n.sortable===!0&&!we(t.type)&&L("NATIVE_DATA_SURFACE_SORT_UNSUPPORTED",`${o}/sortable`);for(let r of["readCapabilities","createCapabilities","updateCapabilities"])Re(n[r],`${o}/${r}`,100,!0);if(n.maxCount!==void 0&&(!Number.isSafeInteger(n.maxCount)||Number(n.maxCount)<1||Number(n.maxCount)>100)&&L("NATIVE_DATA_SURFACE_MAX_COUNT_INVALID",`${o}/maxCount`),n.maxSizeMb!==void 0&&(!Number.isSafeInteger(n.maxSizeMb)||Number(n.maxSizeMb)<1||Number(n.maxSizeMb)>1024)&&L("NATIVE_DATA_SURFACE_MAX_SIZE_INVALID",`${o}/maxSizeMb`),n.accept!==void 0){let r=Array.isArray(n.accept)?n.accept:[n.accept];Re(r,`${o}/accept`,50,!1)}for(let r of["maxLength","precision","scale","min","max","rangeBoundary","options","source","timePrecision","serial","subtable"])Ao(n,t,r,o);Io(n,t,o)}function Eo(e,t,o){if(e===void 0)return;let n=te(e,o);if(ue(n,me.list,o),n.actions!==void 0){let s=te(n.actions,`${o}/actions`);ue(s,["import","export"],`${o}/actions`);for(let r of["import","export"])s[r]!==void 0&&typeof s[r]!="boolean"&&L("NATIVE_DATA_SURFACE_LIST_ACTION_INVALID",`${o}/actions/${r}`)}if(n.fieldOrder!==void 0)for(let s of Re(n.fieldOrder,`${o}/fieldOrder`,500,!0))t.has(s)||L("NATIVE_DATA_SURFACE_LIST_FIELD_INVALID",`${o}/fieldOrder`);n.defaultPageSize!==void 0&&(!Number.isSafeInteger(n.defaultPageSize)||Number(n.defaultPageSize)<1||Number(n.defaultPageSize)>200)&&L("NATIVE_DATA_SURFACE_PAGE_SIZE_INVALID",`${o}/defaultPageSize`);for(let[s,r]of[["searchableFields",dt],["filterFields",Gt]]){if(n[s]===void 0)continue;let a=Re(n[s],`${o}/${s}`,100,!0);for(let i of a){let c=t.get(i);(!c||!r(c.type))&&L("NATIVE_DATA_SURFACE_LIST_FIELD_INVALID",`${o}/${s}`)}}if(n.defaultSort!==void 0){let s=te(n.defaultSort,`${o}/defaultSort`);ue(s,me.defaultSort,`${o}/defaultSort`);let r=pe(s.field,`${o}/defaultSort/field`,63),a=t.get(r);!jt(r)&&(!a||!we(a.type))&&L("NATIVE_DATA_SURFACE_SORT_UNSUPPORTED",`${o}/defaultSort/field`),s.order!==void 0&&!["asc","desc"].includes(s.order)&&L("NATIVE_DATA_SURFACE_SORT_ORDER_INVALID",`${o}/defaultSort/order`)}}function Yt(e,t,o){if(e===void 0)return;let n=te(e,o);if(ue(n,me.layout,o),n.layout!==void 0&&!["flat","sections"].includes(n.layout)&&L("NATIVE_DATA_SURFACE_LAYOUT_INVALID",`${o}/layout`),n.fieldOrder!==void 0){let s=`${o}/fieldOrder`;(!Array.isArray(n.fieldOrder)||n.fieldOrder.length>t.size||n.fieldOrder.length>uo)&&L("NATIVE_DATA_SURFACE_FIELD_ORDER_INVALID",s);let r=n.fieldOrder.map((a,i)=>pe(a,`${s}/${i}`,63));new Set(r).size!==r.length&&L("NATIVE_DATA_SURFACE_FIELD_ORDER_INVALID",s),r.forEach((a,i)=>{t.has(a)||L("NATIVE_DATA_SURFACE_FIELD_ORDER_FIELD_MISSING",`${s}/${i}`)})}}function Ao(e,t,o,n){e[o]===void 0&&t[o]===void 0||((e[o]===void 0||t[o]===void 0)&&L("NATIVE_DATA_SURFACE_FIELD_PROJECTION_MISMATCH",`${n}/${o}`),Q(e[o])!==Q(t[o])&&L("NATIVE_DATA_SURFACE_FIELD_PROJECTION_MISMATCH",`${n}/${o}`))}function Io(e,t,o){let n=t.file||{},s={...e.maxCount===void 0?{}:{maxCount:e.maxCount},...e.maxSizeMb===void 0?{}:{maxSizeMb:e.maxSizeMb},...e.accept===void 0?{}:{accept:lt(e.accept)}};for(let r of["maxCount","maxSizeMb","accept"]){if(s[r]===void 0&&n[r]===void 0)continue;(s[r]===void 0||n[r]===void 0)&&L("NATIVE_DATA_SURFACE_FIELD_PROJECTION_MISMATCH",`${o}/${r}`);let a=r==="accept"?lt(s[r]):s[r],i=r==="accept"?lt(n[r]):n[r];Q(a)!==Q(i)&&L("NATIVE_DATA_SURFACE_FIELD_PROJECTION_MISMATCH",`${o}/${r}`)}}function lt(e){return(Array.isArray(e)?[...e]:[e]).sort((t,o)=>{let n=String(t),s=String(o);return n===s?0:n<s?-1:1})}function Re(e,t,o,n){(!Array.isArray(e)||!n&&e.length===0||e.length>o)&&L("NATIVE_DATA_SURFACE_STRING_ARRAY_INVALID",t);let s=e.map((r,a)=>pe(r,`${t}/${a}`,255));return new Set(s).size!==s.length&&L("NATIVE_DATA_SURFACE_STRING_ARRAY_INVALID",t),s}function te(e,t){return(!e||typeof e!="object"||Array.isArray(e))&&L("NATIVE_OBJECT_REQUIRED",t),e}function ue(e,t,o){let n=new Set(t);for(let s of Object.keys(e))n.has(s)||L("NATIVE_PROPERTY_UNKNOWN",`${o}/${s}`)}function pe(e,t,o){return(typeof e!="string"||e.length===0||e.length>o)&&L("NATIVE_STRING_INVALID",t),e}function mo(e,t,o){e!==void 0&&(typeof e!="string"||e.length>o)&&L("NATIVE_STRING_INVALID",t)}function ut(e,t){e!==void 0&&typeof e!="boolean"&&L("NATIVE_BOOLEAN_REQUIRED",t)}function L(e,t){throw new Ae(e,t)}import{createHash as No}from"crypto";var pt=new Set(["option.single","user.single","department.single","resource-ref.single"]),To=new Set(["option.multiple","cascade.single","cascade.multiple","user.multiple","department.multiple","resource-ref.multiple","address","location","json"]),Ht=new Set(["option.multiple","cascade.single","cascade.multiple","user.multiple","department.multiple","resource-ref.multiple","file","image"]),go=new Set(["option.single","user.single","department.single","resource-ref.single","signature","address","location"]),bo=new Set([...pt,...Ht,"signature","address","location","json"]);function Oi(e,t){let o=new Set([...Array.isArray(t?.list?.searchableFields)?t.list.searchableFields:[],...Object.entries(t?.fields||{}).filter(([,n])=>n?.searchable===!0).map(([n])=>n)]);return e.map(n=>Co(n,o.has(n.code))).sort((n,s)=>n.code.localeCompare(s.code))}function Co(e,t=!1){let o=e.type==="date-range"||e.type==="datetime-range";if(o&&e.rangeBoundary!=="closed"&&e.rangeBoundary!=="half-open")throw new Error("OPENXIANGDA_NATIVE_DATA_RANGE_BOUNDARY_INVALID");return{code:e.code,type:e.type,nullable:!0,indexed:e.indexed===!0,storage:Ro(e),index:$o(e,t),...o?{rangeBoundary:e.rangeBoundary}:{},...e.type==="serial-number"?{serial:{prefix:e.serial?.prefix||"",digits:e.serial?.digits??6,start:e.serial?.start??1}}:{},...e.type==="subtable"&&e.subtable?{subtable:{resourceCode:e.subtable.resourceCode,foreignKey:e.subtable.foreignKey,orderField:e.subtable.orderField,maxRows:e.subtable.maxRows??20}}:{}}}function $i(e,t){if(t.type==="subtable")return null;let o=ne(t.code),n=Xt(e,t),s=[n?` DEFAULT ${n}`:"",ho(o,t),Oo(o,t)].join("");return`${o} ${t.storage}${s}`}function Ri(e,t){return Xt(e,t)}function Oo(e,t){if(t.type!=="date-range"&&t.type!=="datetime-range")return"";if(t.rangeBoundary!=="closed"&&t.rangeBoundary!=="half-open")throw new Error("OPENXIANGDA_NATIVE_DATA_RANGE_BOUNDARY_INVALID");let o=t.type==="datetime-range"&&t.rangeBoundary==="closed";return` CHECK (${e} IS NULL OR (NOT isempty(${e}) AND lower(${e}) IS NOT NULL AND upper(${e}) IS NOT NULL AND lower_inc(${e}) AND ${o?"":"NOT "}upper_inc(${e})))`}function hi(e){return e.type==="serial-number"||Be(e.type)&&e.type!=="subtable"}function Si(e,t){return t.filter(o=>o.type==="serial-number").map(o=>{let n=ze(e,o.code),s=o.serial?.start??1;return`CREATE SEQUENCE IF NOT EXISTS ${n} AS bigint MINVALUE ${s} START WITH ${s} CACHE 1`})}function Di(e,t){let o=Ge(e);return t.filter(n=>n.type==="serial-number").map(n=>`ALTER SEQUENCE ${ze(e,n.code)} OWNED BY ${o}.${ne(n.code)}`)}function yi(e,t){return t.filter(o=>o.type==="serial-number").map(o=>`GRANT USAGE, SELECT ON SEQUENCE ${ze(e,o.code)} TO "openxiangda_data_api"`)}function Vi(e,t){let o=Ge(e),n=[];for(let s of t){if(s.type==="subtable")continue;let r=ne(s.code),a=ne(Ne("idx",e,s.code,s.index));switch(s.index){case"btree":n.push(`CREATE INDEX IF NOT EXISTS ${a} ON ${o} (${r})`);break;case"btree-snapshot-expressions":{let i=ne(Ne("idx",e,s.code,"snapshot-value")),c=ne(Ne("idx",e,s.code,"snapshot-label"));n.push(`CREATE INDEX IF NOT EXISTS ${i} ON ${o} ((${r} ->> 'value'))`,`CREATE INDEX IF NOT EXISTS ${c} ON ${o} ((${r} ->> 'label'))`);break}case"gin-jsonb-path":n.push(`CREATE INDEX IF NOT EXISTS ${a} ON ${o} USING GIN (${r} jsonb_path_ops)`);break;case"gist-range":n.push(`CREATE INDEX IF NOT EXISTS ${a} ON ${o} USING GIST (${r})`);break;case"gin-trigram":{let i=pt.has(s.type)?`((${r} ->> 'label')) gin_trgm_ops`:`${r} gin_trgm_ops`;n.push(`CREATE INDEX IF NOT EXISTS ${a} ON ${o} USING GIN (${i})`);break}case"none":break}if(s.type==="serial-number"){let i=ne(Ne("uidx",e,s.code,"serial"));n.push(`CREATE UNIQUE INDEX IF NOT EXISTS ${i} ON ${o} (${r})`)}}return n}function wi(e,t,o,n){let s=Ge(e),r=Ge(t),a=ne(Ne("uidx",e,"environment_id","subtable-parent")),i=ne(Ne("idx",t,o,n,"subtable-child")),c=ne(Ne("fk",t,o,e)),f=ne(o),p=ne(n);return[`CREATE UNIQUE INDEX IF NOT EXISTS ${a} ON ${s} ("tenant_id", "app_code", "environment_key", "id")`,`CREATE INDEX IF NOT EXISTS ${i} ON ${r} ("tenant_id", "app_code", "environment_key", ${f}, ${p}, "id")`,`DO $native_subtable$ BEGIN
2
2
  ALTER TABLE ${r}
3
- ADD CONSTRAINT ${l}
4
- FOREIGN KEY ("tenant_id", "app_code", "environment_key", ${p})
5
- REFERENCES ${i} ("tenant_id", "app_code", "environment_key", "id")
3
+ ADD CONSTRAINT ${c}
4
+ FOREIGN KEY ("tenant_id", "app_code", "environment_key", ${f})
5
+ REFERENCES ${s} ("tenant_id", "app_code", "environment_key", "id")
6
6
  ON DELETE CASCADE;
7
7
  EXCEPTION WHEN duplicate_object THEN NULL;
8
- END $native_subtable$`]}function _e(e,...t){return`${e}_${mo("sha256").update(t.join(":")).digest("hex").slice(0,32)}`}function te(e){if(!/^[A-Za-z_][A-Za-z0-9_]{0,62}$/.test(e))throw new Error("OPENXIANGDA_NATIVE_IDENTIFIER_INVALID");return`"${e}"`}function Oo(e,t){return e.type==="subtable"?"none":t?"gin-trigram":e.indexed?["date-range","datetime-range"].includes(e.type)?"gist-range":_t.has(e.type)?"btree-snapshot-expressions":No.has(e.type)?"gin-jsonb-path":"btree":"none"}function $o(e){switch(e.type){case"text.short":return`varchar(${e.maxLength??255})`;case"text.long":case"text.rich":return"text";case"number.integer":return"bigint";case"number.decimal":return`numeric(${e.precision??38},${e.scale??10})`;case"boolean":return"boolean";case"date":return"date";case"time":return"time(0)";case"datetime":return"timestamptz";case"date-range":return"daterange";case"datetime-range":return"tstzrange";case"uuid":return"uuid";case"serial-number":return"varchar(255)";case"subtable":return"child-resource";default:return To.has(e.type),"jsonb"}}function Xt(e,t){if(je(t.type)&&t.type!=="subtable")return"'[]'::jsonb";if(t.type!=="serial-number")return"";let o=Kt(t.serial?.prefix||""),n=t.serial?.digits??6;return`(${o} || lpad(nextval(${Kt(Ge(e,t.code))})::text, ${n}, '0'))`}function ho(e,t){return qt.has(t.type)?` CHECK (${e} IS NULL OR jsonb_typeof(${e}) = 'array')`:go.has(t.type)?` CHECK (${e} IS NULL OR jsonb_typeof(${e}) = 'object')`:""}function Je(e){return`"app_data".${te(e)}`}function Ge(e,t){let o=_e("seq",e,t);return`"app_data".${te(o)}`}function Kt(e){return`'${e.replace(/'/g,"''")}'`}var Qt=new Set(["option.single","option.multiple","user.single","user.multiple","department.single","department.multiple","resource-ref.single","resource-ref.multiple"]),Ro=new Set([...Qt,"cascade.single","cascade.multiple","file","image","signature","address","location","json"]),Zt=/^[A-Za-z][A-Za-z0-9_]{0,62}$/,Do=new Set(["__proto__","prototype","constructor"]),Et=class extends Error{constructor(o){super("OPENXIANGDA_SCOPE_PROJECTION_FIELD_PATH_INVALID");this.path=o;this.name="NativeScopeSourceFieldPathV2Error"}path;code="OPENXIANGDA_SCOPE_PROJECTION_FIELD_PATH_INVALID"};function Ve(e,t){let o=tn(e);if(!o)return null;let n=t.get(o[0]);if(!n)return null;let i=o.slice(1).join(".")||void 0;return{field:n,...i?{valuePath:i}:{}}}function At(e){return!!(e&&e.field.type==="user.single"&&e.valuePath==="value")}function en(e,t,o){if(!e||!t||!So(e))return!1;let{field:n,valuePath:i}=e;if(!i)return t.valueType==="uuid"?n.type==="uuid":["text.short","text.long","serial-number"].includes(n.type);if(i==="value")return!(t.valueSourceResourceCode&&n.type.startsWith("resource-ref.")&&n.source?.resourceCode!==t.valueSourceResourceCode);let r=i.slice(9),s=o.get(n.source?.resourceCode||"")?.get(r)?.type;return t.valueType==="uuid"?s==="uuid":["text.short","text.long","serial-number"].includes(s||"")}function Vs(e,t){let o=tn(t);if(!o)throw new Et(String(t||""));let n=e;for(let i of o){if(!n||typeof n!="object"||!Object.prototype.hasOwnProperty.call(n,i))return;n=n[i]}return n}function So(e){let{field:t,valuePath:o}=e;if(!o)return!Ro.has(t.type);if(o==="value")return Qt.has(t.type);if(!o.startsWith("snapshot."))return!1;let n=o.slice(9);return Zt.test(n)&&t.type.startsWith("resource-ref.")&&!!t.source?.snapshotFields?.includes(n)}function tn(e){if(typeof e!="string"||e.length===0||e.length>192)return null;let t=e.split(".");return![1,2,3].includes(t.length)||t.some(o=>!Zt.test(o)||Do.has(o))||t.length===2&&t[1]!=="value"||t.length===3&&t[1]!=="snapshot"?null:t}var yo=new Set(["option.single","user.single","department.single","resource-ref.single"]),Vo=new Set(["text.short","text.long","text.rich","number.integer","number.decimal","boolean","date","time","datetime","uuid","serial-number"]),wo=new Set(["value","label","description","color"]),Po=new Set(["avatarUrl","employeeNo","title","mobile","email"]),Fo=new Set(["fullPath","parent.value","parent.label"]),vo=new Set(["country.value","country.label","province.value","province.label","city.value","city.label","district.value","district.label","street.value","street.label","detail","fullAddress"]),Lo=new Set(["longitude","latitude","accuracy"]),ko=new Set(["address","name","province","city","district","source"]);function Ps(e){let t=new Map(e.map(o=>[o.code,new Map(o.schema.fields.map(n=>[n.code,n]))]));return e.map(o=>({...o,schema:{...o.schema,fields:o.schema.fields.map(n=>{let i=xo(n,t);if(!Object.keys(i).length)return n;let r={...n};return Object.defineProperty(r,"queryPathTypes",{configurable:!1,enumerable:!1,writable:!1,value:Object.freeze(i)}),r})}}))}function Fs(e,t){if(yo.has(e.type)&&wo.has(t)||e.type==="user.single"&&Po.has(t)||e.type==="department.single"&&Fo.has(t))return we(t);if(e.type==="resource-ref.single"){let o=e.queryPathTypes?.[t];return o?{parts:t.split("."),type:o}:null}if(e.type==="address"&&vo.has(t))return we(t);if(e.type==="location"){if(Lo.has(t))return{parts:[t],type:"number.decimal"};if(ko.has(t))return we(t);if(t==="capturedAt")return{parts:[t],type:"datetime"}}return null}function xo(e,t){if(e.type!=="resource-ref.single"||!e.source)return{};let o=t.get(e.source.resourceCode);return o?Object.fromEntries((e.source.snapshotFields||[]).flatMap(n=>{let i=o.get(n);return i?[[`snapshot.${n}`,Vo.has(i.type)?i.type:"json"]]:[]})):{}}function we(e){return{parts:e.split("."),type:"text.short"}}var It=class extends Error{constructor(o,n){super(n);this.pointer=o}pointer;code="NATIVE_EVENT_ACTION_INVALID"};function nn(e,t,o="/events/subscriptions"){if(e.execution===void 0)return;let n=(E,N)=>{throw new It(`${o}${E}`,N)},i=(E,N,m)=>((!E||typeof E!="object"||Array.isArray(E)||Object.keys(E).some(g=>!m.includes(g)))&&n(N,"Invalid action object or unsupported property"),E),r=i(e.execution,"/execution",["kind","version","operations"]);(r.kind!=="native-data"||r.version!==1)&&n("/execution","Expected native-data version 1"),e.platformAccess&&n("/platformAccess","Native actions do not use application runtime capabilities"),(!Array.isArray(e.eventTypes)||!e.eventTypes.length||e.eventTypes.some(E=>!/^openxiangda\.data\.record\.(created|updated|deleted)\.v2$/.test(E)))&&n("/eventTypes","Native data actions require declared data events");let a=e.filter?.resourceCodes;(!Array.isArray(a)||!a.length||a.length>20)&&n("/filter/resourceCodes","Native actions require explicit source resources");let s=new Map(t.map(E=>[E.code,E])),l=a.map(E=>{let N=s.get(E);return N||n("/filter/resourceCodes","Unknown source resource"),new Set((N.schema?.fields||[]).map(m=>m.code))}),p=new Set(e.payload?.fields||[]),_=e.payload?.includeChanges===!0,d=(E,N)=>{let m=i(E,N,["source","path","value"]);if(m.source==="literal"){(!Object.hasOwn(m,"value")||Object.hasOwn(m,"path"))&&n(N,"Literal binding requires only value");let b;try{b=JSON.stringify(m.value)}catch{n(N,"Literal must be JSON")}return(b===void 0||Buffer.byteLength(b)>65536)&&n(N,"Literal is too large or not JSON"),{source:"literal",value:JSON.parse(b)}}(m.source!=="event"||typeof m.path!="string"||Object.hasOwn(m,"value"))&&n(N,"Expected a literal or event binding");let g=m.path.split(".");(g.length>8||g.some(b=>!/^[A-Za-z0-9_-]+$/.test(b)||["__proto__","prototype","constructor"].includes(b)))&&n(N,"Invalid event path");let T=/^data\.projection\.([A-Za-z][A-Za-z0-9_]{0,62})$/.exec(m.path),D=/^data\.changes\.([A-Za-z][A-Za-z0-9_]{0,62})\.(before|after)$/.exec(m.path);if(T||D){let b=(T||D)[1];l.some(O=>!O.has(b))&&n(N,"Source field must exist on every filtered resource"),p.add(b),D&&(_=!0)}else["id","time","type","subject","data.recordId","data.revision","data.operation","data.resourceCode"].includes(m.path)||n(N,"Event path is not part of the data event contract");return{source:"event",path:m.path}};(!Array.isArray(r.operations)||r.operations.length<1||r.operations.length>16)&&n("/execution/operations","Expected 1 to 16 operations");let c={},A=r.operations.map((E,N)=>{let m=`/execution/operations/${N}`,g=i(E,m,["operation","resourceCode","data","id","expectedRevision"]);["create","update","delete"].includes(g.operation)||n(m,"Unsupported Native operation");let T=s.get(g.resourceCode);T||n(m,"Unknown action target resource");let D=new Map((T.schema?.fields||[]).map(O=>[O.code,O])),b=g.data===void 0?{}:i(g.data,`${m}/data`,[...D.keys()]);return Object.keys(b).length>32&&n(m,"Maximum 32 mapped fields per operation"),g.operation==="create"&&(g.id!==void 0||g.expectedRevision!==void 0)&&n(m,"Create does not accept id or expectedRevision"),g.operation==="delete"&&g.data!==void 0&&n(m,"Delete does not accept data"),Object.keys(b).some(O=>D.get(O)?.type==="serial-number")&&n(m,"Generated fields cannot be assigned"),c[g.resourceCode]=X(T),{operation:g.operation,resourceCode:g.resourceCode,...g.operation==="create"?{}:{id:d(g.id,`${m}/id`),expectedRevision:d(g.expectedRevision,`${m}/expectedRevision`)},...g.operation==="delete"?{}:{data:Object.fromEntries(Object.entries(b).map(([O,V])=>[O,d(V,`${m}/data/${O}`)]))}}});(p.size>32||[...p].some(E=>l.some(N=>!N.has(E))))&&n("/payload/fields","Payload must contain at most 32 declared source fields");let f={kind:"native-data",version:1,operations:A,resourceDigests:c};return Buffer.byteLength(JSON.stringify(f))>65536&&n("/execution","Action plan exceeds 64 KiB"),{execution:{...f,digest:X(f)},payload:{includeChanges:_,fields:[...p].sort()}}}function Ee(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)?e:void 0}function sn(e,t){if(e?.instanceCommands===void 0)return[];let o=Ee(e.instanceCommands);if(!o||!Object.keys(o).length||Object.keys(o).some(i=>!["withdraw","terminate"].includes(i)))return["WORKFLOW_INSTANCE_COMMAND_POLICIES_INVALID"];let n=[];for(let[i,r]of Object.entries(o)){let a=Ee(r),s=i==="withdraw"?["beforeFact"]:["beforeFact","capability"];if(!a||Object.keys(a).some(l=>!s.includes(l))){n.push(`WORKFLOW_INSTANCE_COMMAND_POLICY_INVALID:${i}`);continue}if(i==="terminate"){let l=a.capability;(typeof l!="string"||l.length>255||!/^app:[a-z][a-z0-9]*(?:-[a-z0-9]+)*:[A-Za-z0-9:._-]+$/.test(l)||t&&(!l.startsWith(`app:${t.appCode}:`)||!t.capabilities.includes(l)))&&n.push("WORKFLOW_INSTANCE_TERMINATE_CAPABILITY_INVALID")}if(i==="withdraw"||a.beforeFact!==void 0){let l=a.beforeFact,p=Ee(e.inputSchema),_=Ee(Ee(p?.properties)?.[l]),d=Ee(Ee(e.subject)?.factProjection)?.[l],c=t?.fields.get(d);(typeof l!="string"||!/^[A-Za-z][A-Za-z0-9_]{0,62}$/.test(l)||!Array.isArray(p?.required)||!p.required.includes(l)||_?.type!=="string"||_?.format!=="date-time"||typeof d!="string"||t&&(c?.type!=="datetime"||c.nullable===!0))&&n.push(`WORKFLOW_INSTANCE_COMMAND_DEADLINE_FACT_INVALID:${i}`)}}return n}function xs(e,t){let o=e?.terminate?.capability;return typeof o=="string"&&/^app:[a-z][a-z0-9]*(?:-[a-z0-9]+)*:[A-Za-z0-9:._-]+$/.test(o)&&t.includes(o)}function on(e){if(typeof e!="string")return null;let t=/^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})(?:\.(\d{1,3}))?(Z|[+-]\d{2}:\d{2})$/.exec(e);if(!t)return null;let[,o,n,i,r,a,s]=t,l=t[8],p=new Date(Date.UTC(Number(o),Number(n),0)).getUTCDate();if(Number(n)<1||Number(n)>12||Number(i)<1||Number(i)>p||Number(r)>23||Number(a)>59||Number(s)>59||l!=="Z"&&(Number(l.slice(1,3))>23||Number(l.slice(4))>59))return null;let _=Date.parse(e);return Number.isFinite(_)?_:null}function Us(e,t,o,n){let i=e?.[t];if(!i||t==="terminate"&&i.beforeFact===void 0)return null;let r=i.beforeFact,a=Ee(o),s=r&&a&&Object.hasOwn(a,r)?on(a[r]):null,l=n instanceof Date?n.getTime():on(n);return s===null||l===null||!Number.isFinite(l)?"WORKFLOW_V2_CANCELLATION_DEADLINE_INVALID":l<s?null:"WORKFLOW_V2_CANCELLATION_DEADLINE_PASSED"}import*as Ke from"crypto";var rn="native-4",an={"application-native-2":"1.0.0","authz.native-batch-explain":"1.0.0","authz.native-management":"1.0.0","deployment.durable-runs":"1.0.0","deployment.platform-executor":"1.0.0","environment.on-demand-production":"1.0.0","environment.runtime-lifecycle":"1.0.0","data-api-v2":"1.1.0","data.native-golden-crud":"1.0.0","data.audit-read-access":"1.0.0","data.managed-files":"1.1.0","workflow.named-input-sources":"1.0.0","directory-v2":"1.0.0","events-v2":"1.0.0","events.durable-receipts":"1.0.0","events.capture-policy":"1.0.0","events.native-data-actions":"1.0.0","workflow-kernel-v2":"1.0.0","workflow.instance-cancellation-policy":"1.0.0","business-process.durable-command":"1.1.0","workflow.fresh-command-token":"1.0.0","notification-hub-v2":"1.0.0","authentication.application-login-surface":"1.0.0","public-access.anonymous-owner-records":"1.0.0"};var Ws=5,Bs=20,Js=50,Gs=50,zs=100,Fe=class extends Error{constructor(o,n){super(o);this.code=o;this.pointer=n;this.name="NativeDataPolicyExpressionV2Error"}code;pointer};function ze(e,t){let o=[],n=(i,r,a)=>{a>5&&Pe("NATIVE_DATA_POLICY_EXPRESSION_DEPTH_EXCEEDED",r);let s=dn(i,r),l=["allOf","anyOf"].filter(d=>d in s);if(l.length===0){o.push({rule:s,pointer:r}),o.length>50&&Pe("NATIVE_DATA_POLICY_EXPRESSION_LEAVES_EXCEEDED",r);return}let p=l[0],_=s[p];(l.length!==1||Object.keys(s).length!==1||!Array.isArray(_)||_.length<1||_.length>20)&&Pe("NATIVE_DATA_POLICY_EXPRESSION_GROUP_INVALID",r),_.forEach((d,c)=>n(d,`${r}/${p}/${c}`,a+1))};return n(e,t,1),o}function cn(e,t){ze(e,t);let o=(n,i)=>{let r=dn(n,i);if(Array.isArray(r.allOf))return mt(r.allOf.flatMap((a,s)=>o(a,`${i}/allOf/${s}`)),i);if(Array.isArray(r.anyOf)){let a=[[]];return r.anyOf.forEach((s,l)=>{let p=o(s,`${i}/anyOf/${l}`);a=mt(a.flatMap(_=>p.map(d=>[..._,...d])),i)}),a}return[[r]]};return mt(o(e,t),t)}function mt(e,t){let o=e.reduce((n,i)=>n+i.length,0);return(e.length>50||o>100)&&Pe("NATIVE_DATA_POLICY_EXPRESSION_EXPANSION_EXCEEDED",t),e}function dn(e,t){return(!e||typeof e!="object"||Array.isArray(e))&&Pe("NATIVE_DATA_POLICY_EXPRESSION_NODE_INVALID",t),e}function Pe(e,t){throw new Fe(e,t)}var Uo="openxiangda.config-bundle/v3",Rn="openxiangda.contract-bundle/v3",ln="openxiangda.native-configuration-projection/v1",Le=rn,Mo=/^[a-f0-9]{64}$/,jo=/^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/,Wo=/^app:[a-z][a-z0-9]*(?:-[a-z0-9]+)*:[A-Za-z0-9:._*-]+$/,Bo=/^[a-z][a-z0-9]*(?:[-_.][a-z0-9]+)*$/,Jo=/^[a-z][a-z0-9]*(?:[-.][a-z0-9]+)*$/,Go=/^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/,zo=/^[A-Za-z][A-Za-z0-9_]{0,62}$/,un=/^[A-Za-z][A-Za-z0-9_]{0,127}$/,Yo=/^[a-z][a-z0-9]*(?:[-_][a-z0-9]+)*$/,Ho=/^[A-Z][A-Z0-9_]*$/,Ko=/^[a-z][a-z0-9-]{2,63}$/,qo=/^[A-Za-z][A-Za-z0-9_-]{0,127}$/,Xo=/^[A-Za-z][A-Za-z0-9_.]{0,127}$/,Qo=16,Zo=2*1024,ei=new Set(["text.short","text.long","number.integer","number.decimal","boolean","date","time","datetime","option.single","option.multiple","cascade.single","cascade.multiple","user.single","user.multiple","department.single","department.multiple","resource-ref.single","resource-ref.multiple","uuid","serial-number"]),ti=new Set(["overview","database","operations","workflow","members","calendar","document","folder","settings"]),ni=new Set(["approve","reject","return","transfer","delegate","add_assignee","resubmit","withdraw","terminate","admin_reassign","admin_override","retry_resolution"]),oi=4*1024*1024,ii=8*1024*1024,si=40,ri=1e5,gt=1024*1024,ai="openxiangda.event-handler-manifest/v2",Dn="openxiangda.application-route-manifest/v3",fn=64,ci=new Set(["id","revision","created_by","updated_by","created_at","updated_at"]),K=Object.freeze({perspectives:100,resources:100,capabilities:2e3,operations:500,eventConsumers:100,eventProducers:1e3,eventSchemas:100,eventTypes:500,workflows:100,routes:500,adminPages:500,adminNavigationGroups:100,adminNavigationItems:500}),Tt=["openxiangda.data.record.created.v2","openxiangda.data.record.updated.v2","openxiangda.data.record.deleted.v2"],Ct=["openxiangda.workflow.instance.started.v2","openxiangda.workflow.instance.cc_added.v2","openxiangda.workflow.instance.completed.v2","openxiangda.workflow.instance.rejected.v2","openxiangda.workflow.instance.returned.v2","openxiangda.workflow.instance.resumed.v2","openxiangda.workflow.instance.withdrawn.v2","openxiangda.workflow.instance.terminated.v2","openxiangda.workflow.task.created.v2","openxiangda.workflow.task.assigned.v2","openxiangda.workflow.task.assignment_pending.v2","openxiangda.workflow.task.assignment_resolution_failed.v2","openxiangda.workflow.task.approved.v2","openxiangda.workflow.task.completed.v2","openxiangda.workflow.task.rejected.v2","openxiangda.workflow.task.returned.v2","openxiangda.workflow.task.resubmitted.v2","openxiangda.workflow.task.transferred.v2","openxiangda.workflow.task.reassigned.v2","openxiangda.workflow.task.delegated.v2","openxiangda.workflow.task.assignee_added.v2","openxiangda.workflow.task.cancelled.v2","openxiangda.workflow.participant.activated.v2","openxiangda.workflow.participant.completed.v2","openxiangda.workflow.participant.rejected.v2","openxiangda.workflow.participant.returned.v2","openxiangda.workflow.participant.transferred.v2","openxiangda.workflow.participant.reassigned.v2","openxiangda.workflow.participant.delegated.v2","openxiangda.workflow.participant.added.v2","openxiangda.workflow.participant.suspended.v2","openxiangda.workflow.participant.resumed.v2","openxiangda.workflow.participant.cancelled.v2"],di=new Set(Ct),bt=class extends Error{code;pointer;identifiers;constructor(t,o,n={}){super(t),this.name="NativeConfigurationCompilerError",this.code=t,this.pointer=o,this.identifiers=Object.fromEntries(Object.entries(n).slice(0,8).map(([i,r])=>[i,String(r).slice(0,128)]))}};function rr(e){let t=$(e.appCode,"/appCode",128);jo.test(t)||u("NATIVE_CONFIG_APP_CODE_INVALID","/appCode");let o=$t(e.expectedConfigDigest,"/expectedConfigDigest"),n=$t(e.expectedContractDigest,"/expectedContractDigest"),i=On(e.configBytes,oi,"/configBytes","NATIVE_CONFIG_ARTIFACT_TOO_LARGE"),r=On(e.contractBytes,ii,"/contractBytes","NATIVE_CONTRACT_ARTIFACT_TOO_LARGE");$n(i,o,"/configBytes","NATIVE_CONFIG_DIGEST_MISMATCH"),$n(r,n,"/contractBytes","NATIVE_CONTRACT_DIGEST_MISMATCH");let a=Cn(i,"/configBytes","NATIVE_CONFIG_JSON_INVALID","NATIVE_CONFIG_NOT_CANONICAL"),s=Cn(r,"/contractBytes","NATIVE_CONTRACT_JSON_INVALID","NATIVE_CONTRACT_NOT_CANONICAL");bn(a,"/config"),bn(s,"/contracts");let l=a,p=s;pi(l,t),_i(p,t,o);let _=Ei(l,o,p.generatorVersion);Qi(_,p,l),H(_)!==H(p)&&u("NATIVE_CONTRACT_CLOSURE_MISMATCH",ht(_,p,"/contracts"));let d={authz:{appCode:t,...l.authz,perspectives:l.perspectives,capabilityCatalog:_.capabilities},data:{appCode:t,resources:l.data.resources,resourceContracts:_.resources},events:{appCode:t,...l.events,consumers:_.eventConsumers,producers:_.eventProducers,handlerManifest:_.eventHandlerManifest,eventTypes:_.eventTypes,capturePlans:ui({resources:l.data.resources,dataPolicies:l.authz.dataPolicies,subscriptions:_.eventConsumers,capturePolicies:l.events.capturePolicies})},workflows:{appCode:t,...l.workflows,contracts:_.workflows},runtime:{appCode:t,requirements:l.runtime,backend:l.backend,frontend:l.frontend},contracts:_},c={authz:he(d.authz),data:he(d.data),events:he(d.events),workflows:he(d.workflows),runtime:he(d.runtime),contracts:he(d.contracts)},A={configDigest:o,contractDigest:n,generatorVersion:p.generatorVersion},f=li(l),E={schemaVersion:ln,compilerContractVersion:Le,appCode:t,source:A,projections:c,requiredPlatformCapabilities:f,aggregateDigest:X({schemaVersion:ln,compilerContractVersion:Le,appCode:t,source:A,requiredPlatformCapabilities:f,projectionDigests:Object.fromEntries(Object.entries(c).map(([N,m])=>[N,m.digest]))})};return Mn(E)}function li(e){let t=e.authz.roles,o=e.data.resources,n=e.backend.operations,i=t.some(f=>f.capabilities.some(E=>E.endsWith(":directory:read")))||o.some(f=>f.schema.fields.some(E=>["user.single","user.multiple","department.single","department.multiple"].includes(E.type)))||n.some(f=>f.platformAccess?.directory),r=!!(e.events.subscriptions.length||e.events.timers.length||e.events.dateTriggers.length||e.events.schemas.length),a=n.some(f=>f.platformAccess?.managedFiles||f.platformAccess?.managedFileCopies)||e.events.subscriptions.some(f=>f.platformAccess?.managedFileCopies),s=n.some(f=>f.platformAccess?.notification)||e.events.subscriptions.some(f=>f.platformAccess?.notification),l=e.workflows.definitions.filter(f=>f.launch.mode==="standalone"||f.launch.mode==="hidden-handoff"),p=n.some(f=>f.platformAccess?.workflow)||l.length>0,_={resources:o},d={perspectives:e.perspectives,authz:e.authz},c={schemaVersion:e.schemaVersion,appCode:e.appCode,frontend:{routes:e.frontend.routes,user:e.frontend.user,admin:e.frontend.admin,devicePolicy:e.frontend.devicePolicy},backend:{operations:n.map(f=>({code:f.code,method:f.method,path:f.path,capability:f.capability,platformAccess:f.platformAccess||null,ai:f.ai||null}))}};return[{code:"application-native-2",declaration:c},{code:"authz.native-batch-explain",declaration:d},{code:"authz.native-management",declaration:d},{code:"deployment.durable-runs",declaration:c.backend},{code:"deployment.platform-executor",declaration:c.backend},{code:"environment.on-demand-production",declaration:{environments:["preproduction","production"]}},{code:"environment.runtime-lifecycle",declaration:{environments:["preproduction","production"]}},...o.length?[{code:"data-api-v2",declaration:_},{code:"data.native-golden-crud",declaration:_}]:[],...o.some(Mt)?[{code:"data.audit-read-access",declaration:_}]:[],...i?[{code:"directory-v2",declaration:{roles:t.map(f=>({code:f.code,capabilities:f.capabilities.filter(E=>E.endsWith(":directory:read"))})),resources:o.map(f=>({code:f.code,fields:f.schema.fields.filter(E=>["user.single","user.multiple","department.single","department.multiple"].includes(E.type))})),operations:n.filter(f=>f.platformAccess?.directory).map(f=>({code:f.code,directory:f.platformAccess.directory}))}}]:[],...a?[{code:"data.managed-files",declaration:{operations:n.filter(f=>f.platformAccess?.managedFiles||f.platformAccess?.managedFileCopies).map(f=>({code:f.code,...f.platformAccess?.managedFiles?{managedFiles:f.platformAccess.managedFiles}:{},...f.platformAccess?.managedFileCopies?{managedFileCopies:f.platformAccess.managedFileCopies}:{}})),subscriptions:e.events.subscriptions.filter(f=>f.platformAccess?.managedFileCopies).map(f=>({code:f.code,managedFileCopies:f.platformAccess.managedFileCopies}))}}]:[],...e.events.subscriptions.some(f=>f.execution)?[{code:"events.native-data-actions",declaration:e.events.subscriptions.filter(f=>f.execution)}]:[],...e.events.capturePolicies?.length?[{code:"events.capture-policy",declaration:e.events.capturePolicies}]:[],...r?[{code:"events-v2",declaration:e.events},{code:"events.durable-receipts",declaration:e.events}]:[],...e.workflows.activations.length?[{code:"workflow-kernel-v2",declaration:e.workflows},{code:"workflow.fresh-command-token",declaration:e.workflows}]:[],...e.workflows.definitions.some(f=>f.definition.instanceCommands!==void 0)?[{code:"workflow.instance-cancellation-policy",declaration:e.workflows.definitions.filter(f=>f.definition.instanceCommands!==void 0)}]:[],...p?[{code:"business-process.durable-command",declaration:{operations:n.filter(f=>f.platformAccess?.workflow).map(f=>({code:f.code,workflow:f.platformAccess.workflow})),definitions:l,activations:e.workflows.activations.filter(f=>l.some(E=>E.definition.code===f.workflowCode))}}]:[],...s?[{code:"notification-hub-v2",declaration:{operations:n.filter(f=>f.platformAccess?.notification).map(f=>({code:f.code,notification:f.platformAccess.notification})),subscriptions:e.events.subscriptions.filter(f=>f.platformAccess?.notification).map(f=>({code:f.code,notification:f.platformAccess.notification}))}}]:[],...e.frontend.authentication?[{code:"authentication.application-login-surface",declaration:e.frontend.authentication}]:[],...e.frontend.publicAccess?[{code:"public-access.anonymous-owner-records",declaration:e.frontend.publicAccess}]:[]].map(({code:f,declaration:E})=>({code:f,contractVersion:an[f],usageDigest:`sha256:${X(E)}`})).sort((f,E)=>f.code===E.code?0:f.code<E.code?-1:1)}function ui(e){let t=new Map,o=new Set(e.resources.map(r=>String(r.code)));for(let[r,a]of h(e.capturePolicies===void 0?[]:e.capturePolicies,"/capturePlan/capturePolicies",100).entries()){let s=`/capturePlan/capturePolicies/${r}`,l=I(a,s);C(l,["resourceCode","mode"],s);let p=G(l.resourceCode,`${s}/resourceCode`);o.has(p)||u("NATIVE_EVENT_CAPTURE_RESOURCE_NOT_FOUND",s,{resourceCode:p}),t.has(p)&&u("NATIVE_EVENT_CAPTURE_POLICY_DUPLICATE",s,{resourceCode:p}),l.mode!=="all"&&l.mode!=="subscribed"&&u("NATIVE_EVENT_CAPTURE_MODE_INVALID",`${s}/mode`),t.set(p,l.mode)}let n=new Map(e.dataPolicies.map((r,a)=>{let s=I(r,`/capturePlan/dataPolicies/${a}`);return[String(s.code),s]})),i=e.subscriptions.map((r,a)=>I(r,`/capturePlan/subscriptions/${a}`));return e.resources.map((r,a)=>{let s=`/capturePlan/resources/${a}`,l=I(r,s),p=G(l.code,`${s}/code`),_=l.schema?I(l.schema,`${s}/schema`):l,d=new Set(h(_.fields||[],`${s}/schema/fields`,500).map((O,V)=>z(I(O,`${s}/schema/fields/${V}`).code,`${s}/schema/fields/${V}/code`))),c=l.dataPolicyCode?y(l.dataPolicyCode,`${s}/dataPolicyCode`):null,A=c?n.get(c):void 0;c&&!A&&u("NATIVE_EVENT_CAPTURE_AUTHZ_POLICY_NOT_FOUND",s,{resourceCode:p,dataPolicyCode:c});let f=new Set;for(let O of A?.rules||[])f.add(String(O.field));if(A?.readExpression)for(let O of ze(A.readExpression,`${s}/readExpression`))f.add(String(O.rule.field));let E=new Set,N=new Set,m=new Set;for(let[O,V]of i.entries()){let w=h(V.eventTypes,`/capturePlan/subscriptions/${O}/eventTypes`,20).map(String);if(!w.some(B=>B.startsWith("openxiangda.data.")))continue;let x=I(V.filter||{},`/capturePlan/subscriptions/${O}/filter`),M=Array.isArray(x.resourceCodes)?x.resourceCodes.map(String):[];if(M.length&&!M.includes(p))continue;for(let B of w)Tt.includes(B)&&m.add(B);for(let B of fi(x,`/capturePlan/subscriptions/${O}/filter`))E.add(B);let ee=I(V.payload||{},`/capturePlan/subscriptions/${O}/payload`);for(let B of h(ee.fields||[],`/capturePlan/subscriptions/${O}/payload/fields`,32))N.add(z(B,`/capturePlan/subscriptions/${O}/payload/fields`))}let g=new Set([...E,...N]),T=new Set([...g,...f]);T.size>fn&&u("NATIVE_EVENT_CAPTURE_FIELDS_LIMIT",s,{resourceCode:p,maximum:fn});for(let O of T)!d.has(O)&&!(f.has(O)&&ci.has(O))&&u("NATIVE_EVENT_CAPTURE_FIELD_NOT_FOUND",s,{resourceCode:p,field:O});let D=I(l.fieldPolicies||{},`${s}/fieldPolicies`);for(let O of g)D[O]?.mask==="omit"&&u("NATIVE_EVENT_CAPTURE_FIELD_SENSITIVE",s,{resourceCode:p,field:O});let b={resourceCode:p,...t.get(p)==="subscribed"?{capturedEventTypes:[...m].sort()}:{},filterFields:[...E].sort(),projectionFields:[...N].sort(),authorizationFields:[...f].sort(),captureFields:[...T].sort()};return{...b,digest:X(b)}}).sort((r,a)=>r.resourceCode.localeCompare(a.resourceCode))}function fi(e,t){let o=new Set;for(let[a,s]of h(e.changes||[],`${t}/changes`,16).entries()){let l=I(s,`${t}/changes/${a}`);o.add(z(l.field,`${t}/changes/${a}/field`))}let n=I(e.changedFields||{},`${t}/changedFields`);for(let a of["anyOf","allOf","noneOf"])for(let[s,l]of h(n[a]||[],`${t}/changedFields/${a}`,32).entries())o.add(z(l,`${t}/changedFields/${a}/${s}`));let i=0,r=(a,s,l)=>{l>3&&u("NATIVE_EVENT_FILTER_DEPTH_LIMIT",s);let p=I(a,s);if(p.change){let d=I(p.change,`${s}/change`);o.add(z(d.field,`${s}/change/field`)),i+=1;return}if(p.not){r(p.not,`${s}/not`,l+1);return}let _=p.all?"all":p.any?"any":null;_||u("NATIVE_EVENT_FILTER_CONDITION_INVALID",s);for(let[d,c]of h(p[_],`${s}/${_}`,16).entries())r(c,`${s}/${_}/${d}`,l+1)};return e.where&&r(e.where,`${t}/where`,1),i+=Array.isArray(e.changes)?e.changes.length:0,i>16&&u("NATIVE_EVENT_FILTER_ATOM_LIMIT",t),[...o].sort()}function pi(e,t){C(e,["schemaVersion","compilerContractVersion","appCode","perspectives","authz","backend","data","events","workflows","frontend","runtime"],"/config"),v(e.schemaVersion,Uo,"/config/schemaVersion"),v(e.compilerContractVersion,Le,"/config/compilerContractVersion"),v(e.appCode,t,"/config/appCode"),h(e.perspectives,"/config/perspectives",100);let o=I(e.authz,"/config/authz");C(o,["capabilities","roles","scopeDimensions","scopeSources","roleMembershipSources","relationshipGrantSources","dataPolicies","authorizationTransitions"],"/config/authz",["authenticatedUserRoleCode"]),h(o.capabilities,"/config/authz/capabilities",2e3),h(o.roles,"/config/authz/roles",100),h(o.scopeDimensions,"/config/authz/scopeDimensions",100),h(o.scopeSources,"/config/authz/scopeSources",100),h(o.roleMembershipSources,"/config/authz/roleMembershipSources",100),h(o.relationshipGrantSources,"/config/authz/relationshipGrantSources",100),h(o.dataPolicies,"/config/authz/dataPolicies",100),h(o.authorizationTransitions,"/config/authz/authorizationTransitions",100);let n=I(e.backend,"/config/backend");C(n,["secrets","operations"],"/config/backend"),h(n.secrets,"/config/backend/secrets",100),h(n.operations,"/config/backend/operations",500),zi(n.secrets);let i=I(e.data,"/config/data");C(i,["resources"],"/config/data",["resourceDetailRoutes"]),h(i.resources,"/config/data/resources",100),i.resourceDetailRoutes!==void 0&&h(i.resourceDetailRoutes,"/config/data/resourceDetailRoutes",100);let r=I(e.events,"/config/events");C(r,["schemas","subscriptions","timers","dateTriggers"],"/config/events",["capturePolicies"]),h(r.schemas,"/config/events/schemas",100),h(r.subscriptions,"/config/events/subscriptions",100),h(r.timers,"/config/events/timers",100),h(r.dateTriggers,"/config/events/dateTriggers",100);let a=I(e.workflows,"/config/workflows");C(a,["definitions","bindings","activations","providers","editableParameters"],"/config/workflows"),h(a.definitions,"/config/workflows/definitions",100),h(a.bindings,"/config/workflows/bindings",100),h(a.activations,"/config/workflows/activations",100),h(a.providers,"/config/workflows/providers",100),h(a.editableParameters,"/config/workflows/editableParameters",100);let s=I(e.frontend,"/config/frontend");C(s,["routes","user","admin","devicePolicy"],"/config/frontend",["authentication","publicAccess"]),h(s.routes,"/config/frontend/routes",500);let l=I(s.user,"/config/frontend/user");C(l,["applicationTodoCenter"],"/config/frontend/user"),De(l.applicationTodoCenter,"/config/frontend/user/applicationTodoCenter"),Rt(s.devicePolicy,"/config/frontend/devicePolicy"),Object.prototype.hasOwnProperty.call(s,"authentication")&&yn(s.authentication,s.routes,e,"/config/frontend/authentication"),Object.prototype.hasOwnProperty.call(s,"publicAccess")&&Ri(s.publicAccess,e,"/config/frontend/publicAccess");let p=I(s.admin,"/config/frontend/admin");C(p,["navigation"],"/config/frontend/admin",["access"]),p.access!==void 0&&Xe(p.access,"/config/frontend/admin/access",e.appCode),Vi(p.navigation,"/config/frontend/admin/navigation");let _=I(e.runtime,"/config/runtime");C(_,["protocolCapabilities","health"],"/config/runtime"),F(_.protocolCapabilities,"/config/runtime/protocolCapabilities",100),C(I(_.health,"/config/runtime/health"),["livePath","readyPath","versionPath"],"/config/runtime/health"),v(_.health.livePath,"/__platform/health","/config/runtime/health/livePath"),v(_.health.readyPath,"/__platform/ready","/config/runtime/health/readyPath"),v(_.health.versionPath,"/__platform/version","/config/runtime/health/versionPath")}function _i(e,t,o){C(e,["schemaVersion","compilerContractVersion","generatorVersion","appCode","configDigest","perspectives","resources","capabilities","operations","eventConsumers","eventProducers","eventSchemas","eventHandlerManifest","eventTypes","workflows","routes","routeManifest","adminPages","adminNavigation"],"/contracts",["authentication","publicAccess","adminAccess"]),v(e.schemaVersion,Rn,"/contracts/schemaVersion"),v(e.compilerContractVersion,Le,"/contracts/compilerContractVersion"),$(e.generatorVersion,"/contracts/generatorVersion",128),v(e.appCode,t,"/contracts/appCode"),v(e.configDigest,o,"/contracts/configDigest"),h(e.perspectives,"/contracts/perspectives",K.perspectives),h(e.resources,"/contracts/resources",K.resources),h(e.capabilities,"/contracts/capabilities",K.capabilities),h(e.operations,"/contracts/operations",K.operations),h(e.eventConsumers,"/contracts/eventConsumers",K.eventConsumers),h(e.eventProducers,"/contracts/eventProducers",K.eventProducers),h(e.eventSchemas,"/contracts/eventSchemas",K.eventSchemas),I(e.eventHandlerManifest,"/contracts/eventHandlerManifest"),F(e.eventTypes,"/contracts/eventTypes",K.eventTypes),h(e.workflows,"/contracts/workflows",K.workflows),h(e.routes,"/contracts/routes",K.routes),Object.prototype.hasOwnProperty.call(e,"authentication")&&Oi(e.authentication,"/contracts/authentication"),Object.prototype.hasOwnProperty.call(e,"publicAccess")&&Di(e.publicAccess,"/contracts/publicAccess"),Object.prototype.hasOwnProperty.call(e,"adminAccess")&&Xe(e.adminAccess,"/contracts/adminAccess",t),ki(e.routeManifest,"/contracts/routeManifest",t),Fi(e.adminPages,"/contracts/adminPages"),vi(e.adminNavigation,"/contracts/adminNavigation")}function Ei(e,t,o){let n=mi(e);Wi(e,n),Ji(e),Bi(e),Yi(e);let i=e.events.schemas.map((c,A)=>{let f=`/config/events/schemas/${A}`,E=I(c,f),N=$(E.eventType,`${f}/eventType`,255);return N.startsWith("openxiangda.")&&u("NATIVE_EVENT_SCHEMA_RESERVED",`${f}/eventType`,{eventType:N}),v(E.schemaDigest,X(I(E.jsonSchema,`${f}/jsonSchema`)),`${f}/schemaDigest`),E}),r=new Set([...Tt,...Ct,...i.map(c=>String(c.eventType))]),a=new Map(e.data.resources.map(c=>[String(c.code),new Map(c.schema.fields.map(A=>[String(A.code),String(A.type)]))])),s=ne(e.events.subscriptions.map((c,A)=>{let f=`/config/events/subscriptions/${A}`,E=I(c,f),N=F(E.eventTypes,`${f}/eventTypes`,20);N.forEach((D,b)=>{r.has(D)||u("NATIVE_EVENT_TYPE_NOT_REGISTERED",`${f}/eventTypes/${b}`,{eventType:D})});let m=nn(E,e.data.resources,f),g=Ii(E.delivery,N,`${f}/delivery`),T=Ai(E.platformAccess,`${f}/platformAccess`,a);return{code:y(E.code,`${f}/code`),endpointPath:se(E.endpointPath,`${f}/endpointPath`),eventTypes:N,filter:I(E.filter,`${f}/filter`),payload:m?.payload||I(E.payload,`${f}/payload`),...m?{execution:m.execution}:{},...T?{platformAccess:T}:{},delivery:g}}),c=>c.code),l=new Map(i.map(c=>[String(c.eventType),String(c.dataSchemaVersion)])),p=ne([...e.data.resources.flatMap(c=>Tt.map(A=>({code:`data:${c.code}:${A}`,source:"data",eventType:A,dataSchemaVersion:"2.0.0",resourceCode:c.code}))),...i.map(c=>({code:`app:${c.eventType}`,source:"app",eventType:c.eventType,dataSchemaVersion:c.dataSchemaVersion})),...e.events.timers.map(c=>({code:c.code,source:"timer",eventType:c.eventType,dataSchemaVersion:l.get(String(c.eventType))||"2.0.0"})),...e.events.dateTriggers.map(c=>({code:c.code,source:"date",eventType:c.eventType,dataSchemaVersion:l.get(String(c.eventType))||"2.0.0",resourceCode:c.resourceCode,field:c.field})),...e.workflows.activations.length?Ct.map(c=>({code:`workflow:${c}`,source:"workflow",eventType:c,dataSchemaVersion:"2.0.0"})):[]],c=>`${c.source}:${c.code}:${c.eventType}`),_=U([...s.flatMap(c=>c.eventTypes),...p.map(c=>String(c.eventType))]);Pi(e);let d=Pn(e);return{schemaVersion:Rn,compilerContractVersion:Le,generatorVersion:o,appCode:e.appCode,configDigest:t,perspectives:e.perspectives,resources:Ni(e),capabilities:ne(n,c=>c.code),operations:Sn(e),eventConsumers:s,eventProducers:p,eventSchemas:i,eventHandlerManifest:{schemaVersion:ai,appCode:e.appCode,handlers:s.filter(c=>!c.execution).map(c=>({code:c.code,endpointPath:c.endpointPath,eventTypes:c.eventTypes,dataSchemaVersions:U(c.eventTypes.map(A=>A.startsWith("openxiangda.")?"2.0.0":l.get(A)||"2.0.0")),maxBodyBytes:65536,receiptProtocolVersion:2}))},eventTypes:_,workflows:Ln(e),routes:qe(e),...Object.prototype.hasOwnProperty.call(e.frontend,"authentication")?{authentication:$i(e)}:{},...Object.prototype.hasOwnProperty.call(e.frontend,"publicAccess")?{publicAccess:Si(e)}:{},...e.frontend.admin.access?{adminAccess:e.frontend.admin.access}:{},routeManifest:Mi(e),adminPages:d,adminNavigation:yi(e)}}function Ai(e,t,o){if(e===void 0)return;let n=I(e,t);C(n,["notification","managedFileCopies"],t,!0);let i={};if(n.notification!==void 0){let r=I(n.notification,`${t}/notification`);C(r,["mode"],`${t}/notification`),v(r.mode,"business-standard",`${t}/notification/mode`),i.notification={mode:"business-standard"}}if(n.managedFileCopies!==void 0){let r=h(n.managedFileCopies,`${t}/managedFileCopies`,16);r.length||u("NATIVE_EVENT_MANAGED_FILE_COPIES_REQUIRED",`${t}/managedFileCopies`);let a=new Set;i.managedFileCopies=ne(r.map((s,l)=>{let p=`${t}/managedFileCopies/${l}`,_=I(s,p);C(_,["mode","sourceResourceCode","sourceFieldCodes","targetResourceCode","targetFieldCodes"],p),v(_.mode,"copy",`${p}/mode`);let d=G(_.sourceResourceCode,`${p}/sourceResourceCode`),c=G(_.targetResourceCode,`${p}/targetResourceCode`),A=o.get(d),f=o.get(c);(!A||!f)&&u("NATIVE_EVENT_MANAGED_FILE_COPY_RESOURCE_INVALID",p);let E=F(_.sourceFieldCodes,`${p}/sourceFieldCodes`,16),N=F(_.targetFieldCodes,`${p}/targetFieldCodes`,16);(!E.length||E.length!==N.length)&&u("NATIVE_EVENT_MANAGED_FILE_COPY_FIELDS_INVALID",p),E.forEach((g,T)=>{let D=A.get(g),b=f.get(N[T]);(!["file","image"].includes(String(D))||D!==b)&&u("NATIVE_EVENT_MANAGED_FILE_COPY_FIELD_INVALID",`${p}/sourceFieldCodes/${T}`)});let m=`${d}:${E.join(",")}=>${c}:${N.join(",")}`;return a.has(m)&&u("NATIVE_EVENT_MANAGED_FILE_COPY_DUPLICATE",p),a.add(m),{mode:"copy",sourceResourceCode:d,sourceFieldCodes:U(E),targetResourceCode:c,targetFieldCodes:U(N)}}),s=>`${s.sourceResourceCode}:${s.sourceFieldCodes.join(",")}=>${s.targetResourceCode}:${s.targetFieldCodes.join(",")}`)}return Object.keys(i).length||u("NATIVE_EVENT_PLATFORM_ACCESS_EMPTY",t),i}function Ii(e,t,o){let n=I(e,o);C(n,["timeoutMs","maxAttempts","initialBackoffMs","maxBackoffMs","ordering","concurrency"],o),Z(n.timeoutMs,`${o}/timeoutMs`,1e3,3e4),Z(n.maxAttempts,`${o}/maxAttempts`,1,12);let i=Z(n.initialBackoffMs,`${o}/initialBackoffMs`,1e3,3e5);Z(n.maxBackoffMs,`${o}/maxBackoffMs`,i,18e5),Z(n.concurrency,`${o}/concurrency`,1,50);let r=$(n.ordering,`${o}/ordering`,32);return["none","record","workflow-instance"].includes(r)||u("NATIVE_EVENT_DELIVERY_ORDERING_INVALID",`${o}/ordering`),r==="workflow-instance"&&t.some(a=>!di.has(a))&&u("NATIVE_EVENT_WORKFLOW_ORDERING_REQUIRES_WORKFLOW_FACTS",`${o}/ordering`),n}function mi(e){let t=new Map;for(let o of Un(e.appCode))t.set(o.code,o);for(let[o,n]of e.authz.capabilities.entries()){let i=`/config/authz/capabilities/${o}`,r=I(n,i);C(r,["code","kind","name","description"],i,!0);let a=Ae(r.code,`${i}/code`,e.appCode);t.has(a)&&u("NATIVE_CAPABILITY_DUPLICATE",`${i}/code`),["backend","ui"].includes(r.kind)||u("NATIVE_CAPABILITY_KIND_INVALID",`${i}/kind`);let s={code:a,kind:r.kind,name:$(r.name,`${i}/name`,255),source:"explicit",...r.description===void 0?{}:{description:St(r.description,`${i}/description`,2e3)}};t.set(a,s)}for(let[o,n]of e.data.resources.entries()){let i=`/config/data/resources/${o}`,r=ke(n,i,e.appCode),a={read:`\u8BFB\u53D6${r.name}`,create:`\u65B0\u5EFA${r.name}`,update:`\u66F4\u65B0${r.name}`,delete:`\u5220\u9664${r.name}`};for(let s of["read","create","update","delete"]){let l=Ae(r.capabilities[s],`${i}/capabilities/${s}`,e.appCode);t.has(l)&&u("NATIVE_CAPABILITY_DUPLICATE",`${i}/capabilities/${s}`),t.set(l,{code:l,kind:"data",name:a[s],source:"data"})}for(let[s,l]of Object.entries(r.fieldPolicies)){if(Se(s))continue;let p=I(l,`${i}/fieldPolicies/${s}`);for(let _ of["read","create","update"])if(Array.isArray(p[_]))for(let d of F(p[_],`${i}/fieldPolicies/${s}/${_}`,2e3))Ae(d,`${i}/fieldPolicies/${s}/${_}`,e.appCode),!t.has(d)&&t.set(d,{code:d,kind:"data",name:`${r.name}.${s}.${_}`,source:"data"})}}return[...t.values()]}function Ni(e){let t=gi(e);return ne(e.data.resources.map((o,n)=>{let i=ke(o,`/config/data/resources/${n}`,e.appCode),r=t.get(i.code);return{code:i.code,schemaDigest:X(i.schema),fields:ne(i.schema.fields.map(a=>({code:a.code,type:a.type})),a=>a.code),...r?{detailRouteCode:r}:{}}}),o=>o.code)}function gi(e){let t=e.data.resourceDetailRoutes===void 0?[]:h(e.data.resourceDetailRoutes,"/config/data/resourceDetailRoutes",100),o=new Map(e.data.resources.map((r,a)=>{let s=`/config/data/resources/${a}`,l=ke(r,s,e.appCode);return[l.code,l]})),n=new Map(qe(e).map(r=>[String(r.code),r])),i=new Map;for(let[r,a]of t.entries()){let s=`/config/data/resourceDetailRoutes/${r}`,l=I(a,s);C(l,["resourceCode","desktop","mobile"],s);let p=G(l.resourceCode,`${s}/resourceCode`);i.has(p)&&u("NATIVE_DATA_RESOURCE_DETAIL_ROUTE_DUPLICATE",`${s}/resourceCode`);let _=o.get(p);_||u("NATIVE_DATA_RESOURCE_DETAIL_ROUTE_RESOURCE_MISSING",`${s}/resourceCode`);let d=y(l.desktop,`${s}/desktop`),c=y(l.mobile,`${s}/mobile`);d===c&&u("NATIVE_DATA_RESOURCE_DETAIL_ROUTE_INVALID",s);let A=String(_.capabilities.read);for(let[f,E]of[["desktop",d],["mobile",c]]){let N=`${s}/${f}`,m=n.get(E);m||u("NATIVE_DATA_RESOURCE_DETAIL_ROUTE_REFERENCE_MISSING",N),m.surface!=="user"&&u("NATIVE_DATA_RESOURCE_DETAIL_ROUTE_SURFACE_INVALID",N);let g=se(m.path,`${N}/path`),T=[...g.matchAll(/:([A-Za-z][A-Za-z0-9_]*)/g)],D=f==="mobile"?!g.startsWith("/m/"):g==="/m"||g.startsWith("/m/");(g.includes("*")||g.includes("?")||g.includes("#")||g.split("/").includes("..")||T.length!==1||D)&&u("NATIVE_DATA_RESOURCE_DETAIL_ROUTE_PATH_INVALID",N);let b=Array.isArray(m.access?.allOf)?m.access.allOf:[];m.capability!==A&&!b.includes(A)&&u("NATIVE_DATA_RESOURCE_DETAIL_ROUTE_CAPABILITY_INVALID",N)}i.set(p,{desktop:d,mobile:c})}return i}function Sn(e){let t=new Map(e.data.resources.map((i,r)=>{let a=`/config/data/resources/${r}`,s=ke(i,a,e.appCode);return[s.code,new Map(s.schema.fields.map(l=>[String(l.code),String(l.type)]))]})),o=new Set(t.keys()),n=new Set(e.workflows.activations.map((i,r)=>Qe(I(i,`/config/workflows/activations/${r}`).workflowCode,`/config/workflows/activations/${r}/workflowCode`)));return ne(e.backend.operations.map((i,r)=>{let a=`/config/backend/operations/${r}`,s=I(i,a);C(s,["code","method","path","capability","requestSchema","responseSchema","description","platformAccess","ai"],a,!0);let l=$(s.method,`${a}/method`,16);["GET","POST","PUT","PATCH","DELETE"].includes(l)||u("NATIVE_OPERATION_METHOD_INVALID",`${a}/method`);let p=y(s.code,`${a}/code`);Ci(s.ai,a,p,l,o);let _=Ti(s.platformAccess,`${a}/platformAccess`,t,n,new Set(e.authz.roles.map(d=>String(d.code))));return{code:p,method:l,path:se(s.path,`${a}/path`),requiredCapability:Ae(s.capability,`${a}/capability`,e.appCode),requestSchemaDigest:X(I(s.requestSchema,`${a}/requestSchema`)),responseSchemaDigest:X(I(s.responseSchema,`${a}/responseSchema`)),...s.description===void 0?{}:{description:St(s.description,`${a}/description`,2e3)},..._?{platformAccess:_}:{}}}),i=>i.code)}function Ti(e,t,o,n,i){if(e===void 0)return null;let r=I(e,t);C(r,["directory","managedFiles","managedFileCopies","notification","workflow","roleAssertions"],t,!0),Object.keys(r).length===0&&u("NATIVE_OPERATION_PLATFORM_ACCESS_EMPTY",t);let a={};if(r.roleAssertions!==void 0){let s=I(r.roleAssertions,`${t}/roleAssertions`);C(s,["roleCodes"],`${t}/roleAssertions`);let l=F(s.roleCodes,`${t}/roleAssertions/roleCodes`,20);l.length||u("NATIVE_OPERATION_ROLE_ASSERTIONS_REQUIRED",`${t}/roleAssertions/roleCodes`),l.forEach((p,_)=>{i.has(p)||u("NATIVE_ROLE_REFERENCE_MISSING",`${t}/roleAssertions/roleCodes/${_}`)}),a.roleAssertions={roleCodes:U(l)}}if(r.directory!==void 0){let s=I(r.directory,`${t}/directory`);C(s,["mode","fields"],`${t}/directory`),s.mode!=="current-initiator"&&u("NATIVE_OPERATION_DIRECTORY_MODE_INVALID",`${t}/directory/mode`);let l=new Set(["displayName","employeeNumber","primaryDepartment","departments"]),p=F(s.fields,`${t}/directory/fields`,4);(!p.length||p.some(_=>!l.has(_)))&&u("NATIVE_OPERATION_DIRECTORY_FIELDS_INVALID",`${t}/directory/fields`),a.directory={mode:"current-initiator",fields:U(p)}}if(r.managedFiles!==void 0){let s=h(r.managedFiles,`${t}/managedFiles`,16);s.length||u("NATIVE_OPERATION_MANAGED_FILES_REQUIRED",`${t}/managedFiles`);let l=new Set;a.managedFiles=ne(s.map((p,_)=>{let d=`${t}/managedFiles/${_}`,c=I(p,d);C(c,["resourceCode","fieldCodes","intents"],d);let A=G(c.resourceCode,`${d}/resourceCode`);(l.has(A)||!o.has(A))&&u("NATIVE_OPERATION_MANAGED_FILE_RESOURCE_INVALID",`${d}/resourceCode`),l.add(A);let f=F(c.fieldCodes,`${d}/fieldCodes`,16);(!f.length||f.some(N=>!["file","image","signature"].includes(String(o.get(A)?.get(N)||""))))&&u("NATIVE_OPERATION_MANAGED_FILE_FIELD_INVALID",`${d}/fieldCodes`);let E=F(c.intents,`${d}/intents`,2);return(!E.length||E.some(N=>!["create","update"].includes(N)))&&u("NATIVE_OPERATION_MANAGED_FILE_INTENT_INVALID",`${d}/intents`),{resourceCode:A,fieldCodes:U(f),intents:U(E)}}),p=>p.resourceCode)}if(r.managedFileCopies!==void 0){let s=h(r.managedFileCopies,`${t}/managedFileCopies`,16);s.length||u("NATIVE_OPERATION_MANAGED_FILE_COPIES_REQUIRED",`${t}/managedFileCopies`);let l=new Set;a.managedFileCopies=ne(s.map((p,_)=>{let d=`${t}/managedFileCopies/${_}`,c=I(p,d);C(c,["mode","sourceResourceCode","sourceFieldCodes","targetResourceCode","targetFieldCodes"],d),v(c.mode,"copy",`${d}/mode`);let A=G(c.sourceResourceCode,`${d}/sourceResourceCode`),f=G(c.targetResourceCode,`${d}/targetResourceCode`),E=o.get(A),N=o.get(f);(!E||!N)&&u("NATIVE_OPERATION_MANAGED_FILE_COPY_RESOURCE_INVALID",d);let m=F(c.sourceFieldCodes,`${d}/sourceFieldCodes`,16),g=F(c.targetFieldCodes,`${d}/targetFieldCodes`,16);(!m.length||m.length!==g.length)&&u("NATIVE_OPERATION_MANAGED_FILE_COPY_FIELDS_INVALID",d),m.forEach((D,b)=>{let O=E.get(D),V=N.get(g[b]);(!["file","image"].includes(String(O))||O!==V)&&u("NATIVE_OPERATION_MANAGED_FILE_COPY_FIELD_INVALID",`${d}/sourceFieldCodes/${b}`)});let T=`${A}:${m.join(",")}=>${f}:${g.join(",")}`;return l.has(T)&&u("NATIVE_OPERATION_MANAGED_FILE_COPY_DUPLICATE",d),l.add(T),{mode:"copy",sourceResourceCode:A,sourceFieldCodes:U(m),targetResourceCode:f,targetFieldCodes:U(g)}}),p=>`${p.sourceResourceCode}:${p.sourceFieldCodes.join(",")}=>${p.targetResourceCode}:${p.targetFieldCodes.join(",")}`)}if(r.notification!==void 0){let s=I(r.notification,`${t}/notification`);C(s,["mode"],`${t}/notification`),s.mode!=="business-standard"&&u("NATIVE_OPERATION_NOTIFICATION_MODE_INVALID",`${t}/notification/mode`),a.notification={mode:"business-standard"}}if(r.workflow!==void 0){let s=I(r.workflow,`${t}/workflow`);C(s,["codes"],`${t}/workflow`);let l=F(s.codes,`${t}/workflow/codes`,16);(!l.length||l.some(p=>!n.has(p)))&&u("NATIVE_OPERATION_WORKFLOW_CODE_INVALID",`${t}/workflow/codes`),a.workflow={codes:U(l)}}return a}function Ci(e,t,o,n,i){if(e===void 0)return;let r=`${t}/ai`,a=I(e,r);Jo.test(o)||u("NATIVE_OPERATION_AI_CODE_INVALID",`${t}/code`),C(a,["name","description","risk","resources","sideEffects","concurrency","timeoutMs"],r,!0),$(a.name,`${r}/name`,gt),$(a.description,`${r}/description`,gt);let s=$(a.risk,`${r}/risk`,16);["read","write","destructive","external"].includes(s)||u("NATIVE_OPERATION_AI_RISK_INVALID",`${r}/risk`),s==="read"!=(n==="GET")&&u("NATIVE_OPERATION_AI_METHOD_RISK_MISMATCH",`${r}/risk`),n==="DELETE"&&!["destructive","external"].includes(s)&&u("NATIVE_OPERATION_AI_METHOD_RISK_MISMATCH",`${r}/risk`);let l=F(a.resources,`${r}/resources`,16);l.length===0&&u("NATIVE_OPERATION_AI_RESOURCE_REQUIRED",`${r}/resources`),l.forEach((_,d)=>{let c=G(_,`${r}/resources/${d}`);i.has(c)||u("NATIVE_OPERATION_AI_RESOURCE_MISSING",`${r}/resources/${d}`)});let p=F(a.sideEffects,`${r}/sideEffects`,20);(s==="read"&&p.length!==0||s!=="read"&&p.length===0)&&u("NATIVE_OPERATION_AI_SIDE_EFFECT_INVALID",`${r}/sideEffects`),a.concurrency!==void 0&&!["none","revision"].includes($(a.concurrency,`${r}/concurrency`,16))&&u("NATIVE_OPERATION_AI_CONCURRENCY_INVALID",`${r}/concurrency`),a.timeoutMs!==void 0&&Z(a.timeoutMs,`${r}/timeoutMs`,100,3e4)}function Ye(e){return(e.replace(/\/{2,}/g,"/").replace(/\/$/,"")||"/").split("/").map(o=>o.startsWith(":")?":":o.includes("*")?"*":o).join("/")}function bi(e,t){let o=I(e,t),n=$(o.type,`${t}/type`,32),i=["code","type","label","presentation","required"],r=n==="sso"?[...i,"provider"]:n==="dingtalk"?[...i,"flow"]:i;C(o,r,t);let a=y(o.code,`${t}/code`),s=$(o.label,`${t}/label`,255),l=$(o.presentation,`${t}/presentation`,16);["primary","secondary"].includes(l)||u("NATIVE_APPLICATION_AUTH_METHOD_PRESENTATION_INVALID",`${t}/presentation`);let p=De(o.required,`${t}/required`);return["sso","password","dingtalk"].includes(n)||u("NATIVE_APPLICATION_AUTH_METHOD_TYPE_INVALID",`${t}/type`),n==="sso"&&o.provider!=="tenant-default"&&u("NATIVE_APPLICATION_AUTH_SSO_PROVIDER_INVALID",`${t}/provider`),n==="dingtalk"&&!["auto","jsapi","oauth"].includes($(o.flow,`${t}/flow`,16))&&u("NATIVE_APPLICATION_AUTH_DINGTALK_FLOW_INVALID",`${t}/flow`),{code:a,type:n,label:s,presentation:l,required:p,...n==="sso"?{provider:"tenant-default"}:{},...n==="dingtalk"?{flow:o.flow}:{}}}function pn(e,t,o){let n=I(e,o);C(n,["routeCode","path","defaultRouteCode"],o);let i=y(n.routeCode,`${o}/routeCode`),r=se(n.path,`${o}/path`),a=t==="desktop"?"/login":"/m/login";return(r!==a||/[:*?#\\]/.test(r))&&u("NATIVE_APPLICATION_AUTH_SURFACE_PATH_INVALID",`${o}/path`,{device:t,expectedPath:a}),{routeCode:i,path:r,defaultRouteCode:y(n.defaultRouteCode,`${o}/defaultRouteCode`)}}function yn(e,t,o,n){if(e===null)return;let i=I(e,n);C(i,["accountMode","registration","methods","surfaces"],n),v(i.accountMode,"existing-platform-users-only",`${n}/accountMode`);let r=I(i.registration,`${n}/registration`);C(r,["mode"],`${n}/registration`),v(r.mode,"reject",`${n}/registration/mode`);let a=h(i.methods,`${n}/methods`,8);a.length===0&&u("NATIVE_APPLICATION_AUTH_METHOD_REQUIRED",`${n}/methods`);let s=a.map((m,g)=>bi(m,`${n}/methods/${g}`)),l=new Set,p=new Set;for(let[m,g]of s.entries())l.has(g.code)&&u("NATIVE_APPLICATION_AUTH_METHOD_CODE_DUPLICATE",`${n}/methods/${m}/code`),p.has(g.type)&&u("NATIVE_APPLICATION_AUTH_METHOD_TYPE_DUPLICATE",`${n}/methods/${m}/type`),l.add(g.code),p.add(g.type);s.filter(m=>m.presentation==="primary").length!==1&&u("NATIVE_APPLICATION_AUTH_PRIMARY_METHOD_INVALID",`${n}/methods`);let _=I(i.surfaces,`${n}/surfaces`);C(_,["desktop","mobile"],`${n}/surfaces`);let d=pn(_.desktop,"desktop",`${n}/surfaces/desktop`),c=pn(_.mobile,"mobile",`${n}/surfaces/mobile`);d.routeCode===c.routeCode&&u("NATIVE_APPLICATION_AUTH_SURFACE_CODE_DUPLICATE",`${n}/surfaces/mobile/routeCode`);let A=h(t,"/config/frontend/routes",500),f=new Map;for(let[m,g]of A.entries()){let T=I(g,`/config/frontend/routes/${m}`);f.set(String(T.code||""),T)}let E=new Set((Array.isArray(o.data?.resources)?o.data.resources:[]).map(m=>String(m.code||"")).filter(m=>/^[a-z][a-z0-9-]{0,62}$/.test(m)));for(let[m,g]of[["desktop",d],["mobile",c]]){f.has(g.routeCode)&&u("NATIVE_APPLICATION_AUTH_SURFACE_CODE_CONFLICT",`${n}/surfaces/${m}/routeCode`);let T=/^user\.([a-z][a-z0-9-]{0,62})\.(records|submit)$/.exec(String(g.defaultRouteCode||"")),D=f.get(g.defaultRouteCode),b=String(D?.path||"");if(T&&E.has(T[1])){let V=T[2]==="records"?`/my/${T[1]}`:`/my/${T[1]}/submit`;D={surface:"user",path:m==="mobile"?`/m${V}`:V},b=String(D.path)}let O=m==="desktop"?b==="/m"||b.startsWith("/m/"):!(b==="/m"||b.startsWith("/m/"));(!D||D.surface!=="user"||/[:*]/.test(b)||O)&&u("NATIVE_APPLICATION_AUTH_DEFAULT_ROUTE_INVALID",`${n}/surfaces/${m}/defaultRouteCode`)}let N=Vn(o).filter(m=>!m.owner.startsWith("authentication:"));for(let[m,g]of[["desktop",d],["mobile",c]]){let T=N.find(D=>Ye(D.path)===Ye(g.path));T&&u("NATIVE_APPLICATION_AUTH_SURFACE_PATH_CONFLICT",`${n}/surfaces/${m}/path`,{owner:T.owner})}}function Oi(e,t){if(e===null)return;let o={data:{resources:[]},workflows:{definitions:[]},frontend:{routes:[{code:"auth-desktop-default",path:"/auth-desktop-default",surface:"user"},{code:"auth-mobile-default",path:"/m/auth-mobile-default",surface:"user"}],user:{applicationTodoCenter:!1},admin:{navigation:[]},authentication:e}},n=I(e,t),i=I(n.surfaces,`${t}/surfaces`),r={...n,surfaces:{...i,desktop:{...I(i.desktop,`${t}/surfaces/desktop`),defaultRouteCode:"auth-desktop-default"},mobile:{...I(i.mobile,`${t}/surfaces/mobile`),defaultRouteCode:"auth-mobile-default"}}};yn(r,o.frontend.routes,{...o,frontend:{...o.frontend,authentication:r}},t)}function $i(e){let t=e.frontend.authentication;return t===null?null:{accountMode:t.accountMode,registration:{mode:t.registration.mode},methods:t.methods.map(o=>({...o})),surfaces:{desktop:{...t.surfaces.desktop},mobile:{...t.surfaces.mobile}}}}var hi=new Set(["draft.read","draft.update","validate","create","own.list","own.read","public.list","public.read"]);function Ri(e,t,o){let n=I(e,o);C(n,["policies"],o);let i=h(n.policies,`${o}/policies`,16);i.length<1&&u("NATIVE_PUBLIC_POLICY_REQUIRED",o);let r=new Map(t.frontend.routes.map(p=>[p.code,p])),a=new Map(t.data.resources.map(p=>[p.code,p])),s=new Set,l=new Set(i.map(p=>String(p?.code||"")));i.forEach((p,_)=>{let d=`${o}/policies/${_}`,c=I(p,d);C(c,["code","routeCode","mode","resourceCode","operations","fields"],d,["requiredFields","ownRecordFields","publicRecordFields","publicFilters","serverGeneratedFields","schedule","publicSubtableFields","draft","validations"]);let A=y(c.code,`${d}/code`);s.has(A)&&u("NATIVE_PUBLIC_POLICY_DUPLICATE",`${d}/code`);let f=y(c.routeCode,`${d}/routeCode`),E=r.get(f);(!E||E.surface!=="user"||E.capability!==void 0||E.access!==void 0||/[:*]/.test(String(E.path)))&&u("NATIVE_PUBLIC_ROUTE_INVALID",`${d}/routeCode`),v(c.mode,"anonymous",`${d}/mode`);let N=G(c.resourceCode,`${d}/resourceCode`),m=a.get(N);m||u("NATIVE_PUBLIC_RESOURCE_MISSING",`${d}/resourceCode`);let g=new Map(m.schema.fields.map(S=>[String(S.code),String(S.type)])),T=F(c.operations,`${d}/operations`,8);(T.length<1||T.some(S=>!hi.has(S)))&&u("NATIVE_PUBLIC_OPERATION_INVALID",`${d}/operations`),T.includes("draft.read")!==T.includes("draft.update")&&u("NATIVE_PUBLIC_DRAFT_OPERATION_INCOMPLETE",`${d}/operations`);let D=F(c.fields,`${d}/fields`,64);(D.length<1||D.some(S=>!g.has(S)))&&u("NATIVE_PUBLIC_FIELD_INVALID",`${d}/fields`);for(let S of["requiredFields","ownRecordFields","publicRecordFields"]){if(!Object.prototype.hasOwnProperty.call(c,S))continue;F(c[S],`${d}/${S}`,64).some(L=>!D.includes(L))&&u("NATIVE_PUBLIC_FIELD_SCOPE_INVALID",`${d}/${S}`)}let b=Object.prototype.hasOwnProperty.call(c,"serverGeneratedFields")?h(c.serverGeneratedFields,`${d}/serverGeneratedFields`,16):[],O=new Set;b.forEach((S,k)=>{let L=`${d}/serverGeneratedFields/${k}`,W=I(S,L);C(W,["field","kind"],L);let J=z(W.field,`${L}/field`);(O.has(J)||!g.has(J)||D.includes(J)||g.get(J)!=="text.short"&&g.get(J)!=="text.long")&&u("NATIVE_PUBLIC_SERVER_GENERATED_FIELD_INVALID",`${L}/field`),v(W.kind,"random-token",`${L}/kind`),O.add(J)});let V=Object.prototype.hasOwnProperty.call(c,"schedule")?I(c.schedule,`${d}/schedule`):null;if(V){let S=["campusPolicyCode","rulePolicyCode","campusField","ruleCampusField","ruleWeekdaysField","ruleOpenAtField","ruleCloseAtField","ruleSlotMinutesField","ruleAdvanceHoursField","ruleAdvanceDaysField","campusEnabledField","ruleEnabledField","dateField","timeField"];C(V,S,`${d}/schedule`);for(let k of["campusPolicyCode","rulePolicyCode"])y(V[k],`${d}/schedule/${k}`);for(let k of S.filter(L=>!["campusPolicyCode","rulePolicyCode"].includes(L)))z(V[k],`${d}/schedule/${k}`);for(let k of[V.campusField,V.dateField,V.timeField])D.includes(String(k))||u("NATIVE_PUBLIC_SCHEDULE_FIELD_INVALID",`${d}/schedule`);(!l.has(String(V.campusPolicyCode))||!l.has(String(V.rulePolicyCode)))&&u("NATIVE_PUBLIC_SCHEDULE_POLICY_INVALID",`${d}/schedule`)}let w=Object.prototype.hasOwnProperty.call(c,"publicFilters")?h(c.publicFilters,`${d}/publicFilters`,16):[],x=new Set;w.forEach((S,k)=>{let L=`${d}/publicFilters/${k}`,W=I(S,L);C(W,["field","operator","value"],L);let J=z(W.field,`${L}/field`);x.has(J)&&u("NATIVE_PUBLIC_FILTER_DUPLICATE",`${L}/field`),D.includes(J)||u("NATIVE_PUBLIC_FILTER_FIELD_INVALID",`${L}/field`),v(W.operator,"eq",`${L}/operator`),["boolean","text.short","text.long","number.integer","number.decimal","date","time"].includes(g.get(J)||"")||u("NATIVE_PUBLIC_FILTER_FIELD_INVALID",`${L}/field`),W.value!==null&&typeof W.value!="string"&&typeof W.value!="number"&&typeof W.value!="boolean"&&u("NATIVE_PUBLIC_FILTER_VALUE_INVALID",`${L}/value`),x.add(J)});let M=Object.prototype.hasOwnProperty.call(c,"publicSubtableFields")?I(c.publicSubtableFields,`${d}/publicSubtableFields`):null;if(M){Object.keys(M).length>64&&u("NATIVE_PUBLIC_SUBTABLE_FIELDS_INVALID",`${d}/publicSubtableFields`);for(let[S,k]of Object.entries(M)){let L=m.schema.fields.find(Y=>String(Y.code)===S),W=String(L?.subtable?.resourceCode||""),J=a.get(W),de=new Map((J?.schema?.fields||[]).map(Y=>[String(Y.code),String(Y.type)])),j=F(k,`${d}/publicSubtableFields/${S}`,64);(!D.includes(S)||g.get(S)!=="subtable"||!J||j.length<1||j.some(Y=>!de.has(Y))||j.some(Y=>de.get(Y)==="subtable")||j.some(Y=>de.get(Y)==="signature"))&&u("NATIVE_PUBLIC_SUBTABLE_FIELDS_INVALID",`${d}/publicSubtableFields/${S}`)}}if(T.some(S=>S.startsWith("public."))){Object.prototype.hasOwnProperty.call(c,"publicRecordFields")||u("NATIVE_PUBLIC_RECORD_FIELDS_REQUIRED",`${d}/publicRecordFields`);let S=F(c.publicRecordFields,`${d}/publicRecordFields`,64);(S.length<1||S.some(k=>!D.includes(k))||S.some(k=>g.get(k)==="signature"||g.get(k)==="subtable"&&!M?.[k]))&&u("NATIVE_PUBLIC_RECORD_FIELDS_INVALID",`${d}/publicRecordFields`)}let ee=Object.prototype.hasOwnProperty.call(c,"requiredFields")?F(c.requiredFields,`${d}/requiredFields`,64):[],B=m.surface||{},Ie=B.fields||{},ge=String(B.mutationOwner||"native")==="native"&&B.generated?.create!==!1,q=m.schema.fields.filter(S=>We(S,Ie[S.code])).map(S=>String(S.code));if(T.includes("create")&&!ge&&u("NATIVE_PUBLIC_CREATE_FIELDS_INCOMPLETE",`${d}/fields`),T.includes("create")&&!Object.prototype.hasOwnProperty.call(c,"draft")&&u("NATIVE_PUBLIC_DRAFT_REQUIRED",`${d}/draft`),T.includes("create"))for(let S of q){let k=D.includes(S)?ee.includes(S)?null:"requiredFields":"fields";k&&u("NATIVE_PUBLIC_CREATE_FIELDS_INCOMPLETE",`${d}/${k}`,{resourceCode:G,fieldCode:S})}if(Object.prototype.hasOwnProperty.call(c,"draft")){let S=I(c.draft,`${d}/draft`);C(S,["enabled","inactivityTtlSeconds","maxBytes"],`${d}/draft`),v(S.enabled,!0,`${d}/draft/enabled`),Z(S.inactivityTtlSeconds,`${d}/draft/inactivityTtlSeconds`,3600,7776e3),Z(S.maxBytes,`${d}/draft/maxBytes`,4096,262144)}else T.includes("draft.read")&&u("NATIVE_PUBLIC_DRAFT_REQUIRED",`${d}/draft`);let Te=Object.prototype.hasOwnProperty.call(c,"validations")?h(c.validations,`${d}/validations`,16):[],me=new Set;Te.forEach((S,k)=>{let L=`${d}/validations/${k}`,W=I(S,L);C(W,["code","kind","fields","result"],L);let J=y(W.code,`${L}/code`);me.has(J)&&u("NATIVE_PUBLIC_VALIDATION_DUPLICATE",`${L}/code`),v(W.kind,"duplicate",`${L}/kind`),v(W.result,"availability",`${L}/result`);let de=F(W.fields,`${L}/fields`,8);(de.length<1||de.some(j=>!D.includes(j))||de.some(j=>["file","subtable"].includes(g.get(j)||"")))&&u("NATIVE_PUBLIC_VALIDATION_FIELD_INVALID",`${L}/fields`),me.add(J)}),s.add(A)})}function Di(e,t){let o=I(e,t);C(o,["policies"],t),h(o.policies,`${t}/policies`,16).length<1&&u("NATIVE_PUBLIC_POLICY_REQUIRED",t)}function Si(e){return{policies:ne(e.frontend.publicAccess.policies.map(t=>({code:t.code,routeCode:t.routeCode,mode:t.mode,resourceCode:t.resourceCode,operations:U(t.operations),fields:U(t.fields),...t.requiredFields?{requiredFields:U(t.requiredFields)}:{},...t.ownRecordFields?{ownRecordFields:U(t.ownRecordFields)}:{},...t.publicRecordFields?{publicRecordFields:U(t.publicRecordFields)}:{},...t.publicFilters?{publicFilters:t.publicFilters.map(o=>({field:o.field,operator:o.operator,value:o.value})).sort((o,n)=>ie(o.field,n.field))}:{},...t.publicSubtableFields?{publicSubtableFields:Object.fromEntries(Object.entries(t.publicSubtableFields).sort(([o],[n])=>o.localeCompare(n)).map(([o,n])=>[o,U(Array.isArray(n)?n.map(String):[])]))}:{},...t.serverGeneratedFields?{serverGeneratedFields:t.serverGeneratedFields.map(o=>({field:o.field,kind:o.kind})).sort((o,n)=>ie(o.field,n.field))}:{},...t.schedule?{schedule:{campusPolicyCode:t.schedule.campusPolicyCode,rulePolicyCode:t.schedule.rulePolicyCode,campusField:t.schedule.campusField,ruleCampusField:t.schedule.ruleCampusField,ruleWeekdaysField:t.schedule.ruleWeekdaysField,ruleOpenAtField:t.schedule.ruleOpenAtField,ruleCloseAtField:t.schedule.ruleCloseAtField,ruleSlotMinutesField:t.schedule.ruleSlotMinutesField,ruleAdvanceHoursField:t.schedule.ruleAdvanceHoursField,ruleAdvanceDaysField:t.schedule.ruleAdvanceDaysField,campusEnabledField:t.schedule.campusEnabledField,ruleEnabledField:t.schedule.ruleEnabledField,dateField:t.schedule.dateField,timeField:t.schedule.timeField}}:{},...t.draft?{draft:{...t.draft}}:{},...t.validations?{validations:ne(t.validations.map(o=>({code:o.code,kind:o.kind,fields:U(o.fields),result:o.result})),o=>o.code)}:{}})),t=>t.code)}}function Vn(e){let t=[{owner:"platform:admin-entry",path:"/"},{owner:"platform:admin-entry",path:"/admin"},{owner:"platform:file-preview",path:"/files/:resourceCode/:fileId/preview"}];e.frontend.authentication&&t.push({owner:"authentication:desktop",path:e.frontend.authentication.surfaces.desktop.path},{owner:"authentication:mobile",path:e.frontend.authentication.surfaces.mobile.path});for(let o of e.data.resources){let n=wn(o),i=`/admin/resources/${o.code}`,r=[["list",i],["detail",`${i}/:id`],["create",`${i}/new`],["update",`${i}/:id/edit`]];for(let[a,s]of r)n[a]&&t.push({owner:`resource:${o.code}:${a}`,path:s},{owner:`resource:${o.code}:${a}:mobile`,path:`/m${s}`})}if(e.frontend.user.applicationTodoCenter===!0&&t.push({owner:"application:todo-center",path:"/todos"},{owner:"application:todo-center:mobile",path:"/m/todos"}),e.workflows.definitions.length>0){t.push({owner:"workflow:work-center",path:"/work-center"},{owner:"workflow:work-center:mobile",path:"/m/work-center"},{owner:"workflow:task",path:"/tasks/:taskId"},{owner:"workflow:task:mobile",path:"/m/tasks/:taskId"},{owner:"workflow:instance",path:"/workflows/:instanceId"},{owner:"workflow:instance:mobile",path:"/m/workflows/:instanceId"});let o=!1;for(let n of e.workflows.definitions)["standalone","hidden-handoff"].includes(n.launch.mode)&&(o=!0);o&&t.push({owner:"workflow:launch",path:"/workflows/:workflowCode/start"},{owner:"workflow:launch:mobile",path:"/m/workflows/:workflowCode/start"})}return t}function qe(e){let t=new Map(Vn(e).map(o=>[Ye(o.path),o]));return ne(e.frontend.routes.map((o,n)=>{let i=`/config/frontend/routes/${n}`,r=I(o,i);C(r,["code","path","label","surface","parentCode","capability","access","pinned","tabPersistence","keepAlive"],i,!0),["admin","user"].includes(r.surface)||u("NATIVE_ROUTE_SURFACE_INVALID",`${i}/surface`);let a=se(r.path,`${i}/path`);r.surface==="admin"&&a!=="/admin"&&!a.startsWith("/admin/")&&u("NATIVE_ADMIN_ROUTE_PATH_INVALID",`${i}/path`),r.surface==="user"&&(a==="/admin"||a.startsWith("/admin/"))&&u("NATIVE_USER_ROUTE_PATH_RESERVED",`${i}/path`);let s=Ye(a),l=t.get(s);l&&u("NATIVE_ROUTE_PATH_CONFLICT",`${i}/path`,{path:a,owner:l.owner}),t.set(s,{owner:`frontend:${String(r.code||n)}`,path:a});let p=/[:*]/.test(a),_=Dt(r,i,e.appCode),d=r.pinned===void 0?void 0:De(r.pinned,`${i}/pinned`),c=r.tabPersistence===void 0?p?"none":"session":$(r.tabPersistence,`${i}/tabPersistence`,16),A=r.keepAlive===void 0?"none":$(r.keepAlive,`${i}/keepAlive`,16);return["session","none"].includes(c)||u("NATIVE_ROUTE_TAB_PERSISTENCE_INVALID",`${i}/tabPersistence`),["none","memory"].includes(A)||u("NATIVE_ROUTE_KEEP_ALIVE_INVALID",`${i}/keepAlive`),p&&d===!0&&u("NATIVE_DYNAMIC_ROUTE_PINNED_FORBIDDEN",`${i}/pinned`),p&&c==="session"&&u("NATIVE_DYNAMIC_ROUTE_TAB_PERSISTENCE_FORBIDDEN",`${i}/tabPersistence`),p&&A==="memory"&&u("NATIVE_DYNAMIC_ROUTE_KEEP_ALIVE_FORBIDDEN",`${i}/keepAlive`),{code:y(r.code,`${i}/code`),path:a,label:$(r.label,`${i}/label`,255),surface:r.surface,...r.parentCode===void 0?{}:{parentCode:y(r.parentCode,`${i}/parentCode`)},..._,...d===void 0?{}:{pinned:d},tabPersistence:c,keepAlive:A}}),o=>o.code)}function wn(e){let t=e.surface===void 0?{}:I(e.surface,"/surface"),o=t.mutationOwner||"native",n=t.generated===void 0?{}:I(t.generated,"/surface/generated"),i=o==="native";return{list:n.list??!0,detail:n.detail??!0,create:n.create??i,update:n.update??i,delete:n.delete??i}}function Pn(e){let t=[];for(let o of ne(e.data.resources,n=>n.code).flatMap(n=>[{resource:n,viewCode:void 0},...(n.surface?.views||[]).map(i=>({viewCode:i.code,resource:{...n,name:i.name,surface:pt(n.surface,i.code)}}))])){let{resource:n,viewCode:i}=o,r=`/admin/resources/${n.code}${i?`/views/${i}`:""}`,a=wn(n),s=[{operation:"list",kind:"resource-list",path:`${r}`,label:n.name,capability:n.capabilities.read,navigationEligible:!0},{operation:"detail",kind:"resource-detail",path:`${r}/:id`,label:`${n.name}\u8BE6\u60C5`,capability:n.capabilities.read,navigationEligible:!1},{operation:"create",kind:"resource-create",path:`${r}/new`,label:`\u65B0\u589E${n.name}`,capability:n.capabilities.create,navigationEligible:!1},{operation:"update",kind:"resource-update",path:`${r}/:id/edit`,label:`\u7F16\u8F91${n.name}`,capability:n.capabilities.update,navigationEligible:!1}];for(let l of s)a[l.operation]&&t.push({code:`resource:${n.code}${i?`:view:${i}`:""}:${l.operation}`,kind:l.kind,path:l.path,label:l.label,navigationEligible:l.navigationEligible,capability:l.capability,resourceCode:n.code,...i?{viewCode:i}:{}})}for(let o of qe(e))o.surface==="admin"&&t.push({code:`operation:${o.code}`,kind:"operation",path:o.path,label:o.label,navigationEligible:!/[:*]/.test(o.path),routeCode:o.code});return t.sort((o,n)=>ie(o.code,n.code))}function Fn(e){return e.kind==="resource"?`resource:${e.resourceCode}${e.viewCode?`:view:${e.viewCode}`:""}:list`:`operation:${e.routeCode}`}function yi(e){return e.frontend.admin.navigation.map((t,o)=>({code:t.code,label:t.label,...t.icon===void 0?{}:{icon:t.icon},order:t.order??o,items:t.items.map((n,i)=>({pageCode:Fn(n.page),...n.label===void 0?{}:{label:n.label},...n.icon===void 0?{}:{icon:n.icon},order:n.order??i})).sort((n,i)=>n.order-i.order||ie(n.pageCode,i.pageCode))})).sort((t,o)=>t.order-o.order||ie(t.code,o.code))}function Vi(e,t){let o=h(e,t,K.adminNavigationGroups),n=0;o.forEach((i,r)=>{let a=`${t}/${r}`,s=I(i,a);C(s,["code","label","icon","order","items"],a,!0),y(s.code,`${a}/code`),$(s.label,`${a}/label`,255),He(s.icon,`${a}/icon`),mn(s.order,`${a}/order`);let l=h(s.items,`${a}/items`,500);l.length===0&&u("NATIVE_ADMIN_GROUP_ORPHANED",`${a}/items`),n+=l.length,n>K.adminNavigationItems&&u("NATIVE_ARRAY_LIMIT_EXCEEDED",t),l.forEach((p,_)=>{let d=`${a}/items/${_}`,c=I(p,d);C(c,["page","label","icon","order"],d,!0),wi(c.page,`${d}/page`),c.label!==void 0&&$(c.label,`${d}/label`,255),He(c.icon,`${d}/icon`),mn(c.order,`${d}/order`)})})}function wi(e,t){let o=I(e,t),n=$(o.kind,`${t}/kind`,64);if(n==="resource"){C(o,["kind","resourceCode"],t,["viewCode"]),o.viewCode!==void 0&&y(o.viewCode,`${t}/viewCode`),G(o.resourceCode,`${t}/resourceCode`);return}if(n==="operation"){C(o,["kind","routeCode"],t),y(o.routeCode,`${t}/routeCode`);return}u("NATIVE_ADMIN_PAGE_REFERENCE_KIND_INVALID",`${t}/kind`)}function Pi(e){let t=new Map(Pn(e).map(i=>[String(i.code),i])),o=new Set,n=new Set;e.frontend.admin.navigation.forEach((i,r)=>{let a=`/config/frontend/admin/navigation/${r}`;o.has(i.code)&&u("NATIVE_ADMIN_GROUP_DUPLICATE",`${a}/code`),o.add(i.code),i.label===i.code&&u("NATIVE_ADMIN_USER_LABEL_REQUIRED",`${a}/label`),i.items.forEach((s,l)=>{let p=`${a}/items/${l}`,_=Fn(s.page),d=t.get(_);(!d||d.navigationEligible!==!0)&&u("NATIVE_ADMIN_PAGE_NOT_FOUND",`${p}/page`),n.has(_)&&u("NATIVE_ADMIN_PAGE_DUPLICATE",`${p}/page`),n.add(_);let c=s.page.resourceCode||s.page.routeCode||s.page.workflowCode||_,A=s.label||d.label;(!A||A===c||A===_)&&u("NATIVE_ADMIN_USER_LABEL_REQUIRED",`${p}/label`)})})}function Fi(e,t){let o=h(e,t,K.adminPages),n=new Set;o.forEach((i,r)=>{let a=`${t}/${r}`,s=I(i,a);C(s,["code","kind","path","label","navigationEligible","capability","access","resourceCode","viewCode","routeCode"],a,!0);let l=$(s.code,`${a}/code`,255);n.has(l)&&u("NATIVE_ADMIN_PAGE_DUPLICATE",`${a}/code`),n.add(l);let p=$(s.kind,`${a}/kind`,64);if(["resource-list","resource-detail","resource-create","resource-update","operation"].includes(p)||u("NATIVE_ADMIN_PAGE_KIND_INVALID",`${a}/kind`),se(s.path,`${a}/path`),$(s.label,`${a}/label`,255),De(s.navigationEligible,`${a}/navigationEligible`),s.capability!==void 0&&s.access!==void 0&&u("NATIVE_ROUTE_ACCESS_CONFLICT",`${a}/access`),s.capability!==void 0&&$(s.capability,`${a}/capability`,255),s.access!==void 0){let _=I(s.access,`${a}/access`);C(_,["allOf","anyOf"],`${a}/access`,!0);for(let d of["allOf","anyOf"])_[d]!==void 0&&F(_[d],`${a}/access/${d}`,50)}for(let _ of["resourceCode","viewCode","routeCode"])s[_]!==void 0&&y(s[_],`${a}/${_}`)})}function vi(e,t){let o=h(e,t,K.adminNavigationGroups),n=0;o.forEach((i,r)=>{let a=`${t}/${r}`,s=I(i,a);C(s,["code","label","icon","order","items"],a,!0),y(s.code,`${a}/code`),$(s.label,`${a}/label`,255),He(s.icon,`${a}/icon`),Z(s.order,`${a}/order`,-1e4,1e4);let l=h(s.items,`${a}/items`,500);l.length===0&&u("NATIVE_ADMIN_GROUP_ORPHANED",`${a}/items`),n+=l.length,n>K.adminNavigationItems&&u("NATIVE_ARRAY_LIMIT_EXCEEDED",t),l.forEach((p,_)=>{let d=`${a}/items/${_}`,c=I(p,d);C(c,["pageCode","label","icon","order"],d,!0),$(c.pageCode,`${d}/pageCode`,255),c.label!==void 0&&$(c.label,`${d}/label`,255),He(c.icon,`${d}/icon`),Z(c.order,`${d}/order`,-1e4,1e4)})})}var Li=new Set(["application-todo-center","workflow-work-center","workflow-launch","workflow-task","workflow-instance","resource-records","resource-submit"]);function ki(e,t,o){let n=I(e,t);C(n,["schemaVersion","appCode","devicePolicy","rootEntry","authentication","routes","digest"],t),v(n.schemaVersion,Dn,`${t}/schemaVersion`),v(n.appCode,o,`${t}/appCode`),Rt(n.devicePolicy,`${t}/devicePolicy`),xi(n.rootEntry,`${t}/rootEntry`),Ui(n.authentication,`${t}/authentication`),$t(n.digest,`${t}/digest`);let i=h(n.routes,`${t}/routes`,K.routes),r=new Set;i.forEach((a,s)=>{let l=`${t}/routes/${s}`,p=I(a,l),_=p.kind==="resource-records"||p.kind==="resource-submit";C(p,["code","kind","desktop","mobile"],l,["workflowCode",..._?["resourceCode"]:[]]);let d=$(p.code,`${l}/code`,255);r.has(d)&&u("NATIVE_ROUTE_MANIFEST_DUPLICATE",`${l}/code`),r.add(d);let c=$(p.kind,`${l}/kind`,64);if(Li.has(c)||u("NATIVE_ROUTE_MANIFEST_KIND_INVALID",`${l}/kind`),p.workflowCode!==void 0&&y(p.workflowCode,`${l}/workflowCode`),_){let E=G(p.resourceCode,`${l}/resourceCode`);v(d,`user.${E}.${p.kind==="resource-records"?"records":"submit"}`,`${l}/code`)}else p.resourceCode!==void 0&&u("NATIVE_PROPERTY_UNKNOWN",`${l}/resourceCode`);let A=En(p.desktop,`${l}/desktop`,o),f=En(p.mobile,`${l}/mobile`,o);A.surface!=="user"&&u("NATIVE_ROUTE_MANIFEST_DESKTOP_SURFACE_INVALID",`${l}/desktop/surface`),f.surface!=="user"&&u("NATIVE_ROUTE_MANIFEST_MOBILE_SURFACE_INVALID",`${l}/mobile/surface`),A.routeCode===f.routeCode&&u("NATIVE_ROUTE_MANIFEST_PAIR_DUPLICATE",l)}),v(n.digest,X({schemaVersion:n.schemaVersion,appCode:n.appCode,devicePolicy:n.devicePolicy,rootEntry:n.rootEntry,authentication:n.authentication,routes:n.routes}),`${t}/digest`)}function Rt(e,t){let o=I(e,t);C(o,["kind","mobileMaxWidthPx","desktopMinWidthPx"],t),v(o.kind,"viewport-family",`${t}/kind`);let n=Z(o.mobileMaxWidthPx,`${t}/mobileMaxWidthPx`,320,1600),i=Z(o.desktopMinWidthPx,`${t}/desktopMinWidthPx`,320,1600);return i!==n+1&&u("NATIVE_FRONTEND_DEVICE_POLICY_INVALID",t),{kind:"viewport-family",mobileMaxWidthPx:n,desktopMinWidthPx:i}}function xi(e,t){let o=I(e,t);C(o,["code","desktop","mobile"],t);let n=y(o.code,`${t}/code`),i=Ot(o.desktop,`${t}/desktop`),r=Ot(o.mobile,`${t}/mobile`);return(i===r||r==="/"||!r.startsWith("/m/"))&&u("NATIVE_ROUTE_MANIFEST_ROOT_ENTRY_INVALID",t),i.startsWith("/m/")&&u("NATIVE_ROUTE_MANIFEST_ROOT_ENTRY_INVALID",`${t}/desktop`),{code:n,desktop:i,mobile:r}}function Ui(e,t){let o=I(e,t);C(o,["desktop","mobile"],t);let n=_n(o.desktop,`${t}/desktop`,!1),i=_n(o.mobile,`${t}/mobile`,!0);return(n.routeCode===i.routeCode||n.path===i.path)&&u("NATIVE_ROUTE_MANIFEST_AUTHENTICATION_DUPLICATE",t),{desktop:n,mobile:i}}function _n(e,t,o){let n=I(e,t);C(n,["routeCode","path"],t);let i=y(n.routeCode,`${t}/routeCode`),r=Ot(n.path,`${t}/path`);return(o?!r.startsWith("/m/"):r.startsWith("/m/"))&&u("NATIVE_ROUTE_MANIFEST_AUTHENTICATION_PATH_INVALID",`${t}/path`),{routeCode:i,path:r}}function Ot(e,t){let o=se(e,t);return/[:*?#\\\\]/.test(o)&&u("NATIVE_ROUTE_MANIFEST_STATIC_PATH_INVALID",t),o}function En(e,t,o){let n=I(e,t);C(n,["routeCode","path","surface","pathParams","requiresAuthentication"],t,["capability","access"]),y(n.routeCode,`${t}/routeCode`);let i=se(n.path,`${t}/path`),r=$(n.surface,`${t}/surface`,16);["admin","user"].includes(r)||u("NATIVE_ROUTE_SURFACE_INVALID",`${t}/surface`);let a=F(n.pathParams,`${t}/pathParams`,8);return a.forEach((s,l)=>{(!/^[A-Za-z][A-Za-z0-9_]*$/.test(s)||s.length>64)&&u("NATIVE_ROUTE_PATH_PARAM_INVALID",`${t}/pathParams/${l}`)}),H(a)!==H(vn(i))&&u("NATIVE_ROUTE_PATH_PARAMS_MISMATCH",`${t}/pathParams`),Dt(n,t,o),n.requiresAuthentication!==!0&&u("NATIVE_ROUTE_AUTHENTICATION_REQUIRED",`${t}/requiresAuthentication`),n}function vn(e){return U([...e.matchAll(/:([A-Za-z][A-Za-z0-9_]*)/g)].map(t=>t[1]))}function An(e,t,o,n){return{routeCode:e,path:t,surface:o,pathParams:vn(t),...n?.capability?{capability:n.capability}:{},...n?.access?{access:n.access}:{},requiresAuthentication:!0}}function In(e,t,o,n){return e==="workflow-launch"?`workflow.${o}.launch.${t}`:e==="application-todo-center"?`application.todo-center.${t}`:e==="resource-records"?`user.${n}.records.${t}`:e==="resource-submit"?`user.${n}.submit.${t}`:`${e.replace(/-/g,".")}.${t}`}function Mi(e){let t=e.appCode,o=[],n=(A,f,E,N,m,g,T)=>{o.push({code:A,kind:f,...m?{workflowCode:m}:{},...T?{resourceCode:T}:{},desktop:An(In(f,"desktop",m,T),E,"user",g),mobile:An(In(f,"mobile",m,T),N,"user",g)})};e.frontend.user.applicationTodoCenter===!0&&n("application:todo-center","application-todo-center","/todos","/m/todos");let i=Ln(e);i.length>0&&(n("workflow:work-center","workflow-work-center","/work-center","/m/work-center"),n("workflow:task","workflow-task","/tasks/:taskId","/m/tasks/:taskId"),n("workflow:instance","workflow-instance","/workflows/:instanceId","/m/workflows/:instanceId"));for(let A of i){if(!["standalone","hidden-handoff"].includes(A.launch.mode))continue;let f=U([A.launch.submission?.create?.requiredCapability,A.launch.submission?.existing?.requiredCapability].filter(E=>!!E));n(`workflow:${A.code}:launch`,"workflow-launch","/workflows/:workflowCode/start","/m/workflows/:workflowCode/start",A.code,f.length===1?{capability:f[0]}:f.length>1?{access:{anyOf:f}}:void 0)}let r=o.sort((A,f)=>ie(String(A.code),String(f.code))),a=qe(e),s=A=>{let f=A==="mobile"?"/m/":"/",E=a.filter(m=>m.surface==="user"&&!/[:*?#\\\\]/.test(m.path)&&m.path===f).sort((m,g)=>ie(m.code,g.code))[0];if(E)return{code:E.code,path:E.path};let N=a.filter(m=>m.surface==="user"&&!/[:*?#\\\\]/.test(m.path)&&(A==="mobile"?m.path.startsWith("/m/"):!m.path.startsWith("/m/"))).sort((m,g)=>ie(m.code,g.code))[0];return N?{code:N.code,path:N.path}:{code:A==="mobile"?"application-root-mobile":"application-root",path:f}},l=e.frontend.authentication?{desktop:{routeCode:e.frontend.authentication.surfaces.desktop.routeCode,path:e.frontend.authentication.surfaces.desktop.path},mobile:{routeCode:e.frontend.authentication.surfaces.mobile.routeCode,path:e.frontend.authentication.surfaces.mobile.path}}:{desktop:{routeCode:"application-login",path:"/login"},mobile:{routeCode:"application-login-mobile",path:"/m/login"}},p=Rt(e.frontend.devicePolicy,"/config/frontend/devicePolicy"),_=s("desktop"),d=s("mobile"),c={schemaVersion:Dn,appCode:t,devicePolicy:p,rootEntry:{code:_.code,desktop:_.path,mobile:d.path},authentication:l,routes:r};return{...c,digest:X(c)}}function He(e,t){if(e===void 0)return;let o=$(e,t,32);ti.has(o)||u("NATIVE_ADMIN_ICON_INVALID",t)}function mn(e,t){e!==void 0&&Z(e,t,-1e4,1e4)}function Dt(e,t,o){return e.capability!==void 0&&e.access!==void 0&&u("NATIVE_ROUTE_ACCESS_CONFLICT",`${t}/access`),e.capability!==void 0?{capability:Ae(e.capability,`${t}/capability`,o)}:e.access===void 0?{}:{access:Xe(e.access,`${t}/access`,o)}}function Xe(e,t,o){let n=I(e,t);C(n,["allOf","anyOf"],t,!0);let i=n.allOf===void 0?void 0:U(F(n.allOf,`${t}/allOf`,50).map((a,s)=>Ae(a,`${t}/allOf/${s}`,o))),r=n.anyOf===void 0?void 0:U(F(n.anyOf,`${t}/anyOf`,50).map((a,s)=>Ae(a,`${t}/anyOf/${s}`,o)));return(i?.length||0)+(r?.length||0)===0&&u("NATIVE_ROUTE_ACCESS_EMPTY",t),{...i===void 0?{}:{allOf:i},...r===void 0?{}:{anyOf:r}}}function Ln(e){let t=new Map(Sn(e).map(i=>[String(i.code),i])),o=e.workflows.definitions.map((i,r)=>{let a=`/config/workflows/definitions/${r}`,s=I(i,a);C(s,["version","definition","launch"],a,["detailRouteCode"]);let l=I(s.definition,`${a}/definition`),p=s.detailRouteCode===void 0?void 0:xn(s.detailRouteCode,`${a}/detailRouteCode`);return{code:y(l.code,`${a}/definition/code`),title:$(l.title,`${a}/definition/title`,255),version:Re(s.version,`${a}/version`),launch:ji(e,l,s.launch,`${a}/launch`,t),...p?{detailRouteCode:p}:{},definition:l}});return U(o.map(i=>i.code)).map(i=>{let r=o.filter(p=>p.code===i),a=e.workflows.activations.find(p=>p.workflowCode===i)?.definitionVersion,s=r.find(p=>p.version===a)||[...r].sort((p,_)=>_.version-p.version)[0],l=new Set;for(let p of r){let _=I(p.definition.nodes,"/config/workflows/definitions/nodes");for(let d of Object.values(_)){let c=I(d,"/config/workflows/definitions/nodes/*");if(c.kind==="approval")for(let A of F(c.allowedOperations||[],"/config/workflows/definitions/nodes/*/allowedOperations",20))l.add(A)}}return{code:i,title:s.title,acceptedCommandDeactivationPolicy:s.definition.acceptedCommandDeactivationPolicy,subject:s.definition.subject,launch:s.launch,...["standalone","hidden-handoff"].includes(s.launch.mode)&&!s.launch.submission?{processOperationCode:`openxiangda.workflow.${i}.submit`}:{},...s.detailRouteCode?{detailRouteCode:s.detailRouteCode}:{},definitionVersions:hn(r.map(p=>p.version)),bindingVersions:hn(e.workflows.bindings.map((p,_)=>{let d=`/config/workflows/bindings/${_}`,c=I(p,d),A=I(c.binding,`${d}/binding`);return{code:y(A.workflowCode,`${d}/binding/workflowCode`),version:Re(c.version,`${d}/version`)}}).filter(p=>p.code===i).map(p=>p.version)),providerCodes:U(e.workflows.providers.map((p,_)=>y(I(p,`/config/workflows/providers/${_}`).code,`/config/workflows/providers/${_}/code`))),allowedOperations:[...l].sort(ie),editableParameterCodes:U(e.workflows.editableParameters.map((p,_)=>{let d=`/config/workflows/editableParameters/${_}`,c=I(p,d);return{code:y(c.code,`${d}/code`),workflowCode:y(c.workflowCode,`${d}/workflowCode`)}}).filter(p=>p.workflowCode===i).map(p=>p.code))}})}function kn(e,t){let o=I(e,t);C(o,["mode"],t,["submission"]);let n=$(o.mode,`${t}/mode`,32);return["standalone","custom-page","hidden-handoff","work-center-only"].includes(n)||u("NATIVE_WORKFLOW_LAUNCH_MODE_INVALID",`${t}/mode`),{mode:n,...o.submission===void 0?{}:{submission:I(o.submission,`${t}/submission`)}}}function ji(e,t,o,n,i){let r=kn(o,n);if(!r.submission)return{mode:r.mode};["standalone","hidden-handoff"].includes(r.mode)||u("NATIVE_WORKFLOW_NAMED_OPERATION_SUBMISSION_INVALID",`${n}/submission`);let a=I(r.submission,`${n}/submission`);C(a,["kind"],`${n}/submission`,["create","existing","context"]),v(a.kind,"named-operation",`${n}/submission/kind`);let s=n.endsWith("/launch")?n.slice(0,-7):n,l=I(t.subject,`${s}/definition/subject`),p=G(l.resourceCode,`${s}/definition/subject/resourceCode`),_=e.data.resources.findIndex(O=>O.code===p),d=e.data.resources[_];(_<0||!d)&&u("NATIVE_WORKFLOW_SUBJECT_RESOURCE_MISSING",`${s}/definition/subject/resourceCode`);let c=new Set(I(d.schema,`/config/data/resources/${_}/schema`).fields.map(O=>String(O.code))),A=new Map(e.backend.operations.map(O=>[String(O.code),O])),f=(O,V)=>{let w=`${n}/submission/${V}`,x=I(O,w);C(x,["operationCode","inputs","output"],w);let M=y(x.operationCode,`${w}/operationCode`),ee=A.get(M),B=i.get(M),Ie=B?.platformAccess?.workflow?.codes;(!ee||!B||B.method!=="POST"||!Array.isArray(Ie)||!Ie.includes(t.code))&&u("NATIVE_WORKFLOW_NAMED_OPERATION_INVALID",w);let ge=I(ee.requestSchema,`${w}/operation/requestSchema`),q=I(ge.properties,`${w}/operation/requestSchema/properties`),Te=new Set(ge.required===void 0?[]:F(ge.required,`${w}/operation/requestSchema/required`,64)),me=I(x.inputs,`${w}/inputs`),S=Object.entries(me);(!S.length||S.length>64)&&u("NATIVE_WORKFLOW_NAMED_OPERATION_INPUT_INVALID",`${w}/inputs`);let k=new Set,L=new Map,W={};for(let[j,Y]of S){(!un.test(j)||!Object.prototype.hasOwnProperty.call(q,j))&&u("NATIVE_WORKFLOW_NAMED_OPERATION_INPUT_INVALID",`${w}/inputs/${j}`);let Ce=`${w}/inputs/${j}`,Ze=I(Y,Ce),Ne=$(Ze.source,`${Ce}/source`,32);if(["field","idempotency-key","current-user-reference","subject-id","subject-revision","requested-at"].includes(Ne)||u("NATIVE_WORKFLOW_NAMED_OPERATION_INPUT_INVALID",Ce),C(Ze,["source"],Ce,Ne==="field"?["fieldCode"]:!1),L.set(Ne,(L.get(Ne)||0)+1),Ne==="field"){let xe=z(Ze.fieldCode,`${Ce}/fieldCode`);(k.has(xe)||!c.has(xe))&&u("NATIVE_WORKFLOW_NAMED_OPERATION_INPUT_INVALID",`${Ce}/fieldCode`),k.add(xe),W[j]={source:Ne,fieldCode:xe}}else W[j]={source:Ne}}([...Te].some(j=>!(j in me))||(L.get("idempotency-key")||0)!==1||!S.some(([j,Y])=>I(Y,`${w}/inputs/${j}`).source==="idempotency-key"&&Te.has(j))||V==="create"&&((L.get("subject-id")||0)>0||(L.get("subject-revision")||0)>0)||V==="existing"&&((L.get("subject-id")||0)!==1||(L.get("subject-revision")||0)!==1))&&u("NATIVE_WORKFLOW_NAMED_OPERATION_INPUT_INVALID",`${w}/inputs`);let J=I(x.output,`${w}/output`);C(J,["subjectId"],`${w}/output`,["subjectRevision","processCommand"]);let de=I(I(ee.responseSchema,`${w}/operation/responseSchema`).properties,`${w}/operation/responseSchema/properties`);for(let j of["subjectId","subjectRevision","processCommand"]){if(J[j]===void 0)continue;let Y=$(J[j],`${w}/output/${j}`,128);(!un.test(Y)||!Object.prototype.hasOwnProperty.call(de,Y))&&u("NATIVE_WORKFLOW_NAMED_OPERATION_OUTPUT_INVALID",`${w}/output/${j}`)}return{operationCode:M,method:"POST",path:B.path,requiredCapability:B.requiredCapability,requestSchemaDigest:B.requestSchemaDigest,responseSchemaDigest:B.responseSchemaDigest,inputs:W,output:{...J},fieldCodes:k}},E=a.create===void 0?void 0:f(a.create,"create"),N=a.existing===void 0?void 0:f(a.existing,"existing");!E&&!N&&u("NATIVE_WORKFLOW_NAMED_OPERATION_SUBMISSION_INVALID",`${n}/submission`);let m=new Set([...E?.fieldCodes||[],...N?.fieldCodes||[]]),g=a.context===void 0?[]:h(a.context,`${n}/submission/context`,16),T=new Set,D=g.map((O,V)=>{let w=`${n}/submission/context/${V}`,x=I(O,w);C(x,["queryParameter","fieldCode"],w);let M=$(x.queryParameter,`${w}/queryParameter`,64),ee=z(x.fieldCode,`${w}/fieldCode`);return(!/^[A-Za-z][A-Za-z0-9]{0,63}$/.test(M)||T.has(M)||!m.has(ee))&&u("NATIVE_WORKFLOW_LAUNCH_CONTEXT_INVALID",w),T.add(M),{queryParameter:M,fieldCode:ee}}),b=O=>{let{fieldCodes:V,...w}=O;return w};return{mode:r.mode,submission:{kind:"named-operation",...E?{create:b(E)}:{},...N?{existing:b(N)}:{},context:D}}}function xn(e,t){let o=I(e,t);C(o,["desktop","mobile"],t);let n=y(o.desktop,`${t}/desktop`),i=y(o.mobile,`${t}/mobile`);return n===i&&u("NATIVE_WORKFLOW_DETAIL_ROUTE_DUPLICATE",t),{desktop:n,mobile:i}}function Wi(e,t){let o=new Set(t.map(_=>_.code)),n=new Map;e.data.resources.forEach((_,d)=>{let c=`/config/data/resources/${d}`,A=I(_,c);for(let[N,m]of Object.entries(A.fieldPolicies||{})){if(!Se(N))continue;let g=`${c}/fieldPolicies/${N}/read`,T=I(m,`${c}/fieldPolicies/${N}`);for(let D of F(T.read||[],g,2e3))o.has(D)||u("NATIVE_CAPABILITY_REFERENCE_MISSING",g)}if(((A.surface===void 0?{}:I(A.surface,`${c}/surface`)).mutationOwner||"native")==="native")return;let E=I(A.capabilities,`${c}/capabilities`);for(let N of["create","update","delete"])n.set(String(E[N]),N)});let i=new Set;for(let[_,d]of e.authz.roles.entries()){let c=`/config/authz/roles/${_}`,A=I(d,c);C(A,["code","name","description","capabilities"],c,!0);let f=y(A.code,`${c}/code`);i.has(f)&&u("NATIVE_ROLE_DUPLICATE",`${c}/code`),i.add(f),$(A.name,`${c}/name`,255);let E=F(A.capabilities,`${c}/capabilities`,2e3);for(let[N,m]of E.entries())n.has(m)&&u("NATIVE_DATA_SURFACE_MUTATION_GRANT_FORBIDDEN",`${c}/capabilities/${N}`,{operation:n.get(m)}),o.has(m)||u("NATIVE_CAPABILITY_REFERENCE_MISSING",`${c}/capabilities`)}let r=e.authz.authenticatedUserRoleCode===void 0?"":y(e.authz.authenticatedUserRoleCode,"/config/authz/authenticatedUserRoleCode");r&&!i.has(r)&&u("NATIVE_AUTHENTICATED_USER_ROLE_REFERENCE_MISSING","/config/authz/authenticatedUserRoleCode");let a=new Set,s=0;for(let[_,d]of e.perspectives.entries()){let c=`/config/perspectives/${_}`,A=I(d,c);C(A,["code","name","description","roleCodes","capabilityCodes","default"],c,!0);let f=y(A.code,`${c}/code`);a.has(f)&&u("NATIVE_PERSPECTIVE_DUPLICATE",`${c}/code`),a.add(f),$(A.name,`${c}/name`,255);let E=F(A.roleCodes,`${c}/roleCodes`,20);E.length<1&&u("NATIVE_PERSPECTIVE_ROLE_REQUIRED",`${c}/roleCodes`),E.forEach((g,T)=>{i.has(g)||u("NATIVE_PERSPECTIVE_ROLE_MISSING",`${c}/roleCodes/${T}`)});let N=U(e.authz.roles.filter(g=>E.includes(g.code)).flatMap(g=>g.capabilities)),m=F(A.capabilityCodes,`${c}/capabilityCodes`,2e3);H(N)!==H(m)&&u("NATIVE_PERSPECTIVE_CAPABILITY_PROJECTION_MISMATCH",`${c}/capabilityCodes`),A.default===!0?s+=1:A.default!==void 0&&u("NATIVE_PERSPECTIVE_DEFAULT_INVALID",`${c}/default`)}s>1&&u("NATIVE_PERSPECTIVE_DEFAULT_DUPLICATE","/config/perspectives");for(let[_,d]of e.backend.operations.entries()){let c=I(d,`/config/backend/operations/${_}`);o.has(c.capability)||u("NATIVE_CAPABILITY_REFERENCE_MISSING",`/config/backend/operations/${_}/capability`)}let l=new Set,p=new Set;for(let[_,d]of e.frontend.routes.entries()){let c=`/config/frontend/routes/${_}`,A=I(d,c),f=y(A.code,`${c}/code`);l.has(f)&&u("NATIVE_ROUTE_DUPLICATE",`${c}/code`),l.add(f);let E=se(A.path,`${c}/path`);p.has(E)&&u("NATIVE_ROUTE_PATH_DUPLICATE",`${c}/path`),p.add(E);let N=Dt(A,c,e.appCode);N.capability&&!o.has(N.capability)&&u("NATIVE_CAPABILITY_REFERENCE_MISSING",`${c}/capability`);let m=A.access===void 0?void 0:I(A.access,`${c}/access`);for(let g of["allOf","anyOf"]){let T=m?.[g]===void 0?[]:h(m[g],`${c}/access/${g}`,50);for(let[D,b]of T.entries()){let O=Ae(b,`${c}/access/${g}/${D}`,e.appCode);o.has(O)||u("NATIVE_CAPABILITY_REFERENCE_MISSING",`${c}/access/${g}/${D}`)}}}if(e.frontend.admin.access!==void 0){let _=Xe(e.frontend.admin.access,"/config/frontend/admin/access",e.appCode);for(let d of["allOf","anyOf"])for(let[c,A]of(_[d]||[]).entries())o.has(A)||u("NATIVE_CAPABILITY_REFERENCE_MISSING",`/config/frontend/admin/access/${d}/${c}`)}for(let[_,d]of e.frontend.routes.entries()){let c=I(d,`/config/frontend/routes/${_}`);c.parentCode&&!l.has(c.parentCode)&&u("NATIVE_ROUTE_PARENT_MISSING",`/config/frontend/routes/${_}/parentCode`)}}function Bi(e){let t=new Set(e.authz.roles.map(p=>String(p.code))),o=e.authz.authenticatedUserRoleCode===void 0?"":y(e.authz.authenticatedUserRoleCode,"/config/authz/authenticatedUserRoleCode"),n=new Map(e.authz.scopeDimensions.map(p=>[String(p.code),{valueType:p.valueType==="uuid"?"uuid":"string",...p.valueSource?.resourceCode?{valueSourceResourceCode:String(p.valueSource.resourceCode)}:{}}])),i=new Set(n.keys()),r=new Map(e.data.resources.map((p,_)=>{let d=ke(p,`/config/data/resources/${_}`,e.appCode);return[d.code,new Map(d.schema.fields.map(c=>[String(c.code),c]))]}));for(let[p,_]of e.authz.scopeDimensions.entries()){let d=`/config/authz/scopeDimensions/${p}`,c=I(_,d);if(C(c,["code","name","resourceCode","valueType","hierarchyMode","valueSource"],d,!0),c.valueSource===void 0)continue;let A=I(c.valueSource,`${d}/valueSource`);C(A,["kind","resourceCode","labelField","enabledField"],`${d}/valueSource`,!0),A.kind!=="native_resource"&&u("NATIVE_SCOPE_VALUE_SOURCE_KIND_INVALID",`${d}/valueSource/kind`),c.valueType!=="uuid"&&u("NATIVE_SCOPE_VALUE_SOURCE_TYPE_INVALID",`${d}/valueType`);let f=G(A.resourceCode,`${d}/valueSource/resourceCode`),E=r.get(f);E||u("NATIVE_SCOPE_VALUE_SOURCE_RESOURCE_MISSING",`${d}/valueSource/resourceCode`);let N=z(A.labelField,`${d}/valueSource/labelField`);if(["text.short","text.long"].includes(String(E.get(N)?.type||""))||u("NATIVE_SCOPE_VALUE_SOURCE_LABEL_FIELD_INVALID",`${d}/valueSource/labelField`),A.enabledField!==void 0){let m=z(A.enabledField,`${d}/valueSource/enabledField`);E.get(m)?.type!=="boolean"&&u("NATIVE_SCOPE_VALUE_SOURCE_ENABLED_FIELD_INVALID",`${d}/valueSource/enabledField`)}}let a=new Set,s=new Set;for(let[p,_]of e.authz.scopeSources.entries()){let d=`/config/authz/scopeSources/${p}`,c=I(_,d);C(c,["code","name","resourceCode","subject","grants","operationField","enabledField","effectiveFromField","effectiveToField","failureMode"],d,!0);let A=y(c.code,`${d}/code`);a.has(A)&&u("NATIVE_SCOPE_SOURCE_DUPLICATE",`${d}/code`),a.add(A),$(c.name,`${d}/name`,255);let f=G(c.resourceCode,`${d}/resourceCode`),E=r.get(f);E||u("NATIVE_SCOPE_SOURCE_RESOURCE_MISSING",`${d}/resourceCode`);let N=I(c.subject,`${d}/subject`),m=$(N.type,`${d}/subject/type`,32);C(N,m==="role_membership"?["type","userIdField","roleCode"]:["type","userIdField"],`${d}/subject`),["user","role_membership"].includes(m)||u("NATIVE_SCOPE_SOURCE_SUBJECT_INVALID",`${d}/subject/type`);let g=Ve(N.userIdField,E);At(g)||u("NATIVE_SCOPE_SOURCE_SUBJECT_PATH_INVALID",`${d}/subject/userIdField`),m==="role_membership"&&!t.has(String(N.roleCode))&&u("NATIVE_ROLE_REFERENCE_MISSING",`${d}/subject/roleCode`);let T=new Set;for(let[D,b]of h(c.grants,`${d}/grants`,100).entries()){let O=`${d}/grants/${D}`,V=I(b,O);C(V,["dimensionCode","valueField","parentValueField"],O,!0);let w=y(V.dimensionCode,`${O}/dimensionCode`);(!i.has(w)||T.has(w))&&u("NATIVE_SCOPE_SOURCE_DIMENSION_INVALID",`${O}/dimensionCode`),T.add(w),c.failureMode==="last_known_good"&&s.add(w);for(let x of["valueField","parentValueField"]){if(V[x]===void 0)continue;let M=Ve(V[x],E);en(M,n.get(w),r)||u("NATIVE_SCOPE_SOURCE_GRANT_PATH_INVALID",`${O}/${x}`)}}T.size===0&&u("NATIVE_SCOPE_SOURCE_GRANT_REQUIRED",`${d}/grants`),["strict","last_known_good"].includes(c.failureMode)||u("NATIVE_SCOPE_SOURCE_FAILURE_MODE_INVALID",`${d}/failureMode`);for(let D of["operationField","enabledField","effectiveFromField","effectiveToField"]){if(c[D]===void 0)continue;let b=z(c[D],`${d}/${D}`);E.has(b)||u("NATIVE_SCOPE_SOURCE_FIELD_MISSING",`${d}/${D}`)}}Gi(e,t,r,o);let l=new Set;for(let[p,_]of e.authz.dataPolicies.entries()){let d=`/config/authz/dataPolicies/${p}`,c=I(_,d);C(c,["code","name","resourceCode","unrestrictedRoleCodes","operations","matchMode","rules","readExpression","writeBoundary"],d,!0);let A=y(c.code,`${d}/code`);l.has(A)&&u("NATIVE_DATA_POLICY_DUPLICATE",`${d}/code`),l.add(A);let f=c.readExpression!==void 0,E=F(c.operations||[],`${d}/operations`,4);c.operations!==void 0&&(E.length===0||E.some(b=>!["read","create","update","delete"].includes(b)))&&u("NATIVE_DATA_POLICY_OPERATIONS_INVALID",`${d}/operations`),["AND","OR"].includes(c.matchMode)||u("NATIVE_DATA_POLICY_MATCH_MODE_INVALID",`${d}/matchMode`),f&&c.operations!==void 0&&u("NATIVE_DATA_POLICY_READ_EXPRESSION_OPERATIONS_FORBIDDEN",`${d}/operations`);let N=e.data.resources.find(b=>b.dataPolicyCode===A),m=c.resourceCode||N?.code,g=m?r.get(G(m,`${d}/resourceCode`)):void 0;f&&!g&&u("NATIVE_DATA_POLICY_RESOURCE_MISSING",`${d}/resourceCode`);let T=F(c.unrestrictedRoleCodes||[],`${d}/unrestrictedRoleCodes`,100);c.unrestrictedRoleCodes!==void 0&&T.length===0&&u("NATIVE_DATA_POLICY_UNRESTRICTED_ROLES_INVALID",`${d}/unrestrictedRoleCodes`);for(let b of T)t.has(b)||u("NATIVE_ROLE_REFERENCE_MISSING",`${d}/unrestrictedRoleCodes`);let D;try{let b=h(c.rules,`${d}/rules`,100).map((O,V)=>({rule:I(O,`${d}/rules/${V}`),pointer:`${d}/rules/${V}`}));b.length===0?(!f||c.matchMode!=="AND"||c.writeBoundary!=="capability_only")&&u("NATIVE_DATA_POLICY_WRITE_BOUNDARY_REQUIRED",d):c.writeBoundary!==void 0&&u("NATIVE_DATA_POLICY_WRITE_BOUNDARY_INVALID",`${d}/writeBoundary`),D=[...b],f&&(D.push(...ze(c.readExpression,`${d}/readExpression`)),cn(c.readExpression,`${d}/readExpression`))}catch(b){throw b instanceof Fe&&u(b.code,b.pointer),b}for(let{rule:b,pointer:O}of D){C(b,["subject","dimensionCode","relationCode","resourceCode","field","roleCodes","operation","valuePath","emptyMatchesAll","operator","value","operand"],O,!0);let V=z(b.field,`${O}/field`),w=g?.get(V);f&&!w&&u("NATIVE_DATA_POLICY_FIELD_MISSING",`${O}/field`);for(let q of F(b.roleCodes||[],`${O}/roleCodes`,100))t.has(q)||u("NATIVE_ROLE_REFERENCE_MISSING",`${O}/roleCodes`);let x=String(b.operator||""),M=b.operand==="db_now",ee=["is_null","is_not_null"].includes(x),B=["eq","not_eq","in","not_in"].includes(x),Ie=!M&&(b.operator!==void 0||b.value!==void 0);if([b.subject==="current_user"?"current_user":"",typeof b.dimensionCode=="string"?"dimension":"",typeof b.relationCode=="string"?"relationship":"",Ie?"constant":"",M?"db_now":""].filter(Boolean).length!==1&&u("NATIVE_DATA_POLICY_RULE_SOURCE_INVALID",O),b.subject!==void 0&&b.subject!=="current_user"&&u("NATIVE_DATA_POLICY_SUBJECT_INVALID",`${O}/subject`),Ie){if(!B&&!ee&&u("NATIVE_DATA_POLICY_OPERATOR_INVALID",`${O}/operator`),["in","not_in"].includes(x)){let q=h(b.value,`${O}/value`,100).map((Te,me)=>$(Te,`${O}/value/${me}`,2048));(q.length===0||new Set(q).size!==q.length)&&u("NATIVE_DATA_POLICY_VALUE_INVALID",`${O}/value`)}else["eq","not_eq"].includes(x)?$(b.value,`${O}/value`,2048):(b.value!==void 0||b.operand!==void 0)&&u("NATIVE_DATA_POLICY_VALUE_INVALID",`${O}/value`);for(let q of["operation","valuePath","emptyMatchesAll","resourceCode","operand"])b[q]!==void 0&&u("NATIVE_DATA_POLICY_CONSTANT_RULE_INVALID",`${O}/${q}`)}if(M){(!["lt","lte","gt","gte"].includes(x)||b.value!==void 0||w?.type!=="datetime")&&u("NATIVE_DATA_POLICY_DB_NOW_INVALID",O);for(let q of["operation","valuePath","emptyMatchesAll","resourceCode","value"])b[q]!==void 0&&u("NATIVE_DATA_POLICY_DB_NOW_INVALID",`${O}/${q}`)}b.dimensionCode&&!i.has(b.dimensionCode)&&u("NATIVE_SCOPE_DIMENSION_MISSING",`${O}/dimensionCode`),s.has(String(b.dimensionCode||""))&&b.operation!=="read"&&u("NATIVE_SCOPE_SOURCE_LAST_KNOWN_GOOD_UNSAFE",`${O}/operation`)}}for(let[p,_]of e.data.resources.entries()){let d=I(_,`/config/data/resources/${p}`);d.dataPolicyCode&&!l.has(d.dataPolicyCode)&&u("NATIVE_DATA_POLICY_REFERENCE_MISSING",`/config/data/resources/${p}/dataPolicyCode`)}}function Ji(e){try{kt(e.data.resources,"/config/data/resources")}catch(t){throw t instanceof ue&&u(t.code,t.pointer),t}}function Gi(e,t,o,n){let i=new Set;for(let[r,a]of e.authz.roleMembershipSources.entries()){let s=`/config/authz/roleMembershipSources/${r}`,l=I(a,s);C(l,["code","name","resourceCode","userIdField","roleCode","enabledField","effectiveFromField","effectiveToField","failureMode"],s,!0);let p=y(l.code,`${s}/code`);p.length>100&&u("NATIVE_AUTHORIZATION_PROJECTION_SOURCE_CODE_INVALID",`${s}/code`),i.has(p)&&u("NATIVE_AUTHORIZATION_PROJECTION_SOURCE_DUPLICATE",`${s}/code`),i.add(p),$(l.name,`${s}/name`,255);let _=Nn(l.resourceCode,`${s}/resourceCode`,o);gn(l.userIdField,`${s}/userIdField`,_),t.has(String(l.roleCode||""))||u("NATIVE_ROLE_REFERENCE_MISSING",`${s}/roleCode`),n&&l.roleCode===n&&u("NATIVE_AUTHENTICATED_USER_ROLE_SOURCE_CONFLICT",`${s}/roleCode`),Tn(l,s,_)}for(let[r,a]of e.authz.relationshipGrantSources.entries()){let s=`/config/authz/relationshipGrantSources/${r}`,l=I(a,s);C(l,["code","name","resourceCode","subject","relationCode","targetResourceCode","resourceIdField","operations","enabledField","effectiveFromField","effectiveToField","failureMode"],s,!0);let p=y(l.code,`${s}/code`);p.length>100&&u("NATIVE_AUTHORIZATION_PROJECTION_SOURCE_CODE_INVALID",`${s}/code`),i.has(p)&&u("NATIVE_AUTHORIZATION_PROJECTION_SOURCE_DUPLICATE",`${s}/code`),i.add(p),$(l.name,`${s}/name`,255);let _=Nn(l.resourceCode,`${s}/resourceCode`,o),d=I(l.subject,`${s}/subject`),c=$(d.type,`${s}/subject/type`,32);C(d,c==="role_membership"?["type","userIdField","roleCode"]:["type","userIdField"],`${s}/subject`),["user","role_membership"].includes(c)||u("NATIVE_AUTHORIZATION_PROJECTION_SUBJECT_INVALID",`${s}/subject/type`),gn(d.userIdField,`${s}/subject/userIdField`,_),c==="role_membership"&&!t.has(String(d.roleCode||""))&&u("NATIVE_ROLE_REFERENCE_MISSING",`${s}/subject/roleCode`),y(l.relationCode,`${s}/relationCode`);let A=G(l.targetResourceCode,`${s}/targetResourceCode`);o.has(A)||u("NATIVE_AUTHORIZATION_PROJECTION_TARGET_RESOURCE_MISSING",`${s}/targetResourceCode`);let f=Ve(l.resourceIdField,_),E=f?.field.type==="resource-ref.single"&&f.valuePath==="value"&&f.field.source?.resourceCode===A;(l.resourceIdField==="id"?A!==String(l.resourceCode):!E)&&u("NATIVE_AUTHORIZATION_PROJECTION_RESOURCE_ID_FIELD_INVALID",`${s}/resourceIdField`);let N=F(l.operations,`${s}/operations`,20);(N.length===0||N.some(m=>m.length>64||!/^[A-Za-z0-9][A-Za-z0-9:._*-]{0,63}$/.test(m)))&&u("NATIVE_AUTHORIZATION_PROJECTION_OPERATIONS_INVALID",`${s}/operations`),Tn(l,s,_)}}function Nn(e,t,o){let n=G(e,t),i=o.get(n);return i||u("NATIVE_AUTHORIZATION_PROJECTION_RESOURCE_MISSING",t),i}function gn(e,t,o){let n=Ve(e,o);At(n)||u("NATIVE_AUTHORIZATION_PROJECTION_USER_FIELD_INVALID",t)}function Tn(e,t,o){if(e.failureMode!=="strict"&&u("NATIVE_AUTHORIZATION_PROJECTION_FAILURE_MODE_INVALID",`${t}/failureMode`),e.enabledField!==void 0){let n=z(e.enabledField,`${t}/enabledField`);o.get(n)?.type!=="boolean"&&u("NATIVE_AUTHORIZATION_PROJECTION_ENABLED_FIELD_INVALID",`${t}/enabledField`)}for(let n of["effectiveFromField","effectiveToField"]){if(e[n]===void 0)continue;let i=z(e[n],`${t}/${n}`);["date","datetime"].includes(String(o.get(i)?.type))||u("NATIVE_AUTHORIZATION_PROJECTION_EFFECTIVE_FIELD_INVALID",`${t}/${n}`)}}function zi(e){let t=new Set,o=new Set;e.forEach((n,i)=>{let r=`/config/backend/secrets/${i}`,a=I(n,r);C(a,["name","env","description","required","exposure"],r,!0);let s=$(a.name,`${r}/name`,128),l=$(a.env,`${r}/env`,128);Yo.test(s)||u("NATIVE_SECRET_NAME_INVALID",`${r}/name`),(!Ho.test(l)||l.startsWith("OPENXIANGDA_")||["NODE_ENV","PORT"].includes(l))&&u("NATIVE_SECRET_ENV_INVALID",`${r}/env`),t.has(s)&&u("NATIVE_SECRET_NAME_DUPLICATE",`${r}/name`),o.has(l)&&u("NATIVE_SECRET_ENV_DUPLICATE",`${r}/env`),t.add(s),o.add(l),v(a.exposure,"active_only",`${r}/exposure`),a.required!==void 0&&De(a.required,`${r}/required`),a.description!==void 0&&St(a.description,`${r}/description`,2e3)})}function Yi(e){let t=new Set,o=new Map,n=new Map(e.data.resources.map(c=>[String(c.code),c])),i=new Map(e.frontend.routes.map((c,A)=>{let f=I(c,`/config/frontend/routes/${A}`);return[y(f.code,`/config/frontend/routes/${A}/code`),f]}));for(let[c,A]of e.workflows.definitions.entries()){let f=`/config/workflows/definitions/${c}`,E=I(A,f);if(C(E,["version","definition","launch"],f,["detailRouteCode"]),kn(E.launch,`${f}/launch`),E.detailRouteCode!==void 0){let T=xn(E.detailRouteCode,`${f}/detailRouteCode`);for(let[D,b,O]of[["desktop",T.desktop,"admin"],["mobile",T.mobile,"user"]]){let V=`${f}/detailRouteCode/${D}`,w=i.get(b);w||u("NATIVE_WORKFLOW_DETAIL_ROUTE_MISSING",V),w.surface!==O&&u("NATIVE_WORKFLOW_DETAIL_ROUTE_SURFACE_INVALID",V);let x=se(w.path,V),M=[...x.matchAll(/:([A-Za-z][A-Za-z0-9_]*)/g)].map(ee=>ee[1]);(x.includes("*")||M.length!==1||M[0]!=="instanceId")&&u("NATIVE_WORKFLOW_DETAIL_ROUTE_PATH_INVALID",V)}}let N=I(E.definition,`${f}/definition`),m=`${N.code}:${Re(E.version,`${f}/version`)}`;t.has(m)&&u("NATIVE_WORKFLOW_DEFINITION_DUPLICATE",f),t.add(m),Ki(N,`${f}/definition`),Hi(N.subject,n,`${f}/definition/subject`);let g=sn(N,{appCode:e.appCode,capabilities:e.authz.capabilities.map(T=>T.code),fields:new Map((n.get(N.subject.resourceCode)?.schema.fields||[]).map(T=>[T.code,T]))});g.length&&u("NATIVE_WORKFLOW_INSTANCE_COMMAND_POLICY_INVALID",`${f}/definition/instanceCommands`,{errors:g}),N.title===N.code&&u("NATIVE_WORKFLOW_USER_TITLE_REQUIRED",`${f}/definition/title`),o.set(m,N)}let r=new Set,a=new Map;for(let[c,A]of e.workflows.bindings.entries()){let f=I(A,`/config/workflows/bindings/${c}`),E=I(f.binding,`/config/workflows/bindings/${c}/binding`),N=`${E.workflowCode}:${Re(f.version,`/config/workflows/bindings/${c}/version`)}`;r.has(N)&&u("NATIVE_WORKFLOW_BINDING_DUPLICATE",`/config/workflows/bindings/${c}`),r.add(N),qi(E,`/config/workflows/bindings/${c}/binding`),a.set(N,E)}let s=new Set,l=new Map;for(let[c,A]of e.workflows.activations.entries()){let f=`/config/workflows/activations/${c}`,E=I(A,f);C(E,["workflowCode","definitionVersion","bindingVersion","acceptedCommandDeactivationPolicy"],f,["environmentKey"]);let N=y(E.workflowCode,`${f}/workflowCode`);s.has(N)&&u("NATIVE_WORKFLOW_ACTIVATION_DUPLICATE",f),s.add(N);let m=`${N}:${Re(E.definitionVersion,`${f}/definitionVersion`)}`,g=`${N}:${Re(E.bindingVersion,`${f}/bindingVersion`)}`;t.has(m)||u("NATIVE_WORKFLOW_DEFINITION_REFERENCE_MISSING",`${f}/definitionVersion`),r.has(g)||u("NATIVE_WORKFLOW_BINDING_REFERENCE_MISSING",`${f}/bindingVersion`);let T=o.get(m),D=a.get(g);(!["finish-pinned","cancel-on-deactivate"].includes(E.acceptedCommandDeactivationPolicy)||E.acceptedCommandDeactivationPolicy!==T.acceptedCommandDeactivationPolicy)&&u("NATIVE_WORKFLOW_COMMAND_DEACTIVATION_POLICY_MISMATCH",`${f}/acceptedCommandDeactivationPolicy`),Xi(T,D,`/config/workflows/activations/${c}`),l.set(N,D)}let p=new Set;e.workflows.providers.forEach((c,A)=>{let f=`/config/workflows/providers/${A}`,E=I(c,f);C(E,["code","endpointPath","timeoutMs"],f,!0);let N=y(E.code,`${f}/code`);p.has(N)&&u("NATIVE_WORKFLOW_PROVIDER_DUPLICATE",`${f}/code`),p.add(N),se(E.endpointPath,`${f}/endpointPath`),E.timeoutMs!==void 0&&Z(E.timeoutMs,`${f}/timeoutMs`,100,1e4)});for(let[c,A]of l.entries())for(let[f,E]of Object.entries(I(A.bindings,"/config/workflows/bindings/*/binding/bindings"))){let N=I(E,`/config/workflows/${c}/bindings/${f}`);N.provider==="application_provider"&&!p.has(N.providerCode)&&u("NATIVE_WORKFLOW_PROVIDER_REFERENCE_MISSING",`/config/workflows/${c}/bindings/${f}/providerCode`)}let _=new Set(e.authz.roles.map(c=>c.code)),d=new Set;e.workflows.editableParameters.forEach((c,A)=>{let f=`/config/workflows/editableParameters/${A}`,E=I(c,f);C(E,["code","workflowCode","bindingKey","label","valueType","required","allowedRoleCodes","allowedProviderCodes","maxItems"],f,!0);let N=y(E.code,`${f}/code`);d.has(N)&&u("NATIVE_WORKFLOW_EDITABLE_PARAMETER_DUPLICATE",`${f}/code`),d.add(N);let m=Qe(E.workflowCode,`${f}/workflowCode`),g=yt(E.bindingKey,`${f}/bindingKey`),T=l.get(m);(!T||!I(T.bindings,`${f}/bindingKey`)[g])&&u("NATIVE_WORKFLOW_EDITABLE_BINDING_MISSING",`${f}/bindingKey`),$(E.label,`${f}/label`,255),["role_code","user_ids","provider_code"].includes(E.valueType)||u("NATIVE_WORKFLOW_EDITABLE_VALUE_TYPE_INVALID",`${f}/valueType`);for(let D of F(E.allowedRoleCodes||[],`${f}/allowedRoleCodes`,100))_.has(D)||u("NATIVE_ROLE_REFERENCE_MISSING",`${f}/allowedRoleCodes`);for(let D of F(E.allowedProviderCodes||[],`${f}/allowedProviderCodes`,100))p.has(D)||u("NATIVE_WORKFLOW_PROVIDER_REFERENCE_MISSING",`${f}/allowedProviderCodes`);E.required!==void 0&&De(E.required,`${f}/required`),E.maxItems!==void 0&&Z(E.maxItems,`${f}/maxItems`,1,200)})}function Hi(e,t,o){let n=I(e,o);C(n,["resourceCode","factProjection"],o,["summaryFields"]);let i=G(n.resourceCode,`${o}/resourceCode`),r=t.get(i);r||u("NATIVE_WORKFLOW_SUBJECT_RESOURCE_MISSING",`${o}/resourceCode`);let a=new Set(h(I(r.schema,`${o}/resourceCode`).fields,`${o}/resourceCode`,500).map((p,_)=>z(I(p,`${o}/resourceCode/${_}`).code,`${o}/resourceCode/${_}`))),s=I(n.factProjection,`${o}/factProjection`),l=Object.entries(s);(l.length<1||l.length>64)&&u("NATIVE_WORKFLOW_SUBJECT_FACT_PROJECTION_INVALID",`${o}/factProjection`);for(let[p,_]of l){Xo.test(p)||u("NATIVE_WORKFLOW_SUBJECT_FACT_KEY_INVALID",`${o}/factProjection/${p}`);let d=z(_,`${o}/factProjection/${p}`);a.has(d)||u("NATIVE_WORKFLOW_SUBJECT_FIELD_MISSING",`${o}/factProjection/${p}`)}if(n.summaryFields!==void 0){let p=F(n.summaryFields,`${o}/summaryFields`,Qo).map((f,E)=>z(f,`${o}/summaryFields/${E}`)),_=t.get(i),d=_.surface&&typeof _.surface=="object"&&!Array.isArray(_.surface)?_.surface:{},c=d.fields&&typeof d.fields=="object"&&!Array.isArray(d.fields)?d.fields:{},A=new Map(h(I(_.schema,`${o}/resourceCode`).fields,`${o}/resourceCode`,500).map((f,E)=>{let N=I(f,`${o}/resourceCode/${E}`);return[String(N.code),N]}));for(let[f,E]of p.entries()){let N=A.get(E),m=c[E],g=String(N?.type||""),T=N?.maxLength;(!N||N.system===!0||m&&typeof m=="object"&&!Array.isArray(m)&&m.system===!0||["id","revision","created_by","updated_by","created_at","updated_at"].includes(E)||!ei.has(g)||g==="text.long"&&typeof T=="number"&&Number.isFinite(T)&&T>Zo)&&u("NATIVE_WORKFLOW_SUBJECT_SUMMARY_FIELDS_INVALID",`${o}/summaryFields/${f}`)}}}function Ki(e,t){C(e,["schemaVersion","code","title","subject","acceptedCommandDeactivationPolicy","startAt","inputSchema","nodes"],t,["organizationContext","instanceCommands"]),v(e.schemaVersion,"openxiangda.workflow-definition/v2",`${t}/schemaVersion`),Qe(e.code,`${t}/code`),$(e.title,`${t}/title`,255),["finish-pinned","cancel-on-deactivate"].includes(e.acceptedCommandDeactivationPolicy)||u("NATIVE_WORKFLOW_COMMAND_DEACTIVATION_POLICY_REQUIRED",`${t}/acceptedCommandDeactivationPolicy`);let o=I(e.nodes,`${t}/nodes`),n=Object.keys(o);(n.length===0||n.length>200)&&u("NATIVE_WORKFLOW_NODE_COUNT_INVALID",`${t}/nodes`);let i=$(e.startAt,`${t}/startAt`,128);o[i]||u("NATIVE_WORKFLOW_START_NODE_MISSING",`${t}/startAt`);let r=new Map;for(let[p,_]of Object.entries(o)){let d=`${t}/nodes/${p}`,c=I(_,d);v(c.id,p,`${d}/id`),["approval","condition","end"].includes(c.kind)||u("NATIVE_WORKFLOW_NODE_KIND_INVALID",`${d}/kind`);let A=[];if(c.kind==="approval"){$(c.title,`${d}/title`,255),yt(c.binding,`${d}/binding`),["single","any","all","sequence"].includes(c.mode)||u("NATIVE_WORKFLOW_APPROVAL_MODE_INVALID",`${d}/mode`),A.push($(c.onApprove,`${d}/onApprove`,128),$(c.onReject,`${d}/onReject`,128));for(let f of F(c.returnTargets||[],`${d}/returnTargets`,200))o[f]||u("NATIVE_WORKFLOW_TARGET_MISSING",`${d}/returnTargets`);for(let f of F(c.allowedOperations||[],`${d}/allowedOperations`,20))ni.has(f)||u("NATIVE_WORKFLOW_OPERATION_INVALID",`${d}/allowedOperations`)}else if(c.kind==="condition"){let f=h(c.branches,`${d}/branches`,100);f.length===0&&u("NATIVE_WORKFLOW_BRANCH_REQUIRED",`${d}/branches`),f.forEach((E,N)=>{let m=I(E,`${d}/branches/${N}`);ve(m.when,`${d}/branches/${N}/when`,0),A.push($(m.target,`${d}/branches/${N}/target`,128))}),A.push($(c.otherwise,`${d}/otherwise`,128))}else $(c.title,`${d}/title`,255),$(c.outcome,`${d}/outcome`,128);for(let f of A)o[f]||u("NATIVE_WORKFLOW_TARGET_MISSING",d);r.set(p,A)}let a=new Set,s=new Set,l=p=>{if(s.has(p)&&u("NATIVE_WORKFLOW_CYCLE_FORBIDDEN",`${t}/nodes/${p}`),!a.has(p)){a.add(p),s.add(p);for(let _ of r.get(p)||[])l(_);s.delete(p)}};l(i),a.size!==n.length&&u("NATIVE_WORKFLOW_NODE_UNREACHABLE",`${t}/nodes`)}function ve(e,t,o){o>20&&u("NATIVE_WORKFLOW_EXPRESSION_DEPTH_EXCEEDED",t);let n=I(e,t),i=$(n.op,`${t}/op`,16);if(i!=="literal"){if(i==="path"){let r=$(n.path,`${t}/path`,255);/^[A-Za-z][A-Za-z0-9_.]{0,254}$/.test(r)||u("NATIVE_WORKFLOW_EXPRESSION_PATH_INVALID",`${t}/path`);return}if(["eq","neq","gt","gte","lt","lte","in","contains"].includes(i)){ve(n.left,`${t}/left`,o+1),ve(n.right,`${t}/right`,o+1);return}if(["and","or"].includes(i)){let r=h(n.values,`${t}/values`,100);r.length===0&&u("NATIVE_WORKFLOW_EXPRESSION_EMPTY",`${t}/values`),r.forEach((a,s)=>ve(a,`${t}/values/${s}`,o+1));return}if(["not","exists"].includes(i)){ve(n.value,`${t}/value`,o+1);return}u("NATIVE_WORKFLOW_EXPRESSION_OPERATOR_INVALID",`${t}/op`)}}function qi(e,t){v(e.schemaVersion,"openxiangda.workflow-binding/v2",`${t}/schemaVersion`),Qe(e.workflowCode,`${t}/workflowCode`);let o=I(e.bindings,`${t}/bindings`);Object.keys(o).length>200&&u("NATIVE_WORKFLOW_BINDING_LIMIT_EXCEEDED",`${t}/bindings`);for(let[n,i]of Object.entries(o)){yt(n,`${t}/bindings/${n}`);let r=I(i,`${t}/bindings/${n}`),a=$(r.provider,`${t}/bindings/${n}/provider`,64);["fixed_users","initiator","input_users","form_field_users","department_supervisor","app_role","app_role_in_scope","business_relation","previous_node_actor","initiator_select","application_provider"].includes(a)||u("NATIVE_WORKFLOW_BINDING_PROVIDER_INVALID",`${t}/bindings/${n}/provider`),a==="fixed_users"&&h(r.users,`${t}/bindings/${n}/users`,200).length===0&&u("NATIVE_WORKFLOW_BINDING_USERS_REQUIRED",`${t}/bindings/${n}/users`),["input_users","form_field_users"].includes(a)&&$(r.inputPath,`${t}/bindings/${n}/inputPath`,255),["app_role","app_role_in_scope","initiator_select"].includes(a)&&y(r.roleCode,`${t}/bindings/${n}/roleCode`),a==="department_supervisor"&&$(r.departmentIdFrom,`${t}/bindings/${n}/departmentIdFrom`,255),a==="application_provider"&&y(r.providerCode,`${t}/bindings/${n}/providerCode`)}}function Xi(e,t,o){v(t.workflowCode,e.code,`${o}/workflowCode`);let n=I(t.bindings,`${o}/bindings`);for(let[i,r]of Object.entries(I(e.nodes,`${o}/nodes`))){let a=I(r,`${o}/nodes/${i}`);a.kind==="approval"&&!n[a.binding]&&u("NATIVE_WORKFLOW_BINDING_REFERENCE_MISSING",`${o}/nodes/${i}/binding`)}}function Qi(e,t,o){let n=I(t.routeManifest,"/contracts/routeManifest"),i=I(e.routeManifest,"/contracts/routeManifest"),r=new Map;for(let _ of h(o.data?.resources,"/config/data/resources",100)){let d=I(_,"/config/data/resources");r.set(String(d.code||""),d)}let a=new Set(h(i.routes,"/contracts/routeManifest/routes",1e3).map(_=>String(I(_,"/contracts/routeManifest/routes").code||""))),s=[];for(let _ of h(n.routes,"/contracts/routeManifest/routes",1e3)){let d=I(_,"/contracts/routeManifest/routes"),c=String(d.kind||"");if(c!=="resource-records"&&c!=="resource-submit")continue;let A=String(d.resourceCode||""),f=r.get(A);f||u("NATIVE_ROUTE_MANIFEST_RESOURCE_UNKNOWN","/contracts/routeManifest/routes");let N=`user.${A}.${c==="resource-records"?"records":"submit"}`;v(String(d.code||""),N,"/contracts/routeManifest/routes/code");let m=c==="resource-records"?"read":"create",g=String(I(f.capabilities,"/config/data/resources/capabilities")[m]||"");for(let T of["desktop","mobile"]){let D=I(d[T],`/contracts/routeManifest/routes/${T}`),b=T==="mobile"?"/m/my/":"/my/",O=c==="resource-records"?`${b}${A}`:`${b}${A}/submit`;v(String(D.path||""),O,`/contracts/routeManifest/routes/${T}/path`),v(String(D.capability||""),g,`/contracts/routeManifest/routes/${T}/capability`),v(String(D.routeCode||""),`${N}.${T}`,`/contracts/routeManifest/routes/${T}/routeCode`)}(a.has(N)||s.some(T=>String(T.code)===N))&&u("NATIVE_ROUTE_MANIFEST_DUPLICATE","/contracts/routeManifest/routes/code"),s.push(d)}if(!s.length)return;i.routes=h([...i.routes,...s],"/contracts/routeManifest/routes",1e3).sort((_,d)=>ie(String(I(_,"x").code||""),String(I(d,"x").code||"")));let l=String(I(n.rootEntry,"x").code||"");if(s.find(_=>String(_.code)===l&&_.kind==="resource-records")){let _=I(n.rootEntry,"x");i.rootEntry={code:l,desktop:String(_.desktop||""),mobile:String(_.mobile||"")}}i.digest=X({schemaVersion:i.schemaVersion,appCode:i.appCode,devicePolicy:i.devicePolicy,rootEntry:i.rootEntry,authentication:i.authentication,routes:i.routes})}function ke(e,t,o){let n=I(e,t);C(n,["schemaVersion","appCode","code","name","schema","surface","invariants","capabilities","dataPolicyCode","fieldPolicies"],t,!0),v(n.schemaVersion,"openxiangda.data-resource/v2",`${t}/schemaVersion`),v(n.appCode,o,`${t}/appCode`);let i=G(n.code,`${t}/code`),r=$(n.name,`${t}/name`,255),a=I(n.schema,`${t}/schema`);C(a,["fields"],`${t}/schema`);let s,l;try{s=it(a.fields,`${t}/schema/fields`),l=xt(n.invariants,s,`${t}/invariants`),ft(n.surface,s,`${t}/surface`)}catch(c){throw c instanceof ue&&u(c.code,c.pointer),c}let p=new Set(s.map(c=>c.code)),_=I(n.capabilities,`${t}/capabilities`);C(_,["read","create","update","delete"],`${t}/capabilities`);let d=I(n.fieldPolicies,`${t}/fieldPolicies`);for(let[c,A]of Object.entries(d)){!p.has(c)&&!Se(c)&&u("NATIVE_DATA_FIELD_POLICY_FIELD_MISSING",`${t}/fieldPolicies/${c}`);let f=`${t}/fieldPolicies/${c}`,E=I(A,f);Se(c)&&(C(E,["read"],f,!0),(!Array.isArray(E.read)||E.read.length>20||E.read.some(N=>typeof N!="string"||!N.trim())||new Set(E.read).size!==E.read.length)&&u("NATIVE_DATA_AUDIT_READ_POLICY_INVALID",`${f}/read`)),C(E,["read","create","update","mask"],f,!0),E.mask!==void 0&&!["omit","null"].includes(E.mask)&&u("NATIVE_DATA_FIELD_POLICY_MASK_INVALID",`${f}/mask`)}return{...n,code:i,name:r,schema:{fields:s},...n.invariants===void 0?{}:{invariants:l},capabilities:_,fieldPolicies:d}}function Un(e){return[{code:`app:${e}:directory:read`,kind:"platform",name:"\u8BFB\u53D6\u53D7\u9650\u7EC4\u7EC7\u76EE\u5F55",source:"platform"},...[["app:role:read","\u67E5\u770B\u89D2\u8272\u4E0E\u6388\u6743"],["app:role:define","\u5B9A\u4E49\u624B\u5DE5\u89D2\u8272"],["app:role:assign","\u5206\u914D\u89D2\u8272\u6210\u5458"],["app:role:grant-capability","\u6388\u4E88\u89D2\u8272\u80FD\u529B"],["app:scope-grant:manage","\u7BA1\u7406\u6570\u636E\u8303\u56F4"],["app:super-admin:manage","\u7BA1\u7406\u5E94\u7528\u6700\u9AD8\u7BA1\u7406\u5458"]].map(([t,o])=>({code:t,kind:"platform",name:o,source:"platform"}))]}function Cn(e,t,o,n){let i=e.toString("utf8"),r;try{r=JSON.parse(i)}catch{u(o,t)}let a=I(r,t);return H(a)!==i&&u(n,t),a}function bn(e,t){let o=0,n=(i,r,a)=>{if(o+=1,o>ri&&u("NATIVE_ARTIFACT_NODE_LIMIT_EXCEEDED",r),a>si&&u("NATIVE_ARTIFACT_DEPTH_LIMIT_EXCEEDED",r),typeof i=="string"){Buffer.byteLength(i)>gt&&u("NATIVE_ARTIFACT_STRING_LIMIT_EXCEEDED",r);return}if(Array.isArray(i)){i.forEach((s,l)=>n(s,`${r}/${l}`,a+1));return}if(!(!i||typeof i!="object"))for(let[s,l]of Object.entries(i))["__proto__","prototype","constructor"].includes(s)&&u("NATIVE_ARTIFACT_DANGEROUS_KEY",`${r}/${s}`),Zi(s)&&u("NATIVE_ARTIFACT_RUNTIME_FIELD_FORBIDDEN",`${r}/${s}`),n(l,`${r}/${s}`,a+1)};n(e,t,0)}function Zi(e){return["environmentKey","environmentId","secretValue","ciphertext","oauthClient","oauthClientId","oauthClientSecret","signingSecret","kubernetesNamespace","nodePort","productionUrl"].includes(e)}function he(e){return{value:e,digest:X(e)}}function On(e,t,o,n){typeof e!="string"&&!Buffer.isBuffer(e)&&!(e instanceof Uint8Array)&&u("NATIVE_ARTIFACT_BYTES_REQUIRED",o);let i=Buffer.isBuffer(e)?e:Buffer.from(e);return i.byteLength===0&&u("NATIVE_ARTIFACT_EMPTY",o),i.byteLength>t&&u(n,o),i}function $n(e,t,o,n){let i=Ke.createHash("sha256").update(e).digest("hex");Ke.timingSafeEqual(Buffer.from(i),Buffer.from(t))||u(n,o)}function I(e,t){return(!e||typeof e!="object"||Array.isArray(e))&&u("NATIVE_OBJECT_REQUIRED",t),e}function h(e,t,o){return Array.isArray(e)||u("NATIVE_ARRAY_REQUIRED",t),e.length>o&&u("NATIVE_ARRAY_LIMIT_EXCEEDED",t),e}function F(e,t,o){let n=h(e,t,o).map((i,r)=>$(i,`${t}/${r}`,255));return new Set(n).size!==n.length&&u("NATIVE_ARRAY_DUPLICATE",t),n}function $(e,t,o){return(typeof e!="string"||e.length===0||e.length>o)&&u("NATIVE_STRING_INVALID",t),e}function St(e,t,o){return(typeof e!="string"||e.length>o)&&u("NATIVE_STRING_INVALID",t),e}function y(e,t){let o=$(e,t,128);return Bo.test(o)||u("NATIVE_CODE_INVALID",t),o}function G(e,t){let o=$(e,t,64);return Go.test(o)||u("NATIVE_RESOURCE_CODE_INVALID",t),o}function z(e,t){let o=$(e,t,63);return zo.test(o)||u("NATIVE_FIELD_CODE_INVALID",t),o}function Qe(e,t){let o=$(e,t,128);return Ko.test(o)||u("NATIVE_WORKFLOW_CODE_INVALID",t),o}function yt(e,t){let o=$(e,t,128);return qo.test(o)||u("NATIVE_WORKFLOW_BINDING_CODE_INVALID",t),o}function Ae(e,t,o){let n=$(e,t,255);return Wo.test(n)||u("NATIVE_CAPABILITY_CODE_INVALID",t),!n.startsWith(`app:${o}:`)&&!Un(o).some(i=>i.code===n)&&u("NATIVE_CAPABILITY_APP_MISMATCH",t),n}function se(e,t){let o=$(e,t,2048);return(!o.startsWith("/")||o.startsWith("//")||o.includes("..")||o.includes("?")||o.includes("#"))&&u("NATIVE_ABSOLUTE_PATH_INVALID",t),o}function Re(e,t){return(!Number.isInteger(e)||Number(e)<1)&&u("NATIVE_POSITIVE_INTEGER_REQUIRED",t),Number(e)}function Z(e,t,o,n){return(!Number.isInteger(e)||Number(e)<o||Number(e)>n)&&u("NATIVE_INTEGER_OUT_OF_RANGE",t),Number(e)}function De(e,t){return typeof e!="boolean"&&u("NATIVE_BOOLEAN_REQUIRED",t),e}function $t(e,t){let o=$(e,t,64).toLowerCase();return Mo.test(o)||u("NATIVE_DIGEST_INVALID",t),o}function v(e,t,o){e!==t&&u("NATIVE_VALUE_MISMATCH",o)}function C(e,t,o,n=!1){let i=new Set([...t,...Array.isArray(n)?n:[]]);for(let r of Object.keys(e))i.has(r)||u("NATIVE_PROPERTY_UNKNOWN",`${o}/${r}`);if(n!==!0)for(let r of t)Object.prototype.hasOwnProperty.call(e,r)||u("NATIVE_PROPERTY_REQUIRED",`${o}/${r}`)}function ne(e,t){return[...e].sort((o,n)=>ie(t(o),t(n)))}function U(e){return[...new Set(e)].sort(ie)}function hn(e){return[...new Set(e)].sort((t,o)=>t-o)}function ie(e,t){return e===t?0:e<t?-1:1}function Mn(e){return!e||typeof e!="object"||Object.isFrozen(e)||(Object.freeze(e),Object.values(e).forEach(t=>Mn(t))),e}function ht(e,t,o){if(Nt(e,t))return o;if(Array.isArray(e)&&Array.isArray(t)){let n=Math.max(e.length,t.length);for(let i=0;i<n;i+=1)if(!Nt(e[i],t[i]))return ht(e[i],t[i],`${o}/${i}`)}if(e&&t&&typeof e=="object"&&typeof t=="object"&&!Array.isArray(e)&&!Array.isArray(t)){let n=U([...Object.keys(e),...Object.keys(t)]);for(let i of n){let r=e[i],a=t[i];if(!Nt(r,a))return ht(r,a,`${o}/${i}`)}}return o}function Nt(e,t){return e===void 0||t===void 0?e===t:H(e)===H(t)}function u(e,t,o={}){throw new bt(e,t,o)}var cr="7f24caff61e91c02bf2731b154aa24d0033458ae21206175ebfc772ea135bb18";export{Ut as DATA_AUDIT_METADATA_FIELDS,Tt as DATA_EVENT_TYPES_V2,eo as DATA_SYSTEM_SORT_FIELD_CODES,cr as NATIVE_CONFIGURATION_VALIDATOR_DIGEST,K as NATIVE_CONTRACT_CAPACITY_V2,Gs as NATIVE_DATA_POLICY_EXPRESSION_MAX_CLAUSES,Ws as NATIVE_DATA_POLICY_EXPRESSION_MAX_DEPTH,Bs as NATIVE_DATA_POLICY_EXPRESSION_MAX_GROUP_ITEMS,Js as NATIVE_DATA_POLICY_EXPRESSION_MAX_LEAVES,zs as NATIVE_DATA_POLICY_EXPRESSION_MAX_OCCURRENCES,to as NATIVE_DATA_QUERY_OPERATORS_V2,bt as NativeConfigurationCompilerError,ue as NativeDataFieldContractV2Error,Fe as NativeDataPolicyExpressionV2Error,It as NativeEventActionContractError,Et as NativeScopeSourceFieldPathV2Error,Bn as OPENXIANGDA_NATIVE_DATA_FIELD_TYPES_V2,pe as OPENXIANGDA_NATIVE_DATA_SURFACE_KEYS_V2,ot as OPENXIANGDA_NATIVE_SYSTEM_FIELDS_V2,ns as OPENXIANGDA_NATIVE_SYSTEM_FIELD_MAP_V2,Ct as WORKFLOW_EVENT_TYPES_V2,rr as compileNativeApplicationConfiguration,nn as compileNativeEventAction,ui as compileNativeEventCapturePlansV2,li as compileRequiredPlatformCapabilitiesV3,Mt as hasDataAuditReadPolicy,Se as isDataAuditMetadataField,jt as isDataSystemSortField,rs as isNativeDataQueryOperatorV2,je as isNativeMultiValueFieldV2,Ps as materializeNativeDataQueryPathTypesV2,ze as nativeDataPolicyExpressionLeavesV2,cn as nativeDataPolicyExpressionToCnfV2,Fs as nativeDataQueryPathPlanV2,cs as nativeFieldAggregatePlanV2,Cs as nativeFieldColumnDefinitionV2,bs as nativeFieldDefaultSqlV2,Os as nativeFieldHasDefaultV2,Ds as nativeFieldIndexStatementsV2,We as nativeFieldRequiresCreateInputV2,Rs as nativeFieldSequenceGrantStatementsV2,hs as nativeFieldSequenceOwnershipStatementsV2,$s as nativeFieldSequenceStatementsV2,Gt as nativeFieldSupportsFilterV2,as as nativeFieldSupportsOperatorV2,ct as nativeFieldSupportsSearchV2,dt as nativeFieldSupportsSortV2,Jt as nativeOperatorsForFieldV2,Co as nativePhysicalFieldV2,Ts as nativePhysicalFieldsV2,_e as nativePhysicalObjectNameV2,Vs as nativeScopeSourceFieldValueV2,en as nativeScopeSourceGrantPathSupportedV2,At as nativeScopeSourceSubjectPathSupportedV2,Ss as nativeSubtableConstraintStatementsV2,it as parseNativeDataFieldsV2,xt as parseNativeDataResourceInvariantsV2,pt as projectNativeDataResourceViewV2,te as quoteNativeIdentifierV2,Ve as resolveNativeScopeSourceFieldPathV2,kt as validateNativeDataResourceReferencesV2,ft as validateNativeDataResourceSurfaceV2,sn as validateWorkflowInstanceCommandPolicies,Us as workflowInstanceCommandDeadlineError,xs as workflowInstanceTerminateCapabilityAllowed,on as workflowPolicyTimestamp};
8
+ END $native_subtable$`]}function Ne(e,...t){return`${e}_${No("sha256").update(t.join(":")).digest("hex").slice(0,32)}`}function ne(e){if(!/^[A-Za-z_][A-Za-z0-9_]{0,62}$/.test(e))throw new Error("OPENXIANGDA_NATIVE_IDENTIFIER_INVALID");return`"${e}"`}function $o(e,t){return e.type==="subtable"?"none":t?"gin-trigram":e.indexed?["date-range","datetime-range"].includes(e.type)?"gist-range":pt.has(e.type)?"btree-snapshot-expressions":To.has(e.type)?"gin-jsonb-path":"btree":"none"}function Ro(e){switch(e.type){case"text.short":return`varchar(${e.maxLength??255})`;case"text.long":case"text.rich":return"text";case"number.integer":return"bigint";case"number.decimal":return`numeric(${e.precision??38},${e.scale??10})`;case"boolean":return"boolean";case"date":return"date";case"time":return"time(0)";case"datetime":return"timestamptz";case"date-range":return"daterange";case"datetime-range":return"tstzrange";case"uuid":return"uuid";case"serial-number":return"varchar(255)";case"subtable":return"child-resource";default:return bo.has(e.type),"jsonb"}}function Xt(e,t){if(Be(t.type)&&t.type!=="subtable")return"'[]'::jsonb";if(t.type!=="serial-number")return"";let o=Kt(t.serial?.prefix||""),n=t.serial?.digits??6;return`(${o} || lpad(nextval(${Kt(ze(e,t.code))})::text, ${n}, '0'))`}function ho(e,t){return Ht.has(t.type)?` CHECK (${e} IS NULL OR jsonb_typeof(${e}) = 'array')`:go.has(t.type)?` CHECK (${e} IS NULL OR jsonb_typeof(${e}) = 'object')`:""}function Ge(e){return`"app_data".${ne(e)}`}function ze(e,t){let o=Ne("seq",e,t);return`"app_data".${ne(o)}`}function Kt(e){return`'${e.replace(/'/g,"''")}'`}var Qt=new Set(["option.single","option.multiple","user.single","user.multiple","department.single","department.multiple","resource-ref.single","resource-ref.multiple"]),So=new Set([...Qt,"cascade.single","cascade.multiple","file","image","signature","address","location","json"]),Zt=/^[A-Za-z][A-Za-z0-9_]{0,62}$/,Do=new Set(["__proto__","prototype","constructor"]),Et=class extends Error{constructor(o){super("OPENXIANGDA_SCOPE_PROJECTION_FIELD_PATH_INVALID");this.path=o;this.name="NativeScopeSourceFieldPathV2Error"}path;code="OPENXIANGDA_SCOPE_PROJECTION_FIELD_PATH_INVALID"};function Fe(e,t){let o=tn(e);if(!o)return null;let n=t.get(o[0]);if(!n)return null;let s=o.slice(1).join(".")||void 0;return{field:n,...s?{valuePath:s}:{}}}function At(e){return!!(e&&e.field.type==="user.single"&&e.valuePath==="value")}function en(e,t,o){if(!e||!t||!yo(e))return!1;let{field:n,valuePath:s}=e;if(!s)return t.valueType==="uuid"?n.type==="uuid":["text.short","text.long","serial-number"].includes(n.type);if(s==="value")return!(t.valueSourceResourceCode&&n.type.startsWith("resource-ref.")&&n.source?.resourceCode!==t.valueSourceResourceCode);let r=s.slice(9),i=o.get(n.source?.resourceCode||"")?.get(r)?.type;return t.valueType==="uuid"?i==="uuid":["text.short","text.long","serial-number"].includes(i||"")}function Pi(e,t){let o=tn(t);if(!o)throw new Et(String(t||""));let n=e;for(let s of o){if(!n||typeof n!="object"||!Object.prototype.hasOwnProperty.call(n,s))return;n=n[s]}return n}function yo(e){let{field:t,valuePath:o}=e;if(!o)return!So.has(t.type);if(o==="value")return Qt.has(t.type);if(!o.startsWith("snapshot."))return!1;let n=o.slice(9);return Zt.test(n)&&t.type.startsWith("resource-ref.")&&!!t.source?.snapshotFields?.includes(n)}function tn(e){if(typeof e!="string"||e.length===0||e.length>192)return null;let t=e.split(".");return![1,2,3].includes(t.length)||t.some(o=>!Zt.test(o)||Do.has(o))||t.length===2&&t[1]!=="value"||t.length===3&&t[1]!=="snapshot"?null:t}var Vo=new Set(["option.single","user.single","department.single","resource-ref.single"]),wo=new Set(["text.short","text.long","text.rich","number.integer","number.decimal","boolean","date","time","datetime","uuid","serial-number"]),Fo=new Set(["value","label","description","color"]),Po=new Set(["avatarUrl","employeeNo","title","mobile","email"]),Lo=new Set(["fullPath","parent.value","parent.label"]),vo=new Set(["country.value","country.label","province.value","province.label","city.value","city.label","district.value","district.label","street.value","street.label","detail","fullAddress"]),ko=new Set(["longitude","latitude","accuracy"]),Uo=new Set(["address","name","province","city","district","source"]);function vi(e){let t=new Map(e.map(o=>[o.code,new Map(o.schema.fields.map(n=>[n.code,n]))]));return e.map(o=>({...o,schema:{...o.schema,fields:o.schema.fields.map(n=>{let s=xo(n,t);if(!Object.keys(s).length)return n;let r={...n};return Object.defineProperty(r,"queryPathTypes",{configurable:!1,enumerable:!1,writable:!1,value:Object.freeze(s)}),r})}}))}function ki(e,t){if(Vo.has(e.type)&&Fo.has(t)||e.type==="user.single"&&Po.has(t)||e.type==="department.single"&&Lo.has(t))return Pe(t);if(e.type==="resource-ref.single"){let o=e.queryPathTypes?.[t];return o?{parts:t.split("."),type:o}:null}if(e.type==="address"&&vo.has(t))return Pe(t);if(e.type==="location"){if(ko.has(t))return{parts:[t],type:"number.decimal"};if(Uo.has(t))return Pe(t);if(t==="capturedAt")return{parts:[t],type:"datetime"}}return null}function xo(e,t){if(e.type!=="resource-ref.single"||!e.source)return{};let o=t.get(e.source.resourceCode);return o?Object.fromEntries((e.source.snapshotFields||[]).flatMap(n=>{let s=o.get(n);return s?[[`snapshot.${n}`,wo.has(s.type)?s.type:"json"]]:[]})):{}}function Pe(e){return{parts:e.split("."),type:"text.short"}}var It=class extends Error{constructor(o,n){super(n);this.pointer=o}pointer;code="NATIVE_EVENT_ACTION_INVALID"};function nn(e,t,o="/events/subscriptions"){if(e.execution===void 0)return;let n=(A,N)=>{throw new It(`${o}${A}`,N)},s=(A,N,m)=>((!A||typeof A!="object"||Array.isArray(A)||Object.keys(A).some(T=>!m.includes(T)))&&n(N,"Invalid action object or unsupported property"),A),r=s(e.execution,"/execution",["kind","version","operations"]);(r.kind!=="native-data"||r.version!==1)&&n("/execution","Expected native-data version 1"),e.platformAccess&&n("/platformAccess","Native actions do not use application runtime capabilities"),(!Array.isArray(e.eventTypes)||!e.eventTypes.length||e.eventTypes.some(A=>!/^openxiangda\.data\.record\.(created|updated|deleted)\.v2$/.test(A)))&&n("/eventTypes","Native data actions require declared data events");let a=e.filter?.resourceCodes;(!Array.isArray(a)||!a.length||a.length>20)&&n("/filter/resourceCodes","Native actions require explicit source resources");let i=new Map(t.map(A=>[A.code,A])),c=a.map(A=>{let N=i.get(A);return N||n("/filter/resourceCodes","Unknown source resource"),new Set((N.schema?.fields||[]).map(m=>m.code))}),f=new Set(e.payload?.fields||[]),p=e.payload?.includeChanges===!0,l=(A,N)=>{let m=s(A,N,["source","path","value"]);if(m.source==="literal"){(!Object.hasOwn(m,"value")||Object.hasOwn(m,"path"))&&n(N,"Literal binding requires only value");let b;try{b=JSON.stringify(m.value)}catch{n(N,"Literal must be JSON")}return(b===void 0||Buffer.byteLength(b)>65536)&&n(N,"Literal is too large or not JSON"),{source:"literal",value:JSON.parse(b)}}(m.source!=="event"||typeof m.path!="string"||Object.hasOwn(m,"value"))&&n(N,"Expected a literal or event binding");let T=m.path.split(".");(T.length>8||T.some(b=>!/^[A-Za-z0-9_-]+$/.test(b)||["__proto__","prototype","constructor"].includes(b)))&&n(N,"Invalid event path");let C=/^data\.projection\.([A-Za-z][A-Za-z0-9_]{0,62})$/.exec(m.path),$=/^data\.changes\.([A-Za-z][A-Za-z0-9_]{0,62})\.(before|after)$/.exec(m.path);if(C||$){let b=(C||$)[1];c.some(g=>!g.has(b))&&n(N,"Source field must exist on every filtered resource"),f.add(b),$&&(p=!0)}else["id","time","type","subject","data.recordId","data.revision","data.operation","data.resourceCode"].includes(m.path)||n(N,"Event path is not part of the data event contract");return{source:"event",path:m.path}};(!Array.isArray(r.operations)||r.operations.length<1||r.operations.length>16)&&n("/execution/operations","Expected 1 to 16 operations");let u={},E=r.operations.map((A,N)=>{let m=`/execution/operations/${N}`,T=s(A,m,["operation","resourceCode","data","id","expectedRevision"]);["create","update","delete"].includes(T.operation)||n(m,"Unsupported Native operation");let C=i.get(T.resourceCode);C||n(m,"Unknown action target resource");let $=new Map((C.schema?.fields||[]).map(g=>[g.code,g])),b=T.data===void 0?{}:s(T.data,`${m}/data`,[...$.keys()]);return Object.keys(b).length>32&&n(m,"Maximum 32 mapped fields per operation"),T.operation==="create"&&(T.id!==void 0||T.expectedRevision!==void 0)&&n(m,"Create does not accept id or expectedRevision"),T.operation==="delete"&&T.data!==void 0&&n(m,"Delete does not accept data"),Object.keys(b).some(g=>$.get(g)?.type==="serial-number")&&n(m,"Generated fields cannot be assigned"),u[T.resourceCode]=ee(C),{operation:T.operation,resourceCode:T.resourceCode,...T.operation==="create"?{}:{id:l(T.id,`${m}/id`),expectedRevision:l(T.expectedRevision,`${m}/expectedRevision`)},...T.operation==="delete"?{}:{data:Object.fromEntries(Object.entries(b).map(([g,D])=>[g,l(D,`${m}/data/${g}`)]))}}});(f.size>32||[...f].some(A=>c.some(N=>!N.has(A))))&&n("/payload/fields","Payload must contain at most 32 declared source fields");let _={kind:"native-data",version:1,operations:E,resourceDigests:u};return Buffer.byteLength(JSON.stringify(_))>65536&&n("/execution","Action plan exceeds 64 KiB"),{execution:{..._,digest:ee(_)},payload:{includeChanges:p,fields:[...f].sort()}}}function Te(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)?e:void 0}function sn(e,t){if(e?.instanceCommands===void 0)return[];let o=Te(e.instanceCommands);if(!o||!Object.keys(o).length||Object.keys(o).some(s=>!["withdraw","terminate"].includes(s)))return["WORKFLOW_INSTANCE_COMMAND_POLICIES_INVALID"];let n=[];for(let[s,r]of Object.entries(o)){let a=Te(r),i=s==="withdraw"?["beforeFact"]:["beforeFact","capability"];if(!a||Object.keys(a).some(c=>!i.includes(c))){n.push(`WORKFLOW_INSTANCE_COMMAND_POLICY_INVALID:${s}`);continue}if(s==="terminate"){let c=a.capability;(typeof c!="string"||c.length>255||!/^app:[a-z][a-z0-9]*(?:-[a-z0-9]+)*:[A-Za-z0-9:._-]+$/.test(c)||t&&(!c.startsWith(`app:${t.appCode}:`)||!t.capabilities.includes(c)))&&n.push("WORKFLOW_INSTANCE_TERMINATE_CAPABILITY_INVALID")}if(s==="withdraw"||a.beforeFact!==void 0){let c=a.beforeFact,f=Te(e.inputSchema),p=Te(Te(f?.properties)?.[c]),l=Te(Te(e.subject)?.factProjection)?.[c],u=t?.fields.get(l);(typeof c!="string"||!/^[A-Za-z][A-Za-z0-9_]{0,62}$/.test(c)||!Array.isArray(f?.required)||!f.required.includes(c)||p?.type!=="string"||p?.format!=="date-time"||typeof l!="string"||t&&(u?.type!=="datetime"||u.nullable===!0))&&n.push(`WORKFLOW_INSTANCE_COMMAND_DEADLINE_FACT_INVALID:${s}`)}}return n}function ji(e,t){let o=e?.terminate?.capability;return typeof o=="string"&&/^app:[a-z][a-z0-9]*(?:-[a-z0-9]+)*:[A-Za-z0-9:._-]+$/.test(o)&&t.includes(o)}function on(e){if(typeof e!="string")return null;let t=/^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})(?:\.(\d{1,3}))?(Z|[+-]\d{2}:\d{2})$/.exec(e);if(!t)return null;let[,o,n,s,r,a,i]=t,c=t[8],f=new Date(Date.UTC(Number(o),Number(n),0)).getUTCDate();if(Number(n)<1||Number(n)>12||Number(s)<1||Number(s)>f||Number(r)>23||Number(a)>59||Number(i)>59||c!=="Z"&&(Number(c.slice(1,3))>23||Number(c.slice(4))>59))return null;let p=Date.parse(e);return Number.isFinite(p)?p:null}function Bi(e,t,o,n){let s=e?.[t];if(!s||t==="terminate"&&s.beforeFact===void 0)return null;let r=s.beforeFact,a=Te(o),i=r&&a&&Object.hasOwn(a,r)?on(a[r]):null,c=n instanceof Date?n.getTime():on(n);return i===null||c===null||!Number.isFinite(c)?"WORKFLOW_V2_CANCELLATION_DEADLINE_INVALID":c<i?null:"WORKFLOW_V2_CANCELLATION_DEADLINE_PASSED"}import*as He from"crypto";var rn="native-4",an={"application-native-2":"1.0.0","authz.native-batch-explain":"1.0.0","authz.native-management":"1.0.0","deployment.durable-runs":"1.0.0","deployment.platform-executor":"1.0.0","environment.on-demand-production":"1.0.0","environment.runtime-lifecycle":"1.0.0","data-api-v2":"1.1.0","data.native-golden-crud":"1.0.0","data.audit-read-access":"1.0.0","data.managed-files":"1.1.0","workflow.named-input-sources":"1.0.0","directory-v2":"1.0.0","events-v2":"1.0.0","events.durable-receipts":"1.0.0","events.capture-policy":"1.0.0","events.native-data-actions":"1.0.0","workflow-kernel-v2":"1.0.0","workflow.instance-cancellation-policy":"1.0.0","business-process.durable-command":"1.1.0","workflow.fresh-command-token":"1.0.0","notification-hub-v2":"1.0.0","authentication.application-login-surface":"1.0.0","public-access.anonymous-owner-records":"1.0.0"};var Gi=5,zi=20,Yi=50,qi=50,Ki=100,ve=class extends Error{constructor(o,n){super(o);this.code=o;this.pointer=n;this.name="NativeDataPolicyExpressionV2Error"}code;pointer};function Ye(e,t){let o=[],n=(s,r,a)=>{a>5&&Le("NATIVE_DATA_POLICY_EXPRESSION_DEPTH_EXCEEDED",r);let i=dn(s,r),c=["allOf","anyOf"].filter(l=>l in i);if(c.length===0){o.push({rule:i,pointer:r}),o.length>50&&Le("NATIVE_DATA_POLICY_EXPRESSION_LEAVES_EXCEEDED",r);return}let f=c[0],p=i[f];(c.length!==1||Object.keys(i).length!==1||!Array.isArray(p)||p.length<1||p.length>20)&&Le("NATIVE_DATA_POLICY_EXPRESSION_GROUP_INVALID",r),p.forEach((l,u)=>n(l,`${r}/${f}/${u}`,a+1))};return n(e,t,1),o}function cn(e,t){Ye(e,t);let o=(n,s)=>{let r=dn(n,s);if(Array.isArray(r.allOf))return mt(r.allOf.flatMap((a,i)=>o(a,`${s}/allOf/${i}`)),s);if(Array.isArray(r.anyOf)){let a=[[]];return r.anyOf.forEach((i,c)=>{let f=o(i,`${s}/anyOf/${c}`);a=mt(a.flatMap(p=>f.map(l=>[...p,...l])),s)}),a}return[[r]]};return mt(o(e,t),t)}function mt(e,t){let o=e.reduce((n,s)=>n+s.length,0);return(e.length>50||o>100)&&Le("NATIVE_DATA_POLICY_EXPRESSION_EXPANSION_EXCEEDED",t),e}function dn(e,t){return(!e||typeof e!="object"||Array.isArray(e))&&Le("NATIVE_DATA_POLICY_EXPRESSION_NODE_INVALID",t),e}function Le(e,t){throw new ve(e,t)}var Mo="openxiangda.config-bundle/v3",hn="openxiangda.contract-bundle/v3",ln="openxiangda.native-configuration-projection/v1",Ue=rn,jo=/^[a-f0-9]{64}$/,Bo=/^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/,Jo=/^app:[a-z][a-z0-9]*(?:-[a-z0-9]+)*:[A-Za-z0-9:._*-]+$/,Wo=/^[a-z][a-z0-9]*(?:[-_.][a-z0-9]+)*$/,Go=/^[a-z][a-z0-9]*(?:[-.][a-z0-9]+)*$/,zo=/^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/,Yo=/^[A-Za-z][A-Za-z0-9_]{0,62}$/,un=/^[A-Za-z][A-Za-z0-9_]{0,127}$/,qo=/^[a-z][a-z0-9]*(?:[-_][a-z0-9]+)*$/,Ko=/^[A-Z][A-Z0-9_]*$/,Ho=/^[a-z][a-z0-9-]{2,63}$/,Xo=/^[A-Za-z][A-Za-z0-9_-]{0,127}$/,Qo=/^[A-Za-z][A-Za-z0-9_.]{0,127}$/,Zo=16,es=2*1024,ts=new Set(["text.short","text.long","number.integer","number.decimal","boolean","date","time","datetime","option.single","option.multiple","cascade.single","cascade.multiple","user.single","user.multiple","department.single","department.multiple","resource-ref.single","resource-ref.multiple","uuid","serial-number"]),ns=new Set(["overview","database","operations","workflow","members","calendar","document","folder","settings"]),os=new Set(["approve","reject","return","transfer","delegate","add_assignee","resubmit","withdraw","terminate","admin_reassign","admin_override","retry_resolution"]),ss=4*1024*1024,is=8*1024*1024,rs=40,as=1e5,Tt=1024*1024,cs="openxiangda.event-handler-manifest/v2",Sn="openxiangda.application-route-manifest/v3",fn=64,Dn=new Set(["id","revision","created_by","updated_by","created_at","updated_at"]),q=Object.freeze({perspectives:100,resources:100,subjectReadSurfaces:50,capabilities:2e3,operations:500,eventConsumers:100,eventProducers:1e3,eventSchemas:100,eventTypes:500,workflows:100,routes:500,adminPages:500,adminNavigationGroups:100,adminNavigationItems:500}),gt=["openxiangda.data.record.created.v2","openxiangda.data.record.updated.v2","openxiangda.data.record.deleted.v2"],bt=["openxiangda.workflow.instance.started.v2","openxiangda.workflow.instance.cc_added.v2","openxiangda.workflow.instance.completed.v2","openxiangda.workflow.instance.rejected.v2","openxiangda.workflow.instance.returned.v2","openxiangda.workflow.instance.resumed.v2","openxiangda.workflow.instance.withdrawn.v2","openxiangda.workflow.instance.terminated.v2","openxiangda.workflow.task.created.v2","openxiangda.workflow.task.assigned.v2","openxiangda.workflow.task.assignment_pending.v2","openxiangda.workflow.task.assignment_resolution_failed.v2","openxiangda.workflow.task.approved.v2","openxiangda.workflow.task.completed.v2","openxiangda.workflow.task.rejected.v2","openxiangda.workflow.task.returned.v2","openxiangda.workflow.task.resubmitted.v2","openxiangda.workflow.task.transferred.v2","openxiangda.workflow.task.reassigned.v2","openxiangda.workflow.task.delegated.v2","openxiangda.workflow.task.assignee_added.v2","openxiangda.workflow.task.cancelled.v2","openxiangda.workflow.participant.activated.v2","openxiangda.workflow.participant.completed.v2","openxiangda.workflow.participant.rejected.v2","openxiangda.workflow.participant.returned.v2","openxiangda.workflow.participant.transferred.v2","openxiangda.workflow.participant.reassigned.v2","openxiangda.workflow.participant.delegated.v2","openxiangda.workflow.participant.added.v2","openxiangda.workflow.participant.suspended.v2","openxiangda.workflow.participant.resumed.v2","openxiangda.workflow.participant.cancelled.v2"],ds=new Set(bt),Ct=class extends Error{code;pointer;identifiers;constructor(t,o,n={}){super(t),this.name="NativeConfigurationCompilerError",this.code=t,this.pointer=o,this.identifiers=Object.fromEntries(Object.entries(n).slice(0,8).map(([s,r])=>[s,String(r).slice(0,128)]))}};function lr(e){let t=h(e.appCode,"/appCode",128);Bo.test(t)||d("NATIVE_CONFIG_APP_CODE_INVALID","/appCode");let o=$t(e.expectedConfigDigest,"/expectedConfigDigest"),n=$t(e.expectedContractDigest,"/expectedContractDigest"),s=On(e.configBytes,ss,"/configBytes","NATIVE_CONFIG_ARTIFACT_TOO_LARGE"),r=On(e.contractBytes,is,"/contractBytes","NATIVE_CONTRACT_ARTIFACT_TOO_LARGE");$n(s,o,"/configBytes","NATIVE_CONFIG_DIGEST_MISMATCH"),$n(r,n,"/contractBytes","NATIVE_CONTRACT_DIGEST_MISMATCH");let a=bn(s,"/configBytes","NATIVE_CONFIG_JSON_INVALID","NATIVE_CONFIG_NOT_CANONICAL"),i=bn(r,"/contractBytes","NATIVE_CONTRACT_JSON_INVALID","NATIVE_CONTRACT_NOT_CANONICAL");Cn(a,"/config"),Cn(i,"/contracts");let c=a,f=i;_s(c,t),ps(f,t,o);let p=Es(c,o,f.generatorVersion);ti(p,f,c),Q(p)!==Q(f)&&d("NATIVE_CONTRACT_CLOSURE_MISMATCH",Rt(p,f,"/contracts"));let l={authz:{appCode:t,...c.authz,perspectives:c.perspectives,capabilityCatalog:p.capabilities},data:{appCode:t,resources:c.data.resources,resourceContracts:p.resources,...p.subjectReadSurfaces?{subjectReadSurfaces:p.subjectReadSurfaces}:{}},events:{appCode:t,...c.events,consumers:p.eventConsumers,producers:p.eventProducers,handlerManifest:p.eventHandlerManifest,eventTypes:p.eventTypes,capturePlans:us({resources:c.data.resources,dataPolicies:c.authz.dataPolicies,subscriptions:p.eventConsumers,capturePolicies:c.events.capturePolicies})},workflows:{appCode:t,...c.workflows,contracts:p.workflows},runtime:{appCode:t,requirements:c.runtime,backend:c.backend,frontend:c.frontend},contracts:p},u={authz:he(l.authz),data:he(l.data),events:he(l.events),workflows:he(l.workflows),runtime:he(l.runtime),contracts:he(l.contracts)},E={configDigest:o,contractDigest:n,generatorVersion:f.generatorVersion},_=ls(c),A={schemaVersion:ln,compilerContractVersion:Ue,appCode:t,source:E,projections:u,requiredPlatformCapabilities:_,aggregateDigest:ee({schemaVersion:ln,compilerContractVersion:Ue,appCode:t,source:E,requiredPlatformCapabilities:_,projectionDigests:Object.fromEntries(Object.entries(u).map(([N,m])=>[N,m.digest]))})};return jn(A)}function ls(e){let t=e.authz.roles,o=e.data.resources,n=e.backend.operations,s=t.some(_=>_.capabilities.some(A=>A.endsWith(":directory:read")))||o.some(_=>_.schema.fields.some(A=>["user.single","user.multiple","department.single","department.multiple"].includes(A.type)))||n.some(_=>_.platformAccess?.directory),r=!!(e.events.subscriptions.length||e.events.timers.length||e.events.dateTriggers.length||e.events.schemas.length),a=n.some(_=>_.platformAccess?.managedFiles||_.platformAccess?.managedFileCopies)||e.events.subscriptions.some(_=>_.platformAccess?.managedFileCopies),i=n.some(_=>_.platformAccess?.notification)||e.events.subscriptions.some(_=>_.platformAccess?.notification),c=e.workflows.definitions.filter(_=>_.launch.mode==="standalone"||_.launch.mode==="hidden-handoff"),f=n.some(_=>_.platformAccess?.workflow)||c.length>0,p={resources:o},l={perspectives:e.perspectives,authz:e.authz},u={schemaVersion:e.schemaVersion,appCode:e.appCode,frontend:{routes:e.frontend.routes,user:e.frontend.user,admin:e.frontend.admin,devicePolicy:e.frontend.devicePolicy},backend:{operations:n.map(_=>({code:_.code,method:_.method,path:_.path,capability:_.capability,platformAccess:_.platformAccess||null,..._.browser?{browser:_.browser}:{},ai:_.ai||null}))}};return[{code:"application-native-2",declaration:u},{code:"authz.native-batch-explain",declaration:l},{code:"authz.native-management",declaration:l},{code:"deployment.durable-runs",declaration:u.backend},{code:"deployment.platform-executor",declaration:u.backend},{code:"environment.on-demand-production",declaration:{environments:["preproduction","production"]}},{code:"environment.runtime-lifecycle",declaration:{environments:["preproduction","production"]}},...o.length?[{code:"data-api-v2",declaration:p},{code:"data.native-golden-crud",declaration:p}]:[],...o.some(Mt)?[{code:"data.audit-read-access",declaration:p}]:[],...s?[{code:"directory-v2",declaration:{roles:t.map(_=>({code:_.code,capabilities:_.capabilities.filter(A=>A.endsWith(":directory:read"))})),resources:o.map(_=>({code:_.code,fields:_.schema.fields.filter(A=>["user.single","user.multiple","department.single","department.multiple"].includes(A.type))})),operations:n.filter(_=>_.platformAccess?.directory).map(_=>({code:_.code,directory:_.platformAccess.directory}))}}]:[],...a?[{code:"data.managed-files",declaration:{operations:n.filter(_=>_.platformAccess?.managedFiles||_.platformAccess?.managedFileCopies).map(_=>({code:_.code,..._.platformAccess?.managedFiles?{managedFiles:_.platformAccess.managedFiles}:{},..._.platformAccess?.managedFileCopies?{managedFileCopies:_.platformAccess.managedFileCopies}:{}})),subscriptions:e.events.subscriptions.filter(_=>_.platformAccess?.managedFileCopies).map(_=>({code:_.code,managedFileCopies:_.platformAccess.managedFileCopies}))}}]:[],...e.events.subscriptions.some(_=>_.execution)?[{code:"events.native-data-actions",declaration:e.events.subscriptions.filter(_=>_.execution)}]:[],...e.events.capturePolicies?.length?[{code:"events.capture-policy",declaration:e.events.capturePolicies}]:[],...r?[{code:"events-v2",declaration:e.events},{code:"events.durable-receipts",declaration:e.events}]:[],...e.workflows.activations.length?[{code:"workflow-kernel-v2",declaration:e.workflows},{code:"workflow.fresh-command-token",declaration:e.workflows}]:[],...e.workflows.definitions.some(_=>_.definition.instanceCommands!==void 0)?[{code:"workflow.instance-cancellation-policy",declaration:e.workflows.definitions.filter(_=>_.definition.instanceCommands!==void 0)}]:[],...f?[{code:"business-process.durable-command",declaration:{operations:n.filter(_=>_.platformAccess?.workflow).map(_=>({code:_.code,workflow:_.platformAccess.workflow})),definitions:c,activations:e.workflows.activations.filter(_=>c.some(A=>A.definition.code===_.workflowCode))}}]:[],...i?[{code:"notification-hub-v2",declaration:{operations:n.filter(_=>_.platformAccess?.notification).map(_=>({code:_.code,notification:_.platformAccess.notification})),subscriptions:e.events.subscriptions.filter(_=>_.platformAccess?.notification).map(_=>({code:_.code,notification:_.platformAccess.notification}))}}]:[],...e.frontend.authentication?[{code:"authentication.application-login-surface",declaration:e.frontend.authentication}]:[],...e.frontend.publicAccess?[{code:"public-access.anonymous-owner-records",declaration:e.frontend.publicAccess}]:[]].map(({code:_,declaration:A})=>({code:_,contractVersion:an[_],usageDigest:`sha256:${ee(A)}`})).sort((_,A)=>_.code===A.code?0:_.code<A.code?-1:1)}function us(e){let t=new Map,o=new Set(e.resources.map(r=>String(r.code)));for(let[r,a]of R(e.capturePolicies===void 0?[]:e.capturePolicies,"/capturePlan/capturePolicies",100).entries()){let i=`/capturePlan/capturePolicies/${r}`,c=I(a,i);O(c,["resourceCode","mode"],i);let f=z(c.resourceCode,`${i}/resourceCode`);o.has(f)||d("NATIVE_EVENT_CAPTURE_RESOURCE_NOT_FOUND",i,{resourceCode:f}),t.has(f)&&d("NATIVE_EVENT_CAPTURE_POLICY_DUPLICATE",i,{resourceCode:f}),c.mode!=="all"&&c.mode!=="subscribed"&&d("NATIVE_EVENT_CAPTURE_MODE_INVALID",`${i}/mode`),t.set(f,c.mode)}let n=new Map(e.dataPolicies.map((r,a)=>{let i=I(r,`/capturePlan/dataPolicies/${a}`);return[String(i.code),i]})),s=e.subscriptions.map((r,a)=>I(r,`/capturePlan/subscriptions/${a}`));return e.resources.map((r,a)=>{let i=`/capturePlan/resources/${a}`,c=I(r,i),f=z(c.code,`${i}/code`),p=c.schema?I(c.schema,`${i}/schema`):c,l=new Set(R(p.fields||[],`${i}/schema/fields`,500).map((g,D)=>W(I(g,`${i}/schema/fields/${D}`).code,`${i}/schema/fields/${D}/code`))),u=c.dataPolicyCode?w(c.dataPolicyCode,`${i}/dataPolicyCode`):null,E=u?n.get(u):void 0;u&&!E&&d("NATIVE_EVENT_CAPTURE_AUTHZ_POLICY_NOT_FOUND",i,{resourceCode:f,dataPolicyCode:u});let _=new Set;for(let g of E?.rules||[])_.add(String(g.field));if(E?.readExpression)for(let g of Ye(E.readExpression,`${i}/readExpression`))_.add(String(g.rule.field));let A=new Set,N=new Set,m=new Set;for(let[g,D]of s.entries()){let V=R(D.eventTypes,`/capturePlan/subscriptions/${g}/eventTypes`,20).map(String);if(!V.some(M=>M.startsWith("openxiangda.data.")))continue;let x=I(D.filter||{},`/capturePlan/subscriptions/${g}/filter`),k=Array.isArray(x.resourceCodes)?x.resourceCodes.map(String):[];if(k.length&&!k.includes(f))continue;for(let M of V)gt.includes(M)&&m.add(M);for(let M of fs(x,`/capturePlan/subscriptions/${g}/filter`))A.add(M);let Y=I(D.payload||{},`/capturePlan/subscriptions/${g}/payload`);for(let M of R(Y.fields||[],`/capturePlan/subscriptions/${g}/payload/fields`,32))N.add(W(M,`/capturePlan/subscriptions/${g}/payload/fields`))}let T=new Set([...A,...N]),C=new Set([...T,..._]);C.size>fn&&d("NATIVE_EVENT_CAPTURE_FIELDS_LIMIT",i,{resourceCode:f,maximum:fn});for(let g of C)!l.has(g)&&!(_.has(g)&&Dn.has(g))&&d("NATIVE_EVENT_CAPTURE_FIELD_NOT_FOUND",i,{resourceCode:f,field:g});let $=I(c.fieldPolicies||{},`${i}/fieldPolicies`);for(let g of T)$[g]?.mask==="omit"&&d("NATIVE_EVENT_CAPTURE_FIELD_SENSITIVE",i,{resourceCode:f,field:g});let b={resourceCode:f,...t.get(f)==="subscribed"?{capturedEventTypes:[...m].sort()}:{},filterFields:[...A].sort(),projectionFields:[...N].sort(),authorizationFields:[..._].sort(),captureFields:[...C].sort()};return{...b,digest:ee(b)}}).sort((r,a)=>r.resourceCode.localeCompare(a.resourceCode))}function fs(e,t){let o=new Set;for(let[a,i]of R(e.changes||[],`${t}/changes`,16).entries()){let c=I(i,`${t}/changes/${a}`);o.add(W(c.field,`${t}/changes/${a}/field`))}let n=I(e.changedFields||{},`${t}/changedFields`);for(let a of["anyOf","allOf","noneOf"])for(let[i,c]of R(n[a]||[],`${t}/changedFields/${a}`,32).entries())o.add(W(c,`${t}/changedFields/${a}/${i}`));let s=0,r=(a,i,c)=>{c>3&&d("NATIVE_EVENT_FILTER_DEPTH_LIMIT",i);let f=I(a,i);if(f.change){let l=I(f.change,`${i}/change`);o.add(W(l.field,`${i}/change/field`)),s+=1;return}if(f.not){r(f.not,`${i}/not`,c+1);return}let p=f.all?"all":f.any?"any":null;p||d("NATIVE_EVENT_FILTER_CONDITION_INVALID",i);for(let[l,u]of R(f[p],`${i}/${p}`,16).entries())r(u,`${i}/${p}/${l}`,c+1)};return e.where&&r(e.where,`${t}/where`,1),s+=Array.isArray(e.changes)?e.changes.length:0,s>16&&d("NATIVE_EVENT_FILTER_ATOM_LIMIT",t),[...o].sort()}function _s(e,t){O(e,["schemaVersion","compilerContractVersion","appCode","perspectives","authz","backend","data","events","workflows","frontend","runtime"],"/config"),v(e.schemaVersion,Mo,"/config/schemaVersion"),v(e.compilerContractVersion,Ue,"/config/compilerContractVersion"),v(e.appCode,t,"/config/appCode"),R(e.perspectives,"/config/perspectives",100);let o=I(e.authz,"/config/authz");O(o,["capabilities","roles","scopeDimensions","scopeSources","roleMembershipSources","relationshipGrantSources","dataPolicies","authorizationTransitions"],"/config/authz",["authenticatedUserRoleCode"]),R(o.capabilities,"/config/authz/capabilities",2e3),R(o.roles,"/config/authz/roles",100),R(o.scopeDimensions,"/config/authz/scopeDimensions",100),R(o.scopeSources,"/config/authz/scopeSources",100),R(o.roleMembershipSources,"/config/authz/roleMembershipSources",100),R(o.relationshipGrantSources,"/config/authz/relationshipGrantSources",100),R(o.dataPolicies,"/config/authz/dataPolicies",100),R(o.authorizationTransitions,"/config/authz/authorizationTransitions",100);let n=I(e.backend,"/config/backend");O(n,["secrets","operations"],"/config/backend"),R(n.secrets,"/config/backend/secrets",100),R(n.operations,"/config/backend/operations",500),Ks(n.secrets);let s=I(e.data,"/config/data");O(s,["resources"],"/config/data",["resourceDetailRoutes","subjectReadSurfaces"]),R(s.resources,"/config/data/resources",100),s.subjectReadSurfaces!==void 0&&R(s.subjectReadSurfaces,"/config/data/subjectReadSurfaces",q.subjectReadSurfaces),s.resourceDetailRoutes!==void 0&&R(s.resourceDetailRoutes,"/config/data/resourceDetailRoutes",100);let r=I(e.events,"/config/events");O(r,["schemas","subscriptions","timers","dateTriggers"],"/config/events",["capturePolicies"]),R(r.schemas,"/config/events/schemas",100),R(r.subscriptions,"/config/events/subscriptions",100),R(r.timers,"/config/events/timers",100),R(r.dateTriggers,"/config/events/dateTriggers",100);let a=I(e.workflows,"/config/workflows");O(a,["definitions","bindings","activations","providers","editableParameters"],"/config/workflows"),R(a.definitions,"/config/workflows/definitions",100),R(a.bindings,"/config/workflows/bindings",100),R(a.activations,"/config/workflows/activations",100),R(a.providers,"/config/workflows/providers",100),R(a.editableParameters,"/config/workflows/editableParameters",100);let i=I(e.frontend,"/config/frontend");O(i,["routes","user","admin","devicePolicy"],"/config/frontend",["authentication","publicAccess"]),R(i.routes,"/config/frontend/routes",500);let c=I(i.user,"/config/frontend/user");O(c,["applicationTodoCenter"],"/config/frontend/user"),De(c.applicationTodoCenter,"/config/frontend/user/applicationTodoCenter"),ht(i.devicePolicy,"/config/frontend/devicePolicy"),Object.prototype.hasOwnProperty.call(i,"authentication")&&Vn(i.authentication,i.routes,e,"/config/frontend/authentication"),Object.prototype.hasOwnProperty.call(i,"publicAccess")&&ys(i.publicAccess,e,"/config/frontend/publicAccess");let f=I(i.admin,"/config/frontend/admin");O(f,["navigation"],"/config/frontend/admin",["access"]),f.access!==void 0&&Qe(f.access,"/config/frontend/admin/access",e.appCode),Ps(f.navigation,"/config/frontend/admin/navigation");let p=I(e.runtime,"/config/runtime");O(p,["protocolCapabilities","health"],"/config/runtime"),F(p.protocolCapabilities,"/config/runtime/protocolCapabilities",100),O(I(p.health,"/config/runtime/health"),["livePath","readyPath","versionPath"],"/config/runtime/health"),v(p.health.livePath,"/__platform/health","/config/runtime/health/livePath"),v(p.health.readyPath,"/__platform/ready","/config/runtime/health/readyPath"),v(p.health.versionPath,"/__platform/version","/config/runtime/health/versionPath")}function ps(e,t,o){O(e,["schemaVersion","compilerContractVersion","generatorVersion","appCode","configDigest","perspectives","resources","capabilities","operations","eventConsumers","eventProducers","eventSchemas","eventHandlerManifest","eventTypes","workflows","routes","routeManifest","adminPages","adminNavigation"],"/contracts",["authentication","publicAccess","adminAccess","subjectReadSurfaces"]),v(e.schemaVersion,hn,"/contracts/schemaVersion"),v(e.compilerContractVersion,Ue,"/contracts/compilerContractVersion"),h(e.generatorVersion,"/contracts/generatorVersion",128),v(e.appCode,t,"/contracts/appCode"),v(e.configDigest,o,"/contracts/configDigest"),R(e.perspectives,"/contracts/perspectives",q.perspectives),R(e.resources,"/contracts/resources",q.resources),e.subjectReadSurfaces!==void 0&&R(e.subjectReadSurfaces,"/contracts/subjectReadSurfaces",q.subjectReadSurfaces),R(e.capabilities,"/contracts/capabilities",q.capabilities),R(e.operations,"/contracts/operations",q.operations),R(e.eventConsumers,"/contracts/eventConsumers",q.eventConsumers),R(e.eventProducers,"/contracts/eventProducers",q.eventProducers),R(e.eventSchemas,"/contracts/eventSchemas",q.eventSchemas),I(e.eventHandlerManifest,"/contracts/eventHandlerManifest"),F(e.eventTypes,"/contracts/eventTypes",q.eventTypes),R(e.workflows,"/contracts/workflows",q.workflows),R(e.routes,"/contracts/routes",q.routes),Object.prototype.hasOwnProperty.call(e,"authentication")&&hs(e.authentication,"/contracts/authentication"),Object.prototype.hasOwnProperty.call(e,"publicAccess")&&Vs(e.publicAccess,"/contracts/publicAccess"),Object.prototype.hasOwnProperty.call(e,"adminAccess")&&Qe(e.adminAccess,"/contracts/adminAccess",t),Ms(e.routeManifest,"/contracts/routeManifest",t),ks(e.adminPages,"/contracts/adminPages"),Us(e.adminNavigation,"/contracts/adminNavigation")}function Es(e,t,o){let n=ms(e);Gs(e,n),Ys(e),zs(e),Hs(e);let s=e.events.schemas.map((E,_)=>{let A=`/config/events/schemas/${_}`,N=I(E,A),m=h(N.eventType,`${A}/eventType`,255);return m.startsWith("openxiangda.")&&d("NATIVE_EVENT_SCHEMA_RESERVED",`${A}/eventType`,{eventType:m}),v(N.schemaDigest,ee(I(N.jsonSchema,`${A}/jsonSchema`)),`${A}/schemaDigest`),N}),r=new Set([...gt,...bt,...s.map(E=>String(E.eventType))]),a=new Map(e.data.resources.map(E=>[String(E.code),new Map(E.schema.fields.map(_=>[String(_.code),String(_.type)]))])),i=X(e.events.subscriptions.map((E,_)=>{let A=`/config/events/subscriptions/${_}`,N=I(E,A),m=F(N.eventTypes,`${A}/eventTypes`,20);m.forEach((b,g)=>{r.has(b)||d("NATIVE_EVENT_TYPE_NOT_REGISTERED",`${A}/eventTypes/${g}`,{eventType:b})});let T=nn(N,e.data.resources,A),C=Is(N.delivery,m,`${A}/delivery`),$=As(N.platformAccess,`${A}/platformAccess`,a);return{code:w(N.code,`${A}/code`),endpointPath:re(N.endpointPath,`${A}/endpointPath`),eventTypes:m,filter:I(N.filter,`${A}/filter`),payload:T?.payload||I(N.payload,`${A}/payload`),...T?{execution:T.execution}:{},...$?{platformAccess:$}:{},delivery:C}}),E=>E.code),c=new Map(s.map(E=>[String(E.eventType),String(E.dataSchemaVersion)])),f=X([...e.data.resources.flatMap(E=>gt.map(_=>({code:`data:${E.code}:${_}`,source:"data",eventType:_,dataSchemaVersion:"2.0.0",resourceCode:E.code}))),...s.map(E=>({code:`app:${E.eventType}`,source:"app",eventType:E.eventType,dataSchemaVersion:E.dataSchemaVersion})),...e.events.timers.map(E=>({code:E.code,source:"timer",eventType:E.eventType,dataSchemaVersion:c.get(String(E.eventType))||"2.0.0"})),...e.events.dateTriggers.map(E=>({code:E.code,source:"date",eventType:E.eventType,dataSchemaVersion:c.get(String(E.eventType))||"2.0.0",resourceCode:E.resourceCode,field:E.field})),...e.workflows.activations.length?bt.map(E=>({code:`workflow:${E}`,source:"workflow",eventType:E,dataSchemaVersion:"2.0.0"})):[]],E=>`${E.source}:${E.code}:${E.eventType}`),p=j([...i.flatMap(E=>E.eventTypes),...f.map(E=>String(E.eventType))]);vs(e);let l=Pn(e),u=Ts(e,n);return{schemaVersion:hn,compilerContractVersion:Ue,generatorVersion:o,appCode:e.appCode,configDigest:t,perspectives:e.perspectives,resources:Ns(e),...u.length?{subjectReadSurfaces:u}:{},capabilities:X(n,E=>E.code),operations:yn(e),eventConsumers:i,eventProducers:f,eventSchemas:s,eventHandlerManifest:{schemaVersion:cs,appCode:e.appCode,handlers:i.filter(E=>!E.execution).map(E=>({code:E.code,endpointPath:E.endpointPath,eventTypes:E.eventTypes,dataSchemaVersions:j(E.eventTypes.map(_=>_.startsWith("openxiangda.")?"2.0.0":c.get(_)||"2.0.0")),maxBodyBytes:65536,receiptProtocolVersion:2}))},eventTypes:p,workflows:kn(e),routes:Xe(e),...Object.prototype.hasOwnProperty.call(e.frontend,"authentication")?{authentication:Ss(e)}:{},...Object.prototype.hasOwnProperty.call(e.frontend,"publicAccess")?{publicAccess:ws(e)}:{},...e.frontend.admin.access?{adminAccess:e.frontend.admin.access}:{},routeManifest:Js(e),adminPages:l,adminNavigation:Fs(e)}}function As(e,t,o){if(e===void 0)return;let n=I(e,t);O(n,["notification","managedFileCopies"],t,!0);let s={};if(n.notification!==void 0){let r=I(n.notification,`${t}/notification`);O(r,["mode"],`${t}/notification`),v(r.mode,"business-standard",`${t}/notification/mode`),s.notification={mode:"business-standard"}}if(n.managedFileCopies!==void 0){let r=R(n.managedFileCopies,`${t}/managedFileCopies`,16);r.length||d("NATIVE_EVENT_MANAGED_FILE_COPIES_REQUIRED",`${t}/managedFileCopies`);let a=new Set;s.managedFileCopies=X(r.map((i,c)=>{let f=`${t}/managedFileCopies/${c}`,p=I(i,f);O(p,["mode","sourceResourceCode","sourceFieldCodes","targetResourceCode","targetFieldCodes"],f),v(p.mode,"copy",`${f}/mode`);let l=z(p.sourceResourceCode,`${f}/sourceResourceCode`),u=z(p.targetResourceCode,`${f}/targetResourceCode`),E=o.get(l),_=o.get(u);(!E||!_)&&d("NATIVE_EVENT_MANAGED_FILE_COPY_RESOURCE_INVALID",f);let A=F(p.sourceFieldCodes,`${f}/sourceFieldCodes`,16),N=F(p.targetFieldCodes,`${f}/targetFieldCodes`,16);(!A.length||A.length!==N.length)&&d("NATIVE_EVENT_MANAGED_FILE_COPY_FIELDS_INVALID",f),A.forEach((T,C)=>{let $=E.get(T),b=_.get(N[C]);(!["file","image"].includes(String($))||$!==b)&&d("NATIVE_EVENT_MANAGED_FILE_COPY_FIELD_INVALID",`${f}/sourceFieldCodes/${C}`)});let m=`${l}:${A.join(",")}=>${u}:${N.join(",")}`;return a.has(m)&&d("NATIVE_EVENT_MANAGED_FILE_COPY_DUPLICATE",f),a.add(m),{mode:"copy",sourceResourceCode:l,sourceFieldCodes:j(A),targetResourceCode:u,targetFieldCodes:j(N)}}),i=>`${i.sourceResourceCode}:${i.sourceFieldCodes.join(",")}=>${i.targetResourceCode}:${i.targetFieldCodes.join(",")}`)}return Object.keys(s).length||d("NATIVE_EVENT_PLATFORM_ACCESS_EMPTY",t),s}function Is(e,t,o){let n=I(e,o);O(n,["timeoutMs","maxAttempts","initialBackoffMs","maxBackoffMs","ordering","concurrency"],o),Z(n.timeoutMs,`${o}/timeoutMs`,1e3,3e4),Z(n.maxAttempts,`${o}/maxAttempts`,1,12);let s=Z(n.initialBackoffMs,`${o}/initialBackoffMs`,1e3,3e5);Z(n.maxBackoffMs,`${o}/maxBackoffMs`,s,18e5),Z(n.concurrency,`${o}/concurrency`,1,50);let r=h(n.ordering,`${o}/ordering`,32);return["none","record","workflow-instance"].includes(r)||d("NATIVE_EVENT_DELIVERY_ORDERING_INVALID",`${o}/ordering`),r==="workflow-instance"&&t.some(a=>!ds.has(a))&&d("NATIVE_EVENT_WORKFLOW_ORDERING_REQUIRES_WORKFLOW_FACTS",`${o}/ordering`),n}function ms(e){let t=new Map;for(let o of Mn(e.appCode))t.set(o.code,o);for(let[o,n]of e.authz.capabilities.entries()){let s=`/config/authz/capabilities/${o}`,r=I(n,s);O(r,["code","kind","name","description"],s,!0);let a=Ee(r.code,`${s}/code`,e.appCode);t.has(a)&&d("NATIVE_CAPABILITY_DUPLICATE",`${s}/code`),["backend","ui"].includes(r.kind)||d("NATIVE_CAPABILITY_KIND_INVALID",`${s}/kind`);let i={code:a,kind:r.kind,name:h(r.name,`${s}/name`,255),source:"explicit",...r.description===void 0?{}:{description:Dt(r.description,`${s}/description`,2e3)}};t.set(a,i)}for(let[o,n]of e.data.resources.entries()){let s=`/config/data/resources/${o}`,r=be(n,s,e.appCode),a={read:`\u8BFB\u53D6${r.name}`,create:`\u65B0\u5EFA${r.name}`,update:`\u66F4\u65B0${r.name}`,delete:`\u5220\u9664${r.name}`};for(let i of["read","create","update","delete"]){let c=Ee(r.capabilities[i],`${s}/capabilities/${i}`,e.appCode);t.has(c)&&d("NATIVE_CAPABILITY_DUPLICATE",`${s}/capabilities/${i}`),t.set(c,{code:c,kind:"data",name:a[i],source:"data"})}for(let[i,c]of Object.entries(r.fieldPolicies)){if(ye(i))continue;let f=I(c,`${s}/fieldPolicies/${i}`);for(let p of["read","create","update"])if(Array.isArray(f[p]))for(let l of F(f[p],`${s}/fieldPolicies/${i}/${p}`,2e3))Ee(l,`${s}/fieldPolicies/${i}/${p}`,e.appCode),!t.has(l)&&t.set(l,{code:l,kind:"data",name:`${r.name}.${i}.${p}`,source:"data"})}}return[...t.values()]}function Ns(e){let t=gs(e);return X(e.data.resources.map((o,n)=>{let s=be(o,`/config/data/resources/${n}`,e.appCode),r=t.get(s.code);return{code:s.code,schemaDigest:ee(s.schema),fields:X(s.schema.fields.map(a=>({code:a.code,type:a.type})),a=>a.code),...r?{detailRouteCode:r}:{}}}),o=>o.code)}function Ts(e,t){if(e.data.subjectReadSurfaces===void 0)return[];let o=R(e.data.subjectReadSurfaces,"/config/data/subjectReadSurfaces",q.subjectReadSurfaces),n=new Set(t.map(a=>String(a.code))),s=new Map(e.data.resources.map((a,i)=>{let c=`/config/data/resources/${i}`,f=be(a,c,e.appCode);return[String(f.code),{resource:f,fields:new Map(R(I(f.schema,`${c}/schema`).fields,`${c}/schema/fields`,500).map(p=>{let l=I(p,`${c}/schema/fields`);return[String(l.code),l]}))}]})),r=new Set;return X(o.map((a,i)=>{let c=`/config/data/subjectReadSurfaces/${i}`,f=I(a,c);O(f,["code","name","capability","subject","relations"],c);let p=w(f.code,`${c}/code`);r.has(p)&&d("NATIVE_SUBJECT_READ_SURFACE_CODE_DUPLICATE",`${c}/code`),r.add(p);let l=Ee(f.capability,`${c}/capability`,e.appCode);n.has(l)||d("NATIVE_SUBJECT_READ_SURFACE_CAPABILITY_NOT_DECLARED",`${c}/capability`);let u=I(f.subject,`${c}/subject`);O(u,["resourceCode","fields"],`${c}/subject`);let E=z(u.resourceCode,`${c}/subject/resourceCode`),_=s.get(E);_||d("NATIVE_SUBJECT_READ_SURFACE_RESOURCE_NOT_DECLARED",`${c}/subject/resourceCode`);let A=F(u.fields,`${c}/subject/fields`,100).map(($,b)=>W($,`${c}/subject/fields/${b}`));A.length||d("NATIVE_SUBJECT_READ_SURFACE_FIELDS_REQUIRED",`${c}/subject/fields`);for(let[$,b]of A.entries()){let g=_.fields.get(b);(!g||g.type==="subtable")&&d("NATIVE_SUBJECT_READ_SURFACE_FIELD_INVALID",`${c}/subject/fields/${$}`)}let N=R(f.relations,`${c}/relations`,8);N.length||d("NATIVE_SUBJECT_READ_SURFACE_RELATIONS_REQUIRED",`${c}/relations`);let m=new Set,T=0,C=X(N.map(($,b)=>{let g=`${c}/relations/${b}`,D=I($,g);O(D,["code","resourceCode","foreignKeyField","fields","limit"],g,["order"]);let V=w(D.code,`${g}/code`);m.has(V)&&d("NATIVE_SUBJECT_READ_SURFACE_RELATION_CODE_DUPLICATE",`${g}/code`),m.add(V);let x=z(D.resourceCode,`${g}/resourceCode`),k=s.get(x);k||d("NATIVE_SUBJECT_READ_SURFACE_RESOURCE_NOT_DECLARED",`${g}/resourceCode`);let Y=W(D.foreignKeyField,`${g}/foreignKeyField`),M=k.fields.get(Y),ae=I(M?.source||{},`${g}/foreignKeyField/source`);(!M||!["uuid","resource-ref.single"].includes(String(M.type))||M.type==="resource-ref.single"&&(ae.kind!=="resource"||ae.resourceCode!==E))&&d("NATIVE_SUBJECT_READ_SURFACE_RELATION_INVALID",`${g}/foreignKeyField`);let ce=F(D.fields,`${g}/fields`,100).map((oe,y)=>W(oe,`${g}/fields/${y}`));ce.length||d("NATIVE_SUBJECT_READ_SURFACE_FIELDS_REQUIRED",`${g}/fields`);for(let[oe,y]of ce.entries()){let U=k.fields.get(y);(!U||U.type==="subtable")&&d("NATIVE_SUBJECT_READ_SURFACE_FIELD_INVALID",`${g}/fields/${oe}`)}let K=R(D.order||[],`${g}/order`,10).map((oe,y)=>{let U=`${g}/order/${y}`,P=I(oe,U);O(P,["field","direction"],U);let B=W(P.field,`${U}/field`),J=k.fields.get(B);return(!Dn.has(B)&&!J||J?.type==="subtable"||J&&!we(J.type))&&d("NATIVE_SUBJECT_READ_SURFACE_ORDER_FIELD_INVALID",`${U}/field`),["asc","desc"].includes(String(P.direction))||d("NATIVE_SUBJECT_READ_SURFACE_ORDER_DIRECTION_INVALID",`${U}/direction`),{field:B,direction:P.direction}}),fe=Z(D.limit,`${g}/limit`,1,100);return T+=fe,{code:V,resourceCode:x,foreignKeyField:Y,fields:j(ce),...K.length?{order:K}:{},limit:fe}}),$=>$.code);return T>400&&d("NATIVE_SUBJECT_READ_SURFACE_ROW_LIMIT_EXCEEDED",`${c}/relations`),{code:p,name:h(f.name,`${c}/name`,255),capability:l,subject:{resourceCode:E,fields:j(A)},relations:C}}),a=>a.code)}function gs(e){let t=e.data.resourceDetailRoutes===void 0?[]:R(e.data.resourceDetailRoutes,"/config/data/resourceDetailRoutes",100),o=new Map(e.data.resources.map((r,a)=>{let i=`/config/data/resources/${a}`,c=be(r,i,e.appCode);return[c.code,c]})),n=new Map(Xe(e).map(r=>[String(r.code),r])),s=new Map;for(let[r,a]of t.entries()){let i=`/config/data/resourceDetailRoutes/${r}`,c=I(a,i);O(c,["resourceCode","desktop","mobile"],i);let f=z(c.resourceCode,`${i}/resourceCode`);s.has(f)&&d("NATIVE_DATA_RESOURCE_DETAIL_ROUTE_DUPLICATE",`${i}/resourceCode`);let p=o.get(f);p||d("NATIVE_DATA_RESOURCE_DETAIL_ROUTE_RESOURCE_MISSING",`${i}/resourceCode`);let l=w(c.desktop,`${i}/desktop`),u=w(c.mobile,`${i}/mobile`);l===u&&d("NATIVE_DATA_RESOURCE_DETAIL_ROUTE_INVALID",i);let E=String(p.capabilities.read);for(let[_,A]of[["desktop",l],["mobile",u]]){let N=`${i}/${_}`,m=n.get(A);m||d("NATIVE_DATA_RESOURCE_DETAIL_ROUTE_REFERENCE_MISSING",N),m.surface!=="user"&&d("NATIVE_DATA_RESOURCE_DETAIL_ROUTE_SURFACE_INVALID",N);let T=re(m.path,`${N}/path`),C=[...T.matchAll(/:([A-Za-z][A-Za-z0-9_]*)/g)],$=_==="mobile"?!T.startsWith("/m/"):T==="/m"||T.startsWith("/m/");(T.includes("*")||T.includes("?")||T.includes("#")||T.split("/").includes("..")||C.length!==1||$)&&d("NATIVE_DATA_RESOURCE_DETAIL_ROUTE_PATH_INVALID",N);let b=Array.isArray(m.access?.allOf)?m.access.allOf:[];m.capability!==E&&!b.includes(E)&&d("NATIVE_DATA_RESOURCE_DETAIL_ROUTE_CAPABILITY_INVALID",N)}s.set(f,{desktop:l,mobile:u})}return s}function yn(e){let t=new Map(e.data.resources.map((r,a)=>{let i=`/config/data/resources/${a}`,c=be(r,i,e.appCode);return[c.code,new Map(c.schema.fields.map(f=>[String(f.code),f]))]})),o=new Map(e.data.resources.map((r,a)=>{let i=`/config/data/resources/${a}`,c=be(r,i,e.appCode);return[c.code,new Map(c.schema.fields.map(f=>[String(f.code),String(f.type)]))]})),n=new Set(o.keys()),s=new Set(e.workflows.activations.map((r,a)=>Ze(I(r,`/config/workflows/activations/${a}`).workflowCode,`/config/workflows/activations/${a}/workflowCode`)));return X(e.backend.operations.map((r,a)=>{let i=`/config/backend/operations/${a}`,c=I(r,i);O(c,["code","method","path","capability","requestSchema","responseSchema","description","platformAccess","browser","ai"],i,!0);let f=h(c.method,`${i}/method`,16);["GET","POST","PUT","PATCH","DELETE"].includes(f)||d("NATIVE_OPERATION_METHOD_INVALID",`${i}/method`);let p=w(c.code,`${i}/code`);$s(c.ai,i,p,f,n);let l=Os(c.platformAccess,`${i}/platformAccess`,o,s,new Set(e.authz.roles.map(E=>String(E.code)))),u=bs(c.browser,`${i}/browser`,f,c.requestSchema,c.responseSchema,o,t,e.data.subjectReadSurfaces||[]);return{code:p,method:f,path:re(c.path,`${i}/path`),requiredCapability:Ee(c.capability,`${i}/capability`,e.appCode),requestSchemaDigest:ee(I(c.requestSchema,`${i}/requestSchema`)),responseSchemaDigest:ee(I(c.responseSchema,`${i}/responseSchema`)),...c.description===void 0?{}:{description:Dt(c.description,`${i}/description`,2e3)},...l?{platformAccess:l}:{},...u?{browser:u}:{}}}),r=>r.code)}function bs(e,t,o,n,s,r,a,i){if(e===void 0)return null;let c=I(e,t);O(c,["exposure","behavior","idempotency","subject"],t,["refreshTargets","fileIntent"]),v(c.exposure,"authenticated",`${t}/exposure`);let f=h(c.behavior,`${t}/behavior`,32);["read","controlled"].includes(f)||d("NATIVE_OPERATION_BROWSER_BEHAVIOR_INVALID",`${t}/behavior`);let p=h(c.idempotency,`${t}/idempotency`,32);(!["none","required"].includes(p)||f==="controlled"&&p!=="required"||f==="read"&&p!=="none")&&d("NATIVE_OPERATION_BROWSER_IDEMPOTENCY_INVALID",`${t}/idempotency`);let l=I(c.subject,`${t}/subject`);O(l,["resourceCode","inputField"],`${t}/subject`);let u=z(l.resourceCode,`${t}/subject/resourceCode`);r.has(u)||d("NATIVE_OPERATION_BROWSER_SUBJECT_RESOURCE_NOT_DECLARED",`${t}/subject/resourceCode`);let E=W(l.inputField,`${t}/subject/inputField`),_=I(n,`${t}/requestSchema`),A=I(s,`${t}/responseSchema`);(_.type!=="object"||_.additionalProperties!==!1||A.type!=="object"||A.additionalProperties!==!1)&&d("NATIVE_OPERATION_BROWSER_SCHEMA_ROOT_INVALID",`${t}/requestSchema`);let N=I(_.properties,`${t}/requestSchema/properties`),m=new Set(_.required===void 0?[]:F(_.required,`${t}/requestSchema/required`,200));(!(E in N)||!m.has(E))&&d("NATIVE_OPERATION_BROWSER_SUBJECT_INPUT_INVALID",`${t}/subject/inputField`);let T=I(N[E],`${t}/requestSchema/properties/${E}`);(T.type!=="string"||T.format!=="uuid")&&d("NATIVE_OPERATION_BROWSER_SUBJECT_INPUT_INVALID",`${t}/subject/inputField`);let C=new Map((Array.isArray(i)?i:[]).map((V,x)=>{let k=I(V,`/config/data/subjectReadSurfaces/${x}`);return[String(k.code),String(I(k.subject,`/config/data/subjectReadSurfaces/${x}/subject`).resourceCode)]})),$=c.refreshTargets===void 0?[]:R(c.refreshTargets,`${t}/refreshTargets`,16),b=new Set,g=X($.map((V,x)=>{let k=`${t}/refreshTargets/${x}`,Y=I(V,k);O(Y,["kind","code"],k),v(Y.kind,"subject-surface",`${k}/kind`);let M=w(Y.code,`${k}/code`);return(b.has(M)||!C.has(M)||C.get(M)!==u)&&d("NATIVE_OPERATION_BROWSER_REFRESH_TARGET_INVALID",`${k}/code`),b.add(M),{kind:"subject-surface",code:M}}),V=>`${V.kind}:${V.code}`),D=Cs(c.fileIntent,`${t}/fileIntent`,o,f,p,u,N,m,a);return{exposure:"authenticated",behavior:f,idempotency:p,subject:{resourceCode:u,inputField:E},...g.length?{refreshTargets:g}:{},...D?{fileIntent:D}:{}}}function Cs(e,t,o,n,s,r,a,i,c){if(e===void 0)return null;let f=I(e,t);O(f,["recordResourceCode","recordIdInputField","relationField","fileNameField","contentTypeField","sizeField","purposes","maxTtlSeconds","maxBytes"],t),(o!=="GET"||n!=="read"||s!=="none")&&d("NATIVE_OPERATION_FILE_INTENT_BEHAVIOR_INVALID",t);let p=z(f.recordResourceCode,`${t}/recordResourceCode`),l=c.get(p);l||d("NATIVE_OPERATION_FILE_INTENT_RESOURCE_NOT_DECLARED",`${t}/recordResourceCode`);let u=W(f.recordIdInputField,`${t}/recordIdInputField`),E=I(a[u],`${t}/recordIdInputField`);(!i.has(u)||E.type!=="string"||E.format!=="uuid")&&d("NATIVE_OPERATION_FILE_INTENT_RECORD_INPUT_INVALID",`${t}/recordIdInputField`);let _=W(f.relationField,`${t}/relationField`),A=l.get(_);(!A||!["uuid","resource-ref.single"].includes(String(A.type))||String(A.type)==="resource-ref.single"&&(String(I(A.source,`${t}/relationField`).kind||"")!=="resource"||String(I(A.source,`${t}/relationField`).resourceCode||"")!==r))&&d("NATIVE_OPERATION_FILE_INTENT_RELATION_INVALID",`${t}/relationField`);let N=[["fileNameField",["text.short","text.long"]],["contentTypeField",["text.short","text.long"]],["sizeField",["number.integer"]]],m={};for(let[b,g]of N){let D=W(f[b],`${t}/${b}`);g.includes(String(l.get(D)?.type))||d("NATIVE_OPERATION_FILE_INTENT_METADATA_INVALID",`${t}/${b}`),m[b]=D}let T=X(F(f.purposes,`${t}/purposes`,2),b=>b);(!T.length||T.some(b=>!["preview","download"].includes(b)))&&d("NATIVE_OPERATION_FILE_INTENT_PURPOSE_INVALID",`${t}/purposes`);let C=Number(f.maxTtlSeconds);(!Number.isSafeInteger(C)||C<1||C>300)&&d("NATIVE_OPERATION_FILE_INTENT_TTL_INVALID",`${t}/maxTtlSeconds`);let $=Number(f.maxBytes);return(!Number.isSafeInteger($)||$<1||$>104857600)&&d("NATIVE_OPERATION_FILE_INTENT_SIZE_INVALID",`${t}/maxBytes`),{recordResourceCode:p,recordIdInputField:u,relationField:_,fileNameField:m.fileNameField,contentTypeField:m.contentTypeField,sizeField:m.sizeField,purposes:T,maxTtlSeconds:C,maxBytes:$}}function Os(e,t,o,n,s){if(e===void 0)return null;let r=I(e,t);O(r,["directory","managedFiles","managedFileCopies","notification","workflow","roleAssertions"],t,!0),Object.keys(r).length===0&&d("NATIVE_OPERATION_PLATFORM_ACCESS_EMPTY",t);let a={};if(r.roleAssertions!==void 0){let i=I(r.roleAssertions,`${t}/roleAssertions`);O(i,["roleCodes"],`${t}/roleAssertions`);let c=F(i.roleCodes,`${t}/roleAssertions/roleCodes`,20);c.length||d("NATIVE_OPERATION_ROLE_ASSERTIONS_REQUIRED",`${t}/roleAssertions/roleCodes`),c.forEach((f,p)=>{s.has(f)||d("NATIVE_ROLE_REFERENCE_MISSING",`${t}/roleAssertions/roleCodes/${p}`)}),a.roleAssertions={roleCodes:j(c)}}if(r.directory!==void 0){let i=I(r.directory,`${t}/directory`);O(i,["mode","fields"],`${t}/directory`),i.mode!=="current-initiator"&&d("NATIVE_OPERATION_DIRECTORY_MODE_INVALID",`${t}/directory/mode`);let c=new Set(["displayName","employeeNumber","primaryDepartment","departments"]),f=F(i.fields,`${t}/directory/fields`,4);(!f.length||f.some(p=>!c.has(p)))&&d("NATIVE_OPERATION_DIRECTORY_FIELDS_INVALID",`${t}/directory/fields`),a.directory={mode:"current-initiator",fields:j(f)}}if(r.managedFiles!==void 0){let i=R(r.managedFiles,`${t}/managedFiles`,16);i.length||d("NATIVE_OPERATION_MANAGED_FILES_REQUIRED",`${t}/managedFiles`);let c=new Set;a.managedFiles=X(i.map((f,p)=>{let l=`${t}/managedFiles/${p}`,u=I(f,l);O(u,["resourceCode","fieldCodes","intents"],l);let E=z(u.resourceCode,`${l}/resourceCode`);(c.has(E)||!o.has(E))&&d("NATIVE_OPERATION_MANAGED_FILE_RESOURCE_INVALID",`${l}/resourceCode`),c.add(E);let _=F(u.fieldCodes,`${l}/fieldCodes`,16);(!_.length||_.some(N=>!["file","image","signature"].includes(String(o.get(E)?.get(N)||""))))&&d("NATIVE_OPERATION_MANAGED_FILE_FIELD_INVALID",`${l}/fieldCodes`);let A=F(u.intents,`${l}/intents`,2);return(!A.length||A.some(N=>!["create","update"].includes(N)))&&d("NATIVE_OPERATION_MANAGED_FILE_INTENT_INVALID",`${l}/intents`),{resourceCode:E,fieldCodes:j(_),intents:j(A)}}),f=>f.resourceCode)}if(r.managedFileCopies!==void 0){let i=R(r.managedFileCopies,`${t}/managedFileCopies`,16);i.length||d("NATIVE_OPERATION_MANAGED_FILE_COPIES_REQUIRED",`${t}/managedFileCopies`);let c=new Set;a.managedFileCopies=X(i.map((f,p)=>{let l=`${t}/managedFileCopies/${p}`,u=I(f,l);O(u,["mode","sourceResourceCode","sourceFieldCodes","targetResourceCode","targetFieldCodes"],l),v(u.mode,"copy",`${l}/mode`);let E=z(u.sourceResourceCode,`${l}/sourceResourceCode`),_=z(u.targetResourceCode,`${l}/targetResourceCode`),A=o.get(E),N=o.get(_);(!A||!N)&&d("NATIVE_OPERATION_MANAGED_FILE_COPY_RESOURCE_INVALID",l);let m=F(u.sourceFieldCodes,`${l}/sourceFieldCodes`,16),T=F(u.targetFieldCodes,`${l}/targetFieldCodes`,16);(!m.length||m.length!==T.length)&&d("NATIVE_OPERATION_MANAGED_FILE_COPY_FIELDS_INVALID",l),m.forEach(($,b)=>{let g=A.get($),D=N.get(T[b]);(!["file","image"].includes(String(g))||g!==D)&&d("NATIVE_OPERATION_MANAGED_FILE_COPY_FIELD_INVALID",`${l}/sourceFieldCodes/${b}`)});let C=`${E}:${m.join(",")}=>${_}:${T.join(",")}`;return c.has(C)&&d("NATIVE_OPERATION_MANAGED_FILE_COPY_DUPLICATE",l),c.add(C),{mode:"copy",sourceResourceCode:E,sourceFieldCodes:j(m),targetResourceCode:_,targetFieldCodes:j(T)}}),f=>`${f.sourceResourceCode}:${f.sourceFieldCodes.join(",")}=>${f.targetResourceCode}:${f.targetFieldCodes.join(",")}`)}if(r.notification!==void 0){let i=I(r.notification,`${t}/notification`);O(i,["mode"],`${t}/notification`),i.mode!=="business-standard"&&d("NATIVE_OPERATION_NOTIFICATION_MODE_INVALID",`${t}/notification/mode`),a.notification={mode:"business-standard"}}if(r.workflow!==void 0){let i=I(r.workflow,`${t}/workflow`);O(i,["codes"],`${t}/workflow`);let c=F(i.codes,`${t}/workflow/codes`,16);(!c.length||c.some(f=>!n.has(f)))&&d("NATIVE_OPERATION_WORKFLOW_CODE_INVALID",`${t}/workflow/codes`),a.workflow={codes:j(c)}}return a}function $s(e,t,o,n,s){if(e===void 0)return;let r=`${t}/ai`,a=I(e,r);Go.test(o)||d("NATIVE_OPERATION_AI_CODE_INVALID",`${t}/code`),O(a,["name","description","risk","resources","sideEffects","concurrency","timeoutMs"],r,!0),h(a.name,`${r}/name`,Tt),h(a.description,`${r}/description`,Tt);let i=h(a.risk,`${r}/risk`,16);["read","write","destructive","external"].includes(i)||d("NATIVE_OPERATION_AI_RISK_INVALID",`${r}/risk`),i==="read"!=(n==="GET")&&d("NATIVE_OPERATION_AI_METHOD_RISK_MISMATCH",`${r}/risk`),n==="DELETE"&&!["destructive","external"].includes(i)&&d("NATIVE_OPERATION_AI_METHOD_RISK_MISMATCH",`${r}/risk`);let c=F(a.resources,`${r}/resources`,16);c.length===0&&d("NATIVE_OPERATION_AI_RESOURCE_REQUIRED",`${r}/resources`),c.forEach((p,l)=>{let u=z(p,`${r}/resources/${l}`);s.has(u)||d("NATIVE_OPERATION_AI_RESOURCE_MISSING",`${r}/resources/${l}`)});let f=F(a.sideEffects,`${r}/sideEffects`,20);(i==="read"&&f.length!==0||i!=="read"&&f.length===0)&&d("NATIVE_OPERATION_AI_SIDE_EFFECT_INVALID",`${r}/sideEffects`),a.concurrency!==void 0&&!["none","revision"].includes(h(a.concurrency,`${r}/concurrency`,16))&&d("NATIVE_OPERATION_AI_CONCURRENCY_INVALID",`${r}/concurrency`),a.timeoutMs!==void 0&&Z(a.timeoutMs,`${r}/timeoutMs`,100,3e4)}function qe(e){return(e.replace(/\/{2,}/g,"/").replace(/\/$/,"")||"/").split("/").map(o=>o.startsWith(":")?":":o.includes("*")?"*":o).join("/")}function Rs(e,t){let o=I(e,t),n=h(o.type,`${t}/type`,32),s=["code","type","label","presentation","required"],r=n==="sso"?[...s,"provider"]:n==="dingtalk"?[...s,"flow"]:s;O(o,r,t);let a=w(o.code,`${t}/code`),i=h(o.label,`${t}/label`,255),c=h(o.presentation,`${t}/presentation`,16);["primary","secondary"].includes(c)||d("NATIVE_APPLICATION_AUTH_METHOD_PRESENTATION_INVALID",`${t}/presentation`);let f=De(o.required,`${t}/required`);return["sso","password","dingtalk"].includes(n)||d("NATIVE_APPLICATION_AUTH_METHOD_TYPE_INVALID",`${t}/type`),n==="sso"&&o.provider!=="tenant-default"&&d("NATIVE_APPLICATION_AUTH_SSO_PROVIDER_INVALID",`${t}/provider`),n==="dingtalk"&&!["auto","jsapi","oauth"].includes(h(o.flow,`${t}/flow`,16))&&d("NATIVE_APPLICATION_AUTH_DINGTALK_FLOW_INVALID",`${t}/flow`),{code:a,type:n,label:i,presentation:c,required:f,...n==="sso"?{provider:"tenant-default"}:{},...n==="dingtalk"?{flow:o.flow}:{}}}function _n(e,t,o){let n=I(e,o);O(n,["routeCode","path","defaultRouteCode"],o);let s=w(n.routeCode,`${o}/routeCode`),r=re(n.path,`${o}/path`),a=t==="desktop"?"/login":"/m/login";return(r!==a||/[:*?#\\]/.test(r))&&d("NATIVE_APPLICATION_AUTH_SURFACE_PATH_INVALID",`${o}/path`,{device:t,expectedPath:a}),{routeCode:s,path:r,defaultRouteCode:w(n.defaultRouteCode,`${o}/defaultRouteCode`)}}function Vn(e,t,o,n){if(e===null)return;let s=I(e,n);O(s,["accountMode","registration","methods","surfaces"],n),v(s.accountMode,"existing-platform-users-only",`${n}/accountMode`);let r=I(s.registration,`${n}/registration`);O(r,["mode"],`${n}/registration`),v(r.mode,"reject",`${n}/registration/mode`);let a=R(s.methods,`${n}/methods`,8);a.length===0&&d("NATIVE_APPLICATION_AUTH_METHOD_REQUIRED",`${n}/methods`);let i=a.map((m,T)=>Rs(m,`${n}/methods/${T}`)),c=new Set,f=new Set;for(let[m,T]of i.entries())c.has(T.code)&&d("NATIVE_APPLICATION_AUTH_METHOD_CODE_DUPLICATE",`${n}/methods/${m}/code`),f.has(T.type)&&d("NATIVE_APPLICATION_AUTH_METHOD_TYPE_DUPLICATE",`${n}/methods/${m}/type`),c.add(T.code),f.add(T.type);i.filter(m=>m.presentation==="primary").length!==1&&d("NATIVE_APPLICATION_AUTH_PRIMARY_METHOD_INVALID",`${n}/methods`);let p=I(s.surfaces,`${n}/surfaces`);O(p,["desktop","mobile"],`${n}/surfaces`);let l=_n(p.desktop,"desktop",`${n}/surfaces/desktop`),u=_n(p.mobile,"mobile",`${n}/surfaces/mobile`);l.routeCode===u.routeCode&&d("NATIVE_APPLICATION_AUTH_SURFACE_CODE_DUPLICATE",`${n}/surfaces/mobile/routeCode`);let E=R(t,"/config/frontend/routes",500),_=new Map;for(let[m,T]of E.entries()){let C=I(T,`/config/frontend/routes/${m}`);_.set(String(C.code||""),C)}let A=new Set((Array.isArray(o.data?.resources)?o.data.resources:[]).map(m=>String(m.code||"")).filter(m=>/^[a-z][a-z0-9-]{0,62}$/.test(m)));for(let[m,T]of[["desktop",l],["mobile",u]]){_.has(T.routeCode)&&d("NATIVE_APPLICATION_AUTH_SURFACE_CODE_CONFLICT",`${n}/surfaces/${m}/routeCode`);let C=/^user\.([a-z][a-z0-9-]{0,62})\.(records|submit)$/.exec(String(T.defaultRouteCode||"")),$=_.get(T.defaultRouteCode),b=String($?.path||"");if(C&&A.has(C[1])){let D=C[2]==="records"?`/my/${C[1]}`:`/my/${C[1]}/submit`;$={surface:"user",path:m==="mobile"?`/m${D}`:D},b=String($.path)}let g=m==="desktop"?b==="/m"||b.startsWith("/m/"):!(b==="/m"||b.startsWith("/m/"));(!$||$.surface!=="user"||/[:*]/.test(b)||g)&&d("NATIVE_APPLICATION_AUTH_DEFAULT_ROUTE_INVALID",`${n}/surfaces/${m}/defaultRouteCode`)}let N=wn(o).filter(m=>!m.owner.startsWith("authentication:"));for(let[m,T]of[["desktop",l],["mobile",u]]){let C=N.find($=>qe($.path)===qe(T.path));C&&d("NATIVE_APPLICATION_AUTH_SURFACE_PATH_CONFLICT",`${n}/surfaces/${m}/path`,{owner:C.owner})}}function hs(e,t){if(e===null)return;let o={data:{resources:[]},workflows:{definitions:[]},frontend:{routes:[{code:"auth-desktop-default",path:"/auth-desktop-default",surface:"user"},{code:"auth-mobile-default",path:"/m/auth-mobile-default",surface:"user"}],user:{applicationTodoCenter:!1},admin:{navigation:[]},authentication:e}},n=I(e,t),s=I(n.surfaces,`${t}/surfaces`),r={...n,surfaces:{...s,desktop:{...I(s.desktop,`${t}/surfaces/desktop`),defaultRouteCode:"auth-desktop-default"},mobile:{...I(s.mobile,`${t}/surfaces/mobile`),defaultRouteCode:"auth-mobile-default"}}};Vn(r,o.frontend.routes,{...o,frontend:{...o.frontend,authentication:r}},t)}function Ss(e){let t=e.frontend.authentication;return t===null?null:{accountMode:t.accountMode,registration:{mode:t.registration.mode},methods:t.methods.map(o=>({...o})),surfaces:{desktop:{...t.surfaces.desktop},mobile:{...t.surfaces.mobile}}}}var Ds=new Set(["draft.read","draft.update","validate","create","own.list","own.read","public.list","public.read"]);function ys(e,t,o){let n=I(e,o);O(n,["policies"],o);let s=R(n.policies,`${o}/policies`,16);s.length<1&&d("NATIVE_PUBLIC_POLICY_REQUIRED",o);let r=new Map(t.frontend.routes.map(f=>[f.code,f])),a=new Map(t.data.resources.map(f=>[f.code,f])),i=new Set,c=new Set(s.map(f=>String(f?.code||"")));s.forEach((f,p)=>{let l=`${o}/policies/${p}`,u=I(f,l);O(u,["code","routeCode","mode","resourceCode","operations","fields"],l,["requiredFields","ownRecordFields","publicRecordFields","publicFilters","serverGeneratedFields","schedule","publicSubtableFields","draft","validations"]);let E=w(u.code,`${l}/code`);i.has(E)&&d("NATIVE_PUBLIC_POLICY_DUPLICATE",`${l}/code`);let _=w(u.routeCode,`${l}/routeCode`),A=r.get(_);(!A||A.surface!=="user"||A.capability!==void 0||A.access!==void 0||/[:*]/.test(String(A.path)))&&d("NATIVE_PUBLIC_ROUTE_INVALID",`${l}/routeCode`),v(u.mode,"anonymous",`${l}/mode`);let N=z(u.resourceCode,`${l}/resourceCode`),m=a.get(N);m||d("NATIVE_PUBLIC_RESOURCE_MISSING",`${l}/resourceCode`);let T=new Map(m.schema.fields.map(y=>[String(y.code),String(y.type)])),C=F(u.operations,`${l}/operations`,8);(C.length<1||C.some(y=>!Ds.has(y)))&&d("NATIVE_PUBLIC_OPERATION_INVALID",`${l}/operations`),C.includes("draft.read")!==C.includes("draft.update")&&d("NATIVE_PUBLIC_DRAFT_OPERATION_INCOMPLETE",`${l}/operations`);let $=F(u.fields,`${l}/fields`,64);($.length<1||$.some(y=>!T.has(y)))&&d("NATIVE_PUBLIC_FIELD_INVALID",`${l}/fields`);for(let y of["requiredFields","ownRecordFields","publicRecordFields"]){if(!Object.prototype.hasOwnProperty.call(u,y))continue;F(u[y],`${l}/${y}`,64).some(P=>!$.includes(P))&&d("NATIVE_PUBLIC_FIELD_SCOPE_INVALID",`${l}/${y}`)}let b=Object.prototype.hasOwnProperty.call(u,"serverGeneratedFields")?R(u.serverGeneratedFields,`${l}/serverGeneratedFields`,16):[],g=new Set;b.forEach((y,U)=>{let P=`${l}/serverGeneratedFields/${U}`,B=I(y,P);O(B,["field","kind"],P);let J=W(B.field,`${P}/field`);(g.has(J)||!T.has(J)||$.includes(J)||T.get(J)!=="text.short"&&T.get(J)!=="text.long")&&d("NATIVE_PUBLIC_SERVER_GENERATED_FIELD_INVALID",`${P}/field`),v(B.kind,"random-token",`${P}/kind`),g.add(J)});let D=Object.prototype.hasOwnProperty.call(u,"schedule")?I(u.schedule,`${l}/schedule`):null;if(D){let y=["campusPolicyCode","rulePolicyCode","campusField","ruleCampusField","ruleWeekdaysField","ruleOpenAtField","ruleCloseAtField","ruleSlotMinutesField","ruleAdvanceHoursField","ruleAdvanceDaysField","campusEnabledField","ruleEnabledField","dateField","timeField"];O(D,y,`${l}/schedule`);for(let U of["campusPolicyCode","rulePolicyCode"])w(D[U],`${l}/schedule/${U}`);for(let U of y.filter(P=>!["campusPolicyCode","rulePolicyCode"].includes(P)))W(D[U],`${l}/schedule/${U}`);for(let U of[D.campusField,D.dateField,D.timeField])$.includes(String(U))||d("NATIVE_PUBLIC_SCHEDULE_FIELD_INVALID",`${l}/schedule`);(!c.has(String(D.campusPolicyCode))||!c.has(String(D.rulePolicyCode)))&&d("NATIVE_PUBLIC_SCHEDULE_POLICY_INVALID",`${l}/schedule`)}let V=Object.prototype.hasOwnProperty.call(u,"publicFilters")?R(u.publicFilters,`${l}/publicFilters`,16):[],x=new Set;V.forEach((y,U)=>{let P=`${l}/publicFilters/${U}`,B=I(y,P);O(B,["field","operator","value"],P);let J=W(B.field,`${P}/field`);x.has(J)&&d("NATIVE_PUBLIC_FILTER_DUPLICATE",`${P}/field`),$.includes(J)||d("NATIVE_PUBLIC_FILTER_FIELD_INVALID",`${P}/field`),v(B.operator,"eq",`${P}/operator`),["boolean","text.short","text.long","number.integer","number.decimal","date","time"].includes(T.get(J)||"")||d("NATIVE_PUBLIC_FILTER_FIELD_INVALID",`${P}/field`),B.value!==null&&typeof B.value!="string"&&typeof B.value!="number"&&typeof B.value!="boolean"&&d("NATIVE_PUBLIC_FILTER_VALUE_INVALID",`${P}/value`),x.add(J)});let k=Object.prototype.hasOwnProperty.call(u,"publicSubtableFields")?I(u.publicSubtableFields,`${l}/publicSubtableFields`):null;if(k){Object.keys(k).length>64&&d("NATIVE_PUBLIC_SUBTABLE_FIELDS_INVALID",`${l}/publicSubtableFields`);for(let[y,U]of Object.entries(k)){let P=m.schema.fields.find(H=>String(H.code)===y),B=String(P?.subtable?.resourceCode||""),J=a.get(B),_e=new Map((J?.schema?.fields||[]).map(H=>[String(H.code),String(H.type)])),G=F(U,`${l}/publicSubtableFields/${y}`,64);(!$.includes(y)||T.get(y)!=="subtable"||!J||G.length<1||G.some(H=>!_e.has(H))||G.some(H=>_e.get(H)==="subtable")||G.some(H=>_e.get(H)==="signature"))&&d("NATIVE_PUBLIC_SUBTABLE_FIELDS_INVALID",`${l}/publicSubtableFields/${y}`)}}if(C.some(y=>y.startsWith("public."))){Object.prototype.hasOwnProperty.call(u,"publicRecordFields")||d("NATIVE_PUBLIC_RECORD_FIELDS_REQUIRED",`${l}/publicRecordFields`);let y=F(u.publicRecordFields,`${l}/publicRecordFields`,64);(y.length<1||y.some(U=>!$.includes(U))||y.some(U=>T.get(U)==="signature"||T.get(U)==="subtable"&&!k?.[U]))&&d("NATIVE_PUBLIC_RECORD_FIELDS_INVALID",`${l}/publicRecordFields`)}let Y=Object.prototype.hasOwnProperty.call(u,"requiredFields")?F(u.requiredFields,`${l}/requiredFields`,64):[],M=m.surface||{},ae=M.fields||{},ce=String(M.mutationOwner||"native")==="native"&&M.generated?.create!==!1,K=m.schema.fields.filter(y=>Je(y,ae[y.code])).map(y=>String(y.code));if(C.includes("create")&&!ce&&d("NATIVE_PUBLIC_CREATE_FIELDS_INCOMPLETE",`${l}/fields`),C.includes("create")&&!Object.prototype.hasOwnProperty.call(u,"draft")&&d("NATIVE_PUBLIC_DRAFT_REQUIRED",`${l}/draft`),C.includes("create"))for(let y of K){let U=$.includes(y)?Y.includes(y)?null:"requiredFields":"fields";U&&d("NATIVE_PUBLIC_CREATE_FIELDS_INCOMPLETE",`${l}/${U}`,{resourceCode:z,fieldCode:y})}if(Object.prototype.hasOwnProperty.call(u,"draft")){let y=I(u.draft,`${l}/draft`);O(y,["enabled","inactivityTtlSeconds","maxBytes"],`${l}/draft`),v(y.enabled,!0,`${l}/draft/enabled`),Z(y.inactivityTtlSeconds,`${l}/draft/inactivityTtlSeconds`,3600,7776e3),Z(y.maxBytes,`${l}/draft/maxBytes`,4096,262144)}else C.includes("draft.read")&&d("NATIVE_PUBLIC_DRAFT_REQUIRED",`${l}/draft`);let fe=Object.prototype.hasOwnProperty.call(u,"validations")?R(u.validations,`${l}/validations`,16):[],oe=new Set;fe.forEach((y,U)=>{let P=`${l}/validations/${U}`,B=I(y,P);O(B,["code","kind","fields","result"],P);let J=w(B.code,`${P}/code`);oe.has(J)&&d("NATIVE_PUBLIC_VALIDATION_DUPLICATE",`${P}/code`),v(B.kind,"duplicate",`${P}/kind`),v(B.result,"availability",`${P}/result`);let _e=F(B.fields,`${P}/fields`,8);(_e.length<1||_e.some(G=>!$.includes(G))||_e.some(G=>["file","subtable"].includes(T.get(G)||"")))&&d("NATIVE_PUBLIC_VALIDATION_FIELD_INVALID",`${P}/fields`),oe.add(J)}),i.add(E)})}function Vs(e,t){let o=I(e,t);O(o,["policies"],t),R(o.policies,`${t}/policies`,16).length<1&&d("NATIVE_PUBLIC_POLICY_REQUIRED",t)}function ws(e){return{policies:X(e.frontend.publicAccess.policies.map(t=>({code:t.code,routeCode:t.routeCode,mode:t.mode,resourceCode:t.resourceCode,operations:j(t.operations),fields:j(t.fields),...t.requiredFields?{requiredFields:j(t.requiredFields)}:{},...t.ownRecordFields?{ownRecordFields:j(t.ownRecordFields)}:{},...t.publicRecordFields?{publicRecordFields:j(t.publicRecordFields)}:{},...t.publicFilters?{publicFilters:t.publicFilters.map(o=>({field:o.field,operator:o.operator,value:o.value})).sort((o,n)=>ie(o.field,n.field))}:{},...t.publicSubtableFields?{publicSubtableFields:Object.fromEntries(Object.entries(t.publicSubtableFields).sort(([o],[n])=>o.localeCompare(n)).map(([o,n])=>[o,j(Array.isArray(n)?n.map(String):[])]))}:{},...t.serverGeneratedFields?{serverGeneratedFields:t.serverGeneratedFields.map(o=>({field:o.field,kind:o.kind})).sort((o,n)=>ie(o.field,n.field))}:{},...t.schedule?{schedule:{campusPolicyCode:t.schedule.campusPolicyCode,rulePolicyCode:t.schedule.rulePolicyCode,campusField:t.schedule.campusField,ruleCampusField:t.schedule.ruleCampusField,ruleWeekdaysField:t.schedule.ruleWeekdaysField,ruleOpenAtField:t.schedule.ruleOpenAtField,ruleCloseAtField:t.schedule.ruleCloseAtField,ruleSlotMinutesField:t.schedule.ruleSlotMinutesField,ruleAdvanceHoursField:t.schedule.ruleAdvanceHoursField,ruleAdvanceDaysField:t.schedule.ruleAdvanceDaysField,campusEnabledField:t.schedule.campusEnabledField,ruleEnabledField:t.schedule.ruleEnabledField,dateField:t.schedule.dateField,timeField:t.schedule.timeField}}:{},...t.draft?{draft:{...t.draft}}:{},...t.validations?{validations:X(t.validations.map(o=>({code:o.code,kind:o.kind,fields:j(o.fields),result:o.result})),o=>o.code)}:{}})),t=>t.code)}}function wn(e){let t=[{owner:"platform:admin-entry",path:"/"},{owner:"platform:admin-entry",path:"/admin"},{owner:"platform:file-preview",path:"/files/:resourceCode/:fileId/preview"}];e.frontend.authentication&&t.push({owner:"authentication:desktop",path:e.frontend.authentication.surfaces.desktop.path},{owner:"authentication:mobile",path:e.frontend.authentication.surfaces.mobile.path});for(let o of e.data.resources){let n=Fn(o),s=`/admin/resources/${o.code}`,r=[["list",s],["detail",`${s}/:id`],["create",`${s}/new`],["update",`${s}/:id/edit`]];for(let[a,i]of r)n[a]&&t.push({owner:`resource:${o.code}:${a}`,path:i},{owner:`resource:${o.code}:${a}:mobile`,path:`/m${i}`})}if(e.frontend.user.applicationTodoCenter===!0&&t.push({owner:"application:todo-center",path:"/todos"},{owner:"application:todo-center:mobile",path:"/m/todos"}),e.workflows.definitions.length>0){t.push({owner:"workflow:work-center",path:"/work-center"},{owner:"workflow:work-center:mobile",path:"/m/work-center"},{owner:"workflow:task",path:"/tasks/:taskId"},{owner:"workflow:task:mobile",path:"/m/tasks/:taskId"},{owner:"workflow:instance",path:"/workflows/:instanceId"},{owner:"workflow:instance:mobile",path:"/m/workflows/:instanceId"});let o=!1;for(let n of e.workflows.definitions)["standalone","hidden-handoff"].includes(n.launch.mode)&&(o=!0);o&&t.push({owner:"workflow:launch",path:"/workflows/:workflowCode/start"},{owner:"workflow:launch:mobile",path:"/m/workflows/:workflowCode/start"})}return t}function Xe(e){let t=new Map(wn(e).map(o=>[qe(o.path),o]));return X(e.frontend.routes.map((o,n)=>{let s=`/config/frontend/routes/${n}`,r=I(o,s);O(r,["code","path","label","surface","parentCode","capability","access","pinned","tabPersistence","keepAlive"],s,!0),["admin","user"].includes(r.surface)||d("NATIVE_ROUTE_SURFACE_INVALID",`${s}/surface`);let a=re(r.path,`${s}/path`);r.surface==="admin"&&a!=="/admin"&&!a.startsWith("/admin/")&&d("NATIVE_ADMIN_ROUTE_PATH_INVALID",`${s}/path`),r.surface==="user"&&(a==="/admin"||a.startsWith("/admin/"))&&d("NATIVE_USER_ROUTE_PATH_RESERVED",`${s}/path`);let i=qe(a),c=t.get(i);c&&d("NATIVE_ROUTE_PATH_CONFLICT",`${s}/path`,{path:a,owner:c.owner}),t.set(i,{owner:`frontend:${String(r.code||n)}`,path:a});let f=/[:*]/.test(a),p=St(r,s,e.appCode),l=r.pinned===void 0?void 0:De(r.pinned,`${s}/pinned`),u=r.tabPersistence===void 0?f?"none":"session":h(r.tabPersistence,`${s}/tabPersistence`,16),E=r.keepAlive===void 0?"none":h(r.keepAlive,`${s}/keepAlive`,16);return["session","none"].includes(u)||d("NATIVE_ROUTE_TAB_PERSISTENCE_INVALID",`${s}/tabPersistence`),["none","memory"].includes(E)||d("NATIVE_ROUTE_KEEP_ALIVE_INVALID",`${s}/keepAlive`),f&&l===!0&&d("NATIVE_DYNAMIC_ROUTE_PINNED_FORBIDDEN",`${s}/pinned`),f&&u==="session"&&d("NATIVE_DYNAMIC_ROUTE_TAB_PERSISTENCE_FORBIDDEN",`${s}/tabPersistence`),f&&E==="memory"&&d("NATIVE_DYNAMIC_ROUTE_KEEP_ALIVE_FORBIDDEN",`${s}/keepAlive`),{code:w(r.code,`${s}/code`),path:a,label:h(r.label,`${s}/label`,255),surface:r.surface,...r.parentCode===void 0?{}:{parentCode:w(r.parentCode,`${s}/parentCode`)},...p,...l===void 0?{}:{pinned:l},tabPersistence:u,keepAlive:E}}),o=>o.code)}function Fn(e){let t=e.surface===void 0?{}:I(e.surface,"/surface"),o=t.mutationOwner||"native",n=t.generated===void 0?{}:I(t.generated,"/surface/generated"),s=o==="native";return{list:n.list??!0,detail:n.detail??!0,create:n.create??s,update:n.update??s,delete:n.delete??s}}function Pn(e){let t=[];for(let o of X(e.data.resources,n=>n.code).flatMap(n=>[{resource:n,viewCode:void 0},...(n.surface?.views||[]).map(s=>({viewCode:s.code,resource:{...n,name:s.name,surface:_t(n.surface,s.code)}}))])){let{resource:n,viewCode:s}=o,r=`/admin/resources/${n.code}${s?`/views/${s}`:""}`,a=Fn(n),i=[{operation:"list",kind:"resource-list",path:`${r}`,label:n.name,capability:n.capabilities.read,navigationEligible:!0},{operation:"detail",kind:"resource-detail",path:`${r}/:id`,label:`${n.name}\u8BE6\u60C5`,capability:n.capabilities.read,navigationEligible:!1},{operation:"create",kind:"resource-create",path:`${r}/new`,label:`\u65B0\u589E${n.name}`,capability:n.capabilities.create,navigationEligible:!1},{operation:"update",kind:"resource-update",path:`${r}/:id/edit`,label:`\u7F16\u8F91${n.name}`,capability:n.capabilities.update,navigationEligible:!1}];for(let c of i)a[c.operation]&&t.push({code:`resource:${n.code}${s?`:view:${s}`:""}:${c.operation}`,kind:c.kind,path:c.path,label:c.label,navigationEligible:c.navigationEligible,capability:c.capability,resourceCode:n.code,...s?{viewCode:s}:{}})}for(let o of Xe(e))o.surface==="admin"&&t.push({code:`operation:${o.code}`,kind:"operation",path:o.path,label:o.label,navigationEligible:!/[:*]/.test(o.path),routeCode:o.code});return t.sort((o,n)=>ie(o.code,n.code))}function Ln(e){return e.kind==="resource"?`resource:${e.resourceCode}${e.viewCode?`:view:${e.viewCode}`:""}:list`:`operation:${e.routeCode}`}function Fs(e){return e.frontend.admin.navigation.map((t,o)=>({code:t.code,label:t.label,...t.icon===void 0?{}:{icon:t.icon},order:t.order??o,items:t.items.map((n,s)=>({pageCode:Ln(n.page),...n.label===void 0?{}:{label:n.label},...n.icon===void 0?{}:{icon:n.icon},order:n.order??s})).sort((n,s)=>n.order-s.order||ie(n.pageCode,s.pageCode))})).sort((t,o)=>t.order-o.order||ie(t.code,o.code))}function Ps(e,t){let o=R(e,t,q.adminNavigationGroups),n=0;o.forEach((s,r)=>{let a=`${t}/${r}`,i=I(s,a);O(i,["code","label","icon","order","items"],a,!0),w(i.code,`${a}/code`),h(i.label,`${a}/label`,255),Ke(i.icon,`${a}/icon`),mn(i.order,`${a}/order`);let c=R(i.items,`${a}/items`,500);c.length===0&&d("NATIVE_ADMIN_GROUP_ORPHANED",`${a}/items`),n+=c.length,n>q.adminNavigationItems&&d("NATIVE_ARRAY_LIMIT_EXCEEDED",t),c.forEach((f,p)=>{let l=`${a}/items/${p}`,u=I(f,l);O(u,["page","label","icon","order"],l,!0),Ls(u.page,`${l}/page`),u.label!==void 0&&h(u.label,`${l}/label`,255),Ke(u.icon,`${l}/icon`),mn(u.order,`${l}/order`)})})}function Ls(e,t){let o=I(e,t),n=h(o.kind,`${t}/kind`,64);if(n==="resource"){O(o,["kind","resourceCode"],t,["viewCode"]),o.viewCode!==void 0&&w(o.viewCode,`${t}/viewCode`),z(o.resourceCode,`${t}/resourceCode`);return}if(n==="operation"){O(o,["kind","routeCode"],t),w(o.routeCode,`${t}/routeCode`);return}d("NATIVE_ADMIN_PAGE_REFERENCE_KIND_INVALID",`${t}/kind`)}function vs(e){let t=new Map(Pn(e).map(s=>[String(s.code),s])),o=new Set,n=new Set;e.frontend.admin.navigation.forEach((s,r)=>{let a=`/config/frontend/admin/navigation/${r}`;o.has(s.code)&&d("NATIVE_ADMIN_GROUP_DUPLICATE",`${a}/code`),o.add(s.code),s.label===s.code&&d("NATIVE_ADMIN_USER_LABEL_REQUIRED",`${a}/label`),s.items.forEach((i,c)=>{let f=`${a}/items/${c}`,p=Ln(i.page),l=t.get(p);(!l||l.navigationEligible!==!0)&&d("NATIVE_ADMIN_PAGE_NOT_FOUND",`${f}/page`),n.has(p)&&d("NATIVE_ADMIN_PAGE_DUPLICATE",`${f}/page`),n.add(p);let u=i.page.resourceCode||i.page.routeCode||i.page.workflowCode||p,E=i.label||l.label;(!E||E===u||E===p)&&d("NATIVE_ADMIN_USER_LABEL_REQUIRED",`${f}/label`)})})}function ks(e,t){let o=R(e,t,q.adminPages),n=new Set;o.forEach((s,r)=>{let a=`${t}/${r}`,i=I(s,a);O(i,["code","kind","path","label","navigationEligible","capability","access","resourceCode","viewCode","routeCode"],a,!0);let c=h(i.code,`${a}/code`,255);n.has(c)&&d("NATIVE_ADMIN_PAGE_DUPLICATE",`${a}/code`),n.add(c);let f=h(i.kind,`${a}/kind`,64);if(["resource-list","resource-detail","resource-create","resource-update","operation"].includes(f)||d("NATIVE_ADMIN_PAGE_KIND_INVALID",`${a}/kind`),re(i.path,`${a}/path`),h(i.label,`${a}/label`,255),De(i.navigationEligible,`${a}/navigationEligible`),i.capability!==void 0&&i.access!==void 0&&d("NATIVE_ROUTE_ACCESS_CONFLICT",`${a}/access`),i.capability!==void 0&&h(i.capability,`${a}/capability`,255),i.access!==void 0){let p=I(i.access,`${a}/access`);O(p,["allOf","anyOf"],`${a}/access`,!0);for(let l of["allOf","anyOf"])p[l]!==void 0&&F(p[l],`${a}/access/${l}`,50)}for(let p of["resourceCode","viewCode","routeCode"])i[p]!==void 0&&w(i[p],`${a}/${p}`)})}function Us(e,t){let o=R(e,t,q.adminNavigationGroups),n=0;o.forEach((s,r)=>{let a=`${t}/${r}`,i=I(s,a);O(i,["code","label","icon","order","items"],a,!0),w(i.code,`${a}/code`),h(i.label,`${a}/label`,255),Ke(i.icon,`${a}/icon`),Z(i.order,`${a}/order`,-1e4,1e4);let c=R(i.items,`${a}/items`,500);c.length===0&&d("NATIVE_ADMIN_GROUP_ORPHANED",`${a}/items`),n+=c.length,n>q.adminNavigationItems&&d("NATIVE_ARRAY_LIMIT_EXCEEDED",t),c.forEach((f,p)=>{let l=`${a}/items/${p}`,u=I(f,l);O(u,["pageCode","label","icon","order"],l,!0),h(u.pageCode,`${l}/pageCode`,255),u.label!==void 0&&h(u.label,`${l}/label`,255),Ke(u.icon,`${l}/icon`),Z(u.order,`${l}/order`,-1e4,1e4)})})}var xs=new Set(["application-todo-center","workflow-work-center","workflow-launch","workflow-task","workflow-instance","resource-records","resource-submit"]);function Ms(e,t,o){let n=I(e,t);O(n,["schemaVersion","appCode","devicePolicy","rootEntry","authentication","routes","digest"],t),v(n.schemaVersion,Sn,`${t}/schemaVersion`),v(n.appCode,o,`${t}/appCode`),ht(n.devicePolicy,`${t}/devicePolicy`),js(n.rootEntry,`${t}/rootEntry`),Bs(n.authentication,`${t}/authentication`),$t(n.digest,`${t}/digest`);let s=R(n.routes,`${t}/routes`,q.routes),r=new Set;s.forEach((a,i)=>{let c=`${t}/routes/${i}`,f=I(a,c),p=f.kind==="resource-records"||f.kind==="resource-submit";O(f,["code","kind","desktop","mobile"],c,["workflowCode",...p?["resourceCode"]:[]]);let l=h(f.code,`${c}/code`,255);r.has(l)&&d("NATIVE_ROUTE_MANIFEST_DUPLICATE",`${c}/code`),r.add(l);let u=h(f.kind,`${c}/kind`,64);if(xs.has(u)||d("NATIVE_ROUTE_MANIFEST_KIND_INVALID",`${c}/kind`),f.workflowCode!==void 0&&w(f.workflowCode,`${c}/workflowCode`),p){let A=z(f.resourceCode,`${c}/resourceCode`);v(l,`user.${A}.${f.kind==="resource-records"?"records":"submit"}`,`${c}/code`)}else f.resourceCode!==void 0&&d("NATIVE_PROPERTY_UNKNOWN",`${c}/resourceCode`);let E=En(f.desktop,`${c}/desktop`,o),_=En(f.mobile,`${c}/mobile`,o);E.surface!=="user"&&d("NATIVE_ROUTE_MANIFEST_DESKTOP_SURFACE_INVALID",`${c}/desktop/surface`),_.surface!=="user"&&d("NATIVE_ROUTE_MANIFEST_MOBILE_SURFACE_INVALID",`${c}/mobile/surface`),E.routeCode===_.routeCode&&d("NATIVE_ROUTE_MANIFEST_PAIR_DUPLICATE",c)}),v(n.digest,ee({schemaVersion:n.schemaVersion,appCode:n.appCode,devicePolicy:n.devicePolicy,rootEntry:n.rootEntry,authentication:n.authentication,routes:n.routes}),`${t}/digest`)}function ht(e,t){let o=I(e,t);O(o,["kind","mobileMaxWidthPx","desktopMinWidthPx"],t),v(o.kind,"viewport-family",`${t}/kind`);let n=Z(o.mobileMaxWidthPx,`${t}/mobileMaxWidthPx`,320,1600),s=Z(o.desktopMinWidthPx,`${t}/desktopMinWidthPx`,320,1600);return s!==n+1&&d("NATIVE_FRONTEND_DEVICE_POLICY_INVALID",t),{kind:"viewport-family",mobileMaxWidthPx:n,desktopMinWidthPx:s}}function js(e,t){let o=I(e,t);O(o,["code","desktop","mobile"],t);let n=w(o.code,`${t}/code`),s=Ot(o.desktop,`${t}/desktop`),r=Ot(o.mobile,`${t}/mobile`);return(s===r||r==="/"||!r.startsWith("/m/"))&&d("NATIVE_ROUTE_MANIFEST_ROOT_ENTRY_INVALID",t),s.startsWith("/m/")&&d("NATIVE_ROUTE_MANIFEST_ROOT_ENTRY_INVALID",`${t}/desktop`),{code:n,desktop:s,mobile:r}}function Bs(e,t){let o=I(e,t);O(o,["desktop","mobile"],t);let n=pn(o.desktop,`${t}/desktop`,!1),s=pn(o.mobile,`${t}/mobile`,!0);return(n.routeCode===s.routeCode||n.path===s.path)&&d("NATIVE_ROUTE_MANIFEST_AUTHENTICATION_DUPLICATE",t),{desktop:n,mobile:s}}function pn(e,t,o){let n=I(e,t);O(n,["routeCode","path"],t);let s=w(n.routeCode,`${t}/routeCode`),r=Ot(n.path,`${t}/path`);return(o?!r.startsWith("/m/"):r.startsWith("/m/"))&&d("NATIVE_ROUTE_MANIFEST_AUTHENTICATION_PATH_INVALID",`${t}/path`),{routeCode:s,path:r}}function Ot(e,t){let o=re(e,t);return/[:*?#\\\\]/.test(o)&&d("NATIVE_ROUTE_MANIFEST_STATIC_PATH_INVALID",t),o}function En(e,t,o){let n=I(e,t);O(n,["routeCode","path","surface","pathParams","requiresAuthentication"],t,["capability","access"]),w(n.routeCode,`${t}/routeCode`);let s=re(n.path,`${t}/path`),r=h(n.surface,`${t}/surface`,16);["admin","user"].includes(r)||d("NATIVE_ROUTE_SURFACE_INVALID",`${t}/surface`);let a=F(n.pathParams,`${t}/pathParams`,8);return a.forEach((i,c)=>{(!/^[A-Za-z][A-Za-z0-9_]*$/.test(i)||i.length>64)&&d("NATIVE_ROUTE_PATH_PARAM_INVALID",`${t}/pathParams/${c}`)}),Q(a)!==Q(vn(s))&&d("NATIVE_ROUTE_PATH_PARAMS_MISMATCH",`${t}/pathParams`),St(n,t,o),n.requiresAuthentication!==!0&&d("NATIVE_ROUTE_AUTHENTICATION_REQUIRED",`${t}/requiresAuthentication`),n}function vn(e){return j([...e.matchAll(/:([A-Za-z][A-Za-z0-9_]*)/g)].map(t=>t[1]))}function An(e,t,o,n){return{routeCode:e,path:t,surface:o,pathParams:vn(t),...n?.capability?{capability:n.capability}:{},...n?.access?{access:n.access}:{},requiresAuthentication:!0}}function In(e,t,o,n){return e==="workflow-launch"?`workflow.${o}.launch.${t}`:e==="application-todo-center"?`application.todo-center.${t}`:e==="resource-records"?`user.${n}.records.${t}`:e==="resource-submit"?`user.${n}.submit.${t}`:`${e.replace(/-/g,".")}.${t}`}function Js(e){let t=e.appCode,o=[],n=(E,_,A,N,m,T,C)=>{o.push({code:E,kind:_,...m?{workflowCode:m}:{},...C?{resourceCode:C}:{},desktop:An(In(_,"desktop",m,C),A,"user",T),mobile:An(In(_,"mobile",m,C),N,"user",T)})};e.frontend.user.applicationTodoCenter===!0&&n("application:todo-center","application-todo-center","/todos","/m/todos");let s=kn(e);s.length>0&&(n("workflow:work-center","workflow-work-center","/work-center","/m/work-center"),n("workflow:task","workflow-task","/tasks/:taskId","/m/tasks/:taskId"),n("workflow:instance","workflow-instance","/workflows/:instanceId","/m/workflows/:instanceId"));for(let E of s){if(!["standalone","hidden-handoff"].includes(E.launch.mode))continue;let _=j([E.launch.submission?.create?.requiredCapability,E.launch.submission?.existing?.requiredCapability].filter(A=>!!A));n(`workflow:${E.code}:launch`,"workflow-launch","/workflows/:workflowCode/start","/m/workflows/:workflowCode/start",E.code,_.length===1?{capability:_[0]}:_.length>1?{access:{anyOf:_}}:void 0)}let r=o.sort((E,_)=>ie(String(E.code),String(_.code))),a=Xe(e),i=E=>{let _=E==="mobile"?"/m/":"/",A=a.filter(m=>m.surface==="user"&&!/[:*?#\\\\]/.test(m.path)&&m.path===_).sort((m,T)=>ie(m.code,T.code))[0];if(A)return{code:A.code,path:A.path};let N=a.filter(m=>m.surface==="user"&&!/[:*?#\\\\]/.test(m.path)&&(E==="mobile"?m.path.startsWith("/m/"):!m.path.startsWith("/m/"))).sort((m,T)=>ie(m.code,T.code))[0];return N?{code:N.code,path:N.path}:{code:E==="mobile"?"application-root-mobile":"application-root",path:_}},c=e.frontend.authentication?{desktop:{routeCode:e.frontend.authentication.surfaces.desktop.routeCode,path:e.frontend.authentication.surfaces.desktop.path},mobile:{routeCode:e.frontend.authentication.surfaces.mobile.routeCode,path:e.frontend.authentication.surfaces.mobile.path}}:{desktop:{routeCode:"application-login",path:"/login"},mobile:{routeCode:"application-login-mobile",path:"/m/login"}},f=ht(e.frontend.devicePolicy,"/config/frontend/devicePolicy"),p=i("desktop"),l=i("mobile"),u={schemaVersion:Sn,appCode:t,devicePolicy:f,rootEntry:{code:p.code,desktop:p.path,mobile:l.path},authentication:c,routes:r};return{...u,digest:ee(u)}}function Ke(e,t){if(e===void 0)return;let o=h(e,t,32);ns.has(o)||d("NATIVE_ADMIN_ICON_INVALID",t)}function mn(e,t){e!==void 0&&Z(e,t,-1e4,1e4)}function St(e,t,o){return e.capability!==void 0&&e.access!==void 0&&d("NATIVE_ROUTE_ACCESS_CONFLICT",`${t}/access`),e.capability!==void 0?{capability:Ee(e.capability,`${t}/capability`,o)}:e.access===void 0?{}:{access:Qe(e.access,`${t}/access`,o)}}function Qe(e,t,o){let n=I(e,t);O(n,["allOf","anyOf"],t,!0);let s=n.allOf===void 0?void 0:j(F(n.allOf,`${t}/allOf`,50).map((a,i)=>Ee(a,`${t}/allOf/${i}`,o))),r=n.anyOf===void 0?void 0:j(F(n.anyOf,`${t}/anyOf`,50).map((a,i)=>Ee(a,`${t}/anyOf/${i}`,o)));return(s?.length||0)+(r?.length||0)===0&&d("NATIVE_ROUTE_ACCESS_EMPTY",t),{...s===void 0?{}:{allOf:s},...r===void 0?{}:{anyOf:r}}}function kn(e){let t=new Map(yn(e).map(s=>[String(s.code),s])),o=e.workflows.definitions.map((s,r)=>{let a=`/config/workflows/definitions/${r}`,i=I(s,a);O(i,["version","definition","launch"],a,["detailRouteCode"]);let c=I(i.definition,`${a}/definition`),f=i.detailRouteCode===void 0?void 0:xn(i.detailRouteCode,`${a}/detailRouteCode`);return{code:w(c.code,`${a}/definition/code`),title:h(c.title,`${a}/definition/title`,255),version:Se(i.version,`${a}/version`),launch:Ws(e,c,i.launch,`${a}/launch`,t),...f?{detailRouteCode:f}:{},definition:c}});return j(o.map(s=>s.code)).map(s=>{let r=o.filter(f=>f.code===s),a=e.workflows.activations.find(f=>f.workflowCode===s)?.definitionVersion,i=r.find(f=>f.version===a)||[...r].sort((f,p)=>p.version-f.version)[0],c=new Set;for(let f of r){let p=I(f.definition.nodes,"/config/workflows/definitions/nodes");for(let l of Object.values(p)){let u=I(l,"/config/workflows/definitions/nodes/*");if(u.kind==="approval")for(let E of F(u.allowedOperations||[],"/config/workflows/definitions/nodes/*/allowedOperations",20))c.add(E)}}return{code:s,title:i.title,acceptedCommandDeactivationPolicy:i.definition.acceptedCommandDeactivationPolicy,subject:i.definition.subject,launch:i.launch,...["standalone","hidden-handoff"].includes(i.launch.mode)&&!i.launch.submission?{processOperationCode:`openxiangda.workflow.${s}.submit`}:{},...i.detailRouteCode?{detailRouteCode:i.detailRouteCode}:{},definitionVersions:Rn(r.map(f=>f.version)),bindingVersions:Rn(e.workflows.bindings.map((f,p)=>{let l=`/config/workflows/bindings/${p}`,u=I(f,l),E=I(u.binding,`${l}/binding`);return{code:w(E.workflowCode,`${l}/binding/workflowCode`),version:Se(u.version,`${l}/version`)}}).filter(f=>f.code===s).map(f=>f.version)),providerCodes:j(e.workflows.providers.map((f,p)=>w(I(f,`/config/workflows/providers/${p}`).code,`/config/workflows/providers/${p}/code`))),allowedOperations:[...c].sort(ie),editableParameterCodes:j(e.workflows.editableParameters.map((f,p)=>{let l=`/config/workflows/editableParameters/${p}`,u=I(f,l);return{code:w(u.code,`${l}/code`),workflowCode:w(u.workflowCode,`${l}/workflowCode`)}}).filter(f=>f.workflowCode===s).map(f=>f.code))}})}function Un(e,t){let o=I(e,t);O(o,["mode"],t,["submission"]);let n=h(o.mode,`${t}/mode`,32);return["standalone","custom-page","hidden-handoff","work-center-only"].includes(n)||d("NATIVE_WORKFLOW_LAUNCH_MODE_INVALID",`${t}/mode`),{mode:n,...o.submission===void 0?{}:{submission:I(o.submission,`${t}/submission`)}}}function Ws(e,t,o,n,s){let r=Un(o,n);if(!r.submission)return{mode:r.mode};["standalone","hidden-handoff"].includes(r.mode)||d("NATIVE_WORKFLOW_NAMED_OPERATION_SUBMISSION_INVALID",`${n}/submission`);let a=I(r.submission,`${n}/submission`);O(a,["kind"],`${n}/submission`,["create","existing","context"]),v(a.kind,"named-operation",`${n}/submission/kind`);let i=n.endsWith("/launch")?n.slice(0,-7):n,c=I(t.subject,`${i}/definition/subject`),f=z(c.resourceCode,`${i}/definition/subject/resourceCode`),p=e.data.resources.findIndex(g=>g.code===f),l=e.data.resources[p];(p<0||!l)&&d("NATIVE_WORKFLOW_SUBJECT_RESOURCE_MISSING",`${i}/definition/subject/resourceCode`);let u=new Set(I(l.schema,`/config/data/resources/${p}/schema`).fields.map(g=>String(g.code))),E=new Map(e.backend.operations.map(g=>[String(g.code),g])),_=(g,D)=>{let V=`${n}/submission/${D}`,x=I(g,V);O(x,["operationCode","inputs","output"],V);let k=w(x.operationCode,`${V}/operationCode`),Y=E.get(k),M=s.get(k),ae=M?.platformAccess?.workflow?.codes;(!Y||!M||M.method!=="POST"||!Array.isArray(ae)||!ae.includes(t.code))&&d("NATIVE_WORKFLOW_NAMED_OPERATION_INVALID",V);let ce=I(Y.requestSchema,`${V}/operation/requestSchema`),K=I(ce.properties,`${V}/operation/requestSchema/properties`),fe=new Set(ce.required===void 0?[]:F(ce.required,`${V}/operation/requestSchema/required`,64)),oe=I(x.inputs,`${V}/inputs`),y=Object.entries(oe);(!y.length||y.length>64)&&d("NATIVE_WORKFLOW_NAMED_OPERATION_INPUT_INVALID",`${V}/inputs`);let U=new Set,P=new Map,B={};for(let[G,H]of y){(!un.test(G)||!Object.prototype.hasOwnProperty.call(K,G))&&d("NATIVE_WORKFLOW_NAMED_OPERATION_INPUT_INVALID",`${V}/inputs/${G}`);let Ce=`${V}/inputs/${G}`,et=I(H,Ce),ge=h(et.source,`${Ce}/source`,32);if(["field","idempotency-key","current-user-reference","subject-id","subject-revision","requested-at"].includes(ge)||d("NATIVE_WORKFLOW_NAMED_OPERATION_INPUT_INVALID",Ce),O(et,["source"],Ce,ge==="field"?["fieldCode"]:!1),P.set(ge,(P.get(ge)||0)+1),ge==="field"){let xe=W(et.fieldCode,`${Ce}/fieldCode`);(U.has(xe)||!u.has(xe))&&d("NATIVE_WORKFLOW_NAMED_OPERATION_INPUT_INVALID",`${Ce}/fieldCode`),U.add(xe),B[G]={source:ge,fieldCode:xe}}else B[G]={source:ge}}([...fe].some(G=>!(G in oe))||(P.get("idempotency-key")||0)!==1||!y.some(([G,H])=>I(H,`${V}/inputs/${G}`).source==="idempotency-key"&&fe.has(G))||D==="create"&&((P.get("subject-id")||0)>0||(P.get("subject-revision")||0)>0)||D==="existing"&&((P.get("subject-id")||0)!==1||(P.get("subject-revision")||0)!==1))&&d("NATIVE_WORKFLOW_NAMED_OPERATION_INPUT_INVALID",`${V}/inputs`);let J=I(x.output,`${V}/output`);O(J,["subjectId"],`${V}/output`,["subjectRevision","processCommand"]);let _e=I(I(Y.responseSchema,`${V}/operation/responseSchema`).properties,`${V}/operation/responseSchema/properties`);for(let G of["subjectId","subjectRevision","processCommand"]){if(J[G]===void 0)continue;let H=h(J[G],`${V}/output/${G}`,128);(!un.test(H)||!Object.prototype.hasOwnProperty.call(_e,H))&&d("NATIVE_WORKFLOW_NAMED_OPERATION_OUTPUT_INVALID",`${V}/output/${G}`)}return{operationCode:k,method:"POST",path:M.path,requiredCapability:M.requiredCapability,requestSchemaDigest:M.requestSchemaDigest,responseSchemaDigest:M.responseSchemaDigest,inputs:B,output:{...J},fieldCodes:U}},A=a.create===void 0?void 0:_(a.create,"create"),N=a.existing===void 0?void 0:_(a.existing,"existing");!A&&!N&&d("NATIVE_WORKFLOW_NAMED_OPERATION_SUBMISSION_INVALID",`${n}/submission`);let m=new Set([...A?.fieldCodes||[],...N?.fieldCodes||[]]),T=a.context===void 0?[]:R(a.context,`${n}/submission/context`,16),C=new Set,$=T.map((g,D)=>{let V=`${n}/submission/context/${D}`,x=I(g,V);O(x,["queryParameter","fieldCode"],V);let k=h(x.queryParameter,`${V}/queryParameter`,64),Y=W(x.fieldCode,`${V}/fieldCode`);return(!/^[A-Za-z][A-Za-z0-9]{0,63}$/.test(k)||C.has(k)||!m.has(Y))&&d("NATIVE_WORKFLOW_LAUNCH_CONTEXT_INVALID",V),C.add(k),{queryParameter:k,fieldCode:Y}}),b=g=>{let{fieldCodes:D,...V}=g;return V};return{mode:r.mode,submission:{kind:"named-operation",...A?{create:b(A)}:{},...N?{existing:b(N)}:{},context:$}}}function xn(e,t){let o=I(e,t);O(o,["desktop","mobile"],t);let n=w(o.desktop,`${t}/desktop`),s=w(o.mobile,`${t}/mobile`);return n===s&&d("NATIVE_WORKFLOW_DETAIL_ROUTE_DUPLICATE",t),{desktop:n,mobile:s}}function Gs(e,t){let o=new Set(t.map(p=>p.code)),n=new Map;e.data.resources.forEach((p,l)=>{let u=`/config/data/resources/${l}`,E=I(p,u);for(let[N,m]of Object.entries(E.fieldPolicies||{})){if(!ye(N))continue;let T=`${u}/fieldPolicies/${N}/read`,C=I(m,`${u}/fieldPolicies/${N}`);for(let $ of F(C.read||[],T,2e3))o.has($)||d("NATIVE_CAPABILITY_REFERENCE_MISSING",T)}if(((E.surface===void 0?{}:I(E.surface,`${u}/surface`)).mutationOwner||"native")==="native")return;let A=I(E.capabilities,`${u}/capabilities`);for(let N of["create","update","delete"])n.set(String(A[N]),N)});let s=new Set;for(let[p,l]of e.authz.roles.entries()){let u=`/config/authz/roles/${p}`,E=I(l,u);O(E,["code","name","description","capabilities"],u,!0);let _=w(E.code,`${u}/code`);s.has(_)&&d("NATIVE_ROLE_DUPLICATE",`${u}/code`),s.add(_),h(E.name,`${u}/name`,255);let A=F(E.capabilities,`${u}/capabilities`,2e3);for(let[N,m]of A.entries())n.has(m)&&d("NATIVE_DATA_SURFACE_MUTATION_GRANT_FORBIDDEN",`${u}/capabilities/${N}`,{operation:n.get(m)}),o.has(m)||d("NATIVE_CAPABILITY_REFERENCE_MISSING",`${u}/capabilities`)}let r=e.authz.authenticatedUserRoleCode===void 0?"":w(e.authz.authenticatedUserRoleCode,"/config/authz/authenticatedUserRoleCode");r&&!s.has(r)&&d("NATIVE_AUTHENTICATED_USER_ROLE_REFERENCE_MISSING","/config/authz/authenticatedUserRoleCode");let a=new Set,i=0;for(let[p,l]of e.perspectives.entries()){let u=`/config/perspectives/${p}`,E=I(l,u);O(E,["code","name","description","roleCodes","capabilityCodes","default"],u,!0);let _=w(E.code,`${u}/code`);a.has(_)&&d("NATIVE_PERSPECTIVE_DUPLICATE",`${u}/code`),a.add(_),h(E.name,`${u}/name`,255);let A=F(E.roleCodes,`${u}/roleCodes`,20);A.length<1&&d("NATIVE_PERSPECTIVE_ROLE_REQUIRED",`${u}/roleCodes`),A.forEach((T,C)=>{s.has(T)||d("NATIVE_PERSPECTIVE_ROLE_MISSING",`${u}/roleCodes/${C}`)});let N=j(e.authz.roles.filter(T=>A.includes(T.code)).flatMap(T=>T.capabilities)),m=F(E.capabilityCodes,`${u}/capabilityCodes`,2e3);Q(N)!==Q(m)&&d("NATIVE_PERSPECTIVE_CAPABILITY_PROJECTION_MISMATCH",`${u}/capabilityCodes`),E.default===!0?i+=1:E.default!==void 0&&d("NATIVE_PERSPECTIVE_DEFAULT_INVALID",`${u}/default`)}i>1&&d("NATIVE_PERSPECTIVE_DEFAULT_DUPLICATE","/config/perspectives");for(let[p,l]of e.backend.operations.entries()){let u=I(l,`/config/backend/operations/${p}`);o.has(u.capability)||d("NATIVE_CAPABILITY_REFERENCE_MISSING",`/config/backend/operations/${p}/capability`)}let c=new Set,f=new Set;for(let[p,l]of e.frontend.routes.entries()){let u=`/config/frontend/routes/${p}`,E=I(l,u),_=w(E.code,`${u}/code`);c.has(_)&&d("NATIVE_ROUTE_DUPLICATE",`${u}/code`),c.add(_);let A=re(E.path,`${u}/path`);f.has(A)&&d("NATIVE_ROUTE_PATH_DUPLICATE",`${u}/path`),f.add(A);let N=St(E,u,e.appCode);N.capability&&!o.has(N.capability)&&d("NATIVE_CAPABILITY_REFERENCE_MISSING",`${u}/capability`);let m=E.access===void 0?void 0:I(E.access,`${u}/access`);for(let T of["allOf","anyOf"]){let C=m?.[T]===void 0?[]:R(m[T],`${u}/access/${T}`,50);for(let[$,b]of C.entries()){let g=Ee(b,`${u}/access/${T}/${$}`,e.appCode);o.has(g)||d("NATIVE_CAPABILITY_REFERENCE_MISSING",`${u}/access/${T}/${$}`)}}}if(e.frontend.admin.access!==void 0){let p=Qe(e.frontend.admin.access,"/config/frontend/admin/access",e.appCode);for(let l of["allOf","anyOf"])for(let[u,E]of(p[l]||[]).entries())o.has(E)||d("NATIVE_CAPABILITY_REFERENCE_MISSING",`/config/frontend/admin/access/${l}/${u}`)}for(let[p,l]of e.frontend.routes.entries()){let u=I(l,`/config/frontend/routes/${p}`);u.parentCode&&!c.has(u.parentCode)&&d("NATIVE_ROUTE_PARENT_MISSING",`/config/frontend/routes/${p}/parentCode`)}}function zs(e){let t=new Set(e.authz.roles.map(f=>String(f.code))),o=e.authz.authenticatedUserRoleCode===void 0?"":w(e.authz.authenticatedUserRoleCode,"/config/authz/authenticatedUserRoleCode"),n=new Map(e.authz.scopeDimensions.map(f=>[String(f.code),{valueType:f.valueType==="uuid"?"uuid":"string",...f.valueSource?.resourceCode?{valueSourceResourceCode:String(f.valueSource.resourceCode)}:{}}])),s=new Set(n.keys()),r=new Map(e.data.resources.map((f,p)=>{let l=be(f,`/config/data/resources/${p}`,e.appCode);return[l.code,new Map(l.schema.fields.map(u=>[String(u.code),u]))]}));for(let[f,p]of e.authz.scopeDimensions.entries()){let l=`/config/authz/scopeDimensions/${f}`,u=I(p,l);if(O(u,["code","name","resourceCode","valueType","hierarchyMode","valueSource"],l,!0),u.valueSource===void 0)continue;let E=I(u.valueSource,`${l}/valueSource`);O(E,["kind","resourceCode","labelField","enabledField"],`${l}/valueSource`,!0),E.kind!=="native_resource"&&d("NATIVE_SCOPE_VALUE_SOURCE_KIND_INVALID",`${l}/valueSource/kind`),u.valueType!=="uuid"&&d("NATIVE_SCOPE_VALUE_SOURCE_TYPE_INVALID",`${l}/valueType`);let _=z(E.resourceCode,`${l}/valueSource/resourceCode`),A=r.get(_);A||d("NATIVE_SCOPE_VALUE_SOURCE_RESOURCE_MISSING",`${l}/valueSource/resourceCode`);let N=W(E.labelField,`${l}/valueSource/labelField`);if(["text.short","text.long"].includes(String(A.get(N)?.type||""))||d("NATIVE_SCOPE_VALUE_SOURCE_LABEL_FIELD_INVALID",`${l}/valueSource/labelField`),E.enabledField!==void 0){let m=W(E.enabledField,`${l}/valueSource/enabledField`);A.get(m)?.type!=="boolean"&&d("NATIVE_SCOPE_VALUE_SOURCE_ENABLED_FIELD_INVALID",`${l}/valueSource/enabledField`)}}let a=new Set,i=new Set;for(let[f,p]of e.authz.scopeSources.entries()){let l=`/config/authz/scopeSources/${f}`,u=I(p,l);O(u,["code","name","resourceCode","subject","grants","operationField","enabledField","effectiveFromField","effectiveToField","failureMode"],l,!0);let E=w(u.code,`${l}/code`);a.has(E)&&d("NATIVE_SCOPE_SOURCE_DUPLICATE",`${l}/code`),a.add(E),h(u.name,`${l}/name`,255);let _=z(u.resourceCode,`${l}/resourceCode`),A=r.get(_);A||d("NATIVE_SCOPE_SOURCE_RESOURCE_MISSING",`${l}/resourceCode`);let N=I(u.subject,`${l}/subject`),m=h(N.type,`${l}/subject/type`,32);O(N,m==="role_membership"?["type","userIdField","roleCode"]:["type","userIdField"],`${l}/subject`),["user","role_membership"].includes(m)||d("NATIVE_SCOPE_SOURCE_SUBJECT_INVALID",`${l}/subject/type`);let T=Fe(N.userIdField,A);At(T)||d("NATIVE_SCOPE_SOURCE_SUBJECT_PATH_INVALID",`${l}/subject/userIdField`),m==="role_membership"&&!t.has(String(N.roleCode))&&d("NATIVE_ROLE_REFERENCE_MISSING",`${l}/subject/roleCode`);let C=new Set;for(let[$,b]of R(u.grants,`${l}/grants`,100).entries()){let g=`${l}/grants/${$}`,D=I(b,g);O(D,["dimensionCode","valueField","parentValueField"],g,!0);let V=w(D.dimensionCode,`${g}/dimensionCode`);(!s.has(V)||C.has(V))&&d("NATIVE_SCOPE_SOURCE_DIMENSION_INVALID",`${g}/dimensionCode`),C.add(V),u.failureMode==="last_known_good"&&i.add(V);for(let x of["valueField","parentValueField"]){if(D[x]===void 0)continue;let k=Fe(D[x],A);en(k,n.get(V),r)||d("NATIVE_SCOPE_SOURCE_GRANT_PATH_INVALID",`${g}/${x}`)}}C.size===0&&d("NATIVE_SCOPE_SOURCE_GRANT_REQUIRED",`${l}/grants`),["strict","last_known_good"].includes(u.failureMode)||d("NATIVE_SCOPE_SOURCE_FAILURE_MODE_INVALID",`${l}/failureMode`);for(let $ of["operationField","enabledField","effectiveFromField","effectiveToField"]){if(u[$]===void 0)continue;let b=W(u[$],`${l}/${$}`);A.has(b)||d("NATIVE_SCOPE_SOURCE_FIELD_MISSING",`${l}/${$}`)}}qs(e,t,r,o);let c=new Set;for(let[f,p]of e.authz.dataPolicies.entries()){let l=`/config/authz/dataPolicies/${f}`,u=I(p,l);O(u,["code","name","resourceCode","unrestrictedRoleCodes","operations","matchMode","rules","readExpression","writeBoundary"],l,!0);let E=w(u.code,`${l}/code`);c.has(E)&&d("NATIVE_DATA_POLICY_DUPLICATE",`${l}/code`),c.add(E);let _=u.readExpression!==void 0,A=F(u.operations||[],`${l}/operations`,4);u.operations!==void 0&&(A.length===0||A.some(b=>!["read","create","update","delete"].includes(b)))&&d("NATIVE_DATA_POLICY_OPERATIONS_INVALID",`${l}/operations`),["AND","OR"].includes(u.matchMode)||d("NATIVE_DATA_POLICY_MATCH_MODE_INVALID",`${l}/matchMode`),_&&u.operations!==void 0&&d("NATIVE_DATA_POLICY_READ_EXPRESSION_OPERATIONS_FORBIDDEN",`${l}/operations`);let N=e.data.resources.find(b=>b.dataPolicyCode===E),m=u.resourceCode||N?.code,T=m?r.get(z(m,`${l}/resourceCode`)):void 0;_&&!T&&d("NATIVE_DATA_POLICY_RESOURCE_MISSING",`${l}/resourceCode`);let C=F(u.unrestrictedRoleCodes||[],`${l}/unrestrictedRoleCodes`,100);u.unrestrictedRoleCodes!==void 0&&C.length===0&&d("NATIVE_DATA_POLICY_UNRESTRICTED_ROLES_INVALID",`${l}/unrestrictedRoleCodes`);for(let b of C)t.has(b)||d("NATIVE_ROLE_REFERENCE_MISSING",`${l}/unrestrictedRoleCodes`);let $;try{let b=R(u.rules,`${l}/rules`,100).map((g,D)=>({rule:I(g,`${l}/rules/${D}`),pointer:`${l}/rules/${D}`}));b.length===0?(!_||u.matchMode!=="AND"||u.writeBoundary!=="capability_only")&&d("NATIVE_DATA_POLICY_WRITE_BOUNDARY_REQUIRED",l):u.writeBoundary!==void 0&&d("NATIVE_DATA_POLICY_WRITE_BOUNDARY_INVALID",`${l}/writeBoundary`),$=[...b],_&&($.push(...Ye(u.readExpression,`${l}/readExpression`)),cn(u.readExpression,`${l}/readExpression`))}catch(b){throw b instanceof ve&&d(b.code,b.pointer),b}for(let{rule:b,pointer:g}of $){O(b,["subject","dimensionCode","relationCode","resourceCode","field","roleCodes","operation","valuePath","emptyMatchesAll","operator","value","operand"],g,!0);let D=W(b.field,`${g}/field`),V=T?.get(D);_&&!V&&d("NATIVE_DATA_POLICY_FIELD_MISSING",`${g}/field`);for(let K of F(b.roleCodes||[],`${g}/roleCodes`,100))t.has(K)||d("NATIVE_ROLE_REFERENCE_MISSING",`${g}/roleCodes`);let x=String(b.operator||""),k=b.operand==="db_now",Y=["is_null","is_not_null"].includes(x),M=["eq","not_eq","in","not_in"].includes(x),ae=!k&&(b.operator!==void 0||b.value!==void 0);if([b.subject==="current_user"?"current_user":"",typeof b.dimensionCode=="string"?"dimension":"",typeof b.relationCode=="string"?"relationship":"",ae?"constant":"",k?"db_now":""].filter(Boolean).length!==1&&d("NATIVE_DATA_POLICY_RULE_SOURCE_INVALID",g),b.subject!==void 0&&b.subject!=="current_user"&&d("NATIVE_DATA_POLICY_SUBJECT_INVALID",`${g}/subject`),ae){if(!M&&!Y&&d("NATIVE_DATA_POLICY_OPERATOR_INVALID",`${g}/operator`),["in","not_in"].includes(x)){let K=R(b.value,`${g}/value`,100).map((fe,oe)=>h(fe,`${g}/value/${oe}`,2048));(K.length===0||new Set(K).size!==K.length)&&d("NATIVE_DATA_POLICY_VALUE_INVALID",`${g}/value`)}else["eq","not_eq"].includes(x)?h(b.value,`${g}/value`,2048):(b.value!==void 0||b.operand!==void 0)&&d("NATIVE_DATA_POLICY_VALUE_INVALID",`${g}/value`);for(let K of["operation","valuePath","emptyMatchesAll","resourceCode","operand"])b[K]!==void 0&&d("NATIVE_DATA_POLICY_CONSTANT_RULE_INVALID",`${g}/${K}`)}if(k){(!["lt","lte","gt","gte"].includes(x)||b.value!==void 0||V?.type!=="datetime")&&d("NATIVE_DATA_POLICY_DB_NOW_INVALID",g);for(let K of["operation","valuePath","emptyMatchesAll","resourceCode","value"])b[K]!==void 0&&d("NATIVE_DATA_POLICY_DB_NOW_INVALID",`${g}/${K}`)}b.dimensionCode&&!s.has(b.dimensionCode)&&d("NATIVE_SCOPE_DIMENSION_MISSING",`${g}/dimensionCode`),i.has(String(b.dimensionCode||""))&&b.operation!=="read"&&d("NATIVE_SCOPE_SOURCE_LAST_KNOWN_GOOD_UNSAFE",`${g}/operation`)}}for(let[f,p]of e.data.resources.entries()){let l=I(p,`/config/data/resources/${f}`);l.dataPolicyCode&&!c.has(l.dataPolicyCode)&&d("NATIVE_DATA_POLICY_REFERENCE_MISSING",`/config/data/resources/${f}/dataPolicyCode`)}}function Ys(e){try{kt(e.data.resources,"/config/data/resources")}catch(t){throw t instanceof Ae&&d(t.code,t.pointer),t}}function qs(e,t,o,n){let s=new Set;for(let[r,a]of e.authz.roleMembershipSources.entries()){let i=`/config/authz/roleMembershipSources/${r}`,c=I(a,i);O(c,["code","name","resourceCode","userIdField","roleCode","enabledField","effectiveFromField","effectiveToField","failureMode"],i,!0);let f=w(c.code,`${i}/code`);f.length>100&&d("NATIVE_AUTHORIZATION_PROJECTION_SOURCE_CODE_INVALID",`${i}/code`),s.has(f)&&d("NATIVE_AUTHORIZATION_PROJECTION_SOURCE_DUPLICATE",`${i}/code`),s.add(f),h(c.name,`${i}/name`,255);let p=Nn(c.resourceCode,`${i}/resourceCode`,o);Tn(c.userIdField,`${i}/userIdField`,p),t.has(String(c.roleCode||""))||d("NATIVE_ROLE_REFERENCE_MISSING",`${i}/roleCode`),n&&c.roleCode===n&&d("NATIVE_AUTHENTICATED_USER_ROLE_SOURCE_CONFLICT",`${i}/roleCode`),gn(c,i,p)}for(let[r,a]of e.authz.relationshipGrantSources.entries()){let i=`/config/authz/relationshipGrantSources/${r}`,c=I(a,i);O(c,["code","name","resourceCode","subject","relationCode","targetResourceCode","resourceIdField","operations","enabledField","effectiveFromField","effectiveToField","failureMode"],i,!0);let f=w(c.code,`${i}/code`);f.length>100&&d("NATIVE_AUTHORIZATION_PROJECTION_SOURCE_CODE_INVALID",`${i}/code`),s.has(f)&&d("NATIVE_AUTHORIZATION_PROJECTION_SOURCE_DUPLICATE",`${i}/code`),s.add(f),h(c.name,`${i}/name`,255);let p=Nn(c.resourceCode,`${i}/resourceCode`,o),l=I(c.subject,`${i}/subject`),u=h(l.type,`${i}/subject/type`,32);O(l,u==="role_membership"?["type","userIdField","roleCode"]:["type","userIdField"],`${i}/subject`),["user","role_membership"].includes(u)||d("NATIVE_AUTHORIZATION_PROJECTION_SUBJECT_INVALID",`${i}/subject/type`),Tn(l.userIdField,`${i}/subject/userIdField`,p),u==="role_membership"&&!t.has(String(l.roleCode||""))&&d("NATIVE_ROLE_REFERENCE_MISSING",`${i}/subject/roleCode`),w(c.relationCode,`${i}/relationCode`);let E=z(c.targetResourceCode,`${i}/targetResourceCode`);o.has(E)||d("NATIVE_AUTHORIZATION_PROJECTION_TARGET_RESOURCE_MISSING",`${i}/targetResourceCode`);let _=Fe(c.resourceIdField,p),A=_?.field.type==="resource-ref.single"&&_.valuePath==="value"&&_.field.source?.resourceCode===E;(c.resourceIdField==="id"?E!==String(c.resourceCode):!A)&&d("NATIVE_AUTHORIZATION_PROJECTION_RESOURCE_ID_FIELD_INVALID",`${i}/resourceIdField`);let N=F(c.operations,`${i}/operations`,20);(N.length===0||N.some(m=>m.length>64||!/^[A-Za-z0-9][A-Za-z0-9:._*-]{0,63}$/.test(m)))&&d("NATIVE_AUTHORIZATION_PROJECTION_OPERATIONS_INVALID",`${i}/operations`),gn(c,i,p)}}function Nn(e,t,o){let n=z(e,t),s=o.get(n);return s||d("NATIVE_AUTHORIZATION_PROJECTION_RESOURCE_MISSING",t),s}function Tn(e,t,o){let n=Fe(e,o);At(n)||d("NATIVE_AUTHORIZATION_PROJECTION_USER_FIELD_INVALID",t)}function gn(e,t,o){if(e.failureMode!=="strict"&&d("NATIVE_AUTHORIZATION_PROJECTION_FAILURE_MODE_INVALID",`${t}/failureMode`),e.enabledField!==void 0){let n=W(e.enabledField,`${t}/enabledField`);o.get(n)?.type!=="boolean"&&d("NATIVE_AUTHORIZATION_PROJECTION_ENABLED_FIELD_INVALID",`${t}/enabledField`)}for(let n of["effectiveFromField","effectiveToField"]){if(e[n]===void 0)continue;let s=W(e[n],`${t}/${n}`);["date","datetime"].includes(String(o.get(s)?.type))||d("NATIVE_AUTHORIZATION_PROJECTION_EFFECTIVE_FIELD_INVALID",`${t}/${n}`)}}function Ks(e){let t=new Set,o=new Set;e.forEach((n,s)=>{let r=`/config/backend/secrets/${s}`,a=I(n,r);O(a,["name","env","description","required","exposure"],r,!0);let i=h(a.name,`${r}/name`,128),c=h(a.env,`${r}/env`,128);qo.test(i)||d("NATIVE_SECRET_NAME_INVALID",`${r}/name`),(!Ko.test(c)||c.startsWith("OPENXIANGDA_")||["NODE_ENV","PORT"].includes(c))&&d("NATIVE_SECRET_ENV_INVALID",`${r}/env`),t.has(i)&&d("NATIVE_SECRET_NAME_DUPLICATE",`${r}/name`),o.has(c)&&d("NATIVE_SECRET_ENV_DUPLICATE",`${r}/env`),t.add(i),o.add(c),v(a.exposure,"active_only",`${r}/exposure`),a.required!==void 0&&De(a.required,`${r}/required`),a.description!==void 0&&Dt(a.description,`${r}/description`,2e3)})}function Hs(e){let t=new Set,o=new Map,n=new Map(e.data.resources.map(u=>[String(u.code),u])),s=new Map(e.frontend.routes.map((u,E)=>{let _=I(u,`/config/frontend/routes/${E}`);return[w(_.code,`/config/frontend/routes/${E}/code`),_]}));for(let[u,E]of e.workflows.definitions.entries()){let _=`/config/workflows/definitions/${u}`,A=I(E,_);if(O(A,["version","definition","launch"],_,["detailRouteCode"]),Un(A.launch,`${_}/launch`),A.detailRouteCode!==void 0){let C=xn(A.detailRouteCode,`${_}/detailRouteCode`);for(let[$,b,g]of[["desktop",C.desktop,"admin"],["mobile",C.mobile,"user"]]){let D=`${_}/detailRouteCode/${$}`,V=s.get(b);V||d("NATIVE_WORKFLOW_DETAIL_ROUTE_MISSING",D),V.surface!==g&&d("NATIVE_WORKFLOW_DETAIL_ROUTE_SURFACE_INVALID",D);let x=re(V.path,D),k=[...x.matchAll(/:([A-Za-z][A-Za-z0-9_]*)/g)].map(Y=>Y[1]);(x.includes("*")||k.length!==1||k[0]!=="instanceId")&&d("NATIVE_WORKFLOW_DETAIL_ROUTE_PATH_INVALID",D)}}let N=I(A.definition,`${_}/definition`),m=`${N.code}:${Se(A.version,`${_}/version`)}`;t.has(m)&&d("NATIVE_WORKFLOW_DEFINITION_DUPLICATE",_),t.add(m),Qs(N,`${_}/definition`),Xs(N.subject,n,`${_}/definition/subject`);let T=sn(N,{appCode:e.appCode,capabilities:e.authz.capabilities.map(C=>C.code),fields:new Map((n.get(N.subject.resourceCode)?.schema.fields||[]).map(C=>[C.code,C]))});T.length&&d("NATIVE_WORKFLOW_INSTANCE_COMMAND_POLICY_INVALID",`${_}/definition/instanceCommands`,{errors:T}),N.title===N.code&&d("NATIVE_WORKFLOW_USER_TITLE_REQUIRED",`${_}/definition/title`),o.set(m,N)}let r=new Set,a=new Map;for(let[u,E]of e.workflows.bindings.entries()){let _=I(E,`/config/workflows/bindings/${u}`),A=I(_.binding,`/config/workflows/bindings/${u}/binding`),N=`${A.workflowCode}:${Se(_.version,`/config/workflows/bindings/${u}/version`)}`;r.has(N)&&d("NATIVE_WORKFLOW_BINDING_DUPLICATE",`/config/workflows/bindings/${u}`),r.add(N),Zs(A,`/config/workflows/bindings/${u}/binding`),a.set(N,A)}let i=new Set,c=new Map;for(let[u,E]of e.workflows.activations.entries()){let _=`/config/workflows/activations/${u}`,A=I(E,_);O(A,["workflowCode","definitionVersion","bindingVersion","acceptedCommandDeactivationPolicy"],_,["environmentKey"]);let N=w(A.workflowCode,`${_}/workflowCode`);i.has(N)&&d("NATIVE_WORKFLOW_ACTIVATION_DUPLICATE",_),i.add(N);let m=`${N}:${Se(A.definitionVersion,`${_}/definitionVersion`)}`,T=`${N}:${Se(A.bindingVersion,`${_}/bindingVersion`)}`;t.has(m)||d("NATIVE_WORKFLOW_DEFINITION_REFERENCE_MISSING",`${_}/definitionVersion`),r.has(T)||d("NATIVE_WORKFLOW_BINDING_REFERENCE_MISSING",`${_}/bindingVersion`);let C=o.get(m),$=a.get(T);(!["finish-pinned","cancel-on-deactivate"].includes(A.acceptedCommandDeactivationPolicy)||A.acceptedCommandDeactivationPolicy!==C.acceptedCommandDeactivationPolicy)&&d("NATIVE_WORKFLOW_COMMAND_DEACTIVATION_POLICY_MISMATCH",`${_}/acceptedCommandDeactivationPolicy`),ei(C,$,`/config/workflows/activations/${u}`),c.set(N,$)}let f=new Set;e.workflows.providers.forEach((u,E)=>{let _=`/config/workflows/providers/${E}`,A=I(u,_);O(A,["code","endpointPath","timeoutMs"],_,!0);let N=w(A.code,`${_}/code`);f.has(N)&&d("NATIVE_WORKFLOW_PROVIDER_DUPLICATE",`${_}/code`),f.add(N),re(A.endpointPath,`${_}/endpointPath`),A.timeoutMs!==void 0&&Z(A.timeoutMs,`${_}/timeoutMs`,100,1e4)});for(let[u,E]of c.entries())for(let[_,A]of Object.entries(I(E.bindings,"/config/workflows/bindings/*/binding/bindings"))){let N=I(A,`/config/workflows/${u}/bindings/${_}`);N.provider==="application_provider"&&!f.has(N.providerCode)&&d("NATIVE_WORKFLOW_PROVIDER_REFERENCE_MISSING",`/config/workflows/${u}/bindings/${_}/providerCode`)}let p=new Set(e.authz.roles.map(u=>u.code)),l=new Set;e.workflows.editableParameters.forEach((u,E)=>{let _=`/config/workflows/editableParameters/${E}`,A=I(u,_);O(A,["code","workflowCode","bindingKey","label","valueType","required","allowedRoleCodes","allowedProviderCodes","maxItems"],_,!0);let N=w(A.code,`${_}/code`);l.has(N)&&d("NATIVE_WORKFLOW_EDITABLE_PARAMETER_DUPLICATE",`${_}/code`),l.add(N);let m=Ze(A.workflowCode,`${_}/workflowCode`),T=yt(A.bindingKey,`${_}/bindingKey`),C=c.get(m);(!C||!I(C.bindings,`${_}/bindingKey`)[T])&&d("NATIVE_WORKFLOW_EDITABLE_BINDING_MISSING",`${_}/bindingKey`),h(A.label,`${_}/label`,255),["role_code","user_ids","provider_code"].includes(A.valueType)||d("NATIVE_WORKFLOW_EDITABLE_VALUE_TYPE_INVALID",`${_}/valueType`);for(let $ of F(A.allowedRoleCodes||[],`${_}/allowedRoleCodes`,100))p.has($)||d("NATIVE_ROLE_REFERENCE_MISSING",`${_}/allowedRoleCodes`);for(let $ of F(A.allowedProviderCodes||[],`${_}/allowedProviderCodes`,100))f.has($)||d("NATIVE_WORKFLOW_PROVIDER_REFERENCE_MISSING",`${_}/allowedProviderCodes`);A.required!==void 0&&De(A.required,`${_}/required`),A.maxItems!==void 0&&Z(A.maxItems,`${_}/maxItems`,1,200)})}function Xs(e,t,o){let n=I(e,o);O(n,["resourceCode","factProjection"],o,["summaryFields"]);let s=z(n.resourceCode,`${o}/resourceCode`),r=t.get(s);r||d("NATIVE_WORKFLOW_SUBJECT_RESOURCE_MISSING",`${o}/resourceCode`);let a=new Set(R(I(r.schema,`${o}/resourceCode`).fields,`${o}/resourceCode`,500).map((f,p)=>W(I(f,`${o}/resourceCode/${p}`).code,`${o}/resourceCode/${p}`))),i=I(n.factProjection,`${o}/factProjection`),c=Object.entries(i);(c.length<1||c.length>64)&&d("NATIVE_WORKFLOW_SUBJECT_FACT_PROJECTION_INVALID",`${o}/factProjection`);for(let[f,p]of c){Qo.test(f)||d("NATIVE_WORKFLOW_SUBJECT_FACT_KEY_INVALID",`${o}/factProjection/${f}`);let l=W(p,`${o}/factProjection/${f}`);a.has(l)||d("NATIVE_WORKFLOW_SUBJECT_FIELD_MISSING",`${o}/factProjection/${f}`)}if(n.summaryFields!==void 0){let f=F(n.summaryFields,`${o}/summaryFields`,Zo).map((_,A)=>W(_,`${o}/summaryFields/${A}`)),p=t.get(s),l=p.surface&&typeof p.surface=="object"&&!Array.isArray(p.surface)?p.surface:{},u=l.fields&&typeof l.fields=="object"&&!Array.isArray(l.fields)?l.fields:{},E=new Map(R(I(p.schema,`${o}/resourceCode`).fields,`${o}/resourceCode`,500).map((_,A)=>{let N=I(_,`${o}/resourceCode/${A}`);return[String(N.code),N]}));for(let[_,A]of f.entries()){let N=E.get(A),m=u[A],T=String(N?.type||""),C=N?.maxLength;(!N||N.system===!0||m&&typeof m=="object"&&!Array.isArray(m)&&m.system===!0||["id","revision","created_by","updated_by","created_at","updated_at"].includes(A)||!ts.has(T)||T==="text.long"&&typeof C=="number"&&Number.isFinite(C)&&C>es)&&d("NATIVE_WORKFLOW_SUBJECT_SUMMARY_FIELDS_INVALID",`${o}/summaryFields/${_}`)}}}function Qs(e,t){O(e,["schemaVersion","code","title","subject","acceptedCommandDeactivationPolicy","startAt","inputSchema","nodes"],t,["organizationContext","instanceCommands"]),v(e.schemaVersion,"openxiangda.workflow-definition/v2",`${t}/schemaVersion`),Ze(e.code,`${t}/code`),h(e.title,`${t}/title`,255),["finish-pinned","cancel-on-deactivate"].includes(e.acceptedCommandDeactivationPolicy)||d("NATIVE_WORKFLOW_COMMAND_DEACTIVATION_POLICY_REQUIRED",`${t}/acceptedCommandDeactivationPolicy`);let o=I(e.nodes,`${t}/nodes`),n=Object.keys(o);(n.length===0||n.length>200)&&d("NATIVE_WORKFLOW_NODE_COUNT_INVALID",`${t}/nodes`);let s=h(e.startAt,`${t}/startAt`,128);o[s]||d("NATIVE_WORKFLOW_START_NODE_MISSING",`${t}/startAt`);let r=new Map;for(let[f,p]of Object.entries(o)){let l=`${t}/nodes/${f}`,u=I(p,l);v(u.id,f,`${l}/id`),["approval","condition","end"].includes(u.kind)||d("NATIVE_WORKFLOW_NODE_KIND_INVALID",`${l}/kind`);let E=[];if(u.kind==="approval"){h(u.title,`${l}/title`,255),yt(u.binding,`${l}/binding`),["single","any","all","sequence"].includes(u.mode)||d("NATIVE_WORKFLOW_APPROVAL_MODE_INVALID",`${l}/mode`),E.push(h(u.onApprove,`${l}/onApprove`,128),h(u.onReject,`${l}/onReject`,128));for(let _ of F(u.returnTargets||[],`${l}/returnTargets`,200))o[_]||d("NATIVE_WORKFLOW_TARGET_MISSING",`${l}/returnTargets`);for(let _ of F(u.allowedOperations||[],`${l}/allowedOperations`,20))os.has(_)||d("NATIVE_WORKFLOW_OPERATION_INVALID",`${l}/allowedOperations`)}else if(u.kind==="condition"){let _=R(u.branches,`${l}/branches`,100);_.length===0&&d("NATIVE_WORKFLOW_BRANCH_REQUIRED",`${l}/branches`),_.forEach((A,N)=>{let m=I(A,`${l}/branches/${N}`);ke(m.when,`${l}/branches/${N}/when`,0),E.push(h(m.target,`${l}/branches/${N}/target`,128))}),E.push(h(u.otherwise,`${l}/otherwise`,128))}else h(u.title,`${l}/title`,255),h(u.outcome,`${l}/outcome`,128);for(let _ of E)o[_]||d("NATIVE_WORKFLOW_TARGET_MISSING",l);r.set(f,E)}let a=new Set,i=new Set,c=f=>{if(i.has(f)&&d("NATIVE_WORKFLOW_CYCLE_FORBIDDEN",`${t}/nodes/${f}`),!a.has(f)){a.add(f),i.add(f);for(let p of r.get(f)||[])c(p);i.delete(f)}};c(s),a.size!==n.length&&d("NATIVE_WORKFLOW_NODE_UNREACHABLE",`${t}/nodes`)}function ke(e,t,o){o>20&&d("NATIVE_WORKFLOW_EXPRESSION_DEPTH_EXCEEDED",t);let n=I(e,t),s=h(n.op,`${t}/op`,16);if(s!=="literal"){if(s==="path"){let r=h(n.path,`${t}/path`,255);/^[A-Za-z][A-Za-z0-9_.]{0,254}$/.test(r)||d("NATIVE_WORKFLOW_EXPRESSION_PATH_INVALID",`${t}/path`);return}if(["eq","neq","gt","gte","lt","lte","in","contains"].includes(s)){ke(n.left,`${t}/left`,o+1),ke(n.right,`${t}/right`,o+1);return}if(["and","or"].includes(s)){let r=R(n.values,`${t}/values`,100);r.length===0&&d("NATIVE_WORKFLOW_EXPRESSION_EMPTY",`${t}/values`),r.forEach((a,i)=>ke(a,`${t}/values/${i}`,o+1));return}if(["not","exists"].includes(s)){ke(n.value,`${t}/value`,o+1);return}d("NATIVE_WORKFLOW_EXPRESSION_OPERATOR_INVALID",`${t}/op`)}}function Zs(e,t){v(e.schemaVersion,"openxiangda.workflow-binding/v2",`${t}/schemaVersion`),Ze(e.workflowCode,`${t}/workflowCode`);let o=I(e.bindings,`${t}/bindings`);Object.keys(o).length>200&&d("NATIVE_WORKFLOW_BINDING_LIMIT_EXCEEDED",`${t}/bindings`);for(let[n,s]of Object.entries(o)){yt(n,`${t}/bindings/${n}`);let r=I(s,`${t}/bindings/${n}`),a=h(r.provider,`${t}/bindings/${n}/provider`,64);["fixed_users","initiator","input_users","form_field_users","department_supervisor","app_role","app_role_in_scope","business_relation","previous_node_actor","initiator_select","application_provider"].includes(a)||d("NATIVE_WORKFLOW_BINDING_PROVIDER_INVALID",`${t}/bindings/${n}/provider`),a==="fixed_users"&&R(r.users,`${t}/bindings/${n}/users`,200).length===0&&d("NATIVE_WORKFLOW_BINDING_USERS_REQUIRED",`${t}/bindings/${n}/users`),["input_users","form_field_users"].includes(a)&&h(r.inputPath,`${t}/bindings/${n}/inputPath`,255),["app_role","app_role_in_scope","initiator_select"].includes(a)&&w(r.roleCode,`${t}/bindings/${n}/roleCode`),a==="department_supervisor"&&h(r.departmentIdFrom,`${t}/bindings/${n}/departmentIdFrom`,255),a==="application_provider"&&w(r.providerCode,`${t}/bindings/${n}/providerCode`)}}function ei(e,t,o){v(t.workflowCode,e.code,`${o}/workflowCode`);let n=I(t.bindings,`${o}/bindings`);for(let[s,r]of Object.entries(I(e.nodes,`${o}/nodes`))){let a=I(r,`${o}/nodes/${s}`);a.kind==="approval"&&!n[a.binding]&&d("NATIVE_WORKFLOW_BINDING_REFERENCE_MISSING",`${o}/nodes/${s}/binding`)}}function ti(e,t,o){let n=I(t.routeManifest,"/contracts/routeManifest"),s=I(e.routeManifest,"/contracts/routeManifest"),r=new Map;for(let p of R(o.data?.resources,"/config/data/resources",100)){let l=I(p,"/config/data/resources");r.set(String(l.code||""),l)}let a=new Set(R(s.routes,"/contracts/routeManifest/routes",1e3).map(p=>String(I(p,"/contracts/routeManifest/routes").code||""))),i=[];for(let p of R(n.routes,"/contracts/routeManifest/routes",1e3)){let l=I(p,"/contracts/routeManifest/routes"),u=String(l.kind||"");if(u!=="resource-records"&&u!=="resource-submit")continue;let E=String(l.resourceCode||""),_=r.get(E);_||d("NATIVE_ROUTE_MANIFEST_RESOURCE_UNKNOWN","/contracts/routeManifest/routes");let N=`user.${E}.${u==="resource-records"?"records":"submit"}`;v(String(l.code||""),N,"/contracts/routeManifest/routes/code");let m=u==="resource-records"?"read":"create",T=String(I(_.capabilities,"/config/data/resources/capabilities")[m]||"");for(let C of["desktop","mobile"]){let $=I(l[C],`/contracts/routeManifest/routes/${C}`),b=C==="mobile"?"/m/my/":"/my/",g=u==="resource-records"?`${b}${E}`:`${b}${E}/submit`;v(String($.path||""),g,`/contracts/routeManifest/routes/${C}/path`),v(String($.capability||""),T,`/contracts/routeManifest/routes/${C}/capability`),v(String($.routeCode||""),`${N}.${C}`,`/contracts/routeManifest/routes/${C}/routeCode`)}(a.has(N)||i.some(C=>String(C.code)===N))&&d("NATIVE_ROUTE_MANIFEST_DUPLICATE","/contracts/routeManifest/routes/code"),i.push(l)}if(!i.length)return;s.routes=R([...s.routes,...i],"/contracts/routeManifest/routes",1e3).sort((p,l)=>ie(String(I(p,"x").code||""),String(I(l,"x").code||"")));let c=String(I(n.rootEntry,"x").code||"");if(i.find(p=>String(p.code)===c&&p.kind==="resource-records")){let p=I(n.rootEntry,"x");s.rootEntry={code:c,desktop:String(p.desktop||""),mobile:String(p.mobile||"")}}s.digest=ee({schemaVersion:s.schemaVersion,appCode:s.appCode,devicePolicy:s.devicePolicy,rootEntry:s.rootEntry,authentication:s.authentication,routes:s.routes})}function be(e,t,o){let n=I(e,t);O(n,["schemaVersion","appCode","code","name","schema","surface","invariants","capabilities","dataPolicyCode","fieldPolicies"],t,!0),v(n.schemaVersion,"openxiangda.data-resource/v2",`${t}/schemaVersion`),v(n.appCode,o,`${t}/appCode`);let s=z(n.code,`${t}/code`),r=h(n.name,`${t}/name`,255),a=I(n.schema,`${t}/schema`);O(a,["fields"],`${t}/schema`);let i,c;try{i=it(a.fields,`${t}/schema/fields`),c=Ut(n.invariants,i,`${t}/invariants`),ft(n.surface,i,`${t}/surface`)}catch(u){throw u instanceof Ae&&d(u.code,u.pointer),u}let f=new Set(i.map(u=>u.code)),p=I(n.capabilities,`${t}/capabilities`);O(p,["read","create","update","delete"],`${t}/capabilities`);let l=I(n.fieldPolicies,`${t}/fieldPolicies`);for(let[u,E]of Object.entries(l)){!f.has(u)&&!ye(u)&&d("NATIVE_DATA_FIELD_POLICY_FIELD_MISSING",`${t}/fieldPolicies/${u}`);let _=`${t}/fieldPolicies/${u}`,A=I(E,_);ye(u)&&(O(A,["read"],_,!0),(!Array.isArray(A.read)||A.read.length>20||A.read.some(N=>typeof N!="string"||!N.trim())||new Set(A.read).size!==A.read.length)&&d("NATIVE_DATA_AUDIT_READ_POLICY_INVALID",`${_}/read`)),O(A,["read","create","update","mask"],_,!0),A.mask!==void 0&&!["omit","null"].includes(A.mask)&&d("NATIVE_DATA_FIELD_POLICY_MASK_INVALID",`${_}/mask`)}return{...n,code:s,name:r,schema:{fields:i},...n.invariants===void 0?{}:{invariants:c},capabilities:p,fieldPolicies:l}}function Mn(e){return[{code:`app:${e}:directory:read`,kind:"platform",name:"\u8BFB\u53D6\u53D7\u9650\u7EC4\u7EC7\u76EE\u5F55",source:"platform"},...[["app:role:read","\u67E5\u770B\u89D2\u8272\u4E0E\u6388\u6743"],["app:role:define","\u5B9A\u4E49\u624B\u5DE5\u89D2\u8272"],["app:role:assign","\u5206\u914D\u89D2\u8272\u6210\u5458"],["app:role:grant-capability","\u6388\u4E88\u89D2\u8272\u80FD\u529B"],["app:scope-grant:manage","\u7BA1\u7406\u6570\u636E\u8303\u56F4"],["app:super-admin:manage","\u7BA1\u7406\u5E94\u7528\u6700\u9AD8\u7BA1\u7406\u5458"]].map(([t,o])=>({code:t,kind:"platform",name:o,source:"platform"}))]}function bn(e,t,o,n){let s=e.toString("utf8"),r;try{r=JSON.parse(s)}catch{d(o,t)}let a=I(r,t);return Q(a)!==s&&d(n,t),a}function Cn(e,t){let o=0,n=(s,r,a)=>{if(o+=1,o>as&&d("NATIVE_ARTIFACT_NODE_LIMIT_EXCEEDED",r),a>rs&&d("NATIVE_ARTIFACT_DEPTH_LIMIT_EXCEEDED",r),typeof s=="string"){Buffer.byteLength(s)>Tt&&d("NATIVE_ARTIFACT_STRING_LIMIT_EXCEEDED",r);return}if(Array.isArray(s)){s.forEach((i,c)=>n(i,`${r}/${c}`,a+1));return}if(!(!s||typeof s!="object"))for(let[i,c]of Object.entries(s))["__proto__","prototype","constructor"].includes(i)&&d("NATIVE_ARTIFACT_DANGEROUS_KEY",`${r}/${i}`),ni(i)&&d("NATIVE_ARTIFACT_RUNTIME_FIELD_FORBIDDEN",`${r}/${i}`),n(c,`${r}/${i}`,a+1)};n(e,t,0)}function ni(e){return["environmentKey","environmentId","secretValue","ciphertext","oauthClient","oauthClientId","oauthClientSecret","signingSecret","kubernetesNamespace","nodePort","productionUrl"].includes(e)}function he(e){return{value:e,digest:ee(e)}}function On(e,t,o,n){typeof e!="string"&&!Buffer.isBuffer(e)&&!(e instanceof Uint8Array)&&d("NATIVE_ARTIFACT_BYTES_REQUIRED",o);let s=Buffer.isBuffer(e)?e:Buffer.from(e);return s.byteLength===0&&d("NATIVE_ARTIFACT_EMPTY",o),s.byteLength>t&&d(n,o),s}function $n(e,t,o,n){let s=He.createHash("sha256").update(e).digest("hex");He.timingSafeEqual(Buffer.from(s),Buffer.from(t))||d(n,o)}function I(e,t){return(!e||typeof e!="object"||Array.isArray(e))&&d("NATIVE_OBJECT_REQUIRED",t),e}function R(e,t,o){return Array.isArray(e)||d("NATIVE_ARRAY_REQUIRED",t),e.length>o&&d("NATIVE_ARRAY_LIMIT_EXCEEDED",t),e}function F(e,t,o){let n=R(e,t,o).map((s,r)=>h(s,`${t}/${r}`,255));return new Set(n).size!==n.length&&d("NATIVE_ARRAY_DUPLICATE",t),n}function h(e,t,o){return(typeof e!="string"||e.length===0||e.length>o)&&d("NATIVE_STRING_INVALID",t),e}function Dt(e,t,o){return(typeof e!="string"||e.length>o)&&d("NATIVE_STRING_INVALID",t),e}function w(e,t){let o=h(e,t,128);return Wo.test(o)||d("NATIVE_CODE_INVALID",t),o}function z(e,t){let o=h(e,t,64);return zo.test(o)||d("NATIVE_RESOURCE_CODE_INVALID",t),o}function W(e,t){let o=h(e,t,63);return Yo.test(o)||d("NATIVE_FIELD_CODE_INVALID",t),o}function Ze(e,t){let o=h(e,t,128);return Ho.test(o)||d("NATIVE_WORKFLOW_CODE_INVALID",t),o}function yt(e,t){let o=h(e,t,128);return Xo.test(o)||d("NATIVE_WORKFLOW_BINDING_CODE_INVALID",t),o}function Ee(e,t,o){let n=h(e,t,255);return Jo.test(n)||d("NATIVE_CAPABILITY_CODE_INVALID",t),!n.startsWith(`app:${o}:`)&&!Mn(o).some(s=>s.code===n)&&d("NATIVE_CAPABILITY_APP_MISMATCH",t),n}function re(e,t){let o=h(e,t,2048);return(!o.startsWith("/")||o.startsWith("//")||o.includes("..")||o.includes("?")||o.includes("#"))&&d("NATIVE_ABSOLUTE_PATH_INVALID",t),o}function Se(e,t){return(!Number.isInteger(e)||Number(e)<1)&&d("NATIVE_POSITIVE_INTEGER_REQUIRED",t),Number(e)}function Z(e,t,o,n){return(!Number.isInteger(e)||Number(e)<o||Number(e)>n)&&d("NATIVE_INTEGER_OUT_OF_RANGE",t),Number(e)}function De(e,t){return typeof e!="boolean"&&d("NATIVE_BOOLEAN_REQUIRED",t),e}function $t(e,t){let o=h(e,t,64).toLowerCase();return jo.test(o)||d("NATIVE_DIGEST_INVALID",t),o}function v(e,t,o){e!==t&&d("NATIVE_VALUE_MISMATCH",o)}function O(e,t,o,n=!1){let s=new Set([...t,...Array.isArray(n)?n:[]]);for(let r of Object.keys(e))s.has(r)||d("NATIVE_PROPERTY_UNKNOWN",`${o}/${r}`);if(n!==!0)for(let r of t)Object.prototype.hasOwnProperty.call(e,r)||d("NATIVE_PROPERTY_REQUIRED",`${o}/${r}`)}function X(e,t){return[...e].sort((o,n)=>ie(t(o),t(n)))}function j(e){return[...new Set(e)].sort(ie)}function Rn(e){return[...new Set(e)].sort((t,o)=>t-o)}function ie(e,t){return e===t?0:e<t?-1:1}function jn(e){return!e||typeof e!="object"||Object.isFrozen(e)||(Object.freeze(e),Object.values(e).forEach(t=>jn(t))),e}function Rt(e,t,o){if(Nt(e,t))return o;if(Array.isArray(e)&&Array.isArray(t)){let n=Math.max(e.length,t.length);for(let s=0;s<n;s+=1)if(!Nt(e[s],t[s]))return Rt(e[s],t[s],`${o}/${s}`)}if(e&&t&&typeof e=="object"&&typeof t=="object"&&!Array.isArray(e)&&!Array.isArray(t)){let n=j([...Object.keys(e),...Object.keys(t)]);for(let s of n){let r=e[s],a=t[s];if(!Nt(r,a))return Rt(r,a,`${o}/${s}`)}}return o}function Nt(e,t){return e===void 0||t===void 0?e===t:Q(e)===Q(t)}function d(e,t,o={}){throw new Ct(e,t,o)}var fr="0378091333ea27145fe23900d2040da9e1ca417421e8db7b5c9fea08cf7275c9";export{xt as DATA_AUDIT_METADATA_FIELDS,gt as DATA_EVENT_TYPES_V2,to as DATA_SYSTEM_SORT_FIELD_CODES,fr as NATIVE_CONFIGURATION_VALIDATOR_DIGEST,q as NATIVE_CONTRACT_CAPACITY_V2,qi as NATIVE_DATA_POLICY_EXPRESSION_MAX_CLAUSES,Gi as NATIVE_DATA_POLICY_EXPRESSION_MAX_DEPTH,zi as NATIVE_DATA_POLICY_EXPRESSION_MAX_GROUP_ITEMS,Yi as NATIVE_DATA_POLICY_EXPRESSION_MAX_LEAVES,Ki as NATIVE_DATA_POLICY_EXPRESSION_MAX_OCCURRENCES,no as NATIVE_DATA_QUERY_OPERATORS_V2,Ct as NativeConfigurationCompilerError,Ae as NativeDataFieldContractV2Error,ve as NativeDataPolicyExpressionV2Error,It as NativeEventActionContractError,Et as NativeScopeSourceFieldPathV2Error,Wn as OPENXIANGDA_NATIVE_DATA_FIELD_TYPES_V2,me as OPENXIANGDA_NATIVE_DATA_SURFACE_KEYS_V2,st as OPENXIANGDA_NATIVE_SYSTEM_FIELDS_V2,ii as OPENXIANGDA_NATIVE_SYSTEM_FIELD_MAP_V2,bt as WORKFLOW_EVENT_TYPES_V2,lr as compileNativeApplicationConfiguration,nn as compileNativeEventAction,us as compileNativeEventCapturePlansV2,ls as compileRequiredPlatformCapabilitiesV3,Mt as hasDataAuditReadPolicy,ye as isDataAuditMetadataField,jt as isDataSystemSortField,di as isNativeDataQueryOperatorV2,Be as isNativeMultiValueFieldV2,vi as materializeNativeDataQueryPathTypesV2,Ye as nativeDataPolicyExpressionLeavesV2,cn as nativeDataPolicyExpressionToCnfV2,ki as nativeDataQueryPathPlanV2,ui as nativeFieldAggregatePlanV2,$i as nativeFieldColumnDefinitionV2,Ri as nativeFieldDefaultSqlV2,hi as nativeFieldHasDefaultV2,Vi as nativeFieldIndexStatementsV2,Je as nativeFieldRequiresCreateInputV2,yi as nativeFieldSequenceGrantStatementsV2,Di as nativeFieldSequenceOwnershipStatementsV2,Si as nativeFieldSequenceStatementsV2,Gt as nativeFieldSupportsFilterV2,li as nativeFieldSupportsOperatorV2,dt as nativeFieldSupportsSearchV2,we as nativeFieldSupportsSortV2,Wt as nativeOperatorsForFieldV2,Co as nativePhysicalFieldV2,Oi as nativePhysicalFieldsV2,Ne as nativePhysicalObjectNameV2,Pi as nativeScopeSourceFieldValueV2,en as nativeScopeSourceGrantPathSupportedV2,At as nativeScopeSourceSubjectPathSupportedV2,wi as nativeSubtableConstraintStatementsV2,it as parseNativeDataFieldsV2,Ut as parseNativeDataResourceInvariantsV2,_t as projectNativeDataResourceViewV2,ne as quoteNativeIdentifierV2,Fe as resolveNativeScopeSourceFieldPathV2,kt as validateNativeDataResourceReferencesV2,ft as validateNativeDataResourceSurfaceV2,sn as validateWorkflowInstanceCommandPolicies,Bi as workflowInstanceCommandDeadlineError,ji as workflowInstanceTerminateCapabilityAllowed,on as workflowPolicyTimestamp};