openxiangda-contracts 2.34.0 → 2.35.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
- "use strict";var Do=Object.create;var Ke=Object.defineProperty;var Vo=Object.getOwnPropertyDescriptor;var wo=Object.getOwnPropertyNames;var Fo=Object.getPrototypeOf,vo=Object.prototype.hasOwnProperty;var Po=(e,t)=>{for(var o in t)Ke(e,o,{get:t[o],enumerable:!0})},mn=(e,t,o,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of wo(t))!vo.call(e,s)&&s!==o&&Ke(e,s,{get:()=>t[s],enumerable:!(n=Vo(t,s))||n.enumerable});return e};var Lo=(e,t,o)=>(o=e!=null?Do(Fo(e)):{},mn(t||!e||!e.__esModule?Ke(o,"default",{value:e,enumerable:!0}):o,e)),ko=e=>mn(Ke({},"__esModule",{value:!0}),e);var fr={};Po(fr,{DATA_AUDIT_METADATA_FIELDS:()=>Ft,DATA_EVENT_TYPES_V2:()=>At,DATA_SYSTEM_SORT_FIELD_CODES:()=>yn,ManagedConcurrencyContractError:()=>Fe,NATIVE_CONFIGURATION_VALIDATOR_DIGEST:()=>ur,NATIVE_CONTRACT_CAPACITY_V2:()=>Y,NATIVE_DATA_POLICY_EXPRESSION_MAX_CLAUSES:()=>Yr,NATIVE_DATA_POLICY_EXPRESSION_MAX_DEPTH:()=>zr,NATIVE_DATA_POLICY_EXPRESSION_MAX_GROUP_ITEMS:()=>Gr,NATIVE_DATA_POLICY_EXPRESSION_MAX_LEAVES:()=>qr,NATIVE_DATA_POLICY_EXPRESSION_MAX_OCCURRENCES:()=>Kr,NATIVE_DATA_QUERY_OPERATORS_V2:()=>Rn,NATIVE_UNIQUE_KEY_MAX_BYTES:()=>xr,NATIVE_UNIQUE_KEY_NORMALIZERS:()=>en,NativeConfigurationCompilerError:()=>It,NativeDataFieldContractV2Error:()=>de,NativeDataPolicyExpressionV2Error:()=>Le,NativeDecimalLifecycleContractError:()=>ye,NativeEventActionContractError:()=>Et,NativeScopeSourceFieldPathV2Error:()=>ut,NativeUniqueKeyContractError:()=>Pe,OPENXIANGDA_NATIVE_DATA_FIELD_TYPES_V2:()=>bn,OPENXIANGDA_NATIVE_DATA_SURFACE_KEYS_V2:()=>ge,OPENXIANGDA_NATIVE_DRAFT_STATE_KEYS_V2:()=>ot,OPENXIANGDA_NATIVE_SYSTEM_FIELDS_V2:()=>Qe,OPENXIANGDA_NATIVE_SYSTEM_FIELD_MAP_V2:()=>Dt,WORKFLOW_EVENT_TYPES_V2:()=>mt,compileNativeApplicationConfiguration:()=>gi,compileNativeEventAction:()=>nn,compileNativeEventCapturePlansV2:()=>mo,compileRequiredPlatformCapabilitiesV3:()=>Ao,hasDataAuditReadPolicy:()=>vt,isDataAuditMetadataField:()=>Se,isDataSystemSortField:()=>Pt,isNativeDataQueryOperatorV2:()=>Ho,isNativeMultiValueFieldV2:()=>Me,materializeNativeDataQueryPathTypesV2:()=>Js,nativeDataPolicyExpressionLeavesV2:()=>ze,nativeDataPolicyExpressionToCnfV2:()=>an,nativeDataQueryPathPlanV2:()=>Ws,nativeFieldAggregatePlanV2:()=>ss,nativeFieldColumnDefinitionV2:()=>gs,nativeFieldDefaultSqlV2:()=>Ns,nativeFieldHasDefaultV2:()=>Cs,nativeFieldIndexStatementsV2:()=>hs,nativeFieldRequiresCreateInputV2:()=>je,nativeFieldSequenceGrantStatementsV2:()=>ys,nativeFieldSequenceOwnershipStatementsV2:()=>Os,nativeFieldSequenceStatementsV2:()=>bs,nativeFieldSupportsFilterV2:()=>Mt,nativeFieldSupportsOperatorV2:()=>ts,nativeFieldSupportsSearchV2:()=>tt,nativeFieldSupportsSortV2:()=>Ve,nativeOperatorsForFieldV2:()=>Ut,nativePhysicalFieldV2:()=>xn,nativePhysicalFieldsV2:()=>Is,nativePhysicalObjectNameV2:()=>Te,nativeScopeSourceFieldValueV2:()=>Fs,nativeScopeSourceGrantPathSupportedV2:()=>Xt,nativeScopeSourceSubjectPathSupportedV2:()=>ft,nativeSubtableConstraintStatementsV2:()=>$s,nativeUniqueKeysJsonSchema:()=>Gs,parseDecimalReservationLifecycle:()=>ct,parseNativeDataFieldsV2:()=>Ze,parseNativeDataResourceInvariantsV2:()=>wt,parseNativeUniqueKeys:()=>tn,projectNativeDataResourceViewV2:()=>it,quoteNativeIdentifierV2:()=>ne,resolveNativeScopeSourceFieldPathV2:()=>ve,validateDecimalReservationLifecycles:()=>Kt,validateManagedConcurrency:()=>zt,validateNativeDataDraftStateV2:()=>Bt,validateNativeDataResourceReferencesV2:()=>Vt,validateNativeDataResourceSurfaceV2:()=>st,validateWorkflowInstanceCommandPolicies:()=>sn,workflowInstanceCommandDeadlineError:()=>Ys,workflowInstanceTerminateCapabilityAllowed:()=>qs,workflowPolicyTimestamp:()=>on});module.exports=ko(fr);var In=require("node:crypto");function xo(e){if(!e||typeof e!="object")return!1;let t=Object.getPrototypeOf(e);return t===Object.prototype||t===null}function ht(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)=>ht(n,`${t}[${s}]`)).join(",")}]`;if(xo(e))return`{${Object.keys(e).filter(s=>e[s]!==void 0).sort((s,i)=>s===i?0:s<i?-1:1).map(s=>`${JSON.stringify(s)}:${ht(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 ht(e,"$")}function ee(e){return(0,In.createHash)("sha256").update(Q(e)).digest("hex")}var Cn=/^[A-Za-z][A-Za-z0-9_]{0,62}$/,St=/^[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"],Uo=new Set(bn),On=new Set(["option.multiple","cascade.multiple","user.multiple","department.multiple","resource-ref.multiple","file","image","subtable"]),gn=new Set(["option.single","option.multiple","cascade.single","cascade.multiple"]),Nn=new Set(["resource-ref.single","resource-ref.multiple"]),Qe=[{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}],Dt=new Map(Qe.map(e=>[e.code,e])),de=class extends Error{constructor(o,n){super(o);this.code=o;this.pointer=n;this.name="NativeDataFieldContractV2Error"}code;pointer};function Me(e){return On.has(e)}function je(e,t={}){return e.type!=="serial-number"&&t.system!==!0&&e.nullable===!1&&(!Me(e.type)||t.requiredHint===!0)}function Ze(e,t,o=500){Array.isArray(e)||D("NATIVE_ARRAY_REQUIRED",t),e.length===0&&D("NATIVE_DATA_FIELDS_REQUIRED",t),e.length>o&&D("NATIVE_ARRAY_LIMIT_EXCEEDED",t);let n=new Set;return e.map((s,i)=>{let c=`${t}/${i}`,r=re(s,c);ce(r,["code","type","nullable","indexed","options","source","maxLength","precision","scale","exactDecimal","min","max","rangeBoundary","timePrecision","file","serial","subtable"],c);let a=le(r.code,`${c}/code`,63);Cn.test(a)||D("NATIVE_FIELD_CODE_INVALID",`${c}/code`),n.has(a)&&D("NATIVE_DATA_FIELD_DUPLICATE",`${c}/code`),n.add(a);let f=le(r.type,`${c}/type`,32);Uo.has(f)||D("NATIVE_DATA_FIELD_TYPE_INVALID",`${c}/type`);let _=f,d=Rt(r.nullable,`${c}/nullable`),u=Rt(r.indexed,`${c}/indexed`);d===!0&&On.has(_)&&D("NATIVE_DATA_MULTI_FIELD_NULLABLE_INVALID",`${c}/nullable`);let I=Bo(r.options,_,c),l=Jo(r.source,_,c),E=zo(r,_,c),T=Rt(r.exactDecimal,`${c}/exactDecimal`);T!==void 0&&_!=="number.decimal"&&D("NATIVE_DATA_FIELD_EXACT_DECIMAL_TYPE_INVALID",`${c}/exactDecimal`);let g=Mo(r.rangeBoundary,_,c),A=Go(r.file,_,c),m=qo(r.serial,_,c),O=Yo(r.subtable,_,c);return{code:a,type:_,...d===void 0?{}:{nullable:d},...u===void 0?{}:{indexed:u},...I?{options:I}:{},...l?{source:l}:{},...E,...T===void 0?{}:{exactDecimal:T},...g?{rangeBoundary:g}:{},...A?{file:A}:{},...m?{serial:m}:{},...O?{subtable:O}:{}}})}function Mo(e,t,o){let n=`${o}/rangeBoundary`;if(!(t==="date-range"||t==="datetime-range")){e!==void 0&&D("NATIVE_DATA_FIELD_RANGE_BOUNDARY_TYPE_INVALID",n);return}return e!=="closed"&&e!=="half-open"&&D("NATIVE_DATA_FIELD_RANGE_BOUNDARY_REQUIRED",n),e}function Vt(e,t){Array.isArray(e)||D("NATIVE_ARRAY_REQUIRED",t);let o=new Map;e.forEach((n,s)=>{let i=`${t}/${s}`,c=re(n,i),r=le(c.code,`${i}/code`,64);(!St.test(r)||o.has(r))&&D("NATIVE_RESOURCE_CODE_INVALID",`${i}/code`);let a=re(c.schema,`${i}/schema`);o.set(r,{pointer:i,fields:Ze(a.fields,`${i}/schema/fields`)})});for(let[n,s]of o){let i=new Map(s.fields.map(r=>[r.code,r]));s.fields.filter(r=>r.type==="subtable").reduce((r,a)=>r+(a.subtable?.maxRows??20),0)>49&&D("NATIVE_DATA_FIELD_SUBTABLE_AGGREGATE_MAX_ROWS_EXCEEDED",`${s.pointer}/schema/fields`),s.fields.forEach((r,a)=>{let f=`${s.pointer}/schema/fields/${a}`;if(r.source&&jo(r.source,i,o,`${f}/source`),r.subtable){let _=o.get(r.subtable.resourceCode);(!_||r.subtable.resourceCode===n)&&D("NATIVE_DATA_FIELD_SUBTABLE_TARGET_MISSING",`${f}/subtable/resourceCode`);let d=_.fields.find(I=>I.code===r.subtable?.foreignKey);(!d||d.type!=="uuid"||d.nullable!==!1)&&D("NATIVE_DATA_FIELD_SUBTABLE_FOREIGN_KEY_INVALID",`${f}/subtable/foreignKey`);let u=_.fields.find(I=>I.code===r.subtable?.orderField);(!u||u.type!=="number.integer"||u.nullable!==!1)&&D("NATIVE_DATA_FIELD_SUBTABLE_ORDER_FIELD_INVALID",`${f}/subtable/orderField`)}})}}function wt(e,t,o){if(e===void 0)return[];(!Array.isArray(e)||e.length>20)&&D("NATIVE_DATA_RESOURCE_INVARIANTS_INVALID",o);let n=new Map(t.map(i=>[i.code,i])),s=new Set;return e.map((i,c)=>{let r=`${o}/${c}`,a=re(i,r);ce(a,["code","message","expression"],r);let f=le(a.code,`${r}/code`,128);(!/^[a-z][a-z0-9]*(?:[._-][a-z0-9]+)*$/.test(f)||s.has(f))&&D("NATIVE_DATA_RESOURCE_INVARIANT_CODE_INVALID",`${r}/code`),s.add(f);let _=Xe(a.message,`${r}/message`,500);_!==void 0&&_.length===0&&D("NATIVE_DATA_RESOURCE_INVARIANT_MESSAGE_INVALID",`${r}/message`);let d=re(a.expression,`${r}/expression`);if(d.kind==="nonBlankTextWhenOption"){ce(d,["kind","optionField","optionValue","textField"],`${r}/expression`);let A=_e(d.optionField,`${r}/expression/optionField`),m=_e(d.textField,`${r}/expression/textField`),O=le(d.optionValue,`${r}/expression/optionValue`,128),C=n.get(A),b=n.get(m);return(!C||!b)&&D("NATIVE_DATA_RESOURCE_INVARIANT_FIELD_UNKNOWN",`${r}/expression`),(C.type!=="option.single"||!["text.short","text.long"].includes(b.type)||!C.options?.some(y=>y.value===O))&&D("NATIVE_DATA_RESOURCE_INVARIANT_FIELD_TYPES_INVALID",`${r}/expression`),{code:f,..._===void 0?{}:{message:_},expression:{kind:"nonBlankTextWhenOption",optionField:A,optionValue:O,textField:m}}}ce(d,["leftField","operator","rightField"],`${r}/expression`);let u=_e(d.leftField,`${r}/expression/leftField`),I=_e(d.rightField,`${r}/expression/rightField`),l=n.get(u),E=n.get(I);(!l||!E)&&D("NATIVE_DATA_RESOURCE_INVARIANT_FIELD_UNKNOWN",`${r}/expression`),l.type===E.type||["number.integer","number.decimal"].includes(l.type)&&["number.integer","number.decimal"].includes(E.type)||D("NATIVE_DATA_RESOURCE_INVARIANT_FIELD_TYPES_INVALID",`${r}/expression`);let g=String(d.operator);return["eq","neq","gt","gte","lt","lte"].includes(g)||D("NATIVE_DATA_RESOURCE_INVARIANT_OPERATOR_INVALID",`${r}/expression/operator`),!["eq","neq"].includes(g)&&!["number.integer","number.decimal","date","time","datetime","text.short","text.long","text.rich","serial-number","uuid"].includes(l.type)&&D("NATIVE_DATA_RESOURCE_INVARIANT_FIELD_TYPES_INVALID",`${r}/expression`),{code:f,..._===void 0?{}:{message:_},expression:{leftField:u,operator:g,rightField:I}}})}function jo(e,t,o,n){let s=o.get(e.resourceCode);s||D("NATIVE_DATA_FIELD_SOURCE_TARGET_MISSING",`${n}/resourceCode`);let i=new Map(s.fields.map(r=>[r.code,r])),c=i.get(e.labelField);(!c||!["text.short","text.long"].includes(c.type))&&D("NATIVE_DATA_FIELD_SOURCE_LABEL_INVALID",`${n}/labelField`);for(let r of["searchFields","descriptionFields","snapshotFields"])for(let a of e[r]||[])i.has(a)||D("NATIVE_DATA_FIELD_SOURCE_FIELD_MISSING",`${n}/${r}`);for(let[r,a]of(e.filters||[]).entries())i.has(a.field)||D("NATIVE_DATA_FIELD_SOURCE_FILTER_FIELD_MISSING",`${n}/filters/${r}/field`),"binding"in a&&!t.has(a.binding.field)&&D("NATIVE_DATA_FIELD_SOURCE_BINDING_FIELD_MISSING",`${n}/filters/${r}/binding/field`)}function Bo(e,t,o){let n=`${o}/options`;if(e===void 0){gn.has(t)&&D("NATIVE_DATA_FIELD_OPTIONS_REQUIRED",n);return}(!gn.has(t)||!Array.isArray(e))&&D("NATIVE_DATA_FIELD_OPTIONS_TYPE_INVALID",n),(e.length<1||e.length>100)&&D("NATIVE_DATA_FIELD_OPTIONS_INVALID",n);let s=0,i=(c,r,a)=>{a>5&&D("NATIVE_DATA_FIELD_OPTIONS_DEPTH_EXCEEDED",r);let f=new Set;return c.map((_,d)=>{s+=1,s>1e3&&D("NATIVE_DATA_FIELD_OPTIONS_COUNT_EXCEEDED",n);let u=`${r}/${d}`,I=re(_,u);ce(I,["label","value","description","color","children"],u);let l=le(I.label,`${u}/label`,500),E=le(I.value,`${u}/value`,500);f.has(E)&&D("NATIVE_DATA_FIELD_OPTION_VALUE_DUPLICATE",`${u}/value`),f.add(E);let T=Xe(I.description,`${u}/description`,2e3),g=Xe(I.color,`${u}/color`,64),A;return I.children!==void 0&&((!t.startsWith("cascade.")||!Array.isArray(I.children))&&D("NATIVE_DATA_FIELD_OPTION_CHILDREN_INVALID",`${u}/children`),(I.children.length<1||I.children.length>100)&&D("NATIVE_DATA_FIELD_OPTION_CHILDREN_INVALID",`${u}/children`),A=i(I.children,`${u}/children`,a+1)),{label:l,value:E,...T===void 0?{}:{description:T},...g===void 0?{}:{color:g},...A?{children:A}:{}}})};return i(e,n,1)}function Jo(e,t,o){let n=`${o}/source`;if(e===void 0){Nn.has(t)&&D("NATIVE_DATA_FIELD_SOURCE_REQUIRED",n);return}Nn.has(t)||D("NATIVE_DATA_FIELD_SOURCE_TYPE_INVALID",n);let s=re(e,n);ce(s,["kind","resourceCode","labelField","searchFields","descriptionFields","snapshotFields","filters","pageSize","loadMode"],n),s.kind!=="resource"&&D("NATIVE_DATA_FIELD_SOURCE_KIND_INVALID",`${n}/kind`);let i=le(s.resourceCode,`${n}/resourceCode`,64);St.test(i)||D("NATIVE_RESOURCE_CODE_INVALID",`${n}/resourceCode`);let c=_e(s.labelField,`${n}/labelField`),r=$t(s.searchFields,`${n}/searchFields`,10),a=$t(s.descriptionFields,`${n}/descriptionFields`,10),f=$t(s.snapshotFields,`${n}/snapshotFields`,50),_=Re(s.pageSize,`${n}/pageSize`,1,100),d;s.loadMode!==void 0&&(["search","all"].includes(String(s.loadMode))||D("NATIVE_DATA_FIELD_SOURCE_LOAD_MODE_INVALID",`${n}/loadMode`),d=s.loadMode);let u=Wo(s.filters,`${n}/filters`);return{kind:"resource",resourceCode:i,labelField:c,...r?{searchFields:r}:{},...a?{descriptionFields:a}:{},...f?{snapshotFields:f}:{},...u?{filters:u}:{},..._===void 0?{}:{pageSize:_},...d?{loadMode:d}:{}}}function Wo(e,t){if(e!==void 0)return(!Array.isArray(e)||e.length>20)&&D("NATIVE_DATA_FIELD_SOURCE_FILTERS_INVALID",t),e.map((o,n)=>{let s=`${t}/${n}`,i=re(o,s),c=Object.prototype.hasOwnProperty.call(i,"value"),r=Object.prototype.hasOwnProperty.call(i,"binding");ce(i,c?["field","operator","value"]:["field","operator","binding"],s),c===r&&D("NATIVE_DATA_FIELD_SOURCE_FILTER_VALUE_INVALID",s);let a=_e(i.field,`${s}/field`);["eq","in"].includes(String(i.operator))||D("NATIVE_DATA_FIELD_SOURCE_FILTER_OPERATOR_INVALID",`${s}/operator`);let f=i.operator;if(c)return{field:a,operator:f,value:i.value};let _=re(i.binding,`${s}/binding`);return ce(_,["kind","field"],`${s}/binding`),_.kind!=="field"&&D("NATIVE_DATA_FIELD_SOURCE_BINDING_KIND_INVALID",`${s}/binding/kind`),{field:a,operator:f,binding:{kind:"field",field:_e(_.field,`${s}/binding/field`)}}})}function zo(e,t,o){let n={};if(e.maxLength!==void 0&&(["text.short","text.long","text.rich"].includes(t)||D("NATIVE_DATA_FIELD_MAX_LENGTH_TYPE_INVALID",`${o}/maxLength`),n.maxLength=He(e.maxLength,`${o}/maxLength`,1,1e6)),(e.precision!==void 0||e.scale!==void 0)&&((t!=="number.decimal"||e.precision===void 0)&&D("NATIVE_DATA_FIELD_DECIMAL_CONFIG_INVALID",o),n.precision=He(e.precision,`${o}/precision`,1,1e3),n.scale=e.scale===void 0?0:He(e.scale,`${o}/scale`,0,n.precision)),e.min!==void 0||e.max!==void 0){["number.integer","number.decimal"].includes(t)||D("NATIVE_DATA_FIELD_NUMERIC_BOUNDS_TYPE_INVALID",o);let s=Tn(e.min,`${o}/min`),i=Tn(e.max,`${o}/max`);t==="number.integer"&&[s,i].some(c=>c!==void 0&&!Number.isSafeInteger(c))&&D("NATIVE_DATA_FIELD_NUMERIC_BOUNDS_INVALID",o),s!==void 0&&i!==void 0&&s>i&&D("NATIVE_DATA_FIELD_NUMERIC_BOUNDS_INVALID",o),s!==void 0&&(n.min=s),i!==void 0&&(n.max=i)}return e.timePrecision!==void 0&&((t!=="time"||!["minute","second"].includes(e.timePrecision))&&D("NATIVE_DATA_FIELD_TIME_PRECISION_INVALID",`${o}/timePrecision`),n.timePrecision=e.timePrecision),n}function Go(e,t,o){if(e===void 0)return;let n=`${o}/file`;["file","image","signature"].includes(t)||D("NATIVE_DATA_FIELD_FILE_TYPE_INVALID",n);let s=re(e,n);ce(s,["maxCount","maxSizeMb","accept"],n);let i=Re(s.maxCount,`${n}/maxCount`,1,100);t==="signature"&&i!==void 0&&i!==1&&D("NATIVE_DATA_FIELD_SIGNATURE_COUNT_INVALID",`${n}/maxCount`);let c=Re(s.maxSizeMb,`${n}/maxSizeMb`,1,1024),r;return s.accept!==void 0&&((!Array.isArray(s.accept)||s.accept.length>50)&&D("NATIVE_DATA_FIELD_FILE_ACCEPT_INVALID",`${n}/accept`),r=s.accept.map((a,f)=>le(a,`${n}/accept/${f}`,255)),new Set(r).size!==r.length&&D("NATIVE_DATA_FIELD_FILE_ACCEPT_INVALID",`${n}/accept`)),{...i===void 0?{}:{maxCount:i},...c===void 0?{}:{maxSizeMb:c},...r===void 0?{}:{accept:r}}}function qo(e,t,o){let n=`${o}/serial`;if(e===void 0){t==="serial-number"&&D("NATIVE_DATA_FIELD_SERIAL_REQUIRED",n);return}t!=="serial-number"&&D("NATIVE_DATA_FIELD_SERIAL_TYPE_INVALID",n);let s=re(e,n);ce(s,["prefix","digits","start"],n);let i=Xe(s.prefix,`${n}/prefix`,64),c=Re(s.digits,`${n}/digits`,1,32),r=Re(s.start,`${n}/start`,0,Number.MAX_SAFE_INTEGER);return{...i===void 0?{}:{prefix:i},...c===void 0?{}:{digits:c},...r===void 0?{}:{start:r}}}function Yo(e,t,o){let n=`${o}/subtable`;if(e===void 0){t==="subtable"&&D("NATIVE_DATA_FIELD_SUBTABLE_REQUIRED",n);return}t!=="subtable"&&D("NATIVE_DATA_FIELD_SUBTABLE_TYPE_INVALID",n);let s=re(e,n);ce(s,["resourceCode","foreignKey","orderField","maxRows"],n);let i=le(s.resourceCode,`${n}/resourceCode`,64);St.test(i)||D("NATIVE_RESOURCE_CODE_INVALID",`${n}/resourceCode`);let c=_e(s.foreignKey,`${n}/foreignKey`),r=_e(s.orderField,`${n}/orderField`);r===c&&D("NATIVE_DATA_FIELD_SUBTABLE_ORDER_FIELD_INVALID",`${n}/orderField`);let a=Re(s.maxRows,`${n}/maxRows`,1,49);return{resourceCode:i,foreignKey:c,orderField:r,...a===void 0?{}:{maxRows:a}}}function $t(e,t,o){if(e===void 0)return;(!Array.isArray(e)||e.length>o)&&D("NATIVE_DATA_FIELD_SOURCE_FIELDS_INVALID",t);let n=e.map((s,i)=>_e(s,`${t}/${i}`));return new Set(n).size!==n.length&&D("NATIVE_DATA_FIELD_SOURCE_FIELDS_INVALID",t),n}function _e(e,t){let o=le(e,t,63);return Cn.test(o)||D("NATIVE_FIELD_CODE_INVALID",t),o}function re(e,t){return(!e||typeof e!="object"||Array.isArray(e))&&D("NATIVE_OBJECT_REQUIRED",t),e}function ce(e,t,o){let n=new Set(t);for(let s of Object.keys(e))n.has(s)||D("NATIVE_PROPERTY_UNKNOWN",`${o}/${s}`)}function le(e,t,o){return(typeof e!="string"||e.length===0||e.length>o)&&D("NATIVE_STRING_INVALID",t),e}function Xe(e,t,o){if(e!==void 0)return(typeof e!="string"||e.length>o)&&D("NATIVE_STRING_INVALID",t),e}function Rt(e,t){if(e!==void 0)return typeof e!="boolean"&&D("NATIVE_BOOLEAN_REQUIRED",t),e}function Re(e,t,o,n){if(e!==void 0)return He(e,t,o,n)}function Tn(e,t){if(e!==void 0)return(typeof e!="number"||!Number.isFinite(e))&&D("NATIVE_NUMBER_REQUIRED",t),e}function He(e,t,o,n){return(!Number.isSafeInteger(e)||Number(e)<o||Number(e)>n)&&D("NATIVE_INTEGER_OUT_OF_RANGE",t),Number(e)}function D(e,t){throw new de(e,t)}var Ft=["created_by","updated_by","created_at","updated_at"];function Se(e){return Ft.includes(e)}function vt(e){return Ft.some(t=>Object.prototype.hasOwnProperty.call(e.fieldPolicies||{},t))}var yn=Qe.map(e=>e.code);function Pt(e){return yn.includes(e)}var Rn=["eq","neq","gt","gte","lt","lte","contains","startsWith","endsWith","in","between","has","hasAny","hasAll","overlaps","containedBy","jsonContains","isEmpty","isNotEmpty"],Ko=new Set(Rn);function Ho(e){return Ko.has(String(e))}var Lt=["eq","neq","contains","startsWith","endsWith","in","isEmpty","isNotEmpty"],Be=["eq","neq","gt","gte","lt","lte","between","in","isEmpty"],Xo=["eq","neq","in","isEmpty"],et=["eq","neq","in","isEmpty","isNotEmpty"],De=["has","hasAny","hasAll","isEmpty","isNotEmpty"],hn=["overlaps","contains","containedBy","isEmpty"],kt=["jsonContains","isEmpty","isNotEmpty"],xt=["isEmpty","isNotEmpty"],Qo={"text.short":Lt,"text.long":Lt,"text.rich":Lt,"number.integer":Be,"number.decimal":Be,boolean:Xo,date:Be,time:Be,datetime:Be,"date-range":hn,"datetime-range":hn,"option.single":et,"option.multiple":De,"cascade.single":De,"cascade.multiple":De,"user.single":et,"user.multiple":De,"department.single":et,"department.multiple":De,"resource-ref.single":et,"resource-ref.multiple":De,file:xt,image:xt,signature:xt,address:kt,location:kt,uuid:["eq","neq","in","isEmpty"],json:kt,"serial-number":["eq","neq","in","contains","startsWith"],subtable:[]},Zo=new Set(["text.short","text.long","text.rich","option.single","user.single","department.single","resource-ref.single","serial-number"]),es=new Set(["option.multiple","cascade.single","cascade.multiple","user.multiple","department.multiple","resource-ref.multiple","file","image","signature","address","location","json","subtable"]);function Ut(e){return Qo[e]}function ts(e,t){return Ut(e).includes(t)}function tt(e){return Zo.has(e)}function Ve(e){return!es.has(e)}function Mt(e){return Ut(e).length>0}var $n=new Set(["number.integer","number.decimal"]),Sn=new Set(["text.short","text.long","number.integer","number.decimal","date","time","datetime","serial-number"]),ns=new Set([...Sn,"boolean","uuid"]),os=new Set(["option.single","user.single","department.single","resource-ref.single"]);function ss(e,t){return t==="sum"||t==="avg"?$n.has(e)?{valueExpression:"column",numericResult:!0}:null:t==="min"||t==="max"?Sn.has(e)?{valueExpression:"column",numericResult:$n.has(e)}:null:os.has(e)?{valueExpression:"snapshot-value",numericResult:!0}:ns.has(e)?{valueExpression:"column",numericResult:!0}:null}var ot=["version","maxBytes","fields"];function Bt(e,t){if(e===void 0)return;let o=jt(e,t);Dn(o,ot,t);let n=nt(o.version,`${t}/version`,1,1e6),s=nt(o.maxBytes,`${t}/maxBytes`,2,196608);(!n||!s)&&se("NATIVE_DATA_DRAFT_STATE_SCHEMA_INVALID",t);let i=jt(o.fields,`${t}/fields`),c=Object.entries(i);(!c.length||c.length>50)&&se("NATIVE_DATA_DRAFT_STATE_FIELDS_INVALID",`${t}/fields`);for(let[r,a]of c){let f=`${t}/fields/${r}`;/^[A-Za-z][A-Za-z0-9_]{0,62}$/.test(r)||se("NATIVE_DATA_DRAFT_STATE_FIELD_CODE_INVALID",f);let _=jt(a,f),d=Vn(_.type,`${f}/type`,32),u=d==="string"?["type","required","maxLength","enum"]:d==="json.object"?["type","required","maxBytes"]:["type","required"];if(["string","number","integer","boolean","json.object"].includes(d)||se("NATIVE_DATA_DRAFT_STATE_FIELD_TYPE_INVALID",`${f}/type`),Dn(_,u,f),rs(_.required,`${f}/required`),d==="string"){let I=nt(_.maxLength,`${f}/maxLength`,1,196608);I||se("NATIVE_DATA_DRAFT_STATE_FIELD_INVALID",f),_.enum!==void 0&&is(_.enum,`${f}/enum`,100,!1).some(E=>E.length>I)&&se("NATIVE_DATA_DRAFT_STATE_FIELD_INVALID",`${f}/enum`)}else if(d==="json.object"){let I=nt(_.maxBytes,`${f}/maxBytes`,2,65536);(!I||I>s)&&se("NATIVE_DATA_DRAFT_STATE_FIELD_INVALID",f)}}}function is(e,t,o,n){(!Array.isArray(e)||!n&&e.length===0||e.length>o)&&se("NATIVE_DATA_SURFACE_STRING_ARRAY_INVALID",t);let s=e.map((i,c)=>Vn(i,`${t}/${c}`,255));return new Set(s).size!==s.length&&se("NATIVE_DATA_SURFACE_STRING_ARRAY_INVALID",t),s}function jt(e,t){return(!e||typeof e!="object"||Array.isArray(e))&&se("NATIVE_OBJECT_REQUIRED",t),e}function Dn(e,t,o){let n=new Set(t);for(let s of Object.keys(e))n.has(s)||se("NATIVE_PROPERTY_UNKNOWN",`${o}/${s}`)}function Vn(e,t,o){return(typeof e!="string"||e.length===0||e.length>o)&&se("NATIVE_STRING_INVALID",t),e}function rs(e,t){e!==void 0&&typeof e!="boolean"&&se("NATIVE_BOOLEAN_REQUIRED",t)}function nt(e,t,o,n){return(!Number.isSafeInteger(e)||Number(e)<o||Number(e)>n)&&se("NATIVE_INTEGER_INVALID",t),Number(e)}function se(e,t){throw new de(e,t)}var as=500,ge={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","exactDecimal","min","max","rangeBoundary","maxCount","maxSizeMb","accept","options","list","searchable","sortable","source","timePrecision","serial","subtable"],list:["actions","fieldOrder","defaultPageSize","searchableFields","filterFields","defaultSort"],defaultSort:["field","order"],form:["layout","fieldOrder","draftState"],detail:["layout","fieldOrder"],layout:["layout","fieldOrder","draftState"],draftState:ot,mobile:["enabled"]},cs={"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 st(e,t,o){if(e===void 0)return;let n=te(e,o);Ee(n,ge.surface,o);let s=n.mutationOwner===void 0?"native":Ne(n.mutationOwner,`${o}/mutationOwner`,16);["native","action","readonly","workflow","queued-command"].includes(s)||k("NATIVE_DATA_SURFACE_MUTATION_OWNER_INVALID",`${o}/mutationOwner`);let i=n.generated===void 0?{}:te(n.generated,`${o}/generated`);Ee(i,ge.generated,`${o}/generated`);for(let a of ge.generated)Wt(i[a],`${o}/generated/${a}`);if(s!=="native")for(let a of["create","update","delete"])i[a]===!0&&k("NATIVE_DATA_SURFACE_MUTATION_OWNER_CONFLICT",`${o}/generated/${a}`);let c=new Map(t.map(a=>[a.code,a])),r=te(n.fields,`${o}/fields`);for(let a of Object.keys(r))c.has(a)||k("NATIVE_DATA_SURFACE_FIELD_MISSING",`${o}/fields/${a}`);for(let a of t)Object.prototype.hasOwnProperty.call(r,a.code)||k("NATIVE_DATA_SURFACE_FIELD_REQUIRED",`${o}/fields/${a.code}`),ls(r[a.code],a,`${o}/fields/${a.code}`);for(let a of["create","update"]){let f=i[a]??s==="native",_=t.some(d=>{let u=te(r[d.code],`${o}/fields/${d.code}`);return Fn(d,u,a)});f&&!_&&k("NATIVE_DATA_SURFACE_WRITABLE_FIELDS_REQUIRED",`${o}/generated/${a}`)}if(us(n.list,c,`${o}/list`),wn(n.form,c,`${o}/form`,"form"),wn(n.detail,c,`${o}/detail`,"detail"),n.mobile!==void 0){let a=te(n.mobile,`${o}/mobile`);Ee(a,ge.mobile,`${o}/mobile`),Wt(a.enabled,`${o}/mobile/enabled`)}ds(n,t,o)}function it(e,t){let o=e.views?.find(s=>s.code===t);o||k("NATIVE_DATA_VIEW_NOT_FOUND",`/surface/views/${t}`);let n=new Map((o.sections||[]).flatMap(s=>s.fields.map(i=>[i,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,i])=>{let c={...i};delete c.section;let r=n.get(s);return[s,{...c,...r?{section:r}:{},list:o.list.fieldOrder.includes(s)}]}))}}function ds(e,t,o){if(e.views===void 0)return;(!Array.isArray(e.views)||e.views.length>20)&&k("NATIVE_DATA_VIEWS_LIMIT_INVALID",`${o}/views`);let n=new Set;e.views.forEach((s,i)=>{let c=`${o}/views/${i}`,r=te(s,c);Ee(r,["code","name","generated","list","form","detail","mobile","sections"],c);let a=Ne(r.code,`${c}/code`,64);(!/^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/.test(a)||n.has(a))&&k("NATIVE_DATA_VIEW_CODE_INVALID",`${c}/code`),n.add(a),Ne(r.name,`${c}/name`,255),te(r.generated,`${c}/generated`),te(r.mobile,`${c}/mobile`);for(let _ of["list","detail","create","update","delete"])typeof r.generated[_]!="boolean"&&k("NATIVE_DATA_VIEW_OPERATION_INVALID",`${c}/generated/${_}`);typeof r.mobile.enabled!="boolean"&&k("NATIVE_DATA_VIEW_MOBILE_INVALID",`${c}/mobile/enabled`);for(let _ of["list","form","detail"]){let d=te(r[_],`${c}/${_}`),u=we(d.fieldOrder,`${c}/${_}/fieldOrder`,500,!0);for(let I of u){let l=e.fields[I];(!l||(l.hidden??l.system)===!0)&&k("NATIVE_DATA_VIEW_FIELD_INVALID",`${c}/${_}/fieldOrder`)}}if(r.sections!==void 0){(!Array.isArray(r.sections)||r.sections.length>100)&&k("NATIVE_DATA_VIEW_SECTIONS_INVALID",`${c}/sections`);let _=new Set;r.sections.forEach((d,u)=>{let I=`${c}/sections/${u}`,l=te(d,I);Ee(l,["title","fields"],I),Ne(l.title,`${I}/title`,255);for(let E of we(l.fields,`${I}/fields`,100,!0)){let T=e.fields[E];(!T||(T.hidden??T.system)===!0||_.has(E))&&k("NATIVE_DATA_VIEW_FIELD_INVALID",`${I}/fields`),_.add(E)}})}let f=it(e,a);if(st(f,t,c),r.generated.create!==!1&&(e.mutationOwner||"native")==="native")for(let _ of t)je(_,e.fields[_.code])&&Fn(_,e.fields[_.code],"create")&&!r.form.fieldOrder.includes(_.code)&&k("NATIVE_DATA_VIEW_CREATE_REQUIRED_FIELD_MISSING",`${c}/form/fieldOrder`)})}function Fn(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 ls(e,t,o){let n=te(e,o);Ee(n,ge.field,o),Ne(n.label,`${o}/label`,500),n.type!==t.type&&k("NATIVE_DATA_SURFACE_FIELD_TYPE_MISMATCH",`${o}/type`);let s=Ne(n.widget,`${o}/widget`,64);cs[t.type].includes(s)||k("NATIVE_DATA_SURFACE_WIDGET_INCOMPATIBLE",`${o}/widget`),_s(n.section,`${o}/section`,255);for(let i of["requiredHint","system","hidden","list","searchable","sortable"])Wt(n[i],`${o}/${i}`);n.searchable===!0&&!tt(t.type)&&k("NATIVE_DATA_SURFACE_SEARCH_UNSUPPORTED",`${o}/searchable`),n.sortable===!0&&!Ve(t.type)&&k("NATIVE_DATA_SURFACE_SORT_UNSUPPORTED",`${o}/sortable`);for(let i of["readCapabilities","createCapabilities","updateCapabilities"])we(n[i],`${o}/${i}`,100,!0);if(n.maxCount!==void 0&&(!Number.isSafeInteger(n.maxCount)||Number(n.maxCount)<1||Number(n.maxCount)>100)&&k("NATIVE_DATA_SURFACE_MAX_COUNT_INVALID",`${o}/maxCount`),n.maxSizeMb!==void 0&&(!Number.isSafeInteger(n.maxSizeMb)||Number(n.maxSizeMb)<1||Number(n.maxSizeMb)>1024)&&k("NATIVE_DATA_SURFACE_MAX_SIZE_INVALID",`${o}/maxSizeMb`),n.accept!==void 0){let i=Array.isArray(n.accept)?n.accept:[n.accept];we(i,`${o}/accept`,50,!1)}for(let i of["maxLength","precision","scale","exactDecimal","min","max","rangeBoundary","options","source","timePrecision","serial","subtable"])fs(n,t,i,o);ps(n,t,o)}function us(e,t,o){if(e===void 0)return;let n=te(e,o);if(Ee(n,ge.list,o),n.actions!==void 0){let s=te(n.actions,`${o}/actions`);Ee(s,["import","export"],`${o}/actions`);for(let i of["import","export"])s[i]!==void 0&&typeof s[i]!="boolean"&&k("NATIVE_DATA_SURFACE_LIST_ACTION_INVALID",`${o}/actions/${i}`)}if(n.fieldOrder!==void 0)for(let s of we(n.fieldOrder,`${o}/fieldOrder`,500,!0))t.has(s)||k("NATIVE_DATA_SURFACE_LIST_FIELD_INVALID",`${o}/fieldOrder`);n.defaultPageSize!==void 0&&(!Number.isSafeInteger(n.defaultPageSize)||Number(n.defaultPageSize)<1||Number(n.defaultPageSize)>200)&&k("NATIVE_DATA_SURFACE_PAGE_SIZE_INVALID",`${o}/defaultPageSize`);for(let[s,i]of[["searchableFields",tt],["filterFields",Mt]]){if(n[s]===void 0)continue;let c=we(n[s],`${o}/${s}`,100,!0);for(let r of c){let a=t.get(r);(!a||!i(a.type))&&k("NATIVE_DATA_SURFACE_LIST_FIELD_INVALID",`${o}/${s}`)}}if(n.defaultSort!==void 0){let s=te(n.defaultSort,`${o}/defaultSort`);Ee(s,ge.defaultSort,`${o}/defaultSort`);let i=Ne(s.field,`${o}/defaultSort/field`,63),c=t.get(i);!Pt(i)&&(!c||!Ve(c.type))&&k("NATIVE_DATA_SURFACE_SORT_UNSUPPORTED",`${o}/defaultSort/field`),s.order!==void 0&&!["asc","desc"].includes(s.order)&&k("NATIVE_DATA_SURFACE_SORT_ORDER_INVALID",`${o}/defaultSort/order`)}}function wn(e,t,o,n){if(e===void 0)return;let s=te(e,o);if(Ee(s,ge[n],o),s.layout!==void 0&&!["flat","sections"].includes(s.layout)&&k("NATIVE_DATA_SURFACE_LAYOUT_INVALID",`${o}/layout`),s.fieldOrder!==void 0){let i=`${o}/fieldOrder`;(!Array.isArray(s.fieldOrder)||s.fieldOrder.length>t.size||s.fieldOrder.length>as)&&k("NATIVE_DATA_SURFACE_FIELD_ORDER_INVALID",i);let c=s.fieldOrder.map((r,a)=>Ne(r,`${i}/${a}`,63));new Set(c).size!==c.length&&k("NATIVE_DATA_SURFACE_FIELD_ORDER_INVALID",i),c.forEach((r,a)=>{t.has(r)||k("NATIVE_DATA_SURFACE_FIELD_ORDER_FIELD_MISSING",`${i}/${a}`)})}n==="form"&&Bt(s.draftState,`${o}/draftState`)}function fs(e,t,o,n){e[o]===void 0&&t[o]===void 0||((e[o]===void 0||t[o]===void 0)&&k("NATIVE_DATA_SURFACE_FIELD_PROJECTION_MISMATCH",`${n}/${o}`),Q(e[o])!==Q(t[o])&&k("NATIVE_DATA_SURFACE_FIELD_PROJECTION_MISMATCH",`${n}/${o}`))}function ps(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:Jt(e.accept)}};for(let i of["maxCount","maxSizeMb","accept"]){if(s[i]===void 0&&n[i]===void 0)continue;(s[i]===void 0||n[i]===void 0)&&k("NATIVE_DATA_SURFACE_FIELD_PROJECTION_MISMATCH",`${o}/${i}`);let c=i==="accept"?Jt(s[i]):s[i],r=i==="accept"?Jt(n[i]):n[i];Q(c)!==Q(r)&&k("NATIVE_DATA_SURFACE_FIELD_PROJECTION_MISMATCH",`${o}/${i}`)}}function Jt(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 we(e,t,o,n){(!Array.isArray(e)||!n&&e.length===0||e.length>o)&&k("NATIVE_DATA_SURFACE_STRING_ARRAY_INVALID",t);let s=e.map((i,c)=>Ne(i,`${t}/${c}`,255));return new Set(s).size!==s.length&&k("NATIVE_DATA_SURFACE_STRING_ARRAY_INVALID",t),s}function te(e,t){return(!e||typeof e!="object"||Array.isArray(e))&&k("NATIVE_OBJECT_REQUIRED",t),e}function Ee(e,t,o){let n=new Set(t);for(let s of Object.keys(e))n.has(s)||k("NATIVE_PROPERTY_UNKNOWN",`${o}/${s}`)}function Ne(e,t,o){return(typeof e!="string"||e.length===0||e.length>o)&&k("NATIVE_STRING_INVALID",t),e}function _s(e,t,o){e!==void 0&&(typeof e!="string"||e.length>o)&&k("NATIVE_STRING_INVALID",t)}function Wt(e,t){e!==void 0&&typeof e!="boolean"&&k("NATIVE_BOOLEAN_REQUIRED",t)}function k(e,t){throw new de(e,t)}var Fe=class extends Error{constructor(o,n){super(`${o}: ${n}`);this.pointer=o;this.reason=n}pointer;reason;code="NATIVE_MANAGED_CONCURRENCY_INVALID"};function zt(e,t,o){if(e===void 0)return;let n=(A,m)=>{throw new Fe(A,m)},s=(A,m,O)=>((!A||typeof A!="object"||Array.isArray(A)||Object.keys(A).some(C=>!O.includes(C)))&&n(m,"object contains unsupported properties"),A),i=(A,m,O,C)=>{(!Number.isSafeInteger(A)||A<m||A>O)&&n(C,`expected integer ${m}..${O}`)},c=(A,m)=>{(typeof A!="string"||!/^[a-z][a-z0-9_-]{0,63}$/.test(A))&&n(m,"invalid code")},r=(A,m,O)=>((!Array.isArray(A)||A.length>m)&&n(O,"array exceeds bound"),A),a=(A,m)=>{let O=t.find(C=>C.code===A);return O||n(m,"unknown resource"),O},f=(A,m,O)=>{let C=A.schema.fields.find(b=>b.code===m);return!C&&m!=="id"&&n(O,"unknown field"),C},_=(A,m,O=!1)=>{s(A,m,Object.keys(A||{})),Object.keys(A).length>8&&n(m,"at most eight parameters");for(let[C,b]of Object.entries(A))if(c(C,m),s(b,m,["type","values","minimum","maximum","minLength","maxLength"]),b.type==="uuid")Object.keys(b).length!==1&&n(m,"uuid has no options");else if(O&&b.type==="boolean")s(b,m,["type"]);else if(O&&b.type==="string"&&b.values===void 0)s(b,m,["type","minLength","maxLength"]),i(b.maxLength,1,256,m),b.minLength!==void 0&&i(b.minLength,0,b.maxLength,m);else if(b.type==="string"){s(b,m,["type","values"]);let y=r(b.values,100,m);(!y.length||y.some(S=>typeof S!="string"||S.length>128)||new Set(y).size!==y.length)&&n(m,"finite string values required")}else b.type==="integer"?(s(b,m,["type","minimum","maximum"]),i(b.minimum,0,1e6,m),i(b.maximum,b.minimum,b.minimum+1e3,m)):n(m,"unsupported parameter type")},d=(A,m,O,C=!1)=>{s(A,O,["from","key","value"]),!(A.from==="input"&&Object.keys(A).length===2&&Object.hasOwn(m,A.key))&&((A.from==="actor"||C&&A.from==="allocation")&&Object.keys(A).length===1||A.from==="literal"&&Object.keys(A).length===2&&Object.hasOwn(A,"value")&&(A.value===null||["string","boolean"].includes(typeof A.value)||typeof A.value=="number"&&Number.isFinite(A.value))&&JSON.stringify(A.value).length<=512||n(O,"invalid binding"))},u=(A,m,O)=>{d(A,m,O),!(A.from==="input"&&m[A.key].type==="uuid")&&(A.from==="literal"&&typeof A.value=="string"&&/^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i.test(A.value)||n(O,"record and allocation identifiers require a UUID binding"))},I=(A,m,O)=>{d(A,m,O),!(A.from==="input"&&m[A.key].type==="integer"&&m[A.key].minimum>=1)&&(A.from==="literal"&&Number.isSafeInteger(A.value)&&A.value>=1||n(O,"expectedRevision requires a positive integer binding"))},l="/data/concurrency";JSON.stringify(e).length>131072&&n(l,"declaration exceeds 128 KiB");let E=s(e,l,["version","admission","reads","quotas","commands"]);E.version!==1&&n(l,"unsupported version"),s(E.admission,l,["perSecond","burst","maxInFlight"]),i(E.admission.perSecond,1,1e3,l),i(E.admission.burst,1,1e3,l),i(E.admission.maxInFlight,1,1e3,l);let T=(A,m)=>{let O=new Set;for(let C of A)c(C?.code,m),O.has(C.code)&&n(m,"duplicate code"),O.add(C.code)};T(r(E.reads,32,l),l),T(r(E.quotas,16,l),l),T(r(E.commands,32,l),l);for(let A of E.reads){let m=`${l}/reads/${A.code}`;s(A,m,["code","resourceCode","parameters","select","where","limit","scope","freshSeconds","staleSeconds","maxKeys","sourcePerSecond","dependencies"]);let O=a(A.resourceCode,m);_(A.parameters,m),["subject","application"].includes(A.scope)||n(m,"invalid cache scope"),A.scope==="application"&&O.dataPolicyCode&&n(m,"shared cache cannot bypass a row policy");let C=r(A.select,32,m);C.length||n(m,"select required"),C.forEach(y=>f(O,y,m));let b=r(A.dependencies,64,m);b.forEach(y=>f(O,y,m));for(let y of r(A.where||[],8,m))s(y,m,["field","value"]),f(O,y.field,m),d(y.value,A.parameters,m),A.scope==="application"&&y.value.from==="actor"&&n(m,"actor requires subject cache"),b.includes(y.field)||n(m,"filter dependency missing");C.some(y=>!b.includes(y))&&n(m,"selected field dependency missing"),i(A.limit,1,100,m),i(A.freshSeconds,1,300,m),i(A.staleSeconds,0,300,m),i(A.maxKeys,1,1e4,m),i(A.sourcePerSecond,1,20,m)}for(let A of E.quotas){let m=`${l}/quotas/${A.code}`;s(A,m,["code","sourceResource","capacityField","allocationResource","allocationField","reservationSeconds"]);let O=a(A.sourceResource,m),C=a(A.allocationResource,m);f(O,A.capacityField,m)?.type!=="number.integer"&&n(m,"capacity must be an integer"),(f(C,A.allocationField,m)?.type!=="uuid"||f(C,A.allocationField,m)?.nullable!==!1)&&n(m,"allocation reference must be a uuid"),C.surface?.mutationOwner!=="queued-command"&&n(m,"allocation model must be command owned"),A.reservationSeconds!==void 0&&i(A.reservationSeconds,10,86400,m)}new Set(E.quotas.map(A=>A.allocationResource)).size!==E.quotas.length&&n(l,"an allocation model has exactly one pool owner");for(let A of E.commands){let m=`${l}/commands/${A.code}`;s(A,m,["code","mode","intake","execution","capability","parameters","resourceKey","admission","deadlineSeconds","guards","operations","quota"]),A.mode!==void 0&&!["permit","durable"].includes(A.mode)&&n(m,"unsupported mode");let O=A.mode==="durable";if(_(A.parameters,m,O),d(A.resourceKey,A.parameters,m),o.some(C=>C.code===A.capability)||n(m,"command capability must be declared"),s(A.admission,m,["perSecond","burst","maxInFlight","maxQueue","maxWaitSeconds","permitSeconds"]),i(A.admission.perSecond,1,E.admission.perSecond,m),i(A.admission.burst,1,E.admission.burst,m),i(A.admission.maxInFlight,1,E.admission.maxInFlight,m),i(A.admission.maxQueue,1,1e4,m),i(A.admission.maxWaitSeconds,1,3600,m),(!O||A.admission.permitSeconds!==void 0)&&i(A.admission.permitSeconds,5,60,m),i(A.deadlineSeconds,10,3600,m),O){(A.operations!==void 0||A.guards!==void 0||A.quota!==void 0)&&n(m,"backend-plan does not accept static operations, guards or quota"),s(A.intake,m,["perSecond","burst","maxInFlight"]);for(let y of["perSecond","burst","maxInFlight"])i(A.intake[y],1,1e3,m);let C=s(A.execution,m,["kind","handlerCode","timeoutMs","resources","directory"]);C.kind!=="backend-plan"&&n(m,"durable requires backend-plan"),c(C.handlerCode,m),i(C.timeoutMs,100,3e4,m);let b=r(C.resources,32,m);b.length||n(m,"execution resources required"),new Set(b.map(y=>y.resourceCode)).size!==b.length&&n(m,"duplicate execution resource");for(let y of b){s(y,m,["resourceCode","readFields","writeOperations","writeFields"]);let S=a(y.resourceCode,m);for(let F of["readFields","writeFields"]){let J=r(y[F],64,m);new Set(J).size!==J.length&&n(m,"duplicate field"),J.forEach(M=>{F==="readFields"&&Dt.has(M)||f(S,M,m)})}let P=r(y.writeOperations,3,m);(new Set(P).size!==P.length||P.some(F=>!["create","update","increment"].includes(F)))&&n(m,"unsupported execution operation"),y.writeFields.some(F=>["id","revision","created_by","updated_by","created_at","updated_at"].includes(F))&&n(m,"record metadata is platform owned"),!P.length&&y.writeFields.length&&n(m,"write fields require an operation"),P.length&&!y.writeFields.length&&n(m,"write operations require fields"),E.quotas.some(F=>F.allocationResource===y.resourceCode)&&P.length&&n(m,"allocation references remain owned by their pool command")}if(C.directory!==void 0){s(C.directory,m,["mode","fields"]),C.directory.mode!=="current-initiator"&&n(m,"only current initiator allowed");let y=r(C.directory.fields,4,m);(!y.length||new Set(y).size!==y.length||y.some(S=>!["displayName","employeeNumber","primaryDepartment","departments"].includes(S)))&&n(m,"unsupported directory fields")}continue}(A.execution!==void 0||A.intake!==void 0)&&n(m,"execution and intake require durable mode");for(let C of r(A.guards||[],8,m)){s(C,m,["resourceCode","id","conditions"]);let b=a(C.resourceCode,m);u(C.id,A.parameters,m);for(let y of r(C.conditions,16,m)){s(y,m,["kind","field","operator","value"]);let S=f(b,y.field,m);["eq","neq","lt","lte","gt","gte"].includes(y.operator)||n(m,"unsupported guard"),y.kind==="database-now"?(S?.type!=="datetime"||!["lt","lte","gt","gte"].includes(y.operator)||y.value!==void 0)&&n(m,"database-now requires datetime and an ordering operator"):(y.kind!==void 0&&y.kind!=="value"&&n(m,"unsupported condition kind"),d(y.value,A.parameters,m))}}for(let C of r(A.operations,8,m)){s(C,m,["operation","resourceCode","id","expectedRevision","data"]);let b=a(C.resourceCode,m);b.surface?.mutationOwner!=="queued-command"&&n(m,"command mutations require command owned models");let y=E.quotas.find(S=>S.allocationResource===C.resourceCode);y&&(C.operation==="create"?A.quota?.action!=="allocate"||A.quota.pool!==y.code:Object.hasOwn(C.data||{},y.allocationField))&&n(m,"allocation references are owned by their pool command"),["create","update"].includes(C.operation)||n(m,"unsupported operation"),C.operation==="update"?(u(C.id,A.parameters,m),I(C.expectedRevision,A.parameters,m)):(C.id!==void 0||C.expectedRevision!==void 0)&&n(m,"create has no caller supplied id/revision"),s(C.data,m,Object.keys(C.data||{})),Object.keys(C.data).length>32&&n(m,"too many fields");for(let[S,P]of Object.entries(C.data))S==="id"&&n(m,"record identifiers are platform owned"),f(b,S,m),d(P,A.parameters,m,A.quota?.action==="allocate")}if(A.quota){let C=s(A.quota,m,["pool","action","units","mode","allocation"]),b=E.quotas.find(y=>y.code===C.pool);b||n(m,"unknown quota pool"),u(A.resourceKey,A.parameters,m),C.action==="allocate"?(s(C,m,["pool","action","units","mode"]),i(C.units,1,1e3,m),(!["committed","reserved"].includes(C.mode)||C.mode==="reserved"&&!b.reservationSeconds)&&n(m,"invalid allocation mode"),(A.operations.length!==1||A.operations[0].operation!=="create"||A.operations[0].resourceCode!==b.allocationResource||A.operations[0].data[b.allocationField]?.from!=="allocation")&&n(m,"allocation must atomically create its bound business record")):["confirm","release"].includes(C.action)?(s(C,m,["pool","action","allocation"]),u(C.allocation,A.parameters,m),A.operations.length&&n(m,"lifecycle owns allocation state; business reference remains immutable")):n(m,"invalid quota action")}else A.operations.length||n(m,"operations required")}let g=E.commands.filter(A=>A.mode==="durable").map(A=>A.execution.handlerCode);return new Set(g).size!==g.length&&n(l,"handler code must be unique"),JSON.parse(JSON.stringify(E))}var ye=class extends Error{constructor(o,n){super(`\u91D1\u989D\u751F\u547D\u5468\u671F\u58F0\u660E\u65E0\u6548\uFF1A${n}\uFF08${o}\uFF09`);this.pointer=o;this.reason=n}pointer;reason;code="NATIVE_DECIMAL_LIFECYCLE_INVALID"},Yt=["parentTransitions","childTransitions","fulfilledChildStatuses","lockedParentStatuses"],vn=["amountFieldCode","currencyFieldCode","relationFieldCode","parentFieldCode","rootFieldCode","statusFieldCode","parentRelationValue","childRelationValue"],at=e=>!!(e&&typeof e=="object"&&!Array.isArray(e)),rt=e=>Array.isArray(e)?e.filter(at):[],Ae=(e,t)=>{throw new ye(e,t)},Gt=e=>typeof e=="string"&&/^[A-Za-z0-9._:-]{1,128}$/.test(e),qt=(e,t)=>e<t?-1:e>t?1:0;function ct(e,t="/decimalReservationLifecycle"){if(e===void 0)return;if(!at(e)||Object.keys(e).some(s=>!Yt.includes(s))||Yt.some(s=>!Object.prototype.hasOwnProperty.call(e,s)))return Ae(t,"\u5FC5\u987B\u5B8C\u6574\u58F0\u660E\u56DB\u9879\u89C4\u5219\uFF0C\u4E0D\u80FD\u5305\u542B\u672A\u77E5\u5C5E\u6027");let o=s=>{let i=e[s];if(!Array.isArray(i)||i.length>64)return Ae(`${t}/${s}`,"\u72B6\u6001\u8FB9\u6700\u591A 64 \u6761");let c=new Set;return i.map((r,a)=>{let f=`${t}/${s}/${a}`;if(!at(r)||Object.keys(r).some(d=>d!=="from"&&d!=="to")||!Gt(r.from)||!Gt(r.to)||r.from===r.to)return Ae(f,"\u72B6\u6001\u8FB9\u5FC5\u987B\u5305\u542B\u4E0D\u540C\u7684\u6709\u6548 from/to");let _=JSON.stringify([r.from,r.to]);return c.has(_)?Ae(f,"\u72B6\u6001\u8FB9\u4E0D\u80FD\u91CD\u590D"):(c.add(_),{from:r.from,to:r.to})}).sort((r,a)=>qt(r.from,a.from)||qt(r.to,a.to))},n=s=>{let i=e[s];return!Array.isArray(i)||i.length<1||i.length>16||i.some(c=>!Gt(c))||new Set(i).size!==i.length?Ae(`${t}/${s}`,"\u72B6\u6001\u96C6\u5408\u5FC5\u987B\u5305\u542B 1 \u5230 16 \u4E2A\u4E0D\u91CD\u590D\u7684\u6709\u6548\u72B6\u6001"):[...i].sort(qt)};return{parentTransitions:o("parentTransitions"),childTransitions:o("childTransitions"),fulfilledChildStatuses:n("fulfilledChildStatuses"),lockedParentStatuses:n("lockedParentStatuses")}}function Kt(e,t,o="/config/data/resources"){rt(e).forEach((n,s)=>{let i=`${o}/${s}/decimalReservationLifecycle`,c=ct(n.decimalReservationLifecycle,i);if(!c)return;let r=rt(t).map(d=>d.platformAccess?.decimalReservation).filter(d=>at(d)&&d.resourceCode===n.code),a=r.find(d=>d.mode==="reserve");if(!a)return Ae(i,"\u9700\u8981\u540C\u8D44\u6E90\u5DF2\u58F0\u660E\u7684 reserve \u52A8\u4F5C\u6620\u5C04");if(vn.some(d=>typeof a[d]!="string")||r.some(d=>vn.some(u=>d[u]!==a[u])))return Ae(i,"\u540C\u8D44\u6E90\u989D\u5EA6\u52A8\u4F5C\u7684\u5B57\u6BB5\u6620\u5C04\u5FC5\u987B\u4E00\u81F4");let f=rt(n.schema?.fields).find(d=>d.code===a.statusFieldCode);if(f?.type!=="option.single")return Ae(i,"\u989D\u5EA6\u72B6\u6001\u5B57\u6BB5\u5FC5\u987B\u4E3A option.single");let _=new Set(rt(f.options).map(d=>d.value));for(let d of Yt)if((d==="parentTransitions"||d==="childTransitions"?c[d].flatMap(I=>[I.from,I.to]):c[d]).some(I=>!_.has(I)))return Ae(`${i}/${d}`,"\u72B6\u6001\u5FC5\u987B\u6765\u81EA\u989D\u5EA6\u72B6\u6001\u5B57\u6BB5\u7684\u9009\u9879");if(r.some(d=>d.mode==="reserve"&&Array.isArray(d.eligibleParentStatuses)&&d.eligibleParentStatuses.some(u=>c.lockedParentStatuses.includes(String(u)))))return Ae(`${i}/lockedParentStatuses`,"\u9501\u5B9A\u7236\u72B6\u6001\u4E0D\u80FD\u5141\u8BB8\u65B0\u9884\u7559")})}var Ln=require("crypto");var Ht=new Set(["option.single","user.single","department.single","resource-ref.single"]),Es=new Set(["option.multiple","cascade.single","cascade.multiple","user.multiple","department.multiple","resource-ref.multiple","address","location","json"]),kn=new Set(["option.multiple","cascade.single","cascade.multiple","user.multiple","department.multiple","resource-ref.multiple","file","image"]),As=new Set(["option.single","user.single","department.single","resource-ref.single","signature","address","location"]),ms=new Set([...Ht,...kn,"signature","address","location","json"]);function Is(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=>xn(n,o.has(n.code))).sort((n,s)=>n.code.localeCompare(s.code))}function xn(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:Ss(e),index:Rs(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 gs(e,t){if(t.type==="subtable")return null;let o=ne(t.code),n=Un(e,t),s=[n?` DEFAULT ${n}`:"",Ds(o,t),Ts(o,t)].join("");return`${o} ${t.storage}${s}`}function Ns(e,t){return Un(e,t)}function Ts(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 Cs(e){return e.type==="serial-number"||Me(e.type)&&e.type!=="subtable"}function bs(e,t){return t.filter(o=>o.type==="serial-number").map(o=>{let n=lt(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 Os(e,t){let o=dt(e);return t.filter(n=>n.type==="serial-number").map(n=>`ALTER SEQUENCE ${lt(e,n.code)} OWNED BY ${o}.${ne(n.code)}`)}function ys(e,t){return t.filter(o=>o.type==="serial-number").map(o=>`GRANT USAGE, SELECT ON SEQUENCE ${lt(e,o.code)} TO "openxiangda_data_api"`)}function hs(e,t){let o=dt(e),n=[];for(let s of t){if(s.type==="subtable")continue;let i=ne(s.code),c=ne(Te("idx",e,s.code,s.index));switch(s.index){case"btree":n.push(`CREATE INDEX IF NOT EXISTS ${c} ON ${o} (${i})`);break;case"btree-snapshot-expressions":{let r=ne(Te("idx",e,s.code,"snapshot-value")),a=ne(Te("idx",e,s.code,"snapshot-label"));n.push(`CREATE INDEX IF NOT EXISTS ${r} ON ${o} ((${i} ->> 'value'))`,`CREATE INDEX IF NOT EXISTS ${a} ON ${o} ((${i} ->> 'label'))`);break}case"gin-jsonb-path":n.push(`CREATE INDEX IF NOT EXISTS ${c} ON ${o} USING GIN (${i} jsonb_path_ops)`);break;case"gist-range":n.push(`CREATE INDEX IF NOT EXISTS ${c} ON ${o} USING GIST (${i})`);break;case"gin-trigram":{let r=Ht.has(s.type)?`((${i} ->> 'label')) gin_trgm_ops`:`${i} gin_trgm_ops`;n.push(`CREATE INDEX IF NOT EXISTS ${c} ON ${o} USING GIN (${r})`);break}case"none":break}if(s.type==="serial-number"){let r=ne(Te("uidx",e,s.code,"serial"));n.push(`CREATE UNIQUE INDEX IF NOT EXISTS ${r} ON ${o} (${i})`)}}return n}function $s(e,t,o,n){let s=dt(e),i=dt(t),c=ne(Te("uidx",e,"environment_id","subtable-parent")),r=ne(Te("idx",t,o,n,"subtable-child")),a=ne(Te("fk",t,o,e)),f=ne(o),_=ne(n);return[`CREATE UNIQUE INDEX IF NOT EXISTS ${c} ON ${s} ("tenant_id", "app_code", "environment_key", "id")`,`CREATE INDEX IF NOT EXISTS ${r} ON ${i} ("tenant_id", "app_code", "environment_key", ${f}, ${_}, "id")`,`DO $native_subtable$ BEGIN
2
- ALTER TABLE ${i}
3
- ADD CONSTRAINT ${a}
4
- FOREIGN KEY ("tenant_id", "app_code", "environment_key", ${f})
5
- REFERENCES ${s} ("tenant_id", "app_code", "environment_key", "id")
1
+ "use strict";var Jo=Object.create;var tt=Object.defineProperty;var zo=Object.getOwnPropertyDescriptor;var qo=Object.getOwnPropertyNames;var Ko=Object.getPrototypeOf,Yo=Object.prototype.hasOwnProperty;var Ho=(e,t)=>{for(var o in t)tt(e,o,{get:t[o],enumerable:!0})},Vn=(e,t,o,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of qo(t))!Yo.call(e,i)&&i!==o&&tt(e,i,{get:()=>t[i],enumerable:!(n=zo(t,i))||n.enumerable});return e};var Xo=(e,t,o)=>(o=e!=null?Jo(Ko(e)):{},Vn(t||!e||!e.__esModule?tt(o,"default",{value:e,enumerable:!0}):o,e)),Qo=e=>Vn(tt({},"__esModule",{value:!0}),e);var wr={};Ho(wr,{DATA_AUDIT_METADATA_FIELDS:()=>Wt,DATA_EVENT_TYPES_V2:()=>yt,DATA_SYSTEM_SORT_FIELD_CODES:()=>jn,ManagedConcurrencyContractError:()=>Le,NATIVE_CONFIGURATION_VALIDATOR_DIGEST:()=>Vr,NATIVE_CONTRACT_CAPACITY_V2:()=>K,NATIVE_DATA_POLICY_EXPRESSION_MAX_CLAUSES:()=>Aa,NATIVE_DATA_POLICY_EXPRESSION_MAX_DEPTH:()=>pa,NATIVE_DATA_POLICY_EXPRESSION_MAX_GROUP_ITEMS:()=>_a,NATIVE_DATA_POLICY_EXPRESSION_MAX_LEAVES:()=>Ea,NATIVE_DATA_POLICY_EXPRESSION_MAX_OCCURRENCES:()=>ma,NATIVE_DATA_QUERY_OPERATORS_V2:()=>Wn,NATIVE_UNIQUE_KEY_MAX_BYTES:()=>ia,NATIVE_UNIQUE_KEY_NORMALIZERS:()=>ln,NativeConfigurationCompilerError:()=>Rt,NativeDataFieldContractV2Error:()=>le,NativeDataPolicyExpressionV2Error:()=>Ue,NativeDecimalLifecycleContractError:()=>he,NativeEventActionContractError:()=>Tt,NativeScopeSourceFieldPathV2Error:()=>mt,NativeUniqueKeyContractError:()=>xe,OPENXIANGDA_NATIVE_DATA_FIELD_TYPES_V2:()=>kn,OPENXIANGDA_NATIVE_DATA_SURFACE_KEYS_V2:()=>Ne,OPENXIANGDA_NATIVE_DRAFT_STATE_KEYS_V2:()=>dt,OPENXIANGDA_NATIVE_SYSTEM_FIELDS_V2:()=>it,OPENXIANGDA_NATIVE_SYSTEM_FIELD_MAP_V2:()=>jt,WORKFLOW_CONFIGURABLE_OPERATIONS:()=>Ct,WORKFLOW_CONFIGURABLE_PROVIDERS:()=>gn,WORKFLOW_EVENT_TYPES_V2:()=>ht,compileNativeApplicationConfiguration:()=>js,compileNativeEventAction:()=>fn,compileNativeEventCapturePlansV2:()=>wo,compileRequiredPlatformCapabilitiesV3:()=>Vo,formatWorkflowExpression:()=>Ke,hasDataAuditReadPolicy:()=>Bt,isDataAuditMetadataField:()=>we,isDataSystemSortField:()=>Gt,isNativeDataQueryOperatorV2:()=>ui,isNativeMultiValueFieldV2:()=>Ge,materializeNativeDataQueryPathTypesV2:()=>is,nativeDataPolicyExpressionLeavesV2:()=>Xe,nativeDataPolicyExpressionToCnfV2:()=>Tn,nativeDataQueryPathPlanV2:()=>ss,nativeFieldAggregatePlanV2:()=>gi,nativeFieldColumnDefinitionV2:()=>Pi,nativeFieldDefaultSqlV2:()=>vi,nativeFieldHasDefaultV2:()=>ki,nativeFieldIndexStatementsV2:()=>Mi,nativeFieldRequiresCreateInputV2:()=>Je,nativeFieldSequenceGrantStatementsV2:()=>Ui,nativeFieldSequenceOwnershipStatementsV2:()=>ji,nativeFieldSequenceStatementsV2:()=>xi,nativeFieldSupportsFilterV2:()=>Yt,nativeFieldSupportsOperatorV2:()=>Ai,nativeFieldSupportsSearchV2:()=>at,nativeFieldSupportsSortV2:()=>Pe,nativeOperatorsForFieldV2:()=>Kt,nativePhysicalFieldV2:()=>Qn,nativePhysicalFieldsV2:()=>Fi,nativePhysicalObjectNameV2:()=>be,nativeScopeSourceFieldValueV2:()=>Ki,nativeScopeSourceGrantPathSupportedV2:()=>an,nativeScopeSourceSubjectPathSupportedV2:()=>It,nativeSubtableConstraintStatementsV2:()=>Wi,nativeUniqueKeysJsonSchema:()=>as,parseDecimalReservationLifecycle:()=>_t,parseNativeDataFieldsV2:()=>st,parseNativeDataResourceInvariantsV2:()=>Mt,parseNativeUniqueKeys:()=>un,projectNativeDataResourceViewV2:()=>ut,projectWorkflowGraph:()=>us,projectWorkflowNodePolicy:()=>_s,quoteNativeIdentifierV2:()=>ne,resolveNativeScopeSourceFieldPathV2:()=>ke,validateDecimalReservationLifecycles:()=>sn,validateManagedConcurrency:()=>en,validateNativeDataDraftStateV2:()=>Xt,validateNativeDataResourceReferencesV2:()=>Ut,validateNativeDataResourceSurfaceV2:()=>lt,validateWorkflowAdministration:()=>Ot,validateWorkflowInstanceCommandPolicies:()=>_n,validateWorkflowNodeConfigurationPatch:()=>ps,validateWorkflowReadability:()=>mn,workflowExpressionPaths:()=>An,workflowInstanceCommandDeadlineError:()=>ds,workflowInstanceTerminateCapabilityAllowed:()=>cs,workflowNodeAllowedOperations:()=>je,workflowPolicyTimestamp:()=>pn});module.exports=Qo(wr);var wn=require("node:crypto");function Zo(e){if(!e||typeof e!="object")return!1;let t=Object.getPrototypeOf(e);return t===Object.prototype||t===null}function vt(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)=>vt(n,`${t}[${i}]`)).join(",")}]`;if(Zo(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)}:${vt(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 Q(e){return vt(e,"$")}function ee(e){return(0,wn.createHash)("sha256").update(Q(e)).digest("hex")}var Ln=/^[A-Za-z][A-Za-z0-9_]{0,62}$/,xt=/^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/,kn=["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"],ei=new Set(kn),xn=new Set(["option.multiple","cascade.multiple","user.multiple","department.multiple","resource-ref.multiple","file","image","subtable"]),Fn=new Set(["option.single","option.multiple","cascade.single","cascade.multiple"]),Pn=new Set(["resource-ref.single","resource-ref.multiple"]),it=[{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}],jt=new Map(it.map(e=>[e.code,e])),le=class extends Error{constructor(o,n){super(o);this.code=o;this.pointer=n;this.name="NativeDataFieldContractV2Error"}code;pointer};function Ge(e){return xn.has(e)}function Je(e,t={}){return e.type!=="serial-number"&&t.system!==!0&&e.nullable===!1&&(!Ge(e.type)||t.requiredHint===!0)}function st(e,t,o=500){Array.isArray(e)||D("NATIVE_ARRAY_REQUIRED",t),e.length===0&&D("NATIVE_DATA_FIELDS_REQUIRED",t),e.length>o&&D("NATIVE_ARRAY_LIMIT_EXCEEDED",t);let n=new Set;return e.map((i,r)=>{let a=`${t}/${r}`,s=re(i,a);de(s,["code","type","nullable","indexed","options","source","maxLength","precision","scale","exactDecimal","min","max","rangeBoundary","timePrecision","file","serial","subtable"],a);let c=ue(s.code,`${a}/code`,63);Ln.test(c)||D("NATIVE_FIELD_CODE_INVALID",`${a}/code`),n.has(c)&&D("NATIVE_DATA_FIELD_DUPLICATE",`${a}/code`),n.add(c);let u=ue(s.type,`${a}/type`,32);ei.has(u)||D("NATIVE_DATA_FIELD_TYPE_INVALID",`${a}/type`);let _=u,d=kt(s.nullable,`${a}/nullable`),p=kt(s.indexed,`${a}/indexed`);d===!0&&xn.has(_)&&D("NATIVE_DATA_MULTI_FIELD_NULLABLE_INVALID",`${a}/nullable`);let I=oi(s.options,_,a),l=ii(s.source,_,a),E=ri(s,_,a),N=kt(s.exactDecimal,`${a}/exactDecimal`);N!==void 0&&_!=="number.decimal"&&D("NATIVE_DATA_FIELD_EXACT_DECIMAL_TYPE_INVALID",`${a}/exactDecimal`);let g=ti(s.rangeBoundary,_,a),A=ai(s.file,_,a),m=ci(s.serial,_,a),O=di(s.subtable,_,a);return{code:c,type:_,...d===void 0?{}:{nullable:d},...p===void 0?{}:{indexed:p},...I?{options:I}:{},...l?{source:l}:{},...E,...N===void 0?{}:{exactDecimal:N},...g?{rangeBoundary:g}:{},...A?{file:A}:{},...m?{serial:m}:{},...O?{subtable:O}:{}}})}function ti(e,t,o){let n=`${o}/rangeBoundary`;if(!(t==="date-range"||t==="datetime-range")){e!==void 0&&D("NATIVE_DATA_FIELD_RANGE_BOUNDARY_TYPE_INVALID",n);return}return e!=="closed"&&e!=="half-open"&&D("NATIVE_DATA_FIELD_RANGE_BOUNDARY_REQUIRED",n),e}function Ut(e,t){Array.isArray(e)||D("NATIVE_ARRAY_REQUIRED",t);let o=new Map;e.forEach((n,i)=>{let r=`${t}/${i}`,a=re(n,r),s=ue(a.code,`${r}/code`,64);(!xt.test(s)||o.has(s))&&D("NATIVE_RESOURCE_CODE_INVALID",`${r}/code`);let c=re(a.schema,`${r}/schema`);o.set(s,{pointer:r,fields:st(c.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,c)=>s+(c.subtable?.maxRows??20),0)>49&&D("NATIVE_DATA_FIELD_SUBTABLE_AGGREGATE_MAX_ROWS_EXCEEDED",`${i.pointer}/schema/fields`),i.fields.forEach((s,c)=>{let u=`${i.pointer}/schema/fields/${c}`;if(s.source&&ni(s.source,r,o,`${u}/source`),s.subtable){let _=o.get(s.subtable.resourceCode);(!_||s.subtable.resourceCode===n)&&D("NATIVE_DATA_FIELD_SUBTABLE_TARGET_MISSING",`${u}/subtable/resourceCode`);let d=_.fields.find(I=>I.code===s.subtable?.foreignKey);(!d||d.type!=="uuid"||d.nullable!==!1)&&D("NATIVE_DATA_FIELD_SUBTABLE_FOREIGN_KEY_INVALID",`${u}/subtable/foreignKey`);let p=_.fields.find(I=>I.code===s.subtable?.orderField);(!p||p.type!=="number.integer"||p.nullable!==!1)&&D("NATIVE_DATA_FIELD_SUBTABLE_ORDER_FIELD_INVALID",`${u}/subtable/orderField`)}})}}function Mt(e,t,o){if(e===void 0)return[];(!Array.isArray(e)||e.length>20)&&D("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}`,c=re(r,s);de(c,["code","message","expression"],s);let u=ue(c.code,`${s}/code`,128);(!/^[a-z][a-z0-9]*(?:[._-][a-z0-9]+)*$/.test(u)||i.has(u))&&D("NATIVE_DATA_RESOURCE_INVARIANT_CODE_INVALID",`${s}/code`),i.add(u);let _=ot(c.message,`${s}/message`,500);_!==void 0&&_.length===0&&D("NATIVE_DATA_RESOURCE_INVARIANT_MESSAGE_INVALID",`${s}/message`);let d=re(c.expression,`${s}/expression`);if(d.kind==="nonBlankTextWhenOption"){de(d,["kind","optionField","optionValue","textField"],`${s}/expression`);let A=Ee(d.optionField,`${s}/expression/optionField`),m=Ee(d.textField,`${s}/expression/textField`),O=ue(d.optionValue,`${s}/expression/optionValue`,128),b=n.get(A),C=n.get(m);return(!b||!C)&&D("NATIVE_DATA_RESOURCE_INVARIANT_FIELD_UNKNOWN",`${s}/expression`),(b.type!=="option.single"||!["text.short","text.long"].includes(C.type)||!b.options?.some(y=>y.value===O))&&D("NATIVE_DATA_RESOURCE_INVARIANT_FIELD_TYPES_INVALID",`${s}/expression`),{code:u,..._===void 0?{}:{message:_},expression:{kind:"nonBlankTextWhenOption",optionField:A,optionValue:O,textField:m}}}de(d,["leftField","operator","rightField"],`${s}/expression`);let p=Ee(d.leftField,`${s}/expression/leftField`),I=Ee(d.rightField,`${s}/expression/rightField`),l=n.get(p),E=n.get(I);(!l||!E)&&D("NATIVE_DATA_RESOURCE_INVARIANT_FIELD_UNKNOWN",`${s}/expression`),l.type===E.type||["number.integer","number.decimal"].includes(l.type)&&["number.integer","number.decimal"].includes(E.type)||D("NATIVE_DATA_RESOURCE_INVARIANT_FIELD_TYPES_INVALID",`${s}/expression`);let g=String(d.operator);return["eq","neq","gt","gte","lt","lte"].includes(g)||D("NATIVE_DATA_RESOURCE_INVARIANT_OPERATOR_INVALID",`${s}/expression/operator`),!["eq","neq"].includes(g)&&!["number.integer","number.decimal","date","time","datetime","text.short","text.long","text.rich","serial-number","uuid"].includes(l.type)&&D("NATIVE_DATA_RESOURCE_INVARIANT_FIELD_TYPES_INVALID",`${s}/expression`),{code:u,..._===void 0?{}:{message:_},expression:{leftField:p,operator:g,rightField:I}}})}function ni(e,t,o,n){let i=o.get(e.resourceCode);i||D("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))&&D("NATIVE_DATA_FIELD_SOURCE_LABEL_INVALID",`${n}/labelField`);for(let s of["searchFields","descriptionFields","snapshotFields"])for(let c of e[s]||[])r.has(c)||D("NATIVE_DATA_FIELD_SOURCE_FIELD_MISSING",`${n}/${s}`);for(let[s,c]of(e.filters||[]).entries())r.has(c.field)||D("NATIVE_DATA_FIELD_SOURCE_FILTER_FIELD_MISSING",`${n}/filters/${s}/field`),"binding"in c&&!t.has(c.binding.field)&&D("NATIVE_DATA_FIELD_SOURCE_BINDING_FIELD_MISSING",`${n}/filters/${s}/binding/field`)}function oi(e,t,o){let n=`${o}/options`;if(e===void 0){Fn.has(t)&&D("NATIVE_DATA_FIELD_OPTIONS_REQUIRED",n);return}(!Fn.has(t)||!Array.isArray(e))&&D("NATIVE_DATA_FIELD_OPTIONS_TYPE_INVALID",n),(e.length<1||e.length>100)&&D("NATIVE_DATA_FIELD_OPTIONS_INVALID",n);let i=0,r=(a,s,c)=>{c>5&&D("NATIVE_DATA_FIELD_OPTIONS_DEPTH_EXCEEDED",s);let u=new Set;return a.map((_,d)=>{i+=1,i>1e3&&D("NATIVE_DATA_FIELD_OPTIONS_COUNT_EXCEEDED",n);let p=`${s}/${d}`,I=re(_,p);de(I,["label","value","description","color","children"],p);let l=ue(I.label,`${p}/label`,500),E=ue(I.value,`${p}/value`,500);u.has(E)&&D("NATIVE_DATA_FIELD_OPTION_VALUE_DUPLICATE",`${p}/value`),u.add(E);let N=ot(I.description,`${p}/description`,2e3),g=ot(I.color,`${p}/color`,64),A;return I.children!==void 0&&((!t.startsWith("cascade.")||!Array.isArray(I.children))&&D("NATIVE_DATA_FIELD_OPTION_CHILDREN_INVALID",`${p}/children`),(I.children.length<1||I.children.length>100)&&D("NATIVE_DATA_FIELD_OPTION_CHILDREN_INVALID",`${p}/children`),A=r(I.children,`${p}/children`,c+1)),{label:l,value:E,...N===void 0?{}:{description:N},...g===void 0?{}:{color:g},...A?{children:A}:{}}})};return r(e,n,1)}function ii(e,t,o){let n=`${o}/source`;if(e===void 0){Pn.has(t)&&D("NATIVE_DATA_FIELD_SOURCE_REQUIRED",n);return}Pn.has(t)||D("NATIVE_DATA_FIELD_SOURCE_TYPE_INVALID",n);let i=re(e,n);de(i,["kind","resourceCode","labelField","searchFields","descriptionFields","snapshotFields","filters","pageSize","loadMode"],n),i.kind!=="resource"&&D("NATIVE_DATA_FIELD_SOURCE_KIND_INVALID",`${n}/kind`);let r=ue(i.resourceCode,`${n}/resourceCode`,64);xt.test(r)||D("NATIVE_RESOURCE_CODE_INVALID",`${n}/resourceCode`);let a=Ee(i.labelField,`${n}/labelField`),s=Lt(i.searchFields,`${n}/searchFields`,10),c=Lt(i.descriptionFields,`${n}/descriptionFields`,10),u=Lt(i.snapshotFields,`${n}/snapshotFields`,50),_=Ve(i.pageSize,`${n}/pageSize`,1,100),d;i.loadMode!==void 0&&(["search","all"].includes(String(i.loadMode))||D("NATIVE_DATA_FIELD_SOURCE_LOAD_MODE_INVALID",`${n}/loadMode`),d=i.loadMode);let p=si(i.filters,`${n}/filters`);return{kind:"resource",resourceCode:r,labelField:a,...s?{searchFields:s}:{},...c?{descriptionFields:c}:{},...u?{snapshotFields:u}:{},...p?{filters:p}:{},..._===void 0?{}:{pageSize:_},...d?{loadMode:d}:{}}}function si(e,t){if(e!==void 0)return(!Array.isArray(e)||e.length>20)&&D("NATIVE_DATA_FIELD_SOURCE_FILTERS_INVALID",t),e.map((o,n)=>{let i=`${t}/${n}`,r=re(o,i),a=Object.prototype.hasOwnProperty.call(r,"value"),s=Object.prototype.hasOwnProperty.call(r,"binding");de(r,a?["field","operator","value"]:["field","operator","binding"],i),a===s&&D("NATIVE_DATA_FIELD_SOURCE_FILTER_VALUE_INVALID",i);let c=Ee(r.field,`${i}/field`);["eq","in"].includes(String(r.operator))||D("NATIVE_DATA_FIELD_SOURCE_FILTER_OPERATOR_INVALID",`${i}/operator`);let u=r.operator;if(a)return{field:c,operator:u,value:r.value};let _=re(r.binding,`${i}/binding`);return de(_,["kind","field"],`${i}/binding`),_.kind!=="field"&&D("NATIVE_DATA_FIELD_SOURCE_BINDING_KIND_INVALID",`${i}/binding/kind`),{field:c,operator:u,binding:{kind:"field",field:Ee(_.field,`${i}/binding/field`)}}})}function ri(e,t,o){let n={};if(e.maxLength!==void 0&&(["text.short","text.long","text.rich"].includes(t)||D("NATIVE_DATA_FIELD_MAX_LENGTH_TYPE_INVALID",`${o}/maxLength`),n.maxLength=nt(e.maxLength,`${o}/maxLength`,1,1e6)),(e.precision!==void 0||e.scale!==void 0)&&((t!=="number.decimal"||e.precision===void 0)&&D("NATIVE_DATA_FIELD_DECIMAL_CONFIG_INVALID",o),n.precision=nt(e.precision,`${o}/precision`,1,1e3),n.scale=e.scale===void 0?0:nt(e.scale,`${o}/scale`,0,n.precision)),e.min!==void 0||e.max!==void 0){["number.integer","number.decimal"].includes(t)||D("NATIVE_DATA_FIELD_NUMERIC_BOUNDS_TYPE_INVALID",o);let i=vn(e.min,`${o}/min`),r=vn(e.max,`${o}/max`);t==="number.integer"&&[i,r].some(a=>a!==void 0&&!Number.isSafeInteger(a))&&D("NATIVE_DATA_FIELD_NUMERIC_BOUNDS_INVALID",o),i!==void 0&&r!==void 0&&i>r&&D("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))&&D("NATIVE_DATA_FIELD_TIME_PRECISION_INVALID",`${o}/timePrecision`),n.timePrecision=e.timePrecision),n}function ai(e,t,o){if(e===void 0)return;let n=`${o}/file`;["file","image","signature"].includes(t)||D("NATIVE_DATA_FIELD_FILE_TYPE_INVALID",n);let i=re(e,n);de(i,["maxCount","maxSizeMb","accept"],n);let r=Ve(i.maxCount,`${n}/maxCount`,1,100);t==="signature"&&r!==void 0&&r!==1&&D("NATIVE_DATA_FIELD_SIGNATURE_COUNT_INVALID",`${n}/maxCount`);let a=Ve(i.maxSizeMb,`${n}/maxSizeMb`,1,1024),s;return i.accept!==void 0&&((!Array.isArray(i.accept)||i.accept.length>50)&&D("NATIVE_DATA_FIELD_FILE_ACCEPT_INVALID",`${n}/accept`),s=i.accept.map((c,u)=>ue(c,`${n}/accept/${u}`,255)),new Set(s).size!==s.length&&D("NATIVE_DATA_FIELD_FILE_ACCEPT_INVALID",`${n}/accept`)),{...r===void 0?{}:{maxCount:r},...a===void 0?{}:{maxSizeMb:a},...s===void 0?{}:{accept:s}}}function ci(e,t,o){let n=`${o}/serial`;if(e===void 0){t==="serial-number"&&D("NATIVE_DATA_FIELD_SERIAL_REQUIRED",n);return}t!=="serial-number"&&D("NATIVE_DATA_FIELD_SERIAL_TYPE_INVALID",n);let i=re(e,n);de(i,["prefix","digits","start"],n);let r=ot(i.prefix,`${n}/prefix`,64),a=Ve(i.digits,`${n}/digits`,1,32),s=Ve(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 di(e,t,o){let n=`${o}/subtable`;if(e===void 0){t==="subtable"&&D("NATIVE_DATA_FIELD_SUBTABLE_REQUIRED",n);return}t!=="subtable"&&D("NATIVE_DATA_FIELD_SUBTABLE_TYPE_INVALID",n);let i=re(e,n);de(i,["resourceCode","foreignKey","orderField","maxRows"],n);let r=ue(i.resourceCode,`${n}/resourceCode`,64);xt.test(r)||D("NATIVE_RESOURCE_CODE_INVALID",`${n}/resourceCode`);let a=Ee(i.foreignKey,`${n}/foreignKey`),s=Ee(i.orderField,`${n}/orderField`);s===a&&D("NATIVE_DATA_FIELD_SUBTABLE_ORDER_FIELD_INVALID",`${n}/orderField`);let c=Ve(i.maxRows,`${n}/maxRows`,1,49);return{resourceCode:r,foreignKey:a,orderField:s,...c===void 0?{}:{maxRows:c}}}function Lt(e,t,o){if(e===void 0)return;(!Array.isArray(e)||e.length>o)&&D("NATIVE_DATA_FIELD_SOURCE_FIELDS_INVALID",t);let n=e.map((i,r)=>Ee(i,`${t}/${r}`));return new Set(n).size!==n.length&&D("NATIVE_DATA_FIELD_SOURCE_FIELDS_INVALID",t),n}function Ee(e,t){let o=ue(e,t,63);return Ln.test(o)||D("NATIVE_FIELD_CODE_INVALID",t),o}function re(e,t){return(!e||typeof e!="object"||Array.isArray(e))&&D("NATIVE_OBJECT_REQUIRED",t),e}function de(e,t,o){let n=new Set(t);for(let i of Object.keys(e))n.has(i)||D("NATIVE_PROPERTY_UNKNOWN",`${o}/${i}`)}function ue(e,t,o){return(typeof e!="string"||e.length===0||e.length>o)&&D("NATIVE_STRING_INVALID",t),e}function ot(e,t,o){if(e!==void 0)return(typeof e!="string"||e.length>o)&&D("NATIVE_STRING_INVALID",t),e}function kt(e,t){if(e!==void 0)return typeof e!="boolean"&&D("NATIVE_BOOLEAN_REQUIRED",t),e}function Ve(e,t,o,n){if(e!==void 0)return nt(e,t,o,n)}function vn(e,t){if(e!==void 0)return(typeof e!="number"||!Number.isFinite(e))&&D("NATIVE_NUMBER_REQUIRED",t),e}function nt(e,t,o,n){return(!Number.isSafeInteger(e)||Number(e)<o||Number(e)>n)&&D("NATIVE_INTEGER_OUT_OF_RANGE",t),Number(e)}function D(e,t){throw new le(e,t)}var Wt=["created_by","updated_by","created_at","updated_at"];function we(e){return Wt.includes(e)}function Bt(e){return Wt.some(t=>Object.prototype.hasOwnProperty.call(e.fieldPolicies||{},t))}var jn=it.map(e=>e.code);function Gt(e){return jn.includes(e)}var Wn=["eq","neq","gt","gte","lt","lte","contains","startsWith","endsWith","in","between","has","hasAny","hasAll","overlaps","containedBy","jsonContains","isEmpty","isNotEmpty"],li=new Set(Wn);function ui(e){return li.has(String(e))}var Jt=["eq","neq","contains","startsWith","endsWith","in","isEmpty","isNotEmpty"],ze=["eq","neq","gt","gte","lt","lte","between","in","isEmpty"],fi=["eq","neq","in","isEmpty"],rt=["eq","neq","in","isEmpty","isNotEmpty"],Fe=["has","hasAny","hasAll","isEmpty","isNotEmpty"],Un=["overlaps","contains","containedBy","isEmpty"],zt=["jsonContains","isEmpty","isNotEmpty"],qt=["isEmpty","isNotEmpty"],pi={"text.short":Jt,"text.long":Jt,"text.rich":Jt,"number.integer":ze,"number.decimal":ze,boolean:fi,date:ze,time:ze,datetime:ze,"date-range":Un,"datetime-range":Un,"option.single":rt,"option.multiple":Fe,"cascade.single":Fe,"cascade.multiple":Fe,"user.single":rt,"user.multiple":Fe,"department.single":rt,"department.multiple":Fe,"resource-ref.single":rt,"resource-ref.multiple":Fe,file:qt,image:qt,signature:qt,address:zt,location:zt,uuid:["eq","neq","in","isEmpty"],json:zt,"serial-number":["eq","neq","in","contains","startsWith"],subtable:[]},_i=new Set(["text.short","text.long","text.rich","option.single","user.single","department.single","resource-ref.single","serial-number"]),Ei=new Set(["option.multiple","cascade.single","cascade.multiple","user.multiple","department.multiple","resource-ref.multiple","file","image","signature","address","location","json","subtable"]);function Kt(e){return pi[e]}function Ai(e,t){return Kt(e).includes(t)}function at(e){return _i.has(e)}function Pe(e){return!Ei.has(e)}function Yt(e){return Kt(e).length>0}var Mn=new Set(["number.integer","number.decimal"]),Bn=new Set(["text.short","text.long","number.integer","number.decimal","date","time","datetime","serial-number"]),mi=new Set([...Bn,"boolean","uuid"]),Ii=new Set(["option.single","user.single","department.single","resource-ref.single"]);function gi(e,t){return t==="sum"||t==="avg"?Mn.has(e)?{valueExpression:"column",numericResult:!0}:null:t==="min"||t==="max"?Bn.has(e)?{valueExpression:"column",numericResult:Mn.has(e)}:null:Ii.has(e)?{valueExpression:"snapshot-value",numericResult:!0}:mi.has(e)?{valueExpression:"column",numericResult:!0}:null}var dt=["version","maxBytes","fields"];function Xt(e,t){if(e===void 0)return;let o=Ht(e,t);Gn(o,dt,t);let n=ct(o.version,`${t}/version`,1,1e6),i=ct(o.maxBytes,`${t}/maxBytes`,2,196608);(!n||!i)&&ie("NATIVE_DATA_DRAFT_STATE_SCHEMA_INVALID",t);let r=Ht(o.fields,`${t}/fields`),a=Object.entries(r);(!a.length||a.length>50)&&ie("NATIVE_DATA_DRAFT_STATE_FIELDS_INVALID",`${t}/fields`);for(let[s,c]of a){let u=`${t}/fields/${s}`;/^[A-Za-z][A-Za-z0-9_]{0,62}$/.test(s)||ie("NATIVE_DATA_DRAFT_STATE_FIELD_CODE_INVALID",u);let _=Ht(c,u),d=Jn(_.type,`${u}/type`,32),p=d==="string"?["type","required","maxLength","enum"]:d==="json.object"?["type","required","maxBytes"]:["type","required"];if(["string","number","integer","boolean","json.object"].includes(d)||ie("NATIVE_DATA_DRAFT_STATE_FIELD_TYPE_INVALID",`${u}/type`),Gn(_,p,u),Ti(_.required,`${u}/required`),d==="string"){let I=ct(_.maxLength,`${u}/maxLength`,1,196608);I||ie("NATIVE_DATA_DRAFT_STATE_FIELD_INVALID",u),_.enum!==void 0&&Ni(_.enum,`${u}/enum`,100,!1).some(E=>E.length>I)&&ie("NATIVE_DATA_DRAFT_STATE_FIELD_INVALID",`${u}/enum`)}else if(d==="json.object"){let I=ct(_.maxBytes,`${u}/maxBytes`,2,65536);(!I||I>i)&&ie("NATIVE_DATA_DRAFT_STATE_FIELD_INVALID",u)}}}function Ni(e,t,o,n){(!Array.isArray(e)||!n&&e.length===0||e.length>o)&&ie("NATIVE_DATA_SURFACE_STRING_ARRAY_INVALID",t);let i=e.map((r,a)=>Jn(r,`${t}/${a}`,255));return new Set(i).size!==i.length&&ie("NATIVE_DATA_SURFACE_STRING_ARRAY_INVALID",t),i}function Ht(e,t){return(!e||typeof e!="object"||Array.isArray(e))&&ie("NATIVE_OBJECT_REQUIRED",t),e}function Gn(e,t,o){let n=new Set(t);for(let i of Object.keys(e))n.has(i)||ie("NATIVE_PROPERTY_UNKNOWN",`${o}/${i}`)}function Jn(e,t,o){return(typeof e!="string"||e.length===0||e.length>o)&&ie("NATIVE_STRING_INVALID",t),e}function Ti(e,t){e!==void 0&&typeof e!="boolean"&&ie("NATIVE_BOOLEAN_REQUIRED",t)}function ct(e,t,o,n){return(!Number.isSafeInteger(e)||Number(e)<o||Number(e)>n)&&ie("NATIVE_INTEGER_INVALID",t),Number(e)}function ie(e,t){throw new le(e,t)}var bi=500,Ne={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","exactDecimal","min","max","rangeBoundary","maxCount","maxSizeMb","accept","options","list","searchable","sortable","source","timePrecision","serial","subtable"],list:["actions","fieldOrder","defaultPageSize","searchableFields","filterFields","defaultSort"],defaultSort:["field","order"],form:["layout","fieldOrder","draftState"],detail:["layout","fieldOrder"],layout:["layout","fieldOrder","draftState"],draftState:dt,mobile:["enabled"]},Ci={"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 lt(e,t,o){if(e===void 0)return;let n=te(e,o);Ae(n,Ne.surface,o);let i=n.mutationOwner===void 0?"native":Te(n.mutationOwner,`${o}/mutationOwner`,16);["native","action","readonly","workflow","queued-command"].includes(i)||k("NATIVE_DATA_SURFACE_MUTATION_OWNER_INVALID",`${o}/mutationOwner`);let r=n.generated===void 0?{}:te(n.generated,`${o}/generated`);Ae(r,Ne.generated,`${o}/generated`);for(let c of Ne.generated)Zt(r[c],`${o}/generated/${c}`);if(i!=="native")for(let c of["create","update","delete"])r[c]===!0&&k("NATIVE_DATA_SURFACE_MUTATION_OWNER_CONFLICT",`${o}/generated/${c}`);let a=new Map(t.map(c=>[c.code,c])),s=te(n.fields,`${o}/fields`);for(let c of Object.keys(s))a.has(c)||k("NATIVE_DATA_SURFACE_FIELD_MISSING",`${o}/fields/${c}`);for(let c of t)Object.prototype.hasOwnProperty.call(s,c.code)||k("NATIVE_DATA_SURFACE_FIELD_REQUIRED",`${o}/fields/${c.code}`),yi(s[c.code],c,`${o}/fields/${c.code}`);for(let c of["create","update"]){let u=r[c]??i==="native",_=t.some(d=>{let p=te(s[d.code],`${o}/fields/${d.code}`);return qn(d,p,c)});u&&!_&&k("NATIVE_DATA_SURFACE_WRITABLE_FIELDS_REQUIRED",`${o}/generated/${c}`)}if(hi(n.list,a,`${o}/list`),zn(n.form,a,`${o}/form`,"form"),zn(n.detail,a,`${o}/detail`,"detail"),n.mobile!==void 0){let c=te(n.mobile,`${o}/mobile`);Ae(c,Ne.mobile,`${o}/mobile`),Zt(c.enabled,`${o}/mobile/enabled`)}Oi(n,t,o)}function ut(e,t){let o=e.views?.find(i=>i.code===t);o||k("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 Oi(e,t,o){if(e.views===void 0)return;(!Array.isArray(e.views)||e.views.length>20)&&k("NATIVE_DATA_VIEWS_LIMIT_INVALID",`${o}/views`);let n=new Set;e.views.forEach((i,r)=>{let a=`${o}/views/${r}`,s=te(i,a);Ae(s,["code","name","generated","list","form","detail","mobile","sections"],a);let c=Te(s.code,`${a}/code`,64);(!/^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/.test(c)||n.has(c))&&k("NATIVE_DATA_VIEW_CODE_INVALID",`${a}/code`),n.add(c),Te(s.name,`${a}/name`,255),te(s.generated,`${a}/generated`),te(s.mobile,`${a}/mobile`);for(let _ of["list","detail","create","update","delete"])typeof s.generated[_]!="boolean"&&k("NATIVE_DATA_VIEW_OPERATION_INVALID",`${a}/generated/${_}`);typeof s.mobile.enabled!="boolean"&&k("NATIVE_DATA_VIEW_MOBILE_INVALID",`${a}/mobile/enabled`);for(let _ of["list","form","detail"]){let d=te(s[_],`${a}/${_}`),p=ve(d.fieldOrder,`${a}/${_}/fieldOrder`,500,!0);for(let I of p){let l=e.fields[I];(!l||(l.hidden??l.system)===!0)&&k("NATIVE_DATA_VIEW_FIELD_INVALID",`${a}/${_}/fieldOrder`)}}if(s.sections!==void 0){(!Array.isArray(s.sections)||s.sections.length>100)&&k("NATIVE_DATA_VIEW_SECTIONS_INVALID",`${a}/sections`);let _=new Set;s.sections.forEach((d,p)=>{let I=`${a}/sections/${p}`,l=te(d,I);Ae(l,["title","fields"],I),Te(l.title,`${I}/title`,255);for(let E of ve(l.fields,`${I}/fields`,100,!0)){let N=e.fields[E];(!N||(N.hidden??N.system)===!0||_.has(E))&&k("NATIVE_DATA_VIEW_FIELD_INVALID",`${I}/fields`),_.add(E)}})}let u=ut(e,c);if(lt(u,t,a),s.generated.create!==!1&&(e.mutationOwner||"native")==="native")for(let _ of t)Je(_,e.fields[_.code])&&qn(_,e.fields[_.code],"create")&&!s.form.fieldOrder.includes(_.code)&&k("NATIVE_DATA_VIEW_CREATE_REQUIRED_FIELD_MISSING",`${a}/form/fieldOrder`)})}function qn(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 yi(e,t,o){let n=te(e,o);Ae(n,Ne.field,o),Te(n.label,`${o}/label`,500),n.type!==t.type&&k("NATIVE_DATA_SURFACE_FIELD_TYPE_MISMATCH",`${o}/type`);let i=Te(n.widget,`${o}/widget`,64);Ci[t.type].includes(i)||k("NATIVE_DATA_SURFACE_WIDGET_INCOMPATIBLE",`${o}/widget`),Si(n.section,`${o}/section`,255);for(let r of["requiredHint","system","hidden","list","searchable","sortable"])Zt(n[r],`${o}/${r}`);n.searchable===!0&&!at(t.type)&&k("NATIVE_DATA_SURFACE_SEARCH_UNSUPPORTED",`${o}/searchable`),n.sortable===!0&&!Pe(t.type)&&k("NATIVE_DATA_SURFACE_SORT_UNSUPPORTED",`${o}/sortable`);for(let r of["readCapabilities","createCapabilities","updateCapabilities"])ve(n[r],`${o}/${r}`,100,!0);if(n.maxCount!==void 0&&(!Number.isSafeInteger(n.maxCount)||Number(n.maxCount)<1||Number(n.maxCount)>100)&&k("NATIVE_DATA_SURFACE_MAX_COUNT_INVALID",`${o}/maxCount`),n.maxSizeMb!==void 0&&(!Number.isSafeInteger(n.maxSizeMb)||Number(n.maxSizeMb)<1||Number(n.maxSizeMb)>1024)&&k("NATIVE_DATA_SURFACE_MAX_SIZE_INVALID",`${o}/maxSizeMb`),n.accept!==void 0){let r=Array.isArray(n.accept)?n.accept:[n.accept];ve(r,`${o}/accept`,50,!1)}for(let r of["maxLength","precision","scale","exactDecimal","min","max","rangeBoundary","options","source","timePrecision","serial","subtable"])Ri(n,t,r,o);$i(n,t,o)}function hi(e,t,o){if(e===void 0)return;let n=te(e,o);if(Ae(n,Ne.list,o),n.actions!==void 0){let i=te(n.actions,`${o}/actions`);Ae(i,["import","export"],`${o}/actions`);for(let r of["import","export"])i[r]!==void 0&&typeof i[r]!="boolean"&&k("NATIVE_DATA_SURFACE_LIST_ACTION_INVALID",`${o}/actions/${r}`)}if(n.fieldOrder!==void 0)for(let i of ve(n.fieldOrder,`${o}/fieldOrder`,500,!0))t.has(i)||k("NATIVE_DATA_SURFACE_LIST_FIELD_INVALID",`${o}/fieldOrder`);n.defaultPageSize!==void 0&&(!Number.isSafeInteger(n.defaultPageSize)||Number(n.defaultPageSize)<1||Number(n.defaultPageSize)>200)&&k("NATIVE_DATA_SURFACE_PAGE_SIZE_INVALID",`${o}/defaultPageSize`);for(let[i,r]of[["searchableFields",at],["filterFields",Yt]]){if(n[i]===void 0)continue;let a=ve(n[i],`${o}/${i}`,100,!0);for(let s of a){let c=t.get(s);(!c||!r(c.type))&&k("NATIVE_DATA_SURFACE_LIST_FIELD_INVALID",`${o}/${i}`)}}if(n.defaultSort!==void 0){let i=te(n.defaultSort,`${o}/defaultSort`);Ae(i,Ne.defaultSort,`${o}/defaultSort`);let r=Te(i.field,`${o}/defaultSort/field`,63),a=t.get(r);!Gt(r)&&(!a||!Pe(a.type))&&k("NATIVE_DATA_SURFACE_SORT_UNSUPPORTED",`${o}/defaultSort/field`),i.order!==void 0&&!["asc","desc"].includes(i.order)&&k("NATIVE_DATA_SURFACE_SORT_ORDER_INVALID",`${o}/defaultSort/order`)}}function zn(e,t,o,n){if(e===void 0)return;let i=te(e,o);if(Ae(i,Ne[n],o),i.layout!==void 0&&!["flat","sections"].includes(i.layout)&&k("NATIVE_DATA_SURFACE_LAYOUT_INVALID",`${o}/layout`),i.fieldOrder!==void 0){let r=`${o}/fieldOrder`;(!Array.isArray(i.fieldOrder)||i.fieldOrder.length>t.size||i.fieldOrder.length>bi)&&k("NATIVE_DATA_SURFACE_FIELD_ORDER_INVALID",r);let a=i.fieldOrder.map((s,c)=>Te(s,`${r}/${c}`,63));new Set(a).size!==a.length&&k("NATIVE_DATA_SURFACE_FIELD_ORDER_INVALID",r),a.forEach((s,c)=>{t.has(s)||k("NATIVE_DATA_SURFACE_FIELD_ORDER_FIELD_MISSING",`${r}/${c}`)})}n==="form"&&Xt(i.draftState,`${o}/draftState`)}function Ri(e,t,o,n){e[o]===void 0&&t[o]===void 0||((e[o]===void 0||t[o]===void 0)&&k("NATIVE_DATA_SURFACE_FIELD_PROJECTION_MISMATCH",`${n}/${o}`),Q(e[o])!==Q(t[o])&&k("NATIVE_DATA_SURFACE_FIELD_PROJECTION_MISMATCH",`${n}/${o}`))}function $i(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:Qt(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)&&k("NATIVE_DATA_SURFACE_FIELD_PROJECTION_MISMATCH",`${o}/${r}`);let a=r==="accept"?Qt(i[r]):i[r],s=r==="accept"?Qt(n[r]):n[r];Q(a)!==Q(s)&&k("NATIVE_DATA_SURFACE_FIELD_PROJECTION_MISMATCH",`${o}/${r}`)}}function Qt(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 ve(e,t,o,n){(!Array.isArray(e)||!n&&e.length===0||e.length>o)&&k("NATIVE_DATA_SURFACE_STRING_ARRAY_INVALID",t);let i=e.map((r,a)=>Te(r,`${t}/${a}`,255));return new Set(i).size!==i.length&&k("NATIVE_DATA_SURFACE_STRING_ARRAY_INVALID",t),i}function te(e,t){return(!e||typeof e!="object"||Array.isArray(e))&&k("NATIVE_OBJECT_REQUIRED",t),e}function Ae(e,t,o){let n=new Set(t);for(let i of Object.keys(e))n.has(i)||k("NATIVE_PROPERTY_UNKNOWN",`${o}/${i}`)}function Te(e,t,o){return(typeof e!="string"||e.length===0||e.length>o)&&k("NATIVE_STRING_INVALID",t),e}function Si(e,t,o){e!==void 0&&(typeof e!="string"||e.length>o)&&k("NATIVE_STRING_INVALID",t)}function Zt(e,t){e!==void 0&&typeof e!="boolean"&&k("NATIVE_BOOLEAN_REQUIRED",t)}function k(e,t){throw new le(e,t)}var Le=class extends Error{constructor(o,n){super(`${o}: ${n}`);this.pointer=o;this.reason=n}pointer;reason;code="NATIVE_MANAGED_CONCURRENCY_INVALID"};function en(e,t,o){if(e===void 0)return;let n=(A,m)=>{throw new Le(A,m)},i=(A,m,O)=>((!A||typeof A!="object"||Array.isArray(A)||Object.keys(A).some(b=>!O.includes(b)))&&n(m,"object contains unsupported properties"),A),r=(A,m,O,b)=>{(!Number.isSafeInteger(A)||A<m||A>O)&&n(b,`expected integer ${m}..${O}`)},a=(A,m)=>{(typeof A!="string"||!/^[a-z][a-z0-9_-]{0,63}$/.test(A))&&n(m,"invalid code")},s=(A,m,O)=>((!Array.isArray(A)||A.length>m)&&n(O,"array exceeds bound"),A),c=(A,m)=>{let O=t.find(b=>b.code===A);return O||n(m,"unknown resource"),O},u=(A,m,O)=>{let b=A.schema.fields.find(C=>C.code===m);return!b&&m!=="id"&&n(O,"unknown field"),b},_=(A,m,O=!1)=>{i(A,m,Object.keys(A||{})),Object.keys(A).length>8&&n(m,"at most eight parameters");for(let[b,C]of Object.entries(A))if(a(b,m),i(C,m,["type","values","minimum","maximum","minLength","maxLength"]),C.type==="uuid")Object.keys(C).length!==1&&n(m,"uuid has no options");else if(O&&C.type==="boolean")i(C,m,["type"]);else if(O&&C.type==="string"&&C.values===void 0)i(C,m,["type","minLength","maxLength"]),r(C.maxLength,1,256,m),C.minLength!==void 0&&r(C.minLength,0,C.maxLength,m);else if(C.type==="string"){i(C,m,["type","values"]);let y=s(C.values,100,m);(!y.length||y.some(S=>typeof S!="string"||S.length>128)||new Set(y).size!==y.length)&&n(m,"finite string values required")}else C.type==="integer"?(i(C,m,["type","minimum","maximum"]),r(C.minimum,0,1e6,m),r(C.maximum,C.minimum,C.minimum+1e3,m)):n(m,"unsupported parameter type")},d=(A,m,O,b=!1)=>{i(A,O,["from","key","value"]),!(A.from==="input"&&Object.keys(A).length===2&&Object.hasOwn(m,A.key))&&((A.from==="actor"||b&&A.from==="allocation")&&Object.keys(A).length===1||A.from==="literal"&&Object.keys(A).length===2&&Object.hasOwn(A,"value")&&(A.value===null||["string","boolean"].includes(typeof A.value)||typeof A.value=="number"&&Number.isFinite(A.value))&&JSON.stringify(A.value).length<=512||n(O,"invalid binding"))},p=(A,m,O)=>{d(A,m,O),!(A.from==="input"&&m[A.key].type==="uuid")&&(A.from==="literal"&&typeof A.value=="string"&&/^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i.test(A.value)||n(O,"record and allocation identifiers require a UUID binding"))},I=(A,m,O)=>{d(A,m,O),!(A.from==="input"&&m[A.key].type==="integer"&&m[A.key].minimum>=1)&&(A.from==="literal"&&Number.isSafeInteger(A.value)&&A.value>=1||n(O,"expectedRevision requires a positive integer binding"))},l="/data/concurrency";JSON.stringify(e).length>131072&&n(l,"declaration exceeds 128 KiB");let E=i(e,l,["version","admission","reads","quotas","commands"]);E.version!==1&&n(l,"unsupported version"),i(E.admission,l,["perSecond","burst","maxInFlight"]),r(E.admission.perSecond,1,1e3,l),r(E.admission.burst,1,1e3,l),r(E.admission.maxInFlight,1,1e3,l);let N=(A,m)=>{let O=new Set;for(let b of A)a(b?.code,m),O.has(b.code)&&n(m,"duplicate code"),O.add(b.code)};N(s(E.reads,32,l),l),N(s(E.quotas,16,l),l),N(s(E.commands,32,l),l);for(let A of E.reads){let m=`${l}/reads/${A.code}`;i(A,m,["code","resourceCode","parameters","select","where","limit","scope","freshSeconds","staleSeconds","maxKeys","sourcePerSecond","dependencies"]);let O=c(A.resourceCode,m);_(A.parameters,m),["subject","application"].includes(A.scope)||n(m,"invalid cache scope"),A.scope==="application"&&O.dataPolicyCode&&n(m,"shared cache cannot bypass a row policy");let b=s(A.select,32,m);b.length||n(m,"select required"),b.forEach(y=>u(O,y,m));let C=s(A.dependencies,64,m);C.forEach(y=>u(O,y,m));for(let y of s(A.where||[],8,m))i(y,m,["field","value"]),u(O,y.field,m),d(y.value,A.parameters,m),A.scope==="application"&&y.value.from==="actor"&&n(m,"actor requires subject cache"),C.includes(y.field)||n(m,"filter dependency missing");b.some(y=>!C.includes(y))&&n(m,"selected field dependency missing"),r(A.limit,1,100,m),r(A.freshSeconds,1,300,m),r(A.staleSeconds,0,300,m),r(A.maxKeys,1,1e4,m),r(A.sourcePerSecond,1,20,m)}for(let A of E.quotas){let m=`${l}/quotas/${A.code}`;i(A,m,["code","sourceResource","capacityField","allocationResource","allocationField","reservationSeconds"]);let O=c(A.sourceResource,m),b=c(A.allocationResource,m);u(O,A.capacityField,m)?.type!=="number.integer"&&n(m,"capacity must be an integer"),(u(b,A.allocationField,m)?.type!=="uuid"||u(b,A.allocationField,m)?.nullable!==!1)&&n(m,"allocation reference must be a uuid"),b.surface?.mutationOwner!=="queued-command"&&n(m,"allocation model must be command owned"),A.reservationSeconds!==void 0&&r(A.reservationSeconds,10,86400,m)}new Set(E.quotas.map(A=>A.allocationResource)).size!==E.quotas.length&&n(l,"an allocation model has exactly one pool owner");for(let A of E.commands){let m=`${l}/commands/${A.code}`;i(A,m,["code","mode","intake","execution","capability","parameters","resourceKey","admission","deadlineSeconds","guards","operations","quota"]),A.mode!==void 0&&!["permit","durable"].includes(A.mode)&&n(m,"unsupported mode");let O=A.mode==="durable";if(_(A.parameters,m,O),d(A.resourceKey,A.parameters,m),o.some(b=>b.code===A.capability)||n(m,"command capability must be declared"),i(A.admission,m,["perSecond","burst","maxInFlight","maxQueue","maxWaitSeconds","permitSeconds"]),r(A.admission.perSecond,1,E.admission.perSecond,m),r(A.admission.burst,1,E.admission.burst,m),r(A.admission.maxInFlight,1,E.admission.maxInFlight,m),r(A.admission.maxQueue,1,1e4,m),r(A.admission.maxWaitSeconds,1,3600,m),(!O||A.admission.permitSeconds!==void 0)&&r(A.admission.permitSeconds,5,60,m),r(A.deadlineSeconds,10,3600,m),O){(A.operations!==void 0||A.guards!==void 0||A.quota!==void 0)&&n(m,"backend-plan does not accept static operations, guards or quota"),i(A.intake,m,["perSecond","burst","maxInFlight"]);for(let y of["perSecond","burst","maxInFlight"])r(A.intake[y],1,1e3,m);let b=i(A.execution,m,["kind","handlerCode","timeoutMs","resources","directory"]);b.kind!=="backend-plan"&&n(m,"durable requires backend-plan"),a(b.handlerCode,m),r(b.timeoutMs,100,3e4,m);let C=s(b.resources,32,m);C.length||n(m,"execution resources required"),new Set(C.map(y=>y.resourceCode)).size!==C.length&&n(m,"duplicate execution resource");for(let y of C){i(y,m,["resourceCode","readFields","writeOperations","writeFields"]);let S=c(y.resourceCode,m);for(let F of["readFields","writeFields"]){let B=s(y[F],64,m);new Set(B).size!==B.length&&n(m,"duplicate field"),B.forEach(U=>{F==="readFields"&&jt.has(U)||u(S,U,m)})}let v=s(y.writeOperations,3,m);(new Set(v).size!==v.length||v.some(F=>!["create","update","increment"].includes(F)))&&n(m,"unsupported execution operation"),y.writeFields.some(F=>["id","revision","created_by","updated_by","created_at","updated_at"].includes(F))&&n(m,"record metadata is platform owned"),!v.length&&y.writeFields.length&&n(m,"write fields require an operation"),v.length&&!y.writeFields.length&&n(m,"write operations require fields"),E.quotas.some(F=>F.allocationResource===y.resourceCode)&&v.length&&n(m,"allocation references remain owned by their pool command")}if(b.directory!==void 0){i(b.directory,m,["mode","fields"]),b.directory.mode!=="current-initiator"&&n(m,"only current initiator allowed");let y=s(b.directory.fields,4,m);(!y.length||new Set(y).size!==y.length||y.some(S=>!["displayName","employeeNumber","primaryDepartment","departments"].includes(S)))&&n(m,"unsupported directory fields")}continue}(A.execution!==void 0||A.intake!==void 0)&&n(m,"execution and intake require durable mode");for(let b of s(A.guards||[],8,m)){i(b,m,["resourceCode","id","conditions"]);let C=c(b.resourceCode,m);p(b.id,A.parameters,m);for(let y of s(b.conditions,16,m)){i(y,m,["kind","field","operator","value"]);let S=u(C,y.field,m);["eq","neq","lt","lte","gt","gte"].includes(y.operator)||n(m,"unsupported guard"),y.kind==="database-now"?(S?.type!=="datetime"||!["lt","lte","gt","gte"].includes(y.operator)||y.value!==void 0)&&n(m,"database-now requires datetime and an ordering operator"):(y.kind!==void 0&&y.kind!=="value"&&n(m,"unsupported condition kind"),d(y.value,A.parameters,m))}}for(let b of s(A.operations,8,m)){i(b,m,["operation","resourceCode","id","expectedRevision","data"]);let C=c(b.resourceCode,m);C.surface?.mutationOwner!=="queued-command"&&n(m,"command mutations require command owned models");let y=E.quotas.find(S=>S.allocationResource===b.resourceCode);y&&(b.operation==="create"?A.quota?.action!=="allocate"||A.quota.pool!==y.code:Object.hasOwn(b.data||{},y.allocationField))&&n(m,"allocation references are owned by their pool command"),["create","update"].includes(b.operation)||n(m,"unsupported operation"),b.operation==="update"?(p(b.id,A.parameters,m),I(b.expectedRevision,A.parameters,m)):(b.id!==void 0||b.expectedRevision!==void 0)&&n(m,"create has no caller supplied id/revision"),i(b.data,m,Object.keys(b.data||{})),Object.keys(b.data).length>32&&n(m,"too many fields");for(let[S,v]of Object.entries(b.data))S==="id"&&n(m,"record identifiers are platform owned"),u(C,S,m),d(v,A.parameters,m,A.quota?.action==="allocate")}if(A.quota){let b=i(A.quota,m,["pool","action","units","mode","allocation"]),C=E.quotas.find(y=>y.code===b.pool);C||n(m,"unknown quota pool"),p(A.resourceKey,A.parameters,m),b.action==="allocate"?(i(b,m,["pool","action","units","mode"]),r(b.units,1,1e3,m),(!["committed","reserved"].includes(b.mode)||b.mode==="reserved"&&!C.reservationSeconds)&&n(m,"invalid allocation mode"),(A.operations.length!==1||A.operations[0].operation!=="create"||A.operations[0].resourceCode!==C.allocationResource||A.operations[0].data[C.allocationField]?.from!=="allocation")&&n(m,"allocation must atomically create its bound business record")):["confirm","release"].includes(b.action)?(i(b,m,["pool","action","allocation"]),p(b.allocation,A.parameters,m),A.operations.length&&n(m,"lifecycle owns allocation state; business reference remains immutable")):n(m,"invalid quota action")}else A.operations.length||n(m,"operations required")}let g=E.commands.filter(A=>A.mode==="durable").map(A=>A.execution.handlerCode);return new Set(g).size!==g.length&&n(l,"handler code must be unique"),JSON.parse(JSON.stringify(E))}var he=class extends Error{constructor(o,n){super(`\u91D1\u989D\u751F\u547D\u5468\u671F\u58F0\u660E\u65E0\u6548\uFF1A${n}\uFF08${o}\uFF09`);this.pointer=o;this.reason=n}pointer;reason;code="NATIVE_DECIMAL_LIFECYCLE_INVALID"},on=["parentTransitions","childTransitions","fulfilledChildStatuses","lockedParentStatuses"],Kn=["amountFieldCode","currencyFieldCode","relationFieldCode","parentFieldCode","rootFieldCode","statusFieldCode","parentRelationValue","childRelationValue"],pt=e=>!!(e&&typeof e=="object"&&!Array.isArray(e)),ft=e=>Array.isArray(e)?e.filter(pt):[],me=(e,t)=>{throw new he(e,t)},tn=e=>typeof e=="string"&&/^[A-Za-z0-9._:-]{1,128}$/.test(e),nn=(e,t)=>e<t?-1:e>t?1:0;function _t(e,t="/decimalReservationLifecycle"){if(e===void 0)return;if(!pt(e)||Object.keys(e).some(i=>!on.includes(i))||on.some(i=>!Object.prototype.hasOwnProperty.call(e,i)))return me(t,"\u5FC5\u987B\u5B8C\u6574\u58F0\u660E\u56DB\u9879\u89C4\u5219\uFF0C\u4E0D\u80FD\u5305\u542B\u672A\u77E5\u5C5E\u6027");let o=i=>{let r=e[i];if(!Array.isArray(r)||r.length>64)return me(`${t}/${i}`,"\u72B6\u6001\u8FB9\u6700\u591A 64 \u6761");let a=new Set;return r.map((s,c)=>{let u=`${t}/${i}/${c}`;if(!pt(s)||Object.keys(s).some(d=>d!=="from"&&d!=="to")||!tn(s.from)||!tn(s.to)||s.from===s.to)return me(u,"\u72B6\u6001\u8FB9\u5FC5\u987B\u5305\u542B\u4E0D\u540C\u7684\u6709\u6548 from/to");let _=JSON.stringify([s.from,s.to]);return a.has(_)?me(u,"\u72B6\u6001\u8FB9\u4E0D\u80FD\u91CD\u590D"):(a.add(_),{from:s.from,to:s.to})}).sort((s,c)=>nn(s.from,c.from)||nn(s.to,c.to))},n=i=>{let r=e[i];return!Array.isArray(r)||r.length<1||r.length>16||r.some(a=>!tn(a))||new Set(r).size!==r.length?me(`${t}/${i}`,"\u72B6\u6001\u96C6\u5408\u5FC5\u987B\u5305\u542B 1 \u5230 16 \u4E2A\u4E0D\u91CD\u590D\u7684\u6709\u6548\u72B6\u6001"):[...r].sort(nn)};return{parentTransitions:o("parentTransitions"),childTransitions:o("childTransitions"),fulfilledChildStatuses:n("fulfilledChildStatuses"),lockedParentStatuses:n("lockedParentStatuses")}}function sn(e,t,o="/config/data/resources"){ft(e).forEach((n,i)=>{let r=`${o}/${i}/decimalReservationLifecycle`,a=_t(n.decimalReservationLifecycle,r);if(!a)return;let s=ft(t).map(d=>d.platformAccess?.decimalReservation).filter(d=>pt(d)&&d.resourceCode===n.code),c=s.find(d=>d.mode==="reserve");if(!c)return me(r,"\u9700\u8981\u540C\u8D44\u6E90\u5DF2\u58F0\u660E\u7684 reserve \u52A8\u4F5C\u6620\u5C04");if(Kn.some(d=>typeof c[d]!="string")||s.some(d=>Kn.some(p=>d[p]!==c[p])))return me(r,"\u540C\u8D44\u6E90\u989D\u5EA6\u52A8\u4F5C\u7684\u5B57\u6BB5\u6620\u5C04\u5FC5\u987B\u4E00\u81F4");let u=ft(n.schema?.fields).find(d=>d.code===c.statusFieldCode);if(u?.type!=="option.single")return me(r,"\u989D\u5EA6\u72B6\u6001\u5B57\u6BB5\u5FC5\u987B\u4E3A option.single");let _=new Set(ft(u.options).map(d=>d.value));for(let d of on)if((d==="parentTransitions"||d==="childTransitions"?a[d].flatMap(I=>[I.from,I.to]):a[d]).some(I=>!_.has(I)))return me(`${r}/${d}`,"\u72B6\u6001\u5FC5\u987B\u6765\u81EA\u989D\u5EA6\u72B6\u6001\u5B57\u6BB5\u7684\u9009\u9879");if(s.some(d=>d.mode==="reserve"&&Array.isArray(d.eligibleParentStatuses)&&d.eligibleParentStatuses.some(p=>a.lockedParentStatuses.includes(String(p)))))return me(`${r}/lockedParentStatuses`,"\u9501\u5B9A\u7236\u72B6\u6001\u4E0D\u80FD\u5141\u8BB8\u65B0\u9884\u7559")})}var Hn=require("crypto");var rn=new Set(["option.single","user.single","department.single","resource-ref.single"]),Di=new Set(["option.multiple","cascade.single","cascade.multiple","user.multiple","department.multiple","resource-ref.multiple","address","location","json"]),Xn=new Set(["option.multiple","cascade.single","cascade.multiple","user.multiple","department.multiple","resource-ref.multiple","file","image"]),Vi=new Set(["option.single","user.single","department.single","resource-ref.single","signature","address","location"]),wi=new Set([...rn,...Xn,"signature","address","location","json"]);function Fi(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=>Qn(n,o.has(n.code))).sort((n,i)=>n.code.localeCompare(i.code))}function Qn(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:Gi(e),index:Bi(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 Pi(e,t){if(t.type==="subtable")return null;let o=ne(t.code),n=Zn(e,t),i=[n?` DEFAULT ${n}`:"",Ji(o,t),Li(o,t)].join("");return`${o} ${t.storage}${i}`}function vi(e,t){return Zn(e,t)}function Li(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 ki(e){return e.type==="serial-number"||Ge(e.type)&&e.type!=="subtable"}function xi(e,t){return t.filter(o=>o.type==="serial-number").map(o=>{let n=At(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 ji(e,t){let o=Et(e);return t.filter(n=>n.type==="serial-number").map(n=>`ALTER SEQUENCE ${At(e,n.code)} OWNED BY ${o}.${ne(n.code)}`)}function Ui(e,t){return t.filter(o=>o.type==="serial-number").map(o=>`GRANT USAGE, SELECT ON SEQUENCE ${At(e,o.code)} TO "openxiangda_data_api"`)}function Mi(e,t){let o=Et(e),n=[];for(let i of t){if(i.type==="subtable")continue;let r=ne(i.code),a=ne(be("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=ne(be("idx",e,i.code,"snapshot-value")),c=ne(be("idx",e,i.code,"snapshot-label"));n.push(`CREATE INDEX IF NOT EXISTS ${s} 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 s=rn.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=ne(be("uidx",e,i.code,"serial"));n.push(`CREATE UNIQUE INDEX IF NOT EXISTS ${s} ON ${o} (${r})`)}}return n}function Wi(e,t,o,n){let i=Et(e),r=Et(t),a=ne(be("uidx",e,"environment_id","subtable-parent")),s=ne(be("idx",t,o,n,"subtable-child")),c=ne(be("fk",t,o,e)),u=ne(o),_=ne(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", ${u}, ${_}, "id")`,`DO $native_subtable$ BEGIN
2
+ ALTER TABLE ${r}
3
+ ADD CONSTRAINT ${c}
4
+ FOREIGN KEY ("tenant_id", "app_code", "environment_key", ${u})
5
+ REFERENCES ${i} ("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 Te(e,...t){return`${e}_${(0,Ln.createHash)("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 Rs(e,t){return e.type==="subtable"?"none":t?"gin-trigram":e.indexed?["date-range","datetime-range"].includes(e.type)?"gist-range":Ht.has(e.type)?"btree-snapshot-expressions":Es.has(e.type)?"gin-jsonb-path":"btree":"none"}function Ss(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 ms.has(e.type),"jsonb"}}function Un(e,t){if(Me(t.type)&&t.type!=="subtable")return"'[]'::jsonb";if(t.type!=="serial-number")return"";let o=Pn(t.serial?.prefix||""),n=t.serial?.digits??6;return`(${o} || lpad(nextval(${Pn(lt(e,t.code))})::text, ${n}, '0'))`}function Ds(e,t){return kn.has(t.type)?` CHECK (${e} IS NULL OR jsonb_typeof(${e}) = 'array')`:As.has(t.type)?` CHECK (${e} IS NULL OR jsonb_typeof(${e}) = 'object')`:""}function dt(e){return`"app_data".${ne(e)}`}function lt(e,t){let o=Te("seq",e,t);return`"app_data".${ne(o)}`}function Pn(e){return`'${e.replace(/'/g,"''")}'`}var Mn=new Set(["option.single","option.multiple","user.single","user.multiple","department.single","department.multiple","resource-ref.single","resource-ref.multiple"]),Vs=new Set([...Mn,"cascade.single","cascade.multiple","file","image","signature","address","location","json"]),jn=/^[A-Za-z][A-Za-z0-9_]{0,62}$/,ws=new Set(["__proto__","prototype","constructor"]),ut=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=Bn(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 ft(e){return!!(e&&e.field.type==="user.single"&&e.valuePath==="value")}function Xt(e,t,o){if(!e||!t||!vs(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 i=s.slice(9),r=o.get(n.source?.resourceCode||"")?.get(i)?.type;return t.valueType==="uuid"?r==="uuid":["text.short","text.long","serial-number"].includes(r||"")}function Fs(e,t){let o=Bn(t);if(!o)throw new ut(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 vs(e){let{field:t,valuePath:o}=e;if(!o)return!Vs.has(t.type);if(o==="value")return Mn.has(t.type);if(!o.startsWith("snapshot."))return!1;let n=o.slice(9);return jn.test(n)&&t.type.startsWith("resource-ref.")&&!!t.source?.snapshotFields?.includes(n)}function Bn(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=>!jn.test(o)||ws.has(o))||t.length===2&&t[1]!=="value"||t.length===3&&t[1]!=="snapshot"?null:t}var Ps=new Set(["option.single","user.single","department.single","resource-ref.single"]),Ls=new Set(["text.short","text.long","text.rich","number.integer","number.decimal","boolean","date","time","datetime","uuid","serial-number"]),ks=new Set(["value","label","description","color"]),xs=new Set(["avatarUrl","employeeNo","title","mobile","email"]),Us=new Set(["fullPath","parent.value","parent.label"]),Ms=new Set(["country.value","country.label","province.value","province.label","city.value","city.label","district.value","district.label","street.value","street.label","detail","fullAddress"]),js=new Set(["longitude","latitude","accuracy"]),Bs=new Set(["address","name","province","city","district","source"]);function Js(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=zs(n,t);if(!Object.keys(s).length)return n;let i={...n};return Object.defineProperty(i,"queryPathTypes",{configurable:!1,enumerable:!1,writable:!1,value:Object.freeze(s)}),i})}}))}function Ws(e,t){if(Ps.has(e.type)&&ks.has(t)||e.type==="user.single"&&xs.has(t)||e.type==="department.single"&&Us.has(t))return Je(t);if(e.type==="resource-ref.single"){let o=e.queryPathTypes?.[t];return o?{parts:t.split("."),type:o}:null}if(e.type==="address"&&Ms.has(t))return Je(t);if(e.type==="location"){if(js.has(t))return{parts:[t],type:"number.decimal"};if(Bs.has(t))return Je(t);if(t==="capturedAt")return{parts:[t],type:"datetime"}}return null}function zs(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}`,Ls.has(s.type)?s.type:"json"]]:[]})):{}}function Je(e){return{parts:e.split("."),type:"text.short"}}var en=["exact-v1","nfkc-space-v1","nfkc-upper-ascii-v1"],xr=256,Pe=class extends Error{constructor(o,n){super(`\u6761\u4EF6\u552F\u4E00\u952E\u58F0\u660E\u65E0\u6548\uFF1A${n}\uFF08${o}\uFF09`);this.pointer=o;this.reason=n}pointer;reason;code="NATIVE_UNIQUE_KEY_INVALID"},Qt=e=>!!(e&&typeof e=="object"&&!Array.isArray(e)),oe=(e,t)=>{throw new Pe(e,t)},pt=(e,t)=>e<t?-1:e>t?1:0,_t=(e,t,o)=>{Object.keys(e).some(n=>!t.includes(n))&&oe(o,"\u4E0D\u652F\u6301\u672A\u77E5\u5C5E\u6027")};function tn(e,t,o="/uniqueKeys"){if(e===void 0)return;if(!Array.isArray(e)||e.length>8)return oe(o,"\u6BCF\u8D44\u6E90\u6700\u591A 8 \u6761\u89C4\u5219");let n=new Map(t.map(i=>[i.code,i])),s=new Set;return e.map((i,c)=>{let r=`${o}/${c}`;if(!Qt(i))return oe(r,"\u89C4\u5219\u5FC5\u987B\u662F\u5BF9\u8C61");if(_t(i,["code","fields","when"],r),typeof i.code!="string"||!/^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/.test(i.code)||i.code.length>20||s.has(i.code))return oe(`${r}/code`,"\u9700\u8981\u4E0D\u91CD\u590D\u4E14\u4E0D\u8D85\u8FC7 20 \u5B57\u7B26\u7684 lower-kebab-case \u6807\u8BC6");if(s.add(i.code),!Array.isArray(i.fields)||i.fields.length<1||i.fields.length>4)return oe(`${r}/fields`,"\u5FC5\u987B\u9009\u62E9 1 \u5230 4 \u4E2A\u5B57\u6BB5");let a=new Set,f=i.fields.map((I,l)=>{let E=`${r}/fields/${l}`;if(!Qt(I))return oe(E,"\u5B57\u6BB5\u5FC5\u987B\u662F\u5BF9\u8C61");_t(I,["fieldCode","normalizer"],E);let T=n.get(I.fieldCode);if(!T||!["text.short","uuid","option.single","resource-ref.single"].includes(T.type)||a.has(I.fieldCode))return oe(`${E}/fieldCode`,"\u9700\u8981\u4E0D\u91CD\u590D\u7684\u77ED\u6587\u672C\u3001UUID\u3001\u5355\u9009\u6216\u5355\u8BB0\u5F55\u5F15\u7528\u5B57\u6BB5");a.add(I.fieldCode);let g=I.normalizer===void 0?"exact-v1":I.normalizer;return!en.includes(g)||T.type!=="text.short"&&g!=="exact-v1"?oe(`${E}/normalizer`,"\u5F52\u4E00\u5316\u65B9\u5F0F\u4E0D\u652F\u6301\u6216\u4E0E\u5B57\u6BB5\u7C7B\u578B\u4E0D\u7B26"):{fieldCode:T.code,normalizer:g}}).sort((I,l)=>pt(I.fieldCode,l.fieldCode)),_=i.when===void 0?[]:i.when;if(!Array.isArray(_)||_.length>4)return oe(`${r}/when`,"\u6700\u591A 4 \u4E2A\u5408\u53D6\u6761\u4EF6");let d=new Set,u=_.map((I,l)=>{let E=`${r}/when/${l}`;if(!Qt(I))return oe(E,"\u6761\u4EF6\u5FC5\u987B\u662F\u5BF9\u8C61");let T=n.get(I.fieldCode);if(!T)return oe(`${E}/fieldCode`,"\u5B57\u6BB5\u4E0D\u5B58\u5728");let g;if(I.operator==="empty"||I.operator==="nonempty"){if(_t(I,["fieldCode","operator"],E),T.type!=="text.short")return oe(E,"\u7A7A\u503C\u6761\u4EF6\u4EC5\u652F\u6301\u77ED\u6587\u672C");g={fieldCode:T.code,operator:I.operator}}else if(I.operator==="in"||I.operator==="notIn"){_t(I,["fieldCode","operator","values"],E);let m=new Set((T.options??[]).map(O=>O.value));if(T.type!=="option.single"||!Array.isArray(I.values)||I.values.length<1||I.values.length>16||I.values.some(O=>typeof O!="string"||O.length<1||O.length>128||!m.has(O))||new Set(I.values).size!==I.values.length)return oe(E,"\u96C6\u5408\u6761\u4EF6\u9700\u8981 1 \u5230 16 \u4E2A\u4E0D\u91CD\u590D\u7684\u5DF2\u58F0\u660E\u5355\u9009\u503C");g={fieldCode:T.code,operator:I.operator,values:[...I.values].sort(pt)}}else return oe(`${E}/operator`,"\u53EA\u652F\u6301 empty\u3001nonempty\u3001in \u548C notIn");let A=JSON.stringify(g);return d.has(A)?oe(E,"\u6761\u4EF6\u4E0D\u80FD\u91CD\u590D"):(d.add(A),g)}).sort((I,l)=>pt(JSON.stringify(I),JSON.stringify(l)));return{code:i.code,fields:f,when:u}}).sort((i,c)=>pt(i.code,c.code))}var Zt={type:"string",pattern:"^[A-Za-z_][A-Za-z0-9_]{0,62}$"},Gs={type:"array",maxItems:8,items:{type:"object",additionalProperties:!1,required:["code","fields"],properties:{code:{type:"string",maxLength:20,pattern:"^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$"},fields:{type:"array",minItems:1,maxItems:4,uniqueItems:!0,items:{type:"object",additionalProperties:!1,required:["fieldCode"],properties:{fieldCode:Zt,normalizer:{enum:[...en]}}}},when:{type:"array",maxItems:4,uniqueItems:!0,items:{oneOf:[{type:"object",additionalProperties:!1,required:["fieldCode","operator"],properties:{fieldCode:Zt,operator:{enum:["empty","nonempty"]}}},{type:"object",additionalProperties:!1,required:["fieldCode","operator","values"],properties:{fieldCode:Zt,operator:{enum:["in","notIn"]},values:{type:"array",minItems:1,maxItems:16,uniqueItems:!0,items:{type:"string",minLength:1,maxLength:128}}}}]}}}}};var Jn={"openxiangda.workflow.instance.completed.v2":"commit","openxiangda.workflow.instance.rejected.v2":"release","openxiangda.workflow.instance.withdrawn.v2":"release"};function Wn(e,t){let o=()=>{throw new Error("NATIVE_EVENT_DECIMAL_RESERVATION_INVALID")},n=u=>!u||typeof u!="object"||Array.isArray(u)?o():u,s=n(e);if(Object.keys(s).some(u=>!["resourceCode","workflowCode","outcomes"].includes(u))||typeof s.resourceCode!="string"||!/^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/.test(s.resourceCode)||typeof s.workflowCode!="string"||!/^[A-Za-z0-9._:-]{1,128}$/.test(s.workflowCode)||t.execution!==void 0||!Array.isArray(s.outcomes)||!s.outcomes.length||s.outcomes.length>3)return o();let i=t.resources.find(u=>u.code===s.resourceCode),c=t.reservations.find(u=>u.mode==="reserve"&&u.resourceCode===s.resourceCode),r=t.workflows.find(u=>u.code===s.workflowCode);if(!i||!c||!r||r.resourceCode!==i.code)return o();let a=i.fields.find(u=>u.code===c.statusFieldCode);if(a?.type!=="option.single")return o();let f=new Set(a.options?.map(u=>u.value)),_=new Set,d=s.outcomes.map(u=>{let I=n(u),l=I.eventType;return Object.keys(I).some(E=>!["eventType","mode","eligibleChildStatuses"].includes(E))||typeof l!="string"||!Object.prototype.hasOwnProperty.call(Jn,l)||!t.eventTypes.includes(l)||_.has(l)||I.mode!==Jn[l]||!Array.isArray(I.eligibleChildStatuses)||!I.eligibleChildStatuses.length||I.eligibleChildStatuses.length>16||new Set(I.eligibleChildStatuses).size!==I.eligibleChildStatuses.length||I.eligibleChildStatuses.some(E=>typeof E!="string"||!/^[A-Za-z0-9._:-]{1,128}$/.test(E)||!f.has(E))?o():(_.add(l),{eventType:l,mode:I.mode,eligibleChildStatuses:[...I.eligibleChildStatuses].sort()})}).sort((u,I)=>u.eventType.localeCompare(I.eventType));return{resourceCode:s.resourceCode,workflowCode:s.workflowCode,outcomes:d}}function zn(e,t){let o=n=>Array.isArray(n)?n.filter(s=>s&&typeof s=="object"&&!Array.isArray(s)):[];return{eventTypes:Array.isArray(t.eventTypes)?t.eventTypes:[],execution:t.execution,resources:o(e.data?.resources).map(n=>({code:n.code,fields:o(n.schema?.fields).map(s=>({code:s.code,type:s.type,options:o(s.options).map(i=>({value:i.value}))}))})),reservations:o(e.backend?.operations).flatMap(n=>n.platformAccess?.decimalReservation?[n.platformAccess.decimalReservation]:[]),workflows:o(e.workflows?.definitions).map(n=>({code:n.definition?.code,resourceCode:n.definition?.subject?.resourceCode}))}}var Et=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,T)=>{throw new Et(`${o}${E}`,T)},s=(E,T,g)=>((!E||typeof E!="object"||Array.isArray(E)||Object.keys(E).some(A=>!g.includes(A)))&&n(T,"Invalid action object or unsupported property"),E),i=s(e.execution,"/execution",["kind","version","operations"]);(i.kind!=="native-data"||i.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 c=e.filter?.resourceCodes;(!Array.isArray(c)||!c.length||c.length>20)&&n("/filter/resourceCodes","Native actions require explicit source resources");let r=new Map(t.map(E=>[E.code,E])),a=c.map(E=>{let T=r.get(E);return T||n("/filter/resourceCodes","Unknown source resource"),new Set((T.schema?.fields||[]).map(g=>g.code))}),f=new Set(e.payload?.fields||[]),_=e.payload?.includeChanges===!0,d=(E,T)=>{let g=s(E,T,["source","path","value"]);if(g.source==="literal"){(!Object.hasOwn(g,"value")||Object.hasOwn(g,"path"))&&n(T,"Literal binding requires only value");let C;try{C=JSON.stringify(g.value)}catch{n(T,"Literal must be JSON")}return(C===void 0||Buffer.byteLength(C)>65536)&&n(T,"Literal is too large or not JSON"),{source:"literal",value:JSON.parse(C)}}(g.source!=="event"||typeof g.path!="string"||Object.hasOwn(g,"value"))&&n(T,"Expected a literal or event binding");let A=g.path.split(".");(A.length>8||A.some(C=>!/^[A-Za-z0-9_-]+$/.test(C)||["__proto__","prototype","constructor"].includes(C)))&&n(T,"Invalid event path");let m=/^data\.projection\.([A-Za-z][A-Za-z0-9_]{0,62})$/.exec(g.path),O=/^data\.changes\.([A-Za-z][A-Za-z0-9_]{0,62})\.(before|after)$/.exec(g.path);if(m||O){let C=(m||O)[1];a.some(b=>!b.has(C))&&n(T,"Source field must exist on every filtered resource"),f.add(C),O&&(_=!0)}else["id","time","type","subject","data.recordId","data.revision","data.operation","data.resourceCode"].includes(g.path)||n(T,"Event path is not part of the data event contract");return{source:"event",path:g.path}};(!Array.isArray(i.operations)||i.operations.length<1||i.operations.length>16)&&n("/execution/operations","Expected 1 to 16 operations");let u={},I=i.operations.map((E,T)=>{let g=`/execution/operations/${T}`,A=s(E,g,["operation","resourceCode","data","id","expectedRevision"]);["create","update","delete"].includes(A.operation)||n(g,"Unsupported Native operation");let m=r.get(A.resourceCode);m||n(g,"Unknown action target resource");let O=new Map((m.schema?.fields||[]).map(b=>[b.code,b])),C=A.data===void 0?{}:s(A.data,`${g}/data`,[...O.keys()]);return Object.keys(C).length>32&&n(g,"Maximum 32 mapped fields per operation"),A.operation==="create"&&(A.id!==void 0||A.expectedRevision!==void 0)&&n(g,"Create does not accept id or expectedRevision"),A.operation==="delete"&&A.data!==void 0&&n(g,"Delete does not accept data"),Object.keys(C).some(b=>O.get(b)?.type==="serial-number")&&n(g,"Generated fields cannot be assigned"),u[A.resourceCode]=ee(m),{operation:A.operation,resourceCode:A.resourceCode,...A.operation==="create"?{}:{id:d(A.id,`${g}/id`),expectedRevision:d(A.expectedRevision,`${g}/expectedRevision`)},...A.operation==="delete"?{}:{data:Object.fromEntries(Object.entries(C).map(([b,y])=>[b,d(y,`${g}/data/${b}`)]))}}});(f.size>32||[...f].some(E=>a.some(T=>!T.has(E))))&&n("/payload/fields","Payload must contain at most 32 declared source fields");let l={kind:"native-data",version:1,operations:I,resourceDigests:u};return Buffer.byteLength(JSON.stringify(l))>65536&&n("/execution","Action plan exceeds 64 KiB"),{execution:{...l,digest:ee(l)},payload:{includeChanges:_,fields:[...f].sort()}}}function be(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=be(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,i]of Object.entries(o)){let c=be(i),r=s==="withdraw"?["beforeFact"]:["beforeFact","capability"];if(!c||Object.keys(c).some(a=>!r.includes(a))){n.push(`WORKFLOW_INSTANCE_COMMAND_POLICY_INVALID:${s}`);continue}if(s==="terminate"){let a=c.capability;(typeof a!="string"||a.length>255||!/^app:[a-z][a-z0-9]*(?:-[a-z0-9]+)*:[A-Za-z0-9:._-]+$/.test(a)||t&&(!a.startsWith(`app:${t.appCode}:`)||!t.capabilities.includes(a)))&&n.push("WORKFLOW_INSTANCE_TERMINATE_CAPABILITY_INVALID")}if(s==="withdraw"||c.beforeFact!==void 0){let a=c.beforeFact,f=be(e.inputSchema),_=be(be(f?.properties)?.[a]),d=be(be(e.subject)?.factProjection)?.[a],u=t?.fields.get(d);(typeof a!="string"||!/^[A-Za-z][A-Za-z0-9_]{0,62}$/.test(a)||!Array.isArray(f?.required)||!f.required.includes(a)||_?.type!=="string"||_?.format!=="date-time"||typeof d!="string"||t&&(u?.type!=="datetime"||u.nullable===!0))&&n.push(`WORKFLOW_INSTANCE_COMMAND_DEADLINE_FACT_INVALID:${s}`)}}return n}function qs(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,i,c,r]=t,a=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(i)>23||Number(c)>59||Number(r)>59||a!=="Z"&&(Number(a.slice(1,3))>23||Number(a.slice(4))>59))return null;let _=Date.parse(e);return Number.isFinite(_)?_:null}function Ys(e,t,o,n){let s=e?.[t];if(!s||t==="terminate"&&s.beforeFact===void 0)return null;let i=s.beforeFact,c=be(o),r=i&&c&&Object.hasOwn(c,i)?on(c[i]):null,a=n instanceof Date?n.getTime():on(n);return r===null||a===null||!Number.isFinite(a)?"WORKFLOW_V2_CANCELLATION_DEADLINE_INVALID":a<r?null:"WORKFLOW_V2_CANCELLATION_DEADLINE_PASSED"}var Tt=Lo(require("crypto"),1);var Gn="native-4",qn={"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","data.decimal-reservations":"1.1.0","data.decimal-reservation-lifecycle":"1.0.0","data.unique-keys":"1.0.0","data.managed-concurrency":"1.0.0","data.managed-concurrency.durable":"1.0.0","workflow.named-input-sources":"1.0.0","directory-v2":"1.0.0","directory.selected-user":"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 zr=5,Gr=20,qr=50,Yr=50,Kr=100,Le=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=(s,i,c)=>{c>5&&We("NATIVE_DATA_POLICY_EXPRESSION_DEPTH_EXCEEDED",i);let r=Yn(s,i),a=["allOf","anyOf"].filter(d=>d in r);if(a.length===0){o.push({rule:r,pointer:i}),o.length>50&&We("NATIVE_DATA_POLICY_EXPRESSION_LEAVES_EXCEEDED",i);return}let f=a[0],_=r[f];(a.length!==1||Object.keys(r).length!==1||!Array.isArray(_)||_.length<1||_.length>20)&&We("NATIVE_DATA_POLICY_EXPRESSION_GROUP_INVALID",i),_.forEach((d,u)=>n(d,`${i}/${f}/${u}`,c+1))};return n(e,t,1),o}function an(e,t){ze(e,t);let o=(n,s)=>{let i=Yn(n,s);if(Array.isArray(i.allOf))return rn(i.allOf.flatMap((c,r)=>o(c,`${s}/allOf/${r}`)),s);if(Array.isArray(i.anyOf)){let c=[[]];return i.anyOf.forEach((r,a)=>{let f=o(r,`${s}/anyOf/${a}`);c=rn(c.flatMap(_=>f.map(d=>[..._,...d])),s)}),c}return[[i]]};return rn(o(e,t),t)}function rn(e,t){let o=e.reduce((n,s)=>n+s.length,0);return(e.length>50||o>100)&&We("NATIVE_DATA_POLICY_EXPRESSION_EXPANSION_EXCEEDED",t),e}function Yn(e,t){return(!e||typeof e!="object"||Array.isArray(e))&&We("NATIVE_DATA_POLICY_EXPRESSION_NODE_INVALID",t),e}function We(e,t){throw new Le(e,t)}var Ks="openxiangda.config-bundle/v3",po="openxiangda.contract-bundle/v3",Kn="openxiangda.native-configuration-projection/v1",qe=Gn,Hs=/^[a-f0-9]{64}$/,Xs=/^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/,Qs=/^app:[a-z][a-z0-9]*(?:-[a-z0-9]+)*:[A-Za-z0-9:._*-]+$/,Zs=/^[a-z][a-z0-9]*(?:[-_.][a-z0-9]+)*$/,ei=/^[a-z][a-z0-9]*(?:[-.][a-z0-9]+)*$/,ti=/^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/,ni=/^[A-Za-z][A-Za-z0-9_]{0,62}$/,Hn=/^[A-Za-z][A-Za-z0-9_]{0,127}$/,oi=/^[a-z][a-z0-9]*(?:[-_][a-z0-9]+)*$/,si=/^[A-Z][A-Z0-9_]*$/,ii=/^[a-z][a-z0-9-]{2,63}$/,ri=/^[A-Za-z][A-Za-z0-9_-]{0,127}$/,ai=/^[A-Za-z][A-Za-z0-9_.]{0,127}$/,ci=16,di=2*1024,li=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"]),ui=new Set(["overview","database","operations","workflow","members","calendar","document","folder","settings"]),fi=new Set(["approve","reject","return","transfer","delegate","add_assignee","resubmit","withdraw","terminate","admin_reassign","admin_override","retry_resolution"]),pi=4*1024*1024,_i=8*1024*1024,Ei=40,Ai=1e5,dn=1024*1024,mi="openxiangda.event-handler-manifest/v2",_o="openxiangda.application-route-manifest/v3",Xn=64,Eo=new Set(["id","revision","created_by","updated_by","created_at","updated_at"]),Y=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}),At=["openxiangda.data.record.created.v2","openxiangda.data.record.updated.v2","openxiangda.data.record.deleted.v2"],mt=["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"],Ii=new Set(mt),It=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,i])=>[s,String(i).slice(0,128)]))}};function gi(e){let t=R(e.appCode,"/appCode",128);Xs.test(t)||p("NATIVE_CONFIG_APP_CODE_INVALID","/appCode");let o=un(e.expectedConfigDigest,"/expectedConfigDigest"),n=un(e.expectedContractDigest,"/expectedContractDigest"),s=lo(e.configBytes,pi,"/configBytes","NATIVE_CONFIG_ARTIFACT_TOO_LARGE"),i=lo(e.contractBytes,_i,"/contractBytes","NATIVE_CONTRACT_ARTIFACT_TOO_LARGE");uo(s,o,"/configBytes","NATIVE_CONFIG_DIGEST_MISMATCH"),uo(i,n,"/contractBytes","NATIVE_CONTRACT_DIGEST_MISMATCH");let c=ao(s,"/configBytes","NATIVE_CONFIG_JSON_INVALID","NATIVE_CONFIG_NOT_CANONICAL"),r=ao(i,"/contractBytes","NATIVE_CONTRACT_JSON_INVALID","NATIVE_CONTRACT_NOT_CANONICAL");co(c,"/config"),co(r,"/contracts");let a=c,f=r;Ti(a,t),Ci(f,t,o);let _=bi(a,o,f.generatorVersion);dr(_,f,a),Q(_)!==Q(f)&&p("NATIVE_CONTRACT_CLOSURE_MISMATCH",fn(_,f,"/contracts"));let d={authz:{appCode:t,...a.authz,perspectives:a.perspectives,capabilityCatalog:_.capabilities},data:{appCode:t,resources:a.data.resources,resourceContracts:_.resources,..._.concurrency?{concurrency:_.concurrency}:{},..._.subjectReadSurfaces?{subjectReadSurfaces:_.subjectReadSurfaces}:{}},events:{appCode:t,...a.events,consumers:_.eventConsumers,producers:_.eventProducers,handlerManifest:_.eventHandlerManifest,eventTypes:_.eventTypes,capturePlans:mo({resources:a.data.resources,dataPolicies:a.authz.dataPolicies,subscriptions:_.eventConsumers,capturePolicies:a.events.capturePolicies})},workflows:{appCode:t,...a.workflows,contracts:_.workflows},runtime:{appCode:t,requirements:a.runtime,backend:a.backend,frontend:a.frontend},contracts:_},u={authz:ke(d.authz),data:ke(d.data),events:ke(d.events),workflows:ke(d.workflows),runtime:ke(d.runtime),contracts:ke(d.contracts)},I={configDigest:o,contractDigest:n,generatorVersion:f.generatorVersion},l=Ao(a),E={schemaVersion:Kn,compilerContractVersion:qe,appCode:t,source:I,projections:u,requiredPlatformCapabilities:l,aggregateDigest:ee({schemaVersion:Kn,compilerContractVersion:qe,appCode:t,source:I,requiredPlatformCapabilities:l,projectionDigests:Object.fromEntries(Object.entries(u).map(([T,g])=>[T,g.digest]))})};return So(E)}function Ao(e){let t=e.authz.roles,o=e.data.resources,n=e.backend.operations,s=t.some(l=>l.capabilities.some(E=>E.endsWith(":directory:read")))||o.some(l=>l.schema.fields.some(E=>["user.single","user.multiple","department.single","department.multiple"].includes(E.type)))||n.some(l=>l.platformAccess?.directory),i=!!(e.events.subscriptions.length||e.events.timers.length||e.events.dateTriggers.length||e.events.schemas.length),c=n.some(l=>l.platformAccess?.managedFiles||l.platformAccess?.managedFileCopies)||e.events.subscriptions.some(l=>l.platformAccess?.managedFileCopies),r=n.some(l=>l.platformAccess?.notification)||e.events.subscriptions.some(l=>l.platformAccess?.notification),a=e.workflows.definitions.filter(l=>l.launch.mode==="standalone"||l.launch.mode==="hidden-handoff"),f=n.some(l=>l.platformAccess?.workflow)||a.length>0,_={resources:o},d={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(l=>({code:l.code,method:l.method,path:l.path,capability:l.capability,platformAccess:l.platformAccess||null,...l.browser?{browser:l.browser}:{},ai:l.ai||null}))}};return[...o.some(l=>l.uniqueKeys?.length)?[{code:"data.unique-keys",declaration:o.filter(l=>l.uniqueKeys?.length).map(l=>({code:l.code,uniqueKeys:l.uniqueKeys}))}]:[],...e.data.concurrency?[{code:"data.managed-concurrency",declaration:e.data.concurrency}]:[],...e.data.concurrency?.commands.some(l=>l.mode==="durable")?[{code:"data.managed-concurrency.durable",declaration:e.data.concurrency}]:[],...o.some(l=>l.decimalReservationLifecycle)?[{code:"data.decimal-reservation-lifecycle",declaration:o.filter(l=>l.decimalReservationLifecycle).map(l=>({code:l.code,decimalReservationLifecycle:l.decimalReservationLifecycle}))}]:[],...n.some(l=>l.platformAccess?.decimalReservation)||e.events.subscriptions.some(l=>l.platformAccess?.decimalReservation)?[{code:"data.decimal-reservations",declaration:[...n.filter(l=>l.platformAccess?.decimalReservation).map(l=>({code:l.code,decimalReservation:l.platformAccess.decimalReservation})),...e.events.subscriptions.filter(l=>l.platformAccess?.decimalReservation).map(l=>({subscriptionCode:l.code,decimalReservation:l.platformAccess.decimalReservation}))]}]:[],{code:"application-native-2",declaration:u},{code:"authz.native-batch-explain",declaration:d},{code:"authz.native-management",declaration:d},{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:_},{code:"data.native-golden-crud",declaration:_}]:[],...o.some(vt)?[{code:"data.audit-read-access",declaration:_}]:[],...s?[{code:"directory-v2",declaration:{roles:t.map(l=>({code:l.code,capabilities:l.capabilities.filter(E=>E.endsWith(":directory:read"))})),resources:o.map(l=>({code:l.code,fields:l.schema.fields.filter(E=>["user.single","user.multiple","department.single","department.multiple"].includes(E.type))})),operations:n.filter(l=>l.platformAccess?.directory).map(l=>({code:l.code,directory:l.platformAccess.directory}))}}]:[],...n.some(l=>l.platformAccess?.directory?.mode==="selected-user")?[{code:"directory.selected-user",declaration:n.filter(l=>l.platformAccess?.directory?.mode==="selected-user").map(l=>({code:l.code,directory:l.platformAccess.directory}))}]:[],...c?[{code:"data.managed-files",declaration:{operations:n.filter(l=>l.platformAccess?.managedFiles||l.platformAccess?.managedFileCopies).map(l=>({code:l.code,...l.platformAccess?.managedFiles?{managedFiles:l.platformAccess.managedFiles}:{},...l.platformAccess?.managedFileCopies?{managedFileCopies:l.platformAccess.managedFileCopies}:{}})),subscriptions:e.events.subscriptions.filter(l=>l.platformAccess?.managedFileCopies).map(l=>({code:l.code,managedFileCopies:l.platformAccess.managedFileCopies}))}}]:[],...e.events.subscriptions.some(l=>l.execution)?[{code:"events.native-data-actions",declaration:e.events.subscriptions.filter(l=>l.execution)}]:[],...e.events.capturePolicies?.length?[{code:"events.capture-policy",declaration:e.events.capturePolicies}]:[],...i?[{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(l=>l.definition.instanceCommands!==void 0)?[{code:"workflow.instance-cancellation-policy",declaration:e.workflows.definitions.filter(l=>l.definition.instanceCommands!==void 0)}]:[],...f?[{code:"business-process.durable-command",declaration:{operations:n.filter(l=>l.platformAccess?.workflow).map(l=>({code:l.code,workflow:l.platformAccess.workflow})),definitions:a,activations:e.workflows.activations.filter(l=>a.some(E=>E.definition.code===l.workflowCode))}}]:[],...r?[{code:"notification-hub-v2",declaration:{operations:n.filter(l=>l.platformAccess?.notification).map(l=>({code:l.code,notification:l.platformAccess.notification})),subscriptions:e.events.subscriptions.filter(l=>l.platformAccess?.notification).map(l=>({code:l.code,notification:l.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:l,declaration:E})=>({code:l,contractVersion:qn[l],usageDigest:`sha256:${ee(E)}`})).sort((l,E)=>l.code===E.code?0:l.code<E.code?-1:1)}function mo(e){let t=new Map,o=new Set(e.resources.map(i=>String(i.code)));for(let[i,c]of $(e.capturePolicies===void 0?[]:e.capturePolicies,"/capturePlan/capturePolicies",100).entries()){let r=`/capturePlan/capturePolicies/${i}`,a=N(c,r);h(a,["resourceCode","mode"],r);let f=G(a.resourceCode,`${r}/resourceCode`);o.has(f)||p("NATIVE_EVENT_CAPTURE_RESOURCE_NOT_FOUND",r,{resourceCode:f}),t.has(f)&&p("NATIVE_EVENT_CAPTURE_POLICY_DUPLICATE",r,{resourceCode:f}),a.mode!=="all"&&a.mode!=="subscribed"&&p("NATIVE_EVENT_CAPTURE_MODE_INVALID",`${r}/mode`),t.set(f,a.mode)}let n=new Map(e.dataPolicies.map((i,c)=>{let r=N(i,`/capturePlan/dataPolicies/${c}`);return[String(r.code),r]})),s=e.subscriptions.map((i,c)=>N(i,`/capturePlan/subscriptions/${c}`));return e.resources.map((i,c)=>{let r=`/capturePlan/resources/${c}`,a=N(i,r),f=G(a.code,`${r}/code`),_=a.schema?N(a.schema,`${r}/schema`):a,d=new Set($(_.fields||[],`${r}/schema/fields`,500).map((b,y)=>B(N(b,`${r}/schema/fields/${y}`).code,`${r}/schema/fields/${y}/code`))),u=a.dataPolicyCode?w(a.dataPolicyCode,`${r}/dataPolicyCode`):null,I=u?n.get(u):void 0;u&&!I&&p("NATIVE_EVENT_CAPTURE_AUTHZ_POLICY_NOT_FOUND",r,{resourceCode:f,dataPolicyCode:u});let l=new Set;for(let b of I?.rules||[])l.add(String(b.field));if(I?.readExpression)for(let b of ze(I.readExpression,`${r}/readExpression`))l.add(String(b.rule.field));let E=new Set,T=new Set,g=new Set;for(let[b,y]of s.entries()){let S=$(y.eventTypes,`/capturePlan/subscriptions/${b}/eventTypes`,20).map(String);if(!S.some(M=>M.startsWith("openxiangda.data.")))continue;let P=N(y.filter||{},`/capturePlan/subscriptions/${b}/filter`),F=Array.isArray(P.resourceCodes)?P.resourceCodes.map(String):[];if(F.length&&!F.includes(f))continue;for(let M of S)At.includes(M)&&g.add(M);for(let M of Ni(P,`/capturePlan/subscriptions/${b}/filter`))E.add(M);let J=N(y.payload||{},`/capturePlan/subscriptions/${b}/payload`);for(let M of $(J.fields||[],`/capturePlan/subscriptions/${b}/payload/fields`,32))T.add(B(M,`/capturePlan/subscriptions/${b}/payload/fields`))}let A=new Set([...E,...T]),m=new Set([...A,...l]);m.size>Xn&&p("NATIVE_EVENT_CAPTURE_FIELDS_LIMIT",r,{resourceCode:f,maximum:Xn});for(let b of m)!d.has(b)&&!(l.has(b)&&Eo.has(b))&&p("NATIVE_EVENT_CAPTURE_FIELD_NOT_FOUND",r,{resourceCode:f,field:b});let O=N(a.fieldPolicies||{},`${r}/fieldPolicies`);for(let b of A)O[b]?.mask==="omit"&&p("NATIVE_EVENT_CAPTURE_FIELD_SENSITIVE",r,{resourceCode:f,field:b});let C={resourceCode:f,...t.get(f)==="subscribed"?{capturedEventTypes:[...g].sort()}:{},filterFields:[...E].sort(),projectionFields:[...T].sort(),authorizationFields:[...l].sort(),captureFields:[...m].sort()};return{...C,digest:ee(C)}}).sort((i,c)=>i.resourceCode.localeCompare(c.resourceCode))}function Ni(e,t){let o=new Set;for(let[c,r]of $(e.changes||[],`${t}/changes`,16).entries()){let a=N(r,`${t}/changes/${c}`);o.add(B(a.field,`${t}/changes/${c}/field`))}let n=N(e.changedFields||{},`${t}/changedFields`);for(let c of["anyOf","allOf","noneOf"])for(let[r,a]of $(n[c]||[],`${t}/changedFields/${c}`,32).entries())o.add(B(a,`${t}/changedFields/${c}/${r}`));let s=0,i=(c,r,a)=>{a>3&&p("NATIVE_EVENT_FILTER_DEPTH_LIMIT",r);let f=N(c,r);if(f.change){let d=N(f.change,`${r}/change`);o.add(B(d.field,`${r}/change/field`)),s+=1;return}if(f.not){i(f.not,`${r}/not`,a+1);return}let _=f.all?"all":f.any?"any":null;_||p("NATIVE_EVENT_FILTER_CONDITION_INVALID",r);for(let[d,u]of $(f[_],`${r}/${_}`,16).entries())i(u,`${r}/${_}/${d}`,a+1)};return e.where&&i(e.where,`${t}/where`,1),s+=Array.isArray(e.changes)?e.changes.length:0,s>16&&p("NATIVE_EVENT_FILTER_ATOM_LIMIT",t),[...o].sort()}function Ti(e,t){h(e,["schemaVersion","compilerContractVersion","appCode","perspectives","authz","backend","data","events","workflows","frontend","runtime"],"/config"),x(e.schemaVersion,Ks,"/config/schemaVersion"),x(e.compilerContractVersion,qe,"/config/compilerContractVersion"),x(e.appCode,t,"/config/appCode"),$(e.perspectives,"/config/perspectives",100);let o=N(e.authz,"/config/authz");h(o,["capabilities","roles","scopeDimensions","scopeSources","roleMembershipSources","relationshipGrantSources","dataPolicies","authorizationTransitions"],"/config/authz",["authenticatedUserRoleCode"]),$(o.capabilities,"/config/authz/capabilities",2e3),$(o.roles,"/config/authz/roles",100),$(o.scopeDimensions,"/config/authz/scopeDimensions",100),$(o.scopeSources,"/config/authz/scopeSources",100),$(o.roleMembershipSources,"/config/authz/roleMembershipSources",100),$(o.relationshipGrantSources,"/config/authz/relationshipGrantSources",100),$(o.dataPolicies,"/config/authz/dataPolicies",100),$(o.authorizationTransitions,"/config/authz/authorizationTransitions",100);let n=N(e.backend,"/config/backend");h(n,["secrets","operations"],"/config/backend"),$(n.secrets,"/config/backend/secrets",100),$(n.operations,"/config/backend/operations",500),or(n.secrets);let s=N(e.data,"/config/data");h(s,["resources"],"/config/data",["resourceDetailRoutes","subjectReadSurfaces","concurrency"]),$(s.resources,"/config/data/resources",100),s.subjectReadSurfaces!==void 0&&$(s.subjectReadSurfaces,"/config/data/subjectReadSurfaces",Y.subjectReadSurfaces),s.resourceDetailRoutes!==void 0&&$(s.resourceDetailRoutes,"/config/data/resourceDetailRoutes",100);let i=N(e.events,"/config/events");h(i,["schemas","subscriptions","timers","dateTriggers"],"/config/events",["capturePolicies"]),$(i.schemas,"/config/events/schemas",100),$(i.subscriptions,"/config/events/subscriptions",100),$(i.timers,"/config/events/timers",100),$(i.dateTriggers,"/config/events/dateTriggers",100);let c=N(e.workflows,"/config/workflows");h(c,["definitions","bindings","activations","providers","editableParameters"],"/config/workflows"),$(c.definitions,"/config/workflows/definitions",100),$(c.bindings,"/config/workflows/bindings",100),$(c.activations,"/config/workflows/activations",100),$(c.providers,"/config/workflows/providers",100),$(c.editableParameters,"/config/workflows/editableParameters",100);let r=N(e.frontend,"/config/frontend");h(r,["routes","user","admin","devicePolicy"],"/config/frontend",["authentication","publicAccess"]),$(r.routes,"/config/frontend/routes",500);let a=N(r.user,"/config/frontend/user");h(a,["applicationTodoCenter"],"/config/frontend/user"),Ue(a.applicationTodoCenter,"/config/frontend/user/applicationTodoCenter"),pn(r.devicePolicy,"/config/frontend/devicePolicy"),Object.prototype.hasOwnProperty.call(r,"authentication")&&go(r.authentication,r.routes,e,"/config/frontend/authentication"),Object.prototype.hasOwnProperty.call(r,"publicAccess")&&xi(r.publicAccess,e,"/config/frontend/publicAccess");let f=N(r.admin,"/config/frontend/admin");h(f,["navigation"],"/config/frontend/admin",["access"]),f.access!==void 0&&bt(f.access,"/config/frontend/admin/access",e.appCode),Bi(f.navigation,"/config/frontend/admin/navigation");let _=N(e.runtime,"/config/runtime");h(_,["protocolCapabilities","health"],"/config/runtime"),v(_.protocolCapabilities,"/config/runtime/protocolCapabilities",100),h(N(_.health,"/config/runtime/health"),["livePath","readyPath","versionPath"],"/config/runtime/health"),x(_.health.livePath,"/__platform/health","/config/runtime/health/livePath"),x(_.health.readyPath,"/__platform/ready","/config/runtime/health/readyPath"),x(_.health.versionPath,"/__platform/version","/config/runtime/health/versionPath")}function Ci(e,t,o){h(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","concurrency"]),x(e.schemaVersion,po,"/contracts/schemaVersion"),x(e.compilerContractVersion,qe,"/contracts/compilerContractVersion"),R(e.generatorVersion,"/contracts/generatorVersion",128),x(e.appCode,t,"/contracts/appCode"),x(e.configDigest,o,"/contracts/configDigest"),$(e.perspectives,"/contracts/perspectives",Y.perspectives),$(e.resources,"/contracts/resources",Y.resources),e.subjectReadSurfaces!==void 0&&$(e.subjectReadSurfaces,"/contracts/subjectReadSurfaces",Y.subjectReadSurfaces),$(e.capabilities,"/contracts/capabilities",Y.capabilities),$(e.operations,"/contracts/operations",Y.operations),$(e.eventConsumers,"/contracts/eventConsumers",Y.eventConsumers),$(e.eventProducers,"/contracts/eventProducers",Y.eventProducers),$(e.eventSchemas,"/contracts/eventSchemas",Y.eventSchemas),N(e.eventHandlerManifest,"/contracts/eventHandlerManifest"),v(e.eventTypes,"/contracts/eventTypes",Y.eventTypes),$(e.workflows,"/contracts/workflows",Y.workflows),$(e.routes,"/contracts/routes",Y.routes),Object.prototype.hasOwnProperty.call(e,"authentication")&&Pi(e.authentication,"/contracts/authentication"),Object.prototype.hasOwnProperty.call(e,"publicAccess")&&Ui(e.publicAccess,"/contracts/publicAccess"),Object.prototype.hasOwnProperty.call(e,"adminAccess")&&bt(e.adminAccess,"/contracts/adminAccess",t),Yi(e.routeManifest,"/contracts/routeManifest",t),zi(e.adminPages,"/contracts/adminPages"),Gi(e.adminNavigation,"/contracts/adminNavigation")}function bi(e,t,o){let n=hi(e);Zi(e,n),tr(e),er(e),sr(e);let s=e.events.schemas.map((E,T)=>{let g=`/config/events/schemas/${T}`,A=N(E,g),m=R(A.eventType,`${g}/eventType`,255);return m.startsWith("openxiangda.")&&p("NATIVE_EVENT_SCHEMA_RESERVED",`${g}/eventType`,{eventType:m}),x(A.schemaDigest,ee(N(A.jsonSchema,`${g}/jsonSchema`)),`${g}/schemaDigest`),A}),i=new Set([...At,...mt,...s.map(E=>String(E.eventType))]),c=new Map(e.data.resources.map(E=>[String(E.code),new Map(E.schema.fields.map(T=>[String(T.code),String(T.type)]))])),r=X(e.events.subscriptions.map((E,T)=>{let g=`/config/events/subscriptions/${T}`,A=N(E,g),m=v(A.eventTypes,`${g}/eventTypes`,20);m.forEach((y,S)=>{i.has(y)||p("NATIVE_EVENT_TYPE_NOT_REGISTERED",`${g}/eventTypes/${S}`,{eventType:y})});let O=nn(A,e.data.resources,g),C=yi(A.delivery,m,`${g}/delivery`),b=Oi(A.platformAccess,`${g}/platformAccess`,c,e,A);return{code:w(A.code,`${g}/code`),endpointPath:ue(A.endpointPath,`${g}/endpointPath`),eventTypes:m,filter:N(A.filter,`${g}/filter`),payload:O?.payload||N(A.payload,`${g}/payload`),...O?{execution:O.execution}:{},...b?{platformAccess:b}:{},delivery:C}}),E=>E.code),a=new Map(s.map(E=>[String(E.eventType),String(E.dataSchemaVersion)])),f=X([...e.data.resources.flatMap(E=>At.map(T=>({code:`data:${E.code}:${T}`,source:"data",eventType:T,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:a.get(String(E.eventType))||"2.0.0"})),...e.events.dateTriggers.map(E=>({code:E.code,source:"date",eventType:E.eventType,dataSchemaVersion:a.get(String(E.eventType))||"2.0.0",resourceCode:E.resourceCode,field:E.field})),...e.workflows.activations.length?mt.map(E=>({code:`workflow:${E}`,source:"workflow",eventType:E,dataSchemaVersion:"2.0.0"})):[]],E=>`${E.source}:${E.code}:${E.eventType}`),_=j([...r.flatMap(E=>E.eventTypes),...f.map(E=>String(E.eventType))]);Wi(e);let d=Co(e),u;try{u=zt(e.data.concurrency,e.data.resources,n)}catch(E){throw E instanceof Fe&&p(E.code,E.pointer,{reason:E.reason}),E}u?.commands.some(E=>E.mode==="durable")&&e.backend?.enabled===!1&&p("NATIVE_MANAGED_CONCURRENCY_INVALID","/data/concurrency",{reason:"durable commands require backend runtime"});let I=Ri(e,n),l=Io(e);try{Kt(e.data.resources,l)}catch(E){throw E instanceof ye&&p(E.code,E.pointer,{reason:E.reason}),E}return{schemaVersion:po,compilerContractVersion:qe,generatorVersion:o,appCode:e.appCode,configDigest:t,perspectives:e.perspectives,resources:$i(e),...I.length?{subjectReadSurfaces:I}:{},...u?{concurrency:u}:{},capabilities:X(n,E=>E.code),operations:l,eventConsumers:r,eventProducers:f,eventSchemas:s,eventHandlerManifest:{schemaVersion:mi,appCode:e.appCode,handlers:r.filter(E=>!E.execution).map(E=>({code:E.code,endpointPath:E.endpointPath,eventTypes:E.eventTypes,dataSchemaVersions:j(E.eventTypes.map(T=>T.startsWith("openxiangda.")?"2.0.0":a.get(T)||"2.0.0")),maxBodyBytes:65536,receiptProtocolVersion:2}))},eventTypes:_,workflows:yo(e),routes:Ct(e),...Object.prototype.hasOwnProperty.call(e.frontend,"authentication")?{authentication:Li(e)}:{},...Object.prototype.hasOwnProperty.call(e.frontend,"publicAccess")?{publicAccess:Mi(e)}:{},...e.frontend.admin.access?{adminAccess:e.frontend.admin.access}:{},routeManifest:Xi(e),adminPages:d,adminNavigation:ji(e)}}function Oi(e,t,o,n,s){if(e===void 0)return;let i=N(e,t);h(i,["notification","managedFileCopies","decimalReservation"],t,!0);let c={};if(i.decimalReservation!==void 0)try{c.decimalReservation=Wn(i.decimalReservation,zn(n,s))}catch{p("NATIVE_EVENT_DECIMAL_RESERVATION_INVALID",`${t}/decimalReservation`)}if(i.notification!==void 0){let r=N(i.notification,`${t}/notification`);h(r,["mode"],`${t}/notification`),x(r.mode,"business-standard",`${t}/notification/mode`),c.notification={mode:"business-standard"}}if(i.managedFileCopies!==void 0){let r=$(i.managedFileCopies,`${t}/managedFileCopies`,16);r.length||p("NATIVE_EVENT_MANAGED_FILE_COPIES_REQUIRED",`${t}/managedFileCopies`);let a=new Set;c.managedFileCopies=X(r.map((f,_)=>{let d=`${t}/managedFileCopies/${_}`,u=N(f,d);h(u,["mode","sourceResourceCode","sourceFieldCodes","targetResourceCode","targetFieldCodes"],d),x(u.mode,"copy",`${d}/mode`);let I=G(u.sourceResourceCode,`${d}/sourceResourceCode`),l=G(u.targetResourceCode,`${d}/targetResourceCode`),E=o.get(I),T=o.get(l);(!E||!T)&&p("NATIVE_EVENT_MANAGED_FILE_COPY_RESOURCE_INVALID",d);let g=v(u.sourceFieldCodes,`${d}/sourceFieldCodes`,16),A=v(u.targetFieldCodes,`${d}/targetFieldCodes`,16);(!g.length||g.length!==A.length)&&p("NATIVE_EVENT_MANAGED_FILE_COPY_FIELDS_INVALID",d),g.forEach((O,C)=>{let b=E.get(O),y=T.get(A[C]);(!["file","image"].includes(String(b))||b!==y)&&p("NATIVE_EVENT_MANAGED_FILE_COPY_FIELD_INVALID",`${d}/sourceFieldCodes/${C}`)});let m=`${I}:${g.join(",")}=>${l}:${A.join(",")}`;return a.has(m)&&p("NATIVE_EVENT_MANAGED_FILE_COPY_DUPLICATE",d),a.add(m),{mode:"copy",sourceResourceCode:I,sourceFieldCodes:j(g),targetResourceCode:l,targetFieldCodes:j(A)}}),f=>`${f.sourceResourceCode}:${f.sourceFieldCodes.join(",")}=>${f.targetResourceCode}:${f.targetFieldCodes.join(",")}`)}return Object.keys(c).length||p("NATIVE_EVENT_PLATFORM_ACCESS_EMPTY",t),c}function yi(e,t,o){let n=N(e,o);h(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 i=R(n.ordering,`${o}/ordering`,32);return["none","record","workflow-instance"].includes(i)||p("NATIVE_EVENT_DELIVERY_ORDERING_INVALID",`${o}/ordering`),i==="workflow-instance"&&t.some(c=>!Ii.has(c))&&p("NATIVE_EVENT_WORKFLOW_ORDERING_REQUIRES_WORKFLOW_FACTS",`${o}/ordering`),n}function hi(e){let t=new Map;for(let o of Ro(e.appCode))t.set(o.code,o);for(let[o,n]of e.authz.capabilities.entries()){let s=`/config/authz/capabilities/${o}`,i=N(n,s);h(i,["code","kind","name","description"],s,!0);let c=Ce(i.code,`${s}/code`,e.appCode);t.has(c)&&p("NATIVE_CAPABILITY_DUPLICATE",`${s}/code`),["backend","ui"].includes(i.kind)||p("NATIVE_CAPABILITY_KIND_INVALID",`${s}/kind`);let r={code:c,kind:i.kind,name:R(i.name,`${s}/name`,255),source:"explicit",...i.description===void 0?{}:{description:En(i.description,`${s}/description`,2e3)}};t.set(c,r)}for(let[o,n]of e.data.resources.entries()){let s=`/config/data/resources/${o}`,i=he(n,s,e.appCode),c={read:`\u8BFB\u53D6${i.name}`,create:`\u65B0\u5EFA${i.name}`,update:`\u66F4\u65B0${i.name}`,delete:`\u5220\u9664${i.name}`};for(let r of["read","create","update","delete"]){let a=Ce(i.capabilities[r],`${s}/capabilities/${r}`,e.appCode);t.has(a)&&p("NATIVE_CAPABILITY_DUPLICATE",`${s}/capabilities/${r}`),t.set(a,{code:a,kind:"data",name:c[r],source:"data"})}for(let[r,a]of Object.entries(i.fieldPolicies)){if(Se(r))continue;let f=N(a,`${s}/fieldPolicies/${r}`);for(let _ of["read","create","update"])if(Array.isArray(f[_]))for(let d of v(f[_],`${s}/fieldPolicies/${r}/${_}`,2e3))Ce(d,`${s}/fieldPolicies/${r}/${_}`,e.appCode),!t.has(d)&&t.set(d,{code:d,kind:"data",name:`${i.name}.${r}.${_}`,source:"data"})}}return[...t.values()]}function $i(e){let t=Si(e);return X(e.data.resources.map((o,n)=>{let s=he(o,`/config/data/resources/${n}`,e.appCode),i=t.get(s.code);return{code:s.code,schemaDigest:ee(s.schema),fields:X(s.schema.fields.map(c=>({code:c.code,type:c.type})),c=>c.code),...i?{detailRouteCode:i}:{}}}),o=>o.code)}function Ri(e,t){if(e.data.subjectReadSurfaces===void 0)return[];let o=$(e.data.subjectReadSurfaces,"/config/data/subjectReadSurfaces",Y.subjectReadSurfaces),n=new Set(t.map(c=>String(c.code))),s=new Map(e.data.resources.map((c,r)=>{let a=`/config/data/resources/${r}`,f=he(c,a,e.appCode);return[String(f.code),{resource:f,fields:new Map($(N(f.schema,`${a}/schema`).fields,`${a}/schema/fields`,500).map(_=>{let d=N(_,`${a}/schema/fields`);return[String(d.code),d]}))}]})),i=new Set;return X(o.map((c,r)=>{let a=`/config/data/subjectReadSurfaces/${r}`,f=N(c,a);h(f,["code","name","capability","subject","relations"],a);let _=w(f.code,`${a}/code`);i.has(_)&&p("NATIVE_SUBJECT_READ_SURFACE_CODE_DUPLICATE",`${a}/code`),i.add(_);let d=Ce(f.capability,`${a}/capability`,e.appCode);n.has(d)||p("NATIVE_SUBJECT_READ_SURFACE_CAPABILITY_NOT_DECLARED",`${a}/capability`);let u=N(f.subject,`${a}/subject`);h(u,["resourceCode","fields"],`${a}/subject`);let I=G(u.resourceCode,`${a}/subject/resourceCode`),l=s.get(I);l||p("NATIVE_SUBJECT_READ_SURFACE_RESOURCE_NOT_DECLARED",`${a}/subject/resourceCode`);let E=v(u.fields,`${a}/subject/fields`,100).map((O,C)=>B(O,`${a}/subject/fields/${C}`));E.length||p("NATIVE_SUBJECT_READ_SURFACE_FIELDS_REQUIRED",`${a}/subject/fields`);for(let[O,C]of E.entries()){let b=l.fields.get(C);(!b||b.type==="subtable")&&p("NATIVE_SUBJECT_READ_SURFACE_FIELD_INVALID",`${a}/subject/fields/${O}`)}let T=$(f.relations,`${a}/relations`,8);T.length||p("NATIVE_SUBJECT_READ_SURFACE_RELATIONS_REQUIRED",`${a}/relations`);let g=new Set,A=0,m=X(T.map((O,C)=>{let b=`${a}/relations/${C}`,y=N(O,b);h(y,["code","resourceCode","foreignKeyField","fields","limit"],b,["order"]);let S=w(y.code,`${b}/code`);g.has(S)&&p("NATIVE_SUBJECT_READ_SURFACE_RELATION_CODE_DUPLICATE",`${b}/code`),g.add(S);let P=G(y.resourceCode,`${b}/resourceCode`),F=s.get(P);F||p("NATIVE_SUBJECT_READ_SURFACE_RESOURCE_NOT_DECLARED",`${b}/resourceCode`);let J=B(y.foreignKeyField,`${b}/foreignKeyField`),M=F.fields.get(J),fe=N(M?.source||{},`${b}/foreignKeyField/source`);(!M||!["uuid","resource-ref.single"].includes(String(M.type))||M.type==="resource-ref.single"&&(fe.kind!=="resource"||fe.resourceCode!==I))&&p("NATIVE_SUBJECT_READ_SURFACE_RELATION_INVALID",`${b}/foreignKeyField`);let pe=v(y.fields,`${b}/fields`,100).map((ie,V)=>B(ie,`${b}/fields/${V}`));pe.length||p("NATIVE_SUBJECT_READ_SURFACE_FIELDS_REQUIRED",`${b}/fields`);for(let[ie,V]of pe.entries()){let U=F.fields.get(V);(!U||U.type==="subtable")&&p("NATIVE_SUBJECT_READ_SURFACE_FIELD_INVALID",`${b}/fields/${ie}`)}let K=$(y.order||[],`${b}/order`,10).map((ie,V)=>{let U=`${b}/order/${V}`,L=N(ie,U);h(L,["field","direction"],U);let W=B(L.field,`${U}/field`),z=F.fields.get(W);return(!Eo.has(W)&&!z||z?.type==="subtable"||z&&!Ve(z.type))&&p("NATIVE_SUBJECT_READ_SURFACE_ORDER_FIELD_INVALID",`${U}/field`),["asc","desc"].includes(String(L.direction))||p("NATIVE_SUBJECT_READ_SURFACE_ORDER_DIRECTION_INVALID",`${U}/direction`),{field:W,direction:L.direction}}),me=Z(y.limit,`${b}/limit`,1,100);return A+=me,{code:S,resourceCode:P,foreignKeyField:J,fields:j(pe),...K.length?{order:K}:{},limit:me}}),O=>O.code);return A>400&&p("NATIVE_SUBJECT_READ_SURFACE_ROW_LIMIT_EXCEEDED",`${a}/relations`),{code:_,name:R(f.name,`${a}/name`,255),capability:d,subject:{resourceCode:I,fields:j(E)},relations:m}}),c=>c.code)}function Si(e){let t=e.data.resourceDetailRoutes===void 0?[]:$(e.data.resourceDetailRoutes,"/config/data/resourceDetailRoutes",100),o=new Map(e.data.resources.map((i,c)=>{let r=`/config/data/resources/${c}`,a=he(i,r,e.appCode);return[a.code,a]})),n=new Map(Ct(e).map(i=>[String(i.code),i])),s=new Map;for(let[i,c]of t.entries()){let r=`/config/data/resourceDetailRoutes/${i}`,a=N(c,r);h(a,["resourceCode","desktop","mobile"],r);let f=G(a.resourceCode,`${r}/resourceCode`);s.has(f)&&p("NATIVE_DATA_RESOURCE_DETAIL_ROUTE_DUPLICATE",`${r}/resourceCode`);let _=o.get(f);_||p("NATIVE_DATA_RESOURCE_DETAIL_ROUTE_RESOURCE_MISSING",`${r}/resourceCode`);let d=w(a.desktop,`${r}/desktop`),u=w(a.mobile,`${r}/mobile`);d===u&&p("NATIVE_DATA_RESOURCE_DETAIL_ROUTE_INVALID",r);let I=String(_.capabilities.read);for(let[l,E]of[["desktop",d],["mobile",u]]){let T=`${r}/${l}`,g=n.get(E);g||p("NATIVE_DATA_RESOURCE_DETAIL_ROUTE_REFERENCE_MISSING",T),g.surface!=="user"&&p("NATIVE_DATA_RESOURCE_DETAIL_ROUTE_SURFACE_INVALID",T);let A=ue(g.path,`${T}/path`),m=[...A.matchAll(/:([A-Za-z][A-Za-z0-9_]*)/g)],O=l==="mobile"?!A.startsWith("/m/"):A==="/m"||A.startsWith("/m/");(A.includes("*")||A.includes("?")||A.includes("#")||A.split("/").includes("..")||m.length!==1||O)&&p("NATIVE_DATA_RESOURCE_DETAIL_ROUTE_PATH_INVALID",T);let C=Array.isArray(g.access?.allOf)?g.access.allOf:[];g.capability!==I&&!C.includes(I)&&p("NATIVE_DATA_RESOURCE_DETAIL_ROUTE_CAPABILITY_INVALID",T)}s.set(f,{desktop:d,mobile:u})}return s}function Io(e){let t=new Map(e.data.resources.map((c,r)=>{let a=`/config/data/resources/${r}`,f=he(c,a,e.appCode);return[f.code,new Map(f.schema.fields.map(_=>[String(_.code),_]))]})),o=new Map(e.data.resources.map((c,r)=>{let a=`/config/data/resources/${r}`,f=he(c,a,e.appCode);return[f.code,new Map(f.schema.fields.map(_=>[String(_.code),String(_.type)]))]})),n=new Set(o.keys()),s=new Set(e.workflows.activations.map((c,r)=>Ot(N(c,`/config/workflows/activations/${r}`).workflowCode,`/config/workflows/activations/${r}/workflowCode`))),i=new Map;return X(e.backend.operations.map((c,r)=>{let a=`/config/backend/operations/${r}`,f=N(c,a);h(f,["code","method","path","capability","requestSchema","responseSchema","description","platformAccess","browser","ai"],a,!0);let _=R(f.method,`${a}/method`,16);["GET","POST","PUT","PATCH","DELETE"].includes(_)||p("NATIVE_OPERATION_METHOD_INVALID",`${a}/method`);let d=w(f.code,`${a}/code`);Fi(f.ai,a,d,_,n);let u=wi(f.platformAccess,`${a}/platformAccess`,o,t,s,new Set(e.authz.roles.map(l=>String(l.code))));if(u?.decimalReservation){let l=u.decimalReservation,E=String(l.resourceCode),T=JSON.stringify([l.amountFieldCode,l.currencyFieldCode,l.relationFieldCode,l.parentFieldCode,l.rootFieldCode,l.statusFieldCode,l.parentRelationValue,l.childRelationValue]),g=i.get(E);g&&g!==T&&p("NATIVE_DECIMAL_RESERVATION_MAPPING_CONFLICT",`${a}/platformAccess/decimalReservation`),i.set(E,T)}let I=Di(f.browser,`${a}/browser`,_,f.requestSchema,f.responseSchema,o,t,e.data.subjectReadSurfaces||[]);return{code:d,method:_,path:ue(f.path,`${a}/path`),requiredCapability:Ce(f.capability,`${a}/capability`,e.appCode),requestSchemaDigest:ee(N(f.requestSchema,`${a}/requestSchema`)),responseSchemaDigest:ee(N(f.responseSchema,`${a}/responseSchema`)),...f.description===void 0?{}:{description:En(f.description,`${a}/description`,2e3)},...u?{platformAccess:u}:{},...I?{browser:I}:{}}}),c=>c.code)}function Di(e,t,o,n,s,i,c,r){if(e===void 0)return null;let a=N(e,t);h(a,["exposure","behavior","idempotency","subject"],t,["refreshTargets","fileIntent"]),x(a.exposure,"authenticated",`${t}/exposure`);let f=R(a.behavior,`${t}/behavior`,32);["read","controlled"].includes(f)||p("NATIVE_OPERATION_BROWSER_BEHAVIOR_INVALID",`${t}/behavior`);let _=R(a.idempotency,`${t}/idempotency`,32);(!["none","required"].includes(_)||f==="controlled"&&_!=="required"||f==="read"&&_!=="none")&&p("NATIVE_OPERATION_BROWSER_IDEMPOTENCY_INVALID",`${t}/idempotency`);let d=N(a.subject,`${t}/subject`);h(d,["resourceCode","inputField"],`${t}/subject`);let u=G(d.resourceCode,`${t}/subject/resourceCode`);i.has(u)||p("NATIVE_OPERATION_BROWSER_SUBJECT_RESOURCE_NOT_DECLARED",`${t}/subject/resourceCode`);let I=B(d.inputField,`${t}/subject/inputField`),l=N(n,`${t}/requestSchema`),E=N(s,`${t}/responseSchema`);(l.type!=="object"||l.additionalProperties!==!1||E.type!=="object"||E.additionalProperties!==!1)&&p("NATIVE_OPERATION_BROWSER_SCHEMA_ROOT_INVALID",`${t}/requestSchema`);let T=N(l.properties,`${t}/requestSchema/properties`),g=new Set(l.required===void 0?[]:v(l.required,`${t}/requestSchema/required`,200));(!(I in T)||!g.has(I))&&p("NATIVE_OPERATION_BROWSER_SUBJECT_INPUT_INVALID",`${t}/subject/inputField`);let A=N(T[I],`${t}/requestSchema/properties/${I}`);(A.type!=="string"||A.format!=="uuid")&&p("NATIVE_OPERATION_BROWSER_SUBJECT_INPUT_INVALID",`${t}/subject/inputField`);let m=new Map((Array.isArray(r)?r:[]).map((S,P)=>{let F=N(S,`/config/data/subjectReadSurfaces/${P}`);return[String(F.code),String(N(F.subject,`/config/data/subjectReadSurfaces/${P}/subject`).resourceCode)]})),O=a.refreshTargets===void 0?[]:$(a.refreshTargets,`${t}/refreshTargets`,16),C=new Set,b=X(O.map((S,P)=>{let F=`${t}/refreshTargets/${P}`,J=N(S,F);h(J,["kind","code"],F),x(J.kind,"subject-surface",`${F}/kind`);let M=w(J.code,`${F}/code`);return(C.has(M)||!m.has(M)||m.get(M)!==u)&&p("NATIVE_OPERATION_BROWSER_REFRESH_TARGET_INVALID",`${F}/code`),C.add(M),{kind:"subject-surface",code:M}}),S=>`${S.kind}:${S.code}`),y=Vi(a.fileIntent,`${t}/fileIntent`,o,f,_,u,T,g,c);return{exposure:"authenticated",behavior:f,idempotency:_,subject:{resourceCode:u,inputField:I},...b.length?{refreshTargets:b}:{},...y?{fileIntent:y}:{}}}function Vi(e,t,o,n,s,i,c,r,a){if(e===void 0)return null;let f=N(e,t);h(f,["recordResourceCode","recordIdInputField","relationField","fileNameField","contentTypeField","sizeField","purposes","maxTtlSeconds","maxBytes"],t),(o!=="GET"||n!=="read"||s!=="none")&&p("NATIVE_OPERATION_FILE_INTENT_BEHAVIOR_INVALID",t);let _=G(f.recordResourceCode,`${t}/recordResourceCode`),d=a.get(_);d||p("NATIVE_OPERATION_FILE_INTENT_RESOURCE_NOT_DECLARED",`${t}/recordResourceCode`);let u=B(f.recordIdInputField,`${t}/recordIdInputField`),I=N(c[u],`${t}/recordIdInputField`);(!r.has(u)||I.type!=="string"||I.format!=="uuid")&&p("NATIVE_OPERATION_FILE_INTENT_RECORD_INPUT_INVALID",`${t}/recordIdInputField`);let l=B(f.relationField,`${t}/relationField`),E=d.get(l);(!E||!["uuid","resource-ref.single"].includes(String(E.type))||String(E.type)==="resource-ref.single"&&(String(N(E.source,`${t}/relationField`).kind||"")!=="resource"||String(N(E.source,`${t}/relationField`).resourceCode||"")!==i))&&p("NATIVE_OPERATION_FILE_INTENT_RELATION_INVALID",`${t}/relationField`);let T=[["fileNameField",["text.short","text.long"]],["contentTypeField",["text.short","text.long"]],["sizeField",["number.integer"]]],g={};for(let[C,b]of T){let y=B(f[C],`${t}/${C}`);b.includes(String(d.get(y)?.type))||p("NATIVE_OPERATION_FILE_INTENT_METADATA_INVALID",`${t}/${C}`),g[C]=y}let A=X(v(f.purposes,`${t}/purposes`,2),C=>C);(!A.length||A.some(C=>!["preview","download"].includes(C)))&&p("NATIVE_OPERATION_FILE_INTENT_PURPOSE_INVALID",`${t}/purposes`);let m=Number(f.maxTtlSeconds);(!Number.isSafeInteger(m)||m<1||m>300)&&p("NATIVE_OPERATION_FILE_INTENT_TTL_INVALID",`${t}/maxTtlSeconds`);let O=Number(f.maxBytes);return(!Number.isSafeInteger(O)||O<1||O>104857600)&&p("NATIVE_OPERATION_FILE_INTENT_SIZE_INVALID",`${t}/maxBytes`),{recordResourceCode:_,recordIdInputField:u,relationField:l,fileNameField:g.fileNameField,contentTypeField:g.contentTypeField,sizeField:g.sizeField,purposes:A,maxTtlSeconds:m,maxBytes:O}}function wi(e,t,o,n,s,i){if(e===void 0)return null;let c=N(e,t);h(c,["directory","managedFiles","managedFileCopies","notification","workflow","roleAssertions","decimalReservation"],t,!0),Object.keys(c).length===0&&p("NATIVE_OPERATION_PLATFORM_ACCESS_EMPTY",t);let r={};if(c.roleAssertions!==void 0){let a=N(c.roleAssertions,`${t}/roleAssertions`);h(a,["roleCodes"],`${t}/roleAssertions`);let f=v(a.roleCodes,`${t}/roleAssertions/roleCodes`,20);f.length||p("NATIVE_OPERATION_ROLE_ASSERTIONS_REQUIRED",`${t}/roleAssertions/roleCodes`),f.forEach((_,d)=>{i.has(_)||p("NATIVE_ROLE_REFERENCE_MISSING",`${t}/roleAssertions/roleCodes/${d}`)}),r.roleAssertions={roleCodes:j(f)}}if(c.directory!==void 0){let a=N(c.directory,`${t}/directory`);h(a,["mode","fields"],`${t}/directory`),["current-initiator","selected-user"].includes(String(a.mode))||p("NATIVE_OPERATION_DIRECTORY_MODE_INVALID",`${t}/directory/mode`);let f=new Set(["displayName","employeeNumber","primaryDepartment","departments"]),_=v(a.fields,`${t}/directory/fields`,4);(!_.length||_.some(d=>!f.has(d)))&&p("NATIVE_OPERATION_DIRECTORY_FIELDS_INVALID",`${t}/directory/fields`),r.directory={mode:String(a.mode),fields:j(_)}}if(c.managedFiles!==void 0){let a=$(c.managedFiles,`${t}/managedFiles`,16);a.length||p("NATIVE_OPERATION_MANAGED_FILES_REQUIRED",`${t}/managedFiles`);let f=new Set;r.managedFiles=X(a.map((_,d)=>{let u=`${t}/managedFiles/${d}`,I=N(_,u);h(I,["resourceCode","fieldCodes","intents"],u);let l=G(I.resourceCode,`${u}/resourceCode`);(f.has(l)||!o.has(l))&&p("NATIVE_OPERATION_MANAGED_FILE_RESOURCE_INVALID",`${u}/resourceCode`),f.add(l);let E=v(I.fieldCodes,`${u}/fieldCodes`,16);(!E.length||E.some(g=>!["file","image","signature","text.rich"].includes(String(o.get(l)?.get(g)||""))))&&p("NATIVE_OPERATION_MANAGED_FILE_FIELD_INVALID",`${u}/fieldCodes`);let T=v(I.intents,`${u}/intents`,2);return(!T.length||T.some(g=>!["create","update"].includes(g)))&&p("NATIVE_OPERATION_MANAGED_FILE_INTENT_INVALID",`${u}/intents`),{resourceCode:l,fieldCodes:j(E),intents:j(T)}}),_=>_.resourceCode)}if(c.managedFileCopies!==void 0){let a=$(c.managedFileCopies,`${t}/managedFileCopies`,16);a.length||p("NATIVE_OPERATION_MANAGED_FILE_COPIES_REQUIRED",`${t}/managedFileCopies`);let f=new Set;r.managedFileCopies=X(a.map((_,d)=>{let u=`${t}/managedFileCopies/${d}`,I=N(_,u);h(I,["mode","sourceResourceCode","sourceFieldCodes","targetResourceCode","targetFieldCodes"],u),x(I.mode,"copy",`${u}/mode`);let l=G(I.sourceResourceCode,`${u}/sourceResourceCode`),E=G(I.targetResourceCode,`${u}/targetResourceCode`),T=o.get(l),g=o.get(E);(!T||!g)&&p("NATIVE_OPERATION_MANAGED_FILE_COPY_RESOURCE_INVALID",u);let A=v(I.sourceFieldCodes,`${u}/sourceFieldCodes`,16),m=v(I.targetFieldCodes,`${u}/targetFieldCodes`,16);(!A.length||A.length!==m.length)&&p("NATIVE_OPERATION_MANAGED_FILE_COPY_FIELDS_INVALID",u),A.forEach((C,b)=>{let y=T.get(C),S=g.get(m[b]);(!["file","image"].includes(String(y))||y!==S)&&p("NATIVE_OPERATION_MANAGED_FILE_COPY_FIELD_INVALID",`${u}/sourceFieldCodes/${b}`)});let O=`${l}:${A.join(",")}=>${E}:${m.join(",")}`;return f.has(O)&&p("NATIVE_OPERATION_MANAGED_FILE_COPY_DUPLICATE",u),f.add(O),{mode:"copy",sourceResourceCode:l,sourceFieldCodes:j(A),targetResourceCode:E,targetFieldCodes:j(m)}}),_=>`${_.sourceResourceCode}:${_.sourceFieldCodes.join(",")}=>${_.targetResourceCode}:${_.targetFieldCodes.join(",")}`)}if(c.notification!==void 0){let a=N(c.notification,`${t}/notification`);h(a,["mode"],`${t}/notification`),a.mode!=="business-standard"&&p("NATIVE_OPERATION_NOTIFICATION_MODE_INVALID",`${t}/notification/mode`),r.notification={mode:"business-standard"}}if(c.workflow!==void 0){let a=N(c.workflow,`${t}/workflow`);h(a,["codes"],`${t}/workflow`);let f=v(a.codes,`${t}/workflow/codes`,16);(!f.length||f.some(_=>!s.has(_)))&&p("NATIVE_OPERATION_WORKFLOW_CODE_INVALID",`${t}/workflow/codes`),r.workflow={codes:j(f)}}if(c.decimalReservation!==void 0){let a=`${t}/decimalReservation`,f=N(c.decimalReservation,a);h(f,["mode","resourceCode","amountFieldCode","currencyFieldCode","relationFieldCode","parentFieldCode","rootFieldCode","statusFieldCode","parentRelationValue","childRelationValue","eligibleParentStatuses","eligibleChildStatuses"],a);let _=R(f.mode,`${a}/mode`,16);["reserve","commit","release"].includes(_)||p("NATIVE_DECIMAL_RESERVATION_MODE_INVALID",`${a}/mode`);let d=G(f.resourceCode,`${a}/resourceCode`),u=n.get(d);u||p("NATIVE_DECIMAL_RESERVATION_RESOURCE_MISSING",`${a}/resourceCode`);let l=Object.fromEntries(["amountFieldCode","currencyFieldCode","relationFieldCode","parentFieldCode","rootFieldCode","statusFieldCode"].map(C=>[C,B(f[C],`${a}/${C}`)])),E=C=>u.get(l[C]),T=C=>new Set((E(C)?.options||[]).map(b=>String(b.value))),g=w(f.parentRelationValue,`${a}/parentRelationValue`),A=w(f.childRelationValue,`${a}/childRelationValue`),m=v(f.eligibleParentStatuses,`${a}/eligibleParentStatuses`,16),O=v(f.eligibleChildStatuses,`${a}/eligibleChildStatuses`,16);(E("amountFieldCode")?.type!=="number.decimal"||E("amountFieldCode")?.exactDecimal!==!0||E("amountFieldCode")?.precision!==18||E("amountFieldCode")?.scale!==2||E("currencyFieldCode")?.type!=="option.single"||E("relationFieldCode")?.type!=="option.single"||E("parentFieldCode")?.type!=="resource-ref.single"||E("parentFieldCode")?.source?.resourceCode!==d||E("rootFieldCode")?.type!=="uuid"||E("statusFieldCode")?.type!=="option.single"||g===A||!T("relationFieldCode").has(g)||!T("relationFieldCode").has(A)||!m.length||!O.length||m.some(C=>!T("statusFieldCode").has(C))||O.some(C=>!T("statusFieldCode").has(C)))&&p("NATIVE_DECIMAL_RESERVATION_FIELD_INVALID",a),r.decimalReservation={mode:_,resourceCode:d,...l,parentRelationValue:g,childRelationValue:A,eligibleParentStatuses:j(m),eligibleChildStatuses:j(O)}}return r}function Fi(e,t,o,n,s){if(e===void 0)return;let i=`${t}/ai`,c=N(e,i);ei.test(o)||p("NATIVE_OPERATION_AI_CODE_INVALID",`${t}/code`),h(c,["name","description","risk","resources","sideEffects","concurrency","timeoutMs"],i,!0),R(c.name,`${i}/name`,dn),R(c.description,`${i}/description`,dn);let r=R(c.risk,`${i}/risk`,16);["read","write","destructive","external"].includes(r)||p("NATIVE_OPERATION_AI_RISK_INVALID",`${i}/risk`),r==="read"!=(n==="GET")&&p("NATIVE_OPERATION_AI_METHOD_RISK_MISMATCH",`${i}/risk`),n==="DELETE"&&!["destructive","external"].includes(r)&&p("NATIVE_OPERATION_AI_METHOD_RISK_MISMATCH",`${i}/risk`);let a=v(c.resources,`${i}/resources`,16);a.length===0&&p("NATIVE_OPERATION_AI_RESOURCE_REQUIRED",`${i}/resources`),a.forEach((_,d)=>{let u=G(_,`${i}/resources/${d}`);s.has(u)||p("NATIVE_OPERATION_AI_RESOURCE_MISSING",`${i}/resources/${d}`)});let f=v(c.sideEffects,`${i}/sideEffects`,20);(r==="read"&&f.length!==0||r!=="read"&&f.length===0)&&p("NATIVE_OPERATION_AI_SIDE_EFFECT_INVALID",`${i}/sideEffects`),c.concurrency!==void 0&&!["none","revision"].includes(R(c.concurrency,`${i}/concurrency`,16))&&p("NATIVE_OPERATION_AI_CONCURRENCY_INVALID",`${i}/concurrency`),c.timeoutMs!==void 0&&Z(c.timeoutMs,`${i}/timeoutMs`,100,3e4)}function gt(e){return(e.replace(/\/{2,}/g,"/").replace(/\/$/,"")||"/").split("/").map(o=>o.startsWith(":")?":":o.includes("*")?"*":o).join("/")}function vi(e,t){let o=N(e,t),n=R(o.type,`${t}/type`,32),s=["code","type","label","presentation","required"],i=n==="sso"?[...s,"provider"]:n==="dingtalk"?[...s,"flow"]:s;h(o,i,t);let c=w(o.code,`${t}/code`),r=R(o.label,`${t}/label`,255),a=R(o.presentation,`${t}/presentation`,16);["primary","secondary"].includes(a)||p("NATIVE_APPLICATION_AUTH_METHOD_PRESENTATION_INVALID",`${t}/presentation`);let f=Ue(o.required,`${t}/required`);return["sso","password","dingtalk"].includes(n)||p("NATIVE_APPLICATION_AUTH_METHOD_TYPE_INVALID",`${t}/type`),n==="sso"&&o.provider!=="tenant-default"&&p("NATIVE_APPLICATION_AUTH_SSO_PROVIDER_INVALID",`${t}/provider`),n==="dingtalk"&&!["auto","jsapi","oauth"].includes(R(o.flow,`${t}/flow`,16))&&p("NATIVE_APPLICATION_AUTH_DINGTALK_FLOW_INVALID",`${t}/flow`),{code:c,type:n,label:r,presentation:a,required:f,...n==="sso"?{provider:"tenant-default"}:{},...n==="dingtalk"?{flow:o.flow}:{}}}function Qn(e,t,o){let n=N(e,o);h(n,["routeCode","path","defaultRouteCode"],o);let s=w(n.routeCode,`${o}/routeCode`),i=ue(n.path,`${o}/path`),c=t==="desktop"?"/login":"/m/login";return(i!==c||/[:*?#\\]/.test(i))&&p("NATIVE_APPLICATION_AUTH_SURFACE_PATH_INVALID",`${o}/path`,{device:t,expectedPath:c}),{routeCode:s,path:i,defaultRouteCode:w(n.defaultRouteCode,`${o}/defaultRouteCode`)}}function go(e,t,o,n){if(e===null)return;let s=N(e,n);h(s,["accountMode","registration","methods","surfaces"],n),x(s.accountMode,"existing-platform-users-only",`${n}/accountMode`);let i=N(s.registration,`${n}/registration`);h(i,["mode"],`${n}/registration`),x(i.mode,"reject",`${n}/registration/mode`);let c=$(s.methods,`${n}/methods`,8);c.length===0&&p("NATIVE_APPLICATION_AUTH_METHOD_REQUIRED",`${n}/methods`);let r=c.map((g,A)=>vi(g,`${n}/methods/${A}`)),a=new Set,f=new Set;for(let[g,A]of r.entries())a.has(A.code)&&p("NATIVE_APPLICATION_AUTH_METHOD_CODE_DUPLICATE",`${n}/methods/${g}/code`),f.has(A.type)&&p("NATIVE_APPLICATION_AUTH_METHOD_TYPE_DUPLICATE",`${n}/methods/${g}/type`),a.add(A.code),f.add(A.type);r.filter(g=>g.presentation==="primary").length!==1&&p("NATIVE_APPLICATION_AUTH_PRIMARY_METHOD_INVALID",`${n}/methods`);let _=N(s.surfaces,`${n}/surfaces`);h(_,["desktop","mobile"],`${n}/surfaces`);let d=Qn(_.desktop,"desktop",`${n}/surfaces/desktop`),u=Qn(_.mobile,"mobile",`${n}/surfaces/mobile`);d.routeCode===u.routeCode&&p("NATIVE_APPLICATION_AUTH_SURFACE_CODE_DUPLICATE",`${n}/surfaces/mobile/routeCode`);let I=$(t,"/config/frontend/routes",500),l=new Map;for(let[g,A]of I.entries()){let m=N(A,`/config/frontend/routes/${g}`);l.set(String(m.code||""),m)}let E=new Set((Array.isArray(o.data?.resources)?o.data.resources:[]).map(g=>String(g.code||"")).filter(g=>/^[a-z][a-z0-9-]{0,62}$/.test(g)));for(let[g,A]of[["desktop",d],["mobile",u]]){l.has(A.routeCode)&&p("NATIVE_APPLICATION_AUTH_SURFACE_CODE_CONFLICT",`${n}/surfaces/${g}/routeCode`);let m=/^user\.([a-z][a-z0-9-]{0,62})\.(records|submit)$/.exec(String(A.defaultRouteCode||"")),O=l.get(A.defaultRouteCode),C=String(O?.path||"");if(m&&E.has(m[1])){let y=m[2]==="records"?`/my/${m[1]}`:`/my/${m[1]}/submit`;O={surface:"user",path:g==="mobile"?`/m${y}`:y},C=String(O.path)}let b=g==="desktop"?C==="/m"||C.startsWith("/m/"):!(C==="/m"||C.startsWith("/m/"));(!O||O.surface!=="user"||/[:*]/.test(C)||b)&&p("NATIVE_APPLICATION_AUTH_DEFAULT_ROUTE_INVALID",`${n}/surfaces/${g}/defaultRouteCode`)}let T=No(o).filter(g=>!g.owner.startsWith("authentication:"));for(let[g,A]of[["desktop",d],["mobile",u]]){let m=T.find(O=>gt(O.path)===gt(A.path));m&&p("NATIVE_APPLICATION_AUTH_SURFACE_PATH_CONFLICT",`${n}/surfaces/${g}/path`,{owner:m.owner})}}function Pi(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=N(e,t),s=N(n.surfaces,`${t}/surfaces`),i={...n,surfaces:{...s,desktop:{...N(s.desktop,`${t}/surfaces/desktop`),defaultRouteCode:"auth-desktop-default"},mobile:{...N(s.mobile,`${t}/surfaces/mobile`),defaultRouteCode:"auth-mobile-default"}}};go(i,o.frontend.routes,{...o,frontend:{...o.frontend,authentication:i}},t)}function Li(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 ki=new Set(["draft.read","draft.update","validate","create","own.list","own.read","public.list","public.read"]);function xi(e,t,o){let n=N(e,o);h(n,["policies"],o);let s=$(n.policies,`${o}/policies`,16);s.length<1&&p("NATIVE_PUBLIC_POLICY_REQUIRED",o);let i=new Map(t.frontend.routes.map(f=>[f.code,f])),c=new Map(t.data.resources.map(f=>[f.code,f])),r=new Set,a=new Set(s.map(f=>String(f?.code||"")));s.forEach((f,_)=>{let d=`${o}/policies/${_}`,u=N(f,d);h(u,["code","routeCode","mode","resourceCode","operations","fields"],d,["requiredFields","ownRecordFields","publicRecordFields","publicFilters","serverGeneratedFields","schedule","publicSubtableFields","draft","validations"]);let I=w(u.code,`${d}/code`);r.has(I)&&p("NATIVE_PUBLIC_POLICY_DUPLICATE",`${d}/code`);let l=w(u.routeCode,`${d}/routeCode`),E=i.get(l);(!E||E.surface!=="user"||E.capability!==void 0||E.access!==void 0||/[:*]/.test(String(E.path)))&&p("NATIVE_PUBLIC_ROUTE_INVALID",`${d}/routeCode`),x(u.mode,"anonymous",`${d}/mode`);let T=G(u.resourceCode,`${d}/resourceCode`),g=c.get(T);g||p("NATIVE_PUBLIC_RESOURCE_MISSING",`${d}/resourceCode`);let A=new Map(g.schema.fields.map(V=>[String(V.code),String(V.type)])),m=v(u.operations,`${d}/operations`,8);(m.length<1||m.some(V=>!ki.has(V)))&&p("NATIVE_PUBLIC_OPERATION_INVALID",`${d}/operations`),m.includes("draft.read")!==m.includes("draft.update")&&p("NATIVE_PUBLIC_DRAFT_OPERATION_INCOMPLETE",`${d}/operations`);let O=v(u.fields,`${d}/fields`,64);(O.length<1||O.some(V=>!A.has(V)))&&p("NATIVE_PUBLIC_FIELD_INVALID",`${d}/fields`);for(let V of["requiredFields","ownRecordFields","publicRecordFields"]){if(!Object.prototype.hasOwnProperty.call(u,V))continue;v(u[V],`${d}/${V}`,64).some(L=>!O.includes(L))&&p("NATIVE_PUBLIC_FIELD_SCOPE_INVALID",`${d}/${V}`)}let C=Object.prototype.hasOwnProperty.call(u,"serverGeneratedFields")?$(u.serverGeneratedFields,`${d}/serverGeneratedFields`,16):[],b=new Set;C.forEach((V,U)=>{let L=`${d}/serverGeneratedFields/${U}`,W=N(V,L);h(W,["field","kind"],L);let z=B(W.field,`${L}/field`);(b.has(z)||!A.has(z)||O.includes(z)||A.get(z)!=="text.short"&&A.get(z)!=="text.long")&&p("NATIVE_PUBLIC_SERVER_GENERATED_FIELD_INVALID",`${L}/field`),x(W.kind,"random-token",`${L}/kind`),b.add(z)});let y=Object.prototype.hasOwnProperty.call(u,"schedule")?N(u.schedule,`${d}/schedule`):null;if(y){let V=["campusPolicyCode","rulePolicyCode","campusField","ruleCampusField","ruleWeekdaysField","ruleOpenAtField","ruleCloseAtField","ruleSlotMinutesField","ruleAdvanceHoursField","ruleAdvanceDaysField","campusEnabledField","ruleEnabledField","dateField","timeField"];h(y,V,`${d}/schedule`);for(let U of["campusPolicyCode","rulePolicyCode"])w(y[U],`${d}/schedule/${U}`);for(let U of V.filter(L=>!["campusPolicyCode","rulePolicyCode"].includes(L)))B(y[U],`${d}/schedule/${U}`);for(let U of[y.campusField,y.dateField,y.timeField])O.includes(String(U))||p("NATIVE_PUBLIC_SCHEDULE_FIELD_INVALID",`${d}/schedule`);(!a.has(String(y.campusPolicyCode))||!a.has(String(y.rulePolicyCode)))&&p("NATIVE_PUBLIC_SCHEDULE_POLICY_INVALID",`${d}/schedule`)}let S=Object.prototype.hasOwnProperty.call(u,"publicFilters")?$(u.publicFilters,`${d}/publicFilters`,16):[],P=new Set;S.forEach((V,U)=>{let L=`${d}/publicFilters/${U}`,W=N(V,L);h(W,["field","operator","value"],L);let z=B(W.field,`${L}/field`);P.has(z)&&p("NATIVE_PUBLIC_FILTER_DUPLICATE",`${L}/field`),O.includes(z)||p("NATIVE_PUBLIC_FILTER_FIELD_INVALID",`${L}/field`),x(W.operator,"eq",`${L}/operator`),["boolean","text.short","text.long","number.integer","number.decimal","date","time"].includes(A.get(z)||"")||p("NATIVE_PUBLIC_FILTER_FIELD_INVALID",`${L}/field`),W.value!==null&&typeof W.value!="string"&&typeof W.value!="number"&&typeof W.value!="boolean"&&p("NATIVE_PUBLIC_FILTER_VALUE_INVALID",`${L}/value`),P.add(z)});let F=Object.prototype.hasOwnProperty.call(u,"publicSubtableFields")?N(u.publicSubtableFields,`${d}/publicSubtableFields`):null;if(F){Object.keys(F).length>64&&p("NATIVE_PUBLIC_SUBTABLE_FIELDS_INVALID",`${d}/publicSubtableFields`);for(let[V,U]of Object.entries(F)){let L=g.schema.fields.find(H=>String(H.code)===V),W=String(L?.subtable?.resourceCode||""),z=c.get(W),Ie=new Map((z?.schema?.fields||[]).map(H=>[String(H.code),String(H.type)])),q=v(U,`${d}/publicSubtableFields/${V}`,64);(!O.includes(V)||A.get(V)!=="subtable"||!z||q.length<1||q.some(H=>!Ie.has(H))||q.some(H=>Ie.get(H)==="subtable")||q.some(H=>Ie.get(H)==="signature"))&&p("NATIVE_PUBLIC_SUBTABLE_FIELDS_INVALID",`${d}/publicSubtableFields/${V}`)}}if(m.some(V=>V.startsWith("public."))){Object.prototype.hasOwnProperty.call(u,"publicRecordFields")||p("NATIVE_PUBLIC_RECORD_FIELDS_REQUIRED",`${d}/publicRecordFields`);let V=v(u.publicRecordFields,`${d}/publicRecordFields`,64);(V.length<1||V.some(U=>!O.includes(U))||V.some(U=>A.get(U)==="signature"||A.get(U)==="subtable"&&!F?.[U]))&&p("NATIVE_PUBLIC_RECORD_FIELDS_INVALID",`${d}/publicRecordFields`)}let J=Object.prototype.hasOwnProperty.call(u,"requiredFields")?v(u.requiredFields,`${d}/requiredFields`,64):[],M=g.surface||{},fe=M.fields||{},pe=String(M.mutationOwner||"native")==="native"&&M.generated?.create!==!1,K=g.schema.fields.filter(V=>je(V,fe[V.code])).map(V=>String(V.code));if(m.includes("create")&&!pe&&p("NATIVE_PUBLIC_CREATE_FIELDS_INCOMPLETE",`${d}/fields`),m.includes("create")&&!Object.prototype.hasOwnProperty.call(u,"draft")&&p("NATIVE_PUBLIC_DRAFT_REQUIRED",`${d}/draft`),m.includes("create"))for(let V of K){let U=O.includes(V)?J.includes(V)?null:"requiredFields":"fields";U&&p("NATIVE_PUBLIC_CREATE_FIELDS_INCOMPLETE",`${d}/${U}`,{resourceCode:G,fieldCode:V})}if(Object.prototype.hasOwnProperty.call(u,"draft")){let V=N(u.draft,`${d}/draft`);h(V,["enabled","inactivityTtlSeconds","maxBytes"],`${d}/draft`),x(V.enabled,!0,`${d}/draft/enabled`),Z(V.inactivityTtlSeconds,`${d}/draft/inactivityTtlSeconds`,3600,7776e3),Z(V.maxBytes,`${d}/draft/maxBytes`,4096,262144)}else m.includes("draft.read")&&p("NATIVE_PUBLIC_DRAFT_REQUIRED",`${d}/draft`);let me=Object.prototype.hasOwnProperty.call(u,"validations")?$(u.validations,`${d}/validations`,16):[],ie=new Set;me.forEach((V,U)=>{let L=`${d}/validations/${U}`,W=N(V,L);h(W,["code","kind","fields","result"],L);let z=w(W.code,`${L}/code`);ie.has(z)&&p("NATIVE_PUBLIC_VALIDATION_DUPLICATE",`${L}/code`),x(W.kind,"duplicate",`${L}/kind`),x(W.result,"availability",`${L}/result`);let Ie=v(W.fields,`${L}/fields`,8);(Ie.length<1||Ie.some(q=>!O.includes(q))||Ie.some(q=>["file","subtable"].includes(A.get(q)||"")))&&p("NATIVE_PUBLIC_VALIDATION_FIELD_INVALID",`${L}/fields`),ie.add(z)}),r.add(I)})}function Ui(e,t){let o=N(e,t);h(o,["policies"],t),$(o.policies,`${t}/policies`,16).length<1&&p("NATIVE_PUBLIC_POLICY_REQUIRED",t)}function Mi(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)=>ae(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)=>ae(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 No(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=To(o),s=`/admin/resources/${o.code}`,i=[["list",s],["detail",`${s}/:id`],["create",`${s}/new`],["update",`${s}/:id/edit`]];for(let[c,r]of i)n[c]&&t.push({owner:`resource:${o.code}:${c}`,path:r},{owner:`resource:${o.code}:${c}:mobile`,path:`/m${r}`})}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 Ct(e){let t=new Map(No(e).map(o=>[gt(o.path),o]));return X(e.frontend.routes.map((o,n)=>{let s=`/config/frontend/routes/${n}`,i=N(o,s);h(i,["code","path","label","surface","parentCode","capability","access","pinned","tabPersistence","keepAlive"],s,!0),["admin","user"].includes(i.surface)||p("NATIVE_ROUTE_SURFACE_INVALID",`${s}/surface`);let c=ue(i.path,`${s}/path`);i.surface==="admin"&&c!=="/admin"&&!c.startsWith("/admin/")&&p("NATIVE_ADMIN_ROUTE_PATH_INVALID",`${s}/path`),i.surface==="user"&&(c==="/admin"||c.startsWith("/admin/"))&&p("NATIVE_USER_ROUTE_PATH_RESERVED",`${s}/path`);let r=gt(c),a=t.get(r);a&&p("NATIVE_ROUTE_PATH_CONFLICT",`${s}/path`,{path:c,owner:a.owner}),t.set(r,{owner:`frontend:${String(i.code||n)}`,path:c});let f=/[:*]/.test(c),_=_n(i,s,e.appCode),d=i.pinned===void 0?void 0:Ue(i.pinned,`${s}/pinned`),u=i.tabPersistence===void 0?f?"none":"session":R(i.tabPersistence,`${s}/tabPersistence`,16),I=i.keepAlive===void 0?"none":R(i.keepAlive,`${s}/keepAlive`,16);return["session","none"].includes(u)||p("NATIVE_ROUTE_TAB_PERSISTENCE_INVALID",`${s}/tabPersistence`),["none","memory"].includes(I)||p("NATIVE_ROUTE_KEEP_ALIVE_INVALID",`${s}/keepAlive`),f&&d===!0&&p("NATIVE_DYNAMIC_ROUTE_PINNED_FORBIDDEN",`${s}/pinned`),f&&u==="session"&&p("NATIVE_DYNAMIC_ROUTE_TAB_PERSISTENCE_FORBIDDEN",`${s}/tabPersistence`),f&&I==="memory"&&p("NATIVE_DYNAMIC_ROUTE_KEEP_ALIVE_FORBIDDEN",`${s}/keepAlive`),{code:w(i.code,`${s}/code`),path:c,label:R(i.label,`${s}/label`,255),surface:i.surface,...i.parentCode===void 0?{}:{parentCode:w(i.parentCode,`${s}/parentCode`)},..._,...d===void 0?{}:{pinned:d},tabPersistence:u,keepAlive:I}}),o=>o.code)}function To(e){let t=e.surface===void 0?{}:N(e.surface,"/surface"),o=t.mutationOwner||"native",n=t.generated===void 0?{}:N(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 Co(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:it(n.surface,s.code)}}))])){let{resource:n,viewCode:s}=o,i=`/admin/resources/${n.code}${s?`/views/${s}`:""}`,c=To(n),r=[{operation:"list",kind:"resource-list",path:`${i}`,label:n.name,capability:n.capabilities.read,navigationEligible:!0},{operation:"detail",kind:"resource-detail",path:`${i}/:id`,label:`${n.name}\u8BE6\u60C5`,capability:n.capabilities.read,navigationEligible:!1},{operation:"create",kind:"resource-create",path:`${i}/new`,label:`\u65B0\u589E${n.name}`,capability:n.capabilities.create,navigationEligible:!1},{operation:"update",kind:"resource-update",path:`${i}/:id/edit`,label:`\u7F16\u8F91${n.name}`,capability:n.capabilities.update,navigationEligible:!1}];for(let a of r)c[a.operation]&&t.push({code:`resource:${n.code}${s?`:view:${s}`:""}:${a.operation}`,kind:a.kind,path:a.path,label:a.label,navigationEligible:a.navigationEligible,capability:a.capability,resourceCode:n.code,...s?{viewCode:s}:{}})}for(let o of Ct(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)=>ae(o.code,n.code))}function bo(e){return e.kind==="resource"?`resource:${e.resourceCode}${e.viewCode?`:view:${e.viewCode}`:""}:list`:`operation:${e.routeCode}`}function ji(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:bo(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||ae(n.pageCode,s.pageCode))})).sort((t,o)=>t.order-o.order||ae(t.code,o.code))}function Bi(e,t){let o=$(e,t,Y.adminNavigationGroups),n=0;o.forEach((s,i)=>{let c=`${t}/${i}`,r=N(s,c);h(r,["code","label","icon","order","items"],c,!0),w(r.code,`${c}/code`),R(r.label,`${c}/label`,255),Nt(r.icon,`${c}/icon`),oo(r.order,`${c}/order`);let a=$(r.items,`${c}/items`,500);a.length===0&&p("NATIVE_ADMIN_GROUP_ORPHANED",`${c}/items`),n+=a.length,n>Y.adminNavigationItems&&p("NATIVE_ARRAY_LIMIT_EXCEEDED",t),a.forEach((f,_)=>{let d=`${c}/items/${_}`,u=N(f,d);h(u,["page","label","icon","order"],d,!0),Ji(u.page,`${d}/page`),u.label!==void 0&&R(u.label,`${d}/label`,255),Nt(u.icon,`${d}/icon`),oo(u.order,`${d}/order`)})})}function Ji(e,t){let o=N(e,t),n=R(o.kind,`${t}/kind`,64);if(n==="resource"){h(o,["kind","resourceCode"],t,["viewCode"]),o.viewCode!==void 0&&w(o.viewCode,`${t}/viewCode`),G(o.resourceCode,`${t}/resourceCode`);return}if(n==="operation"){h(o,["kind","routeCode"],t),w(o.routeCode,`${t}/routeCode`);return}p("NATIVE_ADMIN_PAGE_REFERENCE_KIND_INVALID",`${t}/kind`)}function Wi(e){let t=new Map(Co(e).map(s=>[String(s.code),s])),o=new Set,n=new Set;e.frontend.admin.navigation.forEach((s,i)=>{let c=`/config/frontend/admin/navigation/${i}`;o.has(s.code)&&p("NATIVE_ADMIN_GROUP_DUPLICATE",`${c}/code`),o.add(s.code),s.label===s.code&&p("NATIVE_ADMIN_USER_LABEL_REQUIRED",`${c}/label`),s.items.forEach((r,a)=>{let f=`${c}/items/${a}`,_=bo(r.page),d=t.get(_);(!d||d.navigationEligible!==!0)&&p("NATIVE_ADMIN_PAGE_NOT_FOUND",`${f}/page`),n.has(_)&&p("NATIVE_ADMIN_PAGE_DUPLICATE",`${f}/page`),n.add(_);let u=r.page.resourceCode||r.page.routeCode||r.page.workflowCode||_,I=r.label||d.label;(!I||I===u||I===_)&&p("NATIVE_ADMIN_USER_LABEL_REQUIRED",`${f}/label`)})})}function zi(e,t){let o=$(e,t,Y.adminPages),n=new Set;o.forEach((s,i)=>{let c=`${t}/${i}`,r=N(s,c);h(r,["code","kind","path","label","navigationEligible","capability","access","resourceCode","viewCode","routeCode"],c,!0);let a=R(r.code,`${c}/code`,255);n.has(a)&&p("NATIVE_ADMIN_PAGE_DUPLICATE",`${c}/code`),n.add(a);let f=R(r.kind,`${c}/kind`,64);if(["resource-list","resource-detail","resource-create","resource-update","operation"].includes(f)||p("NATIVE_ADMIN_PAGE_KIND_INVALID",`${c}/kind`),ue(r.path,`${c}/path`),R(r.label,`${c}/label`,255),Ue(r.navigationEligible,`${c}/navigationEligible`),r.capability!==void 0&&r.access!==void 0&&p("NATIVE_ROUTE_ACCESS_CONFLICT",`${c}/access`),r.capability!==void 0&&R(r.capability,`${c}/capability`,255),r.access!==void 0){let _=N(r.access,`${c}/access`);h(_,["allOf","anyOf"],`${c}/access`,!0);for(let d of["allOf","anyOf"])_[d]!==void 0&&v(_[d],`${c}/access/${d}`,50)}for(let _ of["resourceCode","viewCode","routeCode"])r[_]!==void 0&&w(r[_],`${c}/${_}`)})}function Gi(e,t){let o=$(e,t,Y.adminNavigationGroups),n=0;o.forEach((s,i)=>{let c=`${t}/${i}`,r=N(s,c);h(r,["code","label","icon","order","items"],c,!0),w(r.code,`${c}/code`),R(r.label,`${c}/label`,255),Nt(r.icon,`${c}/icon`),Z(r.order,`${c}/order`,-1e4,1e4);let a=$(r.items,`${c}/items`,500);a.length===0&&p("NATIVE_ADMIN_GROUP_ORPHANED",`${c}/items`),n+=a.length,n>Y.adminNavigationItems&&p("NATIVE_ARRAY_LIMIT_EXCEEDED",t),a.forEach((f,_)=>{let d=`${c}/items/${_}`,u=N(f,d);h(u,["pageCode","label","icon","order"],d,!0),R(u.pageCode,`${d}/pageCode`,255),u.label!==void 0&&R(u.label,`${d}/label`,255),Nt(u.icon,`${d}/icon`),Z(u.order,`${d}/order`,-1e4,1e4)})})}var qi=new Set(["application-todo-center","workflow-work-center","workflow-launch","workflow-task","workflow-instance","resource-records","resource-submit"]);function Yi(e,t,o){let n=N(e,t);h(n,["schemaVersion","appCode","devicePolicy","rootEntry","authentication","routes","digest"],t),x(n.schemaVersion,_o,`${t}/schemaVersion`),x(n.appCode,o,`${t}/appCode`),pn(n.devicePolicy,`${t}/devicePolicy`),Ki(n.rootEntry,`${t}/rootEntry`),Hi(n.authentication,`${t}/authentication`),un(n.digest,`${t}/digest`);let s=$(n.routes,`${t}/routes`,Y.routes),i=new Set;s.forEach((c,r)=>{let a=`${t}/routes/${r}`,f=N(c,a),_=f.kind==="resource-records"||f.kind==="resource-submit";h(f,["code","kind","desktop","mobile"],a,["workflowCode",..._?["resourceCode"]:[]]);let d=R(f.code,`${a}/code`,255);i.has(d)&&p("NATIVE_ROUTE_MANIFEST_DUPLICATE",`${a}/code`),i.add(d);let u=R(f.kind,`${a}/kind`,64);if(qi.has(u)||p("NATIVE_ROUTE_MANIFEST_KIND_INVALID",`${a}/kind`),f.workflowCode!==void 0&&w(f.workflowCode,`${a}/workflowCode`),_){let E=G(f.resourceCode,`${a}/resourceCode`);x(d,`user.${E}.${f.kind==="resource-records"?"records":"submit"}`,`${a}/code`)}else f.resourceCode!==void 0&&p("NATIVE_PROPERTY_UNKNOWN",`${a}/resourceCode`);let I=eo(f.desktop,`${a}/desktop`,o),l=eo(f.mobile,`${a}/mobile`,o);I.surface!=="user"&&p("NATIVE_ROUTE_MANIFEST_DESKTOP_SURFACE_INVALID",`${a}/desktop/surface`),l.surface!=="user"&&p("NATIVE_ROUTE_MANIFEST_MOBILE_SURFACE_INVALID",`${a}/mobile/surface`),I.routeCode===l.routeCode&&p("NATIVE_ROUTE_MANIFEST_PAIR_DUPLICATE",a)}),x(n.digest,ee({schemaVersion:n.schemaVersion,appCode:n.appCode,devicePolicy:n.devicePolicy,rootEntry:n.rootEntry,authentication:n.authentication,routes:n.routes}),`${t}/digest`)}function pn(e,t){let o=N(e,t);h(o,["kind","mobileMaxWidthPx","desktopMinWidthPx"],t),x(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&&p("NATIVE_FRONTEND_DEVICE_POLICY_INVALID",t),{kind:"viewport-family",mobileMaxWidthPx:n,desktopMinWidthPx:s}}function Ki(e,t){let o=N(e,t);h(o,["code","desktop","mobile"],t);let n=w(o.code,`${t}/code`),s=ln(o.desktop,`${t}/desktop`),i=ln(o.mobile,`${t}/mobile`);return(s===i||i==="/"||!i.startsWith("/m/"))&&p("NATIVE_ROUTE_MANIFEST_ROOT_ENTRY_INVALID",t),s.startsWith("/m/")&&p("NATIVE_ROUTE_MANIFEST_ROOT_ENTRY_INVALID",`${t}/desktop`),{code:n,desktop:s,mobile:i}}function Hi(e,t){let o=N(e,t);h(o,["desktop","mobile"],t);let n=Zn(o.desktop,`${t}/desktop`,!1),s=Zn(o.mobile,`${t}/mobile`,!0);return(n.routeCode===s.routeCode||n.path===s.path)&&p("NATIVE_ROUTE_MANIFEST_AUTHENTICATION_DUPLICATE",t),{desktop:n,mobile:s}}function Zn(e,t,o){let n=N(e,t);h(n,["routeCode","path"],t);let s=w(n.routeCode,`${t}/routeCode`),i=ln(n.path,`${t}/path`);return(o?!i.startsWith("/m/"):i.startsWith("/m/"))&&p("NATIVE_ROUTE_MANIFEST_AUTHENTICATION_PATH_INVALID",`${t}/path`),{routeCode:s,path:i}}function ln(e,t){let o=ue(e,t);return/[:*?#\\\\]/.test(o)&&p("NATIVE_ROUTE_MANIFEST_STATIC_PATH_INVALID",t),o}function eo(e,t,o){let n=N(e,t);h(n,["routeCode","path","surface","pathParams","requiresAuthentication"],t,["capability","access"]),w(n.routeCode,`${t}/routeCode`);let s=ue(n.path,`${t}/path`),i=R(n.surface,`${t}/surface`,16);["admin","user"].includes(i)||p("NATIVE_ROUTE_SURFACE_INVALID",`${t}/surface`);let c=v(n.pathParams,`${t}/pathParams`,8);return c.forEach((r,a)=>{(!/^[A-Za-z][A-Za-z0-9_]*$/.test(r)||r.length>64)&&p("NATIVE_ROUTE_PATH_PARAM_INVALID",`${t}/pathParams/${a}`)}),Q(c)!==Q(Oo(s))&&p("NATIVE_ROUTE_PATH_PARAMS_MISMATCH",`${t}/pathParams`),_n(n,t,o),n.requiresAuthentication!==!0&&p("NATIVE_ROUTE_AUTHENTICATION_REQUIRED",`${t}/requiresAuthentication`),n}function Oo(e){return j([...e.matchAll(/:([A-Za-z][A-Za-z0-9_]*)/g)].map(t=>t[1]))}function to(e,t,o,n){return{routeCode:e,path:t,surface:o,pathParams:Oo(t),...n?.capability?{capability:n.capability}:{},...n?.access?{access:n.access}:{},requiresAuthentication:!0}}function no(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 Xi(e){let t=e.appCode,o=[],n=(I,l,E,T,g,A,m)=>{o.push({code:I,kind:l,...g?{workflowCode:g}:{},...m?{resourceCode:m}:{},desktop:to(no(l,"desktop",g,m),E,"user",A),mobile:to(no(l,"mobile",g,m),T,"user",A)})};e.frontend.user.applicationTodoCenter===!0&&n("application:todo-center","application-todo-center","/todos","/m/todos");let s=yo(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 I of s){if(!["standalone","hidden-handoff"].includes(I.launch.mode))continue;let l=j([I.launch.submission?.create?.requiredCapability,I.launch.submission?.existing?.requiredCapability].filter(E=>!!E));n(`workflow:${I.code}:launch`,"workflow-launch","/workflows/:workflowCode/start","/m/workflows/:workflowCode/start",I.code,l.length===1?{capability:l[0]}:l.length>1?{access:{anyOf:l}}:void 0)}let i=o.sort((I,l)=>ae(String(I.code),String(l.code))),c=Ct(e),r=I=>{let l=I==="mobile"?"/m/":"/",E=c.filter(g=>g.surface==="user"&&!/[:*?#\\\\]/.test(g.path)&&g.path===l).sort((g,A)=>ae(g.code,A.code))[0];if(E)return{code:E.code,path:E.path};let T=c.filter(g=>g.surface==="user"&&!/[:*?#\\\\]/.test(g.path)&&(I==="mobile"?g.path.startsWith("/m/"):!g.path.startsWith("/m/"))).sort((g,A)=>ae(g.code,A.code))[0];return T?{code:T.code,path:T.path}:{code:I==="mobile"?"application-root-mobile":"application-root",path:l}},a=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=pn(e.frontend.devicePolicy,"/config/frontend/devicePolicy"),_=r("desktop"),d=r("mobile"),u={schemaVersion:_o,appCode:t,devicePolicy:f,rootEntry:{code:_.code,desktop:_.path,mobile:d.path},authentication:a,routes:i};return{...u,digest:ee(u)}}function Nt(e,t){if(e===void 0)return;let o=R(e,t,32);ui.has(o)||p("NATIVE_ADMIN_ICON_INVALID",t)}function oo(e,t){e!==void 0&&Z(e,t,-1e4,1e4)}function _n(e,t,o){return e.capability!==void 0&&e.access!==void 0&&p("NATIVE_ROUTE_ACCESS_CONFLICT",`${t}/access`),e.capability!==void 0?{capability:Ce(e.capability,`${t}/capability`,o)}:e.access===void 0?{}:{access:bt(e.access,`${t}/access`,o)}}function bt(e,t,o){let n=N(e,t);h(n,["allOf","anyOf"],t,!0);let s=n.allOf===void 0?void 0:j(v(n.allOf,`${t}/allOf`,50).map((c,r)=>Ce(c,`${t}/allOf/${r}`,o))),i=n.anyOf===void 0?void 0:j(v(n.anyOf,`${t}/anyOf`,50).map((c,r)=>Ce(c,`${t}/anyOf/${r}`,o)));return(s?.length||0)+(i?.length||0)===0&&p("NATIVE_ROUTE_ACCESS_EMPTY",t),{...s===void 0?{}:{allOf:s},...i===void 0?{}:{anyOf:i}}}function yo(e){let t=new Map(Io(e).map(s=>[String(s.code),s])),o=e.workflows.definitions.map((s,i)=>{let c=`/config/workflows/definitions/${i}`,r=N(s,c);h(r,["version","definition","launch"],c,["detailRouteCode"]);let a=N(r.definition,`${c}/definition`),f=r.detailRouteCode===void 0?void 0:$o(r.detailRouteCode,`${c}/detailRouteCode`);return{code:w(a.code,`${c}/definition/code`),title:R(a.title,`${c}/definition/title`,255),version:xe(r.version,`${c}/version`),launch:Qi(e,a,r.launch,`${c}/launch`,t),...f?{detailRouteCode:f}:{},definition:a}});return j(o.map(s=>s.code)).map(s=>{let i=o.filter(f=>f.code===s),c=e.workflows.activations.find(f=>f.workflowCode===s)?.definitionVersion,r=i.find(f=>f.version===c)||[...i].sort((f,_)=>_.version-f.version)[0],a=new Set;for(let f of i){let _=N(f.definition.nodes,"/config/workflows/definitions/nodes");for(let d of Object.values(_)){let u=N(d,"/config/workflows/definitions/nodes/*");if(u.kind==="approval")for(let I of v(u.allowedOperations||[],"/config/workflows/definitions/nodes/*/allowedOperations",20))a.add(I)}}return{code:s,title:r.title,acceptedCommandDeactivationPolicy:r.definition.acceptedCommandDeactivationPolicy,subject:r.definition.subject,launch:r.launch,...["standalone","hidden-handoff"].includes(r.launch.mode)&&!r.launch.submission?{processOperationCode:`openxiangda.workflow.${s}.submit`}:{},...r.detailRouteCode?{detailRouteCode:r.detailRouteCode}:{},definitionVersions:fo(i.map(f=>f.version)),bindingVersions:fo(e.workflows.bindings.map((f,_)=>{let d=`/config/workflows/bindings/${_}`,u=N(f,d),I=N(u.binding,`${d}/binding`);return{code:w(I.workflowCode,`${d}/binding/workflowCode`),version:xe(u.version,`${d}/version`)}}).filter(f=>f.code===s).map(f=>f.version)),providerCodes:j(e.workflows.providers.map((f,_)=>w(N(f,`/config/workflows/providers/${_}`).code,`/config/workflows/providers/${_}/code`))),allowedOperations:[...a].sort(ae),editableParameterCodes:j(e.workflows.editableParameters.map((f,_)=>{let d=`/config/workflows/editableParameters/${_}`,u=N(f,d);return{code:w(u.code,`${d}/code`),workflowCode:w(u.workflowCode,`${d}/workflowCode`)}}).filter(f=>f.workflowCode===s).map(f=>f.code))}})}function ho(e,t){let o=N(e,t);h(o,["mode"],t,["submission"]);let n=R(o.mode,`${t}/mode`,32);return["standalone","custom-page","hidden-handoff","work-center-only"].includes(n)||p("NATIVE_WORKFLOW_LAUNCH_MODE_INVALID",`${t}/mode`),{mode:n,...o.submission===void 0?{}:{submission:N(o.submission,`${t}/submission`)}}}function Qi(e,t,o,n,s){let i=ho(o,n);if(!i.submission)return{mode:i.mode};["standalone","hidden-handoff"].includes(i.mode)||p("NATIVE_WORKFLOW_NAMED_OPERATION_SUBMISSION_INVALID",`${n}/submission`);let c=N(i.submission,`${n}/submission`);h(c,["kind"],`${n}/submission`,["create","existing","context"]),x(c.kind,"named-operation",`${n}/submission/kind`);let r=n.endsWith("/launch")?n.slice(0,-7):n,a=N(t.subject,`${r}/definition/subject`),f=G(a.resourceCode,`${r}/definition/subject/resourceCode`),_=e.data.resources.findIndex(b=>b.code===f),d=e.data.resources[_];(_<0||!d)&&p("NATIVE_WORKFLOW_SUBJECT_RESOURCE_MISSING",`${r}/definition/subject/resourceCode`);let u=new Set(N(d.schema,`/config/data/resources/${_}/schema`).fields.map(b=>String(b.code))),I=new Map(e.backend.operations.map(b=>[String(b.code),b])),l=(b,y)=>{let S=`${n}/submission/${y}`,P=N(b,S);h(P,["operationCode","inputs","output"],S);let F=w(P.operationCode,`${S}/operationCode`),J=I.get(F),M=s.get(F),fe=M?.platformAccess?.workflow?.codes;(!J||!M||M.method!=="POST"||!Array.isArray(fe)||!fe.includes(t.code))&&p("NATIVE_WORKFLOW_NAMED_OPERATION_INVALID",S);let pe=N(J.requestSchema,`${S}/operation/requestSchema`),K=N(pe.properties,`${S}/operation/requestSchema/properties`),me=new Set(pe.required===void 0?[]:v(pe.required,`${S}/operation/requestSchema/required`,64)),ie=N(P.inputs,`${S}/inputs`),V=Object.entries(ie);(!V.length||V.length>64)&&p("NATIVE_WORKFLOW_NAMED_OPERATION_INPUT_INVALID",`${S}/inputs`);let U=new Set,L=new Map,W={};for(let[q,H]of V){(!Hn.test(q)||!Object.prototype.hasOwnProperty.call(K,q))&&p("NATIVE_WORKFLOW_NAMED_OPERATION_INPUT_INVALID",`${S}/inputs/${q}`);let $e=`${S}/inputs/${q}`,yt=N(H,$e),Oe=R(yt.source,`${$e}/source`,32);if(["field","idempotency-key","current-user-reference","subject-id","subject-revision","requested-at"].includes(Oe)||p("NATIVE_WORKFLOW_NAMED_OPERATION_INPUT_INVALID",$e),h(yt,["source"],$e,Oe==="field"?["fieldCode"]:!1),L.set(Oe,(L.get(Oe)||0)+1),Oe==="field"){let Ye=B(yt.fieldCode,`${$e}/fieldCode`);(U.has(Ye)||!u.has(Ye))&&p("NATIVE_WORKFLOW_NAMED_OPERATION_INPUT_INVALID",`${$e}/fieldCode`),U.add(Ye),W[q]={source:Oe,fieldCode:Ye}}else W[q]={source:Oe}}([...me].some(q=>!(q in ie))||(L.get("idempotency-key")||0)!==1||!V.some(([q,H])=>N(H,`${S}/inputs/${q}`).source==="idempotency-key"&&me.has(q))||y==="create"&&((L.get("subject-id")||0)>0||(L.get("subject-revision")||0)>0)||y==="existing"&&((L.get("subject-id")||0)!==1||(L.get("subject-revision")||0)!==1))&&p("NATIVE_WORKFLOW_NAMED_OPERATION_INPUT_INVALID",`${S}/inputs`);let z=N(P.output,`${S}/output`);h(z,["subjectId"],`${S}/output`,["subjectRevision","processCommand"]);let Ie=N(N(J.responseSchema,`${S}/operation/responseSchema`).properties,`${S}/operation/responseSchema/properties`);for(let q of["subjectId","subjectRevision","processCommand"]){if(z[q]===void 0)continue;let H=R(z[q],`${S}/output/${q}`,128);(!Hn.test(H)||!Object.prototype.hasOwnProperty.call(Ie,H))&&p("NATIVE_WORKFLOW_NAMED_OPERATION_OUTPUT_INVALID",`${S}/output/${q}`)}return{operationCode:F,method:"POST",path:M.path,requiredCapability:M.requiredCapability,requestSchemaDigest:M.requestSchemaDigest,responseSchemaDigest:M.responseSchemaDigest,inputs:W,output:{...z},fieldCodes:U}},E=c.create===void 0?void 0:l(c.create,"create"),T=c.existing===void 0?void 0:l(c.existing,"existing");!E&&!T&&p("NATIVE_WORKFLOW_NAMED_OPERATION_SUBMISSION_INVALID",`${n}/submission`);let g=new Set([...E?.fieldCodes||[],...T?.fieldCodes||[]]),A=c.context===void 0?[]:$(c.context,`${n}/submission/context`,16),m=new Set,O=A.map((b,y)=>{let S=`${n}/submission/context/${y}`,P=N(b,S);h(P,["queryParameter","fieldCode"],S);let F=R(P.queryParameter,`${S}/queryParameter`,64),J=B(P.fieldCode,`${S}/fieldCode`);return(!/^[A-Za-z][A-Za-z0-9]{0,63}$/.test(F)||m.has(F)||!g.has(J))&&p("NATIVE_WORKFLOW_LAUNCH_CONTEXT_INVALID",S),m.add(F),{queryParameter:F,fieldCode:J}}),C=b=>{let{fieldCodes:y,...S}=b;return S};return{mode:i.mode,submission:{kind:"named-operation",...E?{create:C(E)}:{},...T?{existing:C(T)}:{},context:O}}}function $o(e,t){let o=N(e,t);h(o,["desktop","mobile"],t);let n=w(o.desktop,`${t}/desktop`),s=w(o.mobile,`${t}/mobile`);return n===s&&p("NATIVE_WORKFLOW_DETAIL_ROUTE_DUPLICATE",t),{desktop:n,mobile:s}}function Zi(e,t){let o=new Set(t.map(_=>_.code)),n=new Map;e.data.resources.forEach((_,d)=>{let u=`/config/data/resources/${d}`,I=N(_,u);for(let[T,g]of Object.entries(I.fieldPolicies||{})){if(!Se(T))continue;let A=`${u}/fieldPolicies/${T}/read`,m=N(g,`${u}/fieldPolicies/${T}`);for(let O of v(m.read||[],A,2e3))o.has(O)||p("NATIVE_CAPABILITY_REFERENCE_MISSING",A)}let l=I.surface===void 0?{}:N(I.surface,`${u}/surface`);if(["native","queued-command"].includes(l.mutationOwner||"native"))return;let E=N(I.capabilities,`${u}/capabilities`);for(let T of["create","update","delete"])n.set(String(E[T]),T)});let s=new Set;for(let[_,d]of e.authz.roles.entries()){let u=`/config/authz/roles/${_}`,I=N(d,u);h(I,["code","name","description","capabilities"],u,!0);let l=w(I.code,`${u}/code`);s.has(l)&&p("NATIVE_ROLE_DUPLICATE",`${u}/code`),s.add(l),R(I.name,`${u}/name`,255);let E=v(I.capabilities,`${u}/capabilities`,2e3);for(let[T,g]of E.entries())n.has(g)&&p("NATIVE_DATA_SURFACE_MUTATION_GRANT_FORBIDDEN",`${u}/capabilities/${T}`,{operation:n.get(g)}),o.has(g)||p("NATIVE_CAPABILITY_REFERENCE_MISSING",`${u}/capabilities`)}let i=e.authz.authenticatedUserRoleCode===void 0?"":w(e.authz.authenticatedUserRoleCode,"/config/authz/authenticatedUserRoleCode");i&&!s.has(i)&&p("NATIVE_AUTHENTICATED_USER_ROLE_REFERENCE_MISSING","/config/authz/authenticatedUserRoleCode");let c=new Set,r=0;for(let[_,d]of e.perspectives.entries()){let u=`/config/perspectives/${_}`,I=N(d,u);h(I,["code","name","description","roleCodes","capabilityCodes","default"],u,!0);let l=w(I.code,`${u}/code`);c.has(l)&&p("NATIVE_PERSPECTIVE_DUPLICATE",`${u}/code`),c.add(l),R(I.name,`${u}/name`,255);let E=v(I.roleCodes,`${u}/roleCodes`,20);E.length<1&&p("NATIVE_PERSPECTIVE_ROLE_REQUIRED",`${u}/roleCodes`),E.forEach((A,m)=>{s.has(A)||p("NATIVE_PERSPECTIVE_ROLE_MISSING",`${u}/roleCodes/${m}`)});let T=j(e.authz.roles.filter(A=>E.includes(A.code)).flatMap(A=>A.capabilities)),g=v(I.capabilityCodes,`${u}/capabilityCodes`,2e3);Q(T)!==Q(g)&&p("NATIVE_PERSPECTIVE_CAPABILITY_PROJECTION_MISMATCH",`${u}/capabilityCodes`),I.default===!0?r+=1:I.default!==void 0&&p("NATIVE_PERSPECTIVE_DEFAULT_INVALID",`${u}/default`)}r>1&&p("NATIVE_PERSPECTIVE_DEFAULT_DUPLICATE","/config/perspectives");for(let[_,d]of e.backend.operations.entries()){let u=N(d,`/config/backend/operations/${_}`);o.has(u.capability)||p("NATIVE_CAPABILITY_REFERENCE_MISSING",`/config/backend/operations/${_}/capability`)}let a=new Set,f=new Set;for(let[_,d]of e.frontend.routes.entries()){let u=`/config/frontend/routes/${_}`,I=N(d,u),l=w(I.code,`${u}/code`);a.has(l)&&p("NATIVE_ROUTE_DUPLICATE",`${u}/code`),a.add(l);let E=ue(I.path,`${u}/path`);f.has(E)&&p("NATIVE_ROUTE_PATH_DUPLICATE",`${u}/path`),f.add(E);let T=_n(I,u,e.appCode);T.capability&&!o.has(T.capability)&&p("NATIVE_CAPABILITY_REFERENCE_MISSING",`${u}/capability`);let g=I.access===void 0?void 0:N(I.access,`${u}/access`);for(let A of["allOf","anyOf"]){let m=g?.[A]===void 0?[]:$(g[A],`${u}/access/${A}`,50);for(let[O,C]of m.entries()){let b=Ce(C,`${u}/access/${A}/${O}`,e.appCode);o.has(b)||p("NATIVE_CAPABILITY_REFERENCE_MISSING",`${u}/access/${A}/${O}`)}}}if(e.frontend.admin.access!==void 0){let _=bt(e.frontend.admin.access,"/config/frontend/admin/access",e.appCode);for(let d of["allOf","anyOf"])for(let[u,I]of(_[d]||[]).entries())o.has(I)||p("NATIVE_CAPABILITY_REFERENCE_MISSING",`/config/frontend/admin/access/${d}/${u}`)}for(let[_,d]of e.frontend.routes.entries()){let u=N(d,`/config/frontend/routes/${_}`);u.parentCode&&!a.has(u.parentCode)&&p("NATIVE_ROUTE_PARENT_MISSING",`/config/frontend/routes/${_}/parentCode`)}}function er(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()),i=new Map(e.data.resources.map((f,_)=>{let d=he(f,`/config/data/resources/${_}`,e.appCode);return[d.code,new Map(d.schema.fields.map(u=>[String(u.code),u]))]}));for(let[f,_]of e.authz.scopeDimensions.entries()){let d=`/config/authz/scopeDimensions/${f}`,u=N(_,d);if(h(u,["code","name","resourceCode","valueType","hierarchyMode","valueSource"],d,!0),u.valueSource===void 0)continue;let I=N(u.valueSource,`${d}/valueSource`);h(I,["kind","resourceCode","labelField","enabledField"],`${d}/valueSource`,!0),I.kind!=="native_resource"&&p("NATIVE_SCOPE_VALUE_SOURCE_KIND_INVALID",`${d}/valueSource/kind`),u.valueType!=="uuid"&&p("NATIVE_SCOPE_VALUE_SOURCE_TYPE_INVALID",`${d}/valueType`);let l=G(I.resourceCode,`${d}/valueSource/resourceCode`),E=i.get(l);E||p("NATIVE_SCOPE_VALUE_SOURCE_RESOURCE_MISSING",`${d}/valueSource/resourceCode`);let T=B(I.labelField,`${d}/valueSource/labelField`);if(["text.short","text.long"].includes(String(E.get(T)?.type||""))||p("NATIVE_SCOPE_VALUE_SOURCE_LABEL_FIELD_INVALID",`${d}/valueSource/labelField`),I.enabledField!==void 0){let g=B(I.enabledField,`${d}/valueSource/enabledField`);E.get(g)?.type!=="boolean"&&p("NATIVE_SCOPE_VALUE_SOURCE_ENABLED_FIELD_INVALID",`${d}/valueSource/enabledField`)}}let c=new Set,r=new Set;for(let[f,_]of e.authz.scopeSources.entries()){let d=`/config/authz/scopeSources/${f}`,u=N(_,d);h(u,["code","name","resourceCode","subject","grants","operationField","enabledField","effectiveFromField","effectiveToField","failureMode"],d,!0);let I=w(u.code,`${d}/code`);c.has(I)&&p("NATIVE_SCOPE_SOURCE_DUPLICATE",`${d}/code`),c.add(I),R(u.name,`${d}/name`,255);let l=G(u.resourceCode,`${d}/resourceCode`),E=i.get(l);E||p("NATIVE_SCOPE_SOURCE_RESOURCE_MISSING",`${d}/resourceCode`);let T=N(u.subject,`${d}/subject`),g=R(T.type,`${d}/subject/type`,32);h(T,g==="role_membership"?["type","userIdField","roleCode"]:["type","userIdField"],`${d}/subject`),["user","role_membership"].includes(g)||p("NATIVE_SCOPE_SOURCE_SUBJECT_INVALID",`${d}/subject/type`);let A=ve(T.userIdField,E);ft(A)||p("NATIVE_SCOPE_SOURCE_SUBJECT_PATH_INVALID",`${d}/subject/userIdField`),g==="role_membership"&&!t.has(String(T.roleCode))&&p("NATIVE_ROLE_REFERENCE_MISSING",`${d}/subject/roleCode`);let m=new Set;for(let[O,C]of $(u.grants,`${d}/grants`,100).entries()){let b=`${d}/grants/${O}`,y=N(C,b);h(y,["dimensionCode","valueField","parentValueField"],b,!0);let S=w(y.dimensionCode,`${b}/dimensionCode`);(!s.has(S)||m.has(S))&&p("NATIVE_SCOPE_SOURCE_DIMENSION_INVALID",`${b}/dimensionCode`),m.add(S),u.failureMode==="last_known_good"&&r.add(S);for(let P of["valueField","parentValueField"]){if(y[P]===void 0)continue;let F=ve(y[P],E);Xt(F,n.get(S),i)||p("NATIVE_SCOPE_SOURCE_GRANT_PATH_INVALID",`${b}/${P}`)}}m.size===0&&p("NATIVE_SCOPE_SOURCE_GRANT_REQUIRED",`${d}/grants`),["strict","last_known_good"].includes(u.failureMode)||p("NATIVE_SCOPE_SOURCE_FAILURE_MODE_INVALID",`${d}/failureMode`);for(let O of["operationField","enabledField","effectiveFromField","effectiveToField"]){if(u[O]===void 0)continue;let C=B(u[O],`${d}/${O}`);E.has(C)||p("NATIVE_SCOPE_SOURCE_FIELD_MISSING",`${d}/${O}`)}}nr(e,t,i,o);let a=new Set;for(let[f,_]of e.authz.dataPolicies.entries()){let d=`/config/authz/dataPolicies/${f}`,u=N(_,d);h(u,["code","name","resourceCode","unrestrictedRoleCodes","operations","matchMode","rules","readExpression","writeBoundary"],d,!0);let I=w(u.code,`${d}/code`);a.has(I)&&p("NATIVE_DATA_POLICY_DUPLICATE",`${d}/code`),a.add(I);let l=u.readExpression!==void 0,E=v(u.operations||[],`${d}/operations`,4);u.operations!==void 0&&(E.length===0||E.some(C=>!["read","create","update","delete"].includes(C)))&&p("NATIVE_DATA_POLICY_OPERATIONS_INVALID",`${d}/operations`),["AND","OR"].includes(u.matchMode)||p("NATIVE_DATA_POLICY_MATCH_MODE_INVALID",`${d}/matchMode`),l&&u.operations!==void 0&&p("NATIVE_DATA_POLICY_READ_EXPRESSION_OPERATIONS_FORBIDDEN",`${d}/operations`);let T=e.data.resources.find(C=>C.dataPolicyCode===I),g=u.resourceCode||T?.code,A=g?i.get(G(g,`${d}/resourceCode`)):void 0;l&&!A&&p("NATIVE_DATA_POLICY_RESOURCE_MISSING",`${d}/resourceCode`);let m=v(u.unrestrictedRoleCodes||[],`${d}/unrestrictedRoleCodes`,100);u.unrestrictedRoleCodes!==void 0&&m.length===0&&p("NATIVE_DATA_POLICY_UNRESTRICTED_ROLES_INVALID",`${d}/unrestrictedRoleCodes`);for(let C of m)t.has(C)||p("NATIVE_ROLE_REFERENCE_MISSING",`${d}/unrestrictedRoleCodes`);let O;try{let C=$(u.rules,`${d}/rules`,100).map((b,y)=>({rule:N(b,`${d}/rules/${y}`),pointer:`${d}/rules/${y}`}));C.length===0?(!l||u.matchMode!=="AND"||u.writeBoundary!=="capability_only")&&p("NATIVE_DATA_POLICY_WRITE_BOUNDARY_REQUIRED",d):u.writeBoundary!==void 0&&p("NATIVE_DATA_POLICY_WRITE_BOUNDARY_INVALID",`${d}/writeBoundary`),O=[...C],l&&(O.push(...ze(u.readExpression,`${d}/readExpression`)),an(u.readExpression,`${d}/readExpression`))}catch(C){throw C instanceof Le&&p(C.code,C.pointer),C}for(let{rule:C,pointer:b}of O){h(C,["subject","dimensionCode","relationCode","resourceCode","field","roleCodes","operation","valuePath","emptyMatchesAll","operator","value","operand"],b,!0);let y=B(C.field,`${b}/field`),S=A?.get(y);l&&!S&&p("NATIVE_DATA_POLICY_FIELD_MISSING",`${b}/field`);for(let K of v(C.roleCodes||[],`${b}/roleCodes`,100))t.has(K)||p("NATIVE_ROLE_REFERENCE_MISSING",`${b}/roleCodes`);let P=String(C.operator||""),F=C.operand==="db_now",J=["is_null","is_not_null"].includes(P),M=["eq","not_eq","in","not_in"].includes(P),fe=!F&&(C.operator!==void 0||C.value!==void 0);if([C.subject==="current_user"?"current_user":"",typeof C.dimensionCode=="string"?"dimension":"",typeof C.relationCode=="string"?"relationship":"",fe?"constant":"",F?"db_now":""].filter(Boolean).length!==1&&p("NATIVE_DATA_POLICY_RULE_SOURCE_INVALID",b),C.subject!==void 0&&C.subject!=="current_user"&&p("NATIVE_DATA_POLICY_SUBJECT_INVALID",`${b}/subject`),fe){if(!M&&!J&&p("NATIVE_DATA_POLICY_OPERATOR_INVALID",`${b}/operator`),["in","not_in"].includes(P)){let K=$(C.value,`${b}/value`,100).map((me,ie)=>R(me,`${b}/value/${ie}`,2048));(K.length===0||new Set(K).size!==K.length)&&p("NATIVE_DATA_POLICY_VALUE_INVALID",`${b}/value`)}else["eq","not_eq"].includes(P)?R(C.value,`${b}/value`,2048):(C.value!==void 0||C.operand!==void 0)&&p("NATIVE_DATA_POLICY_VALUE_INVALID",`${b}/value`);for(let K of["operation","valuePath","emptyMatchesAll","resourceCode","operand"])C[K]!==void 0&&p("NATIVE_DATA_POLICY_CONSTANT_RULE_INVALID",`${b}/${K}`)}if(F){(!["lt","lte","gt","gte"].includes(P)||C.value!==void 0||S?.type!=="datetime")&&p("NATIVE_DATA_POLICY_DB_NOW_INVALID",b);for(let K of["operation","valuePath","emptyMatchesAll","resourceCode","value"])C[K]!==void 0&&p("NATIVE_DATA_POLICY_DB_NOW_INVALID",`${b}/${K}`)}C.dimensionCode&&!s.has(C.dimensionCode)&&p("NATIVE_SCOPE_DIMENSION_MISSING",`${b}/dimensionCode`),r.has(String(C.dimensionCode||""))&&C.operation!=="read"&&p("NATIVE_SCOPE_SOURCE_LAST_KNOWN_GOOD_UNSAFE",`${b}/operation`)}}for(let[f,_]of e.data.resources.entries()){let d=N(_,`/config/data/resources/${f}`);d.dataPolicyCode&&!a.has(d.dataPolicyCode)&&p("NATIVE_DATA_POLICY_REFERENCE_MISSING",`/config/data/resources/${f}/dataPolicyCode`)}}function tr(e){try{Vt(e.data.resources,"/config/data/resources")}catch(t){throw t instanceof de&&p(t.code,t.pointer),t}}function nr(e,t,o,n){let s=new Set;for(let[i,c]of e.authz.roleMembershipSources.entries()){let r=`/config/authz/roleMembershipSources/${i}`,a=N(c,r);h(a,["code","name","resourceCode","userIdField","roleCode","enabledField","effectiveFromField","effectiveToField","failureMode"],r,!0);let f=w(a.code,`${r}/code`);f.length>100&&p("NATIVE_AUTHORIZATION_PROJECTION_SOURCE_CODE_INVALID",`${r}/code`),s.has(f)&&p("NATIVE_AUTHORIZATION_PROJECTION_SOURCE_DUPLICATE",`${r}/code`),s.add(f),R(a.name,`${r}/name`,255);let _=so(a.resourceCode,`${r}/resourceCode`,o);io(a.userIdField,`${r}/userIdField`,_),t.has(String(a.roleCode||""))||p("NATIVE_ROLE_REFERENCE_MISSING",`${r}/roleCode`),n&&a.roleCode===n&&p("NATIVE_AUTHENTICATED_USER_ROLE_SOURCE_CONFLICT",`${r}/roleCode`),ro(a,r,_)}for(let[i,c]of e.authz.relationshipGrantSources.entries()){let r=`/config/authz/relationshipGrantSources/${i}`,a=N(c,r);h(a,["code","name","resourceCode","subject","relationCode","targetResourceCode","resourceIdField","operations","enabledField","effectiveFromField","effectiveToField","failureMode"],r,!0);let f=w(a.code,`${r}/code`);f.length>100&&p("NATIVE_AUTHORIZATION_PROJECTION_SOURCE_CODE_INVALID",`${r}/code`),s.has(f)&&p("NATIVE_AUTHORIZATION_PROJECTION_SOURCE_DUPLICATE",`${r}/code`),s.add(f),R(a.name,`${r}/name`,255);let _=so(a.resourceCode,`${r}/resourceCode`,o),d=N(a.subject,`${r}/subject`),u=R(d.type,`${r}/subject/type`,32);h(d,u==="role_membership"?["type","userIdField","roleCode"]:["type","userIdField"],`${r}/subject`),["user","role_membership"].includes(u)||p("NATIVE_AUTHORIZATION_PROJECTION_SUBJECT_INVALID",`${r}/subject/type`),io(d.userIdField,`${r}/subject/userIdField`,_),u==="role_membership"&&!t.has(String(d.roleCode||""))&&p("NATIVE_ROLE_REFERENCE_MISSING",`${r}/subject/roleCode`),w(a.relationCode,`${r}/relationCode`);let I=G(a.targetResourceCode,`${r}/targetResourceCode`);o.has(I)||p("NATIVE_AUTHORIZATION_PROJECTION_TARGET_RESOURCE_MISSING",`${r}/targetResourceCode`);let l=ve(a.resourceIdField,_),E=l?.field.type==="resource-ref.single"&&l.valuePath==="value"&&l.field.source?.resourceCode===I;(a.resourceIdField==="id"?I!==String(a.resourceCode):!E)&&p("NATIVE_AUTHORIZATION_PROJECTION_RESOURCE_ID_FIELD_INVALID",`${r}/resourceIdField`);let T=v(a.operations,`${r}/operations`,20);(T.length===0||T.some(g=>g.length>64||!/^[A-Za-z0-9][A-Za-z0-9:._*-]{0,63}$/.test(g)))&&p("NATIVE_AUTHORIZATION_PROJECTION_OPERATIONS_INVALID",`${r}/operations`),ro(a,r,_)}}function so(e,t,o){let n=G(e,t),s=o.get(n);return s||p("NATIVE_AUTHORIZATION_PROJECTION_RESOURCE_MISSING",t),s}function io(e,t,o){let n=ve(e,o);ft(n)||p("NATIVE_AUTHORIZATION_PROJECTION_USER_FIELD_INVALID",t)}function ro(e,t,o){if(e.failureMode!=="strict"&&p("NATIVE_AUTHORIZATION_PROJECTION_FAILURE_MODE_INVALID",`${t}/failureMode`),e.enabledField!==void 0){let n=B(e.enabledField,`${t}/enabledField`);o.get(n)?.type!=="boolean"&&p("NATIVE_AUTHORIZATION_PROJECTION_ENABLED_FIELD_INVALID",`${t}/enabledField`)}for(let n of["effectiveFromField","effectiveToField"]){if(e[n]===void 0)continue;let s=B(e[n],`${t}/${n}`);["date","datetime"].includes(String(o.get(s)?.type))||p("NATIVE_AUTHORIZATION_PROJECTION_EFFECTIVE_FIELD_INVALID",`${t}/${n}`)}}function or(e){let t=new Set,o=new Set;e.forEach((n,s)=>{let i=`/config/backend/secrets/${s}`,c=N(n,i);h(c,["name","env","description","required","exposure"],i,!0);let r=R(c.name,`${i}/name`,128),a=R(c.env,`${i}/env`,128);oi.test(r)||p("NATIVE_SECRET_NAME_INVALID",`${i}/name`),(!si.test(a)||a.startsWith("OPENXIANGDA_")||["NODE_ENV","PORT"].includes(a))&&p("NATIVE_SECRET_ENV_INVALID",`${i}/env`),t.has(r)&&p("NATIVE_SECRET_NAME_DUPLICATE",`${i}/name`),o.has(a)&&p("NATIVE_SECRET_ENV_DUPLICATE",`${i}/env`),t.add(r),o.add(a),x(c.exposure,"active_only",`${i}/exposure`),c.required!==void 0&&Ue(c.required,`${i}/required`),c.description!==void 0&&En(c.description,`${i}/description`,2e3)})}function sr(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,I)=>{let l=N(u,`/config/frontend/routes/${I}`);return[w(l.code,`/config/frontend/routes/${I}/code`),l]}));for(let[u,I]of e.workflows.definitions.entries()){let l=`/config/workflows/definitions/${u}`,E=N(I,l);if(h(E,["version","definition","launch"],l,["detailRouteCode"]),ho(E.launch,`${l}/launch`),E.detailRouteCode!==void 0){let m=$o(E.detailRouteCode,`${l}/detailRouteCode`);for(let[O,C,b]of[["desktop",m.desktop,["admin","user"]],["mobile",m.mobile,["user"]]]){let y=`${l}/detailRouteCode/${O}`,S=s.get(C);S||p("NATIVE_WORKFLOW_DETAIL_ROUTE_MISSING",y),b.some(J=>J===S.surface)||p("NATIVE_WORKFLOW_DETAIL_ROUTE_SURFACE_INVALID",y);let P=ue(S.path,y),F=[...P.matchAll(/:([A-Za-z][A-Za-z0-9_]*)/g)].map(J=>J[1]);(P.includes("*")||F.length!==1||F[0]!=="instanceId")&&p("NATIVE_WORKFLOW_DETAIL_ROUTE_PATH_INVALID",y)}}let T=N(E.definition,`${l}/definition`),g=`${T.code}:${xe(E.version,`${l}/version`)}`;t.has(g)&&p("NATIVE_WORKFLOW_DEFINITION_DUPLICATE",l),t.add(g),rr(T,`${l}/definition`),ir(T.subject,n,`${l}/definition/subject`);let A=sn(T,{appCode:e.appCode,capabilities:e.authz.capabilities.map(m=>m.code),fields:new Map((n.get(T.subject.resourceCode)?.schema.fields||[]).map(m=>[m.code,m]))});A.length&&p("NATIVE_WORKFLOW_INSTANCE_COMMAND_POLICY_INVALID",`${l}/definition/instanceCommands`,{errors:A}),T.title===T.code&&p("NATIVE_WORKFLOW_USER_TITLE_REQUIRED",`${l}/definition/title`),o.set(g,T)}let i=new Set,c=new Map;for(let[u,I]of e.workflows.bindings.entries()){let l=N(I,`/config/workflows/bindings/${u}`),E=N(l.binding,`/config/workflows/bindings/${u}/binding`),T=`${E.workflowCode}:${xe(l.version,`/config/workflows/bindings/${u}/version`)}`;i.has(T)&&p("NATIVE_WORKFLOW_BINDING_DUPLICATE",`/config/workflows/bindings/${u}`),i.add(T),ar(E,`/config/workflows/bindings/${u}/binding`),c.set(T,E)}let r=new Set,a=new Map;for(let[u,I]of e.workflows.activations.entries()){let l=`/config/workflows/activations/${u}`,E=N(I,l);h(E,["workflowCode","definitionVersion","bindingVersion","acceptedCommandDeactivationPolicy"],l,["environmentKey"]);let T=w(E.workflowCode,`${l}/workflowCode`);r.has(T)&&p("NATIVE_WORKFLOW_ACTIVATION_DUPLICATE",l),r.add(T);let g=`${T}:${xe(E.definitionVersion,`${l}/definitionVersion`)}`,A=`${T}:${xe(E.bindingVersion,`${l}/bindingVersion`)}`;t.has(g)||p("NATIVE_WORKFLOW_DEFINITION_REFERENCE_MISSING",`${l}/definitionVersion`),i.has(A)||p("NATIVE_WORKFLOW_BINDING_REFERENCE_MISSING",`${l}/bindingVersion`);let m=o.get(g),O=c.get(A);(!["finish-pinned","cancel-on-deactivate"].includes(E.acceptedCommandDeactivationPolicy)||E.acceptedCommandDeactivationPolicy!==m.acceptedCommandDeactivationPolicy)&&p("NATIVE_WORKFLOW_COMMAND_DEACTIVATION_POLICY_MISMATCH",`${l}/acceptedCommandDeactivationPolicy`),cr(m,O,`/config/workflows/activations/${u}`),a.set(T,O)}let f=new Set;e.workflows.providers.forEach((u,I)=>{let l=`/config/workflows/providers/${I}`,E=N(u,l);h(E,["code","endpointPath","timeoutMs"],l,!0);let T=w(E.code,`${l}/code`);f.has(T)&&p("NATIVE_WORKFLOW_PROVIDER_DUPLICATE",`${l}/code`),f.add(T),ue(E.endpointPath,`${l}/endpointPath`),E.timeoutMs!==void 0&&Z(E.timeoutMs,`${l}/timeoutMs`,100,1e4)});for(let[u,I]of a.entries())for(let[l,E]of Object.entries(N(I.bindings,"/config/workflows/bindings/*/binding/bindings"))){let T=N(E,`/config/workflows/${u}/bindings/${l}`);T.provider==="application_provider"&&!f.has(T.providerCode)&&p("NATIVE_WORKFLOW_PROVIDER_REFERENCE_MISSING",`/config/workflows/${u}/bindings/${l}/providerCode`)}let _=new Set(e.authz.roles.map(u=>u.code)),d=new Set;e.workflows.editableParameters.forEach((u,I)=>{let l=`/config/workflows/editableParameters/${I}`,E=N(u,l);h(E,["code","workflowCode","bindingKey","label","valueType","required","allowedRoleCodes","allowedProviderCodes","maxItems"],l,!0);let T=w(E.code,`${l}/code`);d.has(T)&&p("NATIVE_WORKFLOW_EDITABLE_PARAMETER_DUPLICATE",`${l}/code`),d.add(T);let g=Ot(E.workflowCode,`${l}/workflowCode`),A=An(E.bindingKey,`${l}/bindingKey`),m=a.get(g);(!m||!N(m.bindings,`${l}/bindingKey`)[A])&&p("NATIVE_WORKFLOW_EDITABLE_BINDING_MISSING",`${l}/bindingKey`),R(E.label,`${l}/label`,255),["role_code","user_ids","provider_code"].includes(E.valueType)||p("NATIVE_WORKFLOW_EDITABLE_VALUE_TYPE_INVALID",`${l}/valueType`);for(let O of v(E.allowedRoleCodes||[],`${l}/allowedRoleCodes`,100))_.has(O)||p("NATIVE_ROLE_REFERENCE_MISSING",`${l}/allowedRoleCodes`);for(let O of v(E.allowedProviderCodes||[],`${l}/allowedProviderCodes`,100))f.has(O)||p("NATIVE_WORKFLOW_PROVIDER_REFERENCE_MISSING",`${l}/allowedProviderCodes`);E.required!==void 0&&Ue(E.required,`${l}/required`),E.maxItems!==void 0&&Z(E.maxItems,`${l}/maxItems`,1,200)})}function ir(e,t,o){let n=N(e,o);h(n,["resourceCode","factProjection"],o,["summaryFields"]);let s=G(n.resourceCode,`${o}/resourceCode`),i=t.get(s);i||p("NATIVE_WORKFLOW_SUBJECT_RESOURCE_MISSING",`${o}/resourceCode`);let c=new Set($(N(i.schema,`${o}/resourceCode`).fields,`${o}/resourceCode`,500).map((f,_)=>B(N(f,`${o}/resourceCode/${_}`).code,`${o}/resourceCode/${_}`))),r=N(n.factProjection,`${o}/factProjection`),a=Object.entries(r);(a.length<1||a.length>64)&&p("NATIVE_WORKFLOW_SUBJECT_FACT_PROJECTION_INVALID",`${o}/factProjection`);for(let[f,_]of a){ai.test(f)||p("NATIVE_WORKFLOW_SUBJECT_FACT_KEY_INVALID",`${o}/factProjection/${f}`);let d=B(_,`${o}/factProjection/${f}`);c.has(d)||p("NATIVE_WORKFLOW_SUBJECT_FIELD_MISSING",`${o}/factProjection/${f}`)}if(n.summaryFields!==void 0){let f=v(n.summaryFields,`${o}/summaryFields`,ci).map((l,E)=>B(l,`${o}/summaryFields/${E}`)),_=t.get(s),d=_.surface&&typeof _.surface=="object"&&!Array.isArray(_.surface)?_.surface:{},u=d.fields&&typeof d.fields=="object"&&!Array.isArray(d.fields)?d.fields:{},I=new Map($(N(_.schema,`${o}/resourceCode`).fields,`${o}/resourceCode`,500).map((l,E)=>{let T=N(l,`${o}/resourceCode/${E}`);return[String(T.code),T]}));for(let[l,E]of f.entries()){let T=I.get(E),g=u[E],A=String(T?.type||""),m=T?.maxLength;(!T||T.system===!0||g&&typeof g=="object"&&!Array.isArray(g)&&g.system===!0||["id","revision","created_by","updated_by","created_at","updated_at"].includes(E)||!li.has(A)||A==="text.long"&&typeof m=="number"&&Number.isFinite(m)&&m>di)&&p("NATIVE_WORKFLOW_SUBJECT_SUMMARY_FIELDS_INVALID",`${o}/summaryFields/${l}`)}}}function rr(e,t){h(e,["schemaVersion","code","title","subject","acceptedCommandDeactivationPolicy","startAt","inputSchema","nodes"],t,["organizationContext","instanceCommands"]),x(e.schemaVersion,"openxiangda.workflow-definition/v2",`${t}/schemaVersion`),Ot(e.code,`${t}/code`),R(e.title,`${t}/title`,255),["finish-pinned","cancel-on-deactivate"].includes(e.acceptedCommandDeactivationPolicy)||p("NATIVE_WORKFLOW_COMMAND_DEACTIVATION_POLICY_REQUIRED",`${t}/acceptedCommandDeactivationPolicy`);let o=N(e.nodes,`${t}/nodes`),n=Object.keys(o);(n.length===0||n.length>200)&&p("NATIVE_WORKFLOW_NODE_COUNT_INVALID",`${t}/nodes`);let s=R(e.startAt,`${t}/startAt`,128);o[s]||p("NATIVE_WORKFLOW_START_NODE_MISSING",`${t}/startAt`);let i=new Map;for(let[f,_]of Object.entries(o)){let d=`${t}/nodes/${f}`,u=N(_,d);x(u.id,f,`${d}/id`),["approval","condition","end"].includes(u.kind)||p("NATIVE_WORKFLOW_NODE_KIND_INVALID",`${d}/kind`);let I=[];if(u.kind==="approval"){R(u.title,`${d}/title`,255),An(u.binding,`${d}/binding`),["single","any","all","sequence"].includes(u.mode)||p("NATIVE_WORKFLOW_APPROVAL_MODE_INVALID",`${d}/mode`),I.push(R(u.onApprove,`${d}/onApprove`,128),R(u.onReject,`${d}/onReject`,128));for(let l of v(u.returnTargets||[],`${d}/returnTargets`,200))o[l]||p("NATIVE_WORKFLOW_TARGET_MISSING",`${d}/returnTargets`);for(let l of v(u.allowedOperations||[],`${d}/allowedOperations`,20))fi.has(l)||p("NATIVE_WORKFLOW_OPERATION_INVALID",`${d}/allowedOperations`)}else if(u.kind==="condition"){let l=$(u.branches,`${d}/branches`,100);l.length===0&&p("NATIVE_WORKFLOW_BRANCH_REQUIRED",`${d}/branches`),l.forEach((E,T)=>{let g=N(E,`${d}/branches/${T}`);Ge(g.when,`${d}/branches/${T}/when`,0),I.push(R(g.target,`${d}/branches/${T}/target`,128))}),I.push(R(u.otherwise,`${d}/otherwise`,128))}else R(u.title,`${d}/title`,255),R(u.outcome,`${d}/outcome`,128);for(let l of I)o[l]||p("NATIVE_WORKFLOW_TARGET_MISSING",d);i.set(f,I)}let c=new Set,r=new Set,a=f=>{if(r.has(f)&&p("NATIVE_WORKFLOW_CYCLE_FORBIDDEN",`${t}/nodes/${f}`),!c.has(f)){c.add(f),r.add(f);for(let _ of i.get(f)||[])a(_);r.delete(f)}};a(s),c.size!==n.length&&p("NATIVE_WORKFLOW_NODE_UNREACHABLE",`${t}/nodes`)}function Ge(e,t,o){o>20&&p("NATIVE_WORKFLOW_EXPRESSION_DEPTH_EXCEEDED",t);let n=N(e,t),s=R(n.op,`${t}/op`,16);if(s!=="literal"){if(s==="path"){let i=R(n.path,`${t}/path`,255);/^[A-Za-z][A-Za-z0-9_.]{0,254}$/.test(i)||p("NATIVE_WORKFLOW_EXPRESSION_PATH_INVALID",`${t}/path`);return}if(["eq","neq","gt","gte","lt","lte","in","contains"].includes(s)){Ge(n.left,`${t}/left`,o+1),Ge(n.right,`${t}/right`,o+1);return}if(["and","or"].includes(s)){let i=$(n.values,`${t}/values`,100);i.length===0&&p("NATIVE_WORKFLOW_EXPRESSION_EMPTY",`${t}/values`),i.forEach((c,r)=>Ge(c,`${t}/values/${r}`,o+1));return}if(["not","exists"].includes(s)){Ge(n.value,`${t}/value`,o+1);return}p("NATIVE_WORKFLOW_EXPRESSION_OPERATOR_INVALID",`${t}/op`)}}function ar(e,t){x(e.schemaVersion,"openxiangda.workflow-binding/v2",`${t}/schemaVersion`),Ot(e.workflowCode,`${t}/workflowCode`);let o=N(e.bindings,`${t}/bindings`);Object.keys(o).length>200&&p("NATIVE_WORKFLOW_BINDING_LIMIT_EXCEEDED",`${t}/bindings`);for(let[n,s]of Object.entries(o)){An(n,`${t}/bindings/${n}`);let i=N(s,`${t}/bindings/${n}`),c=R(i.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(c)||p("NATIVE_WORKFLOW_BINDING_PROVIDER_INVALID",`${t}/bindings/${n}/provider`),c==="fixed_users"&&$(i.users,`${t}/bindings/${n}/users`,200).length===0&&p("NATIVE_WORKFLOW_BINDING_USERS_REQUIRED",`${t}/bindings/${n}/users`),["input_users","form_field_users"].includes(c)&&R(i.inputPath,`${t}/bindings/${n}/inputPath`,255),["app_role","app_role_in_scope","initiator_select"].includes(c)&&w(i.roleCode,`${t}/bindings/${n}/roleCode`),c==="department_supervisor"&&R(i.departmentIdFrom,`${t}/bindings/${n}/departmentIdFrom`,255),c==="application_provider"&&w(i.providerCode,`${t}/bindings/${n}/providerCode`)}}function cr(e,t,o){x(t.workflowCode,e.code,`${o}/workflowCode`);let n=N(t.bindings,`${o}/bindings`);for(let[s,i]of Object.entries(N(e.nodes,`${o}/nodes`))){let c=N(i,`${o}/nodes/${s}`);c.kind==="approval"&&!n[c.binding]&&p("NATIVE_WORKFLOW_BINDING_REFERENCE_MISSING",`${o}/nodes/${s}/binding`)}}function dr(e,t,o){let n=N(t.routeManifest,"/contracts/routeManifest"),s=N(e.routeManifest,"/contracts/routeManifest"),i=new Map;for(let _ of $(o.data?.resources,"/config/data/resources",100)){let d=N(_,"/config/data/resources");i.set(String(d.code||""),d)}let c=new Set($(s.routes,"/contracts/routeManifest/routes",1e3).map(_=>String(N(_,"/contracts/routeManifest/routes").code||""))),r=[];for(let _ of $(n.routes,"/contracts/routeManifest/routes",1e3)){let d=N(_,"/contracts/routeManifest/routes"),u=String(d.kind||"");if(u!=="resource-records"&&u!=="resource-submit")continue;let I=String(d.resourceCode||""),l=i.get(I);l||p("NATIVE_ROUTE_MANIFEST_RESOURCE_UNKNOWN","/contracts/routeManifest/routes");let T=`user.${I}.${u==="resource-records"?"records":"submit"}`;x(String(d.code||""),T,"/contracts/routeManifest/routes/code");let g=u==="resource-records"?"read":"create",A=String(N(l.capabilities,"/config/data/resources/capabilities")[g]||"");for(let m of["desktop","mobile"]){let O=N(d[m],`/contracts/routeManifest/routes/${m}`),C=m==="mobile"?"/m/my/":"/my/",b=u==="resource-records"?`${C}${I}`:`${C}${I}/submit`;x(String(O.path||""),b,`/contracts/routeManifest/routes/${m}/path`),x(String(O.capability||""),A,`/contracts/routeManifest/routes/${m}/capability`),x(String(O.routeCode||""),`${T}.${m}`,`/contracts/routeManifest/routes/${m}/routeCode`)}(c.has(T)||r.some(m=>String(m.code)===T))&&p("NATIVE_ROUTE_MANIFEST_DUPLICATE","/contracts/routeManifest/routes/code"),r.push(d)}if(!r.length)return;s.routes=$([...s.routes,...r],"/contracts/routeManifest/routes",1e3).sort((_,d)=>ae(String(N(_,"x").code||""),String(N(d,"x").code||"")));let a=String(N(n.rootEntry,"x").code||"");if(r.find(_=>String(_.code)===a&&_.kind==="resource-records")){let _=N(n.rootEntry,"x");s.rootEntry={code:a,desktop:String(_.desktop||""),mobile:String(_.mobile||"")}}s.digest=ee({schemaVersion:s.schemaVersion,appCode:s.appCode,devicePolicy:s.devicePolicy,rootEntry:s.rootEntry,authentication:s.authentication,routes:s.routes})}function he(e,t,o){let n=N(e,t);h(n,["schemaVersion","appCode","code","name","schema","surface","invariants","decimalReservationLifecycle","uniqueKeys","capabilities","dataPolicyCode","fieldPolicies"],t,!0),x(n.schemaVersion,"openxiangda.data-resource/v2",`${t}/schemaVersion`),x(n.appCode,o,`${t}/appCode`);let s=G(n.code,`${t}/code`),i=R(n.name,`${t}/name`,255),c=N(n.schema,`${t}/schema`);h(c,["fields"],`${t}/schema`);let r,a,f,_;try{f=ct(n.decimalReservationLifecycle,`${t}/decimalReservationLifecycle`),r=Ze(c.fields,`${t}/schema/fields`),_=tn(n.uniqueKeys,r,`${t}/uniqueKeys`),a=wt(n.invariants,r,`${t}/invariants`),st(n.surface,r,`${t}/surface`)}catch(l){throw(l instanceof de||l instanceof ye||l instanceof Pe)&&p(l.code,l.pointer),l}let d=new Set(r.map(l=>l.code)),u=N(n.capabilities,`${t}/capabilities`);h(u,["read","create","update","delete"],`${t}/capabilities`);let I=N(n.fieldPolicies,`${t}/fieldPolicies`);for(let[l,E]of Object.entries(I)){!d.has(l)&&!Se(l)&&p("NATIVE_DATA_FIELD_POLICY_FIELD_MISSING",`${t}/fieldPolicies/${l}`);let T=`${t}/fieldPolicies/${l}`,g=N(E,T);Se(l)&&(h(g,["read"],T,!0),(!Array.isArray(g.read)||g.read.length>20||g.read.some(A=>typeof A!="string"||!A.trim())||new Set(g.read).size!==g.read.length)&&p("NATIVE_DATA_AUDIT_READ_POLICY_INVALID",`${T}/read`)),h(g,["read","create","update","mask"],T,!0),g.mask!==void 0&&!["omit","null"].includes(g.mask)&&p("NATIVE_DATA_FIELD_POLICY_MASK_INVALID",`${T}/mask`)}return{...n,code:s,name:i,schema:{fields:r},...n.invariants===void 0?{}:{invariants:a},...f?{decimalReservationLifecycle:f}:{},..._!==void 0?{uniqueKeys:_}:{},capabilities:u,fieldPolicies:I}}function Ro(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 ao(e,t,o,n){let s=e.toString("utf8"),i;try{i=JSON.parse(s)}catch{p(o,t)}let c=N(i,t);return Q(c)!==s&&p(n,t),c}function co(e,t){let o=0,n=(s,i,c)=>{if(o+=1,o>Ai&&p("NATIVE_ARTIFACT_NODE_LIMIT_EXCEEDED",i),c>Ei&&p("NATIVE_ARTIFACT_DEPTH_LIMIT_EXCEEDED",i),typeof s=="string"){Buffer.byteLength(s)>dn&&p("NATIVE_ARTIFACT_STRING_LIMIT_EXCEEDED",i);return}if(Array.isArray(s)){s.forEach((r,a)=>n(r,`${i}/${a}`,c+1));return}if(!(!s||typeof s!="object"))for(let[r,a]of Object.entries(s))["__proto__","prototype","constructor"].includes(r)&&p("NATIVE_ARTIFACT_DANGEROUS_KEY",`${i}/${r}`),lr(r)&&p("NATIVE_ARTIFACT_RUNTIME_FIELD_FORBIDDEN",`${i}/${r}`),n(a,`${i}/${r}`,c+1)};n(e,t,0)}function lr(e){return["environmentKey","environmentId","secretValue","ciphertext","oauthClient","oauthClientId","oauthClientSecret","signingSecret","kubernetesNamespace","nodePort","productionUrl"].includes(e)}function ke(e){return{value:e,digest:ee(e)}}function lo(e,t,o,n){typeof e!="string"&&!Buffer.isBuffer(e)&&!(e instanceof Uint8Array)&&p("NATIVE_ARTIFACT_BYTES_REQUIRED",o);let s=Buffer.isBuffer(e)?e:Buffer.from(e);return s.byteLength===0&&p("NATIVE_ARTIFACT_EMPTY",o),s.byteLength>t&&p(n,o),s}function uo(e,t,o,n){let s=Tt.createHash("sha256").update(e).digest("hex");Tt.timingSafeEqual(Buffer.from(s),Buffer.from(t))||p(n,o)}function N(e,t){return(!e||typeof e!="object"||Array.isArray(e))&&p("NATIVE_OBJECT_REQUIRED",t),e}function $(e,t,o){return Array.isArray(e)||p("NATIVE_ARRAY_REQUIRED",t),e.length>o&&p("NATIVE_ARRAY_LIMIT_EXCEEDED",t),e}function v(e,t,o){let n=$(e,t,o).map((s,i)=>R(s,`${t}/${i}`,255));return new Set(n).size!==n.length&&p("NATIVE_ARRAY_DUPLICATE",t),n}function R(e,t,o){return(typeof e!="string"||e.length===0||e.length>o)&&p("NATIVE_STRING_INVALID",t),e}function En(e,t,o){return(typeof e!="string"||e.length>o)&&p("NATIVE_STRING_INVALID",t),e}function w(e,t){let o=R(e,t,128);return Zs.test(o)||p("NATIVE_CODE_INVALID",t),o}function G(e,t){let o=R(e,t,64);return ti.test(o)||p("NATIVE_RESOURCE_CODE_INVALID",t),o}function B(e,t){let o=R(e,t,63);return ni.test(o)||p("NATIVE_FIELD_CODE_INVALID",t),o}function Ot(e,t){let o=R(e,t,128);return ii.test(o)||p("NATIVE_WORKFLOW_CODE_INVALID",t),o}function An(e,t){let o=R(e,t,128);return ri.test(o)||p("NATIVE_WORKFLOW_BINDING_CODE_INVALID",t),o}function Ce(e,t,o){let n=R(e,t,255);return Qs.test(n)||p("NATIVE_CAPABILITY_CODE_INVALID",t),!n.startsWith(`app:${o}:`)&&!Ro(o).some(s=>s.code===n)&&p("NATIVE_CAPABILITY_APP_MISMATCH",t),n}function ue(e,t){let o=R(e,t,2048);return(!o.startsWith("/")||o.startsWith("//")||o.includes("..")||o.includes("?")||o.includes("#"))&&p("NATIVE_ABSOLUTE_PATH_INVALID",t),o}function xe(e,t){return(!Number.isInteger(e)||Number(e)<1)&&p("NATIVE_POSITIVE_INTEGER_REQUIRED",t),Number(e)}function Z(e,t,o,n){return(!Number.isInteger(e)||Number(e)<o||Number(e)>n)&&p("NATIVE_INTEGER_OUT_OF_RANGE",t),Number(e)}function Ue(e,t){return typeof e!="boolean"&&p("NATIVE_BOOLEAN_REQUIRED",t),e}function un(e,t){let o=R(e,t,64).toLowerCase();return Hs.test(o)||p("NATIVE_DIGEST_INVALID",t),o}function x(e,t,o){e!==t&&p("NATIVE_VALUE_MISMATCH",o)}function h(e,t,o,n=!1){let s=new Set([...t,...Array.isArray(n)?n:[]]);for(let i of Object.keys(e))s.has(i)||p("NATIVE_PROPERTY_UNKNOWN",`${o}/${i}`);if(n!==!0)for(let i of t)Object.prototype.hasOwnProperty.call(e,i)||p("NATIVE_PROPERTY_REQUIRED",`${o}/${i}`)}function X(e,t){return[...e].sort((o,n)=>ae(t(o),t(n)))}function j(e){return[...new Set(e)].sort(ae)}function fo(e){return[...new Set(e)].sort((t,o)=>t-o)}function ae(e,t){return e===t?0:e<t?-1:1}function So(e){return!e||typeof e!="object"||Object.isFrozen(e)||(Object.freeze(e),Object.values(e).forEach(t=>So(t))),e}function fn(e,t,o){if(cn(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(!cn(e[s],t[s]))return fn(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 i=e[s],c=t[s];if(!cn(i,c))return fn(i,c,`${o}/${s}`)}}return o}function cn(e,t){return e===void 0||t===void 0?e===t:Q(e)===Q(t)}function p(e,t,o={}){throw new It(e,t,o)}var ur="b7ac11f81972d310db01573232792d62a070632d07ae8d0fef19c4e100488f8b";0&&(module.exports={DATA_AUDIT_METADATA_FIELDS,DATA_EVENT_TYPES_V2,DATA_SYSTEM_SORT_FIELD_CODES,ManagedConcurrencyContractError,NATIVE_CONFIGURATION_VALIDATOR_DIGEST,NATIVE_CONTRACT_CAPACITY_V2,NATIVE_DATA_POLICY_EXPRESSION_MAX_CLAUSES,NATIVE_DATA_POLICY_EXPRESSION_MAX_DEPTH,NATIVE_DATA_POLICY_EXPRESSION_MAX_GROUP_ITEMS,NATIVE_DATA_POLICY_EXPRESSION_MAX_LEAVES,NATIVE_DATA_POLICY_EXPRESSION_MAX_OCCURRENCES,NATIVE_DATA_QUERY_OPERATORS_V2,NATIVE_UNIQUE_KEY_MAX_BYTES,NATIVE_UNIQUE_KEY_NORMALIZERS,NativeConfigurationCompilerError,NativeDataFieldContractV2Error,NativeDataPolicyExpressionV2Error,NativeDecimalLifecycleContractError,NativeEventActionContractError,NativeScopeSourceFieldPathV2Error,NativeUniqueKeyContractError,OPENXIANGDA_NATIVE_DATA_FIELD_TYPES_V2,OPENXIANGDA_NATIVE_DATA_SURFACE_KEYS_V2,OPENXIANGDA_NATIVE_DRAFT_STATE_KEYS_V2,OPENXIANGDA_NATIVE_SYSTEM_FIELDS_V2,OPENXIANGDA_NATIVE_SYSTEM_FIELD_MAP_V2,WORKFLOW_EVENT_TYPES_V2,compileNativeApplicationConfiguration,compileNativeEventAction,compileNativeEventCapturePlansV2,compileRequiredPlatformCapabilitiesV3,hasDataAuditReadPolicy,isDataAuditMetadataField,isDataSystemSortField,isNativeDataQueryOperatorV2,isNativeMultiValueFieldV2,materializeNativeDataQueryPathTypesV2,nativeDataPolicyExpressionLeavesV2,nativeDataPolicyExpressionToCnfV2,nativeDataQueryPathPlanV2,nativeFieldAggregatePlanV2,nativeFieldColumnDefinitionV2,nativeFieldDefaultSqlV2,nativeFieldHasDefaultV2,nativeFieldIndexStatementsV2,nativeFieldRequiresCreateInputV2,nativeFieldSequenceGrantStatementsV2,nativeFieldSequenceOwnershipStatementsV2,nativeFieldSequenceStatementsV2,nativeFieldSupportsFilterV2,nativeFieldSupportsOperatorV2,nativeFieldSupportsSearchV2,nativeFieldSupportsSortV2,nativeOperatorsForFieldV2,nativePhysicalFieldV2,nativePhysicalFieldsV2,nativePhysicalObjectNameV2,nativeScopeSourceFieldValueV2,nativeScopeSourceGrantPathSupportedV2,nativeScopeSourceSubjectPathSupportedV2,nativeSubtableConstraintStatementsV2,nativeUniqueKeysJsonSchema,parseDecimalReservationLifecycle,parseNativeDataFieldsV2,parseNativeDataResourceInvariantsV2,parseNativeUniqueKeys,projectNativeDataResourceViewV2,quoteNativeIdentifierV2,resolveNativeScopeSourceFieldPathV2,validateDecimalReservationLifecycles,validateManagedConcurrency,validateNativeDataDraftStateV2,validateNativeDataResourceReferencesV2,validateNativeDataResourceSurfaceV2,validateWorkflowInstanceCommandPolicies,workflowInstanceCommandDeadlineError,workflowInstanceTerminateCapabilityAllowed,workflowPolicyTimestamp});
8
+ END $native_subtable$`]}function be(e,...t){return`${e}_${(0,Hn.createHash)("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 Bi(e,t){return e.type==="subtable"?"none":t?"gin-trigram":e.indexed?["date-range","datetime-range"].includes(e.type)?"gist-range":rn.has(e.type)?"btree-snapshot-expressions":Di.has(e.type)?"gin-jsonb-path":"btree":"none"}function Gi(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 wi.has(e.type),"jsonb"}}function Zn(e,t){if(Ge(t.type)&&t.type!=="subtable")return"'[]'::jsonb";if(t.type!=="serial-number")return"";let o=Yn(t.serial?.prefix||""),n=t.serial?.digits??6;return`(${o} || lpad(nextval(${Yn(At(e,t.code))})::text, ${n}, '0'))`}function Ji(e,t){return Xn.has(t.type)?` CHECK (${e} IS NULL OR jsonb_typeof(${e}) = 'array')`:Vi.has(t.type)?` CHECK (${e} IS NULL OR jsonb_typeof(${e}) = 'object')`:""}function Et(e){return`"app_data".${ne(e)}`}function At(e,t){let o=be("seq",e,t);return`"app_data".${ne(o)}`}function Yn(e){return`'${e.replace(/'/g,"''")}'`}var eo=new Set(["option.single","option.multiple","user.single","user.multiple","department.single","department.multiple","resource-ref.single","resource-ref.multiple"]),zi=new Set([...eo,"cascade.single","cascade.multiple","file","image","signature","address","location","json"]),to=/^[A-Za-z][A-Za-z0-9_]{0,62}$/,qi=new Set(["__proto__","prototype","constructor"]),mt=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 ke(e,t){let o=no(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 It(e){return!!(e&&e.field.type==="user.single"&&e.valuePath==="value")}function an(e,t,o){if(!e||!t||!Yi(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 Ki(e,t){let o=no(t);if(!o)throw new mt(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 Yi(e){let{field:t,valuePath:o}=e;if(!o)return!zi.has(t.type);if(o==="value")return eo.has(t.type);if(!o.startsWith("snapshot."))return!1;let n=o.slice(9);return to.test(n)&&t.type.startsWith("resource-ref.")&&!!t.source?.snapshotFields?.includes(n)}function no(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=>!to.test(o)||qi.has(o))||t.length===2&&t[1]!=="value"||t.length===3&&t[1]!=="snapshot"?null:t}var Hi=new Set(["option.single","user.single","department.single","resource-ref.single"]),Xi=new Set(["text.short","text.long","text.rich","number.integer","number.decimal","boolean","date","time","datetime","uuid","serial-number"]),Qi=new Set(["value","label","description","color"]),Zi=new Set(["avatarUrl","employeeNo","title","mobile","email"]),es=new Set(["fullPath","parent.value","parent.label"]),ts=new Set(["country.value","country.label","province.value","province.label","city.value","city.label","district.value","district.label","street.value","street.label","detail","fullAddress"]),ns=new Set(["longitude","latitude","accuracy"]),os=new Set(["address","name","province","city","district","source"]);function is(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=rs(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 ss(e,t){if(Hi.has(e.type)&&Qi.has(t)||e.type==="user.single"&&Zi.has(t)||e.type==="department.single"&&es.has(t))return qe(t);if(e.type==="resource-ref.single"){let o=e.queryPathTypes?.[t];return o?{parts:t.split("."),type:o}:null}if(e.type==="address"&&ts.has(t))return qe(t);if(e.type==="location"){if(ns.has(t))return{parts:[t],type:"number.decimal"};if(os.has(t))return qe(t);if(t==="capturedAt")return{parts:[t],type:"datetime"}}return null}function rs(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}`,Xi.has(i.type)?i.type:"json"]]:[]})):{}}function qe(e){return{parts:e.split("."),type:"text.short"}}var ln=["exact-v1","nfkc-space-v1","nfkc-upper-ascii-v1"],ia=256,xe=class extends Error{constructor(o,n){super(`\u6761\u4EF6\u552F\u4E00\u952E\u58F0\u660E\u65E0\u6548\uFF1A${n}\uFF08${o}\uFF09`);this.pointer=o;this.reason=n}pointer;reason;code="NATIVE_UNIQUE_KEY_INVALID"},cn=e=>!!(e&&typeof e=="object"&&!Array.isArray(e)),oe=(e,t)=>{throw new xe(e,t)},gt=(e,t)=>e<t?-1:e>t?1:0,Nt=(e,t,o)=>{Object.keys(e).some(n=>!t.includes(n))&&oe(o,"\u4E0D\u652F\u6301\u672A\u77E5\u5C5E\u6027")};function un(e,t,o="/uniqueKeys"){if(e===void 0)return;if(!Array.isArray(e)||e.length>8)return oe(o,"\u6BCF\u8D44\u6E90\u6700\u591A 8 \u6761\u89C4\u5219");let n=new Map(t.map(r=>[r.code,r])),i=new Set;return e.map((r,a)=>{let s=`${o}/${a}`;if(!cn(r))return oe(s,"\u89C4\u5219\u5FC5\u987B\u662F\u5BF9\u8C61");if(Nt(r,["code","fields","when"],s),typeof r.code!="string"||!/^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/.test(r.code)||r.code.length>20||i.has(r.code))return oe(`${s}/code`,"\u9700\u8981\u4E0D\u91CD\u590D\u4E14\u4E0D\u8D85\u8FC7 20 \u5B57\u7B26\u7684 lower-kebab-case \u6807\u8BC6");if(i.add(r.code),!Array.isArray(r.fields)||r.fields.length<1||r.fields.length>4)return oe(`${s}/fields`,"\u5FC5\u987B\u9009\u62E9 1 \u5230 4 \u4E2A\u5B57\u6BB5");let c=new Set,u=r.fields.map((I,l)=>{let E=`${s}/fields/${l}`;if(!cn(I))return oe(E,"\u5B57\u6BB5\u5FC5\u987B\u662F\u5BF9\u8C61");Nt(I,["fieldCode","normalizer"],E);let N=n.get(I.fieldCode);if(!N||!["text.short","uuid","option.single","resource-ref.single"].includes(N.type)||c.has(I.fieldCode))return oe(`${E}/fieldCode`,"\u9700\u8981\u4E0D\u91CD\u590D\u7684\u77ED\u6587\u672C\u3001UUID\u3001\u5355\u9009\u6216\u5355\u8BB0\u5F55\u5F15\u7528\u5B57\u6BB5");c.add(I.fieldCode);let g=I.normalizer===void 0?"exact-v1":I.normalizer;return!ln.includes(g)||N.type!=="text.short"&&g!=="exact-v1"?oe(`${E}/normalizer`,"\u5F52\u4E00\u5316\u65B9\u5F0F\u4E0D\u652F\u6301\u6216\u4E0E\u5B57\u6BB5\u7C7B\u578B\u4E0D\u7B26"):{fieldCode:N.code,normalizer:g}}).sort((I,l)=>gt(I.fieldCode,l.fieldCode)),_=r.when===void 0?[]:r.when;if(!Array.isArray(_)||_.length>4)return oe(`${s}/when`,"\u6700\u591A 4 \u4E2A\u5408\u53D6\u6761\u4EF6");let d=new Set,p=_.map((I,l)=>{let E=`${s}/when/${l}`;if(!cn(I))return oe(E,"\u6761\u4EF6\u5FC5\u987B\u662F\u5BF9\u8C61");let N=n.get(I.fieldCode);if(!N)return oe(`${E}/fieldCode`,"\u5B57\u6BB5\u4E0D\u5B58\u5728");let g;if(I.operator==="empty"||I.operator==="nonempty"){if(Nt(I,["fieldCode","operator"],E),N.type!=="text.short")return oe(E,"\u7A7A\u503C\u6761\u4EF6\u4EC5\u652F\u6301\u77ED\u6587\u672C");g={fieldCode:N.code,operator:I.operator}}else if(I.operator==="in"||I.operator==="notIn"){Nt(I,["fieldCode","operator","values"],E);let m=new Set((N.options??[]).map(O=>O.value));if(N.type!=="option.single"||!Array.isArray(I.values)||I.values.length<1||I.values.length>16||I.values.some(O=>typeof O!="string"||O.length<1||O.length>128||!m.has(O))||new Set(I.values).size!==I.values.length)return oe(E,"\u96C6\u5408\u6761\u4EF6\u9700\u8981 1 \u5230 16 \u4E2A\u4E0D\u91CD\u590D\u7684\u5DF2\u58F0\u660E\u5355\u9009\u503C");g={fieldCode:N.code,operator:I.operator,values:[...I.values].sort(gt)}}else return oe(`${E}/operator`,"\u53EA\u652F\u6301 empty\u3001nonempty\u3001in \u548C notIn");let A=JSON.stringify(g);return d.has(A)?oe(E,"\u6761\u4EF6\u4E0D\u80FD\u91CD\u590D"):(d.add(A),g)}).sort((I,l)=>gt(JSON.stringify(I),JSON.stringify(l)));return{code:r.code,fields:u,when:p}}).sort((r,a)=>gt(r.code,a.code))}var dn={type:"string",pattern:"^[A-Za-z_][A-Za-z0-9_]{0,62}$"},as={type:"array",maxItems:8,items:{type:"object",additionalProperties:!1,required:["code","fields"],properties:{code:{type:"string",maxLength:20,pattern:"^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$"},fields:{type:"array",minItems:1,maxItems:4,uniqueItems:!0,items:{type:"object",additionalProperties:!1,required:["fieldCode"],properties:{fieldCode:dn,normalizer:{enum:[...ln]}}}},when:{type:"array",maxItems:4,uniqueItems:!0,items:{oneOf:[{type:"object",additionalProperties:!1,required:["fieldCode","operator"],properties:{fieldCode:dn,operator:{enum:["empty","nonempty"]}}},{type:"object",additionalProperties:!1,required:["fieldCode","operator","values"],properties:{fieldCode:dn,operator:{enum:["in","notIn"]},values:{type:"array",minItems:1,maxItems:16,uniqueItems:!0,items:{type:"string",minLength:1,maxLength:128}}}}]}}}}};var oo={"openxiangda.workflow.instance.completed.v2":"commit","openxiangda.workflow.instance.rejected.v2":"release","openxiangda.workflow.instance.withdrawn.v2":"release"};function io(e,t){let o=()=>{throw new Error("NATIVE_EVENT_DECIMAL_RESERVATION_INVALID")},n=p=>!p||typeof p!="object"||Array.isArray(p)?o():p,i=n(e);if(Object.keys(i).some(p=>!["resourceCode","workflowCode","outcomes"].includes(p))||typeof i.resourceCode!="string"||!/^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/.test(i.resourceCode)||typeof i.workflowCode!="string"||!/^[A-Za-z0-9._:-]{1,128}$/.test(i.workflowCode)||t.execution!==void 0||!Array.isArray(i.outcomes)||!i.outcomes.length||i.outcomes.length>3)return o();let r=t.resources.find(p=>p.code===i.resourceCode),a=t.reservations.find(p=>p.mode==="reserve"&&p.resourceCode===i.resourceCode),s=t.workflows.find(p=>p.code===i.workflowCode);if(!r||!a||!s||s.resourceCode!==r.code)return o();let c=r.fields.find(p=>p.code===a.statusFieldCode);if(c?.type!=="option.single")return o();let u=new Set(c.options?.map(p=>p.value)),_=new Set,d=i.outcomes.map(p=>{let I=n(p),l=I.eventType;return Object.keys(I).some(E=>!["eventType","mode","eligibleChildStatuses"].includes(E))||typeof l!="string"||!Object.prototype.hasOwnProperty.call(oo,l)||!t.eventTypes.includes(l)||_.has(l)||I.mode!==oo[l]||!Array.isArray(I.eligibleChildStatuses)||!I.eligibleChildStatuses.length||I.eligibleChildStatuses.length>16||new Set(I.eligibleChildStatuses).size!==I.eligibleChildStatuses.length||I.eligibleChildStatuses.some(E=>typeof E!="string"||!/^[A-Za-z0-9._:-]{1,128}$/.test(E)||!u.has(E))?o():(_.add(l),{eventType:l,mode:I.mode,eligibleChildStatuses:[...I.eligibleChildStatuses].sort()})}).sort((p,I)=>p.eventType.localeCompare(I.eventType));return{resourceCode:i.resourceCode,workflowCode:i.workflowCode,outcomes:d}}function so(e,t){let o=n=>Array.isArray(n)?n.filter(i=>i&&typeof i=="object"&&!Array.isArray(i)):[];return{eventTypes:Array.isArray(t.eventTypes)?t.eventTypes:[],execution:t.execution,resources:o(e.data?.resources).map(n=>({code:n.code,fields:o(n.schema?.fields).map(i=>({code:i.code,type:i.type,options:o(i.options).map(r=>({value:r.value}))}))})),reservations:o(e.backend?.operations).flatMap(n=>n.platformAccess?.decimalReservation?[n.platformAccess.decimalReservation]:[]),workflows:o(e.workflows?.definitions).map(n=>({code:n.definition?.code,resourceCode:n.definition?.subject?.resourceCode}))}}var Tt=class extends Error{constructor(o,n){super(n);this.pointer=o}pointer;code="NATIVE_EVENT_ACTION_INVALID"};function fn(e,t,o="/events/subscriptions"){if(e.execution===void 0)return;let n=(E,N)=>{throw new Tt(`${o}${E}`,N)},i=(E,N,g)=>((!E||typeof E!="object"||Array.isArray(E)||Object.keys(E).some(A=>!g.includes(A)))&&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])),c=a.map(E=>{let N=s.get(E);return N||n("/filter/resourceCodes","Unknown source resource"),new Set((N.schema?.fields||[]).map(g=>g.code))}),u=new Set(e.payload?.fields||[]),_=e.payload?.includeChanges===!0,d=(E,N)=>{let g=i(E,N,["source","path","value"]);if(g.source==="literal"){(!Object.hasOwn(g,"value")||Object.hasOwn(g,"path"))&&n(N,"Literal binding requires only value");let b;try{b=JSON.stringify(g.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)}}(g.source!=="event"||typeof g.path!="string"||Object.hasOwn(g,"value"))&&n(N,"Expected a literal or event binding");let A=g.path.split(".");(A.length>8||A.some(b=>!/^[A-Za-z0-9_-]+$/.test(b)||["__proto__","prototype","constructor"].includes(b)))&&n(N,"Invalid event path");let m=/^data\.projection\.([A-Za-z][A-Za-z0-9_]{0,62})$/.exec(g.path),O=/^data\.changes\.([A-Za-z][A-Za-z0-9_]{0,62})\.(before|after)$/.exec(g.path);if(m||O){let b=(m||O)[1];c.some(C=>!C.has(b))&&n(N,"Source field must exist on every filtered resource"),u.add(b),O&&(_=!0)}else["id","time","type","subject","data.recordId","data.revision","data.operation","data.resourceCode"].includes(g.path)||n(N,"Event path is not part of the data event contract");return{source:"event",path:g.path}};(!Array.isArray(r.operations)||r.operations.length<1||r.operations.length>16)&&n("/execution/operations","Expected 1 to 16 operations");let p={},I=r.operations.map((E,N)=>{let g=`/execution/operations/${N}`,A=i(E,g,["operation","resourceCode","data","id","expectedRevision"]);["create","update","delete"].includes(A.operation)||n(g,"Unsupported Native operation");let m=s.get(A.resourceCode);m||n(g,"Unknown action target resource");let O=new Map((m.schema?.fields||[]).map(C=>[C.code,C])),b=A.data===void 0?{}:i(A.data,`${g}/data`,[...O.keys()]);return Object.keys(b).length>32&&n(g,"Maximum 32 mapped fields per operation"),A.operation==="create"&&(A.id!==void 0||A.expectedRevision!==void 0)&&n(g,"Create does not accept id or expectedRevision"),A.operation==="delete"&&A.data!==void 0&&n(g,"Delete does not accept data"),Object.keys(b).some(C=>O.get(C)?.type==="serial-number")&&n(g,"Generated fields cannot be assigned"),p[A.resourceCode]=ee(m),{operation:A.operation,resourceCode:A.resourceCode,...A.operation==="create"?{}:{id:d(A.id,`${g}/id`),expectedRevision:d(A.expectedRevision,`${g}/expectedRevision`)},...A.operation==="delete"?{}:{data:Object.fromEntries(Object.entries(b).map(([C,y])=>[C,d(y,`${g}/data/${C}`)]))}}});(u.size>32||[...u].some(E=>c.some(N=>!N.has(E))))&&n("/payload/fields","Payload must contain at most 32 declared source fields");let l={kind:"native-data",version:1,operations:I,resourceDigests:p};return Buffer.byteLength(JSON.stringify(l))>65536&&n("/execution","Action plan exceeds 64 KiB"),{execution:{...l,digest:ee(l)},payload:{includeChanges:_,fields:[...u].sort()}}}function Oe(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)?e:void 0}function _n(e,t){if(e?.instanceCommands===void 0)return[];let o=Oe(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=Oe(r),s=i==="withdraw"?["beforeFact"]:["beforeFact","capability"];if(!a||Object.keys(a).some(c=>!s.includes(c))){n.push(`WORKFLOW_INSTANCE_COMMAND_POLICY_INVALID:${i}`);continue}if(i==="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(i==="withdraw"||a.beforeFact!==void 0){let c=a.beforeFact,u=Oe(e.inputSchema),_=Oe(Oe(u?.properties)?.[c]),d=Oe(Oe(e.subject)?.factProjection)?.[c],p=t?.fields.get(d);(typeof c!="string"||!/^[A-Za-z][A-Za-z0-9_]{0,62}$/.test(c)||!Array.isArray(u?.required)||!u.required.includes(c)||_?.type!=="string"||_?.format!=="date-time"||typeof d!="string"||t&&(p?.type!=="datetime"||p.nullable===!0))&&n.push(`WORKFLOW_INSTANCE_COMMAND_DEADLINE_FACT_INVALID:${i}`)}}return n}function cs(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 pn(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,c=t[8],u=new Date(Date.UTC(Number(o),Number(n),0)).getUTCDate();if(Number(n)<1||Number(n)>12||Number(i)<1||Number(i)>u||Number(r)>23||Number(a)>59||Number(s)>59||c!=="Z"&&(Number(c.slice(1,3))>23||Number(c.slice(4))>59))return null;let _=Date.parse(e);return Number.isFinite(_)?_:null}function ds(e,t,o,n){let i=e?.[t];if(!i||t==="terminate"&&i.beforeFact===void 0)return null;let r=i.beforeFact,a=Oe(o),s=r&&a&&Object.hasOwn(a,r)?pn(a[r]):null,c=n instanceof Date?n.getTime():pn(n);return s===null||c===null||!Number.isFinite(c)?"WORKFLOW_V2_CANCELLATION_DEADLINE_INVALID":c<s?null:"WORKFLOW_V2_CANCELLATION_DEADLINE_PASSED"}var ae=e=>e&&typeof e=="object"&&!Array.isArray(e)?e:{},Re=(e,t)=>typeof e=="string"&&!!e.trim()&&e.length<=t,ls=/^[A-Za-z][A-Za-z0-9_]*(?:\.[A-Za-z][A-Za-z0-9_]*){0,15}$/,En=e=>typeof e=="string"&&e.length<=256&&ls.test(e)&&!e.split(".").some(t=>["__proto__","prototype","constructor"].includes(t));function bt(e,t){let o=ae(e),n=!0;for(let i of t.split(".")){n&&=Array.isArray(o.required)&&o.required.includes(i);let r=ae(o.properties)[i];if(!r||typeof r!="object")return null;o=ae(r)}return{schema:o,required:n}}function An(e){let t=new Set,o=[],n=2048,i=(r,a)=>{if(--n<0||a>20){o.push("WORKFLOW_EXPRESSION_BUDGET_EXCEEDED");return}let s=ae(r);if(s.op==="path")En(s.path)?t.add(s.path):o.push("WORKFLOW_EXPRESSION_PATH_INVALID");else{if(s.op==="literal")return;if(s.op==="and"||s.op==="or")if(!Array.isArray(s.values)||!s.values.length||s.values.length>128)o.push("WORKFLOW_EXPRESSION_GROUP_INVALID");else for(let c of s.values){if(n<0)break;i(c,a+1)}else s.op==="not"||s.op==="exists"?i(s.value,a+1):["eq","neq","gt","gte","lt","lte","in","contains"].includes(String(s.op))?(i(s.left,a+1),i(s.right,a+1)):o.push("WORKFLOW_EXPRESSION_OPERATOR_INVALID")}};return i(e,0),{paths:[...t],errors:[...new Set(o)]}}function mn(e){if(e?.readability===void 0)return[];let t=[],o=ae(e.readability);(Object.keys(o).some(a=>!["variables","logic"].includes(a))||!Object.keys(o).length)&&t.push("WORKFLOW_READABILITY_INVALID");let n=ae(o.variables);o.variables!==void 0&&(typeof o.variables!="object"||Array.isArray(o.variables)||o.variables===null)&&t.push("WORKFLOW_VARIABLES_INVALID"),Object.keys(n).length>128&&t.push("WORKFLOW_VARIABLE_LIMIT_EXCEEDED");for(let[a,s]of Object.entries(n)){let c=ae(s);(!En(a)||!bt(e.inputSchema,a))&&t.push(`WORKFLOW_VARIABLE_SOURCE_UNKNOWN:${a}`),(!Re(c.label,160)||Object.keys(c).some(u=>!["label","unit","description"].includes(u))||c.unit!==void 0&&!Re(c.unit,32)||c.description!==void 0&&!Re(c.description,2e3))&&t.push(`WORKFLOW_VARIABLE_METADATA_INVALID:${a}`)}let i=o.logic===void 0?[]:o.logic;(!Array.isArray(i)||i.length>32)&&t.push("WORKFLOW_LOGIC_LIMIT_INVALID");let r=new Set;for(let a of Array.isArray(i)?i.slice(0,32):[]){let s=ae(a),c=String(s.code||"");(!/^[a-z][a-z0-9-]{2,63}$/.test(c)||r.has(c)||!Re(s.title,160)||!Re(s.description,4e3)||Object.keys(s).some(u=>!["code","title","description","phase","nodeId","inputPaths","outputPaths","source"].includes(u)))&&t.push(`WORKFLOW_LOGIC_METADATA_INVALID:${c}`),r.add(c),(!["submission","node_input","completion"].includes(String(s.phase))||s.phase==="node_input"&&!ae(e.nodes)[String(s.nodeId)]||s.phase!=="node_input"&&s.nodeId!==void 0)&&t.push(`WORKFLOW_LOGIC_ANCHOR_INVALID:${c}`);for(let u of["inputPaths","outputPaths"]){let _=s[u];if(!(u==="outputPaths"&&_===void 0))if(!Array.isArray(_)||_.length>32||new Set(_).size!==_.length)t.push(`WORKFLOW_LOGIC_PATHS_INVALID:${c}:${u}`);else for(let d of _)(!En(d)||!bt(e.inputSchema,d))&&t.push(`WORKFLOW_LOGIC_SOURCE_UNKNOWN:${c}:${String(d)}`)}if(s.source!==void 0){let u=ae(s.source);(!Re(u.path,256)||String(u.path).startsWith("/")||String(u.path).includes("..")||String(u.path).includes("://")||!/^sha256:[a-f0-9]{64}$/.test(String(u.digest))||u.symbol!==void 0&&!Re(u.symbol,160)||Object.keys(u).some(_=>!["path","symbol","digest"].includes(_)))&&t.push(`WORKFLOW_LOGIC_SOURCE_REFERENCE_INVALID:${c}`)}}for(let a of Object.values(ae(e.nodes))){let s=ae(a),c=Array.isArray(s.branches)?s.branches:[];for(let u of c){let _=An(u.when);t.push(..._.errors.map(d=>`${d}:${s.id}`));for(let d of _.paths)bt(e.inputSchema,d)||t.push(`WORKFLOW_VARIABLE_SOURCE_UNKNOWN:${s.id}:${d}`)}}return[...new Set(t)]}function us(e,t){let o=[],n=new Map,i=[];for(let s of Object.values(e.nodes)){if(s.kind==="approval")for(let[c,u,_]of[["approve",s.onApprove,"\u540C\u610F"],["reject",s.onReject,"\u62D2\u7EDD"]])u&&o.push({id:`${s.id}:${c}`,from:s.id,to:u,kind:c,label:_,variablePaths:[]});if(s.kind==="condition"){for(let[c,u]of(s.branches||[]).entries()){let _=An(u.when);for(let d of _.paths)n.has(d)||n.set(d,new Set),n.get(d).add(s.id);o.push({id:`${s.id}:branch:${c}`,from:s.id,to:u.target,kind:"branch",label:u.label||`\u6761\u4EF6 ${c+1}`,priority:c+1,expression:u.when,variablePaths:_.paths}),i.push(..._.errors.map(d=>({code:d,path:s.id})))}s.otherwise&&o.push({id:`${s.id}:default`,from:s.id,to:s.otherwise,kind:"default",label:"\u5747\u4E0D\u6EE1\u8DB3\u65F6",variablePaths:[]})}}let a=[...new Set([...n.keys(),...Object.keys(e.readability?.variables||{}),...(e.readability?.logic||[]).flatMap(s=>[...s.inputPaths,...s.outputPaths||[]])])].slice(0,128).map(s=>{let c=bt(e.inputSchema,s),u=e.readability?.variables?.[s],_=s.split("."),d=e.subject?.factProjection[_[0]];return c||i.push({code:"WORKFLOW_VARIABLE_SOURCE_UNKNOWN",path:s}),{path:s,label:u?.label||String(c?.schema.title||s),type:String(c?.schema.type||"unknown"),...u,required:c?.required||!1,usedBy:[...n.get(s)||[]],source:c&&d&&e.subject?{kind:"subject_field",resourceCode:e.subject.resourceCode,fieldPath:[d,..._.slice(1)].join(".")}:{kind:c?"input":"unknown"}}});return{schemaVersion:"openxiangda.workflow-graph/v2",workflowCode:e.code,definitionDigest:t,startAt:e.startAt,fixedTopology:!0,branchStrategy:"first_match",nodes:Object.values(e.nodes).map(s=>({id:s.id,kind:s.kind,title:s.title||s.id,...s.binding?{binding:s.binding}:{},...s.mode?{mode:s.mode}:{},...s.outcome?{outcome:s.outcome}:{}})),edges:o,variables:a,logic:e.readability?.logic||[],diagnostics:i}}function Ke(e,t=[],o=0){if(!e||o>20)return"\u65E0\u6CD5\u8BC6\u522B\u7684\u6761\u4EF6";if(e.op==="path")return t.find(a=>a.path===e.path)?.label||e.path;if(e.op==="literal")return JSON.stringify(e.value)??"\u7F3A\u503C";if(e.op==="and"||e.op==="or")return e.values.slice(0,128).map(a=>`\uFF08${Ke(a,t,o+1)}\uFF09`).join(e.op==="and"?" \u4E14 ":" \u6216 ");if(e.op==="not"||e.op==="exists")return`${e.op==="not"?"\u4E0D\u6EE1\u8DB3":"\u5B58\u5728"}\uFF08${Ke(e.value,t,o+1)}\uFF09`;if(!("left"in e))return"\u65E0\u6CD5\u8BC6\u522B\u7684\u6761\u4EF6";let n={eq:"=",neq:"\u2260",gt:">",gte:"\u2265",lt:"<",lte:"\u2264",in:"\u5C5E\u4E8E",contains:"\u5305\u542B"},i=e.left.op==="path"?e.left.path:void 0,r=i&&e.right.op==="literal"&&typeof e.right.value=="number"?t.find(a=>a.path===i)?.unit:void 0;return`${Ke(e.left,t,o+1)} ${n[e.op]} ${Ke(e.right,t,o+1)}${r?` ${r}`:""}`}var Ct=["approve","reject","return","transfer","delegate","add_assignee"],gn=["fixed_users","app_role","app_role_in_scope"],fs=["single","any","all","sequence"],$e=e=>!!e&&typeof e=="object"&&!Array.isArray(e),Ye=(e,t)=>Object.keys(e).every(o=>t.includes(o)),In=(e,t,o)=>Array.isArray(e)&&e.length>0&&e.length<=o&&new Set(e).size===e.length&&e.every(n=>typeof n=="string"&&t.includes(n));function je(e){return e.allowedOperations||[...Ct]}function ro(e,t,o={},n=!1){return!(!$e(e)||!Object.keys(e).length||!Ye(e,n?["enabled","label","commentRequired"]:["label","commentRequired"])||e.label!==void 0&&(typeof e.label!="string"||!e.label.trim()||e.label.length>40||/[\u0000-\u001f\u007f]/.test(e.label))||e.enabled!==void 0&&(typeof e.enabled!="boolean"||["approve","reject"].includes(t)&&!e.enabled)||e.commentRequired!==void 0&&(typeof e.commentRequired!="boolean"||!["approve","reject"].includes(t)||(t==="reject"||o.commentRequired)&&!e.commentRequired))}function Ot(e,t){let o=[];for(let[n,i]of Object.entries(e?.nodes||{})){if(!$e(i))continue;let r=i.administration,a=i.operationPolicy;if(i.kind!=="approval"){(r!==void 0||a!==void 0)&&o.push(`WORKFLOW_NODE_ADMINISTRATION_APPROVAL_REQUIRED:${n}`);continue}if(a!==void 0&&(!$e(a)||Object.keys(a).length>8||Object.entries(a).some(([c,u])=>!Ct.includes(c)||!je(i).includes(c)||!ro(u,c)))&&o.push(`WORKFLOW_NODE_OPERATION_POLICY_INVALID:${n}`),r===void 0)continue;if(!$e(r)||!Ye(r,["modes","assigneeProviders","operations"])){o.push(`WORKFLOW_NODE_ADMINISTRATION_INVALID:${n}`);continue}r.modes!==void 0&&(!In(r.modes,fs,4)||!r.modes.includes(i.mode))&&o.push(`WORKFLOW_NODE_ADMINISTRATION_MODES_INVALID:${n}`),r.assigneeProviders!==void 0&&!In(r.assigneeProviders,gn,3)&&o.push(`WORKFLOW_NODE_ADMINISTRATION_PROVIDERS_INVALID:${n}`);let s=t?.bindings[i.binding||""];s&&Array.isArray(r.assigneeProviders)&&r.assigneeProviders.includes("app_role_in_scope")&&!s.scope&&o.push(`WORKFLOW_NODE_ADMINISTRATION_SCOPE_REQUIRED:${n}`),r.operations!==void 0&&(!In(r.operations,Ct,8)||r.operations.some(c=>!je(i).includes(c)))&&o.push(`WORKFLOW_NODE_ADMINISTRATION_OPERATIONS_INVALID:${n}`)}return o}function ps(e,t,o){let n=[];if(!e||!$e(o)||!Object.keys(o).length||!Ye(o,["title","description","assignee","mode","operations"]))return["WORKFLOW_V2_NODE_CONFIGURATION_PATCH_INVALID"];let i=o;for(let a of["title","description"])i[a]!==void 0&&(typeof i[a]!="string"||i[a].length>(a==="title"?255:1e3)||a==="title"&&!i[a].trim())&&n.push("WORKFLOW_V2_NODE_CONFIGURATION_PATCH_INVALID");let r=e.administration;if(i.mode!==void 0&&(e.kind!=="approval"||!r?.modes?.includes(i.mode))&&n.push("WORKFLOW_V2_NODE_CONFIGURATION_MODE_READONLY"),i.operations!==void 0&&(e.kind!=="approval"||!$e(i.operations)||!Object.keys(i.operations).length||Object.keys(i.operations).length>8||Object.entries(i.operations).some(([a,s])=>!r?.operations?.includes(a)||!je(e).includes(a)||!ro(s,a,e.operationPolicy?.[a],!0)))&&n.push("WORKFLOW_V2_NODE_CONFIGURATION_OPERATION_INVALID"),i.assignee!==void 0){let a=i.assignee,s=r?.assigneeProviders||(t&&gn.includes(t.provider)?[t.provider]:[]);!$e(a)||e.kind!=="approval"||!s.includes(a.provider)||a.provider==="app_role_in_scope"&&!t?.scope?n.push("WORKFLOW_V2_NODE_CONFIGURATION_PROVIDER_READONLY"):a.provider==="fixed_users"?(!Ye(a,["provider","users"])||!Array.isArray(a.users)||a.users.length<1||a.users.length>200||new Set(a.users).size!==a.users.length||a.users.some(c=>typeof c!="string"||!c.trim()||c.length>255))&&n.push("WORKFLOW_V2_NODE_CONFIGURATION_USERS_INVALID"):(!Ye(a,["provider","roleCode"])||typeof a.roleCode!="string"||!/^[a-z][a-z0-9_-]{0,127}$/.test(a.roleCode))&&n.push("WORKFLOW_V2_NODE_CONFIGURATION_ROLE_INVALID")}return n}function _s(e,t){let o=Object.fromEntries(je(e).flatMap(n=>{let i=n,r=t?.operations?.[i],a={...e.operationPolicy?.[i],...r?.label!==void 0?{label:r.label}:{},...r?.commentRequired!==void 0?{commentRequired:r.commentRequired}:{}};return Object.keys(a).length?[[i,a]]:[]}));return{mode:t?.mode||e.mode,allowedOperations:je(e).filter(n=>t?.operations?.[n]?.enabled!==!1),operationPolicy:o,fieldPolicy:{default:e.fieldPolicy?.default||"readonly",fields:{...e.fieldPolicy?.fields}}}}var Dt=Xo(require("crypto"),1);var ao="native-4",co={"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","data.decimal-reservations":"1.1.0","data.decimal-reservation-lifecycle":"1.0.0","data.unique-keys":"1.0.0","data.managed-concurrency":"1.0.0","data.managed-concurrency.durable":"1.0.0","workflow.named-input-sources":"1.0.0","directory-v2":"1.0.0","directory.selected-user":"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","workflow.node-administration":"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 pa=5,_a=20,Ea=50,Aa=50,ma=100,Ue=class extends Error{constructor(o,n){super(o);this.code=o;this.pointer=n;this.name="NativeDataPolicyExpressionV2Error"}code;pointer};function Xe(e,t){let o=[],n=(i,r,a)=>{a>5&&He("NATIVE_DATA_POLICY_EXPRESSION_DEPTH_EXCEEDED",r);let s=lo(i,r),c=["allOf","anyOf"].filter(d=>d in s);if(c.length===0){o.push({rule:s,pointer:r}),o.length>50&&He("NATIVE_DATA_POLICY_EXPRESSION_LEAVES_EXCEEDED",r);return}let u=c[0],_=s[u];(c.length!==1||Object.keys(s).length!==1||!Array.isArray(_)||_.length<1||_.length>20)&&He("NATIVE_DATA_POLICY_EXPRESSION_GROUP_INVALID",r),_.forEach((d,p)=>n(d,`${r}/${u}/${p}`,a+1))};return n(e,t,1),o}function Tn(e,t){Xe(e,t);let o=(n,i)=>{let r=lo(n,i);if(Array.isArray(r.allOf))return Nn(r.allOf.flatMap((a,s)=>o(a,`${i}/allOf/${s}`)),i);if(Array.isArray(r.anyOf)){let a=[[]];return r.anyOf.forEach((s,c)=>{let u=o(s,`${i}/anyOf/${c}`);a=Nn(a.flatMap(_=>u.map(d=>[..._,...d])),i)}),a}return[[r]]};return Nn(o(e,t),t)}function Nn(e,t){let o=e.reduce((n,i)=>n+i.length,0);return(e.length>50||o>100)&&He("NATIVE_DATA_POLICY_EXPRESSION_EXPANSION_EXCEEDED",t),e}function lo(e,t){return(!e||typeof e!="object"||Array.isArray(e))&&He("NATIVE_DATA_POLICY_EXPRESSION_NODE_INVALID",t),e}function He(e,t){throw new Ue(e,t)}var Es="openxiangda.config-bundle/v3",$o="openxiangda.contract-bundle/v3",uo="openxiangda.native-configuration-projection/v1",Ze=ao,As=/^[a-f0-9]{64}$/,ms=/^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/,Is=/^app:[a-z][a-z0-9]*(?:-[a-z0-9]+)*:[A-Za-z0-9:._*-]+$/,gs=/^[a-z][a-z0-9]*(?:[-_.][a-z0-9]+)*$/,Ns=/^[a-z][a-z0-9]*(?:[-.][a-z0-9]+)*$/,Ts=/^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/,bs=/^[A-Za-z][A-Za-z0-9_]{0,62}$/,fo=/^[A-Za-z][A-Za-z0-9_]{0,127}$/,Cs=/^[a-z][a-z0-9]*(?:[-_][a-z0-9]+)*$/,Os=/^[A-Z][A-Z0-9_]*$/,ys=/^[a-z][a-z0-9-]{2,63}$/,hs=/^[A-Za-z][A-Za-z0-9_-]{0,127}$/,Rs=/^[A-Za-z][A-Za-z0-9_.]{0,127}$/,$s=16,Ss=2*1024,Ds=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"]),Vs=new Set(["overview","database","operations","workflow","members","calendar","document","folder","settings"]),ws=new Set(["approve","reject","return","transfer","delegate","add_assignee","resubmit","withdraw","terminate","admin_reassign","admin_override","retry_resolution"]),Fs=4*1024*1024,Ps=8*1024*1024,vs=40,Ls=1e5,Cn=1024*1024,ks="openxiangda.event-handler-manifest/v2",So="openxiangda.application-route-manifest/v3",po=64,Do=new Set(["id","revision","created_by","updated_by","created_at","updated_at"]),K=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}),yt=["openxiangda.data.record.created.v2","openxiangda.data.record.updated.v2","openxiangda.data.record.deleted.v2"],ht=["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"],xs=new Set(ht),Rt=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 js(e){let t=$(e.appCode,"/appCode",128);ms.test(t)||f("NATIVE_CONFIG_APP_CODE_INVALID","/appCode");let o=yn(e.expectedConfigDigest,"/expectedConfigDigest"),n=yn(e.expectedContractDigest,"/expectedContractDigest"),i=yo(e.configBytes,Fs,"/configBytes","NATIVE_CONFIG_ARTIFACT_TOO_LARGE"),r=yo(e.contractBytes,Ps,"/contractBytes","NATIVE_CONTRACT_ARTIFACT_TOO_LARGE");ho(i,o,"/configBytes","NATIVE_CONFIG_DIGEST_MISMATCH"),ho(r,n,"/contractBytes","NATIVE_CONTRACT_DIGEST_MISMATCH");let a=Co(i,"/configBytes","NATIVE_CONFIG_JSON_INVALID","NATIVE_CONFIG_NOT_CANONICAL"),s=Co(r,"/contractBytes","NATIVE_CONTRACT_JSON_INVALID","NATIVE_CONTRACT_NOT_CANONICAL");Oo(a,"/config"),Oo(s,"/contracts");let c=a,u=s;Ms(c,t),Ws(u,t,o);let _=Bs(c,o,u.generatorVersion);Sr(_,u,c),Q(_)!==Q(u)&&f("NATIVE_CONTRACT_CLOSURE_MISMATCH",hn(_,u,"/contracts"));let d={authz:{appCode:t,...c.authz,perspectives:c.perspectives,capabilityCatalog:_.capabilities},data:{appCode:t,resources:c.data.resources,resourceContracts:_.resources,..._.concurrency?{concurrency:_.concurrency}:{},..._.subjectReadSurfaces?{subjectReadSurfaces:_.subjectReadSurfaces}:{}},events:{appCode:t,...c.events,consumers:_.eventConsumers,producers:_.eventProducers,handlerManifest:_.eventHandlerManifest,eventTypes:_.eventTypes,capturePlans:wo({resources:c.data.resources,dataPolicies:c.authz.dataPolicies,subscriptions:_.eventConsumers,capturePolicies:c.events.capturePolicies})},workflows:{appCode:t,...c.workflows,contracts:_.workflows},runtime:{appCode:t,requirements:c.runtime,backend:c.backend,frontend:c.frontend},contracts:_},p={authz:Me(d.authz),data:Me(d.data),events:Me(d.events),workflows:Me(d.workflows),runtime:Me(d.runtime),contracts:Me(d.contracts)},I={configDigest:o,contractDigest:n,generatorVersion:u.generatorVersion},l=Vo(c),E={schemaVersion:uo,compilerContractVersion:Ze,appCode:t,source:I,projections:p,requiredPlatformCapabilities:l,aggregateDigest:ee({schemaVersion:uo,compilerContractVersion:Ze,appCode:t,source:I,requiredPlatformCapabilities:l,projectionDigests:Object.fromEntries(Object.entries(p).map(([N,g])=>[N,g.digest]))})};return Go(E)}function Vo(e){let t=e.authz.roles,o=e.data.resources,n=e.backend.operations,i=t.some(l=>l.capabilities.some(E=>E.endsWith(":directory:read")))||o.some(l=>l.schema.fields.some(E=>["user.single","user.multiple","department.single","department.multiple"].includes(E.type)))||n.some(l=>l.platformAccess?.directory),r=!!(e.events.subscriptions.length||e.events.timers.length||e.events.dateTriggers.length||e.events.schemas.length),a=n.some(l=>l.platformAccess?.managedFiles||l.platformAccess?.managedFileCopies)||e.events.subscriptions.some(l=>l.platformAccess?.managedFileCopies),s=n.some(l=>l.platformAccess?.notification)||e.events.subscriptions.some(l=>l.platformAccess?.notification),c=e.workflows.definitions.filter(l=>l.launch.mode==="standalone"||l.launch.mode==="hidden-handoff"),u=n.some(l=>l.platformAccess?.workflow)||c.length>0,_={resources:o},d={perspectives:e.perspectives,authz:e.authz},p={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(l=>({code:l.code,method:l.method,path:l.path,capability:l.capability,platformAccess:l.platformAccess||null,...l.browser?{browser:l.browser}:{},ai:l.ai||null}))}};return[...o.some(l=>l.uniqueKeys?.length)?[{code:"data.unique-keys",declaration:o.filter(l=>l.uniqueKeys?.length).map(l=>({code:l.code,uniqueKeys:l.uniqueKeys}))}]:[],...e.data.concurrency?[{code:"data.managed-concurrency",declaration:e.data.concurrency}]:[],...e.data.concurrency?.commands.some(l=>l.mode==="durable")?[{code:"data.managed-concurrency.durable",declaration:e.data.concurrency}]:[],...o.some(l=>l.decimalReservationLifecycle)?[{code:"data.decimal-reservation-lifecycle",declaration:o.filter(l=>l.decimalReservationLifecycle).map(l=>({code:l.code,decimalReservationLifecycle:l.decimalReservationLifecycle}))}]:[],...n.some(l=>l.platformAccess?.decimalReservation)||e.events.subscriptions.some(l=>l.platformAccess?.decimalReservation)?[{code:"data.decimal-reservations",declaration:[...n.filter(l=>l.platformAccess?.decimalReservation).map(l=>({code:l.code,decimalReservation:l.platformAccess.decimalReservation})),...e.events.subscriptions.filter(l=>l.platformAccess?.decimalReservation).map(l=>({subscriptionCode:l.code,decimalReservation:l.platformAccess.decimalReservation}))]}]:[],{code:"application-native-2",declaration:p},{code:"authz.native-batch-explain",declaration:d},{code:"authz.native-management",declaration:d},{code:"deployment.durable-runs",declaration:p.backend},{code:"deployment.platform-executor",declaration:p.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(Bt)?[{code:"data.audit-read-access",declaration:_}]:[],...i?[{code:"directory-v2",declaration:{roles:t.map(l=>({code:l.code,capabilities:l.capabilities.filter(E=>E.endsWith(":directory:read"))})),resources:o.map(l=>({code:l.code,fields:l.schema.fields.filter(E=>["user.single","user.multiple","department.single","department.multiple"].includes(E.type))})),operations:n.filter(l=>l.platformAccess?.directory).map(l=>({code:l.code,directory:l.platformAccess.directory}))}}]:[],...n.some(l=>l.platformAccess?.directory?.mode==="selected-user")?[{code:"directory.selected-user",declaration:n.filter(l=>l.platformAccess?.directory?.mode==="selected-user").map(l=>({code:l.code,directory:l.platformAccess.directory}))}]:[],...a?[{code:"data.managed-files",declaration:{operations:n.filter(l=>l.platformAccess?.managedFiles||l.platformAccess?.managedFileCopies).map(l=>({code:l.code,...l.platformAccess?.managedFiles?{managedFiles:l.platformAccess.managedFiles}:{},...l.platformAccess?.managedFileCopies?{managedFileCopies:l.platformAccess.managedFileCopies}:{}})),subscriptions:e.events.subscriptions.filter(l=>l.platformAccess?.managedFileCopies).map(l=>({code:l.code,managedFileCopies:l.platformAccess.managedFileCopies}))}}]:[],...e.events.subscriptions.some(l=>l.execution)?[{code:"events.native-data-actions",declaration:e.events.subscriptions.filter(l=>l.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(l=>l.definition.instanceCommands!==void 0)?[{code:"workflow.instance-cancellation-policy",declaration:e.workflows.definitions.filter(l=>l.definition.instanceCommands!==void 0)}]:[],...e.workflows.definitions.some(l=>Object.values(l.definition.nodes).some(E=>E.administration!==void 0||E.operationPolicy!==void 0))?[{code:"workflow.node-administration",declaration:e.workflows.definitions.filter(l=>Object.values(l.definition.nodes).some(E=>E.administration!==void 0||E.operationPolicy!==void 0))}]:[],...u?[{code:"business-process.durable-command",declaration:{operations:n.filter(l=>l.platformAccess?.workflow).map(l=>({code:l.code,workflow:l.platformAccess.workflow})),definitions:c,activations:e.workflows.activations.filter(l=>c.some(E=>E.definition.code===l.workflowCode))}}]:[],...s?[{code:"notification-hub-v2",declaration:{operations:n.filter(l=>l.platformAccess?.notification).map(l=>({code:l.code,notification:l.platformAccess.notification})),subscriptions:e.events.subscriptions.filter(l=>l.platformAccess?.notification).map(l=>({code:l.code,notification:l.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:l,declaration:E})=>({code:l,contractVersion:co[l],usageDigest:`sha256:${ee(E)}`})).sort((l,E)=>l.code===E.code?0:l.code<E.code?-1:1)}function wo(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 s=`/capturePlan/capturePolicies/${r}`,c=T(a,s);h(c,["resourceCode","mode"],s);let u=z(c.resourceCode,`${s}/resourceCode`);o.has(u)||f("NATIVE_EVENT_CAPTURE_RESOURCE_NOT_FOUND",s,{resourceCode:u}),t.has(u)&&f("NATIVE_EVENT_CAPTURE_POLICY_DUPLICATE",s,{resourceCode:u}),c.mode!=="all"&&c.mode!=="subscribed"&&f("NATIVE_EVENT_CAPTURE_MODE_INVALID",`${s}/mode`),t.set(u,c.mode)}let n=new Map(e.dataPolicies.map((r,a)=>{let s=T(r,`/capturePlan/dataPolicies/${a}`);return[String(s.code),s]})),i=e.subscriptions.map((r,a)=>T(r,`/capturePlan/subscriptions/${a}`));return e.resources.map((r,a)=>{let s=`/capturePlan/resources/${a}`,c=T(r,s),u=z(c.code,`${s}/code`),_=c.schema?T(c.schema,`${s}/schema`):c,d=new Set(R(_.fields||[],`${s}/schema/fields`,500).map((C,y)=>W(T(C,`${s}/schema/fields/${y}`).code,`${s}/schema/fields/${y}/code`))),p=c.dataPolicyCode?w(c.dataPolicyCode,`${s}/dataPolicyCode`):null,I=p?n.get(p):void 0;p&&!I&&f("NATIVE_EVENT_CAPTURE_AUTHZ_POLICY_NOT_FOUND",s,{resourceCode:u,dataPolicyCode:p});let l=new Set;for(let C of I?.rules||[])l.add(String(C.field));if(I?.readExpression)for(let C of Xe(I.readExpression,`${s}/readExpression`))l.add(String(C.rule.field));let E=new Set,N=new Set,g=new Set;for(let[C,y]of i.entries()){let S=R(y.eventTypes,`/capturePlan/subscriptions/${C}/eventTypes`,20).map(String);if(!S.some(U=>U.startsWith("openxiangda.data.")))continue;let v=T(y.filter||{},`/capturePlan/subscriptions/${C}/filter`),F=Array.isArray(v.resourceCodes)?v.resourceCodes.map(String):[];if(F.length&&!F.includes(u))continue;for(let U of S)yt.includes(U)&&g.add(U);for(let U of Us(v,`/capturePlan/subscriptions/${C}/filter`))E.add(U);let B=T(y.payload||{},`/capturePlan/subscriptions/${C}/payload`);for(let U of R(B.fields||[],`/capturePlan/subscriptions/${C}/payload/fields`,32))N.add(W(U,`/capturePlan/subscriptions/${C}/payload/fields`))}let A=new Set([...E,...N]),m=new Set([...A,...l]);m.size>po&&f("NATIVE_EVENT_CAPTURE_FIELDS_LIMIT",s,{resourceCode:u,maximum:po});for(let C of m)!d.has(C)&&!(l.has(C)&&Do.has(C))&&f("NATIVE_EVENT_CAPTURE_FIELD_NOT_FOUND",s,{resourceCode:u,field:C});let O=T(c.fieldPolicies||{},`${s}/fieldPolicies`);for(let C of A)O[C]?.mask==="omit"&&f("NATIVE_EVENT_CAPTURE_FIELD_SENSITIVE",s,{resourceCode:u,field:C});let b={resourceCode:u,...t.get(u)==="subscribed"?{capturedEventTypes:[...g].sort()}:{},filterFields:[...E].sort(),projectionFields:[...N].sort(),authorizationFields:[...l].sort(),captureFields:[...m].sort()};return{...b,digest:ee(b)}}).sort((r,a)=>r.resourceCode.localeCompare(a.resourceCode))}function Us(e,t){let o=new Set;for(let[a,s]of R(e.changes||[],`${t}/changes`,16).entries()){let c=T(s,`${t}/changes/${a}`);o.add(W(c.field,`${t}/changes/${a}/field`))}let n=T(e.changedFields||{},`${t}/changedFields`);for(let a of["anyOf","allOf","noneOf"])for(let[s,c]of R(n[a]||[],`${t}/changedFields/${a}`,32).entries())o.add(W(c,`${t}/changedFields/${a}/${s}`));let i=0,r=(a,s,c)=>{c>3&&f("NATIVE_EVENT_FILTER_DEPTH_LIMIT",s);let u=T(a,s);if(u.change){let d=T(u.change,`${s}/change`);o.add(W(d.field,`${s}/change/field`)),i+=1;return}if(u.not){r(u.not,`${s}/not`,c+1);return}let _=u.all?"all":u.any?"any":null;_||f("NATIVE_EVENT_FILTER_CONDITION_INVALID",s);for(let[d,p]of R(u[_],`${s}/${_}`,16).entries())r(p,`${s}/${_}/${d}`,c+1)};return e.where&&r(e.where,`${t}/where`,1),i+=Array.isArray(e.changes)?e.changes.length:0,i>16&&f("NATIVE_EVENT_FILTER_ATOM_LIMIT",t),[...o].sort()}function Ms(e,t){h(e,["schemaVersion","compilerContractVersion","appCode","perspectives","authz","backend","data","events","workflows","frontend","runtime"],"/config"),x(e.schemaVersion,Es,"/config/schemaVersion"),x(e.compilerContractVersion,Ze,"/config/compilerContractVersion"),x(e.appCode,t,"/config/appCode"),R(e.perspectives,"/config/perspectives",100);let o=T(e.authz,"/config/authz");h(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=T(e.backend,"/config/backend");h(n,["secrets","operations"],"/config/backend"),R(n.secrets,"/config/backend/secrets",100),R(n.operations,"/config/backend/operations",500),Cr(n.secrets);let i=T(e.data,"/config/data");h(i,["resources"],"/config/data",["resourceDetailRoutes","subjectReadSurfaces","concurrency"]),R(i.resources,"/config/data/resources",100),i.subjectReadSurfaces!==void 0&&R(i.subjectReadSurfaces,"/config/data/subjectReadSurfaces",K.subjectReadSurfaces),i.resourceDetailRoutes!==void 0&&R(i.resourceDetailRoutes,"/config/data/resourceDetailRoutes",100);let r=T(e.events,"/config/events");h(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=T(e.workflows,"/config/workflows");h(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 s=T(e.frontend,"/config/frontend");h(s,["routes","user","admin","devicePolicy"],"/config/frontend",["authentication","publicAccess"]),R(s.routes,"/config/frontend/routes",500);let c=T(s.user,"/config/frontend/user");h(c,["applicationTodoCenter"],"/config/frontend/user"),Be(c.applicationTodoCenter,"/config/frontend/user/applicationTodoCenter"),Rn(s.devicePolicy,"/config/frontend/devicePolicy"),Object.prototype.hasOwnProperty.call(s,"authentication")&&Po(s.authentication,s.routes,e,"/config/frontend/authentication"),Object.prototype.hasOwnProperty.call(s,"publicAccess")&&ir(s.publicAccess,e,"/config/frontend/publicAccess");let u=T(s.admin,"/config/frontend/admin");h(u,["navigation"],"/config/frontend/admin",["access"]),u.access!==void 0&&wt(u.access,"/config/frontend/admin/access",e.appCode),cr(u.navigation,"/config/frontend/admin/navigation");let _=T(e.runtime,"/config/runtime");h(_,["protocolCapabilities","health"],"/config/runtime"),P(_.protocolCapabilities,"/config/runtime/protocolCapabilities",100),h(T(_.health,"/config/runtime/health"),["livePath","readyPath","versionPath"],"/config/runtime/health"),x(_.health.livePath,"/__platform/health","/config/runtime/health/livePath"),x(_.health.readyPath,"/__platform/ready","/config/runtime/health/readyPath"),x(_.health.versionPath,"/__platform/version","/config/runtime/health/versionPath")}function Ws(e,t,o){h(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","concurrency"]),x(e.schemaVersion,$o,"/contracts/schemaVersion"),x(e.compilerContractVersion,Ze,"/contracts/compilerContractVersion"),$(e.generatorVersion,"/contracts/generatorVersion",128),x(e.appCode,t,"/contracts/appCode"),x(e.configDigest,o,"/contracts/configDigest"),R(e.perspectives,"/contracts/perspectives",K.perspectives),R(e.resources,"/contracts/resources",K.resources),e.subjectReadSurfaces!==void 0&&R(e.subjectReadSurfaces,"/contracts/subjectReadSurfaces",K.subjectReadSurfaces),R(e.capabilities,"/contracts/capabilities",K.capabilities),R(e.operations,"/contracts/operations",K.operations),R(e.eventConsumers,"/contracts/eventConsumers",K.eventConsumers),R(e.eventProducers,"/contracts/eventProducers",K.eventProducers),R(e.eventSchemas,"/contracts/eventSchemas",K.eventSchemas),T(e.eventHandlerManifest,"/contracts/eventHandlerManifest"),P(e.eventTypes,"/contracts/eventTypes",K.eventTypes),R(e.workflows,"/contracts/workflows",K.workflows),R(e.routes,"/contracts/routes",K.routes),Object.prototype.hasOwnProperty.call(e,"authentication")&&tr(e.authentication,"/contracts/authentication"),Object.prototype.hasOwnProperty.call(e,"publicAccess")&&sr(e.publicAccess,"/contracts/publicAccess"),Object.prototype.hasOwnProperty.call(e,"adminAccess")&&wt(e.adminAccess,"/contracts/adminAccess",t),_r(e.routeManifest,"/contracts/routeManifest",t),ur(e.adminPages,"/contracts/adminPages"),fr(e.adminNavigation,"/contracts/adminNavigation")}function Bs(e,t,o){let n=zs(e);gr(e,n),Tr(e),Nr(e),Or(e);let i=e.events.schemas.map((E,N)=>{let g=`/config/events/schemas/${N}`,A=T(E,g),m=$(A.eventType,`${g}/eventType`,255);return m.startsWith("openxiangda.")&&f("NATIVE_EVENT_SCHEMA_RESERVED",`${g}/eventType`,{eventType:m}),x(A.schemaDigest,ee(T(A.jsonSchema,`${g}/jsonSchema`)),`${g}/schemaDigest`),A}),r=new Set([...yt,...ht,...i.map(E=>String(E.eventType))]),a=new Map(e.data.resources.map(E=>[String(E.code),new Map(E.schema.fields.map(N=>[String(N.code),String(N.type)]))])),s=X(e.events.subscriptions.map((E,N)=>{let g=`/config/events/subscriptions/${N}`,A=T(E,g),m=P(A.eventTypes,`${g}/eventTypes`,20);m.forEach((y,S)=>{r.has(y)||f("NATIVE_EVENT_TYPE_NOT_REGISTERED",`${g}/eventTypes/${S}`,{eventType:y})});let O=fn(A,e.data.resources,g),b=Js(A.delivery,m,`${g}/delivery`),C=Gs(A.platformAccess,`${g}/platformAccess`,a,e,A);return{code:w(A.code,`${g}/code`),endpointPath:fe(A.endpointPath,`${g}/endpointPath`),eventTypes:m,filter:T(A.filter,`${g}/filter`),payload:O?.payload||T(A.payload,`${g}/payload`),...O?{execution:O.execution}:{},...C?{platformAccess:C}:{},delivery:b}}),E=>E.code),c=new Map(i.map(E=>[String(E.eventType),String(E.dataSchemaVersion)])),u=X([...e.data.resources.flatMap(E=>yt.map(N=>({code:`data:${E.code}:${N}`,source:"data",eventType:N,dataSchemaVersion:"2.0.0",resourceCode:E.code}))),...i.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?ht.map(E=>({code:`workflow:${E}`,source:"workflow",eventType:E,dataSchemaVersion:"2.0.0"})):[]],E=>`${E.source}:${E.code}:${E.eventType}`),_=M([...s.flatMap(E=>E.eventTypes),...u.map(E=>String(E.eventType))]);lr(e);let d=ko(e),p;try{p=en(e.data.concurrency,e.data.resources,n)}catch(E){throw E instanceof Le&&f(E.code,E.pointer,{reason:E.reason}),E}p?.commands.some(E=>E.mode==="durable")&&e.backend?.enabled===!1&&f("NATIVE_MANAGED_CONCURRENCY_INVALID","/data/concurrency",{reason:"durable commands require backend runtime"});let I=Ks(e,n),l=Fo(e);try{sn(e.data.resources,l)}catch(E){throw E instanceof he&&f(E.code,E.pointer,{reason:E.reason}),E}return{schemaVersion:$o,compilerContractVersion:Ze,generatorVersion:o,appCode:e.appCode,configDigest:t,perspectives:e.perspectives,resources:qs(e),...I.length?{subjectReadSurfaces:I}:{},...p?{concurrency:p}:{},capabilities:X(n,E=>E.code),operations:l,eventConsumers:s,eventProducers:u,eventSchemas:i,eventHandlerManifest:{schemaVersion:ks,appCode:e.appCode,handlers:s.filter(E=>!E.execution).map(E=>({code:E.code,endpointPath:E.endpointPath,eventTypes:E.eventTypes,dataSchemaVersions:M(E.eventTypes.map(N=>N.startsWith("openxiangda.")?"2.0.0":c.get(N)||"2.0.0")),maxBodyBytes:65536,receiptProtocolVersion:2}))},eventTypes:_,workflows:Uo(e),routes:Vt(e),...Object.prototype.hasOwnProperty.call(e.frontend,"authentication")?{authentication:nr(e)}:{},...Object.prototype.hasOwnProperty.call(e.frontend,"publicAccess")?{publicAccess:rr(e)}:{},...e.frontend.admin.access?{adminAccess:e.frontend.admin.access}:{},routeManifest:mr(e),adminPages:d,adminNavigation:ar(e)}}function Gs(e,t,o,n,i){if(e===void 0)return;let r=T(e,t);h(r,["notification","managedFileCopies","decimalReservation"],t,!0);let a={};if(r.decimalReservation!==void 0)try{a.decimalReservation=io(r.decimalReservation,so(n,i))}catch{f("NATIVE_EVENT_DECIMAL_RESERVATION_INVALID",`${t}/decimalReservation`)}if(r.notification!==void 0){let s=T(r.notification,`${t}/notification`);h(s,["mode"],`${t}/notification`),x(s.mode,"business-standard",`${t}/notification/mode`),a.notification={mode:"business-standard"}}if(r.managedFileCopies!==void 0){let s=R(r.managedFileCopies,`${t}/managedFileCopies`,16);s.length||f("NATIVE_EVENT_MANAGED_FILE_COPIES_REQUIRED",`${t}/managedFileCopies`);let c=new Set;a.managedFileCopies=X(s.map((u,_)=>{let d=`${t}/managedFileCopies/${_}`,p=T(u,d);h(p,["mode","sourceResourceCode","sourceFieldCodes","targetResourceCode","targetFieldCodes"],d),x(p.mode,"copy",`${d}/mode`);let I=z(p.sourceResourceCode,`${d}/sourceResourceCode`),l=z(p.targetResourceCode,`${d}/targetResourceCode`),E=o.get(I),N=o.get(l);(!E||!N)&&f("NATIVE_EVENT_MANAGED_FILE_COPY_RESOURCE_INVALID",d);let g=P(p.sourceFieldCodes,`${d}/sourceFieldCodes`,16),A=P(p.targetFieldCodes,`${d}/targetFieldCodes`,16);(!g.length||g.length!==A.length)&&f("NATIVE_EVENT_MANAGED_FILE_COPY_FIELDS_INVALID",d),g.forEach((O,b)=>{let C=E.get(O),y=N.get(A[b]);(!["file","image"].includes(String(C))||C!==y)&&f("NATIVE_EVENT_MANAGED_FILE_COPY_FIELD_INVALID",`${d}/sourceFieldCodes/${b}`)});let m=`${I}:${g.join(",")}=>${l}:${A.join(",")}`;return c.has(m)&&f("NATIVE_EVENT_MANAGED_FILE_COPY_DUPLICATE",d),c.add(m),{mode:"copy",sourceResourceCode:I,sourceFieldCodes:M(g),targetResourceCode:l,targetFieldCodes:M(A)}}),u=>`${u.sourceResourceCode}:${u.sourceFieldCodes.join(",")}=>${u.targetResourceCode}:${u.targetFieldCodes.join(",")}`)}return Object.keys(a).length||f("NATIVE_EVENT_PLATFORM_ACCESS_EMPTY",t),a}function Js(e,t,o){let n=T(e,o);h(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)||f("NATIVE_EVENT_DELIVERY_ORDERING_INVALID",`${o}/ordering`),r==="workflow-instance"&&t.some(a=>!xs.has(a))&&f("NATIVE_EVENT_WORKFLOW_ORDERING_REQUIRES_WORKFLOW_FACTS",`${o}/ordering`),n}function zs(e){let t=new Map;for(let o of Bo(e.appCode))t.set(o.code,o);for(let[o,n]of e.authz.capabilities.entries()){let i=`/config/authz/capabilities/${o}`,r=T(n,i);h(r,["code","kind","name","description"],i,!0);let a=Ce(r.code,`${i}/code`,e.appCode);t.has(a)&&f("NATIVE_CAPABILITY_DUPLICATE",`${i}/code`),["backend","ui"].includes(r.kind)||f("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:Sn(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=Se(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 c=Ce(r.capabilities[s],`${i}/capabilities/${s}`,e.appCode);t.has(c)&&f("NATIVE_CAPABILITY_DUPLICATE",`${i}/capabilities/${s}`),t.set(c,{code:c,kind:"data",name:a[s],source:"data"})}for(let[s,c]of Object.entries(r.fieldPolicies)){if(we(s))continue;let u=T(c,`${i}/fieldPolicies/${s}`);for(let _ of["read","create","update"])if(Array.isArray(u[_]))for(let d of P(u[_],`${i}/fieldPolicies/${s}/${_}`,2e3))Ce(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 qs(e){let t=Ys(e);return X(e.data.resources.map((o,n)=>{let i=Se(o,`/config/data/resources/${n}`,e.appCode),r=t.get(i.code);return{code:i.code,schemaDigest:ee(i.schema),fields:X(i.schema.fields.map(a=>({code:a.code,type:a.type})),a=>a.code),...r?{detailRouteCode:r}:{}}}),o=>o.code)}function Ks(e,t){if(e.data.subjectReadSurfaces===void 0)return[];let o=R(e.data.subjectReadSurfaces,"/config/data/subjectReadSurfaces",K.subjectReadSurfaces),n=new Set(t.map(a=>String(a.code))),i=new Map(e.data.resources.map((a,s)=>{let c=`/config/data/resources/${s}`,u=Se(a,c,e.appCode);return[String(u.code),{resource:u,fields:new Map(R(T(u.schema,`${c}/schema`).fields,`${c}/schema/fields`,500).map(_=>{let d=T(_,`${c}/schema/fields`);return[String(d.code),d]}))}]})),r=new Set;return X(o.map((a,s)=>{let c=`/config/data/subjectReadSurfaces/${s}`,u=T(a,c);h(u,["code","name","capability","subject","relations"],c);let _=w(u.code,`${c}/code`);r.has(_)&&f("NATIVE_SUBJECT_READ_SURFACE_CODE_DUPLICATE",`${c}/code`),r.add(_);let d=Ce(u.capability,`${c}/capability`,e.appCode);n.has(d)||f("NATIVE_SUBJECT_READ_SURFACE_CAPABILITY_NOT_DECLARED",`${c}/capability`);let p=T(u.subject,`${c}/subject`);h(p,["resourceCode","fields"],`${c}/subject`);let I=z(p.resourceCode,`${c}/subject/resourceCode`),l=i.get(I);l||f("NATIVE_SUBJECT_READ_SURFACE_RESOURCE_NOT_DECLARED",`${c}/subject/resourceCode`);let E=P(p.fields,`${c}/subject/fields`,100).map((O,b)=>W(O,`${c}/subject/fields/${b}`));E.length||f("NATIVE_SUBJECT_READ_SURFACE_FIELDS_REQUIRED",`${c}/subject/fields`);for(let[O,b]of E.entries()){let C=l.fields.get(b);(!C||C.type==="subtable")&&f("NATIVE_SUBJECT_READ_SURFACE_FIELD_INVALID",`${c}/subject/fields/${O}`)}let N=R(u.relations,`${c}/relations`,8);N.length||f("NATIVE_SUBJECT_READ_SURFACE_RELATIONS_REQUIRED",`${c}/relations`);let g=new Set,A=0,m=X(N.map((O,b)=>{let C=`${c}/relations/${b}`,y=T(O,C);h(y,["code","resourceCode","foreignKeyField","fields","limit"],C,["order"]);let S=w(y.code,`${C}/code`);g.has(S)&&f("NATIVE_SUBJECT_READ_SURFACE_RELATION_CODE_DUPLICATE",`${C}/code`),g.add(S);let v=z(y.resourceCode,`${C}/resourceCode`),F=i.get(v);F||f("NATIVE_SUBJECT_READ_SURFACE_RESOURCE_NOT_DECLARED",`${C}/resourceCode`);let B=W(y.foreignKeyField,`${C}/foreignKeyField`),U=F.fields.get(B),pe=T(U?.source||{},`${C}/foreignKeyField/source`);(!U||!["uuid","resource-ref.single"].includes(String(U.type))||U.type==="resource-ref.single"&&(pe.kind!=="resource"||pe.resourceCode!==I))&&f("NATIVE_SUBJECT_READ_SURFACE_RELATION_INVALID",`${C}/foreignKeyField`);let _e=P(y.fields,`${C}/fields`,100).map((se,V)=>W(se,`${C}/fields/${V}`));_e.length||f("NATIVE_SUBJECT_READ_SURFACE_FIELDS_REQUIRED",`${C}/fields`);for(let[se,V]of _e.entries()){let j=F.fields.get(V);(!j||j.type==="subtable")&&f("NATIVE_SUBJECT_READ_SURFACE_FIELD_INVALID",`${C}/fields/${se}`)}let Y=R(y.order||[],`${C}/order`,10).map((se,V)=>{let j=`${C}/order/${V}`,L=T(se,j);h(L,["field","direction"],j);let G=W(L.field,`${j}/field`),J=F.fields.get(G);return(!Do.has(G)&&!J||J?.type==="subtable"||J&&!Pe(J.type))&&f("NATIVE_SUBJECT_READ_SURFACE_ORDER_FIELD_INVALID",`${j}/field`),["asc","desc"].includes(String(L.direction))||f("NATIVE_SUBJECT_READ_SURFACE_ORDER_DIRECTION_INVALID",`${j}/direction`),{field:G,direction:L.direction}}),Ie=Z(y.limit,`${C}/limit`,1,100);return A+=Ie,{code:S,resourceCode:v,foreignKeyField:B,fields:M(_e),...Y.length?{order:Y}:{},limit:Ie}}),O=>O.code);return A>400&&f("NATIVE_SUBJECT_READ_SURFACE_ROW_LIMIT_EXCEEDED",`${c}/relations`),{code:_,name:$(u.name,`${c}/name`,255),capability:d,subject:{resourceCode:I,fields:M(E)},relations:m}}),a=>a.code)}function Ys(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 s=`/config/data/resources/${a}`,c=Se(r,s,e.appCode);return[c.code,c]})),n=new Map(Vt(e).map(r=>[String(r.code),r])),i=new Map;for(let[r,a]of t.entries()){let s=`/config/data/resourceDetailRoutes/${r}`,c=T(a,s);h(c,["resourceCode","desktop","mobile"],s);let u=z(c.resourceCode,`${s}/resourceCode`);i.has(u)&&f("NATIVE_DATA_RESOURCE_DETAIL_ROUTE_DUPLICATE",`${s}/resourceCode`);let _=o.get(u);_||f("NATIVE_DATA_RESOURCE_DETAIL_ROUTE_RESOURCE_MISSING",`${s}/resourceCode`);let d=w(c.desktop,`${s}/desktop`),p=w(c.mobile,`${s}/mobile`);d===p&&f("NATIVE_DATA_RESOURCE_DETAIL_ROUTE_INVALID",s);let I=String(_.capabilities.read);for(let[l,E]of[["desktop",d],["mobile",p]]){let N=`${s}/${l}`,g=n.get(E);g||f("NATIVE_DATA_RESOURCE_DETAIL_ROUTE_REFERENCE_MISSING",N),g.surface!=="user"&&f("NATIVE_DATA_RESOURCE_DETAIL_ROUTE_SURFACE_INVALID",N);let A=fe(g.path,`${N}/path`),m=[...A.matchAll(/:([A-Za-z][A-Za-z0-9_]*)/g)],O=l==="mobile"?!A.startsWith("/m/"):A==="/m"||A.startsWith("/m/");(A.includes("*")||A.includes("?")||A.includes("#")||A.split("/").includes("..")||m.length!==1||O)&&f("NATIVE_DATA_RESOURCE_DETAIL_ROUTE_PATH_INVALID",N);let b=Array.isArray(g.access?.allOf)?g.access.allOf:[];g.capability!==I&&!b.includes(I)&&f("NATIVE_DATA_RESOURCE_DETAIL_ROUTE_CAPABILITY_INVALID",N)}i.set(u,{desktop:d,mobile:p})}return i}function Fo(e){let t=new Map(e.data.resources.map((a,s)=>{let c=`/config/data/resources/${s}`,u=Se(a,c,e.appCode);return[u.code,new Map(u.schema.fields.map(_=>[String(_.code),_]))]})),o=new Map(e.data.resources.map((a,s)=>{let c=`/config/data/resources/${s}`,u=Se(a,c,e.appCode);return[u.code,new Map(u.schema.fields.map(_=>[String(_.code),String(_.type)]))]})),n=new Set(o.keys()),i=new Set(e.workflows.activations.map((a,s)=>Ft(T(a,`/config/workflows/activations/${s}`).workflowCode,`/config/workflows/activations/${s}/workflowCode`))),r=new Map;return X(e.backend.operations.map((a,s)=>{let c=`/config/backend/operations/${s}`,u=T(a,c);h(u,["code","method","path","capability","requestSchema","responseSchema","description","platformAccess","browser","ai"],c,!0);let _=$(u.method,`${c}/method`,16);["GET","POST","PUT","PATCH","DELETE"].includes(_)||f("NATIVE_OPERATION_METHOD_INVALID",`${c}/method`);let d=w(u.code,`${c}/code`);Zs(u.ai,c,d,_,n);let p=Qs(u.platformAccess,`${c}/platformAccess`,o,t,i,new Set(e.authz.roles.map(l=>String(l.code))));if(p?.decimalReservation){let l=p.decimalReservation,E=String(l.resourceCode),N=JSON.stringify([l.amountFieldCode,l.currencyFieldCode,l.relationFieldCode,l.parentFieldCode,l.rootFieldCode,l.statusFieldCode,l.parentRelationValue,l.childRelationValue]),g=r.get(E);g&&g!==N&&f("NATIVE_DECIMAL_RESERVATION_MAPPING_CONFLICT",`${c}/platformAccess/decimalReservation`),r.set(E,N)}let I=Hs(u.browser,`${c}/browser`,_,u.requestSchema,u.responseSchema,o,t,e.data.subjectReadSurfaces||[]);return{code:d,method:_,path:fe(u.path,`${c}/path`),requiredCapability:Ce(u.capability,`${c}/capability`,e.appCode),requestSchemaDigest:ee(T(u.requestSchema,`${c}/requestSchema`)),responseSchemaDigest:ee(T(u.responseSchema,`${c}/responseSchema`)),...u.description===void 0?{}:{description:Sn(u.description,`${c}/description`,2e3)},...p?{platformAccess:p}:{},...I?{browser:I}:{}}}),a=>a.code)}function Hs(e,t,o,n,i,r,a,s){if(e===void 0)return null;let c=T(e,t);h(c,["exposure","behavior","idempotency","subject"],t,["refreshTargets","fileIntent"]),x(c.exposure,"authenticated",`${t}/exposure`);let u=$(c.behavior,`${t}/behavior`,32);["read","controlled"].includes(u)||f("NATIVE_OPERATION_BROWSER_BEHAVIOR_INVALID",`${t}/behavior`);let _=$(c.idempotency,`${t}/idempotency`,32);(!["none","required"].includes(_)||u==="controlled"&&_!=="required"||u==="read"&&_!=="none")&&f("NATIVE_OPERATION_BROWSER_IDEMPOTENCY_INVALID",`${t}/idempotency`);let d=T(c.subject,`${t}/subject`);h(d,["resourceCode","inputField"],`${t}/subject`);let p=z(d.resourceCode,`${t}/subject/resourceCode`);r.has(p)||f("NATIVE_OPERATION_BROWSER_SUBJECT_RESOURCE_NOT_DECLARED",`${t}/subject/resourceCode`);let I=W(d.inputField,`${t}/subject/inputField`),l=T(n,`${t}/requestSchema`),E=T(i,`${t}/responseSchema`);(l.type!=="object"||l.additionalProperties!==!1||E.type!=="object"||E.additionalProperties!==!1)&&f("NATIVE_OPERATION_BROWSER_SCHEMA_ROOT_INVALID",`${t}/requestSchema`);let N=T(l.properties,`${t}/requestSchema/properties`),g=new Set(l.required===void 0?[]:P(l.required,`${t}/requestSchema/required`,200));(!(I in N)||!g.has(I))&&f("NATIVE_OPERATION_BROWSER_SUBJECT_INPUT_INVALID",`${t}/subject/inputField`);let A=T(N[I],`${t}/requestSchema/properties/${I}`);(A.type!=="string"||A.format!=="uuid")&&f("NATIVE_OPERATION_BROWSER_SUBJECT_INPUT_INVALID",`${t}/subject/inputField`);let m=new Map((Array.isArray(s)?s:[]).map((S,v)=>{let F=T(S,`/config/data/subjectReadSurfaces/${v}`);return[String(F.code),String(T(F.subject,`/config/data/subjectReadSurfaces/${v}/subject`).resourceCode)]})),O=c.refreshTargets===void 0?[]:R(c.refreshTargets,`${t}/refreshTargets`,16),b=new Set,C=X(O.map((S,v)=>{let F=`${t}/refreshTargets/${v}`,B=T(S,F);h(B,["kind","code"],F),x(B.kind,"subject-surface",`${F}/kind`);let U=w(B.code,`${F}/code`);return(b.has(U)||!m.has(U)||m.get(U)!==p)&&f("NATIVE_OPERATION_BROWSER_REFRESH_TARGET_INVALID",`${F}/code`),b.add(U),{kind:"subject-surface",code:U}}),S=>`${S.kind}:${S.code}`),y=Xs(c.fileIntent,`${t}/fileIntent`,o,u,_,p,N,g,a);return{exposure:"authenticated",behavior:u,idempotency:_,subject:{resourceCode:p,inputField:I},...C.length?{refreshTargets:C}:{},...y?{fileIntent:y}:{}}}function Xs(e,t,o,n,i,r,a,s,c){if(e===void 0)return null;let u=T(e,t);h(u,["recordResourceCode","recordIdInputField","relationField","fileNameField","contentTypeField","sizeField","purposes","maxTtlSeconds","maxBytes"],t),(o!=="GET"||n!=="read"||i!=="none")&&f("NATIVE_OPERATION_FILE_INTENT_BEHAVIOR_INVALID",t);let _=z(u.recordResourceCode,`${t}/recordResourceCode`),d=c.get(_);d||f("NATIVE_OPERATION_FILE_INTENT_RESOURCE_NOT_DECLARED",`${t}/recordResourceCode`);let p=W(u.recordIdInputField,`${t}/recordIdInputField`),I=T(a[p],`${t}/recordIdInputField`);(!s.has(p)||I.type!=="string"||I.format!=="uuid")&&f("NATIVE_OPERATION_FILE_INTENT_RECORD_INPUT_INVALID",`${t}/recordIdInputField`);let l=W(u.relationField,`${t}/relationField`),E=d.get(l);(!E||!["uuid","resource-ref.single"].includes(String(E.type))||String(E.type)==="resource-ref.single"&&(String(T(E.source,`${t}/relationField`).kind||"")!=="resource"||String(T(E.source,`${t}/relationField`).resourceCode||"")!==r))&&f("NATIVE_OPERATION_FILE_INTENT_RELATION_INVALID",`${t}/relationField`);let N=[["fileNameField",["text.short","text.long"]],["contentTypeField",["text.short","text.long"]],["sizeField",["number.integer"]]],g={};for(let[b,C]of N){let y=W(u[b],`${t}/${b}`);C.includes(String(d.get(y)?.type))||f("NATIVE_OPERATION_FILE_INTENT_METADATA_INVALID",`${t}/${b}`),g[b]=y}let A=X(P(u.purposes,`${t}/purposes`,2),b=>b);(!A.length||A.some(b=>!["preview","download"].includes(b)))&&f("NATIVE_OPERATION_FILE_INTENT_PURPOSE_INVALID",`${t}/purposes`);let m=Number(u.maxTtlSeconds);(!Number.isSafeInteger(m)||m<1||m>300)&&f("NATIVE_OPERATION_FILE_INTENT_TTL_INVALID",`${t}/maxTtlSeconds`);let O=Number(u.maxBytes);return(!Number.isSafeInteger(O)||O<1||O>104857600)&&f("NATIVE_OPERATION_FILE_INTENT_SIZE_INVALID",`${t}/maxBytes`),{recordResourceCode:_,recordIdInputField:p,relationField:l,fileNameField:g.fileNameField,contentTypeField:g.contentTypeField,sizeField:g.sizeField,purposes:A,maxTtlSeconds:m,maxBytes:O}}function Qs(e,t,o,n,i,r){if(e===void 0)return null;let a=T(e,t);h(a,["directory","managedFiles","managedFileCopies","notification","workflow","roleAssertions","decimalReservation"],t,!0),Object.keys(a).length===0&&f("NATIVE_OPERATION_PLATFORM_ACCESS_EMPTY",t);let s={};if(a.roleAssertions!==void 0){let c=T(a.roleAssertions,`${t}/roleAssertions`);h(c,["roleCodes"],`${t}/roleAssertions`);let u=P(c.roleCodes,`${t}/roleAssertions/roleCodes`,20);u.length||f("NATIVE_OPERATION_ROLE_ASSERTIONS_REQUIRED",`${t}/roleAssertions/roleCodes`),u.forEach((_,d)=>{r.has(_)||f("NATIVE_ROLE_REFERENCE_MISSING",`${t}/roleAssertions/roleCodes/${d}`)}),s.roleAssertions={roleCodes:M(u)}}if(a.directory!==void 0){let c=T(a.directory,`${t}/directory`);h(c,["mode","fields"],`${t}/directory`),["current-initiator","selected-user"].includes(String(c.mode))||f("NATIVE_OPERATION_DIRECTORY_MODE_INVALID",`${t}/directory/mode`);let u=new Set(["displayName","employeeNumber","primaryDepartment","departments"]),_=P(c.fields,`${t}/directory/fields`,4);(!_.length||_.some(d=>!u.has(d)))&&f("NATIVE_OPERATION_DIRECTORY_FIELDS_INVALID",`${t}/directory/fields`),s.directory={mode:String(c.mode),fields:M(_)}}if(a.managedFiles!==void 0){let c=R(a.managedFiles,`${t}/managedFiles`,16);c.length||f("NATIVE_OPERATION_MANAGED_FILES_REQUIRED",`${t}/managedFiles`);let u=new Set;s.managedFiles=X(c.map((_,d)=>{let p=`${t}/managedFiles/${d}`,I=T(_,p);h(I,["resourceCode","fieldCodes","intents"],p);let l=z(I.resourceCode,`${p}/resourceCode`);(u.has(l)||!o.has(l))&&f("NATIVE_OPERATION_MANAGED_FILE_RESOURCE_INVALID",`${p}/resourceCode`),u.add(l);let E=P(I.fieldCodes,`${p}/fieldCodes`,16);(!E.length||E.some(g=>!["file","image","signature","text.rich"].includes(String(o.get(l)?.get(g)||""))))&&f("NATIVE_OPERATION_MANAGED_FILE_FIELD_INVALID",`${p}/fieldCodes`);let N=P(I.intents,`${p}/intents`,2);return(!N.length||N.some(g=>!["create","update"].includes(g)))&&f("NATIVE_OPERATION_MANAGED_FILE_INTENT_INVALID",`${p}/intents`),{resourceCode:l,fieldCodes:M(E),intents:M(N)}}),_=>_.resourceCode)}if(a.managedFileCopies!==void 0){let c=R(a.managedFileCopies,`${t}/managedFileCopies`,16);c.length||f("NATIVE_OPERATION_MANAGED_FILE_COPIES_REQUIRED",`${t}/managedFileCopies`);let u=new Set;s.managedFileCopies=X(c.map((_,d)=>{let p=`${t}/managedFileCopies/${d}`,I=T(_,p);h(I,["mode","sourceResourceCode","sourceFieldCodes","targetResourceCode","targetFieldCodes"],p),x(I.mode,"copy",`${p}/mode`);let l=z(I.sourceResourceCode,`${p}/sourceResourceCode`),E=z(I.targetResourceCode,`${p}/targetResourceCode`),N=o.get(l),g=o.get(E);(!N||!g)&&f("NATIVE_OPERATION_MANAGED_FILE_COPY_RESOURCE_INVALID",p);let A=P(I.sourceFieldCodes,`${p}/sourceFieldCodes`,16),m=P(I.targetFieldCodes,`${p}/targetFieldCodes`,16);(!A.length||A.length!==m.length)&&f("NATIVE_OPERATION_MANAGED_FILE_COPY_FIELDS_INVALID",p),A.forEach((b,C)=>{let y=N.get(b),S=g.get(m[C]);(!["file","image"].includes(String(y))||y!==S)&&f("NATIVE_OPERATION_MANAGED_FILE_COPY_FIELD_INVALID",`${p}/sourceFieldCodes/${C}`)});let O=`${l}:${A.join(",")}=>${E}:${m.join(",")}`;return u.has(O)&&f("NATIVE_OPERATION_MANAGED_FILE_COPY_DUPLICATE",p),u.add(O),{mode:"copy",sourceResourceCode:l,sourceFieldCodes:M(A),targetResourceCode:E,targetFieldCodes:M(m)}}),_=>`${_.sourceResourceCode}:${_.sourceFieldCodes.join(",")}=>${_.targetResourceCode}:${_.targetFieldCodes.join(",")}`)}if(a.notification!==void 0){let c=T(a.notification,`${t}/notification`);h(c,["mode"],`${t}/notification`),c.mode!=="business-standard"&&f("NATIVE_OPERATION_NOTIFICATION_MODE_INVALID",`${t}/notification/mode`),s.notification={mode:"business-standard"}}if(a.workflow!==void 0){let c=T(a.workflow,`${t}/workflow`);h(c,["codes"],`${t}/workflow`);let u=P(c.codes,`${t}/workflow/codes`,16);(!u.length||u.some(_=>!i.has(_)))&&f("NATIVE_OPERATION_WORKFLOW_CODE_INVALID",`${t}/workflow/codes`),s.workflow={codes:M(u)}}if(a.decimalReservation!==void 0){let c=`${t}/decimalReservation`,u=T(a.decimalReservation,c);h(u,["mode","resourceCode","amountFieldCode","currencyFieldCode","relationFieldCode","parentFieldCode","rootFieldCode","statusFieldCode","parentRelationValue","childRelationValue","eligibleParentStatuses","eligibleChildStatuses"],c);let _=$(u.mode,`${c}/mode`,16);["reserve","commit","release"].includes(_)||f("NATIVE_DECIMAL_RESERVATION_MODE_INVALID",`${c}/mode`);let d=z(u.resourceCode,`${c}/resourceCode`),p=n.get(d);p||f("NATIVE_DECIMAL_RESERVATION_RESOURCE_MISSING",`${c}/resourceCode`);let l=Object.fromEntries(["amountFieldCode","currencyFieldCode","relationFieldCode","parentFieldCode","rootFieldCode","statusFieldCode"].map(b=>[b,W(u[b],`${c}/${b}`)])),E=b=>p.get(l[b]),N=b=>new Set((E(b)?.options||[]).map(C=>String(C.value))),g=w(u.parentRelationValue,`${c}/parentRelationValue`),A=w(u.childRelationValue,`${c}/childRelationValue`),m=P(u.eligibleParentStatuses,`${c}/eligibleParentStatuses`,16),O=P(u.eligibleChildStatuses,`${c}/eligibleChildStatuses`,16);(E("amountFieldCode")?.type!=="number.decimal"||E("amountFieldCode")?.exactDecimal!==!0||E("amountFieldCode")?.precision!==18||E("amountFieldCode")?.scale!==2||E("currencyFieldCode")?.type!=="option.single"||E("relationFieldCode")?.type!=="option.single"||E("parentFieldCode")?.type!=="resource-ref.single"||E("parentFieldCode")?.source?.resourceCode!==d||E("rootFieldCode")?.type!=="uuid"||E("statusFieldCode")?.type!=="option.single"||g===A||!N("relationFieldCode").has(g)||!N("relationFieldCode").has(A)||!m.length||!O.length||m.some(b=>!N("statusFieldCode").has(b))||O.some(b=>!N("statusFieldCode").has(b)))&&f("NATIVE_DECIMAL_RESERVATION_FIELD_INVALID",c),s.decimalReservation={mode:_,resourceCode:d,...l,parentRelationValue:g,childRelationValue:A,eligibleParentStatuses:M(m),eligibleChildStatuses:M(O)}}return s}function Zs(e,t,o,n,i){if(e===void 0)return;let r=`${t}/ai`,a=T(e,r);Ns.test(o)||f("NATIVE_OPERATION_AI_CODE_INVALID",`${t}/code`),h(a,["name","description","risk","resources","sideEffects","concurrency","timeoutMs"],r,!0),$(a.name,`${r}/name`,Cn),$(a.description,`${r}/description`,Cn);let s=$(a.risk,`${r}/risk`,16);["read","write","destructive","external"].includes(s)||f("NATIVE_OPERATION_AI_RISK_INVALID",`${r}/risk`),s==="read"!=(n==="GET")&&f("NATIVE_OPERATION_AI_METHOD_RISK_MISMATCH",`${r}/risk`),n==="DELETE"&&!["destructive","external"].includes(s)&&f("NATIVE_OPERATION_AI_METHOD_RISK_MISMATCH",`${r}/risk`);let c=P(a.resources,`${r}/resources`,16);c.length===0&&f("NATIVE_OPERATION_AI_RESOURCE_REQUIRED",`${r}/resources`),c.forEach((_,d)=>{let p=z(_,`${r}/resources/${d}`);i.has(p)||f("NATIVE_OPERATION_AI_RESOURCE_MISSING",`${r}/resources/${d}`)});let u=P(a.sideEffects,`${r}/sideEffects`,20);(s==="read"&&u.length!==0||s!=="read"&&u.length===0)&&f("NATIVE_OPERATION_AI_SIDE_EFFECT_INVALID",`${r}/sideEffects`),a.concurrency!==void 0&&!["none","revision"].includes($(a.concurrency,`${r}/concurrency`,16))&&f("NATIVE_OPERATION_AI_CONCURRENCY_INVALID",`${r}/concurrency`),a.timeoutMs!==void 0&&Z(a.timeoutMs,`${r}/timeoutMs`,100,3e4)}function $t(e){return(e.replace(/\/{2,}/g,"/").replace(/\/$/,"")||"/").split("/").map(o=>o.startsWith(":")?":":o.includes("*")?"*":o).join("/")}function er(e,t){let o=T(e,t),n=$(o.type,`${t}/type`,32),i=["code","type","label","presentation","required"],r=n==="sso"?[...i,"provider"]:n==="dingtalk"?[...i,"flow"]:i;h(o,r,t);let a=w(o.code,`${t}/code`),s=$(o.label,`${t}/label`,255),c=$(o.presentation,`${t}/presentation`,16);["primary","secondary"].includes(c)||f("NATIVE_APPLICATION_AUTH_METHOD_PRESENTATION_INVALID",`${t}/presentation`);let u=Be(o.required,`${t}/required`);return["sso","password","dingtalk"].includes(n)||f("NATIVE_APPLICATION_AUTH_METHOD_TYPE_INVALID",`${t}/type`),n==="sso"&&o.provider!=="tenant-default"&&f("NATIVE_APPLICATION_AUTH_SSO_PROVIDER_INVALID",`${t}/provider`),n==="dingtalk"&&!["auto","jsapi","oauth"].includes($(o.flow,`${t}/flow`,16))&&f("NATIVE_APPLICATION_AUTH_DINGTALK_FLOW_INVALID",`${t}/flow`),{code:a,type:n,label:s,presentation:c,required:u,...n==="sso"?{provider:"tenant-default"}:{},...n==="dingtalk"?{flow:o.flow}:{}}}function _o(e,t,o){let n=T(e,o);h(n,["routeCode","path","defaultRouteCode"],o);let i=w(n.routeCode,`${o}/routeCode`),r=fe(n.path,`${o}/path`),a=t==="desktop"?"/login":"/m/login";return(r!==a||/[:*?#\\]/.test(r))&&f("NATIVE_APPLICATION_AUTH_SURFACE_PATH_INVALID",`${o}/path`,{device:t,expectedPath:a}),{routeCode:i,path:r,defaultRouteCode:w(n.defaultRouteCode,`${o}/defaultRouteCode`)}}function Po(e,t,o,n){if(e===null)return;let i=T(e,n);h(i,["accountMode","registration","methods","surfaces"],n),x(i.accountMode,"existing-platform-users-only",`${n}/accountMode`);let r=T(i.registration,`${n}/registration`);h(r,["mode"],`${n}/registration`),x(r.mode,"reject",`${n}/registration/mode`);let a=R(i.methods,`${n}/methods`,8);a.length===0&&f("NATIVE_APPLICATION_AUTH_METHOD_REQUIRED",`${n}/methods`);let s=a.map((g,A)=>er(g,`${n}/methods/${A}`)),c=new Set,u=new Set;for(let[g,A]of s.entries())c.has(A.code)&&f("NATIVE_APPLICATION_AUTH_METHOD_CODE_DUPLICATE",`${n}/methods/${g}/code`),u.has(A.type)&&f("NATIVE_APPLICATION_AUTH_METHOD_TYPE_DUPLICATE",`${n}/methods/${g}/type`),c.add(A.code),u.add(A.type);s.filter(g=>g.presentation==="primary").length!==1&&f("NATIVE_APPLICATION_AUTH_PRIMARY_METHOD_INVALID",`${n}/methods`);let _=T(i.surfaces,`${n}/surfaces`);h(_,["desktop","mobile"],`${n}/surfaces`);let d=_o(_.desktop,"desktop",`${n}/surfaces/desktop`),p=_o(_.mobile,"mobile",`${n}/surfaces/mobile`);d.routeCode===p.routeCode&&f("NATIVE_APPLICATION_AUTH_SURFACE_CODE_DUPLICATE",`${n}/surfaces/mobile/routeCode`);let I=R(t,"/config/frontend/routes",500),l=new Map;for(let[g,A]of I.entries()){let m=T(A,`/config/frontend/routes/${g}`);l.set(String(m.code||""),m)}let E=new Set((Array.isArray(o.data?.resources)?o.data.resources:[]).map(g=>String(g.code||"")).filter(g=>/^[a-z][a-z0-9-]{0,62}$/.test(g)));for(let[g,A]of[["desktop",d],["mobile",p]]){l.has(A.routeCode)&&f("NATIVE_APPLICATION_AUTH_SURFACE_CODE_CONFLICT",`${n}/surfaces/${g}/routeCode`);let m=/^user\.([a-z][a-z0-9-]{0,62})\.(records|submit)$/.exec(String(A.defaultRouteCode||"")),O=l.get(A.defaultRouteCode),b=String(O?.path||"");if(m&&E.has(m[1])){let y=m[2]==="records"?`/my/${m[1]}`:`/my/${m[1]}/submit`;O={surface:"user",path:g==="mobile"?`/m${y}`:y},b=String(O.path)}let C=g==="desktop"?b==="/m"||b.startsWith("/m/"):!(b==="/m"||b.startsWith("/m/"));(!O||O.surface!=="user"||/[:*]/.test(b)||C)&&f("NATIVE_APPLICATION_AUTH_DEFAULT_ROUTE_INVALID",`${n}/surfaces/${g}/defaultRouteCode`)}let N=vo(o).filter(g=>!g.owner.startsWith("authentication:"));for(let[g,A]of[["desktop",d],["mobile",p]]){let m=N.find(O=>$t(O.path)===$t(A.path));m&&f("NATIVE_APPLICATION_AUTH_SURFACE_PATH_CONFLICT",`${n}/surfaces/${g}/path`,{owner:m.owner})}}function tr(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=T(e,t),i=T(n.surfaces,`${t}/surfaces`),r={...n,surfaces:{...i,desktop:{...T(i.desktop,`${t}/surfaces/desktop`),defaultRouteCode:"auth-desktop-default"},mobile:{...T(i.mobile,`${t}/surfaces/mobile`),defaultRouteCode:"auth-mobile-default"}}};Po(r,o.frontend.routes,{...o,frontend:{...o.frontend,authentication:r}},t)}function nr(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 or=new Set(["draft.read","draft.update","validate","create","own.list","own.read","public.list","public.read"]);function ir(e,t,o){let n=T(e,o);h(n,["policies"],o);let i=R(n.policies,`${o}/policies`,16);i.length<1&&f("NATIVE_PUBLIC_POLICY_REQUIRED",o);let r=new Map(t.frontend.routes.map(u=>[u.code,u])),a=new Map(t.data.resources.map(u=>[u.code,u])),s=new Set,c=new Set(i.map(u=>String(u?.code||"")));i.forEach((u,_)=>{let d=`${o}/policies/${_}`,p=T(u,d);h(p,["code","routeCode","mode","resourceCode","operations","fields"],d,["requiredFields","ownRecordFields","publicRecordFields","publicFilters","serverGeneratedFields","schedule","publicSubtableFields","draft","validations"]);let I=w(p.code,`${d}/code`);s.has(I)&&f("NATIVE_PUBLIC_POLICY_DUPLICATE",`${d}/code`);let l=w(p.routeCode,`${d}/routeCode`),E=r.get(l);(!E||E.surface!=="user"||E.capability!==void 0||E.access!==void 0||/[:*]/.test(String(E.path)))&&f("NATIVE_PUBLIC_ROUTE_INVALID",`${d}/routeCode`),x(p.mode,"anonymous",`${d}/mode`);let N=z(p.resourceCode,`${d}/resourceCode`),g=a.get(N);g||f("NATIVE_PUBLIC_RESOURCE_MISSING",`${d}/resourceCode`);let A=new Map(g.schema.fields.map(V=>[String(V.code),String(V.type)])),m=P(p.operations,`${d}/operations`,8);(m.length<1||m.some(V=>!or.has(V)))&&f("NATIVE_PUBLIC_OPERATION_INVALID",`${d}/operations`),m.includes("draft.read")!==m.includes("draft.update")&&f("NATIVE_PUBLIC_DRAFT_OPERATION_INCOMPLETE",`${d}/operations`);let O=P(p.fields,`${d}/fields`,64);(O.length<1||O.some(V=>!A.has(V)))&&f("NATIVE_PUBLIC_FIELD_INVALID",`${d}/fields`);for(let V of["requiredFields","ownRecordFields","publicRecordFields"]){if(!Object.prototype.hasOwnProperty.call(p,V))continue;P(p[V],`${d}/${V}`,64).some(L=>!O.includes(L))&&f("NATIVE_PUBLIC_FIELD_SCOPE_INVALID",`${d}/${V}`)}let b=Object.prototype.hasOwnProperty.call(p,"serverGeneratedFields")?R(p.serverGeneratedFields,`${d}/serverGeneratedFields`,16):[],C=new Set;b.forEach((V,j)=>{let L=`${d}/serverGeneratedFields/${j}`,G=T(V,L);h(G,["field","kind"],L);let J=W(G.field,`${L}/field`);(C.has(J)||!A.has(J)||O.includes(J)||A.get(J)!=="text.short"&&A.get(J)!=="text.long")&&f("NATIVE_PUBLIC_SERVER_GENERATED_FIELD_INVALID",`${L}/field`),x(G.kind,"random-token",`${L}/kind`),C.add(J)});let y=Object.prototype.hasOwnProperty.call(p,"schedule")?T(p.schedule,`${d}/schedule`):null;if(y){let V=["campusPolicyCode","rulePolicyCode","campusField","ruleCampusField","ruleWeekdaysField","ruleOpenAtField","ruleCloseAtField","ruleSlotMinutesField","ruleAdvanceHoursField","ruleAdvanceDaysField","campusEnabledField","ruleEnabledField","dateField","timeField"];h(y,V,`${d}/schedule`);for(let j of["campusPolicyCode","rulePolicyCode"])w(y[j],`${d}/schedule/${j}`);for(let j of V.filter(L=>!["campusPolicyCode","rulePolicyCode"].includes(L)))W(y[j],`${d}/schedule/${j}`);for(let j of[y.campusField,y.dateField,y.timeField])O.includes(String(j))||f("NATIVE_PUBLIC_SCHEDULE_FIELD_INVALID",`${d}/schedule`);(!c.has(String(y.campusPolicyCode))||!c.has(String(y.rulePolicyCode)))&&f("NATIVE_PUBLIC_SCHEDULE_POLICY_INVALID",`${d}/schedule`)}let S=Object.prototype.hasOwnProperty.call(p,"publicFilters")?R(p.publicFilters,`${d}/publicFilters`,16):[],v=new Set;S.forEach((V,j)=>{let L=`${d}/publicFilters/${j}`,G=T(V,L);h(G,["field","operator","value"],L);let J=W(G.field,`${L}/field`);v.has(J)&&f("NATIVE_PUBLIC_FILTER_DUPLICATE",`${L}/field`),O.includes(J)||f("NATIVE_PUBLIC_FILTER_FIELD_INVALID",`${L}/field`),x(G.operator,"eq",`${L}/operator`),["boolean","text.short","text.long","number.integer","number.decimal","date","time"].includes(A.get(J)||"")||f("NATIVE_PUBLIC_FILTER_FIELD_INVALID",`${L}/field`),G.value!==null&&typeof G.value!="string"&&typeof G.value!="number"&&typeof G.value!="boolean"&&f("NATIVE_PUBLIC_FILTER_VALUE_INVALID",`${L}/value`),v.add(J)});let F=Object.prototype.hasOwnProperty.call(p,"publicSubtableFields")?T(p.publicSubtableFields,`${d}/publicSubtableFields`):null;if(F){Object.keys(F).length>64&&f("NATIVE_PUBLIC_SUBTABLE_FIELDS_INVALID",`${d}/publicSubtableFields`);for(let[V,j]of Object.entries(F)){let L=g.schema.fields.find(H=>String(H.code)===V),G=String(L?.subtable?.resourceCode||""),J=a.get(G),ge=new Map((J?.schema?.fields||[]).map(H=>[String(H.code),String(H.type)])),q=P(j,`${d}/publicSubtableFields/${V}`,64);(!O.includes(V)||A.get(V)!=="subtable"||!J||q.length<1||q.some(H=>!ge.has(H))||q.some(H=>ge.get(H)==="subtable")||q.some(H=>ge.get(H)==="signature"))&&f("NATIVE_PUBLIC_SUBTABLE_FIELDS_INVALID",`${d}/publicSubtableFields/${V}`)}}if(m.some(V=>V.startsWith("public."))){Object.prototype.hasOwnProperty.call(p,"publicRecordFields")||f("NATIVE_PUBLIC_RECORD_FIELDS_REQUIRED",`${d}/publicRecordFields`);let V=P(p.publicRecordFields,`${d}/publicRecordFields`,64);(V.length<1||V.some(j=>!O.includes(j))||V.some(j=>A.get(j)==="signature"||A.get(j)==="subtable"&&!F?.[j]))&&f("NATIVE_PUBLIC_RECORD_FIELDS_INVALID",`${d}/publicRecordFields`)}let B=Object.prototype.hasOwnProperty.call(p,"requiredFields")?P(p.requiredFields,`${d}/requiredFields`,64):[],U=g.surface||{},pe=U.fields||{},_e=String(U.mutationOwner||"native")==="native"&&U.generated?.create!==!1,Y=g.schema.fields.filter(V=>Je(V,pe[V.code])).map(V=>String(V.code));if(m.includes("create")&&!_e&&f("NATIVE_PUBLIC_CREATE_FIELDS_INCOMPLETE",`${d}/fields`),m.includes("create")&&!Object.prototype.hasOwnProperty.call(p,"draft")&&f("NATIVE_PUBLIC_DRAFT_REQUIRED",`${d}/draft`),m.includes("create"))for(let V of Y){let j=O.includes(V)?B.includes(V)?null:"requiredFields":"fields";j&&f("NATIVE_PUBLIC_CREATE_FIELDS_INCOMPLETE",`${d}/${j}`,{resourceCode:z,fieldCode:V})}if(Object.prototype.hasOwnProperty.call(p,"draft")){let V=T(p.draft,`${d}/draft`);h(V,["enabled","inactivityTtlSeconds","maxBytes"],`${d}/draft`),x(V.enabled,!0,`${d}/draft/enabled`),Z(V.inactivityTtlSeconds,`${d}/draft/inactivityTtlSeconds`,3600,7776e3),Z(V.maxBytes,`${d}/draft/maxBytes`,4096,262144)}else m.includes("draft.read")&&f("NATIVE_PUBLIC_DRAFT_REQUIRED",`${d}/draft`);let Ie=Object.prototype.hasOwnProperty.call(p,"validations")?R(p.validations,`${d}/validations`,16):[],se=new Set;Ie.forEach((V,j)=>{let L=`${d}/validations/${j}`,G=T(V,L);h(G,["code","kind","fields","result"],L);let J=w(G.code,`${L}/code`);se.has(J)&&f("NATIVE_PUBLIC_VALIDATION_DUPLICATE",`${L}/code`),x(G.kind,"duplicate",`${L}/kind`),x(G.result,"availability",`${L}/result`);let ge=P(G.fields,`${L}/fields`,8);(ge.length<1||ge.some(q=>!O.includes(q))||ge.some(q=>["file","subtable"].includes(A.get(q)||"")))&&f("NATIVE_PUBLIC_VALIDATION_FIELD_INVALID",`${L}/fields`),se.add(J)}),s.add(I)})}function sr(e,t){let o=T(e,t);h(o,["policies"],t),R(o.policies,`${t}/policies`,16).length<1&&f("NATIVE_PUBLIC_POLICY_REQUIRED",t)}function rr(e){return{policies:X(e.frontend.publicAccess.policies.map(t=>({code:t.code,routeCode:t.routeCode,mode:t.mode,resourceCode:t.resourceCode,operations:M(t.operations),fields:M(t.fields),...t.requiredFields?{requiredFields:M(t.requiredFields)}:{},...t.ownRecordFields?{ownRecordFields:M(t.ownRecordFields)}:{},...t.publicRecordFields?{publicRecordFields:M(t.publicRecordFields)}:{},...t.publicFilters?{publicFilters:t.publicFilters.map(o=>({field:o.field,operator:o.operator,value:o.value})).sort((o,n)=>ce(o.field,n.field))}:{},...t.publicSubtableFields?{publicSubtableFields:Object.fromEntries(Object.entries(t.publicSubtableFields).sort(([o],[n])=>o.localeCompare(n)).map(([o,n])=>[o,M(Array.isArray(n)?n.map(String):[])]))}:{},...t.serverGeneratedFields?{serverGeneratedFields:t.serverGeneratedFields.map(o=>({field:o.field,kind:o.kind})).sort((o,n)=>ce(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:M(o.fields),result:o.result})),o=>o.code)}:{}})),t=>t.code)}}function vo(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=Lo(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 Vt(e){let t=new Map(vo(e).map(o=>[$t(o.path),o]));return X(e.frontend.routes.map((o,n)=>{let i=`/config/frontend/routes/${n}`,r=T(o,i);h(r,["code","path","label","surface","parentCode","capability","access","pinned","tabPersistence","keepAlive"],i,!0),["admin","user"].includes(r.surface)||f("NATIVE_ROUTE_SURFACE_INVALID",`${i}/surface`);let a=fe(r.path,`${i}/path`);r.surface==="admin"&&a!=="/admin"&&!a.startsWith("/admin/")&&f("NATIVE_ADMIN_ROUTE_PATH_INVALID",`${i}/path`),r.surface==="user"&&(a==="/admin"||a.startsWith("/admin/"))&&f("NATIVE_USER_ROUTE_PATH_RESERVED",`${i}/path`);let s=$t(a),c=t.get(s);c&&f("NATIVE_ROUTE_PATH_CONFLICT",`${i}/path`,{path:a,owner:c.owner}),t.set(s,{owner:`frontend:${String(r.code||n)}`,path:a});let u=/[:*]/.test(a),_=$n(r,i,e.appCode),d=r.pinned===void 0?void 0:Be(r.pinned,`${i}/pinned`),p=r.tabPersistence===void 0?u?"none":"session":$(r.tabPersistence,`${i}/tabPersistence`,16),I=r.keepAlive===void 0?"none":$(r.keepAlive,`${i}/keepAlive`,16);return["session","none"].includes(p)||f("NATIVE_ROUTE_TAB_PERSISTENCE_INVALID",`${i}/tabPersistence`),["none","memory"].includes(I)||f("NATIVE_ROUTE_KEEP_ALIVE_INVALID",`${i}/keepAlive`),u&&d===!0&&f("NATIVE_DYNAMIC_ROUTE_PINNED_FORBIDDEN",`${i}/pinned`),u&&p==="session"&&f("NATIVE_DYNAMIC_ROUTE_TAB_PERSISTENCE_FORBIDDEN",`${i}/tabPersistence`),u&&I==="memory"&&f("NATIVE_DYNAMIC_ROUTE_KEEP_ALIVE_FORBIDDEN",`${i}/keepAlive`),{code:w(r.code,`${i}/code`),path:a,label:$(r.label,`${i}/label`,255),surface:r.surface,...r.parentCode===void 0?{}:{parentCode:w(r.parentCode,`${i}/parentCode`)},..._,...d===void 0?{}:{pinned:d},tabPersistence:p,keepAlive:I}}),o=>o.code)}function Lo(e){let t=e.surface===void 0?{}:T(e.surface,"/surface"),o=t.mutationOwner||"native",n=t.generated===void 0?{}:T(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 ko(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(i=>({viewCode:i.code,resource:{...n,name:i.name,surface:ut(n.surface,i.code)}}))])){let{resource:n,viewCode:i}=o,r=`/admin/resources/${n.code}${i?`/views/${i}`:""}`,a=Lo(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 c of s)a[c.operation]&&t.push({code:`resource:${n.code}${i?`:view:${i}`:""}:${c.operation}`,kind:c.kind,path:c.path,label:c.label,navigationEligible:c.navigationEligible,capability:c.capability,resourceCode:n.code,...i?{viewCode:i}:{}})}for(let o of Vt(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)=>ce(o.code,n.code))}function xo(e){return e.kind==="resource"?`resource:${e.resourceCode}${e.viewCode?`:view:${e.viewCode}`:""}:list`:`operation:${e.routeCode}`}function ar(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:xo(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||ce(n.pageCode,i.pageCode))})).sort((t,o)=>t.order-o.order||ce(t.code,o.code))}function cr(e,t){let o=R(e,t,K.adminNavigationGroups),n=0;o.forEach((i,r)=>{let a=`${t}/${r}`,s=T(i,a);h(s,["code","label","icon","order","items"],a,!0),w(s.code,`${a}/code`),$(s.label,`${a}/label`,255),St(s.icon,`${a}/icon`),go(s.order,`${a}/order`);let c=R(s.items,`${a}/items`,500);c.length===0&&f("NATIVE_ADMIN_GROUP_ORPHANED",`${a}/items`),n+=c.length,n>K.adminNavigationItems&&f("NATIVE_ARRAY_LIMIT_EXCEEDED",t),c.forEach((u,_)=>{let d=`${a}/items/${_}`,p=T(u,d);h(p,["page","label","icon","order"],d,!0),dr(p.page,`${d}/page`),p.label!==void 0&&$(p.label,`${d}/label`,255),St(p.icon,`${d}/icon`),go(p.order,`${d}/order`)})})}function dr(e,t){let o=T(e,t),n=$(o.kind,`${t}/kind`,64);if(n==="resource"){h(o,["kind","resourceCode"],t,["viewCode"]),o.viewCode!==void 0&&w(o.viewCode,`${t}/viewCode`),z(o.resourceCode,`${t}/resourceCode`);return}if(n==="operation"){h(o,["kind","routeCode"],t),w(o.routeCode,`${t}/routeCode`);return}f("NATIVE_ADMIN_PAGE_REFERENCE_KIND_INVALID",`${t}/kind`)}function lr(e){let t=new Map(ko(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)&&f("NATIVE_ADMIN_GROUP_DUPLICATE",`${a}/code`),o.add(i.code),i.label===i.code&&f("NATIVE_ADMIN_USER_LABEL_REQUIRED",`${a}/label`),i.items.forEach((s,c)=>{let u=`${a}/items/${c}`,_=xo(s.page),d=t.get(_);(!d||d.navigationEligible!==!0)&&f("NATIVE_ADMIN_PAGE_NOT_FOUND",`${u}/page`),n.has(_)&&f("NATIVE_ADMIN_PAGE_DUPLICATE",`${u}/page`),n.add(_);let p=s.page.resourceCode||s.page.routeCode||s.page.workflowCode||_,I=s.label||d.label;(!I||I===p||I===_)&&f("NATIVE_ADMIN_USER_LABEL_REQUIRED",`${u}/label`)})})}function ur(e,t){let o=R(e,t,K.adminPages),n=new Set;o.forEach((i,r)=>{let a=`${t}/${r}`,s=T(i,a);h(s,["code","kind","path","label","navigationEligible","capability","access","resourceCode","viewCode","routeCode"],a,!0);let c=$(s.code,`${a}/code`,255);n.has(c)&&f("NATIVE_ADMIN_PAGE_DUPLICATE",`${a}/code`),n.add(c);let u=$(s.kind,`${a}/kind`,64);if(["resource-list","resource-detail","resource-create","resource-update","operation"].includes(u)||f("NATIVE_ADMIN_PAGE_KIND_INVALID",`${a}/kind`),fe(s.path,`${a}/path`),$(s.label,`${a}/label`,255),Be(s.navigationEligible,`${a}/navigationEligible`),s.capability!==void 0&&s.access!==void 0&&f("NATIVE_ROUTE_ACCESS_CONFLICT",`${a}/access`),s.capability!==void 0&&$(s.capability,`${a}/capability`,255),s.access!==void 0){let _=T(s.access,`${a}/access`);h(_,["allOf","anyOf"],`${a}/access`,!0);for(let d of["allOf","anyOf"])_[d]!==void 0&&P(_[d],`${a}/access/${d}`,50)}for(let _ of["resourceCode","viewCode","routeCode"])s[_]!==void 0&&w(s[_],`${a}/${_}`)})}function fr(e,t){let o=R(e,t,K.adminNavigationGroups),n=0;o.forEach((i,r)=>{let a=`${t}/${r}`,s=T(i,a);h(s,["code","label","icon","order","items"],a,!0),w(s.code,`${a}/code`),$(s.label,`${a}/label`,255),St(s.icon,`${a}/icon`),Z(s.order,`${a}/order`,-1e4,1e4);let c=R(s.items,`${a}/items`,500);c.length===0&&f("NATIVE_ADMIN_GROUP_ORPHANED",`${a}/items`),n+=c.length,n>K.adminNavigationItems&&f("NATIVE_ARRAY_LIMIT_EXCEEDED",t),c.forEach((u,_)=>{let d=`${a}/items/${_}`,p=T(u,d);h(p,["pageCode","label","icon","order"],d,!0),$(p.pageCode,`${d}/pageCode`,255),p.label!==void 0&&$(p.label,`${d}/label`,255),St(p.icon,`${d}/icon`),Z(p.order,`${d}/order`,-1e4,1e4)})})}var pr=new Set(["application-todo-center","workflow-work-center","workflow-launch","workflow-task","workflow-instance","resource-records","resource-submit"]);function _r(e,t,o){let n=T(e,t);h(n,["schemaVersion","appCode","devicePolicy","rootEntry","authentication","routes","digest"],t),x(n.schemaVersion,So,`${t}/schemaVersion`),x(n.appCode,o,`${t}/appCode`),Rn(n.devicePolicy,`${t}/devicePolicy`),Er(n.rootEntry,`${t}/rootEntry`),Ar(n.authentication,`${t}/authentication`),yn(n.digest,`${t}/digest`);let i=R(n.routes,`${t}/routes`,K.routes),r=new Set;i.forEach((a,s)=>{let c=`${t}/routes/${s}`,u=T(a,c),_=u.kind==="resource-records"||u.kind==="resource-submit";h(u,["code","kind","desktop","mobile"],c,["workflowCode",..._?["resourceCode"]:[]]);let d=$(u.code,`${c}/code`,255);r.has(d)&&f("NATIVE_ROUTE_MANIFEST_DUPLICATE",`${c}/code`),r.add(d);let p=$(u.kind,`${c}/kind`,64);if(pr.has(p)||f("NATIVE_ROUTE_MANIFEST_KIND_INVALID",`${c}/kind`),u.workflowCode!==void 0&&w(u.workflowCode,`${c}/workflowCode`),_){let E=z(u.resourceCode,`${c}/resourceCode`);x(d,`user.${E}.${u.kind==="resource-records"?"records":"submit"}`,`${c}/code`)}else u.resourceCode!==void 0&&f("NATIVE_PROPERTY_UNKNOWN",`${c}/resourceCode`);let I=Ao(u.desktop,`${c}/desktop`,o),l=Ao(u.mobile,`${c}/mobile`,o);I.surface!=="user"&&f("NATIVE_ROUTE_MANIFEST_DESKTOP_SURFACE_INVALID",`${c}/desktop/surface`),l.surface!=="user"&&f("NATIVE_ROUTE_MANIFEST_MOBILE_SURFACE_INVALID",`${c}/mobile/surface`),I.routeCode===l.routeCode&&f("NATIVE_ROUTE_MANIFEST_PAIR_DUPLICATE",c)}),x(n.digest,ee({schemaVersion:n.schemaVersion,appCode:n.appCode,devicePolicy:n.devicePolicy,rootEntry:n.rootEntry,authentication:n.authentication,routes:n.routes}),`${t}/digest`)}function Rn(e,t){let o=T(e,t);h(o,["kind","mobileMaxWidthPx","desktopMinWidthPx"],t),x(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&&f("NATIVE_FRONTEND_DEVICE_POLICY_INVALID",t),{kind:"viewport-family",mobileMaxWidthPx:n,desktopMinWidthPx:i}}function Er(e,t){let o=T(e,t);h(o,["code","desktop","mobile"],t);let n=w(o.code,`${t}/code`),i=On(o.desktop,`${t}/desktop`),r=On(o.mobile,`${t}/mobile`);return(i===r||r==="/"||!r.startsWith("/m/"))&&f("NATIVE_ROUTE_MANIFEST_ROOT_ENTRY_INVALID",t),i.startsWith("/m/")&&f("NATIVE_ROUTE_MANIFEST_ROOT_ENTRY_INVALID",`${t}/desktop`),{code:n,desktop:i,mobile:r}}function Ar(e,t){let o=T(e,t);h(o,["desktop","mobile"],t);let n=Eo(o.desktop,`${t}/desktop`,!1),i=Eo(o.mobile,`${t}/mobile`,!0);return(n.routeCode===i.routeCode||n.path===i.path)&&f("NATIVE_ROUTE_MANIFEST_AUTHENTICATION_DUPLICATE",t),{desktop:n,mobile:i}}function Eo(e,t,o){let n=T(e,t);h(n,["routeCode","path"],t);let i=w(n.routeCode,`${t}/routeCode`),r=On(n.path,`${t}/path`);return(o?!r.startsWith("/m/"):r.startsWith("/m/"))&&f("NATIVE_ROUTE_MANIFEST_AUTHENTICATION_PATH_INVALID",`${t}/path`),{routeCode:i,path:r}}function On(e,t){let o=fe(e,t);return/[:*?#\\\\]/.test(o)&&f("NATIVE_ROUTE_MANIFEST_STATIC_PATH_INVALID",t),o}function Ao(e,t,o){let n=T(e,t);h(n,["routeCode","path","surface","pathParams","requiresAuthentication"],t,["capability","access"]),w(n.routeCode,`${t}/routeCode`);let i=fe(n.path,`${t}/path`),r=$(n.surface,`${t}/surface`,16);["admin","user"].includes(r)||f("NATIVE_ROUTE_SURFACE_INVALID",`${t}/surface`);let a=P(n.pathParams,`${t}/pathParams`,8);return a.forEach((s,c)=>{(!/^[A-Za-z][A-Za-z0-9_]*$/.test(s)||s.length>64)&&f("NATIVE_ROUTE_PATH_PARAM_INVALID",`${t}/pathParams/${c}`)}),Q(a)!==Q(jo(i))&&f("NATIVE_ROUTE_PATH_PARAMS_MISMATCH",`${t}/pathParams`),$n(n,t,o),n.requiresAuthentication!==!0&&f("NATIVE_ROUTE_AUTHENTICATION_REQUIRED",`${t}/requiresAuthentication`),n}function jo(e){return M([...e.matchAll(/:([A-Za-z][A-Za-z0-9_]*)/g)].map(t=>t[1]))}function mo(e,t,o,n){return{routeCode:e,path:t,surface:o,pathParams:jo(t),...n?.capability?{capability:n.capability}:{},...n?.access?{access:n.access}:{},requiresAuthentication:!0}}function Io(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 mr(e){let t=e.appCode,o=[],n=(I,l,E,N,g,A,m)=>{o.push({code:I,kind:l,...g?{workflowCode:g}:{},...m?{resourceCode:m}:{},desktop:mo(Io(l,"desktop",g,m),E,"user",A),mobile:mo(Io(l,"mobile",g,m),N,"user",A)})};e.frontend.user.applicationTodoCenter===!0&&n("application:todo-center","application-todo-center","/todos","/m/todos");let i=Uo(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 I of i){if(!["standalone","hidden-handoff"].includes(I.launch.mode))continue;let l=M([I.launch.submission?.create?.requiredCapability,I.launch.submission?.existing?.requiredCapability].filter(E=>!!E));n(`workflow:${I.code}:launch`,"workflow-launch","/workflows/:workflowCode/start","/m/workflows/:workflowCode/start",I.code,l.length===1?{capability:l[0]}:l.length>1?{access:{anyOf:l}}:void 0)}let r=o.sort((I,l)=>ce(String(I.code),String(l.code))),a=Vt(e),s=I=>{let l=I==="mobile"?"/m/":"/",E=a.filter(g=>g.surface==="user"&&!/[:*?#\\\\]/.test(g.path)&&g.path===l).sort((g,A)=>ce(g.code,A.code))[0];if(E)return{code:E.code,path:E.path};let N=a.filter(g=>g.surface==="user"&&!/[:*?#\\\\]/.test(g.path)&&(I==="mobile"?g.path.startsWith("/m/"):!g.path.startsWith("/m/"))).sort((g,A)=>ce(g.code,A.code))[0];return N?{code:N.code,path:N.path}:{code:I==="mobile"?"application-root-mobile":"application-root",path:l}},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"}},u=Rn(e.frontend.devicePolicy,"/config/frontend/devicePolicy"),_=s("desktop"),d=s("mobile"),p={schemaVersion:So,appCode:t,devicePolicy:u,rootEntry:{code:_.code,desktop:_.path,mobile:d.path},authentication:c,routes:r};return{...p,digest:ee(p)}}function St(e,t){if(e===void 0)return;let o=$(e,t,32);Vs.has(o)||f("NATIVE_ADMIN_ICON_INVALID",t)}function go(e,t){e!==void 0&&Z(e,t,-1e4,1e4)}function $n(e,t,o){return e.capability!==void 0&&e.access!==void 0&&f("NATIVE_ROUTE_ACCESS_CONFLICT",`${t}/access`),e.capability!==void 0?{capability:Ce(e.capability,`${t}/capability`,o)}:e.access===void 0?{}:{access:wt(e.access,`${t}/access`,o)}}function wt(e,t,o){let n=T(e,t);h(n,["allOf","anyOf"],t,!0);let i=n.allOf===void 0?void 0:M(P(n.allOf,`${t}/allOf`,50).map((a,s)=>Ce(a,`${t}/allOf/${s}`,o))),r=n.anyOf===void 0?void 0:M(P(n.anyOf,`${t}/anyOf`,50).map((a,s)=>Ce(a,`${t}/anyOf/${s}`,o)));return(i?.length||0)+(r?.length||0)===0&&f("NATIVE_ROUTE_ACCESS_EMPTY",t),{...i===void 0?{}:{allOf:i},...r===void 0?{}:{anyOf:r}}}function Uo(e){let t=new Map(Fo(e).map(i=>[String(i.code),i])),o=e.workflows.definitions.map((i,r)=>{let a=`/config/workflows/definitions/${r}`,s=T(i,a);h(s,["version","definition","launch"],a,["detailRouteCode"]);let c=T(s.definition,`${a}/definition`),u=s.detailRouteCode===void 0?void 0:Wo(s.detailRouteCode,`${a}/detailRouteCode`);return{code:w(c.code,`${a}/definition/code`),title:$(c.title,`${a}/definition/title`,255),version:We(s.version,`${a}/version`),launch:Ir(e,c,s.launch,`${a}/launch`,t),...u?{detailRouteCode:u}:{},definition:c}});return M(o.map(i=>i.code)).map(i=>{let r=o.filter(u=>u.code===i),a=e.workflows.activations.find(u=>u.workflowCode===i)?.definitionVersion,s=r.find(u=>u.version===a)||[...r].sort((u,_)=>_.version-u.version)[0],c=new Set;for(let u of r){let _=T(u.definition.nodes,"/config/workflows/definitions/nodes");for(let d of Object.values(_)){let p=T(d,"/config/workflows/definitions/nodes/*");if(p.kind==="approval")for(let I of P(p.allowedOperations||[],"/config/workflows/definitions/nodes/*/allowedOperations",20))c.add(I)}}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:Ro(r.map(u=>u.version)),bindingVersions:Ro(e.workflows.bindings.map((u,_)=>{let d=`/config/workflows/bindings/${_}`,p=T(u,d),I=T(p.binding,`${d}/binding`);return{code:w(I.workflowCode,`${d}/binding/workflowCode`),version:We(p.version,`${d}/version`)}}).filter(u=>u.code===i).map(u=>u.version)),providerCodes:M(e.workflows.providers.map((u,_)=>w(T(u,`/config/workflows/providers/${_}`).code,`/config/workflows/providers/${_}/code`))),allowedOperations:[...c].sort(ce),editableParameterCodes:M(e.workflows.editableParameters.map((u,_)=>{let d=`/config/workflows/editableParameters/${_}`,p=T(u,d);return{code:w(p.code,`${d}/code`),workflowCode:w(p.workflowCode,`${d}/workflowCode`)}}).filter(u=>u.workflowCode===i).map(u=>u.code))}})}function Mo(e,t){let o=T(e,t);h(o,["mode"],t,["submission"]);let n=$(o.mode,`${t}/mode`,32);return["standalone","custom-page","hidden-handoff","work-center-only"].includes(n)||f("NATIVE_WORKFLOW_LAUNCH_MODE_INVALID",`${t}/mode`),{mode:n,...o.submission===void 0?{}:{submission:T(o.submission,`${t}/submission`)}}}function Ir(e,t,o,n,i){let r=Mo(o,n);if(!r.submission)return{mode:r.mode};["standalone","hidden-handoff"].includes(r.mode)||f("NATIVE_WORKFLOW_NAMED_OPERATION_SUBMISSION_INVALID",`${n}/submission`);let a=T(r.submission,`${n}/submission`);h(a,["kind"],`${n}/submission`,["create","existing","context"]),x(a.kind,"named-operation",`${n}/submission/kind`);let s=n.endsWith("/launch")?n.slice(0,-7):n,c=T(t.subject,`${s}/definition/subject`),u=z(c.resourceCode,`${s}/definition/subject/resourceCode`),_=e.data.resources.findIndex(C=>C.code===u),d=e.data.resources[_];(_<0||!d)&&f("NATIVE_WORKFLOW_SUBJECT_RESOURCE_MISSING",`${s}/definition/subject/resourceCode`);let p=new Set(T(d.schema,`/config/data/resources/${_}/schema`).fields.map(C=>String(C.code))),I=new Map(e.backend.operations.map(C=>[String(C.code),C])),l=(C,y)=>{let S=`${n}/submission/${y}`,v=T(C,S);h(v,["operationCode","inputs","output"],S);let F=w(v.operationCode,`${S}/operationCode`),B=I.get(F),U=i.get(F),pe=U?.platformAccess?.workflow?.codes;(!B||!U||U.method!=="POST"||!Array.isArray(pe)||!pe.includes(t.code))&&f("NATIVE_WORKFLOW_NAMED_OPERATION_INVALID",S);let _e=T(B.requestSchema,`${S}/operation/requestSchema`),Y=T(_e.properties,`${S}/operation/requestSchema/properties`),Ie=new Set(_e.required===void 0?[]:P(_e.required,`${S}/operation/requestSchema/required`,64)),se=T(v.inputs,`${S}/inputs`),V=Object.entries(se);(!V.length||V.length>64)&&f("NATIVE_WORKFLOW_NAMED_OPERATION_INPUT_INVALID",`${S}/inputs`);let j=new Set,L=new Map,G={};for(let[q,H]of V){(!fo.test(q)||!Object.prototype.hasOwnProperty.call(Y,q))&&f("NATIVE_WORKFLOW_NAMED_OPERATION_INPUT_INVALID",`${S}/inputs/${q}`);let De=`${S}/inputs/${q}`,Pt=T(H,De),ye=$(Pt.source,`${De}/source`,32);if(["field","idempotency-key","current-user-reference","subject-id","subject-revision","requested-at"].includes(ye)||f("NATIVE_WORKFLOW_NAMED_OPERATION_INPUT_INVALID",De),h(Pt,["source"],De,ye==="field"?["fieldCode"]:!1),L.set(ye,(L.get(ye)||0)+1),ye==="field"){let et=W(Pt.fieldCode,`${De}/fieldCode`);(j.has(et)||!p.has(et))&&f("NATIVE_WORKFLOW_NAMED_OPERATION_INPUT_INVALID",`${De}/fieldCode`),j.add(et),G[q]={source:ye,fieldCode:et}}else G[q]={source:ye}}([...Ie].some(q=>!(q in se))||(L.get("idempotency-key")||0)!==1||!V.some(([q,H])=>T(H,`${S}/inputs/${q}`).source==="idempotency-key"&&Ie.has(q))||y==="create"&&((L.get("subject-id")||0)>0||(L.get("subject-revision")||0)>0)||y==="existing"&&((L.get("subject-id")||0)!==1||(L.get("subject-revision")||0)!==1))&&f("NATIVE_WORKFLOW_NAMED_OPERATION_INPUT_INVALID",`${S}/inputs`);let J=T(v.output,`${S}/output`);h(J,["subjectId"],`${S}/output`,["subjectRevision","processCommand"]);let ge=T(T(B.responseSchema,`${S}/operation/responseSchema`).properties,`${S}/operation/responseSchema/properties`);for(let q of["subjectId","subjectRevision","processCommand"]){if(J[q]===void 0)continue;let H=$(J[q],`${S}/output/${q}`,128);(!fo.test(H)||!Object.prototype.hasOwnProperty.call(ge,H))&&f("NATIVE_WORKFLOW_NAMED_OPERATION_OUTPUT_INVALID",`${S}/output/${q}`)}return{operationCode:F,method:"POST",path:U.path,requiredCapability:U.requiredCapability,requestSchemaDigest:U.requestSchemaDigest,responseSchemaDigest:U.responseSchemaDigest,inputs:G,output:{...J},fieldCodes:j}},E=a.create===void 0?void 0:l(a.create,"create"),N=a.existing===void 0?void 0:l(a.existing,"existing");!E&&!N&&f("NATIVE_WORKFLOW_NAMED_OPERATION_SUBMISSION_INVALID",`${n}/submission`);let g=new Set([...E?.fieldCodes||[],...N?.fieldCodes||[]]),A=a.context===void 0?[]:R(a.context,`${n}/submission/context`,16),m=new Set,O=A.map((C,y)=>{let S=`${n}/submission/context/${y}`,v=T(C,S);h(v,["queryParameter","fieldCode"],S);let F=$(v.queryParameter,`${S}/queryParameter`,64),B=W(v.fieldCode,`${S}/fieldCode`);return(!/^[A-Za-z][A-Za-z0-9]{0,63}$/.test(F)||m.has(F)||!g.has(B))&&f("NATIVE_WORKFLOW_LAUNCH_CONTEXT_INVALID",S),m.add(F),{queryParameter:F,fieldCode:B}}),b=C=>{let{fieldCodes:y,...S}=C;return S};return{mode:r.mode,submission:{kind:"named-operation",...E?{create:b(E)}:{},...N?{existing:b(N)}:{},context:O}}}function Wo(e,t){let o=T(e,t);h(o,["desktop","mobile"],t);let n=w(o.desktop,`${t}/desktop`),i=w(o.mobile,`${t}/mobile`);return n===i&&f("NATIVE_WORKFLOW_DETAIL_ROUTE_DUPLICATE",t),{desktop:n,mobile:i}}function gr(e,t){let o=new Set(t.map(_=>_.code)),n=new Map;e.data.resources.forEach((_,d)=>{let p=`/config/data/resources/${d}`,I=T(_,p);for(let[N,g]of Object.entries(I.fieldPolicies||{})){if(!we(N))continue;let A=`${p}/fieldPolicies/${N}/read`,m=T(g,`${p}/fieldPolicies/${N}`);for(let O of P(m.read||[],A,2e3))o.has(O)||f("NATIVE_CAPABILITY_REFERENCE_MISSING",A)}let l=I.surface===void 0?{}:T(I.surface,`${p}/surface`);if(["native","queued-command"].includes(l.mutationOwner||"native"))return;let E=T(I.capabilities,`${p}/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 p=`/config/authz/roles/${_}`,I=T(d,p);h(I,["code","name","description","capabilities"],p,!0);let l=w(I.code,`${p}/code`);i.has(l)&&f("NATIVE_ROLE_DUPLICATE",`${p}/code`),i.add(l),$(I.name,`${p}/name`,255);let E=P(I.capabilities,`${p}/capabilities`,2e3);for(let[N,g]of E.entries())n.has(g)&&f("NATIVE_DATA_SURFACE_MUTATION_GRANT_FORBIDDEN",`${p}/capabilities/${N}`,{operation:n.get(g)}),o.has(g)||f("NATIVE_CAPABILITY_REFERENCE_MISSING",`${p}/capabilities`)}let r=e.authz.authenticatedUserRoleCode===void 0?"":w(e.authz.authenticatedUserRoleCode,"/config/authz/authenticatedUserRoleCode");r&&!i.has(r)&&f("NATIVE_AUTHENTICATED_USER_ROLE_REFERENCE_MISSING","/config/authz/authenticatedUserRoleCode");let a=new Set,s=0;for(let[_,d]of e.perspectives.entries()){let p=`/config/perspectives/${_}`,I=T(d,p);h(I,["code","name","description","roleCodes","capabilityCodes","default"],p,!0);let l=w(I.code,`${p}/code`);a.has(l)&&f("NATIVE_PERSPECTIVE_DUPLICATE",`${p}/code`),a.add(l),$(I.name,`${p}/name`,255);let E=P(I.roleCodes,`${p}/roleCodes`,20);E.length<1&&f("NATIVE_PERSPECTIVE_ROLE_REQUIRED",`${p}/roleCodes`),E.forEach((A,m)=>{i.has(A)||f("NATIVE_PERSPECTIVE_ROLE_MISSING",`${p}/roleCodes/${m}`)});let N=M(e.authz.roles.filter(A=>E.includes(A.code)).flatMap(A=>A.capabilities)),g=P(I.capabilityCodes,`${p}/capabilityCodes`,2e3);Q(N)!==Q(g)&&f("NATIVE_PERSPECTIVE_CAPABILITY_PROJECTION_MISMATCH",`${p}/capabilityCodes`),I.default===!0?s+=1:I.default!==void 0&&f("NATIVE_PERSPECTIVE_DEFAULT_INVALID",`${p}/default`)}s>1&&f("NATIVE_PERSPECTIVE_DEFAULT_DUPLICATE","/config/perspectives");for(let[_,d]of e.backend.operations.entries()){let p=T(d,`/config/backend/operations/${_}`);o.has(p.capability)||f("NATIVE_CAPABILITY_REFERENCE_MISSING",`/config/backend/operations/${_}/capability`)}let c=new Set,u=new Set;for(let[_,d]of e.frontend.routes.entries()){let p=`/config/frontend/routes/${_}`,I=T(d,p),l=w(I.code,`${p}/code`);c.has(l)&&f("NATIVE_ROUTE_DUPLICATE",`${p}/code`),c.add(l);let E=fe(I.path,`${p}/path`);u.has(E)&&f("NATIVE_ROUTE_PATH_DUPLICATE",`${p}/path`),u.add(E);let N=$n(I,p,e.appCode);N.capability&&!o.has(N.capability)&&f("NATIVE_CAPABILITY_REFERENCE_MISSING",`${p}/capability`);let g=I.access===void 0?void 0:T(I.access,`${p}/access`);for(let A of["allOf","anyOf"]){let m=g?.[A]===void 0?[]:R(g[A],`${p}/access/${A}`,50);for(let[O,b]of m.entries()){let C=Ce(b,`${p}/access/${A}/${O}`,e.appCode);o.has(C)||f("NATIVE_CAPABILITY_REFERENCE_MISSING",`${p}/access/${A}/${O}`)}}}if(e.frontend.admin.access!==void 0){let _=wt(e.frontend.admin.access,"/config/frontend/admin/access",e.appCode);for(let d of["allOf","anyOf"])for(let[p,I]of(_[d]||[]).entries())o.has(I)||f("NATIVE_CAPABILITY_REFERENCE_MISSING",`/config/frontend/admin/access/${d}/${p}`)}for(let[_,d]of e.frontend.routes.entries()){let p=T(d,`/config/frontend/routes/${_}`);p.parentCode&&!c.has(p.parentCode)&&f("NATIVE_ROUTE_PARENT_MISSING",`/config/frontend/routes/${_}/parentCode`)}}function Nr(e){let t=new Set(e.authz.roles.map(u=>String(u.code))),o=e.authz.authenticatedUserRoleCode===void 0?"":w(e.authz.authenticatedUserRoleCode,"/config/authz/authenticatedUserRoleCode"),n=new Map(e.authz.scopeDimensions.map(u=>[String(u.code),{valueType:u.valueType==="uuid"?"uuid":"string",...u.valueSource?.resourceCode?{valueSourceResourceCode:String(u.valueSource.resourceCode)}:{}}])),i=new Set(n.keys()),r=new Map(e.data.resources.map((u,_)=>{let d=Se(u,`/config/data/resources/${_}`,e.appCode);return[d.code,new Map(d.schema.fields.map(p=>[String(p.code),p]))]}));for(let[u,_]of e.authz.scopeDimensions.entries()){let d=`/config/authz/scopeDimensions/${u}`,p=T(_,d);if(h(p,["code","name","resourceCode","valueType","hierarchyMode","valueSource"],d,!0),p.valueSource===void 0)continue;let I=T(p.valueSource,`${d}/valueSource`);h(I,["kind","resourceCode","labelField","enabledField"],`${d}/valueSource`,!0),I.kind!=="native_resource"&&f("NATIVE_SCOPE_VALUE_SOURCE_KIND_INVALID",`${d}/valueSource/kind`),p.valueType!=="uuid"&&f("NATIVE_SCOPE_VALUE_SOURCE_TYPE_INVALID",`${d}/valueType`);let l=z(I.resourceCode,`${d}/valueSource/resourceCode`),E=r.get(l);E||f("NATIVE_SCOPE_VALUE_SOURCE_RESOURCE_MISSING",`${d}/valueSource/resourceCode`);let N=W(I.labelField,`${d}/valueSource/labelField`);if(["text.short","text.long"].includes(String(E.get(N)?.type||""))||f("NATIVE_SCOPE_VALUE_SOURCE_LABEL_FIELD_INVALID",`${d}/valueSource/labelField`),I.enabledField!==void 0){let g=W(I.enabledField,`${d}/valueSource/enabledField`);E.get(g)?.type!=="boolean"&&f("NATIVE_SCOPE_VALUE_SOURCE_ENABLED_FIELD_INVALID",`${d}/valueSource/enabledField`)}}let a=new Set,s=new Set;for(let[u,_]of e.authz.scopeSources.entries()){let d=`/config/authz/scopeSources/${u}`,p=T(_,d);h(p,["code","name","resourceCode","subject","grants","operationField","enabledField","effectiveFromField","effectiveToField","failureMode"],d,!0);let I=w(p.code,`${d}/code`);a.has(I)&&f("NATIVE_SCOPE_SOURCE_DUPLICATE",`${d}/code`),a.add(I),$(p.name,`${d}/name`,255);let l=z(p.resourceCode,`${d}/resourceCode`),E=r.get(l);E||f("NATIVE_SCOPE_SOURCE_RESOURCE_MISSING",`${d}/resourceCode`);let N=T(p.subject,`${d}/subject`),g=$(N.type,`${d}/subject/type`,32);h(N,g==="role_membership"?["type","userIdField","roleCode"]:["type","userIdField"],`${d}/subject`),["user","role_membership"].includes(g)||f("NATIVE_SCOPE_SOURCE_SUBJECT_INVALID",`${d}/subject/type`);let A=ke(N.userIdField,E);It(A)||f("NATIVE_SCOPE_SOURCE_SUBJECT_PATH_INVALID",`${d}/subject/userIdField`),g==="role_membership"&&!t.has(String(N.roleCode))&&f("NATIVE_ROLE_REFERENCE_MISSING",`${d}/subject/roleCode`);let m=new Set;for(let[O,b]of R(p.grants,`${d}/grants`,100).entries()){let C=`${d}/grants/${O}`,y=T(b,C);h(y,["dimensionCode","valueField","parentValueField"],C,!0);let S=w(y.dimensionCode,`${C}/dimensionCode`);(!i.has(S)||m.has(S))&&f("NATIVE_SCOPE_SOURCE_DIMENSION_INVALID",`${C}/dimensionCode`),m.add(S),p.failureMode==="last_known_good"&&s.add(S);for(let v of["valueField","parentValueField"]){if(y[v]===void 0)continue;let F=ke(y[v],E);an(F,n.get(S),r)||f("NATIVE_SCOPE_SOURCE_GRANT_PATH_INVALID",`${C}/${v}`)}}m.size===0&&f("NATIVE_SCOPE_SOURCE_GRANT_REQUIRED",`${d}/grants`),["strict","last_known_good"].includes(p.failureMode)||f("NATIVE_SCOPE_SOURCE_FAILURE_MODE_INVALID",`${d}/failureMode`);for(let O of["operationField","enabledField","effectiveFromField","effectiveToField"]){if(p[O]===void 0)continue;let b=W(p[O],`${d}/${O}`);E.has(b)||f("NATIVE_SCOPE_SOURCE_FIELD_MISSING",`${d}/${O}`)}}br(e,t,r,o);let c=new Set;for(let[u,_]of e.authz.dataPolicies.entries()){let d=`/config/authz/dataPolicies/${u}`,p=T(_,d);h(p,["code","name","resourceCode","unrestrictedRoleCodes","operations","matchMode","rules","readExpression","writeBoundary"],d,!0);let I=w(p.code,`${d}/code`);c.has(I)&&f("NATIVE_DATA_POLICY_DUPLICATE",`${d}/code`),c.add(I);let l=p.readExpression!==void 0,E=P(p.operations||[],`${d}/operations`,4);p.operations!==void 0&&(E.length===0||E.some(b=>!["read","create","update","delete"].includes(b)))&&f("NATIVE_DATA_POLICY_OPERATIONS_INVALID",`${d}/operations`),["AND","OR"].includes(p.matchMode)||f("NATIVE_DATA_POLICY_MATCH_MODE_INVALID",`${d}/matchMode`),l&&p.operations!==void 0&&f("NATIVE_DATA_POLICY_READ_EXPRESSION_OPERATIONS_FORBIDDEN",`${d}/operations`);let N=e.data.resources.find(b=>b.dataPolicyCode===I),g=p.resourceCode||N?.code,A=g?r.get(z(g,`${d}/resourceCode`)):void 0;l&&!A&&f("NATIVE_DATA_POLICY_RESOURCE_MISSING",`${d}/resourceCode`);let m=P(p.unrestrictedRoleCodes||[],`${d}/unrestrictedRoleCodes`,100);p.unrestrictedRoleCodes!==void 0&&m.length===0&&f("NATIVE_DATA_POLICY_UNRESTRICTED_ROLES_INVALID",`${d}/unrestrictedRoleCodes`);for(let b of m)t.has(b)||f("NATIVE_ROLE_REFERENCE_MISSING",`${d}/unrestrictedRoleCodes`);let O;try{let b=R(p.rules,`${d}/rules`,100).map((C,y)=>({rule:T(C,`${d}/rules/${y}`),pointer:`${d}/rules/${y}`}));b.length===0?(!l||p.matchMode!=="AND"||p.writeBoundary!=="capability_only")&&f("NATIVE_DATA_POLICY_WRITE_BOUNDARY_REQUIRED",d):p.writeBoundary!==void 0&&f("NATIVE_DATA_POLICY_WRITE_BOUNDARY_INVALID",`${d}/writeBoundary`),O=[...b],l&&(O.push(...Xe(p.readExpression,`${d}/readExpression`)),Tn(p.readExpression,`${d}/readExpression`))}catch(b){throw b instanceof Ue&&f(b.code,b.pointer),b}for(let{rule:b,pointer:C}of O){h(b,["subject","dimensionCode","relationCode","resourceCode","field","roleCodes","operation","valuePath","emptyMatchesAll","operator","value","operand"],C,!0);let y=W(b.field,`${C}/field`),S=A?.get(y);l&&!S&&f("NATIVE_DATA_POLICY_FIELD_MISSING",`${C}/field`);for(let Y of P(b.roleCodes||[],`${C}/roleCodes`,100))t.has(Y)||f("NATIVE_ROLE_REFERENCE_MISSING",`${C}/roleCodes`);let v=String(b.operator||""),F=b.operand==="db_now",B=["is_null","is_not_null"].includes(v),U=["eq","not_eq","in","not_in"].includes(v),pe=!F&&(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":"",pe?"constant":"",F?"db_now":""].filter(Boolean).length!==1&&f("NATIVE_DATA_POLICY_RULE_SOURCE_INVALID",C),b.subject!==void 0&&b.subject!=="current_user"&&f("NATIVE_DATA_POLICY_SUBJECT_INVALID",`${C}/subject`),pe){if(!U&&!B&&f("NATIVE_DATA_POLICY_OPERATOR_INVALID",`${C}/operator`),["in","not_in"].includes(v)){let Y=R(b.value,`${C}/value`,100).map((Ie,se)=>$(Ie,`${C}/value/${se}`,2048));(Y.length===0||new Set(Y).size!==Y.length)&&f("NATIVE_DATA_POLICY_VALUE_INVALID",`${C}/value`)}else["eq","not_eq"].includes(v)?$(b.value,`${C}/value`,2048):(b.value!==void 0||b.operand!==void 0)&&f("NATIVE_DATA_POLICY_VALUE_INVALID",`${C}/value`);for(let Y of["operation","valuePath","emptyMatchesAll","resourceCode","operand"])b[Y]!==void 0&&f("NATIVE_DATA_POLICY_CONSTANT_RULE_INVALID",`${C}/${Y}`)}if(F){(!["lt","lte","gt","gte"].includes(v)||b.value!==void 0||S?.type!=="datetime")&&f("NATIVE_DATA_POLICY_DB_NOW_INVALID",C);for(let Y of["operation","valuePath","emptyMatchesAll","resourceCode","value"])b[Y]!==void 0&&f("NATIVE_DATA_POLICY_DB_NOW_INVALID",`${C}/${Y}`)}b.dimensionCode&&!i.has(b.dimensionCode)&&f("NATIVE_SCOPE_DIMENSION_MISSING",`${C}/dimensionCode`),s.has(String(b.dimensionCode||""))&&b.operation!=="read"&&f("NATIVE_SCOPE_SOURCE_LAST_KNOWN_GOOD_UNSAFE",`${C}/operation`)}}for(let[u,_]of e.data.resources.entries()){let d=T(_,`/config/data/resources/${u}`);d.dataPolicyCode&&!c.has(d.dataPolicyCode)&&f("NATIVE_DATA_POLICY_REFERENCE_MISSING",`/config/data/resources/${u}/dataPolicyCode`)}}function Tr(e){try{Ut(e.data.resources,"/config/data/resources")}catch(t){throw t instanceof le&&f(t.code,t.pointer),t}}function br(e,t,o,n){let i=new Set;for(let[r,a]of e.authz.roleMembershipSources.entries()){let s=`/config/authz/roleMembershipSources/${r}`,c=T(a,s);h(c,["code","name","resourceCode","userIdField","roleCode","enabledField","effectiveFromField","effectiveToField","failureMode"],s,!0);let u=w(c.code,`${s}/code`);u.length>100&&f("NATIVE_AUTHORIZATION_PROJECTION_SOURCE_CODE_INVALID",`${s}/code`),i.has(u)&&f("NATIVE_AUTHORIZATION_PROJECTION_SOURCE_DUPLICATE",`${s}/code`),i.add(u),$(c.name,`${s}/name`,255);let _=No(c.resourceCode,`${s}/resourceCode`,o);To(c.userIdField,`${s}/userIdField`,_),t.has(String(c.roleCode||""))||f("NATIVE_ROLE_REFERENCE_MISSING",`${s}/roleCode`),n&&c.roleCode===n&&f("NATIVE_AUTHENTICATED_USER_ROLE_SOURCE_CONFLICT",`${s}/roleCode`),bo(c,s,_)}for(let[r,a]of e.authz.relationshipGrantSources.entries()){let s=`/config/authz/relationshipGrantSources/${r}`,c=T(a,s);h(c,["code","name","resourceCode","subject","relationCode","targetResourceCode","resourceIdField","operations","enabledField","effectiveFromField","effectiveToField","failureMode"],s,!0);let u=w(c.code,`${s}/code`);u.length>100&&f("NATIVE_AUTHORIZATION_PROJECTION_SOURCE_CODE_INVALID",`${s}/code`),i.has(u)&&f("NATIVE_AUTHORIZATION_PROJECTION_SOURCE_DUPLICATE",`${s}/code`),i.add(u),$(c.name,`${s}/name`,255);let _=No(c.resourceCode,`${s}/resourceCode`,o),d=T(c.subject,`${s}/subject`),p=$(d.type,`${s}/subject/type`,32);h(d,p==="role_membership"?["type","userIdField","roleCode"]:["type","userIdField"],`${s}/subject`),["user","role_membership"].includes(p)||f("NATIVE_AUTHORIZATION_PROJECTION_SUBJECT_INVALID",`${s}/subject/type`),To(d.userIdField,`${s}/subject/userIdField`,_),p==="role_membership"&&!t.has(String(d.roleCode||""))&&f("NATIVE_ROLE_REFERENCE_MISSING",`${s}/subject/roleCode`),w(c.relationCode,`${s}/relationCode`);let I=z(c.targetResourceCode,`${s}/targetResourceCode`);o.has(I)||f("NATIVE_AUTHORIZATION_PROJECTION_TARGET_RESOURCE_MISSING",`${s}/targetResourceCode`);let l=ke(c.resourceIdField,_),E=l?.field.type==="resource-ref.single"&&l.valuePath==="value"&&l.field.source?.resourceCode===I;(c.resourceIdField==="id"?I!==String(c.resourceCode):!E)&&f("NATIVE_AUTHORIZATION_PROJECTION_RESOURCE_ID_FIELD_INVALID",`${s}/resourceIdField`);let N=P(c.operations,`${s}/operations`,20);(N.length===0||N.some(g=>g.length>64||!/^[A-Za-z0-9][A-Za-z0-9:._*-]{0,63}$/.test(g)))&&f("NATIVE_AUTHORIZATION_PROJECTION_OPERATIONS_INVALID",`${s}/operations`),bo(c,s,_)}}function No(e,t,o){let n=z(e,t),i=o.get(n);return i||f("NATIVE_AUTHORIZATION_PROJECTION_RESOURCE_MISSING",t),i}function To(e,t,o){let n=ke(e,o);It(n)||f("NATIVE_AUTHORIZATION_PROJECTION_USER_FIELD_INVALID",t)}function bo(e,t,o){if(e.failureMode!=="strict"&&f("NATIVE_AUTHORIZATION_PROJECTION_FAILURE_MODE_INVALID",`${t}/failureMode`),e.enabledField!==void 0){let n=W(e.enabledField,`${t}/enabledField`);o.get(n)?.type!=="boolean"&&f("NATIVE_AUTHORIZATION_PROJECTION_ENABLED_FIELD_INVALID",`${t}/enabledField`)}for(let n of["effectiveFromField","effectiveToField"]){if(e[n]===void 0)continue;let i=W(e[n],`${t}/${n}`);["date","datetime"].includes(String(o.get(i)?.type))||f("NATIVE_AUTHORIZATION_PROJECTION_EFFECTIVE_FIELD_INVALID",`${t}/${n}`)}}function Cr(e){let t=new Set,o=new Set;e.forEach((n,i)=>{let r=`/config/backend/secrets/${i}`,a=T(n,r);h(a,["name","env","description","required","exposure"],r,!0);let s=$(a.name,`${r}/name`,128),c=$(a.env,`${r}/env`,128);Cs.test(s)||f("NATIVE_SECRET_NAME_INVALID",`${r}/name`),(!Os.test(c)||c.startsWith("OPENXIANGDA_")||["NODE_ENV","PORT"].includes(c))&&f("NATIVE_SECRET_ENV_INVALID",`${r}/env`),t.has(s)&&f("NATIVE_SECRET_NAME_DUPLICATE",`${r}/name`),o.has(c)&&f("NATIVE_SECRET_ENV_DUPLICATE",`${r}/env`),t.add(s),o.add(c),x(a.exposure,"active_only",`${r}/exposure`),a.required!==void 0&&Be(a.required,`${r}/required`),a.description!==void 0&&Sn(a.description,`${r}/description`,2e3)})}function Or(e){let t=new Set,o=new Map,n=new Map(e.data.resources.map(p=>[String(p.code),p])),i=new Map(e.frontend.routes.map((p,I)=>{let l=T(p,`/config/frontend/routes/${I}`);return[w(l.code,`/config/frontend/routes/${I}/code`),l]}));for(let[p,I]of e.workflows.definitions.entries()){let l=`/config/workflows/definitions/${p}`,E=T(I,l);if(h(E,["version","definition","launch"],l,["detailRouteCode"]),Mo(E.launch,`${l}/launch`),E.detailRouteCode!==void 0){let m=Wo(E.detailRouteCode,`${l}/detailRouteCode`);for(let[O,b,C]of[["desktop",m.desktop,["admin","user"]],["mobile",m.mobile,["user"]]]){let y=`${l}/detailRouteCode/${O}`,S=i.get(b);S||f("NATIVE_WORKFLOW_DETAIL_ROUTE_MISSING",y),C.some(B=>B===S.surface)||f("NATIVE_WORKFLOW_DETAIL_ROUTE_SURFACE_INVALID",y);let v=fe(S.path,y),F=[...v.matchAll(/:([A-Za-z][A-Za-z0-9_]*)/g)].map(B=>B[1]);(v.includes("*")||F.length!==1||F[0]!=="instanceId")&&f("NATIVE_WORKFLOW_DETAIL_ROUTE_PATH_INVALID",y)}}let N=T(E.definition,`${l}/definition`),g=`${N.code}:${We(E.version,`${l}/version`)}`;t.has(g)&&f("NATIVE_WORKFLOW_DEFINITION_DUPLICATE",l),t.add(g),hr(N,`${l}/definition`),yr(N.subject,n,`${l}/definition/subject`);let A=_n(N,{appCode:e.appCode,capabilities:e.authz.capabilities.map(m=>m.code),fields:new Map((n.get(N.subject.resourceCode)?.schema.fields||[]).map(m=>[m.code,m]))});A.length&&f("NATIVE_WORKFLOW_INSTANCE_COMMAND_POLICY_INVALID",`${l}/definition/instanceCommands`,{errors:A}),N.title===N.code&&f("NATIVE_WORKFLOW_USER_TITLE_REQUIRED",`${l}/definition/title`),o.set(g,N)}let r=new Set,a=new Map;for(let[p,I]of e.workflows.bindings.entries()){let l=T(I,`/config/workflows/bindings/${p}`),E=T(l.binding,`/config/workflows/bindings/${p}/binding`),N=`${E.workflowCode}:${We(l.version,`/config/workflows/bindings/${p}/version`)}`;r.has(N)&&f("NATIVE_WORKFLOW_BINDING_DUPLICATE",`/config/workflows/bindings/${p}`),r.add(N),Rr(E,`/config/workflows/bindings/${p}/binding`),a.set(N,E)}let s=new Set,c=new Map;for(let[p,I]of e.workflows.activations.entries()){let l=`/config/workflows/activations/${p}`,E=T(I,l);h(E,["workflowCode","definitionVersion","bindingVersion","acceptedCommandDeactivationPolicy"],l,["environmentKey"]);let N=w(E.workflowCode,`${l}/workflowCode`);s.has(N)&&f("NATIVE_WORKFLOW_ACTIVATION_DUPLICATE",l),s.add(N);let g=`${N}:${We(E.definitionVersion,`${l}/definitionVersion`)}`,A=`${N}:${We(E.bindingVersion,`${l}/bindingVersion`)}`;t.has(g)||f("NATIVE_WORKFLOW_DEFINITION_REFERENCE_MISSING",`${l}/definitionVersion`),r.has(A)||f("NATIVE_WORKFLOW_BINDING_REFERENCE_MISSING",`${l}/bindingVersion`);let m=o.get(g),O=a.get(A),b=Ot(m,O);b.length&&f(b[0],l),(!["finish-pinned","cancel-on-deactivate"].includes(E.acceptedCommandDeactivationPolicy)||E.acceptedCommandDeactivationPolicy!==m.acceptedCommandDeactivationPolicy)&&f("NATIVE_WORKFLOW_COMMAND_DEACTIVATION_POLICY_MISMATCH",`${l}/acceptedCommandDeactivationPolicy`),$r(m,O,`/config/workflows/activations/${p}`),c.set(N,O)}let u=new Set;e.workflows.providers.forEach((p,I)=>{let l=`/config/workflows/providers/${I}`,E=T(p,l);h(E,["code","endpointPath","timeoutMs"],l,!0);let N=w(E.code,`${l}/code`);u.has(N)&&f("NATIVE_WORKFLOW_PROVIDER_DUPLICATE",`${l}/code`),u.add(N),fe(E.endpointPath,`${l}/endpointPath`),E.timeoutMs!==void 0&&Z(E.timeoutMs,`${l}/timeoutMs`,100,1e4)});for(let[p,I]of c.entries())for(let[l,E]of Object.entries(T(I.bindings,"/config/workflows/bindings/*/binding/bindings"))){let N=T(E,`/config/workflows/${p}/bindings/${l}`);N.provider==="application_provider"&&!u.has(N.providerCode)&&f("NATIVE_WORKFLOW_PROVIDER_REFERENCE_MISSING",`/config/workflows/${p}/bindings/${l}/providerCode`)}let _=new Set(e.authz.roles.map(p=>p.code)),d=new Set;e.workflows.editableParameters.forEach((p,I)=>{let l=`/config/workflows/editableParameters/${I}`,E=T(p,l);h(E,["code","workflowCode","bindingKey","label","valueType","required","allowedRoleCodes","allowedProviderCodes","maxItems"],l,!0);let N=w(E.code,`${l}/code`);d.has(N)&&f("NATIVE_WORKFLOW_EDITABLE_PARAMETER_DUPLICATE",`${l}/code`),d.add(N);let g=Ft(E.workflowCode,`${l}/workflowCode`),A=Dn(E.bindingKey,`${l}/bindingKey`),m=c.get(g);(!m||!T(m.bindings,`${l}/bindingKey`)[A])&&f("NATIVE_WORKFLOW_EDITABLE_BINDING_MISSING",`${l}/bindingKey`),$(E.label,`${l}/label`,255),["role_code","user_ids","provider_code"].includes(E.valueType)||f("NATIVE_WORKFLOW_EDITABLE_VALUE_TYPE_INVALID",`${l}/valueType`);for(let O of P(E.allowedRoleCodes||[],`${l}/allowedRoleCodes`,100))_.has(O)||f("NATIVE_ROLE_REFERENCE_MISSING",`${l}/allowedRoleCodes`);for(let O of P(E.allowedProviderCodes||[],`${l}/allowedProviderCodes`,100))u.has(O)||f("NATIVE_WORKFLOW_PROVIDER_REFERENCE_MISSING",`${l}/allowedProviderCodes`);E.required!==void 0&&Be(E.required,`${l}/required`),E.maxItems!==void 0&&Z(E.maxItems,`${l}/maxItems`,1,200)})}function yr(e,t,o){let n=T(e,o);h(n,["resourceCode","factProjection"],o,["summaryFields"]);let i=z(n.resourceCode,`${o}/resourceCode`),r=t.get(i);r||f("NATIVE_WORKFLOW_SUBJECT_RESOURCE_MISSING",`${o}/resourceCode`);let a=new Set(R(T(r.schema,`${o}/resourceCode`).fields,`${o}/resourceCode`,500).map((u,_)=>W(T(u,`${o}/resourceCode/${_}`).code,`${o}/resourceCode/${_}`))),s=T(n.factProjection,`${o}/factProjection`),c=Object.entries(s);(c.length<1||c.length>64)&&f("NATIVE_WORKFLOW_SUBJECT_FACT_PROJECTION_INVALID",`${o}/factProjection`);for(let[u,_]of c){Rs.test(u)||f("NATIVE_WORKFLOW_SUBJECT_FACT_KEY_INVALID",`${o}/factProjection/${u}`);let d=W(_,`${o}/factProjection/${u}`);a.has(d)||f("NATIVE_WORKFLOW_SUBJECT_FIELD_MISSING",`${o}/factProjection/${u}`)}if(n.summaryFields!==void 0){let u=P(n.summaryFields,`${o}/summaryFields`,$s).map((l,E)=>W(l,`${o}/summaryFields/${E}`)),_=t.get(i),d=_.surface&&typeof _.surface=="object"&&!Array.isArray(_.surface)?_.surface:{},p=d.fields&&typeof d.fields=="object"&&!Array.isArray(d.fields)?d.fields:{},I=new Map(R(T(_.schema,`${o}/resourceCode`).fields,`${o}/resourceCode`,500).map((l,E)=>{let N=T(l,`${o}/resourceCode/${E}`);return[String(N.code),N]}));for(let[l,E]of u.entries()){let N=I.get(E),g=p[E],A=String(N?.type||""),m=N?.maxLength;(!N||N.system===!0||g&&typeof g=="object"&&!Array.isArray(g)&&g.system===!0||["id","revision","created_by","updated_by","created_at","updated_at"].includes(E)||!Ds.has(A)||A==="text.long"&&typeof m=="number"&&Number.isFinite(m)&&m>Ss)&&f("NATIVE_WORKFLOW_SUBJECT_SUMMARY_FIELDS_INVALID",`${o}/summaryFields/${l}`)}}}function hr(e,t){h(e,["schemaVersion","code","title","subject","acceptedCommandDeactivationPolicy","startAt","inputSchema","nodes"],t,["organizationContext","instanceCommands","readability"]),x(e.schemaVersion,"openxiangda.workflow-definition/v2",`${t}/schemaVersion`),Ft(e.code,`${t}/code`),$(e.title,`${t}/title`,255),["finish-pinned","cancel-on-deactivate"].includes(e.acceptedCommandDeactivationPolicy)||f("NATIVE_WORKFLOW_COMMAND_DEACTIVATION_POLICY_REQUIRED",`${t}/acceptedCommandDeactivationPolicy`);let o=T(e.nodes,`${t}/nodes`),n=Object.keys(o);(n.length===0||n.length>200)&&f("NATIVE_WORKFLOW_NODE_COUNT_INVALID",`${t}/nodes`);let i=$(e.startAt,`${t}/startAt`,128),r=mn(e);r.length&&f(r[0],`${t}/readability`);let a=Ot(e);a.length&&f(a[0],`${t}/nodes`),o[i]||f("NATIVE_WORKFLOW_START_NODE_MISSING",`${t}/startAt`);let s=new Map;for(let[d,p]of Object.entries(o)){let I=`${t}/nodes/${d}`,l=T(p,I);x(l.id,d,`${I}/id`),["approval","condition","end"].includes(l.kind)||f("NATIVE_WORKFLOW_NODE_KIND_INVALID",`${I}/kind`);let E=[];if(l.kind==="approval"){$(l.title,`${I}/title`,255),Dn(l.binding,`${I}/binding`),["single","any","all","sequence"].includes(l.mode)||f("NATIVE_WORKFLOW_APPROVAL_MODE_INVALID",`${I}/mode`),E.push($(l.onApprove,`${I}/onApprove`,128),$(l.onReject,`${I}/onReject`,128));for(let N of P(l.returnTargets||[],`${I}/returnTargets`,200))o[N]||f("NATIVE_WORKFLOW_TARGET_MISSING",`${I}/returnTargets`);for(let N of P(l.allowedOperations||[],`${I}/allowedOperations`,20))ws.has(N)||f("NATIVE_WORKFLOW_OPERATION_INVALID",`${I}/allowedOperations`)}else if(l.kind==="condition"){let N=R(l.branches,`${I}/branches`,100);N.length===0&&f("NATIVE_WORKFLOW_BRANCH_REQUIRED",`${I}/branches`),N.forEach((g,A)=>{let m=T(g,`${I}/branches/${A}`);Qe(m.when,`${I}/branches/${A}/when`,0),E.push($(m.target,`${I}/branches/${A}/target`,128))}),E.push($(l.otherwise,`${I}/otherwise`,128))}else $(l.title,`${I}/title`,255),$(l.outcome,`${I}/outcome`,128);for(let N of E)o[N]||f("NATIVE_WORKFLOW_TARGET_MISSING",I);s.set(d,E)}let c=new Set,u=new Set,_=d=>{if(u.has(d)&&f("NATIVE_WORKFLOW_CYCLE_FORBIDDEN",`${t}/nodes/${d}`),!c.has(d)){c.add(d),u.add(d);for(let p of s.get(d)||[])_(p);u.delete(d)}};_(i),c.size!==n.length&&f("NATIVE_WORKFLOW_NODE_UNREACHABLE",`${t}/nodes`)}function Qe(e,t,o){o>20&&f("NATIVE_WORKFLOW_EXPRESSION_DEPTH_EXCEEDED",t);let n=T(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)||f("NATIVE_WORKFLOW_EXPRESSION_PATH_INVALID",`${t}/path`);return}if(["eq","neq","gt","gte","lt","lte","in","contains"].includes(i)){Qe(n.left,`${t}/left`,o+1),Qe(n.right,`${t}/right`,o+1);return}if(["and","or"].includes(i)){let r=R(n.values,`${t}/values`,100);r.length===0&&f("NATIVE_WORKFLOW_EXPRESSION_EMPTY",`${t}/values`),r.forEach((a,s)=>Qe(a,`${t}/values/${s}`,o+1));return}if(["not","exists"].includes(i)){Qe(n.value,`${t}/value`,o+1);return}f("NATIVE_WORKFLOW_EXPRESSION_OPERATOR_INVALID",`${t}/op`)}}function Rr(e,t){x(e.schemaVersion,"openxiangda.workflow-binding/v2",`${t}/schemaVersion`),Ft(e.workflowCode,`${t}/workflowCode`);let o=T(e.bindings,`${t}/bindings`);Object.keys(o).length>200&&f("NATIVE_WORKFLOW_BINDING_LIMIT_EXCEEDED",`${t}/bindings`);for(let[n,i]of Object.entries(o)){Dn(n,`${t}/bindings/${n}`);let r=T(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)||f("NATIVE_WORKFLOW_BINDING_PROVIDER_INVALID",`${t}/bindings/${n}/provider`),a==="fixed_users"&&R(r.users,`${t}/bindings/${n}/users`,200).length===0&&f("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)&&w(r.roleCode,`${t}/bindings/${n}/roleCode`),a==="department_supervisor"&&$(r.departmentIdFrom,`${t}/bindings/${n}/departmentIdFrom`,255),a==="application_provider"&&w(r.providerCode,`${t}/bindings/${n}/providerCode`)}}function $r(e,t,o){x(t.workflowCode,e.code,`${o}/workflowCode`);let n=T(t.bindings,`${o}/bindings`);for(let[i,r]of Object.entries(T(e.nodes,`${o}/nodes`))){let a=T(r,`${o}/nodes/${i}`);a.kind==="approval"&&!n[a.binding]&&f("NATIVE_WORKFLOW_BINDING_REFERENCE_MISSING",`${o}/nodes/${i}/binding`)}}function Sr(e,t,o){let n=T(t.routeManifest,"/contracts/routeManifest"),i=T(e.routeManifest,"/contracts/routeManifest"),r=new Map;for(let _ of R(o.data?.resources,"/config/data/resources",100)){let d=T(_,"/config/data/resources");r.set(String(d.code||""),d)}let a=new Set(R(i.routes,"/contracts/routeManifest/routes",1e3).map(_=>String(T(_,"/contracts/routeManifest/routes").code||""))),s=[];for(let _ of R(n.routes,"/contracts/routeManifest/routes",1e3)){let d=T(_,"/contracts/routeManifest/routes"),p=String(d.kind||"");if(p!=="resource-records"&&p!=="resource-submit")continue;let I=String(d.resourceCode||""),l=r.get(I);l||f("NATIVE_ROUTE_MANIFEST_RESOURCE_UNKNOWN","/contracts/routeManifest/routes");let N=`user.${I}.${p==="resource-records"?"records":"submit"}`;x(String(d.code||""),N,"/contracts/routeManifest/routes/code");let g=p==="resource-records"?"read":"create",A=String(T(l.capabilities,"/config/data/resources/capabilities")[g]||"");for(let m of["desktop","mobile"]){let O=T(d[m],`/contracts/routeManifest/routes/${m}`),b=m==="mobile"?"/m/my/":"/my/",C=p==="resource-records"?`${b}${I}`:`${b}${I}/submit`;x(String(O.path||""),C,`/contracts/routeManifest/routes/${m}/path`),x(String(O.capability||""),A,`/contracts/routeManifest/routes/${m}/capability`),x(String(O.routeCode||""),`${N}.${m}`,`/contracts/routeManifest/routes/${m}/routeCode`)}(a.has(N)||s.some(m=>String(m.code)===N))&&f("NATIVE_ROUTE_MANIFEST_DUPLICATE","/contracts/routeManifest/routes/code"),s.push(d)}if(!s.length)return;i.routes=R([...i.routes,...s],"/contracts/routeManifest/routes",1e3).sort((_,d)=>ce(String(T(_,"x").code||""),String(T(d,"x").code||"")));let c=String(T(n.rootEntry,"x").code||"");if(s.find(_=>String(_.code)===c&&_.kind==="resource-records")){let _=T(n.rootEntry,"x");i.rootEntry={code:c,desktop:String(_.desktop||""),mobile:String(_.mobile||"")}}i.digest=ee({schemaVersion:i.schemaVersion,appCode:i.appCode,devicePolicy:i.devicePolicy,rootEntry:i.rootEntry,authentication:i.authentication,routes:i.routes})}function Se(e,t,o){let n=T(e,t);h(n,["schemaVersion","appCode","code","name","schema","surface","invariants","decimalReservationLifecycle","uniqueKeys","capabilities","dataPolicyCode","fieldPolicies"],t,!0),x(n.schemaVersion,"openxiangda.data-resource/v2",`${t}/schemaVersion`),x(n.appCode,o,`${t}/appCode`);let i=z(n.code,`${t}/code`),r=$(n.name,`${t}/name`,255),a=T(n.schema,`${t}/schema`);h(a,["fields"],`${t}/schema`);let s,c,u,_;try{u=_t(n.decimalReservationLifecycle,`${t}/decimalReservationLifecycle`),s=st(a.fields,`${t}/schema/fields`),_=un(n.uniqueKeys,s,`${t}/uniqueKeys`),c=Mt(n.invariants,s,`${t}/invariants`),lt(n.surface,s,`${t}/surface`)}catch(l){throw(l instanceof le||l instanceof he||l instanceof xe)&&f(l.code,l.pointer),l}let d=new Set(s.map(l=>l.code)),p=T(n.capabilities,`${t}/capabilities`);h(p,["read","create","update","delete"],`${t}/capabilities`);let I=T(n.fieldPolicies,`${t}/fieldPolicies`);for(let[l,E]of Object.entries(I)){!d.has(l)&&!we(l)&&f("NATIVE_DATA_FIELD_POLICY_FIELD_MISSING",`${t}/fieldPolicies/${l}`);let N=`${t}/fieldPolicies/${l}`,g=T(E,N);we(l)&&(h(g,["read"],N,!0),(!Array.isArray(g.read)||g.read.length>20||g.read.some(A=>typeof A!="string"||!A.trim())||new Set(g.read).size!==g.read.length)&&f("NATIVE_DATA_AUDIT_READ_POLICY_INVALID",`${N}/read`)),h(g,["read","create","update","mask"],N,!0),g.mask!==void 0&&!["omit","null"].includes(g.mask)&&f("NATIVE_DATA_FIELD_POLICY_MASK_INVALID",`${N}/mask`)}return{...n,code:i,name:r,schema:{fields:s},...n.invariants===void 0?{}:{invariants:c},...u?{decimalReservationLifecycle:u}:{},..._!==void 0?{uniqueKeys:_}:{},capabilities:p,fieldPolicies:I}}function Bo(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 Co(e,t,o,n){let i=e.toString("utf8"),r;try{r=JSON.parse(i)}catch{f(o,t)}let a=T(r,t);return Q(a)!==i&&f(n,t),a}function Oo(e,t){let o=0,n=(i,r,a)=>{if(o+=1,o>Ls&&f("NATIVE_ARTIFACT_NODE_LIMIT_EXCEEDED",r),a>vs&&f("NATIVE_ARTIFACT_DEPTH_LIMIT_EXCEEDED",r),typeof i=="string"){Buffer.byteLength(i)>Cn&&f("NATIVE_ARTIFACT_STRING_LIMIT_EXCEEDED",r);return}if(Array.isArray(i)){i.forEach((s,c)=>n(s,`${r}/${c}`,a+1));return}if(!(!i||typeof i!="object"))for(let[s,c]of Object.entries(i))["__proto__","prototype","constructor"].includes(s)&&f("NATIVE_ARTIFACT_DANGEROUS_KEY",`${r}/${s}`),Dr(s)&&f("NATIVE_ARTIFACT_RUNTIME_FIELD_FORBIDDEN",`${r}/${s}`),n(c,`${r}/${s}`,a+1)};n(e,t,0)}function Dr(e){return["environmentKey","environmentId","secretValue","ciphertext","oauthClient","oauthClientId","oauthClientSecret","signingSecret","kubernetesNamespace","nodePort","productionUrl"].includes(e)}function Me(e){return{value:e,digest:ee(e)}}function yo(e,t,o,n){typeof e!="string"&&!Buffer.isBuffer(e)&&!(e instanceof Uint8Array)&&f("NATIVE_ARTIFACT_BYTES_REQUIRED",o);let i=Buffer.isBuffer(e)?e:Buffer.from(e);return i.byteLength===0&&f("NATIVE_ARTIFACT_EMPTY",o),i.byteLength>t&&f(n,o),i}function ho(e,t,o,n){let i=Dt.createHash("sha256").update(e).digest("hex");Dt.timingSafeEqual(Buffer.from(i),Buffer.from(t))||f(n,o)}function T(e,t){return(!e||typeof e!="object"||Array.isArray(e))&&f("NATIVE_OBJECT_REQUIRED",t),e}function R(e,t,o){return Array.isArray(e)||f("NATIVE_ARRAY_REQUIRED",t),e.length>o&&f("NATIVE_ARRAY_LIMIT_EXCEEDED",t),e}function P(e,t,o){let n=R(e,t,o).map((i,r)=>$(i,`${t}/${r}`,255));return new Set(n).size!==n.length&&f("NATIVE_ARRAY_DUPLICATE",t),n}function $(e,t,o){return(typeof e!="string"||e.length===0||e.length>o)&&f("NATIVE_STRING_INVALID",t),e}function Sn(e,t,o){return(typeof e!="string"||e.length>o)&&f("NATIVE_STRING_INVALID",t),e}function w(e,t){let o=$(e,t,128);return gs.test(o)||f("NATIVE_CODE_INVALID",t),o}function z(e,t){let o=$(e,t,64);return Ts.test(o)||f("NATIVE_RESOURCE_CODE_INVALID",t),o}function W(e,t){let o=$(e,t,63);return bs.test(o)||f("NATIVE_FIELD_CODE_INVALID",t),o}function Ft(e,t){let o=$(e,t,128);return ys.test(o)||f("NATIVE_WORKFLOW_CODE_INVALID",t),o}function Dn(e,t){let o=$(e,t,128);return hs.test(o)||f("NATIVE_WORKFLOW_BINDING_CODE_INVALID",t),o}function Ce(e,t,o){let n=$(e,t,255);return Is.test(n)||f("NATIVE_CAPABILITY_CODE_INVALID",t),!n.startsWith(`app:${o}:`)&&!Bo(o).some(i=>i.code===n)&&f("NATIVE_CAPABILITY_APP_MISMATCH",t),n}function fe(e,t){let o=$(e,t,2048);return(!o.startsWith("/")||o.startsWith("//")||o.includes("..")||o.includes("?")||o.includes("#"))&&f("NATIVE_ABSOLUTE_PATH_INVALID",t),o}function We(e,t){return(!Number.isInteger(e)||Number(e)<1)&&f("NATIVE_POSITIVE_INTEGER_REQUIRED",t),Number(e)}function Z(e,t,o,n){return(!Number.isInteger(e)||Number(e)<o||Number(e)>n)&&f("NATIVE_INTEGER_OUT_OF_RANGE",t),Number(e)}function Be(e,t){return typeof e!="boolean"&&f("NATIVE_BOOLEAN_REQUIRED",t),e}function yn(e,t){let o=$(e,t,64).toLowerCase();return As.test(o)||f("NATIVE_DIGEST_INVALID",t),o}function x(e,t,o){e!==t&&f("NATIVE_VALUE_MISMATCH",o)}function h(e,t,o,n=!1){let i=new Set([...t,...Array.isArray(n)?n:[]]);for(let r of Object.keys(e))i.has(r)||f("NATIVE_PROPERTY_UNKNOWN",`${o}/${r}`);if(n!==!0)for(let r of t)Object.prototype.hasOwnProperty.call(e,r)||f("NATIVE_PROPERTY_REQUIRED",`${o}/${r}`)}function X(e,t){return[...e].sort((o,n)=>ce(t(o),t(n)))}function M(e){return[...new Set(e)].sort(ce)}function Ro(e){return[...new Set(e)].sort((t,o)=>t-o)}function ce(e,t){return e===t?0:e<t?-1:1}function Go(e){return!e||typeof e!="object"||Object.isFrozen(e)||(Object.freeze(e),Object.values(e).forEach(t=>Go(t))),e}function hn(e,t,o){if(bn(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(!bn(e[i],t[i]))return hn(e[i],t[i],`${o}/${i}`)}if(e&&t&&typeof e=="object"&&typeof t=="object"&&!Array.isArray(e)&&!Array.isArray(t)){let n=M([...Object.keys(e),...Object.keys(t)]);for(let i of n){let r=e[i],a=t[i];if(!bn(r,a))return hn(r,a,`${o}/${i}`)}}return o}function bn(e,t){return e===void 0||t===void 0?e===t:Q(e)===Q(t)}function f(e,t,o={}){throw new Rt(e,t,o)}var Vr="ab3888c95ba081c93144418aec5895d2a381511dc2c857a4e7e71965470025e8";0&&(module.exports={DATA_AUDIT_METADATA_FIELDS,DATA_EVENT_TYPES_V2,DATA_SYSTEM_SORT_FIELD_CODES,ManagedConcurrencyContractError,NATIVE_CONFIGURATION_VALIDATOR_DIGEST,NATIVE_CONTRACT_CAPACITY_V2,NATIVE_DATA_POLICY_EXPRESSION_MAX_CLAUSES,NATIVE_DATA_POLICY_EXPRESSION_MAX_DEPTH,NATIVE_DATA_POLICY_EXPRESSION_MAX_GROUP_ITEMS,NATIVE_DATA_POLICY_EXPRESSION_MAX_LEAVES,NATIVE_DATA_POLICY_EXPRESSION_MAX_OCCURRENCES,NATIVE_DATA_QUERY_OPERATORS_V2,NATIVE_UNIQUE_KEY_MAX_BYTES,NATIVE_UNIQUE_KEY_NORMALIZERS,NativeConfigurationCompilerError,NativeDataFieldContractV2Error,NativeDataPolicyExpressionV2Error,NativeDecimalLifecycleContractError,NativeEventActionContractError,NativeScopeSourceFieldPathV2Error,NativeUniqueKeyContractError,OPENXIANGDA_NATIVE_DATA_FIELD_TYPES_V2,OPENXIANGDA_NATIVE_DATA_SURFACE_KEYS_V2,OPENXIANGDA_NATIVE_DRAFT_STATE_KEYS_V2,OPENXIANGDA_NATIVE_SYSTEM_FIELDS_V2,OPENXIANGDA_NATIVE_SYSTEM_FIELD_MAP_V2,WORKFLOW_CONFIGURABLE_OPERATIONS,WORKFLOW_CONFIGURABLE_PROVIDERS,WORKFLOW_EVENT_TYPES_V2,compileNativeApplicationConfiguration,compileNativeEventAction,compileNativeEventCapturePlansV2,compileRequiredPlatformCapabilitiesV3,formatWorkflowExpression,hasDataAuditReadPolicy,isDataAuditMetadataField,isDataSystemSortField,isNativeDataQueryOperatorV2,isNativeMultiValueFieldV2,materializeNativeDataQueryPathTypesV2,nativeDataPolicyExpressionLeavesV2,nativeDataPolicyExpressionToCnfV2,nativeDataQueryPathPlanV2,nativeFieldAggregatePlanV2,nativeFieldColumnDefinitionV2,nativeFieldDefaultSqlV2,nativeFieldHasDefaultV2,nativeFieldIndexStatementsV2,nativeFieldRequiresCreateInputV2,nativeFieldSequenceGrantStatementsV2,nativeFieldSequenceOwnershipStatementsV2,nativeFieldSequenceStatementsV2,nativeFieldSupportsFilterV2,nativeFieldSupportsOperatorV2,nativeFieldSupportsSearchV2,nativeFieldSupportsSortV2,nativeOperatorsForFieldV2,nativePhysicalFieldV2,nativePhysicalFieldsV2,nativePhysicalObjectNameV2,nativeScopeSourceFieldValueV2,nativeScopeSourceGrantPathSupportedV2,nativeScopeSourceSubjectPathSupportedV2,nativeSubtableConstraintStatementsV2,nativeUniqueKeysJsonSchema,parseDecimalReservationLifecycle,parseNativeDataFieldsV2,parseNativeDataResourceInvariantsV2,parseNativeUniqueKeys,projectNativeDataResourceViewV2,projectWorkflowGraph,projectWorkflowNodePolicy,quoteNativeIdentifierV2,resolveNativeScopeSourceFieldPathV2,validateDecimalReservationLifecycles,validateManagedConcurrency,validateNativeDataDraftStateV2,validateNativeDataResourceReferencesV2,validateNativeDataResourceSurfaceV2,validateWorkflowAdministration,validateWorkflowInstanceCommandPolicies,validateWorkflowNodeConfigurationPatch,validateWorkflowReadability,workflowExpressionPaths,workflowInstanceCommandDeadlineError,workflowInstanceTerminateCapabilityAllowed,workflowNodeAllowedOperations,workflowPolicyTimestamp});