openxiangda-contracts 2.35.0 → 2.47.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.
Files changed (84) hide show
  1. package/dist/browser.d.ts +7 -0
  2. package/dist/browser.d.ts.map +1 -1
  3. package/dist/browser.js +7 -0
  4. package/dist/browser.js.map +1 -1
  5. package/dist/data-field-validation.d.ts.map +1 -1
  6. package/dist/data-field-validation.js +3 -2
  7. package/dist/data-field-validation.js.map +1 -1
  8. package/dist/field-value-schemas.d.ts +1 -1
  9. package/dist/field-value-schemas.d.ts.map +1 -1
  10. package/dist/field-value-schemas.js +2 -1
  11. package/dist/field-value-schemas.js.map +1 -1
  12. package/dist/index.d.ts +8 -0
  13. package/dist/index.d.ts.map +1 -1
  14. package/dist/index.js +8 -0
  15. package/dist/index.js.map +1 -1
  16. package/dist/native-compiler/compiler.d.ts +1 -1
  17. package/dist/native-compiler/compiler.d.ts.map +1 -1
  18. package/dist/native-compiler/compiler.js +104 -5
  19. package/dist/native-compiler/compiler.js.map +1 -1
  20. package/dist/native-compiler/data-capacity.d.ts +8 -0
  21. package/dist/native-compiler/data-capacity.d.ts.map +1 -0
  22. package/dist/native-compiler/data-capacity.js +15 -0
  23. package/dist/native-compiler/data-capacity.js.map +1 -0
  24. package/dist/native-compiler/data-field.d.ts.map +1 -1
  25. package/dist/native-compiler/data-field.js +3 -2
  26. package/dist/native-compiler/data-field.js.map +1 -1
  27. package/dist/native-compiler/index.cjs +5 -4
  28. package/dist/native-compiler/index.d.ts +9 -0
  29. package/dist/native-compiler/index.d.ts.map +1 -1
  30. package/dist/native-compiler/index.js +5 -4
  31. package/dist/native-compiler/role-membership-batch.d.ts +73 -0
  32. package/dist/native-compiler/role-membership-batch.d.ts.map +1 -0
  33. package/dist/native-compiler/role-membership-batch.js +91 -0
  34. package/dist/native-compiler/role-membership-batch.js.map +1 -0
  35. package/dist/native-compiler/workflow-assignment-routing.d.ts +121 -0
  36. package/dist/native-compiler/workflow-assignment-routing.d.ts.map +1 -0
  37. package/dist/native-compiler/workflow-assignment-routing.js +113 -0
  38. package/dist/native-compiler/workflow-assignment-routing.js.map +1 -0
  39. package/dist/native-compiler/workflow-automatic-cc.d.ts +20 -0
  40. package/dist/native-compiler/workflow-automatic-cc.d.ts.map +1 -0
  41. package/dist/native-compiler/workflow-automatic-cc.js +36 -0
  42. package/dist/native-compiler/workflow-automatic-cc.js.map +1 -0
  43. package/dist/native-compiler/workflow-business-step-identity.d.ts +12 -0
  44. package/dist/native-compiler/workflow-business-step-identity.d.ts.map +1 -0
  45. package/dist/native-compiler/workflow-business-step-identity.js +11 -0
  46. package/dist/native-compiler/workflow-business-step-identity.js.map +1 -0
  47. package/dist/native-compiler/workflow-business-step.d.ts +119 -0
  48. package/dist/native-compiler/workflow-business-step.d.ts.map +1 -0
  49. package/dist/native-compiler/workflow-business-step.js +357 -0
  50. package/dist/native-compiler/workflow-business-step.js.map +1 -0
  51. package/dist/native-compiler/workflow-delegation-administration.d.ts +1084 -0
  52. package/dist/native-compiler/workflow-delegation-administration.d.ts.map +1 -0
  53. package/dist/native-compiler/workflow-delegation-administration.js +68 -0
  54. package/dist/native-compiler/workflow-delegation-administration.js.map +1 -0
  55. package/dist/native-compiler/workflow-graph.d.ts +28 -2
  56. package/dist/native-compiler/workflow-graph.d.ts.map +1 -1
  57. package/dist/native-compiler/workflow-graph.js +25 -7
  58. package/dist/native-compiler/workflow-graph.js.map +1 -1
  59. package/dist/native-compiler/workflow-node-administration.d.ts.map +1 -1
  60. package/dist/native-compiler/workflow-node-administration.js +12 -3
  61. package/dist/native-compiler/workflow-node-administration.js.map +1 -1
  62. package/dist/native-compiler/workflow-task-page.d.ts +160 -0
  63. package/dist/native-compiler/workflow-task-page.d.ts.map +1 -0
  64. package/dist/native-compiler/workflow-task-page.js +324 -0
  65. package/dist/native-compiler/workflow-task-page.js.map +1 -0
  66. package/dist/native-version.d.ts +12 -0
  67. package/dist/native-version.d.ts.map +1 -1
  68. package/dist/native-version.js +12 -0
  69. package/dist/native-version.js.map +1 -1
  70. package/dist/native.d.ts +2 -0
  71. package/dist/native.d.ts.map +1 -1
  72. package/dist/native.js.map +1 -1
  73. package/dist/schemas.d.ts +5060 -1319
  74. package/dist/schemas.d.ts.map +1 -1
  75. package/dist/schemas.js +226 -7
  76. package/dist/schemas.js.map +1 -1
  77. package/dist/types.d.ts +174 -3
  78. package/dist/types.d.ts.map +1 -1
  79. package/dist/types.js +13 -0
  80. package/dist/types.js.map +1 -1
  81. package/dist/validation.d.ts.map +1 -1
  82. package/dist/validation.js +7 -3
  83. package/dist/validation.js.map +1 -1
  84. package/package.json +1 -1
@@ -1,8 +1,9 @@
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}
1
+ "use strict";var ms=Object.create;var wt=Object.defineProperty;var gs=Object.getOwnPropertyDescriptor;var As=Object.getOwnPropertyNames;var Es=Object.getPrototypeOf,Is=Object.prototype.hasOwnProperty;var bs=(e,t)=>{for(var o in t)wt(e,o,{get:t[o],enumerable:!0})},So=(e,t,o,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of As(t))!Is.call(e,i)&&i!==o&&wt(e,i,{get:()=>t[i],enumerable:!(n=gs(t,i))||n.enumerable});return e};var ys=(e,t,o)=>(o=e!=null?ms(Es(e)):{},So(t||!e||!e.__esModule?wt(o,"default",{value:e,enumerable:!0}):o,e)),Ns=e=>So(wt({},"__esModule",{value:!0}),e);var Tc={};bs(Tc,{DATA_AUDIT_METADATA_FIELDS:()=>wn,DATA_EVENT_TYPES_V2:()=>dn,DATA_FORM_DRAFT_MAX_BYTES:()=>Sc,DATA_SUBTABLE_MAX_ROWS:()=>Dt,DATA_SUBTABLE_MAX_TOTAL_ROWS:()=>$t,DATA_SYSTEM_SORT_FIELD_CODES:()=>Po,DATA_TRANSACTION_MAX_BYTES:()=>Cc,DATA_TRANSACTION_MAX_OPERATIONS:()=>Rc,ManagedConcurrencyContractError:()=>Ye,NATIVE_CONFIGURATION_VALIDATOR_DIGEST:()=>Nc,NATIVE_CONTRACT_CAPACITY_V2:()=>Y,NATIVE_DATA_POLICY_EXPRESSION_MAX_CLAUSES:()=>Nd,NATIVE_DATA_POLICY_EXPRESSION_MAX_DEPTH:()=>Id,NATIVE_DATA_POLICY_EXPRESSION_MAX_GROUP_ITEMS:()=>bd,NATIVE_DATA_POLICY_EXPRESSION_MAX_LEAVES:()=>yd,NATIVE_DATA_POLICY_EXPRESSION_MAX_OCCURRENCES:()=>Td,NATIVE_DATA_QUERY_OPERATORS_V2:()=>jo,NATIVE_ROLE_MEMBERSHIP_BATCH_MAX_BYTES:()=>Hd,NATIVE_ROLE_MEMBERSHIP_BATCH_MAX_ITEMS:()=>Yd,NATIVE_UNIQUE_KEY_MAX_BYTES:()=>ed,NATIVE_UNIQUE_KEY_NORMALIZERS:()=>Hn,NativeConfigurationCompilerError:()=>un,NativeDataFieldContractV2Error:()=>_e,NativeDataPolicyExpressionV2Error:()=>nt,NativeDecimalLifecycleContractError:()=>Pe,NativeEventActionContractError:()=>Xt,NativeRoleMembershipBatchInputError:()=>In,NativeScopeSourceFieldPathV2Error:()=>Jt,NativeUniqueKeyContractError:()=>Xe,OPENXIANGDA_NATIVE_DATA_FIELD_TYPES_V2:()=>Fo,OPENXIANGDA_NATIVE_DATA_SURFACE_KEYS_V2:()=>he,OPENXIANGDA_NATIVE_DRAFT_STATE_KEYS_V2:()=>jt,OPENXIANGDA_NATIVE_SYSTEM_FIELDS_V2:()=>Ft,OPENXIANGDA_NATIVE_SYSTEM_FIELD_MAP_V2:()=>Rn,WORKFLOW_AUTOMATIC_CC_MAX_RECIPIENTS:()=>ld,WORKFLOW_AUTOMATIC_CC_PROVIDERS:()=>fi,WORKFLOW_BUSINESS_STEP_EVENT:()=>Qe,WORKFLOW_BUSINESS_STEP_EVENTS:()=>oo,WORKFLOW_BUSINESS_STEP_FACTS_KEY:()=>vr,WORKFLOW_BUSINESS_STEP_MAX_BYTES:()=>Qt,WORKFLOW_BUSINESS_STEP_MAX_RECEIPT_BYTES:()=>si,WORKFLOW_CONFIGURABLE_OPERATIONS:()=>nn,WORKFLOW_CONFIGURABLE_PROVIDERS:()=>on,WORKFLOW_EVENT_TYPES_V2:()=>ln,WORKFLOW_ROUTING_MAX_BYTES:()=>gd,WORKFLOW_ROUTING_MAX_MATCHED_RULES:()=>md,WORKFLOW_ROUTING_MAX_RULES:()=>_d,WORKFLOW_TASK_PAGE_DEFINITION_MAX_BYTES:()=>mi,WORKFLOW_TASK_PAGE_MAX_BYTES:()=>an,WORKFLOW_TASK_PAGE_MAX_FIELDS:()=>_i,WORKFLOW_TASK_SUBTABLE_MAX_ROWS:()=>uo,WORKFLOW_TASK_SUBTABLE_MAX_TOTAL_ROWS:()=>gi,WorkflowTaskPageError:()=>ge,applyWorkflowTaskPageValues:()=>Ii,applyWorkflowTaskSubtableRows:()=>Gr,assertNativeRoleMembershipBatchInput:()=>Ac,compileNativeApplicationConfiguration:()=>ha,compileNativeEventAction:()=>Qn,compileNativeEventCapturePlansV2:()=>zi,compileRequiredPlatformCapabilitiesV3:()=>Ji,compileWorkflowBusinessStepHandlers:()=>Zt,evaluateWorkflowTaskPageExpression:()=>Se,formatWorkflowExpression:()=>mt,hasDataAuditReadPolicy:()=>Dn,isDataAuditMetadataField:()=>Ge,isDataSystemSortField:()=>$n,isNativeDataQueryOperatorV2:()=>Ps,isNativeMultiValueFieldV2:()=>at,materializeNativeDataQueryPathTypesV2:()=>wr,nativeDataPolicyExpressionLeavesV2:()=>Ot,nativeDataPolicyExpressionToCnfV2:()=>go,nativeDataQueryPathPlanV2:()=>Dr,nativeFieldAggregatePlanV2:()=>Ks,nativeFieldColumnDefinitionV2:()=>sr,nativeFieldDefaultSqlV2:()=>rr,nativeFieldHasDefaultV2:()=>cr,nativeFieldIndexStatementsV2:()=>fr,nativeFieldRequiresCreateInputV2:()=>ct,nativeFieldSequenceGrantStatementsV2:()=>ur,nativeFieldSequenceOwnershipStatementsV2:()=>lr,nativeFieldSequenceStatementsV2:()=>dr,nativeFieldSupportsFilterV2:()=>Pn,nativeFieldSupportsOperatorV2:()=>Ms,nativeFieldSupportsSearchV2:()=>Lt,nativeFieldSupportsSortV2:()=>Je,nativeOperatorsForFieldV2:()=>vn,nativePhysicalFieldV2:()=>Yo,nativePhysicalFieldsV2:()=>ir,nativePhysicalObjectNameV2:()=>Ce,nativeScopeSourceFieldValueV2:()=>Ir,nativeScopeSourceGrantPathSupportedV2:()=>Jn,nativeScopeSourceSubjectPathSupportedV2:()=>zt,nativeSubtableConstraintStatementsV2:()=>pr,nativeUniqueKeysJsonSchema:()=>kr,parseDecimalReservationLifecycle:()=>Kt,parseNativeDataFieldsV2:()=>vt,parseNativeDataResourceInvariantsV2:()=>Sn,parseNativeUniqueKeys:()=>Xn,projectNativeDataResourceViewV2:()=>Mt,projectWorkflowGraph:()=>Wr,projectWorkflowNodePolicy:()=>Br,quoteNativeIdentifierV2:()=>oe,refreshWorkflowTaskPageFacts:()=>qr,resolveNativeScopeSourceFieldPathV2:()=>He,selectWorkflowAssignmentRoutingRules:()=>ea,serializedDataBytes:()=>Os,validateDecimalReservationLifecycles:()=>Gn,validateManagedConcurrency:()=>Mn,validateNativeDataDraftStateV2:()=>xn,validateNativeDataResourceReferencesV2:()=>Cn,validateNativeDataResourceSurfaceV2:()=>Wt,validateWorkflowAdministration:()=>sn,validateWorkflowAssignmentRoutingBindings:()=>_o,validateWorkflowAssignmentRoutingPolicy:()=>Nt,validateWorkflowAssignmentRoutingRules:()=>Qr,validateWorkflowAutomaticCc:()=>rn,validateWorkflowBusinessStepHandlerContract:()=>Lr,validateWorkflowBusinessStepRequest:()=>Pr,validateWorkflowBusinessStepResult:()=>ci,validateWorkflowBusinessStepSchema:()=>ft,validateWorkflowBusinessStepSubscriptions:()=>so,validateWorkflowBusinessSteps:()=>_t,validateWorkflowInstanceCommandPolicies:()=>eo,validateWorkflowNodeConfigurationPatch:()=>Ur,validateWorkflowReadability:()=>co,validateWorkflowTaskPages:()=>It,workflowAssignmentRoutingFacts:()=>Zr,workflowAssignmentRoutingPolicySchema:()=>Xr,workflowAssignmentRoutingSemantic:()=>Ti,workflowBusinessStepFactSchema:()=>pt,workflowBusinessStepHandlerDigest:()=>yc,workflowBusinessStepInput:()=>xr,workflowBusinessStepPath:()=>di,workflowBusinessStepReceiptSignatureSuffix:()=>bc,workflowBusinessStepValueMatches:()=>ut,workflowDelegationMutationRequestSchema:()=>_s,workflowExpressionPaths:()=>ao,workflowInstanceCommandDeadlineError:()=>Fr,workflowInstanceTerminateCapabilityAllowed:()=>Vr,workflowNodeAllowedOperations:()=>tt,workflowPolicyTimestamp:()=>Zn,workflowTaskPageFieldState:()=>fo,workflowTaskPageReplayCoversInvalidation:()=>Jr,workflowTaskSubtableRows:()=>Kr});module.exports=Ns(Tc);var wo=require("node:crypto");function Ts(e){if(!e||typeof e!="object")return!1;let t=Object.getPrototypeOf(e);return t===Object.prototype||t===null}function Nn(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)=>Nn(n,`${t}[${i}]`)).join(",")}]`;if(Ts(e))return`{${Object.keys(e).filter(i=>e[i]!==void 0).sort((i,s)=>i===s?0:i<s?-1:1).map(i=>`${JSON.stringify(i)}:${Nn(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 ee(e){return Nn(e,"$")}function X(e){return(0,wo.createHash)("sha256").update(ee(e)).digest("hex")}var Dt=100,$t=400,Rc=1e3,Cc=2097152,Sc=2097152;function Os(e){try{return new TextEncoder().encode(JSON.stringify(e)).byteLength}catch{return 1/0}}var Vo=/^[A-Za-z][A-Za-z0-9_]{0,62}$/,hn=/^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/,Fo=["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"],hs=new Set(Fo),vo=new Set(["option.multiple","cascade.multiple","user.multiple","department.multiple","resource-ref.multiple","file","image","subtable"]),Do=new Set(["option.single","option.multiple","cascade.single","cascade.multiple"]),$o=new Set(["resource-ref.single","resource-ref.multiple"]),Ft=[{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}],Rn=new Map(Ft.map(e=>[e.code,e])),_e=class extends Error{constructor(o,n){super(o);this.code=o;this.pointer=n;this.name="NativeDataFieldContractV2Error"}code;pointer};function at(e){return vo.has(e)}function ct(e,t={}){return e.type!=="serial-number"&&t.system!==!0&&e.nullable===!1&&(!at(e.type)||t.requiredHint===!0)}function vt(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,s)=>{let a=`${t}/${s}`,r=le(i,a);pe(r,["code","type","nullable","indexed","options","source","maxLength","precision","scale","exactDecimal","min","max","rangeBoundary","timePrecision","file","serial","subtable"],a);let c=me(r.code,`${a}/code`,63);Vo.test(c)||D("NATIVE_FIELD_CODE_INVALID",`${a}/code`),n.has(c)&&D("NATIVE_DATA_FIELD_DUPLICATE",`${a}/code`),n.add(c);let l=me(r.type,`${a}/type`,32);hs.has(l)||D("NATIVE_DATA_FIELD_TYPE_INVALID",`${a}/type`);let p=l,d=On(r.nullable,`${a}/nullable`),f=On(r.indexed,`${a}/indexed`);d===!0&&vo.has(p)&&D("NATIVE_DATA_MULTI_FIELD_NULLABLE_INVALID",`${a}/nullable`);let g=Ss(r.options,p,a),E=ws(r.source,p,a),A=$s(r,p,a),b=On(r.exactDecimal,`${a}/exactDecimal`);b!==void 0&&p!=="number.decimal"&&D("NATIVE_DATA_FIELD_EXACT_DECIMAL_TYPE_INVALID",`${a}/exactDecimal`);let I=Rs(r.rangeBoundary,p,a),_=ks(r.file,p,a),u=Vs(r.serial,p,a),N=Fs(r.subtable,p,a);return{code:c,type:p,...d===void 0?{}:{nullable:d},...f===void 0?{}:{indexed:f},...g?{options:g}:{},...E?{source:E}:{},...A,...b===void 0?{}:{exactDecimal:b},...I?{rangeBoundary:I}:{},..._?{file:_}:{},...u?{serial:u}:{},...N?{subtable:N}:{}}})}function Rs(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 Cn(e,t){Array.isArray(e)||D("NATIVE_ARRAY_REQUIRED",t);let o=new Map;e.forEach((n,i)=>{let s=`${t}/${i}`,a=le(n,s),r=me(a.code,`${s}/code`,64);(!hn.test(r)||o.has(r))&&D("NATIVE_RESOURCE_CODE_INVALID",`${s}/code`);let c=le(a.schema,`${s}/schema`);o.set(r,{pointer:s,fields:vt(c.fields,`${s}/schema/fields`)})});for(let[n,i]of o){let s=new Map(i.fields.map(r=>[r.code,r]));i.fields.filter(r=>r.type==="subtable").reduce((r,c)=>r+(c.subtable?.maxRows??20),0)>400&&D("NATIVE_DATA_FIELD_SUBTABLE_AGGREGATE_MAX_ROWS_EXCEEDED",`${i.pointer}/schema/fields`),i.fields.forEach((r,c)=>{let l=`${i.pointer}/schema/fields/${c}`;if(r.source&&Cs(r.source,s,o,`${l}/source`),r.subtable){let p=o.get(r.subtable.resourceCode);(!p||r.subtable.resourceCode===n)&&D("NATIVE_DATA_FIELD_SUBTABLE_TARGET_MISSING",`${l}/subtable/resourceCode`);let d=p.fields.find(g=>g.code===r.subtable?.foreignKey);(!d||d.type!=="uuid"||d.nullable!==!1)&&D("NATIVE_DATA_FIELD_SUBTABLE_FOREIGN_KEY_INVALID",`${l}/subtable/foreignKey`);let f=p.fields.find(g=>g.code===r.subtable?.orderField);(!f||f.type!=="number.integer"||f.nullable!==!1)&&D("NATIVE_DATA_FIELD_SUBTABLE_ORDER_FIELD_INVALID",`${l}/subtable/orderField`)}})}}function Sn(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(s=>[s.code,s])),i=new Set;return e.map((s,a)=>{let r=`${o}/${a}`,c=le(s,r);pe(c,["code","message","expression"],r);let l=me(c.code,`${r}/code`,128);(!/^[a-z][a-z0-9]*(?:[._-][a-z0-9]+)*$/.test(l)||i.has(l))&&D("NATIVE_DATA_RESOURCE_INVARIANT_CODE_INVALID",`${r}/code`),i.add(l);let p=Vt(c.message,`${r}/message`,500);p!==void 0&&p.length===0&&D("NATIVE_DATA_RESOURCE_INVARIANT_MESSAGE_INVALID",`${r}/message`);let d=le(c.expression,`${r}/expression`);if(d.kind==="nonBlankTextWhenOption"){pe(d,["kind","optionField","optionValue","textField"],`${r}/expression`);let _=Ie(d.optionField,`${r}/expression/optionField`),u=Ie(d.textField,`${r}/expression/textField`),N=me(d.optionValue,`${r}/expression/optionValue`,128),y=n.get(_),O=n.get(u);return(!y||!O)&&D("NATIVE_DATA_RESOURCE_INVARIANT_FIELD_UNKNOWN",`${r}/expression`),(y.type!=="option.single"||!["text.short","text.long"].includes(O.type)||!y.options?.some(h=>h.value===N))&&D("NATIVE_DATA_RESOURCE_INVARIANT_FIELD_TYPES_INVALID",`${r}/expression`),{code:l,...p===void 0?{}:{message:p},expression:{kind:"nonBlankTextWhenOption",optionField:_,optionValue:N,textField:u}}}pe(d,["leftField","operator","rightField"],`${r}/expression`);let f=Ie(d.leftField,`${r}/expression/leftField`),g=Ie(d.rightField,`${r}/expression/rightField`),E=n.get(f),A=n.get(g);(!E||!A)&&D("NATIVE_DATA_RESOURCE_INVARIANT_FIELD_UNKNOWN",`${r}/expression`),E.type===A.type||["number.integer","number.decimal"].includes(E.type)&&["number.integer","number.decimal"].includes(A.type)||D("NATIVE_DATA_RESOURCE_INVARIANT_FIELD_TYPES_INVALID",`${r}/expression`);let I=String(d.operator);return["eq","neq","gt","gte","lt","lte"].includes(I)||D("NATIVE_DATA_RESOURCE_INVARIANT_OPERATOR_INVALID",`${r}/expression/operator`),!["eq","neq"].includes(I)&&!["number.integer","number.decimal","date","time","datetime","text.short","text.long","text.rich","serial-number","uuid"].includes(E.type)&&D("NATIVE_DATA_RESOURCE_INVARIANT_FIELD_TYPES_INVALID",`${r}/expression`),{code:l,...p===void 0?{}:{message:p},expression:{leftField:f,operator:I,rightField:g}}})}function Cs(e,t,o,n){let i=o.get(e.resourceCode);i||D("NATIVE_DATA_FIELD_SOURCE_TARGET_MISSING",`${n}/resourceCode`);let s=new Map(i.fields.map(r=>[r.code,r])),a=s.get(e.labelField);(!a||!["text.short","text.long"].includes(a.type))&&D("NATIVE_DATA_FIELD_SOURCE_LABEL_INVALID",`${n}/labelField`);for(let r of["searchFields","descriptionFields","snapshotFields"])for(let c of e[r]||[])s.has(c)||D("NATIVE_DATA_FIELD_SOURCE_FIELD_MISSING",`${n}/${r}`);for(let[r,c]of(e.filters||[]).entries())s.has(c.field)||D("NATIVE_DATA_FIELD_SOURCE_FILTER_FIELD_MISSING",`${n}/filters/${r}/field`),"binding"in c&&!t.has(c.binding.field)&&D("NATIVE_DATA_FIELD_SOURCE_BINDING_FIELD_MISSING",`${n}/filters/${r}/binding/field`)}function Ss(e,t,o){let n=`${o}/options`;if(e===void 0){Do.has(t)&&D("NATIVE_DATA_FIELD_OPTIONS_REQUIRED",n);return}(!Do.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,s=(a,r,c)=>{c>5&&D("NATIVE_DATA_FIELD_OPTIONS_DEPTH_EXCEEDED",r);let l=new Set;return a.map((p,d)=>{i+=1,i>1e3&&D("NATIVE_DATA_FIELD_OPTIONS_COUNT_EXCEEDED",n);let f=`${r}/${d}`,g=le(p,f);pe(g,["label","value","description","color","children"],f);let E=me(g.label,`${f}/label`,500),A=me(g.value,`${f}/value`,500);l.has(A)&&D("NATIVE_DATA_FIELD_OPTION_VALUE_DUPLICATE",`${f}/value`),l.add(A);let b=Vt(g.description,`${f}/description`,2e3),I=Vt(g.color,`${f}/color`,64),_;return g.children!==void 0&&((!t.startsWith("cascade.")||!Array.isArray(g.children))&&D("NATIVE_DATA_FIELD_OPTION_CHILDREN_INVALID",`${f}/children`),(g.children.length<1||g.children.length>100)&&D("NATIVE_DATA_FIELD_OPTION_CHILDREN_INVALID",`${f}/children`),_=s(g.children,`${f}/children`,c+1)),{label:E,value:A,...b===void 0?{}:{description:b},...I===void 0?{}:{color:I},..._?{children:_}:{}}})};return s(e,n,1)}function ws(e,t,o){let n=`${o}/source`;if(e===void 0){$o.has(t)&&D("NATIVE_DATA_FIELD_SOURCE_REQUIRED",n);return}$o.has(t)||D("NATIVE_DATA_FIELD_SOURCE_TYPE_INVALID",n);let i=le(e,n);pe(i,["kind","resourceCode","labelField","searchFields","descriptionFields","snapshotFields","filters","pageSize","loadMode"],n),i.kind!=="resource"&&D("NATIVE_DATA_FIELD_SOURCE_KIND_INVALID",`${n}/kind`);let s=me(i.resourceCode,`${n}/resourceCode`,64);hn.test(s)||D("NATIVE_RESOURCE_CODE_INVALID",`${n}/resourceCode`);let a=Ie(i.labelField,`${n}/labelField`),r=Tn(i.searchFields,`${n}/searchFields`,10),c=Tn(i.descriptionFields,`${n}/descriptionFields`,10),l=Tn(i.snapshotFields,`${n}/snapshotFields`,50),p=Ke(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 f=Ds(i.filters,`${n}/filters`);return{kind:"resource",resourceCode:s,labelField:a,...r?{searchFields:r}:{},...c?{descriptionFields:c}:{},...l?{snapshotFields:l}:{},...f?{filters:f}:{},...p===void 0?{}:{pageSize:p},...d?{loadMode:d}:{}}}function Ds(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}`,s=le(o,i),a=Object.prototype.hasOwnProperty.call(s,"value"),r=Object.prototype.hasOwnProperty.call(s,"binding");pe(s,a?["field","operator","value"]:["field","operator","binding"],i),a===r&&D("NATIVE_DATA_FIELD_SOURCE_FILTER_VALUE_INVALID",i);let c=Ie(s.field,`${i}/field`);["eq","in"].includes(String(s.operator))||D("NATIVE_DATA_FIELD_SOURCE_FILTER_OPERATOR_INVALID",`${i}/operator`);let l=s.operator;if(a)return{field:c,operator:l,value:s.value};let p=le(s.binding,`${i}/binding`);return pe(p,["kind","field"],`${i}/binding`),p.kind!=="field"&&D("NATIVE_DATA_FIELD_SOURCE_BINDING_KIND_INVALID",`${i}/binding/kind`),{field:c,operator:l,binding:{kind:"field",field:Ie(p.field,`${i}/binding/field`)}}})}function $s(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=kt(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=kt(e.precision,`${o}/precision`,1,1e3),n.scale=e.scale===void 0?0:kt(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=ko(e.min,`${o}/min`),s=ko(e.max,`${o}/max`);t==="number.integer"&&[i,s].some(a=>a!==void 0&&!Number.isSafeInteger(a))&&D("NATIVE_DATA_FIELD_NUMERIC_BOUNDS_INVALID",o),i!==void 0&&s!==void 0&&i>s&&D("NATIVE_DATA_FIELD_NUMERIC_BOUNDS_INVALID",o),i!==void 0&&(n.min=i),s!==void 0&&(n.max=s)}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 ks(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=le(e,n);pe(i,["maxCount","maxSizeMb","accept"],n);let s=Ke(i.maxCount,`${n}/maxCount`,1,100);t==="signature"&&s!==void 0&&s!==1&&D("NATIVE_DATA_FIELD_SIGNATURE_COUNT_INVALID",`${n}/maxCount`);let a=Ke(i.maxSizeMb,`${n}/maxSizeMb`,1,1024),r;return i.accept!==void 0&&((!Array.isArray(i.accept)||i.accept.length>50)&&D("NATIVE_DATA_FIELD_FILE_ACCEPT_INVALID",`${n}/accept`),r=i.accept.map((c,l)=>me(c,`${n}/accept/${l}`,255)),new Set(r).size!==r.length&&D("NATIVE_DATA_FIELD_FILE_ACCEPT_INVALID",`${n}/accept`)),{...s===void 0?{}:{maxCount:s},...a===void 0?{}:{maxSizeMb:a},...r===void 0?{}:{accept:r}}}function Vs(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=le(e,n);pe(i,["prefix","digits","start"],n);let s=Vt(i.prefix,`${n}/prefix`,64),a=Ke(i.digits,`${n}/digits`,1,32),r=Ke(i.start,`${n}/start`,0,Number.MAX_SAFE_INTEGER);return{...s===void 0?{}:{prefix:s},...a===void 0?{}:{digits:a},...r===void 0?{}:{start:r}}}function Fs(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=le(e,n);pe(i,["resourceCode","foreignKey","orderField","maxRows"],n);let s=me(i.resourceCode,`${n}/resourceCode`,64);hn.test(s)||D("NATIVE_RESOURCE_CODE_INVALID",`${n}/resourceCode`);let a=Ie(i.foreignKey,`${n}/foreignKey`),r=Ie(i.orderField,`${n}/orderField`);r===a&&D("NATIVE_DATA_FIELD_SUBTABLE_ORDER_FIELD_INVALID",`${n}/orderField`);let c=Ke(i.maxRows,`${n}/maxRows`,1,100);return{resourceCode:s,foreignKey:a,orderField:r,...c===void 0?{}:{maxRows:c}}}function Tn(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,s)=>Ie(i,`${t}/${s}`));return new Set(n).size!==n.length&&D("NATIVE_DATA_FIELD_SOURCE_FIELDS_INVALID",t),n}function Ie(e,t){let o=me(e,t,63);return Vo.test(o)||D("NATIVE_FIELD_CODE_INVALID",t),o}function le(e,t){return(!e||typeof e!="object"||Array.isArray(e))&&D("NATIVE_OBJECT_REQUIRED",t),e}function pe(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 me(e,t,o){return(typeof e!="string"||e.length===0||e.length>o)&&D("NATIVE_STRING_INVALID",t),e}function Vt(e,t,o){if(e!==void 0)return(typeof e!="string"||e.length>o)&&D("NATIVE_STRING_INVALID",t),e}function On(e,t){if(e!==void 0)return typeof e!="boolean"&&D("NATIVE_BOOLEAN_REQUIRED",t),e}function Ke(e,t,o,n){if(e!==void 0)return kt(e,t,o,n)}function ko(e,t){if(e!==void 0)return(typeof e!="number"||!Number.isFinite(e))&&D("NATIVE_NUMBER_REQUIRED",t),e}function kt(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 _e(e,t)}var wn=["created_by","updated_by","created_at","updated_at"];function Ge(e){return wn.includes(e)}function Dn(e){return wn.some(t=>Object.prototype.hasOwnProperty.call(e.fieldPolicies||{},t))}var Po=Ft.map(e=>e.code);function $n(e){return Po.includes(e)}var jo=["eq","neq","gt","gte","lt","lte","contains","startsWith","endsWith","in","between","has","hasAny","hasAll","overlaps","containedBy","jsonContains","isEmpty","isNotEmpty"],vs=new Set(jo);function Ps(e){return vs.has(String(e))}var kn=["eq","neq","contains","startsWith","endsWith","in","isEmpty","isNotEmpty"],dt=["eq","neq","gt","gte","lt","lte","between","in","isEmpty"],Ls=["eq","neq","in","isEmpty"],Pt=["eq","neq","in","isEmpty","isNotEmpty"],qe=["has","hasAny","hasAll","isEmpty","isNotEmpty"],Lo=["overlaps","contains","containedBy","isEmpty"],Vn=["jsonContains","isEmpty","isNotEmpty"],Fn=["isEmpty","isNotEmpty"],xs={"text.short":kn,"text.long":kn,"text.rich":kn,"number.integer":dt,"number.decimal":dt,boolean:Ls,date:dt,time:dt,datetime:dt,"date-range":Lo,"datetime-range":Lo,"option.single":Pt,"option.multiple":qe,"cascade.single":qe,"cascade.multiple":qe,"user.single":Pt,"user.multiple":qe,"department.single":Pt,"department.multiple":qe,"resource-ref.single":Pt,"resource-ref.multiple":qe,file:Fn,image:Fn,signature:Fn,address:Vn,location:Vn,uuid:["eq","neq","in","isEmpty"],json:Vn,"serial-number":["eq","neq","in","contains","startsWith"],subtable:[]},js=new Set(["text.short","text.long","text.rich","option.single","user.single","department.single","resource-ref.single","serial-number"]),Ws=new Set(["option.multiple","cascade.single","cascade.multiple","user.multiple","department.multiple","resource-ref.multiple","file","image","signature","address","location","json","subtable"]);function vn(e){return xs[e]}function Ms(e,t){return vn(e).includes(t)}function Lt(e){return js.has(e)}function Je(e){return!Ws.has(e)}function Pn(e){return vn(e).length>0}var xo=new Set(["number.integer","number.decimal"]),Wo=new Set(["text.short","text.long","number.integer","number.decimal","date","time","datetime","serial-number"]),Us=new Set([...Wo,"boolean","uuid"]),Bs=new Set(["option.single","user.single","department.single","resource-ref.single"]);function Ks(e,t){return t==="sum"||t==="avg"?xo.has(e)?{valueExpression:"column",numericResult:!0}:null:t==="min"||t==="max"?Wo.has(e)?{valueExpression:"column",numericResult:xo.has(e)}:null:Bs.has(e)?{valueExpression:"snapshot-value",numericResult:!0}:Us.has(e)?{valueExpression:"column",numericResult:!0}:null}var jt=["version","maxBytes","fields"];function xn(e,t){if(e===void 0)return;let o=Ln(e,t);Mo(o,jt,t);let n=xt(o.version,`${t}/version`,1,1e6),i=xt(o.maxBytes,`${t}/maxBytes`,2,196608);(!n||!i)&&ae("NATIVE_DATA_DRAFT_STATE_SCHEMA_INVALID",t);let s=Ln(o.fields,`${t}/fields`),a=Object.entries(s);(!a.length||a.length>50)&&ae("NATIVE_DATA_DRAFT_STATE_FIELDS_INVALID",`${t}/fields`);for(let[r,c]of a){let l=`${t}/fields/${r}`;/^[A-Za-z][A-Za-z0-9_]{0,62}$/.test(r)||ae("NATIVE_DATA_DRAFT_STATE_FIELD_CODE_INVALID",l);let p=Ln(c,l),d=Uo(p.type,`${l}/type`,32),f=d==="string"?["type","required","maxLength","enum"]:d==="json.object"?["type","required","maxBytes"]:["type","required"];if(["string","number","integer","boolean","json.object"].includes(d)||ae("NATIVE_DATA_DRAFT_STATE_FIELD_TYPE_INVALID",`${l}/type`),Mo(p,f,l),qs(p.required,`${l}/required`),d==="string"){let g=xt(p.maxLength,`${l}/maxLength`,1,196608);g||ae("NATIVE_DATA_DRAFT_STATE_FIELD_INVALID",l),p.enum!==void 0&&Gs(p.enum,`${l}/enum`,100,!1).some(A=>A.length>g)&&ae("NATIVE_DATA_DRAFT_STATE_FIELD_INVALID",`${l}/enum`)}else if(d==="json.object"){let g=xt(p.maxBytes,`${l}/maxBytes`,2,65536);(!g||g>i)&&ae("NATIVE_DATA_DRAFT_STATE_FIELD_INVALID",l)}}}function Gs(e,t,o,n){(!Array.isArray(e)||!n&&e.length===0||e.length>o)&&ae("NATIVE_DATA_SURFACE_STRING_ARRAY_INVALID",t);let i=e.map((s,a)=>Uo(s,`${t}/${a}`,255));return new Set(i).size!==i.length&&ae("NATIVE_DATA_SURFACE_STRING_ARRAY_INVALID",t),i}function Ln(e,t){return(!e||typeof e!="object"||Array.isArray(e))&&ae("NATIVE_OBJECT_REQUIRED",t),e}function Mo(e,t,o){let n=new Set(t);for(let i of Object.keys(e))n.has(i)||ae("NATIVE_PROPERTY_UNKNOWN",`${o}/${i}`)}function Uo(e,t,o){return(typeof e!="string"||e.length===0||e.length>o)&&ae("NATIVE_STRING_INVALID",t),e}function qs(e,t){e!==void 0&&typeof e!="boolean"&&ae("NATIVE_BOOLEAN_REQUIRED",t)}function xt(e,t,o,n){return(!Number.isSafeInteger(e)||Number(e)<o||Number(e)>n)&&ae("NATIVE_INTEGER_INVALID",t),Number(e)}function ae(e,t){throw new _e(e,t)}var Js=500,he={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:jt,mobile:["enabled"]},zs={"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 Wt(e,t,o){if(e===void 0)return;let n=ne(e,o);be(n,he.surface,o);let i=n.mutationOwner===void 0?"native":Re(n.mutationOwner,`${o}/mutationOwner`,16);["native","action","readonly","workflow","queued-command"].includes(i)||x("NATIVE_DATA_SURFACE_MUTATION_OWNER_INVALID",`${o}/mutationOwner`);let s=n.generated===void 0?{}:ne(n.generated,`${o}/generated`);be(s,he.generated,`${o}/generated`);for(let c of he.generated)Wn(s[c],`${o}/generated/${c}`);if(i!=="native")for(let c of["create","update","delete"])s[c]===!0&&x("NATIVE_DATA_SURFACE_MUTATION_OWNER_CONFLICT",`${o}/generated/${c}`);let a=new Map(t.map(c=>[c.code,c])),r=ne(n.fields,`${o}/fields`);for(let c of Object.keys(r))a.has(c)||x("NATIVE_DATA_SURFACE_FIELD_MISSING",`${o}/fields/${c}`);for(let c of t)Object.prototype.hasOwnProperty.call(r,c.code)||x("NATIVE_DATA_SURFACE_FIELD_REQUIRED",`${o}/fields/${c.code}`),Hs(r[c.code],c,`${o}/fields/${c.code}`);for(let c of["create","update"]){let l=s[c]??i==="native",p=t.some(d=>{let f=ne(r[d.code],`${o}/fields/${d.code}`);return Ko(d,f,c)});l&&!p&&x("NATIVE_DATA_SURFACE_WRITABLE_FIELDS_REQUIRED",`${o}/generated/${c}`)}if(Xs(n.list,a,`${o}/list`),Bo(n.form,a,`${o}/form`,"form"),Bo(n.detail,a,`${o}/detail`,"detail"),n.mobile!==void 0){let c=ne(n.mobile,`${o}/mobile`);be(c,he.mobile,`${o}/mobile`),Wn(c.enabled,`${o}/mobile/enabled`)}Ys(n,t,o)}function Mt(e,t){let o=e.views?.find(i=>i.code===t);o||x("NATIVE_DATA_VIEW_NOT_FOUND",`/surface/views/${t}`);let n=new Map((o.sections||[]).flatMap(i=>i.fields.map(s=>[s,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,s])=>{let a={...s};delete a.section;let r=n.get(i);return[i,{...a,...r?{section:r}:{},list:o.list.fieldOrder.includes(i)}]}))}}function Ys(e,t,o){if(e.views===void 0)return;(!Array.isArray(e.views)||e.views.length>20)&&x("NATIVE_DATA_VIEWS_LIMIT_INVALID",`${o}/views`);let n=new Set;e.views.forEach((i,s)=>{let a=`${o}/views/${s}`,r=ne(i,a);be(r,["code","name","generated","list","form","detail","mobile","sections"],a);let c=Re(r.code,`${a}/code`,64);(!/^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/.test(c)||n.has(c))&&x("NATIVE_DATA_VIEW_CODE_INVALID",`${a}/code`),n.add(c),Re(r.name,`${a}/name`,255),ne(r.generated,`${a}/generated`),ne(r.mobile,`${a}/mobile`);for(let p of["list","detail","create","update","delete"])typeof r.generated[p]!="boolean"&&x("NATIVE_DATA_VIEW_OPERATION_INVALID",`${a}/generated/${p}`);typeof r.mobile.enabled!="boolean"&&x("NATIVE_DATA_VIEW_MOBILE_INVALID",`${a}/mobile/enabled`);for(let p of["list","form","detail"]){let d=ne(r[p],`${a}/${p}`),f=ze(d.fieldOrder,`${a}/${p}/fieldOrder`,500,!0);for(let g of f){let E=e.fields[g];(!E||(E.hidden??E.system)===!0)&&x("NATIVE_DATA_VIEW_FIELD_INVALID",`${a}/${p}/fieldOrder`)}}if(r.sections!==void 0){(!Array.isArray(r.sections)||r.sections.length>100)&&x("NATIVE_DATA_VIEW_SECTIONS_INVALID",`${a}/sections`);let p=new Set;r.sections.forEach((d,f)=>{let g=`${a}/sections/${f}`,E=ne(d,g);be(E,["title","fields"],g),Re(E.title,`${g}/title`,255);for(let A of ze(E.fields,`${g}/fields`,100,!0)){let b=e.fields[A];(!b||(b.hidden??b.system)===!0||p.has(A))&&x("NATIVE_DATA_VIEW_FIELD_INVALID",`${g}/fields`),p.add(A)}})}let l=Mt(e,c);if(Wt(l,t,a),r.generated.create!==!1&&(e.mutationOwner||"native")==="native")for(let p of t)ct(p,e.fields[p.code])&&Ko(p,e.fields[p.code],"create")&&!r.form.fieldOrder.includes(p.code)&&x("NATIVE_DATA_VIEW_CREATE_REQUIRED_FIELD_MISSING",`${a}/form/fieldOrder`)})}function Ko(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 Hs(e,t,o){let n=ne(e,o);be(n,he.field,o),Re(n.label,`${o}/label`,500),n.type!==t.type&&x("NATIVE_DATA_SURFACE_FIELD_TYPE_MISMATCH",`${o}/type`);let i=Re(n.widget,`${o}/widget`,64);zs[t.type].includes(i)||x("NATIVE_DATA_SURFACE_WIDGET_INCOMPATIBLE",`${o}/widget`),er(n.section,`${o}/section`,255);for(let s of["requiredHint","system","hidden","list","searchable","sortable"])Wn(n[s],`${o}/${s}`);n.searchable===!0&&!Lt(t.type)&&x("NATIVE_DATA_SURFACE_SEARCH_UNSUPPORTED",`${o}/searchable`),n.sortable===!0&&!Je(t.type)&&x("NATIVE_DATA_SURFACE_SORT_UNSUPPORTED",`${o}/sortable`);for(let s of["readCapabilities","createCapabilities","updateCapabilities"])ze(n[s],`${o}/${s}`,100,!0);if(n.maxCount!==void 0&&(!Number.isSafeInteger(n.maxCount)||Number(n.maxCount)<1||Number(n.maxCount)>100)&&x("NATIVE_DATA_SURFACE_MAX_COUNT_INVALID",`${o}/maxCount`),n.maxSizeMb!==void 0&&(!Number.isSafeInteger(n.maxSizeMb)||Number(n.maxSizeMb)<1||Number(n.maxSizeMb)>1024)&&x("NATIVE_DATA_SURFACE_MAX_SIZE_INVALID",`${o}/maxSizeMb`),n.accept!==void 0){let s=Array.isArray(n.accept)?n.accept:[n.accept];ze(s,`${o}/accept`,50,!1)}for(let s of["maxLength","precision","scale","exactDecimal","min","max","rangeBoundary","options","source","timePrecision","serial","subtable"])Qs(n,t,s,o);Zs(n,t,o)}function Xs(e,t,o){if(e===void 0)return;let n=ne(e,o);if(be(n,he.list,o),n.actions!==void 0){let i=ne(n.actions,`${o}/actions`);be(i,["import","export"],`${o}/actions`);for(let s of["import","export"])i[s]!==void 0&&typeof i[s]!="boolean"&&x("NATIVE_DATA_SURFACE_LIST_ACTION_INVALID",`${o}/actions/${s}`)}if(n.fieldOrder!==void 0)for(let i of ze(n.fieldOrder,`${o}/fieldOrder`,500,!0))t.has(i)||x("NATIVE_DATA_SURFACE_LIST_FIELD_INVALID",`${o}/fieldOrder`);n.defaultPageSize!==void 0&&(!Number.isSafeInteger(n.defaultPageSize)||Number(n.defaultPageSize)<1||Number(n.defaultPageSize)>200)&&x("NATIVE_DATA_SURFACE_PAGE_SIZE_INVALID",`${o}/defaultPageSize`);for(let[i,s]of[["searchableFields",Lt],["filterFields",Pn]]){if(n[i]===void 0)continue;let a=ze(n[i],`${o}/${i}`,100,!0);for(let r of a){let c=t.get(r);(!c||!s(c.type))&&x("NATIVE_DATA_SURFACE_LIST_FIELD_INVALID",`${o}/${i}`)}}if(n.defaultSort!==void 0){let i=ne(n.defaultSort,`${o}/defaultSort`);be(i,he.defaultSort,`${o}/defaultSort`);let s=Re(i.field,`${o}/defaultSort/field`,63),a=t.get(s);!$n(s)&&(!a||!Je(a.type))&&x("NATIVE_DATA_SURFACE_SORT_UNSUPPORTED",`${o}/defaultSort/field`),i.order!==void 0&&!["asc","desc"].includes(i.order)&&x("NATIVE_DATA_SURFACE_SORT_ORDER_INVALID",`${o}/defaultSort/order`)}}function Bo(e,t,o,n){if(e===void 0)return;let i=ne(e,o);if(be(i,he[n],o),i.layout!==void 0&&!["flat","sections"].includes(i.layout)&&x("NATIVE_DATA_SURFACE_LAYOUT_INVALID",`${o}/layout`),i.fieldOrder!==void 0){let s=`${o}/fieldOrder`;(!Array.isArray(i.fieldOrder)||i.fieldOrder.length>t.size||i.fieldOrder.length>Js)&&x("NATIVE_DATA_SURFACE_FIELD_ORDER_INVALID",s);let a=i.fieldOrder.map((r,c)=>Re(r,`${s}/${c}`,63));new Set(a).size!==a.length&&x("NATIVE_DATA_SURFACE_FIELD_ORDER_INVALID",s),a.forEach((r,c)=>{t.has(r)||x("NATIVE_DATA_SURFACE_FIELD_ORDER_FIELD_MISSING",`${s}/${c}`)})}n==="form"&&xn(i.draftState,`${o}/draftState`)}function Qs(e,t,o,n){e[o]===void 0&&t[o]===void 0||((e[o]===void 0||t[o]===void 0)&&x("NATIVE_DATA_SURFACE_FIELD_PROJECTION_MISMATCH",`${n}/${o}`),ee(e[o])!==ee(t[o])&&x("NATIVE_DATA_SURFACE_FIELD_PROJECTION_MISMATCH",`${n}/${o}`))}function Zs(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:jn(e.accept)}};for(let s of["maxCount","maxSizeMb","accept"]){if(i[s]===void 0&&n[s]===void 0)continue;(i[s]===void 0||n[s]===void 0)&&x("NATIVE_DATA_SURFACE_FIELD_PROJECTION_MISMATCH",`${o}/${s}`);let a=s==="accept"?jn(i[s]):i[s],r=s==="accept"?jn(n[s]):n[s];ee(a)!==ee(r)&&x("NATIVE_DATA_SURFACE_FIELD_PROJECTION_MISMATCH",`${o}/${s}`)}}function jn(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 ze(e,t,o,n){(!Array.isArray(e)||!n&&e.length===0||e.length>o)&&x("NATIVE_DATA_SURFACE_STRING_ARRAY_INVALID",t);let i=e.map((s,a)=>Re(s,`${t}/${a}`,255));return new Set(i).size!==i.length&&x("NATIVE_DATA_SURFACE_STRING_ARRAY_INVALID",t),i}function ne(e,t){return(!e||typeof e!="object"||Array.isArray(e))&&x("NATIVE_OBJECT_REQUIRED",t),e}function be(e,t,o){let n=new Set(t);for(let i of Object.keys(e))n.has(i)||x("NATIVE_PROPERTY_UNKNOWN",`${o}/${i}`)}function Re(e,t,o){return(typeof e!="string"||e.length===0||e.length>o)&&x("NATIVE_STRING_INVALID",t),e}function er(e,t,o){e!==void 0&&(typeof e!="string"||e.length>o)&&x("NATIVE_STRING_INVALID",t)}function Wn(e,t){e!==void 0&&typeof e!="boolean"&&x("NATIVE_BOOLEAN_REQUIRED",t)}function x(e,t){throw new _e(e,t)}var Ye=class extends Error{constructor(o,n){super(`${o}: ${n}`);this.pointer=o;this.reason=n}pointer;reason;code="NATIVE_MANAGED_CONCURRENCY_INVALID"};function Mn(e,t,o){if(e===void 0)return;let n=(_,u)=>{throw new Ye(_,u)},i=(_,u,N)=>((!_||typeof _!="object"||Array.isArray(_)||Object.keys(_).some(y=>!N.includes(y)))&&n(u,"object contains unsupported properties"),_),s=(_,u,N,y)=>{(!Number.isSafeInteger(_)||_<u||_>N)&&n(y,`expected integer ${u}..${N}`)},a=(_,u)=>{(typeof _!="string"||!/^[a-z][a-z0-9_-]{0,63}$/.test(_))&&n(u,"invalid code")},r=(_,u,N)=>((!Array.isArray(_)||_.length>u)&&n(N,"array exceeds bound"),_),c=(_,u)=>{let N=t.find(y=>y.code===_);return N||n(u,"unknown resource"),N},l=(_,u,N)=>{let y=_.schema.fields.find(O=>O.code===u);return!y&&u!=="id"&&n(N,"unknown field"),y},p=(_,u,N=!1)=>{i(_,u,Object.keys(_||{})),Object.keys(_).length>8&&n(u,"at most eight parameters");for(let[y,O]of Object.entries(_))if(a(y,u),i(O,u,["type","values","minimum","maximum","minLength","maxLength"]),O.type==="uuid")Object.keys(O).length!==1&&n(u,"uuid has no options");else if(N&&O.type==="boolean")i(O,u,["type"]);else if(N&&O.type==="string"&&O.values===void 0)i(O,u,["type","minLength","maxLength"]),s(O.maxLength,1,256,u),O.minLength!==void 0&&s(O.minLength,0,O.maxLength,u);else if(O.type==="string"){i(O,u,["type","values"]);let h=r(O.values,100,u);(!h.length||h.some(C=>typeof C!="string"||C.length>128)||new Set(h).size!==h.length)&&n(u,"finite string values required")}else O.type==="integer"?(i(O,u,["type","minimum","maximum"]),s(O.minimum,0,1e6,u),s(O.maximum,O.minimum,O.minimum+1e3,u)):n(u,"unsupported parameter type")},d=(_,u,N,y=!1)=>{i(_,N,["from","key","value"]),!(_.from==="input"&&Object.keys(_).length===2&&Object.hasOwn(u,_.key))&&((_.from==="actor"||y&&_.from==="allocation")&&Object.keys(_).length===1||_.from==="literal"&&Object.keys(_).length===2&&Object.hasOwn(_,"value")&&(_.value===null||["string","boolean"].includes(typeof _.value)||typeof _.value=="number"&&Number.isFinite(_.value))&&JSON.stringify(_.value).length<=512||n(N,"invalid binding"))},f=(_,u,N)=>{d(_,u,N),!(_.from==="input"&&u[_.key].type==="uuid")&&(_.from==="literal"&&typeof _.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(_.value)||n(N,"record and allocation identifiers require a UUID binding"))},g=(_,u,N)=>{d(_,u,N),!(_.from==="input"&&u[_.key].type==="integer"&&u[_.key].minimum>=1)&&(_.from==="literal"&&Number.isSafeInteger(_.value)&&_.value>=1||n(N,"expectedRevision requires a positive integer binding"))},E="/data/concurrency";JSON.stringify(e).length>131072&&n(E,"declaration exceeds 128 KiB");let A=i(e,E,["version","admission","reads","quotas","commands"]);A.version!==1&&n(E,"unsupported version"),i(A.admission,E,["perSecond","burst","maxInFlight"]),s(A.admission.perSecond,1,1e3,E),s(A.admission.burst,1,1e3,E),s(A.admission.maxInFlight,1,1e3,E);let b=(_,u)=>{let N=new Set;for(let y of _)a(y?.code,u),N.has(y.code)&&n(u,"duplicate code"),N.add(y.code)};b(r(A.reads,32,E),E),b(r(A.quotas,16,E),E),b(r(A.commands,32,E),E);for(let _ of A.reads){let u=`${E}/reads/${_.code}`;i(_,u,["code","resourceCode","parameters","select","where","limit","scope","freshSeconds","staleSeconds","maxKeys","sourcePerSecond","dependencies"]);let N=c(_.resourceCode,u);p(_.parameters,u),["subject","application"].includes(_.scope)||n(u,"invalid cache scope"),_.scope==="application"&&N.dataPolicyCode&&n(u,"shared cache cannot bypass a row policy");let y=r(_.select,32,u);y.length||n(u,"select required"),y.forEach(h=>l(N,h,u));let O=r(_.dependencies,64,u);O.forEach(h=>l(N,h,u));for(let h of r(_.where||[],8,u))i(h,u,["field","value"]),l(N,h.field,u),d(h.value,_.parameters,u),_.scope==="application"&&h.value.from==="actor"&&n(u,"actor requires subject cache"),O.includes(h.field)||n(u,"filter dependency missing");y.some(h=>!O.includes(h))&&n(u,"selected field dependency missing"),s(_.limit,1,100,u),s(_.freshSeconds,1,300,u),s(_.staleSeconds,0,300,u),s(_.maxKeys,1,1e4,u),s(_.sourcePerSecond,1,20,u)}for(let _ of A.quotas){let u=`${E}/quotas/${_.code}`;i(_,u,["code","sourceResource","capacityField","allocationResource","allocationField","reservationSeconds"]);let N=c(_.sourceResource,u),y=c(_.allocationResource,u);l(N,_.capacityField,u)?.type!=="number.integer"&&n(u,"capacity must be an integer"),(l(y,_.allocationField,u)?.type!=="uuid"||l(y,_.allocationField,u)?.nullable!==!1)&&n(u,"allocation reference must be a uuid"),y.surface?.mutationOwner!=="queued-command"&&n(u,"allocation model must be command owned"),_.reservationSeconds!==void 0&&s(_.reservationSeconds,10,86400,u)}new Set(A.quotas.map(_=>_.allocationResource)).size!==A.quotas.length&&n(E,"an allocation model has exactly one pool owner");for(let _ of A.commands){let u=`${E}/commands/${_.code}`;i(_,u,["code","mode","intake","execution","capability","parameters","resourceKey","admission","deadlineSeconds","guards","operations","quota"]),_.mode!==void 0&&!["permit","durable"].includes(_.mode)&&n(u,"unsupported mode");let N=_.mode==="durable";if(p(_.parameters,u,N),d(_.resourceKey,_.parameters,u),o.some(y=>y.code===_.capability)||n(u,"command capability must be declared"),i(_.admission,u,["perSecond","burst","maxInFlight","maxQueue","maxWaitSeconds","permitSeconds"]),s(_.admission.perSecond,1,A.admission.perSecond,u),s(_.admission.burst,1,A.admission.burst,u),s(_.admission.maxInFlight,1,A.admission.maxInFlight,u),s(_.admission.maxQueue,1,1e4,u),s(_.admission.maxWaitSeconds,1,3600,u),(!N||_.admission.permitSeconds!==void 0)&&s(_.admission.permitSeconds,5,60,u),s(_.deadlineSeconds,10,3600,u),N){(_.operations!==void 0||_.guards!==void 0||_.quota!==void 0)&&n(u,"backend-plan does not accept static operations, guards or quota"),i(_.intake,u,["perSecond","burst","maxInFlight"]);for(let h of["perSecond","burst","maxInFlight"])s(_.intake[h],1,1e3,u);let y=i(_.execution,u,["kind","handlerCode","timeoutMs","resources","directory"]);y.kind!=="backend-plan"&&n(u,"durable requires backend-plan"),a(y.handlerCode,u),s(y.timeoutMs,100,3e4,u);let O=r(y.resources,32,u);O.length||n(u,"execution resources required"),new Set(O.map(h=>h.resourceCode)).size!==O.length&&n(u,"duplicate execution resource");for(let h of O){i(h,u,["resourceCode","readFields","writeOperations","writeFields"]);let C=c(h.resourceCode,u);for(let V of["readFields","writeFields"]){let M=r(h[V],64,u);new Set(M).size!==M.length&&n(u,"duplicate field"),M.forEach(P=>{V==="readFields"&&Rn.has(P)||l(C,P,u)})}let k=r(h.writeOperations,3,u);(new Set(k).size!==k.length||k.some(V=>!["create","update","increment"].includes(V)))&&n(u,"unsupported execution operation"),h.writeFields.some(V=>["id","revision","created_by","updated_by","created_at","updated_at"].includes(V))&&n(u,"record metadata is platform owned"),!k.length&&h.writeFields.length&&n(u,"write fields require an operation"),k.length&&!h.writeFields.length&&n(u,"write operations require fields"),A.quotas.some(V=>V.allocationResource===h.resourceCode)&&k.length&&n(u,"allocation references remain owned by their pool command")}if(y.directory!==void 0){i(y.directory,u,["mode","fields"]),y.directory.mode!=="current-initiator"&&n(u,"only current initiator allowed");let h=r(y.directory.fields,4,u);(!h.length||new Set(h).size!==h.length||h.some(C=>!["displayName","employeeNumber","primaryDepartment","departments"].includes(C)))&&n(u,"unsupported directory fields")}continue}(_.execution!==void 0||_.intake!==void 0)&&n(u,"execution and intake require durable mode");for(let y of r(_.guards||[],8,u)){i(y,u,["resourceCode","id","conditions"]);let O=c(y.resourceCode,u);f(y.id,_.parameters,u);for(let h of r(y.conditions,16,u)){i(h,u,["kind","field","operator","value"]);let C=l(O,h.field,u);["eq","neq","lt","lte","gt","gte"].includes(h.operator)||n(u,"unsupported guard"),h.kind==="database-now"?(C?.type!=="datetime"||!["lt","lte","gt","gte"].includes(h.operator)||h.value!==void 0)&&n(u,"database-now requires datetime and an ordering operator"):(h.kind!==void 0&&h.kind!=="value"&&n(u,"unsupported condition kind"),d(h.value,_.parameters,u))}}for(let y of r(_.operations,8,u)){i(y,u,["operation","resourceCode","id","expectedRevision","data"]);let O=c(y.resourceCode,u);O.surface?.mutationOwner!=="queued-command"&&n(u,"command mutations require command owned models");let h=A.quotas.find(C=>C.allocationResource===y.resourceCode);h&&(y.operation==="create"?_.quota?.action!=="allocate"||_.quota.pool!==h.code:Object.hasOwn(y.data||{},h.allocationField))&&n(u,"allocation references are owned by their pool command"),["create","update"].includes(y.operation)||n(u,"unsupported operation"),y.operation==="update"?(f(y.id,_.parameters,u),g(y.expectedRevision,_.parameters,u)):(y.id!==void 0||y.expectedRevision!==void 0)&&n(u,"create has no caller supplied id/revision"),i(y.data,u,Object.keys(y.data||{})),Object.keys(y.data).length>32&&n(u,"too many fields");for(let[C,k]of Object.entries(y.data))C==="id"&&n(u,"record identifiers are platform owned"),l(O,C,u),d(k,_.parameters,u,_.quota?.action==="allocate")}if(_.quota){let y=i(_.quota,u,["pool","action","units","mode","allocation"]),O=A.quotas.find(h=>h.code===y.pool);O||n(u,"unknown quota pool"),f(_.resourceKey,_.parameters,u),y.action==="allocate"?(i(y,u,["pool","action","units","mode"]),s(y.units,1,1e3,u),(!["committed","reserved"].includes(y.mode)||y.mode==="reserved"&&!O.reservationSeconds)&&n(u,"invalid allocation mode"),(_.operations.length!==1||_.operations[0].operation!=="create"||_.operations[0].resourceCode!==O.allocationResource||_.operations[0].data[O.allocationField]?.from!=="allocation")&&n(u,"allocation must atomically create its bound business record")):["confirm","release"].includes(y.action)?(i(y,u,["pool","action","allocation"]),f(y.allocation,_.parameters,u),_.operations.length&&n(u,"lifecycle owns allocation state; business reference remains immutable")):n(u,"invalid quota action")}else _.operations.length||n(u,"operations required")}let I=A.commands.filter(_=>_.mode==="durable").map(_=>_.execution.handlerCode);return new Set(I).size!==I.length&&n(E,"handler code must be unique"),JSON.parse(JSON.stringify(A))}var Pe=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"},Kn=["parentTransitions","childTransitions","fulfilledChildStatuses","lockedParentStatuses"],Go=["amountFieldCode","currencyFieldCode","relationFieldCode","parentFieldCode","rootFieldCode","statusFieldCode","parentRelationValue","childRelationValue"],Bt=e=>!!(e&&typeof e=="object"&&!Array.isArray(e)),Ut=e=>Array.isArray(e)?e.filter(Bt):[],ye=(e,t)=>{throw new Pe(e,t)},Un=e=>typeof e=="string"&&/^[A-Za-z0-9._:-]{1,128}$/.test(e),Bn=(e,t)=>e<t?-1:e>t?1:0;function Kt(e,t="/decimalReservationLifecycle"){if(e===void 0)return;if(!Bt(e)||Object.keys(e).some(i=>!Kn.includes(i))||Kn.some(i=>!Object.prototype.hasOwnProperty.call(e,i)))return ye(t,"\u5FC5\u987B\u5B8C\u6574\u58F0\u660E\u56DB\u9879\u89C4\u5219\uFF0C\u4E0D\u80FD\u5305\u542B\u672A\u77E5\u5C5E\u6027");let o=i=>{let s=e[i];if(!Array.isArray(s)||s.length>64)return ye(`${t}/${i}`,"\u72B6\u6001\u8FB9\u6700\u591A 64 \u6761");let a=new Set;return s.map((r,c)=>{let l=`${t}/${i}/${c}`;if(!Bt(r)||Object.keys(r).some(d=>d!=="from"&&d!=="to")||!Un(r.from)||!Un(r.to)||r.from===r.to)return ye(l,"\u72B6\u6001\u8FB9\u5FC5\u987B\u5305\u542B\u4E0D\u540C\u7684\u6709\u6548 from/to");let p=JSON.stringify([r.from,r.to]);return a.has(p)?ye(l,"\u72B6\u6001\u8FB9\u4E0D\u80FD\u91CD\u590D"):(a.add(p),{from:r.from,to:r.to})}).sort((r,c)=>Bn(r.from,c.from)||Bn(r.to,c.to))},n=i=>{let s=e[i];return!Array.isArray(s)||s.length<1||s.length>16||s.some(a=>!Un(a))||new Set(s).size!==s.length?ye(`${t}/${i}`,"\u72B6\u6001\u96C6\u5408\u5FC5\u987B\u5305\u542B 1 \u5230 16 \u4E2A\u4E0D\u91CD\u590D\u7684\u6709\u6548\u72B6\u6001"):[...s].sort(Bn)};return{parentTransitions:o("parentTransitions"),childTransitions:o("childTransitions"),fulfilledChildStatuses:n("fulfilledChildStatuses"),lockedParentStatuses:n("lockedParentStatuses")}}function Gn(e,t,o="/config/data/resources"){Ut(e).forEach((n,i)=>{let s=`${o}/${i}/decimalReservationLifecycle`,a=Kt(n.decimalReservationLifecycle,s);if(!a)return;let r=Ut(t).map(d=>d.platformAccess?.decimalReservation).filter(d=>Bt(d)&&d.resourceCode===n.code),c=r.find(d=>d.mode==="reserve");if(!c)return ye(s,"\u9700\u8981\u540C\u8D44\u6E90\u5DF2\u58F0\u660E\u7684 reserve \u52A8\u4F5C\u6620\u5C04");if(Go.some(d=>typeof c[d]!="string")||r.some(d=>Go.some(f=>d[f]!==c[f])))return ye(s,"\u540C\u8D44\u6E90\u989D\u5EA6\u52A8\u4F5C\u7684\u5B57\u6BB5\u6620\u5C04\u5FC5\u987B\u4E00\u81F4");let l=Ut(n.schema?.fields).find(d=>d.code===c.statusFieldCode);if(l?.type!=="option.single")return ye(s,"\u989D\u5EA6\u72B6\u6001\u5B57\u6BB5\u5FC5\u987B\u4E3A option.single");let p=new Set(Ut(l.options).map(d=>d.value));for(let d of Kn)if((d==="parentTransitions"||d==="childTransitions"?a[d].flatMap(g=>[g.from,g.to]):a[d]).some(g=>!p.has(g)))return ye(`${s}/${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(f=>a.lockedParentStatuses.includes(String(f)))))return ye(`${s}/lockedParentStatuses`,"\u9501\u5B9A\u7236\u72B6\u6001\u4E0D\u80FD\u5141\u8BB8\u65B0\u9884\u7559")})}var Jo=require("crypto");var qn=new Set(["option.single","user.single","department.single","resource-ref.single"]),tr=new Set(["option.multiple","cascade.single","cascade.multiple","user.multiple","department.multiple","resource-ref.multiple","address","location","json"]),zo=new Set(["option.multiple","cascade.single","cascade.multiple","user.multiple","department.multiple","resource-ref.multiple","file","image"]),nr=new Set(["option.single","user.single","department.single","resource-ref.single","signature","address","location"]),or=new Set([...qn,...zo,"signature","address","location","json"]);function ir(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=>Yo(n,o.has(n.code))).sort((n,i)=>n.code.localeCompare(i.code))}function Yo(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:mr(e),index:_r(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 sr(e,t){if(t.type==="subtable")return null;let o=oe(t.code),n=Ho(e,t),i=[n?` DEFAULT ${n}`:"",gr(o,t),ar(o,t)].join("");return`${o} ${t.storage}${i}`}function rr(e,t){return Ho(e,t)}function ar(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 cr(e){return e.type==="serial-number"||at(e.type)&&e.type!=="subtable"}function dr(e,t){return t.filter(o=>o.type==="serial-number").map(o=>{let n=qt(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 lr(e,t){let o=Gt(e);return t.filter(n=>n.type==="serial-number").map(n=>`ALTER SEQUENCE ${qt(e,n.code)} OWNED BY ${o}.${oe(n.code)}`)}function ur(e,t){return t.filter(o=>o.type==="serial-number").map(o=>`GRANT USAGE, SELECT ON SEQUENCE ${qt(e,o.code)} TO "openxiangda_data_api"`)}function fr(e,t){let o=Gt(e),n=[];for(let i of t){if(i.type==="subtable")continue;let s=oe(i.code),a=oe(Ce("idx",e,i.code,i.index));switch(i.index){case"btree":n.push(`CREATE INDEX IF NOT EXISTS ${a} ON ${o} (${s})`);break;case"btree-snapshot-expressions":{let r=oe(Ce("idx",e,i.code,"snapshot-value")),c=oe(Ce("idx",e,i.code,"snapshot-label"));n.push(`CREATE INDEX IF NOT EXISTS ${r} ON ${o} ((${s} ->> 'value'))`,`CREATE INDEX IF NOT EXISTS ${c} ON ${o} ((${s} ->> 'label'))`);break}case"gin-jsonb-path":n.push(`CREATE INDEX IF NOT EXISTS ${a} ON ${o} USING GIN (${s} jsonb_path_ops)`);break;case"gist-range":n.push(`CREATE INDEX IF NOT EXISTS ${a} ON ${o} USING GIST (${s})`);break;case"gin-trigram":{let r=qn.has(i.type)?`((${s} ->> 'label')) gin_trgm_ops`:`${s} gin_trgm_ops`;n.push(`CREATE INDEX IF NOT EXISTS ${a} ON ${o} USING GIN (${r})`);break}case"none":break}if(i.type==="serial-number"){let r=oe(Ce("uidx",e,i.code,"serial"));n.push(`CREATE UNIQUE INDEX IF NOT EXISTS ${r} ON ${o} (${s})`)}}return n}function pr(e,t,o,n){let i=Gt(e),s=Gt(t),a=oe(Ce("uidx",e,"environment_id","subtable-parent")),r=oe(Ce("idx",t,o,n,"subtable-child")),c=oe(Ce("fk",t,o,e)),l=oe(o),p=oe(n);return[`CREATE UNIQUE INDEX IF NOT EXISTS ${a} ON ${i} ("tenant_id", "app_code", "environment_key", "id")`,`CREATE INDEX IF NOT EXISTS ${r} ON ${s} ("tenant_id", "app_code", "environment_key", ${l}, ${p}, "id")`,`DO $native_subtable$ BEGIN
2
+ ALTER TABLE ${s}
3
3
  ADD CONSTRAINT ${c}
4
- FOREIGN KEY ("tenant_id", "app_code", "environment_key", ${u})
4
+ FOREIGN KEY ("tenant_id", "app_code", "environment_key", ${l})
5
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 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});
8
+ END $native_subtable$`]}function Ce(e,...t){return`${e}_${(0,Jo.createHash)("sha256").update(t.join(":")).digest("hex").slice(0,32)}`}function oe(e){if(!/^[A-Za-z_][A-Za-z0-9_]{0,62}$/.test(e))throw new Error("OPENXIANGDA_NATIVE_IDENTIFIER_INVALID");return`"${e}"`}function _r(e,t){return e.type==="subtable"?"none":t?"gin-trigram":e.indexed?["date-range","datetime-range"].includes(e.type)?"gist-range":qn.has(e.type)?"btree-snapshot-expressions":tr.has(e.type)?"gin-jsonb-path":"btree":"none"}function mr(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 or.has(e.type),"jsonb"}}function Ho(e,t){if(at(t.type)&&t.type!=="subtable")return"'[]'::jsonb";if(t.type!=="serial-number")return"";let o=qo(t.serial?.prefix||""),n=t.serial?.digits??6;return`(${o} || lpad(nextval(${qo(qt(e,t.code))})::text, ${n}, '0'))`}function gr(e,t){return zo.has(t.type)?` CHECK (${e} IS NULL OR jsonb_typeof(${e}) = 'array')`:nr.has(t.type)?` CHECK (${e} IS NULL OR jsonb_typeof(${e}) = 'object')`:""}function Gt(e){return`"app_data".${oe(e)}`}function qt(e,t){let o=Ce("seq",e,t);return`"app_data".${oe(o)}`}function qo(e){return`'${e.replace(/'/g,"''")}'`}var Xo=new Set(["option.single","option.multiple","user.single","user.multiple","department.single","department.multiple","resource-ref.single","resource-ref.multiple"]),Ar=new Set([...Xo,"cascade.single","cascade.multiple","file","image","signature","address","location","json"]),Qo=/^[A-Za-z][A-Za-z0-9_]{0,62}$/,Er=new Set(["__proto__","prototype","constructor"]),Jt=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 He(e,t){let o=Zo(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 zt(e){return!!(e&&e.field.type==="user.single"&&e.valuePath==="value")}function Jn(e,t,o){if(!e||!t||!br(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 s=i.slice(9),r=o.get(n.source?.resourceCode||"")?.get(s)?.type;return t.valueType==="uuid"?r==="uuid":["text.short","text.long","serial-number"].includes(r||"")}function Ir(e,t){let o=Zo(t);if(!o)throw new Jt(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 br(e){let{field:t,valuePath:o}=e;if(!o)return!Ar.has(t.type);if(o==="value")return Xo.has(t.type);if(!o.startsWith("snapshot."))return!1;let n=o.slice(9);return Qo.test(n)&&t.type.startsWith("resource-ref.")&&!!t.source?.snapshotFields?.includes(n)}function Zo(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=>!Qo.test(o)||Er.has(o))||t.length===2&&t[1]!=="value"||t.length===3&&t[1]!=="snapshot"?null:t}var yr=new Set(["option.single","user.single","department.single","resource-ref.single"]),Nr=new Set(["text.short","text.long","text.rich","number.integer","number.decimal","boolean","date","time","datetime","uuid","serial-number"]),Tr=new Set(["value","label","description","color"]),Or=new Set(["avatarUrl","employeeNo","title","mobile","email"]),hr=new Set(["fullPath","parent.value","parent.label"]),Rr=new Set(["country.value","country.label","province.value","province.label","city.value","city.label","district.value","district.label","street.value","street.label","detail","fullAddress"]),Cr=new Set(["longitude","latitude","accuracy"]),Sr=new Set(["address","name","province","city","district","source"]);function wr(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=$r(n,t);if(!Object.keys(i).length)return n;let s={...n};return Object.defineProperty(s,"queryPathTypes",{configurable:!1,enumerable:!1,writable:!1,value:Object.freeze(i)}),s})}}))}function Dr(e,t){if(yr.has(e.type)&&Tr.has(t)||e.type==="user.single"&&Or.has(t)||e.type==="department.single"&&hr.has(t))return lt(t);if(e.type==="resource-ref.single"){let o=e.queryPathTypes?.[t];return o?{parts:t.split("."),type:o}:null}if(e.type==="address"&&Rr.has(t))return lt(t);if(e.type==="location"){if(Cr.has(t))return{parts:[t],type:"number.decimal"};if(Sr.has(t))return lt(t);if(t==="capturedAt")return{parts:[t],type:"datetime"}}return null}function $r(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}`,Nr.has(i.type)?i.type:"json"]]:[]})):{}}function lt(e){return{parts:e.split("."),type:"text.short"}}var Hn=["exact-v1","nfkc-space-v1","nfkc-upper-ascii-v1"],ed=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"},zn=e=>!!(e&&typeof e=="object"&&!Array.isArray(e)),ie=(e,t)=>{throw new Xe(e,t)},Yt=(e,t)=>e<t?-1:e>t?1:0,Ht=(e,t,o)=>{Object.keys(e).some(n=>!t.includes(n))&&ie(o,"\u4E0D\u652F\u6301\u672A\u77E5\u5C5E\u6027")};function Xn(e,t,o="/uniqueKeys"){if(e===void 0)return;if(!Array.isArray(e)||e.length>8)return ie(o,"\u6BCF\u8D44\u6E90\u6700\u591A 8 \u6761\u89C4\u5219");let n=new Map(t.map(s=>[s.code,s])),i=new Set;return e.map((s,a)=>{let r=`${o}/${a}`;if(!zn(s))return ie(r,"\u89C4\u5219\u5FC5\u987B\u662F\u5BF9\u8C61");if(Ht(s,["code","fields","when"],r),typeof s.code!="string"||!/^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/.test(s.code)||s.code.length>20||i.has(s.code))return ie(`${r}/code`,"\u9700\u8981\u4E0D\u91CD\u590D\u4E14\u4E0D\u8D85\u8FC7 20 \u5B57\u7B26\u7684 lower-kebab-case \u6807\u8BC6");if(i.add(s.code),!Array.isArray(s.fields)||s.fields.length<1||s.fields.length>4)return ie(`${r}/fields`,"\u5FC5\u987B\u9009\u62E9 1 \u5230 4 \u4E2A\u5B57\u6BB5");let c=new Set,l=s.fields.map((g,E)=>{let A=`${r}/fields/${E}`;if(!zn(g))return ie(A,"\u5B57\u6BB5\u5FC5\u987B\u662F\u5BF9\u8C61");Ht(g,["fieldCode","normalizer"],A);let b=n.get(g.fieldCode);if(!b||!["text.short","uuid","option.single","resource-ref.single"].includes(b.type)||c.has(g.fieldCode))return ie(`${A}/fieldCode`,"\u9700\u8981\u4E0D\u91CD\u590D\u7684\u77ED\u6587\u672C\u3001UUID\u3001\u5355\u9009\u6216\u5355\u8BB0\u5F55\u5F15\u7528\u5B57\u6BB5");c.add(g.fieldCode);let I=g.normalizer===void 0?"exact-v1":g.normalizer;return!Hn.includes(I)||b.type!=="text.short"&&I!=="exact-v1"?ie(`${A}/normalizer`,"\u5F52\u4E00\u5316\u65B9\u5F0F\u4E0D\u652F\u6301\u6216\u4E0E\u5B57\u6BB5\u7C7B\u578B\u4E0D\u7B26"):{fieldCode:b.code,normalizer:I}}).sort((g,E)=>Yt(g.fieldCode,E.fieldCode)),p=s.when===void 0?[]:s.when;if(!Array.isArray(p)||p.length>4)return ie(`${r}/when`,"\u6700\u591A 4 \u4E2A\u5408\u53D6\u6761\u4EF6");let d=new Set,f=p.map((g,E)=>{let A=`${r}/when/${E}`;if(!zn(g))return ie(A,"\u6761\u4EF6\u5FC5\u987B\u662F\u5BF9\u8C61");let b=n.get(g.fieldCode);if(!b)return ie(`${A}/fieldCode`,"\u5B57\u6BB5\u4E0D\u5B58\u5728");let I;if(g.operator==="empty"||g.operator==="nonempty"){if(Ht(g,["fieldCode","operator"],A),b.type!=="text.short")return ie(A,"\u7A7A\u503C\u6761\u4EF6\u4EC5\u652F\u6301\u77ED\u6587\u672C");I={fieldCode:b.code,operator:g.operator}}else if(g.operator==="in"||g.operator==="notIn"){Ht(g,["fieldCode","operator","values"],A);let u=new Set((b.options??[]).map(N=>N.value));if(b.type!=="option.single"||!Array.isArray(g.values)||g.values.length<1||g.values.length>16||g.values.some(N=>typeof N!="string"||N.length<1||N.length>128||!u.has(N))||new Set(g.values).size!==g.values.length)return ie(A,"\u96C6\u5408\u6761\u4EF6\u9700\u8981 1 \u5230 16 \u4E2A\u4E0D\u91CD\u590D\u7684\u5DF2\u58F0\u660E\u5355\u9009\u503C");I={fieldCode:b.code,operator:g.operator,values:[...g.values].sort(Yt)}}else return ie(`${A}/operator`,"\u53EA\u652F\u6301 empty\u3001nonempty\u3001in \u548C notIn");let _=JSON.stringify(I);return d.has(_)?ie(A,"\u6761\u4EF6\u4E0D\u80FD\u91CD\u590D"):(d.add(_),I)}).sort((g,E)=>Yt(JSON.stringify(g),JSON.stringify(E)));return{code:s.code,fields:l,when:f}}).sort((s,a)=>Yt(s.code,a.code))}var Yn={type:"string",pattern:"^[A-Za-z_][A-Za-z0-9_]{0,62}$"},kr={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:Yn,normalizer:{enum:[...Hn]}}}},when:{type:"array",maxItems:4,uniqueItems:!0,items:{oneOf:[{type:"object",additionalProperties:!1,required:["fieldCode","operator"],properties:{fieldCode:Yn,operator:{enum:["empty","nonempty"]}}},{type:"object",additionalProperties:!1,required:["fieldCode","operator","values"],properties:{fieldCode:Yn,operator:{enum:["in","notIn"]},values:{type:"array",minItems:1,maxItems:16,uniqueItems:!0,items:{type:"string",minLength:1,maxLength:128}}}}]}}}}};var ei={"openxiangda.workflow.instance.completed.v2":"commit","openxiangda.workflow.instance.rejected.v2":"release","openxiangda.workflow.instance.withdrawn.v2":"release"};function ti(e,t){let o=()=>{throw new Error("NATIVE_EVENT_DECIMAL_RESERVATION_INVALID")},n=f=>!f||typeof f!="object"||Array.isArray(f)?o():f,i=n(e);if(Object.keys(i).some(f=>!["resourceCode","workflowCode","outcomes"].includes(f))||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 s=t.resources.find(f=>f.code===i.resourceCode),a=t.reservations.find(f=>f.mode==="reserve"&&f.resourceCode===i.resourceCode),r=t.workflows.find(f=>f.code===i.workflowCode);if(!s||!a||!r||r.resourceCode!==s.code)return o();let c=s.fields.find(f=>f.code===a.statusFieldCode);if(c?.type!=="option.single")return o();let l=new Set(c.options?.map(f=>f.value)),p=new Set,d=i.outcomes.map(f=>{let g=n(f),E=g.eventType;return Object.keys(g).some(A=>!["eventType","mode","eligibleChildStatuses"].includes(A))||typeof E!="string"||!Object.prototype.hasOwnProperty.call(ei,E)||!t.eventTypes.includes(E)||p.has(E)||g.mode!==ei[E]||!Array.isArray(g.eligibleChildStatuses)||!g.eligibleChildStatuses.length||g.eligibleChildStatuses.length>16||new Set(g.eligibleChildStatuses).size!==g.eligibleChildStatuses.length||g.eligibleChildStatuses.some(A=>typeof A!="string"||!/^[A-Za-z0-9._:-]{1,128}$/.test(A)||!l.has(A))?o():(p.add(E),{eventType:E,mode:g.mode,eligibleChildStatuses:[...g.eligibleChildStatuses].sort()})}).sort((f,g)=>f.eventType.localeCompare(g.eventType));return{resourceCode:i.resourceCode,workflowCode:i.workflowCode,outcomes:d}}function ni(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(s=>({value:s.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 Xt=class extends Error{constructor(o,n){super(n);this.pointer=o}pointer;code="NATIVE_EVENT_ACTION_INVALID"};function Qn(e,t,o="/events/subscriptions"){if(e.execution===void 0)return;let n=(A,b)=>{throw new Xt(`${o}${A}`,b)},i=(A,b,I)=>((!A||typeof A!="object"||Array.isArray(A)||Object.keys(A).some(_=>!I.includes(_)))&&n(b,"Invalid action object or unsupported property"),A),s=i(e.execution,"/execution",["kind","version","operations"]);(s.kind!=="native-data"||s.version!==1)&&n("/execution","Expected native-data version 1"),e.platformAccess&&n("/platformAccess","Native actions do not use application runtime capabilities"),(!Array.isArray(e.eventTypes)||!e.eventTypes.length||e.eventTypes.some(A=>!/^openxiangda\.data\.record\.(created|updated|deleted)\.v2$/.test(A)))&&n("/eventTypes","Native data actions require declared data events");let a=e.filter?.resourceCodes;(!Array.isArray(a)||!a.length||a.length>20)&&n("/filter/resourceCodes","Native actions require explicit source resources");let r=new Map(t.map(A=>[A.code,A])),c=a.map(A=>{let b=r.get(A);return b||n("/filter/resourceCodes","Unknown source resource"),new Set((b.schema?.fields||[]).map(I=>I.code))}),l=new Set(e.payload?.fields||[]),p=e.payload?.includeChanges===!0,d=(A,b)=>{let I=i(A,b,["source","path","value"]);if(I.source==="literal"){(!Object.hasOwn(I,"value")||Object.hasOwn(I,"path"))&&n(b,"Literal binding requires only value");let y;try{y=JSON.stringify(I.value)}catch{n(b,"Literal must be JSON")}return(y===void 0||Buffer.byteLength(y)>65536)&&n(b,"Literal is too large or not JSON"),{source:"literal",value:JSON.parse(y)}}(I.source!=="event"||typeof I.path!="string"||Object.hasOwn(I,"value"))&&n(b,"Expected a literal or event binding");let _=I.path.split(".");(_.length>8||_.some(y=>!/^[A-Za-z0-9_-]+$/.test(y)||["__proto__","prototype","constructor"].includes(y)))&&n(b,"Invalid event path");let u=/^data\.projection\.([A-Za-z][A-Za-z0-9_]{0,62})$/.exec(I.path),N=/^data\.changes\.([A-Za-z][A-Za-z0-9_]{0,62})\.(before|after)$/.exec(I.path);if(u||N){let y=(u||N)[1];c.some(O=>!O.has(y))&&n(b,"Source field must exist on every filtered resource"),l.add(y),N&&(p=!0)}else["id","time","type","subject","data.recordId","data.revision","data.operation","data.resourceCode"].includes(I.path)||n(b,"Event path is not part of the data event contract");return{source:"event",path:I.path}};(!Array.isArray(s.operations)||s.operations.length<1||s.operations.length>16)&&n("/execution/operations","Expected 1 to 16 operations");let f={},g=s.operations.map((A,b)=>{let I=`/execution/operations/${b}`,_=i(A,I,["operation","resourceCode","data","id","expectedRevision"]);["create","update","delete"].includes(_.operation)||n(I,"Unsupported Native operation");let u=r.get(_.resourceCode);u||n(I,"Unknown action target resource");let N=new Map((u.schema?.fields||[]).map(O=>[O.code,O])),y=_.data===void 0?{}:i(_.data,`${I}/data`,[...N.keys()]);return Object.keys(y).length>32&&n(I,"Maximum 32 mapped fields per operation"),_.operation==="create"&&(_.id!==void 0||_.expectedRevision!==void 0)&&n(I,"Create does not accept id or expectedRevision"),_.operation==="delete"&&_.data!==void 0&&n(I,"Delete does not accept data"),Object.keys(y).some(O=>N.get(O)?.type==="serial-number")&&n(I,"Generated fields cannot be assigned"),f[_.resourceCode]=X(u),{operation:_.operation,resourceCode:_.resourceCode,..._.operation==="create"?{}:{id:d(_.id,`${I}/id`),expectedRevision:d(_.expectedRevision,`${I}/expectedRevision`)},..._.operation==="delete"?{}:{data:Object.fromEntries(Object.entries(y).map(([O,h])=>[O,d(h,`${I}/data/${O}`)]))}}});(l.size>32||[...l].some(A=>c.some(b=>!b.has(A))))&&n("/payload/fields","Payload must contain at most 32 declared source fields");let E={kind:"native-data",version:1,operations:g,resourceDigests:f};return Buffer.byteLength(JSON.stringify(E))>65536&&n("/execution","Action plan exceeds 64 KiB"),{execution:{...E,digest:X(E)},payload:{includeChanges:p,fields:[...l].sort()}}}function ke(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)?e:void 0}function eo(e,t){if(e?.instanceCommands===void 0)return[];let o=ke(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,s]of Object.entries(o)){let a=ke(s),r=i==="withdraw"?["beforeFact"]:["beforeFact","capability"];if(!a||Object.keys(a).some(c=>!r.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,l=ke(e.inputSchema),p=ke(ke(l?.properties)?.[c]),d=ke(ke(e.subject)?.factProjection)?.[c],f=t?.fields.get(d);(typeof c!="string"||!/^[A-Za-z][A-Za-z0-9_]{0,62}$/.test(c)||!Array.isArray(l?.required)||!l.required.includes(c)||p?.type!=="string"||p?.format!=="date-time"||typeof d!="string"||t&&(f?.type!=="datetime"||f.nullable===!0))&&n.push(`WORKFLOW_INSTANCE_COMMAND_DEADLINE_FACT_INVALID:${i}`)}}return n}function Vr(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 Zn(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,s,a,r]=t,c=t[8],l=new Date(Date.UTC(Number(o),Number(n),0)).getUTCDate();if(Number(n)<1||Number(n)>12||Number(i)<1||Number(i)>l||Number(s)>23||Number(a)>59||Number(r)>59||c!=="Z"&&(Number(c.slice(1,3))>23||Number(c.slice(4))>59))return null;let p=Date.parse(e);return Number.isFinite(p)?p:null}function Fr(e,t,o,n){let i=e?.[t];if(!i||t==="terminate"&&i.beforeFact===void 0)return null;let s=i.beforeFact,a=ke(o),r=s&&a&&Object.hasOwn(a,s)?Zn(a[s]):null,c=n instanceof Date?n.getTime():Zn(n);return r===null||c===null||!Number.isFinite(c)?"WORKFLOW_V2_CANCELLATION_DEADLINE_INVALID":c<r?null:"WORKFLOW_V2_CANCELLATION_DEADLINE_PASSED"}var Qe="openxiangda.workflow.step.requested.v2",oo=[Qe,"openxiangda.workflow.step.result_received.v2","openxiangda.workflow.step.completed.v2","openxiangda.workflow.step.continuation_failed.v2"],Qt=16384,si=2048,vr="steps",io=/^[A-Za-z][A-Za-z0-9_-]{0,127}$/,ri=/^[A-Za-z][A-Za-z0-9_]{0,62}$/,Le=new Set(["__proto__","prototype","constructor"]),B=e=>!!e&&typeof e=="object"&&!Array.isArray(e)&&[Object.prototype,null].includes(Object.getPrototypeOf(e)),ai=e=>{try{let t=JSON.stringify(e);return t===void 0?1/0:new TextEncoder().encode(t).length}catch{return 1/0}},Ze=(e,t,o=0)=>{if(o>32)return!1;if(e===t)return!0;if(Array.isArray(e)&&Array.isArray(t))return e.length===t.length&&e.every((s,a)=>Ze(s,t[a],o+1));if(!B(e)||!B(t))return!1;let n=Object.keys(e).filter(s=>e[s]!==void 0),i=Object.keys(t).filter(s=>t[s]!==void 0);return n.length===i.length&&n.every(s=>Object.hasOwn(t,s)&&Ze(e[s],t[s],o+1))};function to(e,t){let o=0,n=(i,s)=>++o>1e4||s>8?!1:i===null||typeof i=="boolean"||typeof i=="string"?!0:typeof i=="number"?Number.isFinite(i):Array.isArray(i)?i.length<=200&&i.every(a=>n(a,s+1)):B(i)&&Object.keys(i).length<=32&&Object.keys(i).every(a=>!Le.has(a))&&Object.values(i).every(a=>n(a,s+1));return ai(e)<=t&&n(e,0)}function ci(e){return!B(e)||Object.keys(e).some(t=>!["executionId","handlerVersion","inputDigest","expectedFactRevision","output","receipt"].includes(t))?!1:/^[a-f0-9]{8}-[a-f0-9]{4}-[1-5][a-f0-9]{3}-[89ab][a-f0-9]{3}-[a-f0-9]{12}$/i.test(e.executionId||"")&&Number.isSafeInteger(e.handlerVersion)&&e.handlerVersion>=1&&e.handlerVersion<=1e6&&/^[a-f0-9]{64}$/.test(e.inputDigest||"")&&Number.isSafeInteger(e.expectedFactRevision)&&e.expectedFactRevision>=0&&B(e.output)&&to(e.output,Qt)&&(e.receipt===void 0||B(e.receipt)&&to(e.receipt,si))}function Pr(e){return B(e)&&Object.keys(e).every(t=>["executionId","nodeId","handlerCode","handlerVersion","mode","input","inputDigest","expectedFactRevision"].includes(t))&&typeof e.nodeId=="string"&&io.test(e.nodeId)&&!Le.has(e.nodeId)&&typeof e.handlerCode=="string"&&/^[a-z][a-z0-9-]{0,100}$/.test(e.handlerCode)&&e.handlerCode.endsWith(`-v${e.handlerVersion}`)&&["pure","reconciled-effect"].includes(e.mode)&&ci({executionId:e.executionId,handlerVersion:e.handlerVersion,inputDigest:e.inputDigest,expectedFactRevision:e.expectedFactRevision,output:e.input})}function ut(e,t,o=Qt){if(!to(t,o))return!1;let n=1e4,i=(s,a,r)=>{if(--n<0||r>8||!B(s))return!1;let c=a===null?"null":Array.isArray(a)?"array":typeof a=="number"&&Number.isSafeInteger(a)?"integer":typeof a,l=Array.isArray(s.type)?s.type:[s.type];if(!l.includes(c)&&!(c==="integer"&&l.includes("number"))||s.enum!==void 0&&(!Array.isArray(s.enum)||!s.enum.some(p=>Ze(p,a)))||Object.hasOwn(s,"const")&&!Ze(s.const,a))return!1;if(typeof a=="number")return Number.isFinite(a)&&(s.minimum===void 0||a>=s.minimum)&&(s.maximum===void 0||a<=s.maximum);if(typeof a=="string"){let p=Array.from(a).length;return(s.minLength===void 0||p>=s.minLength)&&(s.maxLength===void 0||p<=s.maxLength)}return Array.isArray(a)?a.length<=s.maxItems&&(s.minItems===void 0||a.length>=s.minItems)&&a.every(p=>i(s.items,p,r+1)):B(a)?!B(s.properties)||Object.keys(a).some(p=>Le.has(p)||!Object.hasOwn(s.properties,p))||(Array.isArray(s.required)?s.required:[]).some(p=>!Object.hasOwn(a,p))||s.minProperties!==void 0&&Object.keys(a).length<s.minProperties||s.maxProperties!==void 0&&Object.keys(a).length>s.maxProperties?!1:Object.entries(a).every(([p,d])=>i(s.properties[p],d,r+1)):a===null||typeof a=="boolean"};return i(e,t,0)}function di(e){return typeof e=="string"&&e.length<=256&&e.split(".").length<=8&&e.split(".").every(t=>io.test(t)&&!Le.has(t))}function ft(e){let t=0,o=(n,i)=>{if(!B(n)||i>6||++t>256||Object.keys(n).some(r=>!["type","title","description","properties","required","additionalProperties","items","maxItems","minItems","maxLength","minLength","minimum","maximum","enum","const","maxProperties","minProperties"].includes(r)))return!1;let s=Array.isArray(n.type)?n.type:[n.type];if(!s.length||s.length>2||s.some(r=>!["object","array","string","integer","number","boolean","null"].includes(r))||s.length>1&&(!s.includes("null")||new Set(s).size!==s.length))return!1;for(let r of["title","description"])if(n[r]!==void 0&&(typeof n[r]!="string"||n[r].length>2e3))return!1;for(let r of["minimum","maximum"])if(n[r]!==void 0&&(typeof n[r]!="number"||!Number.isFinite(n[r])))return!1;for(let[r,c]of[["maxItems",200],["minItems",200],["maxLength",16384],["minLength",16384],["maxProperties",32],["minProperties",32]])if(n[r]!==void 0&&(!Number.isSafeInteger(n[r])||n[r]<0||n[r]>c))return!1;for(let[r,c]of[["minimum","maximum"],["minItems","maxItems"],["minLength","maxLength"],["minProperties","maxProperties"]])if(n[r]!==void 0&&n[c]!==void 0&&n[r]>n[c])return!1;if(["properties","required","additionalProperties","maxProperties","minProperties"].some(r=>n[r]!==void 0)&&!s.includes("object")||["items","maxItems","minItems"].some(r=>n[r]!==void 0)&&!s.includes("array")||["maxLength","minLength"].some(r=>n[r]!==void 0)&&!s.includes("string")||["minimum","maximum"].some(r=>n[r]!==void 0)&&!s.some(r=>r==="integer"||r==="number")||n.enum!==void 0&&(!Array.isArray(n.enum)||!n.enum.length||n.enum.length>100)||s.includes("object")&&(!B(n.properties)||n.additionalProperties!==!1||Object.keys(n.properties).length>32||Object.keys(n.properties).some(r=>!ri.test(r)||Le.has(r))||n.required!==void 0&&(!Array.isArray(n.required)||new Set(n.required).size!==n.required.length||n.required.some(r=>typeof r!="string"||!Object.hasOwn(n.properties,r)))||n.minProperties!==void 0&&n.minProperties>Object.keys(n.properties).length||n.maxProperties!==void 0&&n.maxProperties<(n.required?.length||0)||!Object.values(n.properties).every(r=>o(r,i+1)))||s.includes("array")&&(!Number.isSafeInteger(n.maxItems)||!o(n.items,i+1)))return!1;let a={...n};return delete a.enum,delete a.const,!(n.enum!==void 0&&(!n.enum.every(r=>ut(a,r))||n.enum.some((r,c)=>n.enum.slice(0,c).some(l=>Ze(r,l))))||Object.hasOwn(n,"const")&&!ut(a,n.const))};return B(e)&&e.type==="object"&&ai(e)<=Qt&&o(e,0)}function pt(e){let t=Object.fromEntries(Object.values(e.nodes||{}).filter(o=>o?.kind==="action").map(o=>[o.id,o.outputSchema]));return Object.keys(t).length?{...e.inputSchema,properties:{...e.inputSchema?.properties,steps:{type:"object",additionalProperties:!1,properties:t}}}:e.inputSchema||{}}function li(e,t){let o=e;for(let n of t.split(".")){if(!B(o?.properties)||!Object.hasOwn(o.properties,n))return;o=o.properties[n]}return B(o)?o:void 0}var oi=(e,t)=>!!li(e,t);function Lr(e){return B(e)&&Object.keys(e).every(t=>["version","mode","inputSchema","outputSchema"].includes(t))&&Number.isSafeInteger(e.version)&&e.version>=1&&e.version<=1e6&&["pure","reconciled-effect"].includes(e.mode)&&ft(e.inputSchema)&&ft(e.outputSchema)}function ii(e){return e.kind==="approval"?[e.onApprove,e.onReject]:e.kind==="condition"?[...Array.isArray(e.branches)?e.branches.map(t=>t.target):[],e.otherwise]:e.kind==="cc"||e.kind==="action"?[e.next]:[]}function no(e,t=0){return!B(e)||t>16?[]:e.op==="path"?typeof e.path=="string"?[e.path]:[]:["left","right","value"].flatMap(o=>no(e[o],t+1)).concat(Array.isArray(e.values)?e.values.flatMap(o=>no(o,t+1)):[])}function _t(e,t){if(!B(e)||!B(e.nodes))return["WORKFLOW_STEP_DEFINITION_INVALID"];let o=e.nodes,n=Object.entries(o).filter(([,r])=>r?.kind==="action");if(!n.length)return[];let i=[];Object.hasOwn(e.inputSchema?.properties||{},"steps")&&i.push("WORKFLOW_STEP_FACT_NAMESPACE_RESERVED");let s=pt(e);for(let[r,c]of n){(Object.keys(c).some(d=>!["id","kind","title","next","handler","inputSchema","outputSchema","inputs"].includes(d))||c.id!==r||!io.test(r)||Le.has(r)||typeof c.title!="string"||!c.title.trim()||c.title.length>255||typeof c.next!="string"||!Object.hasOwn(o,c.next))&&i.push(`WORKFLOW_STEP_NODE_INVALID:${r}`);let l=c.handler;(!B(l)||Object.keys(l).some(d=>!["code","version","mode"].includes(d))||!Number.isSafeInteger(l.version)||l.version<1||l.version>1e6||!/^[a-z][a-z0-9-]{0,100}$/.test(l.code||"")||!String(l.code).endsWith(`-v${l.version}`)||!["pure","reconciled-effect"].includes(l.mode))&&i.push(`WORKFLOW_STEP_HANDLER_INVALID:${r}`);let p=ft(c.inputSchema);if((!p||!ft(c.outputSchema))&&i.push(`WORKFLOW_STEP_SCHEMA_INVALID:${r}`),!B(c.inputs)||Object.keys(c.inputs).length>32){i.push(`WORKFLOW_STEP_INPUTS_INVALID:${r}`);continue}for(let d of Array.isArray(c.inputSchema?.required)?c.inputSchema.required:[])Object.hasOwn(c.inputs,d)||i.push(`WORKFLOW_STEP_INPUT_REQUIRED:${r}:${d}`);for(let[d,f]of Object.entries(c.inputs)){if(!ri.test(d)||Le.has(d)||!Object.hasOwn(c.inputSchema?.properties||{},d)||!B(f)){i.push(`WORKFLOW_STEP_INPUT_INVALID:${r}:${d}`);continue}if(f.source==="literal")(!p||Object.keys(f).some(g=>!["source","value"].includes(g))||!Object.hasOwn(f,"value")||!ut(c.inputSchema.properties[d],f.value))&&i.push(`WORKFLOW_STEP_LITERAL_INVALID:${r}:${d}`);else if(f.source!=="fact"||Object.keys(f).some(g=>!["source","path"].includes(g))||!di(f.path)||!oi(s,f.path))i.push(`WORKFLOW_STEP_FACT_PATH_INVALID:${r}:${d}`);else if(p){let g=li(s,f.path),E=c.inputSchema.properties[d],A=Array.isArray(g.type)?g.type:[g.type],b=Array.isArray(E.type)?E.type:[E.type];A.some(I=>!b.includes(I)&&!(I==="integer"&&b.includes("number")))&&i.push(`WORKFLOW_STEP_FACT_TYPE_MISMATCH:${r}:${d}`)}}}let a=(r,c)=>{let l=new Set,p=[e.startAt||""];for(;p.length&&l.size<=200;){let d=p.shift();if(!(d===c||l.has(d)||!o[d])){if(d===r)return!0;l.add(d),p.push(...ii(o[d]))}}return!1};for(let[r,c]of Object.entries(o)){if(!B(c))continue;let l=c.kind==="action"?Object.values(c.inputs||{}).flatMap(d=>d?.source==="fact"?[d.path]:[]):(Array.isArray(c.branches)?c.branches:[]).flatMap(d=>no(d?.when)),p=t?.bindings?.[c.binding];p&&l.push(...[p.inputPath,p.departmentIdFrom,p.resourceIdFrom,p.scope?.valueFrom].filter(d=>typeof d=="string"));for(let d of l.filter(f=>typeof f=="string"&&f.startsWith("steps."))){let f=d.split(".")[1];(o[f]?.kind!=="action"||f===r||!oi(s,d)||a(r,f))&&i.push(`WORKFLOW_STEP_OUTPUT_NOT_AVAILABLE:${r}:${d}`)}}if(t)for(let[,r]of n){let c=new Set,l=[r.next];for(;l.length&&c.size<=200;){let p=l.shift();if(c.has(p)||!B(o[p]))continue;c.add(p);let d=o[p];if(!(d.kind==="action"||d.kind==="end")){if(d.kind==="approval"){let f=t.bindings?.[d.binding];f&&["application_provider","initiator_select"].includes(f.provider)&&i.push(`WORKFLOW_STEP_NEXT_PROVIDER_REQUIRES_PREPARED_RESULT:${p}`);continue}l.push(...ii(d))}}}return[...new Set(i)]}function xr(e,t){let o={};for(let[n,i]of Object.entries(e.inputs)){let s=i.source==="literal"?i.value:i.path.split(".").reduce((a,r)=>B(a)&&Object.hasOwn(a,r)?a[r]:void 0,t);s!==void 0&&(o[n]=s)}if(!ut(e.inputSchema,o))throw new Error("WORKFLOW_STEP_INPUT_SCHEMA_INVALID");return o}function so(e,t,o){let n=Zt(e),i=[];Object.keys(n).length&&!o&&i.push("WORKFLOW_STEP_BACKEND_REQUIRED");for(let s of Object.keys(n)){let a=t.find(r=>r.code===s);(!a||a.execution||a.action||!Array.isArray(a.eventTypes)||a.eventTypes.length!==1||a.eventTypes[0]!==Qe||!B(a.filter)||Object.keys(a.filter).length!==1||!B(a.filter.workflowStep)||Object.keys(a.filter.workflowStep).length!==1||a.filter.workflowStep.handlerCode!==s||!B(a.payload)||a.payload.includeChanges!==!1||!Array.isArray(a.payload.fields)||a.payload.fields.length)&&i.push(`WORKFLOW_STEP_SUBSCRIPTION_INVALID:${s}`)}for(let s of t)(s.eventTypes?.includes(Qe)&&!n[s.code]||s.filter?.workflowStep&&!n[s.code])&&i.push(`WORKFLOW_STEP_HANDLER_NOT_DECLARED:${s.code}`);return i}function Zt(e){let t={};for(let o of e){let n=_t(o);if(n.length)throw new Error(n.join("; "));for(let i of Object.values(o.nodes||{})){if(i.kind!=="action")continue;let s={version:i.handler.version,mode:i.handler.mode,inputSchema:i.inputSchema,outputSchema:i.outputSchema},a=t[i.handler.code];if(a&&!Ze(a,s))throw new Error(`WORKFLOW_STEP_HANDLER_CONTRACT_CONFLICT:${i.handler.code}`);t[i.handler.code]=s}}return t}var de=e=>e&&typeof e=="object"&&!Array.isArray(e)?e:{},xe=(e,t)=>typeof e=="string"&&!!e.trim()&&e.length<=t,jr=/^[A-Za-z][A-Za-z0-9_-]*(?:\.[A-Za-z][A-Za-z0-9_-]*){0,15}$/,ro=e=>typeof e=="string"&&e.length<=256&&jr.test(e)&&!e.split(".").some(t=>["__proto__","prototype","constructor"].includes(t));function en(e,t){let o=de(e),n=!0;for(let i of t.split(".")){n&&=Array.isArray(o.required)&&o.required.includes(i);let s=de(o.properties)[i];if(!s||typeof s!="object")return null;o=de(s)}return{schema:o,required:n}}function ao(e){let t=new Set,o=[],n=2048,i=(s,a)=>{if(--n<0||a>20){o.push("WORKFLOW_EXPRESSION_BUDGET_EXCEEDED");return}let r=de(s);if(r.op==="path")ro(r.path)?t.add(r.path):o.push("WORKFLOW_EXPRESSION_PATH_INVALID");else{if(r.op==="literal")return;if(r.op==="and"||r.op==="or")if(!Array.isArray(r.values)||!r.values.length||r.values.length>128)o.push("WORKFLOW_EXPRESSION_GROUP_INVALID");else for(let c of r.values){if(n<0)break;i(c,a+1)}else r.op==="not"||r.op==="exists"?i(r.value,a+1):["eq","neq","gt","gte","lt","lte","in","contains"].includes(String(r.op))?(i(r.left,a+1),i(r.right,a+1)):o.push("WORKFLOW_EXPRESSION_OPERATOR_INVALID")}};return i(e,0),{paths:[...t],errors:[...new Set(o)]}}function co(e){if(e?.readability===void 0)return[];let t=[],o=pt(e),n=de(e.readability);(Object.keys(n).some(r=>!["variables","logic"].includes(r))||!Object.keys(n).length)&&t.push("WORKFLOW_READABILITY_INVALID");let i=de(n.variables);n.variables!==void 0&&(typeof n.variables!="object"||Array.isArray(n.variables)||n.variables===null)&&t.push("WORKFLOW_VARIABLES_INVALID"),Object.keys(i).length>128&&t.push("WORKFLOW_VARIABLE_LIMIT_EXCEEDED");for(let[r,c]of Object.entries(i)){let l=de(c);(!ro(r)||!en(o,r))&&t.push(`WORKFLOW_VARIABLE_SOURCE_UNKNOWN:${r}`),(!xe(l.label,160)||Object.keys(l).some(p=>!["label","unit","description"].includes(p))||l.unit!==void 0&&!xe(l.unit,32)||l.description!==void 0&&!xe(l.description,2e3))&&t.push(`WORKFLOW_VARIABLE_METADATA_INVALID:${r}`)}let s=n.logic===void 0?[]:n.logic;(!Array.isArray(s)||s.length>32)&&t.push("WORKFLOW_LOGIC_LIMIT_INVALID");let a=new Set;for(let r of Array.isArray(s)?s.slice(0,32):[]){let c=de(r),l=String(c.code||"");(!/^[a-z][a-z0-9-]{2,63}$/.test(l)||a.has(l)||!xe(c.title,160)||!xe(c.description,4e3)||Object.keys(c).some(p=>!["code","title","description","phase","nodeId","inputPaths","outputPaths","source"].includes(p)))&&t.push(`WORKFLOW_LOGIC_METADATA_INVALID:${l}`),a.add(l),(!["submission","node_input","completion"].includes(String(c.phase))||c.phase==="node_input"&&!de(e.nodes)[String(c.nodeId)]||c.phase!=="node_input"&&c.nodeId!==void 0)&&t.push(`WORKFLOW_LOGIC_ANCHOR_INVALID:${l}`);for(let p of["inputPaths","outputPaths"]){let d=c[p];if(!(p==="outputPaths"&&d===void 0))if(!Array.isArray(d)||d.length>32||new Set(d).size!==d.length)t.push(`WORKFLOW_LOGIC_PATHS_INVALID:${l}:${p}`);else for(let f of d)(!ro(f)||!en(o,f))&&t.push(`WORKFLOW_LOGIC_SOURCE_UNKNOWN:${l}:${String(f)}`)}if(c.source!==void 0){let p=de(c.source);(!xe(p.path,256)||String(p.path).startsWith("/")||String(p.path).includes("..")||String(p.path).includes("://")||!/^sha256:[a-f0-9]{64}$/.test(String(p.digest))||p.symbol!==void 0&&!xe(p.symbol,160)||Object.keys(p).some(d=>!["path","symbol","digest"].includes(d)))&&t.push(`WORKFLOW_LOGIC_SOURCE_REFERENCE_INVALID:${l}`)}}for(let r of Object.values(de(e.nodes))){let c=de(r),l=Array.isArray(c.branches)?c.branches:[];for(let p of l){let d=ao(p.when);t.push(...d.errors.map(f=>`${f}:${c.id}`));for(let f of d.paths)en(o,f)||t.push(`WORKFLOW_VARIABLE_SOURCE_UNKNOWN:${c.id}:${f}`)}}return[...new Set(t)]}function Wr(e,t){let o=pt(e),n=[],i=new Map,s=[];for(let c of Object.values(e.nodes)){if(c.kind==="approval")for(let[l,p,d]of[["approve",c.onApprove,"\u540C\u610F"],["reject",c.onReject,"\u62D2\u7EDD"]])p&&n.push({id:`${c.id}:${l}`,from:c.id,to:p,kind:l,label:d,variablePaths:[]});if(c.kind==="cc"&&c.next&&n.push({id:`${c.id}:next`,from:c.id,to:c.next,kind:"next",label:"\u6284\u9001\u540E\u7EE7\u7EED",variablePaths:[]}),c.kind==="action"&&c.next){let l=Object.values(c.inputs||{}).flatMap(p=>p.source==="fact"?[p.path]:[]);for(let p of l)i.has(p)||i.set(p,new Set),i.get(p).add(c.id);n.push({id:`${c.id}:next`,from:c.id,to:c.next,kind:"next",label:"\u6210\u529F\u56DE\u6267\u540E\u7EE7\u7EED",variablePaths:l})}if(c.kind==="condition"){for(let[l,p]of(c.branches||[]).entries()){let d=ao(p.when);for(let f of d.paths)i.has(f)||i.set(f,new Set),i.get(f).add(c.id);n.push({id:`${c.id}:branch:${l}`,from:c.id,to:p.target,kind:"branch",label:p.label||`\u6761\u4EF6 ${l+1}`,priority:l+1,expression:p.when,variablePaths:d.paths}),s.push(...d.errors.map(f=>({code:f,path:c.id})))}c.otherwise&&n.push({id:`${c.id}:default`,from:c.id,to:c.otherwise,kind:"default",label:"\u5747\u4E0D\u6EE1\u8DB3\u65F6",variablePaths:[]})}}let r=[...new Set([...i.keys(),...Object.keys(e.readability?.variables||{}),...(e.readability?.logic||[]).flatMap(c=>[...c.inputPaths,...c.outputPaths||[]])])].slice(0,128).map(c=>{let l=en(o,c),p=e.readability?.variables?.[c],d=c.split("."),f=e.subject?.factProjection[d[0]],g=d[0]==="steps"?e.nodes[d[1]]:void 0;return l||s.push({code:"WORKFLOW_VARIABLE_SOURCE_UNKNOWN",path:c}),{path:c,label:p?.label||String(l?.schema.title||c),type:String(l?.schema.type||"unknown"),...p,required:l?.required||!1,usedBy:[...i.get(c)||[]],source:l&&g?.handler?{kind:"step_output",nodeId:g.id,handlerCode:g.handler.code,handlerVersion:g.handler.version}:l&&f&&e.subject?{kind:"subject_field",resourceCode:e.subject.resourceCode,fieldPath:[f,...d.slice(1)].join(".")}:{kind:l?"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(c=>({id:c.id,kind:c.kind,title:c.title||c.id,...c.binding?{binding:c.binding}:{},...c.mode?{mode:c.mode}:{},...c.outcome?{outcome:c.outcome}:{},...c.kind==="cc"?{emptyPolicy:c.emptyPolicy,notify:c.notify!==!1}:{},...c.kind==="action"&&c.handler?{businessStep:{handler:c.handler,inputs:c.inputs||{},outputPaths:Object.keys(de(c.outputSchema).properties||{}).map(l=>`steps.${c.id}.${l}`)}}:{}})),edges:n,variables:r,logic:e.readability?.logic||[],diagnostics:s}}function mt(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${mt(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${mt(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,s=i&&e.right.op==="literal"&&typeof e.right.value=="number"?t.find(a=>a.path===i)?.unit:void 0;return`${mt(e.left,t,o+1)} ${n[e.op]} ${mt(e.right,t,o+1)}${s?` ${s}`:""}`}var nn=["approve","reject","return","transfer","delegate","add_assignee"],on=["fixed_users","app_role","app_role_in_scope"],Mr=["single","any","all","sequence"],Ve=e=>!!e&&typeof e=="object"&&!Array.isArray(e),et=(e,t)=>Object.keys(e).every(o=>t.includes(o)),tn=(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 tt(e){return e.allowedOperations||[...nn]}function ui(e,t,o={},n=!1){return!(!Ve(e)||!Object.keys(e).length||!et(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 sn(e,t){let o=[];for(let[n,i]of Object.entries(e?.nodes||{})){if(!Ve(i))continue;let s=i.administration,a=i.operationPolicy;if(i.kind==="cc"){(a!==void 0||s!==void 0&&(!Ve(s)||!et(s,["assigneeProviders"])))&&o.push(`WORKFLOW_NODE_ADMINISTRATION_INVALID:${n}`),s?.assigneeProviders!==void 0&&!tn(s.assigneeProviders,on,3)&&o.push(`WORKFLOW_NODE_ADMINISTRATION_PROVIDERS_INVALID:${n}`),s?.assigneeProviders?.includes("app_role_in_scope")&&t&&!t.bindings[i.binding||""]?.scope&&o.push(`WORKFLOW_NODE_ADMINISTRATION_SCOPE_REQUIRED:${n}`);continue}if(i.kind!=="approval"){(s!==void 0||a!==void 0)&&o.push(`WORKFLOW_NODE_ADMINISTRATION_APPROVAL_REQUIRED:${n}`);continue}if(a!==void 0&&(!Ve(a)||Object.keys(a).length>8||Object.entries(a).some(([c,l])=>!nn.includes(c)||!tt(i).includes(c)||!ui(l,c)))&&o.push(`WORKFLOW_NODE_OPERATION_POLICY_INVALID:${n}`),s===void 0)continue;if(!Ve(s)||!et(s,["modes","assigneeProviders","operations"])){o.push(`WORKFLOW_NODE_ADMINISTRATION_INVALID:${n}`);continue}s.modes!==void 0&&(!tn(s.modes,Mr,4)||!s.modes.includes(i.mode))&&o.push(`WORKFLOW_NODE_ADMINISTRATION_MODES_INVALID:${n}`),s.assigneeProviders!==void 0&&!tn(s.assigneeProviders,on,3)&&o.push(`WORKFLOW_NODE_ADMINISTRATION_PROVIDERS_INVALID:${n}`);let r=t?.bindings[i.binding||""];r&&Array.isArray(s.assigneeProviders)&&s.assigneeProviders.includes("app_role_in_scope")&&!r.scope&&o.push(`WORKFLOW_NODE_ADMINISTRATION_SCOPE_REQUIRED:${n}`),s.operations!==void 0&&(!tn(s.operations,nn,8)||s.operations.some(c=>!tt(i).includes(c)))&&o.push(`WORKFLOW_NODE_ADMINISTRATION_OPERATIONS_INVALID:${n}`)}return o}function Ur(e,t,o){let n=[];if(!e||!Ve(o)||!Object.keys(o).length||!et(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 s=e.administration;if(i.mode!==void 0&&(e.kind!=="approval"||!s?.modes?.includes(i.mode))&&n.push("WORKFLOW_V2_NODE_CONFIGURATION_MODE_READONLY"),i.operations!==void 0&&(e.kind!=="approval"||!Ve(i.operations)||!Object.keys(i.operations).length||Object.keys(i.operations).length>8||Object.entries(i.operations).some(([a,r])=>!s?.operations?.includes(a)||!tt(e).includes(a)||!ui(r,a,e.operationPolicy?.[a],!0)))&&n.push("WORKFLOW_V2_NODE_CONFIGURATION_OPERATION_INVALID"),i.assignee!==void 0){let a=i.assignee,r=s?.assigneeProviders||(e.kind==="approval"&&t&&on.includes(t.provider)?[t.provider]:[]);!Ve(a)||!["approval","cc"].includes(e.kind)||!r.includes(a.provider)||a.provider==="app_role_in_scope"&&!t?.scope?n.push("WORKFLOW_V2_NODE_CONFIGURATION_PROVIDER_READONLY"):a.provider==="fixed_users"?(!et(a,["provider","users"])||!Array.isArray(a.users)||a.users.length<1||a.users.length>(e.kind==="cc"?20: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"):(!et(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 Br(e,t){let o=Object.fromEntries(tt(e).flatMap(n=>{let i=n,s=t?.operations?.[i],a={...e.operationPolicy?.[i],...s?.label!==void 0?{label:s.label}:{},...s?.commentRequired!==void 0?{commentRequired:s.commentRequired}:{}};return Object.keys(a).length?[[i,a]]:[]}));return{mode:t?.mode||e.mode,allowedOperations:tt(e).filter(n=>t?.operations?.[n]?.enabled!==!1),operationPolicy:o,fieldPolicy:{default:e.fieldPolicy?.default||"readonly",fields:{...e.fieldPolicy?.fields}}}}var ld=20,fi=["fixed_users","initiator","input_users","form_field_users","app_role","app_role_in_scope","previous_node_actor"];function rn(e,t){let o=[];for(let[n,i]of Object.entries(e?.nodes||{})){if(i?.kind!=="cc"||((Object.keys(i).some(c=>!["id","kind","title","binding","next","emptyPolicy","notify","administration"].includes(c))||typeof i.title!="string"||!i.title.trim()||i.title.length>255||typeof i.binding!="string"||!i.binding.trim()||i.binding.length>255||typeof i.next!="string"||!i.next.trim()||!e.nodes?.[i.next]||!["block","skip"].includes(i.emptyPolicy)||i.notify!==void 0&&typeof i.notify!="boolean")&&o.push(`WORKFLOW_CC_NODE_INVALID:${n}`),!t))continue;let s=t.bindings?.[i.binding];if(!s){o.push(`WORKFLOW_CC_BINDING_NOT_FOUND:${n}`);continue}fi.includes(s.provider)||o.push(`WORKFLOW_CC_PROVIDER_INVALID:${n}`);let a=s.min??1,r=s.max??20;(!Number.isSafeInteger(a)||!Number.isSafeInteger(r)||a<1||r<a||r>20||s.provider==="fixed_users"&&(!Array.isArray(s.users)||!s.users.length||s.users.length>r))&&o.push(`WORKFLOW_CC_RECIPIENT_LIMIT_INVALID:${n}`)}return[...new Set(o)]}var _i=64,an=1024*1024,mi=65536,uo=100,gi=400,je=new Set(["__proto__","prototype","constructor"]),Ai=/^[A-Za-z][A-Za-z0-9_-]{0,63}$/,At=/^[A-Za-z][A-Za-z0-9_]{0,62}$/,pi=/^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/,se=e=>!!e&&typeof e=="object"&&!Array.isArray(e)&&[null,Object.prototype].includes(Object.getPrototypeOf(e)),we=(e,t)=>se(e)&&Object.keys(e).every(o=>t.includes(o)&&!je.has(o)),cn=e=>{try{return new TextEncoder().encode(JSON.stringify(e)).length}catch{return 1/0}},Ei=e=>e==null||typeof e=="string"&&!e.trim()||Array.isArray(e)&&e.length===0;function Fe(e,t){if(e===t)return!0;if(Array.isArray(e)&&Array.isArray(t))return e.length===t.length&&e.every((n,i)=>Fe(n,t[i]));if(!se(e)||!se(t))return!1;let o=Object.keys(e);return o.length===Object.keys(t).length&&o.every(n=>Object.hasOwn(t,n)&&Fe(e[n],t[n]))}function lo(e,t){let o=t.split(".");if(!(o.some(n=>!Ai.test(n)||je.has(n))||o.length>12))return o.reduce((n,i)=>se(n)&&Object.hasOwn(n,i)?n[i]:void 0,e)}function Se(e,t){switch(e.op){case"literal":return e.value;case"path":return lo({values:t},e.path);case"and":return e.values.every(o=>!!Se(o,t));case"or":return e.values.some(o=>!!Se(o,t));case"not":return!Se(e.value,t);case"exists":return!Ei(Se(e.value,t));default:{let o=Se(e.left,t),n=Se(e.right,t);return e.op==="eq"?Fe(o,n):e.op==="neq"?!Fe(o,n):e.op==="in"?Array.isArray(n)&&n.some(i=>Fe(i,o)):e.op==="contains"?Array.isArray(o)?o.some(i=>Fe(i,n)):typeof o=="string"&&typeof n=="string"&&o.includes(n):typeof o!="number"||typeof n!="number"||!Number.isFinite(o)||!Number.isFinite(n)?!1:e.op==="gt"?o>n:e.op==="gte"?o>=n:e.op==="lt"?o<n:o<=n}}}function gt(e,t,o=0,n={nodes:0}){if(o>8||++n.nodes>64||!se(e))return!1;if(e.op==="literal")return we(e,["op","value"])&&Object.hasOwn(e,"value")&&cn(e.value)<=4096&&Et(e.value);if(e.op==="path"){if(!we(e,["op","path"])||typeof e.path!="string")return!1;let i=e.path.split(".");return i[0]==="values"&&i.length>=2&&i.length<=8&&t.has(i[1])&&i.every(s=>At.test(s)&&!je.has(s))}return["not","exists"].includes(e.op)?we(e,["op","value"])&&gt(e.value,t,o+1,n):["and","or"].includes(e.op)?we(e,["op","values"])&&Array.isArray(e.values)&&e.values.length>0&&e.values.length<=16&&e.values.every(i=>gt(i,t,o+1,n)):["eq","neq","gt","gte","lt","lte","in","contains"].includes(e.op)&&we(e,["op","left","right"])&&gt(e.left,t,o+1,n)&&gt(e.right,t,o+1,n)}function It(e,t,o){let n=[],i=e.taskPages;if(i!==void 0&&(!se(i)||Object.keys(i).length===0||Object.keys(i).length>16||cn(i)>mi))return["WORKFLOW_TASK_PAGES_INVALID"];for(let[s,a]of Object.entries(i||{})){let r=`taskPages.${s}`;if(!Ai.test(s)||je.has(s)||!we(a,["title","fields"])||typeof a.title!="string"||!a.title.trim()||a.title.length>160||!Array.isArray(a.fields)||!a.fields.length||a.fields.length>_i){n.push(`WORKFLOW_TASK_PAGE_INVALID:${r}`);continue}let c=new Set(a.fields.map(d=>d?.code));c.size!==a.fields.length&&n.push(`WORKFLOW_TASK_PAGE_DUPLICATE_FIELD:${r}`);let l=0,p=new Set;for(let d of a.fields){if(!we(d,["code","readonly","required","visibleWhen","requiredWhen","subtable"])||!At.test(d.code)||je.has(d.code)||["readonly","required"].some(f=>d[f]!==void 0&&typeof d[f]!="boolean")||d.readonly&&(d.required||d.requiredWhen)){n.push(`WORKFLOW_TASK_PAGE_FIELD_INVALID:${r}`);continue}for(let f of["visibleWhen","requiredWhen"])d[f]!==void 0&&!gt(d[f],c)&&n.push(`WORKFLOW_TASK_PAGE_EXPRESSION_INVALID:${r}.${d.code}.${f}`);if(t){let f=t.get(d.code);if((!f||f.system||f.hidden||f.type==="serial-number"||!d.readonly&&f.widget==="readonly"||!d.readonly&&f.type==="subtable"&&!d.subtable||d.subtable&&f.type!=="subtable")&&n.push(`WORKFLOW_TASK_PAGE_RESOURCE_FIELD_INVALID:${r}.${d.code}`),d.subtable&&f?.subtable){let g=f.subtable;l+=g.maxRows??20,(p.has(g.resourceCode)||!Number.isSafeInteger(g.maxRows??20)||(g.maxRows??20)<1||(g.maxRows??20)>uo||!At.test(g.foreignKey)||!At.test(g.orderField)||g.foreignKey===g.orderField)&&n.push(`WORKFLOW_TASK_SUBTABLE_RELATION_INVALID:${r}.${d.code}`),p.add(g.resourceCode);let E=o?.get(g.resourceCode);o&&(!E||!["uuid","resource-ref.single"].includes(E.get(g.foreignKey)?.type||"")||E.get(g.orderField)?.type!=="number.integer")&&n.push(`WORKFLOW_TASK_SUBTABLE_RELATION_INVALID:${r}.${d.code}`);for(let A of Array.isArray(d.subtable.fields)?d.subtable.fields:[]){if(!A||typeof A.code!="string")continue;let b=E?.get(A.code);(A.code===g.foreignKey||A.code===g.orderField||E&&(!b||b.system||b.hidden||b.type==="subtable"||!A.readonly&&(b.widget==="readonly"||b.type==="serial-number")))&&n.push(`WORKFLOW_TASK_SUBTABLE_FIELD_UNSUPPORTED:${r}.${d.code}.${A.code}`)}}else d.subtable&&t&&n.push(`WORKFLOW_TASK_SUBTABLE_RELATION_INVALID:${r}.${d.code}`)}d.subtable&&(d.readonly||!we(d.subtable,["fields","create","delete","reorder"])||["create","delete","reorder"].some(f=>d.subtable?.[f]!==void 0&&typeof d.subtable[f]!="boolean")||!Array.isArray(d.subtable.fields)||d.subtable.fields.some(f=>f?.subtable)?n.push(`WORKFLOW_TASK_SUBTABLE_PAGE_INVALID:${r}.${d.code}`):n.push(...It({taskPages:{child:{title:"\u5B50\u884C",fields:d.subtable.fields}}},o?.get(t?.get(d.code)?.subtable?.resourceCode||"")).map(f=>`${f}:${r}.${d.code}`)))}(l>gi||l<0||!Number.isSafeInteger(l))&&n.push(`WORKFLOW_TASK_SUBTABLE_BUDGET_EXCEEDED:${r}`)}for(let[s,a]of Object.entries(e.nodes||{}))se(a)&&a.taskPageCode!==void 0&&(a.kind!=="approval"||typeof a.taskPageCode!="string"||!se(i)||!Object.hasOwn(i,a.taskPageCode)?n.push(`WORKFLOW_TASK_PAGE_NOT_FOUND:${s}`):Array.isArray(i[a.taskPageCode]?.fields)&&i[a.taskPageCode].fields.some(r=>r&&(a.fieldPolicy?.fields?.[r.code]||a.fieldPolicy?.default)==="hidden")&&n.push(`WORKFLOW_TASK_PAGE_FIELD_HIDDEN:${s}`));return n}function fo(e,t){return e.fields.map(o=>({code:o.code,visible:o.visibleWhen===void 0||!!Se(o.visibleWhen,t),readonly:o.readonly===!0,required:o.required===!0||o.requiredWhen!==void 0&&!!Se(o.requiredWhen,t)}))}var ge=class extends Error{constructor(o,n){super(o);this.code=o;this.field=n}code;field;rowIndex;childField};function Kr(e,t){return t.map(o=>({key:String(o.id),id:String(o.id),revision:Number(o.revision),state:"persisted",values:Object.fromEntries(fo({title:"\u5B50\u884C",fields:e.fields},o).filter(n=>n.visible&&!n.readonly).map(n=>[n.code,o[n.code]??null]))}))}function Gr(e,t,o,n,i,s=!0){let a=e.subtable,r=f=>{throw new ge(f,e.code)};if(!a||!Number.isSafeInteger(t)||t<1||t>uo||!Array.isArray(n)||n.length>2*t||cn(n)>an||!Et(n))return r("WORKFLOW_TASK_SUBTABLE_VALUES_INVALID");let c=new Map(o.map(f=>[String(f.id),f])),l=new Set,p=new Set,d=[];for(let f of n){if(!we(f,["key","state","id","revision","values"])||typeof f.key!="string"||!pi.test(f.key)||l.has(f.key)||!["created","persisted","deleted"].includes(f.state)||!se(f.values))return r("WORKFLOW_TASK_SUBTABLE_ROW_INVALID");if(l.add(f.key),f.state==="created"){if(!a.create||f.id!==void 0||f.revision!==void 0||c.has(f.key))return r("WORKFLOW_TASK_SUBTABLE_CREATE_FORBIDDEN")}else{if(typeof f.id!="string"||f.id!==f.key||!pi.test(f.id)||p.has(f.id)||!Number.isSafeInteger(f.revision)||f.revision<1||!c.has(f.id))return r("WORKFLOW_TASK_SUBTABLE_SCOPE_CONFLICT");if(p.add(f.id),s&&Number(c.get(f.id).revision)!==f.revision)return r("WORKFLOW_TASK_SUBTABLE_REVISION_CONFLICT")}if(f.state==="deleted"){if(!a.delete||Object.keys(f.values).length)return r("WORKFLOW_TASK_SUBTABLE_DELETE_FORBIDDEN");continue}try{Ii({title:e.code,fields:a.fields},f.id?c.get(f.id):{},f.values,i)}catch(g){if(!(g instanceof ge))throw g;let E=new ge(g.code,e.code);throw E.rowIndex=d.length,g.field!==void 0&&(E.childField=g.field),E}d.push(f)}if(p.size!==c.size)return r("WORKFLOW_TASK_SUBTABLE_SCOPE_CONFLICT");if(d.length>t)return r("WORKFLOW_TASK_SUBTABLE_MAX_ROWS_EXCEEDED");if(!a.reorder){let f=o.filter(E=>d.some(A=>A.id===String(E.id))).map(E=>String(E.id)),g=d.filter(E=>E.state==="persisted").map(E=>E.id);if(!Fe(f,g)||d.some((E,A)=>E.state==="created"&&d.slice(A+1).some(b=>b.state==="persisted")))return r("WORKFLOW_TASK_SUBTABLE_REORDER_FORBIDDEN")}return n}function Et(e,t={members:0},o=0){return++t.members>5e4||o>12?!1:e===null||typeof e=="boolean"?!0:typeof e=="string"?e.length<=an:typeof e=="number"?Number.isFinite(e):Array.isArray(e)?e.length<=1e3&&e.every(n=>Et(n,t,o+1)):se(e)&&Object.entries(e).every(([n,i])=>!je.has(n)&&Et(i,t,o+1))}function Ii(e,t,o,n){if(!se(o)||cn(o)>an||!Et(o))throw new ge("WORKFLOW_TASK_FORM_VALUES_INVALID");let i={...t,...o},s=new Map(fo(e,i).map(a=>[a.code,a]));for(let a of Object.keys(o)){let r=s.get(a);if(!r||r.readonly||!r.visible)throw new ge("WORKFLOW_TASK_FORM_FIELD_NOT_EDITABLE",a)}if(n)for(let a of s.values()){let r=i[a.code],c=e.fields.find(l=>l.code===a.code)?.subtable&&Array.isArray(r)?r.every(l=>se(l)&&l.state==="deleted"):Ei(r);if(a.visible&&!a.readonly&&a.required&&c)throw new ge("WORKFLOW_TASK_FORM_REQUIRED",a.code)}return i}function qr(e,t,o){let n=JSON.parse(JSON.stringify(t));for(let[a,r]of Object.entries(e.subject?.factProjection||{})){let c=a.split(".");if(!c.length||c.length>12||a.length>128||c[0]==="steps"||c.some(p=>!At.test(p)||je.has(p)))throw new ge("WORKFLOW_TASK_FORM_FACT_PROJECTION_INVALID");if(!Object.hasOwn(o,r))throw new ge("WORKFLOW_TASK_FORM_FACT_FIELD_MISSING",r);let l=n;for(let p of c.slice(0,-1))l=l[p]=se(l[p])?l[p]:{};l[c.at(-1)]=o[r]===void 0?void 0:JSON.parse(JSON.stringify(o[r]))}let i=new Set,s=Object.values(e.nodes||{}).filter(a=>a.kind==="action");for(let a=0;a<=s.length;a++){let r=!1;for(let c of s)se(n.steps)&&Object.hasOwn(n.steps,c.id)&&Object.values(c.inputs||{}).some(l=>l.source==="fact"&&!Fe(lo(t,l.path),lo(n,l.path)))&&(delete n.steps[c.id],i.add(c.id),r=!0);if(!r)break}return{facts:n,invalidatedNodeIds:[...i].sort()}}function Jr(e,t,o){let n=e.nodes||{};for(let i of o){let s=new Set,a=new Map,r=c=>{if(c===i)return!0;if(a.has(c))return a.get(c);if(s.has(c)||s.size>200)return!1;let l=n[c];if(!se(l)||l.kind==="end")return!1;s.add(c);let p=l.kind==="approval"?[l.onApprove]:l.kind==="condition"?[...(l.branches||[]).map(f=>f.target),l.otherwise]:[l.next],d=p.length>0&&p.every(f=>typeof f=="string"&&r(f));return s.delete(c),a.set(c,d),d};if(!r(t))return!1}return!0}var _d=256,md=64,gd=262144,zr=/^[a-z][a-z0-9_-]{0,127}$/,Yr=/^[A-Za-z][A-Za-z0-9_]*(?:\.[A-Za-z][A-Za-z0-9_]*)*$/,yi=new Set(["__proto__","prototype","constructor"]),Ne=e=>!!e&&typeof e=="object"&&!Array.isArray(e),yt=(e,t)=>Object.keys(e).every(o=>t.includes(o)),We=(e,t)=>typeof e=="string"&&e.trim().length>0&&e.length<=t&&!/[\u0000-\u001f\u007f]/.test(e),De=e=>typeof e=="string"&&zr.test(e)&&!yi.has(e),Ni=e=>typeof e=="string"&&e.length<=255&&Yr.test(e)&&!e.split(".").some(t=>yi.has(t)),Hr=e=>Ne(e)&&yt(e,["dimension","valueFrom","value"])&&De(e.dimension)&&(We(e.value,255)&&e.valueFrom===void 0||Ni(e.valueFrom)&&e.value===void 0),bi=e=>typeof e=="string"&&/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d{1,3})?(?:Z|[+-]\d{2}:\d{2})$/.test(e)&&Number.isFinite(Date.parse(e)),bt={type:"string",pattern:"^[a-z][a-z0-9_-]{0,127}$"},po={type:"string",minLength:1,maxLength:128},Xr={type:"object",additionalProperties:!1,required:["policyCode","title","strategy","dimensions","sources"],properties:{policyCode:bt,title:po,strategy:{enum:["replace_then_append","replace_only"]},dimensions:{type:"object",maxProperties:8,propertyNames:bt,additionalProperties:{type:"object",additionalProperties:!1,required:["title","valueFrom"],properties:{title:po,valueFrom:{type:"string",minLength:1,maxLength:255}}}},sources:{type:"object",minProperties:1,maxProperties:16,propertyNames:bt,additionalProperties:{type:"object",additionalProperties:!1,required:["title","provider","roleCode"],properties:{title:po,provider:{enum:["app_role","app_role_in_scope"]},roleCode:bt,scope:{type:"object",additionalProperties:!1,required:["dimension"],properties:{dimension:bt,value:{type:"string",minLength:1,maxLength:255},valueFrom:{type:"string",minLength:1,maxLength:255}}}}}}}};function Nt(e){if(!Ne(e)||!yt(e,["policyCode","title","strategy","dimensions","sources"])||!De(e.policyCode)||!We(e.title,128)||!["replace_then_append","replace_only"].includes(e.strategy))return["WORKFLOW_V2_ROUTING_POLICY_INVALID"];let t=[];return(!Ne(e.dimensions)||Object.keys(e.dimensions).length>8||Object.entries(e.dimensions).some(([o,n])=>!De(o)||!Ne(n)||!yt(n,["title","valueFrom"])||!We(n.title,128)||!Ni(n.valueFrom)))&&t.push("WORKFLOW_V2_ROUTING_DIMENSIONS_INVALID"),(!Ne(e.sources)||Object.keys(e.sources).length<1||Object.keys(e.sources).length>16||Object.entries(e.sources).some(([o,n])=>!De(o)||!Ne(n)||!yt(n,["title","provider","roleCode","scope"])||!We(n.title,128)||!De(n.roleCode)||!["app_role","app_role_in_scope"].includes(n.provider)||(n.provider==="app_role_in_scope"?!Hr(n.scope):n.scope!==void 0)))&&t.push("WORKFLOW_V2_ROUTING_SOURCES_INVALID"),t}function Qr(e,t){if(Nt(e).length)return["WORKFLOW_V2_ROUTING_POLICY_INVALID"];if(!Array.isArray(t)||t.length>256||new TextEncoder().encode(JSON.stringify(t)).length>262144)return["WORKFLOW_V2_ROUTING_RULE_LIMIT_EXCEEDED"];let o=[],n=new Set;for(let i of t){if(!Ne(i)||!yt(i,["ruleCode","title","enabled","workflowCode","nodeId","matches","sourceCode","effect","priority","validFrom","validTo"])||!De(i.ruleCode)||!We(i.title,128)||typeof i.enabled!="boolean"||!De(i.sourceCode)||!Object.hasOwn(e.sources,i.sourceCode)||!["append","replace"].includes(i.effect)||!Number.isSafeInteger(i.priority)||i.priority<-1e3||i.priority>1e3||i.workflowCode!==void 0&&!De(i.workflowCode)||i.nodeId!==void 0&&(!De(i.nodeId)||i.workflowCode===void 0)||i.validFrom!==void 0&&!bi(i.validFrom)||i.validTo!==void 0&&!bi(i.validTo)||i.validFrom&&i.validTo&&Date.parse(i.validFrom)>=Date.parse(i.validTo)){o.push("WORKFLOW_V2_ROUTING_RULE_INVALID");continue}n.has(i.ruleCode)&&o.push(`WORKFLOW_V2_ROUTING_RULE_DUPLICATE:${i.ruleCode}`),n.add(i.ruleCode),(!Ne(i.matches)||Object.entries(i.matches).some(([s,a])=>!Object.hasOwn(e.dimensions,s)||!Array.isArray(a)||a.length<1||a.length>64||new Set(a).size!==a.length||a.some(r=>!We(r,255))))&&o.push(`WORKFLOW_V2_ROUTING_MATCH_INVALID:${i.ruleCode}`)}return[...new Set(o)]}function Ti(e){return JSON.stringify({policyCode:e.policyCode,strategy:e.strategy,dimensions:Object.entries(e.dimensions).sort(([t],[o])=>t<o?-1:t>o?1:0).map(([t,o])=>[t,o.valueFrom]),sources:Object.entries(e.sources).sort(([t],[o])=>t<o?-1:t>o?1:0).map(([t,o])=>[t,o.provider,o.roleCode,o.scope?.dimension??null,o.scope?.valueFrom??null,o.scope?.value??null])})}function _o(e){let t=[],o=new Map;for(let n of e)for(let[i,s]of Object.entries(n.bindings||{})){if(!Ne(s)||s.routing===void 0)continue;let a=Nt(s.routing);if(a.length){t.push(...a.map(l=>`${l}:${i}`));continue}let r=Ti(s.routing),c=o.get(s.routing.policyCode);c&&c!==r&&t.push(`WORKFLOW_V2_ROUTING_POLICY_CONFLICT:${s.routing.policyCode}`),o.set(s.routing.policyCode,r)}return[...new Set(t)]}function Zr(e,t){let o={};for(let[n,i]of Object.entries(e.dimensions)){let s=t;for(let a of i.valueFrom.split("."))s=Ne(s)&&Object.hasOwn(s,a)?s[a]:void 0;if(!(typeof s=="string"&&We(s,255)||typeof s=="number"&&Number.isFinite(s)||typeof s=="boolean"))throw new Error(`WORKFLOW_V2_ROUTING_FACT_REQUIRED:${n}`);o[n]=String(s)}return o}function ea(e,t,o){let n=t.filter(l=>l.enabled&&(!l.validFrom||Date.parse(l.validFrom)<=o.at)&&(!l.validTo||Date.parse(l.validTo)>o.at)&&(!l.workflowCode||l.workflowCode===o.workflowCode)&&(!l.nodeId||l.nodeId===o.nodeId)&&Object.entries(l.matches).every(([p,d])=>d.includes(o.facts[p])));if(n.length>64)throw new Error("WORKFLOW_V2_ROUTING_MATCH_LIMIT_EXCEEDED");let i=(l,p)=>p.priority-l.priority||+!!l.workflowCode-+!!p.workflowCode||+!!l.nodeId-+!!p.nodeId||(l.ruleCode<p.ruleCode?-1:l.ruleCode>p.ruleCode?1:0),s=n.filter(l=>l.effect==="replace").sort(i);if(s.length>1&&s[0].priority===s[1].priority)throw new Error("WORKFLOW_V2_ROUTING_REPLACE_CONFLICT");let a=s[0],r=a&&e.strategy==="replace_only"?[]:n.filter(l=>l.effect==="append").sort(i),c=[...a?[a]:[],...r];return{matched:n.sort(i),replacement:a,applied:c,ignored:n.filter(l=>!c.includes(l))}}var mn=ys(require("crypto"),1);var Oi="native-4",hi={"application-native-2":"1.0.0","authz.native-batch-explain":"1.0.0","authz.native-management":"1.0.0","authz.native-membership-batch":"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","workflow.assignment-routing":"1.0.0","workflow.role-references":"1.0.0","workflow.delegation-management":"1.0.0","workflow.automatic-cc":"1.0.0","workflow.task-page-submit":"1.0.0","workflow.task-private-drafts":"1.0.0","workflow.task-managed-files":"1.0.0","workflow.task-rich-fields":"1.0.0","workflow.task-owned-subtables":"1.0.0","workflow.task-owned-files":"1.0.0","workflow.durable-business-step":"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 Id=5,bd=20,yd=50,Nd=50,Td=100,nt=class extends Error{constructor(o,n){super(o);this.code=o;this.pointer=n;this.name="NativeDataPolicyExpressionV2Error"}code;pointer};function Ot(e,t){let o=[],n=(i,s,a)=>{a>5&&Tt("NATIVE_DATA_POLICY_EXPRESSION_DEPTH_EXCEEDED",s);let r=Ri(i,s),c=["allOf","anyOf"].filter(d=>d in r);if(c.length===0){o.push({rule:r,pointer:s}),o.length>50&&Tt("NATIVE_DATA_POLICY_EXPRESSION_LEAVES_EXCEEDED",s);return}let l=c[0],p=r[l];(c.length!==1||Object.keys(r).length!==1||!Array.isArray(p)||p.length<1||p.length>20)&&Tt("NATIVE_DATA_POLICY_EXPRESSION_GROUP_INVALID",s),p.forEach((d,f)=>n(d,`${s}/${l}/${f}`,a+1))};return n(e,t,1),o}function go(e,t){Ot(e,t);let o=(n,i)=>{let s=Ri(n,i);if(Array.isArray(s.allOf))return mo(s.allOf.flatMap((a,r)=>o(a,`${i}/allOf/${r}`)),i);if(Array.isArray(s.anyOf)){let a=[[]];return s.anyOf.forEach((r,c)=>{let l=o(r,`${i}/anyOf/${c}`);a=mo(a.flatMap(p=>l.map(d=>[...p,...d])),i)}),a}return[[s]]};return mo(o(e,t),t)}function mo(e,t){let o=e.reduce((n,i)=>n+i.length,0);return(e.length>50||o>100)&&Tt("NATIVE_DATA_POLICY_EXPRESSION_EXPANSION_EXCEEDED",t),e}function Ri(e,t){return(!e||typeof e!="object"||Array.isArray(e))&&Tt("NATIVE_DATA_POLICY_EXPRESSION_NODE_INVALID",t),e}function Tt(e,t){throw new nt(e,t)}var ta="openxiangda.config-bundle/v3",Ki="openxiangda.contract-bundle/v3",Ci="openxiangda.native-configuration-projection/v1",Rt=Oi,na=/^[a-f0-9]{64}$/,oa=/^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/,ia=/^app:[a-z][a-z0-9]*(?:-[a-z0-9]+)*:[A-Za-z0-9:._*-]+$/,sa=/^[a-z][a-z0-9]*(?:[-_.][a-z0-9]+)*$/,ra=/^[a-z][a-z0-9]*(?:[-.][a-z0-9]+)*$/,aa=/^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/,ca=/^[A-Za-z][A-Za-z0-9_]{0,62}$/,Si=/^[A-Za-z][A-Za-z0-9_]{0,127}$/,da=/^[a-z][a-z0-9]*(?:[-_][a-z0-9]+)*$/,la=/^[A-Z][A-Z0-9_]*$/,ua=/^[a-z][a-z0-9-]{2,63}$/,fa=/^[A-Za-z][A-Za-z0-9_-]{0,127}$/,pa=/^[A-Za-z][A-Za-z0-9_.]{0,127}$/,_a=16,ma=2*1024,ga=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"]),Aa=new Set(["overview","database","operations","workflow","members","calendar","document","folder","settings"]),Ea=new Set(["approve","reject","return","transfer","delegate","add_assignee","resubmit","withdraw","terminate","admin_reassign","admin_override","retry_resolution"]),Ia=4*1024*1024,ba=8*1024*1024,ya=40,Na=1e5,Eo=1024*1024,Ta="openxiangda.event-handler-manifest/v2",Gi="openxiangda.application-route-manifest/v3",wi=64,qi=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}),dn=["openxiangda.data.record.created.v2","openxiangda.data.record.updated.v2","openxiangda.data.record.deleted.v2"],ln=[Qe,"openxiangda.workflow.step.result_received.v2","openxiangda.workflow.step.completed.v2","openxiangda.workflow.step.continuation_failed.v2","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"],Oa=new Set(ln),un=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,s])=>[i,String(s).slice(0,128)]))}};function ha(e){let t=S(e.appCode,"/appCode",128);oa.test(t)||m("NATIVE_CONFIG_APP_CODE_INVALID","/appCode");let o=bo(e.expectedConfigDigest,"/expectedConfigDigest"),n=bo(e.expectedContractDigest,"/expectedContractDigest"),i=Mi(e.configBytes,Ia,"/configBytes","NATIVE_CONFIG_ARTIFACT_TOO_LARGE"),s=Mi(e.contractBytes,ba,"/contractBytes","NATIVE_CONTRACT_ARTIFACT_TOO_LARGE");Ui(i,o,"/configBytes","NATIVE_CONFIG_DIGEST_MISMATCH"),Ui(s,n,"/contractBytes","NATIVE_CONTRACT_DIGEST_MISMATCH");let a=ji(i,"/configBytes","NATIVE_CONFIG_JSON_INVALID","NATIVE_CONFIG_NOT_CANONICAL"),r=ji(s,"/contractBytes","NATIVE_CONTRACT_JSON_INVALID","NATIVE_CONTRACT_NOT_CANONICAL");Wi(a,"/config"),Wi(r,"/contracts");let c=a,l=r;Ca(c,t),Sa(l,t,o);let p=wa(c,o,l.generatorVersion);mc(p,l,c),ee(p)!==ee(l)&&m("NATIVE_CONTRACT_CLOSURE_MISMATCH",yo(p,l,"/contracts"));let d={authz:{appCode:t,...c.authz,perspectives:c.perspectives,capabilityCatalog:p.capabilities},data:{appCode:t,resources:c.data.resources,resourceContracts:p.resources,...p.concurrency?{concurrency:p.concurrency}:{},...p.subjectReadSurfaces?{subjectReadSurfaces:p.subjectReadSurfaces}:{}},events:{appCode:t,...c.events,consumers:p.eventConsumers,producers:p.eventProducers,handlerManifest:p.eventHandlerManifest,eventTypes:p.eventTypes,capturePlans:zi({resources:c.data.resources,dataPolicies:c.authz.dataPolicies,subscriptions:p.eventConsumers,capturePolicies:c.events.capturePolicies})},workflows:{appCode:t,...c.workflows,contracts:p.workflows},runtime:{appCode:t,requirements:c.runtime,backend:c.backend,frontend:c.frontend},contracts:p},f={authz:ot(d.authz),data:ot(d.data),events:ot(d.events),workflows:ot(d.workflows),runtime:ot(d.runtime),contracts:ot(d.contracts)},g={configDigest:o,contractDigest:n,generatorVersion:l.generatorVersion},E=Ji(c),A={schemaVersion:Ci,compilerContractVersion:Rt,appCode:t,source:g,projections:f,requiredPlatformCapabilities:E,aggregateDigest:X({schemaVersion:Ci,compilerContractVersion:Rt,appCode:t,source:g,requiredPlatformCapabilities:E,projectionDigests:Object.fromEntries(Object.entries(f).map(([b,I])=>[b,I.digest]))})};return rs(A)}function Ji(e){let t=e.authz.roles,o=e.data.resources,n=e.backend.operations,i=t.some(u=>u.capabilities.some(N=>N.endsWith(":directory:read")))||o.some(u=>u.schema.fields.some(N=>["user.single","user.multiple","department.single","department.multiple"].includes(N.type)))||n.some(u=>u.platformAccess?.directory),s=!!(e.events.subscriptions.length||e.events.timers.length||e.events.dateTriggers.length||e.events.schemas.length),a=n.some(u=>u.platformAccess?.managedFiles||u.platformAccess?.managedFileCopies)||e.events.subscriptions.some(u=>u.platformAccess?.managedFileCopies),r=n.some(u=>u.platformAccess?.notification)||e.events.subscriptions.some(u=>u.platformAccess?.notification),c=(u,N,y=!1)=>{let O=o.find(h=>h.code===u.definition.subject?.resourceCode)?.schema.fields||[];return Object.values(u.definition.taskPages||{}).some(h=>h.fields.some(C=>{if(C.readonly)return!1;let k=O.find(M=>M.code===C.code);if(!y&&k&&N.includes(k.type))return!0;if(!C.subtable||!k?.subtable)return!1;let V=o.find(M=>M.code===k.subtable.resourceCode)?.schema.fields||[];return C.subtable.fields.some(M=>!M.readonly&&V.some(P=>P.code===M.code&&N.includes(P.type)))}))},l=e.workflows.definitions.filter(u=>c(u,["file","image","signature","text.rich"])),p=e.workflows.definitions.filter(u=>c(u,["signature","text.rich"])),d=e.workflows.definitions.filter(u=>c(u,["file","image","signature","text.rich"],!0)),f=e.workflows.definitions.filter(u=>u.launch.mode==="standalone"||u.launch.mode==="hidden-handoff"),g=n.some(u=>u.platformAccess?.workflow)||f.length>0,E=f.filter(u=>{let N=u.launch.submission;if(!N)return!1;let y=o.find(O=>O.code===u.definition.subject.resourceCode);return[N.create,N.existing].some(O=>O&&Object.values(O.inputs).some(h=>h.source==="field"&&y?.schema.fields.some(C=>C.code===h.fieldCode&&C.type.startsWith("resource-ref.")&&C.source)))}),A={resources:o},b={perspectives:e.perspectives,authz:e.authz},I={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(u=>({code:u.code,method:u.method,path:u.path,capability:u.capability,platformAccess:u.platformAccess||null,...u.browser?{browser:u.browser}:{},ai:u.ai||null}))}};return[...o.some(u=>u.uniqueKeys?.length)?[{code:"data.unique-keys",declaration:o.filter(u=>u.uniqueKeys?.length).map(u=>({code:u.code,uniqueKeys:u.uniqueKeys}))}]:[],...e.data.concurrency?[{code:"data.managed-concurrency",declaration:e.data.concurrency}]:[],...e.data.concurrency?.commands.some(u=>u.mode==="durable")?[{code:"data.managed-concurrency.durable",declaration:e.data.concurrency}]:[],...o.some(u=>u.decimalReservationLifecycle)?[{code:"data.decimal-reservation-lifecycle",declaration:o.filter(u=>u.decimalReservationLifecycle).map(u=>({code:u.code,decimalReservationLifecycle:u.decimalReservationLifecycle}))}]:[],...n.some(u=>u.platformAccess?.decimalReservation)||e.events.subscriptions.some(u=>u.platformAccess?.decimalReservation)?[{code:"data.decimal-reservations",declaration:[...n.filter(u=>u.platformAccess?.decimalReservation).map(u=>({code:u.code,decimalReservation:u.platformAccess.decimalReservation})),...e.events.subscriptions.filter(u=>u.platformAccess?.decimalReservation).map(u=>({subscriptionCode:u.code,decimalReservation:u.platformAccess.decimalReservation}))]}]:[],{code:"application-native-2",declaration:I},{code:"authz.native-batch-explain",declaration:b},{code:"authz.native-management",declaration:b},{code:"deployment.durable-runs",declaration:I.backend},{code:"deployment.platform-executor",declaration:I.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:A},{code:"data.native-golden-crud",declaration:A}]:[],...o.some(Dn)?[{code:"data.audit-read-access",declaration:A}]:[],...i?[{code:"directory-v2",declaration:{roles:t.map(u=>({code:u.code,capabilities:u.capabilities.filter(N=>N.endsWith(":directory:read"))})),resources:o.map(u=>({code:u.code,fields:u.schema.fields.filter(N=>["user.single","user.multiple","department.single","department.multiple"].includes(N.type))})),operations:n.filter(u=>u.platformAccess?.directory).map(u=>({code:u.code,directory:u.platformAccess.directory}))}}]:[],...n.some(u=>u.platformAccess?.directory?.mode==="selected-user")?[{code:"directory.selected-user",declaration:n.filter(u=>u.platformAccess?.directory?.mode==="selected-user").map(u=>({code:u.code,directory:u.platformAccess.directory}))}]:[],...a?[{code:"data.managed-files",declaration:{operations:n.filter(u=>u.platformAccess?.managedFiles||u.platformAccess?.managedFileCopies).map(u=>({code:u.code,...u.platformAccess?.managedFiles?{managedFiles:u.platformAccess.managedFiles}:{},...u.platformAccess?.managedFileCopies?{managedFileCopies:u.platformAccess.managedFileCopies}:{}})),subscriptions:e.events.subscriptions.filter(u=>u.platformAccess?.managedFileCopies).map(u=>({code:u.code,managedFileCopies:u.platformAccess.managedFileCopies}))}}]:[],...e.events.subscriptions.some(u=>u.execution)?[{code:"events.native-data-actions",declaration:e.events.subscriptions.filter(u=>u.execution)}]:[],...e.events.capturePolicies?.length?[{code:"events.capture-policy",declaration:e.events.capturePolicies}]:[],...s?[{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(u=>u.definition.instanceCommands!==void 0)?[{code:"workflow.instance-cancellation-policy",declaration:e.workflows.definitions.filter(u=>u.definition.instanceCommands!==void 0)}]:[],...E.length?[{code:"workflow.named-input-sources",declaration:E}]:[],...e.workflows.definitions.some(u=>Object.values(u.definition.nodes).some(N=>N.administration!==void 0||N.operationPolicy!==void 0))?[{code:"workflow.node-administration",declaration:e.workflows.definitions.filter(u=>Object.values(u.definition.nodes).some(N=>N.administration!==void 0||N.operationPolicy!==void 0))}]:[],...e.workflows.definitions.some(u=>Object.values(u.definition.nodes).some(N=>N.kind==="cc"))?[{code:"workflow.automatic-cc",declaration:e.workflows.definitions.filter(u=>Object.values(u.definition.nodes).some(N=>N.kind==="cc"))}]:[],...e.workflows.definitions.some(u=>u.definition.taskPages!==void 0)?["workflow.task-page-submit","workflow.task-private-drafts"].map(u=>({code:u,declaration:e.workflows.definitions.filter(N=>N.definition.taskPages!==void 0)})):[],...l.length?[{code:"workflow.task-managed-files",declaration:l}]:[],...d.length?[{code:"workflow.task-owned-files",declaration:d}]:[],...p.length?[{code:"workflow.task-rich-fields",declaration:p}]:[],...e.workflows.definitions.some(u=>Object.values(u.definition.taskPages||{}).some(N=>N.fields.some(y=>y.subtable)))?[{code:"workflow.task-owned-subtables",declaration:e.workflows.definitions.filter(u=>Object.values(u.definition.taskPages||{}).some(N=>N.fields.some(y=>y.subtable)))}]:[],...e.workflows.definitions.some(u=>Object.values(u.definition.nodes).some(N=>N.kind==="action"))?[{code:"workflow.durable-business-step",declaration:e.workflows.definitions.filter(u=>Object.values(u.definition.nodes).some(N=>N.kind==="action"))}]:[],...e.workflows.bindings.some(u=>Object.values(u.binding.bindings).some(N=>N.routing!==void 0))?[{code:"workflow.assignment-routing",declaration:e.workflows.bindings.filter(u=>Object.values(u.binding.bindings).some(N=>N.routing!==void 0))}]:[],...g?[{code:"business-process.durable-command",declaration:{operations:n.filter(u=>u.platformAccess?.workflow).map(u=>({code:u.code,workflow:u.platformAccess.workflow})),definitions:f,activations:e.workflows.activations.filter(u=>f.some(N=>N.definition.code===u.workflowCode))}}]:[],...r?[{code:"notification-hub-v2",declaration:{operations:n.filter(u=>u.platformAccess?.notification).map(u=>({code:u.code,notification:u.platformAccess.notification})),subscriptions:e.events.subscriptions.filter(u=>u.platformAccess?.notification).map(u=>({code:u.code,notification:u.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:u,declaration:N})=>({code:u,contractVersion:hi[u],usageDigest:`sha256:${X(N)}`})).sort((u,N)=>u.code===N.code?0:u.code<N.code?-1:1)}function zi(e){let t=new Map,o=new Set(e.resources.map(s=>String(s.code)));for(let[s,a]of w(e.capturePolicies===void 0?[]:e.capturePolicies,"/capturePlan/capturePolicies",100).entries()){let r=`/capturePlan/capturePolicies/${s}`,c=T(a,r);R(c,["resourceCode","mode"],r);let l=J(c.resourceCode,`${r}/resourceCode`);o.has(l)||m("NATIVE_EVENT_CAPTURE_RESOURCE_NOT_FOUND",r,{resourceCode:l}),t.has(l)&&m("NATIVE_EVENT_CAPTURE_POLICY_DUPLICATE",r,{resourceCode:l}),c.mode!=="all"&&c.mode!=="subscribed"&&m("NATIVE_EVENT_CAPTURE_MODE_INVALID",`${r}/mode`),t.set(l,c.mode)}let n=new Map(e.dataPolicies.map((s,a)=>{let r=T(s,`/capturePlan/dataPolicies/${a}`);return[String(r.code),r]})),i=e.subscriptions.map((s,a)=>T(s,`/capturePlan/subscriptions/${a}`));return e.resources.map((s,a)=>{let r=`/capturePlan/resources/${a}`,c=T(s,r),l=J(c.code,`${r}/code`),p=c.schema?T(c.schema,`${r}/schema`):c,d=new Set(w(p.fields||[],`${r}/schema/fields`,500).map((O,h)=>K(T(O,`${r}/schema/fields/${h}`).code,`${r}/schema/fields/${h}/code`))),f=c.dataPolicyCode?F(c.dataPolicyCode,`${r}/dataPolicyCode`):null,g=f?n.get(f):void 0;f&&!g&&m("NATIVE_EVENT_CAPTURE_AUTHZ_POLICY_NOT_FOUND",r,{resourceCode:l,dataPolicyCode:f});let E=new Set;for(let O of g?.rules||[])E.add(String(O.field));if(g?.readExpression)for(let O of Ot(g.readExpression,`${r}/readExpression`))E.add(String(O.rule.field));let A=new Set,b=new Set,I=new Set;for(let[O,h]of i.entries()){let C=w(h.eventTypes,`/capturePlan/subscriptions/${O}/eventTypes`,20).map(String);if(!C.some(P=>P.startsWith("openxiangda.data.")))continue;let k=T(h.filter||{},`/capturePlan/subscriptions/${O}/filter`),V=Array.isArray(k.resourceCodes)?k.resourceCodes.map(String):[];if(V.length&&!V.includes(l))continue;for(let P of C)dn.includes(P)&&I.add(P);for(let P of Ra(k,`/capturePlan/subscriptions/${O}/filter`))A.add(P);let M=T(h.payload||{},`/capturePlan/subscriptions/${O}/payload`);for(let P of w(M.fields||[],`/capturePlan/subscriptions/${O}/payload/fields`,32))b.add(K(P,`/capturePlan/subscriptions/${O}/payload/fields`))}let _=new Set([...A,...b]),u=new Set([..._,...E]);u.size>wi&&m("NATIVE_EVENT_CAPTURE_FIELDS_LIMIT",r,{resourceCode:l,maximum:wi});for(let O of u)!d.has(O)&&!(E.has(O)&&qi.has(O))&&m("NATIVE_EVENT_CAPTURE_FIELD_NOT_FOUND",r,{resourceCode:l,field:O});let N=T(c.fieldPolicies||{},`${r}/fieldPolicies`);for(let O of _)N[O]?.mask==="omit"&&m("NATIVE_EVENT_CAPTURE_FIELD_SENSITIVE",r,{resourceCode:l,field:O});let y={resourceCode:l,...t.get(l)==="subscribed"?{capturedEventTypes:[...I].sort()}:{},filterFields:[...A].sort(),projectionFields:[...b].sort(),authorizationFields:[...E].sort(),captureFields:[...u].sort()};return{...y,digest:X(y)}}).sort((s,a)=>s.resourceCode.localeCompare(a.resourceCode))}function Ra(e,t){let o=new Set;for(let[a,r]of w(e.changes||[],`${t}/changes`,16).entries()){let c=T(r,`${t}/changes/${a}`);o.add(K(c.field,`${t}/changes/${a}/field`))}let n=T(e.changedFields||{},`${t}/changedFields`);for(let a of["anyOf","allOf","noneOf"])for(let[r,c]of w(n[a]||[],`${t}/changedFields/${a}`,32).entries())o.add(K(c,`${t}/changedFields/${a}/${r}`));let i=0,s=(a,r,c)=>{c>3&&m("NATIVE_EVENT_FILTER_DEPTH_LIMIT",r);let l=T(a,r);if(l.change){let d=T(l.change,`${r}/change`);o.add(K(d.field,`${r}/change/field`)),i+=1;return}if(l.not){s(l.not,`${r}/not`,c+1);return}let p=l.all?"all":l.any?"any":null;p||m("NATIVE_EVENT_FILTER_CONDITION_INVALID",r);for(let[d,f]of w(l[p],`${r}/${p}`,16).entries())s(f,`${r}/${p}/${d}`,c+1)};return e.where&&s(e.where,`${t}/where`,1),i+=Array.isArray(e.changes)?e.changes.length:0,i>16&&m("NATIVE_EVENT_FILTER_ATOM_LIMIT",t),[...o].sort()}function Ca(e,t){R(e,["schemaVersion","compilerContractVersion","appCode","perspectives","authz","backend","data","events","workflows","frontend","runtime"],"/config"),j(e.schemaVersion,ta,"/config/schemaVersion"),j(e.compilerContractVersion,Rt,"/config/compilerContractVersion"),j(e.appCode,t,"/config/appCode"),w(e.perspectives,"/config/perspectives",100);let o=T(e.authz,"/config/authz");R(o,["capabilities","roles","scopeDimensions","scopeSources","roleMembershipSources","relationshipGrantSources","dataPolicies","authorizationTransitions"],"/config/authz",["authenticatedUserRoleCode"]),w(o.capabilities,"/config/authz/capabilities",2e3),w(o.roles,"/config/authz/roles",100),w(o.scopeDimensions,"/config/authz/scopeDimensions",100),w(o.scopeSources,"/config/authz/scopeSources",100),w(o.roleMembershipSources,"/config/authz/roleMembershipSources",100),w(o.relationshipGrantSources,"/config/authz/relationshipGrantSources",100),w(o.dataPolicies,"/config/authz/dataPolicies",100),w(o.authorizationTransitions,"/config/authz/authorizationTransitions",100);let n=T(e.backend,"/config/backend");R(n,["secrets","operations"],"/config/backend"),w(n.secrets,"/config/backend/secrets",100),w(n.operations,"/config/backend/operations",500),dc(n.secrets);let i=T(e.data,"/config/data");R(i,["resources"],"/config/data",["resourceDetailRoutes","subjectReadSurfaces","concurrency"]),w(i.resources,"/config/data/resources",100),i.subjectReadSurfaces!==void 0&&w(i.subjectReadSurfaces,"/config/data/subjectReadSurfaces",Y.subjectReadSurfaces),i.resourceDetailRoutes!==void 0&&w(i.resourceDetailRoutes,"/config/data/resourceDetailRoutes",100);let s=T(e.events,"/config/events");R(s,["schemas","subscriptions","timers","dateTriggers"],"/config/events",["capturePolicies"]),w(s.schemas,"/config/events/schemas",100),w(s.subscriptions,"/config/events/subscriptions",100),w(s.timers,"/config/events/timers",100),w(s.dateTriggers,"/config/events/dateTriggers",100);let a=T(e.workflows,"/config/workflows");R(a,["definitions","bindings","activations","providers","editableParameters"],"/config/workflows"),w(a.definitions,"/config/workflows/definitions",100),w(a.bindings,"/config/workflows/bindings",100),w(a.activations,"/config/workflows/activations",100),w(a.providers,"/config/workflows/providers",100),w(a.editableParameters,"/config/workflows/editableParameters",100);let r=T(e.frontend,"/config/frontend");R(r,["routes","user","admin","devicePolicy"],"/config/frontend",["authentication","publicAccess"]),w(r.routes,"/config/frontend/routes",500);let c=T(r.user,"/config/frontend/user");R(c,["applicationTodoCenter"],"/config/frontend/user"),st(c.applicationTodoCenter,"/config/frontend/user/applicationTodoCenter"),No(r.devicePolicy,"/config/frontend/devicePolicy"),Object.prototype.hasOwnProperty.call(r,"authentication")&&Hi(r.authentication,r.routes,e,"/config/frontend/authentication"),Object.prototype.hasOwnProperty.call(r,"publicAccess")&&Ka(r.publicAccess,e,"/config/frontend/publicAccess");let l=T(r.admin,"/config/frontend/admin");R(l,["navigation"],"/config/frontend/admin",["access"]),l.access!==void 0&&An(l.access,"/config/frontend/admin/access",e.appCode),za(l.navigation,"/config/frontend/admin/navigation");let p=T(e.runtime,"/config/runtime");R(p,["protocolCapabilities","health"],"/config/runtime"),v(p.protocolCapabilities,"/config/runtime/protocolCapabilities",100),R(T(p.health,"/config/runtime/health"),["livePath","readyPath","versionPath"],"/config/runtime/health"),j(p.health.livePath,"/__platform/health","/config/runtime/health/livePath"),j(p.health.readyPath,"/__platform/ready","/config/runtime/health/readyPath"),j(p.health.versionPath,"/__platform/version","/config/runtime/health/versionPath")}function Sa(e,t,o){R(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"]),j(e.schemaVersion,Ki,"/contracts/schemaVersion"),j(e.compilerContractVersion,Rt,"/contracts/compilerContractVersion"),S(e.generatorVersion,"/contracts/generatorVersion",128),j(e.appCode,t,"/contracts/appCode"),j(e.configDigest,o,"/contracts/configDigest"),w(e.perspectives,"/contracts/perspectives",Y.perspectives),w(e.resources,"/contracts/resources",Y.resources),e.subjectReadSurfaces!==void 0&&w(e.subjectReadSurfaces,"/contracts/subjectReadSurfaces",Y.subjectReadSurfaces),w(e.capabilities,"/contracts/capabilities",Y.capabilities),w(e.operations,"/contracts/operations",Y.operations),w(e.eventConsumers,"/contracts/eventConsumers",Y.eventConsumers),w(e.eventProducers,"/contracts/eventProducers",Y.eventProducers),w(e.eventSchemas,"/contracts/eventSchemas",Y.eventSchemas),T(e.eventHandlerManifest,"/contracts/eventHandlerManifest"),v(e.eventTypes,"/contracts/eventTypes",Y.eventTypes),w(e.workflows,"/contracts/workflows",Y.workflows),w(e.routes,"/contracts/routes",Y.routes),Object.prototype.hasOwnProperty.call(e,"authentication")&&Ma(e.authentication,"/contracts/authentication"),Object.prototype.hasOwnProperty.call(e,"publicAccess")&&Ga(e.publicAccess,"/contracts/publicAccess"),Object.prototype.hasOwnProperty.call(e,"adminAccess")&&An(e.adminAccess,"/contracts/adminAccess",t),ec(e.routeManifest,"/contracts/routeManifest",t),Xa(e.adminPages,"/contracts/adminPages"),Qa(e.adminNavigation,"/contracts/adminNavigation")}function wa(e,t,o){let n=ka(e);sc(e,n),ac(e),rc(e),lc(e);let i=e.events.schemas.map((_,u)=>{let N=`/config/events/schemas/${u}`,y=T(_,N),O=S(y.eventType,`${N}/eventType`,255);return O.startsWith("openxiangda.")&&m("NATIVE_EVENT_SCHEMA_RESERVED",`${N}/eventType`,{eventType:O}),j(y.schemaDigest,X(T(y.jsonSchema,`${N}/jsonSchema`)),`${N}/schemaDigest`),y}),s=new Set([...dn,...ln,...i.map(_=>String(_.eventType))]),a=new Map(e.data.resources.map(_=>[String(_.code),new Map(_.schema.fields.map(u=>[String(u.code),String(u.type)]))])),r=Z(e.events.subscriptions.map((_,u)=>{let N=`/config/events/subscriptions/${u}`,y=T(_,N),O=v(y.eventTypes,`${N}/eventTypes`,20);O.forEach((V,M)=>{s.has(V)||m("NATIVE_EVENT_TYPE_NOT_REGISTERED",`${N}/eventTypes/${M}`,{eventType:V})});let h=Qn(y,e.data.resources,N),C=$a(y.delivery,O,`${N}/delivery`),k=Da(y.platformAccess,`${N}/platformAccess`,a,e,y);return{code:F(y.code,`${N}/code`),endpointPath:Ae(y.endpointPath,`${N}/endpointPath`),eventTypes:O,filter:T(y.filter,`${N}/filter`),payload:h?.payload||T(y.payload,`${N}/payload`),...h?{execution:h.execution}:{},...k?{platformAccess:k}:{},delivery:C}}),_=>_.code),c=new Map(i.map(_=>[String(_.eventType),String(_.dataSchemaVersion)])),l=Z([...e.data.resources.flatMap(_=>dn.map(u=>({code:`data:${_.code}:${u}`,source:"data",eventType:u,dataSchemaVersion:"2.0.0",resourceCode:_.code}))),...i.map(_=>({code:`app:${_.eventType}`,source:"app",eventType:_.eventType,dataSchemaVersion:_.dataSchemaVersion})),...e.events.timers.map(_=>({code:_.code,source:"timer",eventType:_.eventType,dataSchemaVersion:c.get(String(_.eventType))||"2.0.0"})),...e.events.dateTriggers.map(_=>({code:_.code,source:"date",eventType:_.eventType,dataSchemaVersion:c.get(String(_.eventType))||"2.0.0",resourceCode:_.resourceCode,field:_.field})),...e.workflows.activations.length?ln.filter(_=>!oo.includes(_)||e.workflows.definitions.some(u=>Object.values(u.definition.nodes).some(N=>N.kind==="action"))).map(_=>({code:`workflow:${_}`,source:"workflow",eventType:_,dataSchemaVersion:"2.0.0"})):[]],_=>`${_.source}:${_.code}:${_.eventType}`),p=U([...r.flatMap(_=>_.eventTypes),...l.map(_=>String(_.eventType))]);Ha(e);let d=Zi(e),f;try{f=Mn(e.data.concurrency,e.data.resources,n)}catch(_){throw _ instanceof Ye&&m(_.code,_.pointer,{reason:_.reason}),_}f?.commands.some(_=>_.mode==="durable")&&e.backend?.enabled===!1&&m("NATIVE_MANAGED_CONCURRENCY_INVALID","/data/concurrency",{reason:"durable commands require backend runtime"});let g=Fa(e,n),E=Yi(e),A=e.workflows.definitions.map(_=>_.definition),b=Zt(A),I=so(A,r,!0);I.length&&m(I[0],"/config/events/subscriptions");try{Gn(e.data.resources,E)}catch(_){throw _ instanceof Pe&&m(_.code,_.pointer,{reason:_.reason}),_}return{schemaVersion:Ki,compilerContractVersion:Rt,generatorVersion:o,appCode:e.appCode,configDigest:t,perspectives:e.perspectives,resources:Va(e),...g.length?{subjectReadSurfaces:g}:{},...f?{concurrency:f}:{},capabilities:Z(n,_=>_.code),operations:E,eventConsumers:r,eventProducers:l,eventSchemas:i,eventHandlerManifest:{schemaVersion:Ta,appCode:e.appCode,handlers:r.filter(_=>!_.execution).map(_=>({code:_.code,endpointPath:_.endpointPath,eventTypes:_.eventTypes,dataSchemaVersions:U(_.eventTypes.map(u=>u.startsWith("openxiangda.")?"2.0.0":c.get(u)||"2.0.0")),maxBodyBytes:65536,receiptProtocolVersion:2,...b[_.code]?{workflowStep:b[_.code]}:{}}))},eventTypes:p,workflows:ns(e),routes:gn(e),...Object.prototype.hasOwnProperty.call(e.frontend,"authentication")?{authentication:Ua(e)}:{},...Object.prototype.hasOwnProperty.call(e.frontend,"publicAccess")?{publicAccess:qa(e)}:{},...e.frontend.admin.access?{adminAccess:e.frontend.admin.access}:{},routeManifest:oc(e),adminPages:d,adminNavigation:Ja(e)}}function Da(e,t,o,n,i){if(e===void 0)return;let s=T(e,t);R(s,["notification","managedFileCopies","decimalReservation"],t,!0);let a={};if(s.decimalReservation!==void 0)try{a.decimalReservation=ti(s.decimalReservation,ni(n,i))}catch{m("NATIVE_EVENT_DECIMAL_RESERVATION_INVALID",`${t}/decimalReservation`)}if(s.notification!==void 0){let r=T(s.notification,`${t}/notification`);R(r,["mode"],`${t}/notification`),j(r.mode,"business-standard",`${t}/notification/mode`),a.notification={mode:"business-standard"}}if(s.managedFileCopies!==void 0){let r=w(s.managedFileCopies,`${t}/managedFileCopies`,16);r.length||m("NATIVE_EVENT_MANAGED_FILE_COPIES_REQUIRED",`${t}/managedFileCopies`);let c=new Set;a.managedFileCopies=Z(r.map((l,p)=>{let d=`${t}/managedFileCopies/${p}`,f=T(l,d);R(f,["mode","sourceResourceCode","sourceFieldCodes","targetResourceCode","targetFieldCodes"],d),j(f.mode,"copy",`${d}/mode`);let g=J(f.sourceResourceCode,`${d}/sourceResourceCode`),E=J(f.targetResourceCode,`${d}/targetResourceCode`),A=o.get(g),b=o.get(E);(!A||!b)&&m("NATIVE_EVENT_MANAGED_FILE_COPY_RESOURCE_INVALID",d);let I=v(f.sourceFieldCodes,`${d}/sourceFieldCodes`,16),_=v(f.targetFieldCodes,`${d}/targetFieldCodes`,16);(!I.length||I.length!==_.length)&&m("NATIVE_EVENT_MANAGED_FILE_COPY_FIELDS_INVALID",d),I.forEach((N,y)=>{let O=A.get(N),h=b.get(_[y]);(!["file","image"].includes(String(O))||O!==h)&&m("NATIVE_EVENT_MANAGED_FILE_COPY_FIELD_INVALID",`${d}/sourceFieldCodes/${y}`)});let u=`${g}:${I.join(",")}=>${E}:${_.join(",")}`;return c.has(u)&&m("NATIVE_EVENT_MANAGED_FILE_COPY_DUPLICATE",d),c.add(u),{mode:"copy",sourceResourceCode:g,sourceFieldCodes:U(I),targetResourceCode:E,targetFieldCodes:U(_)}}),l=>`${l.sourceResourceCode}:${l.sourceFieldCodes.join(",")}=>${l.targetResourceCode}:${l.targetFieldCodes.join(",")}`)}return Object.keys(a).length||m("NATIVE_EVENT_PLATFORM_ACCESS_EMPTY",t),a}function $a(e,t,o){let n=T(e,o);R(n,["timeoutMs","maxAttempts","initialBackoffMs","maxBackoffMs","ordering","concurrency"],o),te(n.timeoutMs,`${o}/timeoutMs`,1e3,3e4),te(n.maxAttempts,`${o}/maxAttempts`,1,12);let i=te(n.initialBackoffMs,`${o}/initialBackoffMs`,1e3,3e5);te(n.maxBackoffMs,`${o}/maxBackoffMs`,i,18e5),te(n.concurrency,`${o}/concurrency`,1,50);let s=S(n.ordering,`${o}/ordering`,32);return["none","record","workflow-instance"].includes(s)||m("NATIVE_EVENT_DELIVERY_ORDERING_INVALID",`${o}/ordering`),s==="workflow-instance"&&t.some(a=>!Oa.has(a))&&m("NATIVE_EVENT_WORKFLOW_ORDERING_REQUIRES_WORKFLOW_FACTS",`${o}/ordering`),n}function ka(e){let t=new Map;for(let o of ss(e.appCode))t.set(o.code,o);for(let[o,n]of e.authz.capabilities.entries()){let i=`/config/authz/capabilities/${o}`,s=T(n,i);R(s,["code","kind","name","description"],i,!0);let a=$e(s.code,`${i}/code`,e.appCode);t.has(a)&&m("NATIVE_CAPABILITY_DUPLICATE",`${i}/code`),["backend","ui"].includes(s.kind)||m("NATIVE_CAPABILITY_KIND_INVALID",`${i}/kind`);let r={code:a,kind:s.kind,name:S(s.name,`${i}/name`,255),source:"explicit",...s.description===void 0?{}:{description:Oo(s.description,`${i}/description`,2e3)}};t.set(a,r)}for(let[o,n]of e.data.resources.entries()){let i=`/config/data/resources/${o}`,s=Me(n,i,e.appCode),a={read:`\u8BFB\u53D6${s.name}`,create:`\u65B0\u5EFA${s.name}`,update:`\u66F4\u65B0${s.name}`,delete:`\u5220\u9664${s.name}`};for(let r of["read","create","update","delete"]){let c=$e(s.capabilities[r],`${i}/capabilities/${r}`,e.appCode);t.has(c)&&m("NATIVE_CAPABILITY_DUPLICATE",`${i}/capabilities/${r}`),t.set(c,{code:c,kind:"data",name:a[r],source:"data"})}for(let[r,c]of Object.entries(s.fieldPolicies)){if(Ge(r))continue;let l=T(c,`${i}/fieldPolicies/${r}`);for(let p of["read","create","update"])if(Array.isArray(l[p]))for(let d of v(l[p],`${i}/fieldPolicies/${r}/${p}`,2e3))$e(d,`${i}/fieldPolicies/${r}/${p}`,e.appCode),!t.has(d)&&t.set(d,{code:d,kind:"data",name:`${s.name}.${r}.${p}`,source:"data"})}}return[...t.values()]}function Va(e){let t=va(e);return Z(e.data.resources.map((o,n)=>{let i=Me(o,`/config/data/resources/${n}`,e.appCode),s=t.get(i.code);return{code:i.code,schemaDigest:X(i.schema),fields:Z(i.schema.fields.map(a=>({code:a.code,type:a.type})),a=>a.code),...s?{detailRouteCode:s}:{}}}),o=>o.code)}function Fa(e,t){if(e.data.subjectReadSurfaces===void 0)return[];let o=w(e.data.subjectReadSurfaces,"/config/data/subjectReadSurfaces",Y.subjectReadSurfaces),n=new Set(t.map(a=>String(a.code))),i=new Map(e.data.resources.map((a,r)=>{let c=`/config/data/resources/${r}`,l=Me(a,c,e.appCode);return[String(l.code),{resource:l,fields:new Map(w(T(l.schema,`${c}/schema`).fields,`${c}/schema/fields`,500).map(p=>{let d=T(p,`${c}/schema/fields`);return[String(d.code),d]}))}]})),s=new Set;return Z(o.map((a,r)=>{let c=`/config/data/subjectReadSurfaces/${r}`,l=T(a,c);R(l,["code","name","capability","subject","relations"],c);let p=F(l.code,`${c}/code`);s.has(p)&&m("NATIVE_SUBJECT_READ_SURFACE_CODE_DUPLICATE",`${c}/code`),s.add(p);let d=$e(l.capability,`${c}/capability`,e.appCode);n.has(d)||m("NATIVE_SUBJECT_READ_SURFACE_CAPABILITY_NOT_DECLARED",`${c}/capability`);let f=T(l.subject,`${c}/subject`);R(f,["resourceCode","fields"],`${c}/subject`);let g=J(f.resourceCode,`${c}/subject/resourceCode`),E=i.get(g);E||m("NATIVE_SUBJECT_READ_SURFACE_RESOURCE_NOT_DECLARED",`${c}/subject/resourceCode`);let A=v(f.fields,`${c}/subject/fields`,100).map((N,y)=>K(N,`${c}/subject/fields/${y}`));A.length||m("NATIVE_SUBJECT_READ_SURFACE_FIELDS_REQUIRED",`${c}/subject/fields`);for(let[N,y]of A.entries()){let O=E.fields.get(y);(!O||O.type==="subtable")&&m("NATIVE_SUBJECT_READ_SURFACE_FIELD_INVALID",`${c}/subject/fields/${N}`)}let b=w(l.relations,`${c}/relations`,8);b.length||m("NATIVE_SUBJECT_READ_SURFACE_RELATIONS_REQUIRED",`${c}/relations`);let I=new Set,_=0,u=Z(b.map((N,y)=>{let O=`${c}/relations/${y}`,h=T(N,O);R(h,["code","resourceCode","foreignKeyField","fields","limit"],O,["order"]);let C=F(h.code,`${O}/code`);I.has(C)&&m("NATIVE_SUBJECT_READ_SURFACE_RELATION_CODE_DUPLICATE",`${O}/code`),I.add(C);let k=J(h.resourceCode,`${O}/resourceCode`),V=i.get(k);V||m("NATIVE_SUBJECT_READ_SURFACE_RESOURCE_NOT_DECLARED",`${O}/resourceCode`);let M=K(h.foreignKeyField,`${O}/foreignKeyField`),P=V.fields.get(M),re=T(P?.source||{},`${O}/foreignKeyField/source`);(!P||!["uuid","resource-ref.single"].includes(String(P.type))||P.type==="resource-ref.single"&&(re.kind!=="resource"||re.resourceCode!==g))&&m("NATIVE_SUBJECT_READ_SURFACE_RELATION_INVALID",`${O}/foreignKeyField`);let Ee=v(h.fields,`${O}/fields`,100).map((ce,$)=>K(ce,`${O}/fields/${$}`));Ee.length||m("NATIVE_SUBJECT_READ_SURFACE_FIELDS_REQUIRED",`${O}/fields`);for(let[ce,$]of Ee.entries()){let W=V.fields.get($);(!W||W.type==="subtable")&&m("NATIVE_SUBJECT_READ_SURFACE_FIELD_INVALID",`${O}/fields/${ce}`)}let H=w(h.order||[],`${O}/order`,10).map((ce,$)=>{let W=`${O}/order/${$}`,L=T(ce,W);R(L,["field","direction"],W);let G=K(L.field,`${W}/field`),q=V.fields.get(G);return(!qi.has(G)&&!q||q?.type==="subtable"||q&&!Je(q.type))&&m("NATIVE_SUBJECT_READ_SURFACE_ORDER_FIELD_INVALID",`${W}/field`),["asc","desc"].includes(String(L.direction))||m("NATIVE_SUBJECT_READ_SURFACE_ORDER_DIRECTION_INVALID",`${W}/direction`),{field:G,direction:L.direction}}),Te=te(h.limit,`${O}/limit`,1,100);return _+=Te,{code:C,resourceCode:k,foreignKeyField:M,fields:U(Ee),...H.length?{order:H}:{},limit:Te}}),N=>N.code);return _>400&&m("NATIVE_SUBJECT_READ_SURFACE_ROW_LIMIT_EXCEEDED",`${c}/relations`),{code:p,name:S(l.name,`${c}/name`,255),capability:d,subject:{resourceCode:g,fields:U(A)},relations:u}}),a=>a.code)}function va(e){let t=e.data.resourceDetailRoutes===void 0?[]:w(e.data.resourceDetailRoutes,"/config/data/resourceDetailRoutes",100),o=new Map(e.data.resources.map((s,a)=>{let r=`/config/data/resources/${a}`,c=Me(s,r,e.appCode);return[c.code,c]})),n=new Map(gn(e).map(s=>[String(s.code),s])),i=new Map;for(let[s,a]of t.entries()){let r=`/config/data/resourceDetailRoutes/${s}`,c=T(a,r);R(c,["resourceCode","desktop","mobile"],r);let l=J(c.resourceCode,`${r}/resourceCode`);i.has(l)&&m("NATIVE_DATA_RESOURCE_DETAIL_ROUTE_DUPLICATE",`${r}/resourceCode`);let p=o.get(l);p||m("NATIVE_DATA_RESOURCE_DETAIL_ROUTE_RESOURCE_MISSING",`${r}/resourceCode`);let d=F(c.desktop,`${r}/desktop`),f=F(c.mobile,`${r}/mobile`);d===f&&m("NATIVE_DATA_RESOURCE_DETAIL_ROUTE_INVALID",r);let g=String(p.capabilities.read);for(let[E,A]of[["desktop",d],["mobile",f]]){let b=`${r}/${E}`,I=n.get(A);I||m("NATIVE_DATA_RESOURCE_DETAIL_ROUTE_REFERENCE_MISSING",b),I.surface!=="user"&&m("NATIVE_DATA_RESOURCE_DETAIL_ROUTE_SURFACE_INVALID",b);let _=Ae(I.path,`${b}/path`),u=[..._.matchAll(/:([A-Za-z][A-Za-z0-9_]*)/g)],N=E==="mobile"?!_.startsWith("/m/"):_==="/m"||_.startsWith("/m/");(_.includes("*")||_.includes("?")||_.includes("#")||_.split("/").includes("..")||u.length!==1||N)&&m("NATIVE_DATA_RESOURCE_DETAIL_ROUTE_PATH_INVALID",b);let y=Array.isArray(I.access?.allOf)?I.access.allOf:[];I.capability!==g&&!y.includes(g)&&m("NATIVE_DATA_RESOURCE_DETAIL_ROUTE_CAPABILITY_INVALID",b)}i.set(l,{desktop:d,mobile:f})}return i}function Yi(e){let t=new Map(e.data.resources.map((a,r)=>{let c=`/config/data/resources/${r}`,l=Me(a,c,e.appCode);return[l.code,new Map(l.schema.fields.map(p=>[String(p.code),p]))]})),o=new Map(e.data.resources.map((a,r)=>{let c=`/config/data/resources/${r}`,l=Me(a,c,e.appCode);return[l.code,new Map(l.schema.fields.map(p=>[String(p.code),String(p.type)]))]})),n=new Set(o.keys()),i=new Set(e.workflows.activations.map((a,r)=>En(T(a,`/config/workflows/activations/${r}`).workflowCode,`/config/workflows/activations/${r}/workflowCode`))),s=new Map;return Z(e.backend.operations.map((a,r)=>{let c=`/config/backend/operations/${r}`,l=T(a,c);R(l,["code","method","path","capability","requestSchema","responseSchema","description","platformAccess","browser","ai"],c,!0);let p=S(l.method,`${c}/method`,16);["GET","POST","PUT","PATCH","DELETE"].includes(p)||m("NATIVE_OPERATION_METHOD_INVALID",`${c}/method`);let d=F(l.code,`${c}/code`);ja(l.ai,c,d,p,n);let f=xa(l.platformAccess,`${c}/platformAccess`,o,t,i,new Set(e.authz.roles.map(E=>String(E.code))));if(f?.decimalReservation){let E=f.decimalReservation,A=String(E.resourceCode),b=JSON.stringify([E.amountFieldCode,E.currencyFieldCode,E.relationFieldCode,E.parentFieldCode,E.rootFieldCode,E.statusFieldCode,E.parentRelationValue,E.childRelationValue]),I=s.get(A);I&&I!==b&&m("NATIVE_DECIMAL_RESERVATION_MAPPING_CONFLICT",`${c}/platformAccess/decimalReservation`),s.set(A,b)}let g=Pa(l.browser,`${c}/browser`,p,l.requestSchema,l.responseSchema,o,t,e.data.subjectReadSurfaces||[]);return{code:d,method:p,path:Ae(l.path,`${c}/path`),requiredCapability:$e(l.capability,`${c}/capability`,e.appCode),requestSchemaDigest:X(T(l.requestSchema,`${c}/requestSchema`)),responseSchemaDigest:X(T(l.responseSchema,`${c}/responseSchema`)),...l.description===void 0?{}:{description:Oo(l.description,`${c}/description`,2e3)},...f?{platformAccess:f}:{},...g?{browser:g}:{}}}),a=>a.code)}function Pa(e,t,o,n,i,s,a,r){if(e===void 0)return null;let c=T(e,t);R(c,["exposure","behavior","idempotency","subject"],t,["refreshTargets","fileIntent"]),j(c.exposure,"authenticated",`${t}/exposure`);let l=S(c.behavior,`${t}/behavior`,32);["read","controlled"].includes(l)||m("NATIVE_OPERATION_BROWSER_BEHAVIOR_INVALID",`${t}/behavior`);let p=S(c.idempotency,`${t}/idempotency`,32);(!["none","required"].includes(p)||l==="controlled"&&p!=="required"||l==="read"&&p!=="none")&&m("NATIVE_OPERATION_BROWSER_IDEMPOTENCY_INVALID",`${t}/idempotency`);let d=T(c.subject,`${t}/subject`);R(d,["resourceCode","inputField"],`${t}/subject`);let f=J(d.resourceCode,`${t}/subject/resourceCode`);s.has(f)||m("NATIVE_OPERATION_BROWSER_SUBJECT_RESOURCE_NOT_DECLARED",`${t}/subject/resourceCode`);let g=K(d.inputField,`${t}/subject/inputField`),E=T(n,`${t}/requestSchema`),A=T(i,`${t}/responseSchema`);(E.type!=="object"||E.additionalProperties!==!1||A.type!=="object"||A.additionalProperties!==!1)&&m("NATIVE_OPERATION_BROWSER_SCHEMA_ROOT_INVALID",`${t}/requestSchema`);let b=T(E.properties,`${t}/requestSchema/properties`),I=new Set(E.required===void 0?[]:v(E.required,`${t}/requestSchema/required`,200));(!(g in b)||!I.has(g))&&m("NATIVE_OPERATION_BROWSER_SUBJECT_INPUT_INVALID",`${t}/subject/inputField`);let _=T(b[g],`${t}/requestSchema/properties/${g}`);(_.type!=="string"||_.format!=="uuid")&&m("NATIVE_OPERATION_BROWSER_SUBJECT_INPUT_INVALID",`${t}/subject/inputField`);let u=new Map((Array.isArray(r)?r:[]).map((C,k)=>{let V=T(C,`/config/data/subjectReadSurfaces/${k}`);return[String(V.code),String(T(V.subject,`/config/data/subjectReadSurfaces/${k}/subject`).resourceCode)]})),N=c.refreshTargets===void 0?[]:w(c.refreshTargets,`${t}/refreshTargets`,16),y=new Set,O=Z(N.map((C,k)=>{let V=`${t}/refreshTargets/${k}`,M=T(C,V);R(M,["kind","code"],V),j(M.kind,"subject-surface",`${V}/kind`);let P=F(M.code,`${V}/code`);return(y.has(P)||!u.has(P)||u.get(P)!==f)&&m("NATIVE_OPERATION_BROWSER_REFRESH_TARGET_INVALID",`${V}/code`),y.add(P),{kind:"subject-surface",code:P}}),C=>`${C.kind}:${C.code}`),h=La(c.fileIntent,`${t}/fileIntent`,o,l,p,f,b,I,a);return{exposure:"authenticated",behavior:l,idempotency:p,subject:{resourceCode:f,inputField:g},...O.length?{refreshTargets:O}:{},...h?{fileIntent:h}:{}}}function La(e,t,o,n,i,s,a,r,c){if(e===void 0)return null;let l=T(e,t);R(l,["recordResourceCode","recordIdInputField","relationField","fileNameField","contentTypeField","sizeField","purposes","maxTtlSeconds","maxBytes"],t),(o!=="GET"||n!=="read"||i!=="none")&&m("NATIVE_OPERATION_FILE_INTENT_BEHAVIOR_INVALID",t);let p=J(l.recordResourceCode,`${t}/recordResourceCode`),d=c.get(p);d||m("NATIVE_OPERATION_FILE_INTENT_RESOURCE_NOT_DECLARED",`${t}/recordResourceCode`);let f=K(l.recordIdInputField,`${t}/recordIdInputField`),g=T(a[f],`${t}/recordIdInputField`);(!r.has(f)||g.type!=="string"||g.format!=="uuid")&&m("NATIVE_OPERATION_FILE_INTENT_RECORD_INPUT_INVALID",`${t}/recordIdInputField`);let E=K(l.relationField,`${t}/relationField`),A=d.get(E);(!A||!["uuid","resource-ref.single"].includes(String(A.type))||String(A.type)==="resource-ref.single"&&(String(T(A.source,`${t}/relationField`).kind||"")!=="resource"||String(T(A.source,`${t}/relationField`).resourceCode||"")!==s))&&m("NATIVE_OPERATION_FILE_INTENT_RELATION_INVALID",`${t}/relationField`);let b=[["fileNameField",["text.short","text.long"]],["contentTypeField",["text.short","text.long"]],["sizeField",["number.integer"]]],I={};for(let[y,O]of b){let h=K(l[y],`${t}/${y}`);O.includes(String(d.get(h)?.type))||m("NATIVE_OPERATION_FILE_INTENT_METADATA_INVALID",`${t}/${y}`),I[y]=h}let _=Z(v(l.purposes,`${t}/purposes`,2),y=>y);(!_.length||_.some(y=>!["preview","download"].includes(y)))&&m("NATIVE_OPERATION_FILE_INTENT_PURPOSE_INVALID",`${t}/purposes`);let u=Number(l.maxTtlSeconds);(!Number.isSafeInteger(u)||u<1||u>300)&&m("NATIVE_OPERATION_FILE_INTENT_TTL_INVALID",`${t}/maxTtlSeconds`);let N=Number(l.maxBytes);return(!Number.isSafeInteger(N)||N<1||N>104857600)&&m("NATIVE_OPERATION_FILE_INTENT_SIZE_INVALID",`${t}/maxBytes`),{recordResourceCode:p,recordIdInputField:f,relationField:E,fileNameField:I.fileNameField,contentTypeField:I.contentTypeField,sizeField:I.sizeField,purposes:_,maxTtlSeconds:u,maxBytes:N}}function xa(e,t,o,n,i,s){if(e===void 0)return null;let a=T(e,t);R(a,["directory","managedFiles","managedFileCopies","notification","workflow","roleAssertions","decimalReservation"],t,!0),Object.keys(a).length===0&&m("NATIVE_OPERATION_PLATFORM_ACCESS_EMPTY",t);let r={};if(a.roleAssertions!==void 0){let c=T(a.roleAssertions,`${t}/roleAssertions`);R(c,["roleCodes"],`${t}/roleAssertions`);let l=v(c.roleCodes,`${t}/roleAssertions/roleCodes`,20);l.length||m("NATIVE_OPERATION_ROLE_ASSERTIONS_REQUIRED",`${t}/roleAssertions/roleCodes`),l.forEach((p,d)=>{s.has(p)||m("NATIVE_ROLE_REFERENCE_MISSING",`${t}/roleAssertions/roleCodes/${d}`)}),r.roleAssertions={roleCodes:U(l)}}if(a.directory!==void 0){let c=T(a.directory,`${t}/directory`);R(c,["mode","fields"],`${t}/directory`),["current-initiator","selected-user"].includes(String(c.mode))||m("NATIVE_OPERATION_DIRECTORY_MODE_INVALID",`${t}/directory/mode`);let l=new Set(["displayName","employeeNumber","primaryDepartment","departments"]),p=v(c.fields,`${t}/directory/fields`,4);(!p.length||p.some(d=>!l.has(d)))&&m("NATIVE_OPERATION_DIRECTORY_FIELDS_INVALID",`${t}/directory/fields`),r.directory={mode:String(c.mode),fields:U(p)}}if(a.managedFiles!==void 0){let c=w(a.managedFiles,`${t}/managedFiles`,16);c.length||m("NATIVE_OPERATION_MANAGED_FILES_REQUIRED",`${t}/managedFiles`);let l=new Set;r.managedFiles=Z(c.map((p,d)=>{let f=`${t}/managedFiles/${d}`,g=T(p,f);R(g,["resourceCode","fieldCodes","intents"],f);let E=J(g.resourceCode,`${f}/resourceCode`);(l.has(E)||!o.has(E))&&m("NATIVE_OPERATION_MANAGED_FILE_RESOURCE_INVALID",`${f}/resourceCode`),l.add(E);let A=v(g.fieldCodes,`${f}/fieldCodes`,16);(!A.length||A.some(I=>!["file","image","signature","text.rich"].includes(String(o.get(E)?.get(I)||""))))&&m("NATIVE_OPERATION_MANAGED_FILE_FIELD_INVALID",`${f}/fieldCodes`);let b=v(g.intents,`${f}/intents`,2);return(!b.length||b.some(I=>!["create","update"].includes(I)))&&m("NATIVE_OPERATION_MANAGED_FILE_INTENT_INVALID",`${f}/intents`),{resourceCode:E,fieldCodes:U(A),intents:U(b)}}),p=>p.resourceCode)}if(a.managedFileCopies!==void 0){let c=w(a.managedFileCopies,`${t}/managedFileCopies`,16);c.length||m("NATIVE_OPERATION_MANAGED_FILE_COPIES_REQUIRED",`${t}/managedFileCopies`);let l=new Set;r.managedFileCopies=Z(c.map((p,d)=>{let f=`${t}/managedFileCopies/${d}`,g=T(p,f);R(g,["mode","sourceResourceCode","sourceFieldCodes","targetResourceCode","targetFieldCodes"],f),j(g.mode,"copy",`${f}/mode`);let E=J(g.sourceResourceCode,`${f}/sourceResourceCode`),A=J(g.targetResourceCode,`${f}/targetResourceCode`),b=o.get(E),I=o.get(A);(!b||!I)&&m("NATIVE_OPERATION_MANAGED_FILE_COPY_RESOURCE_INVALID",f);let _=v(g.sourceFieldCodes,`${f}/sourceFieldCodes`,16),u=v(g.targetFieldCodes,`${f}/targetFieldCodes`,16);(!_.length||_.length!==u.length)&&m("NATIVE_OPERATION_MANAGED_FILE_COPY_FIELDS_INVALID",f),_.forEach((y,O)=>{let h=b.get(y),C=I.get(u[O]);(!["file","image"].includes(String(h))||h!==C)&&m("NATIVE_OPERATION_MANAGED_FILE_COPY_FIELD_INVALID",`${f}/sourceFieldCodes/${O}`)});let N=`${E}:${_.join(",")}=>${A}:${u.join(",")}`;return l.has(N)&&m("NATIVE_OPERATION_MANAGED_FILE_COPY_DUPLICATE",f),l.add(N),{mode:"copy",sourceResourceCode:E,sourceFieldCodes:U(_),targetResourceCode:A,targetFieldCodes:U(u)}}),p=>`${p.sourceResourceCode}:${p.sourceFieldCodes.join(",")}=>${p.targetResourceCode}:${p.targetFieldCodes.join(",")}`)}if(a.notification!==void 0){let c=T(a.notification,`${t}/notification`);R(c,["mode"],`${t}/notification`),c.mode!=="business-standard"&&m("NATIVE_OPERATION_NOTIFICATION_MODE_INVALID",`${t}/notification/mode`),r.notification={mode:"business-standard"}}if(a.workflow!==void 0){let c=T(a.workflow,`${t}/workflow`);R(c,["codes"],`${t}/workflow`);let l=v(c.codes,`${t}/workflow/codes`,16);(!l.length||l.some(p=>!i.has(p)))&&m("NATIVE_OPERATION_WORKFLOW_CODE_INVALID",`${t}/workflow/codes`),r.workflow={codes:U(l)}}if(a.decimalReservation!==void 0){let c=`${t}/decimalReservation`,l=T(a.decimalReservation,c);R(l,["mode","resourceCode","amountFieldCode","currencyFieldCode","relationFieldCode","parentFieldCode","rootFieldCode","statusFieldCode","parentRelationValue","childRelationValue","eligibleParentStatuses","eligibleChildStatuses"],c);let p=S(l.mode,`${c}/mode`,16);["reserve","commit","release"].includes(p)||m("NATIVE_DECIMAL_RESERVATION_MODE_INVALID",`${c}/mode`);let d=J(l.resourceCode,`${c}/resourceCode`),f=n.get(d);f||m("NATIVE_DECIMAL_RESERVATION_RESOURCE_MISSING",`${c}/resourceCode`);let E=Object.fromEntries(["amountFieldCode","currencyFieldCode","relationFieldCode","parentFieldCode","rootFieldCode","statusFieldCode"].map(y=>[y,K(l[y],`${c}/${y}`)])),A=y=>f.get(E[y]),b=y=>new Set((A(y)?.options||[]).map(O=>String(O.value))),I=F(l.parentRelationValue,`${c}/parentRelationValue`),_=F(l.childRelationValue,`${c}/childRelationValue`),u=v(l.eligibleParentStatuses,`${c}/eligibleParentStatuses`,16),N=v(l.eligibleChildStatuses,`${c}/eligibleChildStatuses`,16);(A("amountFieldCode")?.type!=="number.decimal"||A("amountFieldCode")?.exactDecimal!==!0||A("amountFieldCode")?.precision!==18||A("amountFieldCode")?.scale!==2||A("currencyFieldCode")?.type!=="option.single"||A("relationFieldCode")?.type!=="option.single"||A("parentFieldCode")?.type!=="resource-ref.single"||A("parentFieldCode")?.source?.resourceCode!==d||A("rootFieldCode")?.type!=="uuid"||A("statusFieldCode")?.type!=="option.single"||I===_||!b("relationFieldCode").has(I)||!b("relationFieldCode").has(_)||!u.length||!N.length||u.some(y=>!b("statusFieldCode").has(y))||N.some(y=>!b("statusFieldCode").has(y)))&&m("NATIVE_DECIMAL_RESERVATION_FIELD_INVALID",c),r.decimalReservation={mode:p,resourceCode:d,...E,parentRelationValue:I,childRelationValue:_,eligibleParentStatuses:U(u),eligibleChildStatuses:U(N)}}return r}function ja(e,t,o,n,i){if(e===void 0)return;let s=`${t}/ai`,a=T(e,s);ra.test(o)||m("NATIVE_OPERATION_AI_CODE_INVALID",`${t}/code`),R(a,["name","description","risk","resources","sideEffects","concurrency","timeoutMs"],s,!0),S(a.name,`${s}/name`,Eo),S(a.description,`${s}/description`,Eo);let r=S(a.risk,`${s}/risk`,16);["read","write","destructive","external"].includes(r)||m("NATIVE_OPERATION_AI_RISK_INVALID",`${s}/risk`),r==="read"!=(n==="GET")&&m("NATIVE_OPERATION_AI_METHOD_RISK_MISMATCH",`${s}/risk`),n==="DELETE"&&!["destructive","external"].includes(r)&&m("NATIVE_OPERATION_AI_METHOD_RISK_MISMATCH",`${s}/risk`);let c=v(a.resources,`${s}/resources`,16);c.length===0&&m("NATIVE_OPERATION_AI_RESOURCE_REQUIRED",`${s}/resources`),c.forEach((p,d)=>{let f=J(p,`${s}/resources/${d}`);i.has(f)||m("NATIVE_OPERATION_AI_RESOURCE_MISSING",`${s}/resources/${d}`)});let l=v(a.sideEffects,`${s}/sideEffects`,20);(r==="read"&&l.length!==0||r!=="read"&&l.length===0)&&m("NATIVE_OPERATION_AI_SIDE_EFFECT_INVALID",`${s}/sideEffects`),a.concurrency!==void 0&&!["none","revision"].includes(S(a.concurrency,`${s}/concurrency`,16))&&m("NATIVE_OPERATION_AI_CONCURRENCY_INVALID",`${s}/concurrency`),a.timeoutMs!==void 0&&te(a.timeoutMs,`${s}/timeoutMs`,100,3e4)}function fn(e){return(e.replace(/\/{2,}/g,"/").replace(/\/$/,"")||"/").split("/").map(o=>o.startsWith(":")?":":o.includes("*")?"*":o).join("/")}function Wa(e,t){let o=T(e,t),n=S(o.type,`${t}/type`,32),i=["code","type","label","presentation","required"],s=n==="sso"?[...i,"provider"]:n==="dingtalk"?[...i,"flow"]:i;R(o,s,t);let a=F(o.code,`${t}/code`),r=S(o.label,`${t}/label`,255),c=S(o.presentation,`${t}/presentation`,16);["primary","secondary"].includes(c)||m("NATIVE_APPLICATION_AUTH_METHOD_PRESENTATION_INVALID",`${t}/presentation`);let l=st(o.required,`${t}/required`);return["sso","password","dingtalk"].includes(n)||m("NATIVE_APPLICATION_AUTH_METHOD_TYPE_INVALID",`${t}/type`),n==="sso"&&o.provider!=="tenant-default"&&m("NATIVE_APPLICATION_AUTH_SSO_PROVIDER_INVALID",`${t}/provider`),n==="dingtalk"&&!["auto","jsapi","oauth"].includes(S(o.flow,`${t}/flow`,16))&&m("NATIVE_APPLICATION_AUTH_DINGTALK_FLOW_INVALID",`${t}/flow`),{code:a,type:n,label:r,presentation:c,required:l,...n==="sso"?{provider:"tenant-default"}:{},...n==="dingtalk"?{flow:o.flow}:{}}}function Di(e,t,o){let n=T(e,o);R(n,["routeCode","path","defaultRouteCode"],o);let i=F(n.routeCode,`${o}/routeCode`),s=Ae(n.path,`${o}/path`),a=t==="desktop"?"/login":"/m/login";return(s!==a||/[:*?#\\]/.test(s))&&m("NATIVE_APPLICATION_AUTH_SURFACE_PATH_INVALID",`${o}/path`,{device:t,expectedPath:a}),{routeCode:i,path:s,defaultRouteCode:F(n.defaultRouteCode,`${o}/defaultRouteCode`)}}function Hi(e,t,o,n){if(e===null)return;let i=T(e,n);R(i,["accountMode","registration","methods","surfaces"],n),j(i.accountMode,"existing-platform-users-only",`${n}/accountMode`);let s=T(i.registration,`${n}/registration`);R(s,["mode"],`${n}/registration`),j(s.mode,"reject",`${n}/registration/mode`);let a=w(i.methods,`${n}/methods`,8);a.length===0&&m("NATIVE_APPLICATION_AUTH_METHOD_REQUIRED",`${n}/methods`);let r=a.map((I,_)=>Wa(I,`${n}/methods/${_}`)),c=new Set,l=new Set;for(let[I,_]of r.entries())c.has(_.code)&&m("NATIVE_APPLICATION_AUTH_METHOD_CODE_DUPLICATE",`${n}/methods/${I}/code`),l.has(_.type)&&m("NATIVE_APPLICATION_AUTH_METHOD_TYPE_DUPLICATE",`${n}/methods/${I}/type`),c.add(_.code),l.add(_.type);r.filter(I=>I.presentation==="primary").length!==1&&m("NATIVE_APPLICATION_AUTH_PRIMARY_METHOD_INVALID",`${n}/methods`);let p=T(i.surfaces,`${n}/surfaces`);R(p,["desktop","mobile"],`${n}/surfaces`);let d=Di(p.desktop,"desktop",`${n}/surfaces/desktop`),f=Di(p.mobile,"mobile",`${n}/surfaces/mobile`);d.routeCode===f.routeCode&&m("NATIVE_APPLICATION_AUTH_SURFACE_CODE_DUPLICATE",`${n}/surfaces/mobile/routeCode`);let g=w(t,"/config/frontend/routes",500),E=new Map;for(let[I,_]of g.entries()){let u=T(_,`/config/frontend/routes/${I}`);E.set(String(u.code||""),u)}let A=new Set((Array.isArray(o.data?.resources)?o.data.resources:[]).map(I=>String(I.code||"")).filter(I=>/^[a-z][a-z0-9-]{0,62}$/.test(I)));for(let[I,_]of[["desktop",d],["mobile",f]]){E.has(_.routeCode)&&m("NATIVE_APPLICATION_AUTH_SURFACE_CODE_CONFLICT",`${n}/surfaces/${I}/routeCode`);let u=/^user\.([a-z][a-z0-9-]{0,62})\.(records|submit)$/.exec(String(_.defaultRouteCode||"")),N=E.get(_.defaultRouteCode),y=String(N?.path||"");if(u&&A.has(u[1])){let h=u[2]==="records"?`/my/${u[1]}`:`/my/${u[1]}/submit`;N={surface:"user",path:I==="mobile"?`/m${h}`:h},y=String(N.path)}let O=I==="desktop"?y==="/m"||y.startsWith("/m/"):!(y==="/m"||y.startsWith("/m/"));(!N||N.surface!=="user"||/[:*]/.test(y)||O)&&m("NATIVE_APPLICATION_AUTH_DEFAULT_ROUTE_INVALID",`${n}/surfaces/${I}/defaultRouteCode`)}let b=Xi(o).filter(I=>!I.owner.startsWith("authentication:"));for(let[I,_]of[["desktop",d],["mobile",f]]){let u=b.find(N=>fn(N.path)===fn(_.path));u&&m("NATIVE_APPLICATION_AUTH_SURFACE_PATH_CONFLICT",`${n}/surfaces/${I}/path`,{owner:u.owner})}}function Ma(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`),s={...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"}}};Hi(s,o.frontend.routes,{...o,frontend:{...o.frontend,authentication:s}},t)}function Ua(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 Ba=new Set(["draft.read","draft.update","validate","create","own.list","own.read","public.list","public.read"]);function Ka(e,t,o){let n=T(e,o);R(n,["policies"],o);let i=w(n.policies,`${o}/policies`,16);i.length<1&&m("NATIVE_PUBLIC_POLICY_REQUIRED",o);let s=new Map(t.frontend.routes.map(l=>[l.code,l])),a=new Map(t.data.resources.map(l=>[l.code,l])),r=new Set,c=new Set(i.map(l=>String(l?.code||"")));i.forEach((l,p)=>{let d=`${o}/policies/${p}`,f=T(l,d);R(f,["code","routeCode","mode","resourceCode","operations","fields"],d,["requiredFields","ownRecordFields","publicRecordFields","publicFilters","serverGeneratedFields","schedule","publicSubtableFields","draft","validations"]);let g=F(f.code,`${d}/code`);r.has(g)&&m("NATIVE_PUBLIC_POLICY_DUPLICATE",`${d}/code`);let E=F(f.routeCode,`${d}/routeCode`),A=s.get(E);(!A||A.surface!=="user"||A.capability!==void 0||A.access!==void 0||/[:*]/.test(String(A.path)))&&m("NATIVE_PUBLIC_ROUTE_INVALID",`${d}/routeCode`),j(f.mode,"anonymous",`${d}/mode`);let b=J(f.resourceCode,`${d}/resourceCode`),I=a.get(b);I||m("NATIVE_PUBLIC_RESOURCE_MISSING",`${d}/resourceCode`);let _=new Map(I.schema.fields.map($=>[String($.code),String($.type)])),u=v(f.operations,`${d}/operations`,8);(u.length<1||u.some($=>!Ba.has($)))&&m("NATIVE_PUBLIC_OPERATION_INVALID",`${d}/operations`),u.includes("draft.read")!==u.includes("draft.update")&&m("NATIVE_PUBLIC_DRAFT_OPERATION_INCOMPLETE",`${d}/operations`);let N=v(f.fields,`${d}/fields`,64);(N.length<1||N.some($=>!_.has($)))&&m("NATIVE_PUBLIC_FIELD_INVALID",`${d}/fields`);for(let $ of["requiredFields","ownRecordFields","publicRecordFields"]){if(!Object.prototype.hasOwnProperty.call(f,$))continue;v(f[$],`${d}/${$}`,64).some(L=>!N.includes(L))&&m("NATIVE_PUBLIC_FIELD_SCOPE_INVALID",`${d}/${$}`)}let y=Object.prototype.hasOwnProperty.call(f,"serverGeneratedFields")?w(f.serverGeneratedFields,`${d}/serverGeneratedFields`,16):[],O=new Set;y.forEach(($,W)=>{let L=`${d}/serverGeneratedFields/${W}`,G=T($,L);R(G,["field","kind"],L);let q=K(G.field,`${L}/field`);(O.has(q)||!_.has(q)||N.includes(q)||_.get(q)!=="text.short"&&_.get(q)!=="text.long")&&m("NATIVE_PUBLIC_SERVER_GENERATED_FIELD_INVALID",`${L}/field`),j(G.kind,"random-token",`${L}/kind`),O.add(q)});let h=Object.prototype.hasOwnProperty.call(f,"schedule")?T(f.schedule,`${d}/schedule`):null;if(h){let $=["campusPolicyCode","rulePolicyCode","campusField","ruleCampusField","ruleWeekdaysField","ruleOpenAtField","ruleCloseAtField","ruleSlotMinutesField","ruleAdvanceHoursField","ruleAdvanceDaysField","campusEnabledField","ruleEnabledField","dateField","timeField"];R(h,$,`${d}/schedule`);for(let W of["campusPolicyCode","rulePolicyCode"])F(h[W],`${d}/schedule/${W}`);for(let W of $.filter(L=>!["campusPolicyCode","rulePolicyCode"].includes(L)))K(h[W],`${d}/schedule/${W}`);for(let W of[h.campusField,h.dateField,h.timeField])N.includes(String(W))||m("NATIVE_PUBLIC_SCHEDULE_FIELD_INVALID",`${d}/schedule`);(!c.has(String(h.campusPolicyCode))||!c.has(String(h.rulePolicyCode)))&&m("NATIVE_PUBLIC_SCHEDULE_POLICY_INVALID",`${d}/schedule`)}let C=Object.prototype.hasOwnProperty.call(f,"publicFilters")?w(f.publicFilters,`${d}/publicFilters`,16):[],k=new Set;C.forEach(($,W)=>{let L=`${d}/publicFilters/${W}`,G=T($,L);R(G,["field","operator","value"],L);let q=K(G.field,`${L}/field`);k.has(q)&&m("NATIVE_PUBLIC_FILTER_DUPLICATE",`${L}/field`),N.includes(q)||m("NATIVE_PUBLIC_FILTER_FIELD_INVALID",`${L}/field`),j(G.operator,"eq",`${L}/operator`),["boolean","text.short","text.long","number.integer","number.decimal","date","time"].includes(_.get(q)||"")||m("NATIVE_PUBLIC_FILTER_FIELD_INVALID",`${L}/field`),G.value!==null&&typeof G.value!="string"&&typeof G.value!="number"&&typeof G.value!="boolean"&&m("NATIVE_PUBLIC_FILTER_VALUE_INVALID",`${L}/value`),k.add(q)});let V=Object.prototype.hasOwnProperty.call(f,"publicSubtableFields")?T(f.publicSubtableFields,`${d}/publicSubtableFields`):null;if(V){Object.keys(V).length>64&&m("NATIVE_PUBLIC_SUBTABLE_FIELDS_INVALID",`${d}/publicSubtableFields`);for(let[$,W]of Object.entries(V)){let L=I.schema.fields.find(Q=>String(Q.code)===$),G=String(L?.subtable?.resourceCode||""),q=a.get(G),Oe=new Map((q?.schema?.fields||[]).map(Q=>[String(Q.code),String(Q.type)])),z=v(W,`${d}/publicSubtableFields/${$}`,64);(!N.includes($)||_.get($)!=="subtable"||!q||z.length<1||z.some(Q=>!Oe.has(Q))||z.some(Q=>Oe.get(Q)==="subtable")||z.some(Q=>Oe.get(Q)==="signature"))&&m("NATIVE_PUBLIC_SUBTABLE_FIELDS_INVALID",`${d}/publicSubtableFields/${$}`)}}if(u.some($=>$.startsWith("public."))){Object.prototype.hasOwnProperty.call(f,"publicRecordFields")||m("NATIVE_PUBLIC_RECORD_FIELDS_REQUIRED",`${d}/publicRecordFields`);let $=v(f.publicRecordFields,`${d}/publicRecordFields`,64);($.length<1||$.some(W=>!N.includes(W))||$.some(W=>_.get(W)==="signature"||_.get(W)==="subtable"&&!V?.[W]))&&m("NATIVE_PUBLIC_RECORD_FIELDS_INVALID",`${d}/publicRecordFields`)}let M=Object.prototype.hasOwnProperty.call(f,"requiredFields")?v(f.requiredFields,`${d}/requiredFields`,64):[],P=I.surface||{},re=P.fields||{},Ee=String(P.mutationOwner||"native")==="native"&&P.generated?.create!==!1,H=I.schema.fields.filter($=>ct($,re[$.code])).map($=>String($.code));if(u.includes("create")&&!Ee&&m("NATIVE_PUBLIC_CREATE_FIELDS_INCOMPLETE",`${d}/fields`),u.includes("create")&&!Object.prototype.hasOwnProperty.call(f,"draft")&&m("NATIVE_PUBLIC_DRAFT_REQUIRED",`${d}/draft`),u.includes("create"))for(let $ of H){let W=N.includes($)?M.includes($)?null:"requiredFields":"fields";W&&m("NATIVE_PUBLIC_CREATE_FIELDS_INCOMPLETE",`${d}/${W}`,{resourceCode:J,fieldCode:$})}if(Object.prototype.hasOwnProperty.call(f,"draft")){let $=T(f.draft,`${d}/draft`);R($,["enabled","inactivityTtlSeconds","maxBytes"],`${d}/draft`),j($.enabled,!0,`${d}/draft/enabled`),te($.inactivityTtlSeconds,`${d}/draft/inactivityTtlSeconds`,3600,7776e3),te($.maxBytes,`${d}/draft/maxBytes`,4096,262144)}else u.includes("draft.read")&&m("NATIVE_PUBLIC_DRAFT_REQUIRED",`${d}/draft`);let Te=Object.prototype.hasOwnProperty.call(f,"validations")?w(f.validations,`${d}/validations`,16):[],ce=new Set;Te.forEach(($,W)=>{let L=`${d}/validations/${W}`,G=T($,L);R(G,["code","kind","fields","result"],L);let q=F(G.code,`${L}/code`);ce.has(q)&&m("NATIVE_PUBLIC_VALIDATION_DUPLICATE",`${L}/code`),j(G.kind,"duplicate",`${L}/kind`),j(G.result,"availability",`${L}/result`);let Oe=v(G.fields,`${L}/fields`,8);(Oe.length<1||Oe.some(z=>!N.includes(z))||Oe.some(z=>["file","subtable"].includes(_.get(z)||"")))&&m("NATIVE_PUBLIC_VALIDATION_FIELD_INVALID",`${L}/fields`),ce.add(q)}),r.add(g)})}function Ga(e,t){let o=T(e,t);R(o,["policies"],t),w(o.policies,`${t}/policies`,16).length<1&&m("NATIVE_PUBLIC_POLICY_REQUIRED",t)}function qa(e){return{policies:Z(e.frontend.publicAccess.policies.map(t=>({code:t.code,routeCode:t.routeCode,mode:t.mode,resourceCode:t.resourceCode,operations:U(t.operations),fields:U(t.fields),...t.requiredFields?{requiredFields:U(t.requiredFields)}:{},...t.ownRecordFields?{ownRecordFields:U(t.ownRecordFields)}:{},...t.publicRecordFields?{publicRecordFields:U(t.publicRecordFields)}:{},...t.publicFilters?{publicFilters:t.publicFilters.map(o=>({field:o.field,operator:o.operator,value:o.value})).sort((o,n)=>ue(o.field,n.field))}:{},...t.publicSubtableFields?{publicSubtableFields:Object.fromEntries(Object.entries(t.publicSubtableFields).sort(([o],[n])=>o.localeCompare(n)).map(([o,n])=>[o,U(Array.isArray(n)?n.map(String):[])]))}:{},...t.serverGeneratedFields?{serverGeneratedFields:t.serverGeneratedFields.map(o=>({field:o.field,kind:o.kind})).sort((o,n)=>ue(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:Z(t.validations.map(o=>({code:o.code,kind:o.kind,fields:U(o.fields),result:o.result})),o=>o.code)}:{}})),t=>t.code)}}function Xi(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=Qi(o),i=`/admin/resources/${o.code}`,s=[["list",i],["detail",`${i}/:id`],["create",`${i}/new`],["update",`${i}/:id/edit`]];for(let[a,r]of s)n[a]&&t.push({owner:`resource:${o.code}:${a}`,path:r},{owner:`resource:${o.code}:${a}: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 gn(e){let t=new Map(Xi(e).map(o=>[fn(o.path),o]));return Z(e.frontend.routes.map((o,n)=>{let i=`/config/frontend/routes/${n}`,s=T(o,i);R(s,["code","path","label","surface","parentCode","capability","access","pinned","tabPersistence","keepAlive"],i,!0),["admin","user"].includes(s.surface)||m("NATIVE_ROUTE_SURFACE_INVALID",`${i}/surface`);let a=Ae(s.path,`${i}/path`);s.surface==="admin"&&a!=="/admin"&&!a.startsWith("/admin/")&&m("NATIVE_ADMIN_ROUTE_PATH_INVALID",`${i}/path`),s.surface==="user"&&(a==="/admin"||a.startsWith("/admin/"))&&m("NATIVE_USER_ROUTE_PATH_RESERVED",`${i}/path`);let r=fn(a),c=t.get(r);c&&m("NATIVE_ROUTE_PATH_CONFLICT",`${i}/path`,{path:a,owner:c.owner}),t.set(r,{owner:`frontend:${String(s.code||n)}`,path:a});let l=/[:*]/.test(a),p=To(s,i,e.appCode),d=s.pinned===void 0?void 0:st(s.pinned,`${i}/pinned`),f=s.tabPersistence===void 0?l?"none":"session":S(s.tabPersistence,`${i}/tabPersistence`,16),g=s.keepAlive===void 0?"none":S(s.keepAlive,`${i}/keepAlive`,16);return["session","none"].includes(f)||m("NATIVE_ROUTE_TAB_PERSISTENCE_INVALID",`${i}/tabPersistence`),["none","memory"].includes(g)||m("NATIVE_ROUTE_KEEP_ALIVE_INVALID",`${i}/keepAlive`),l&&d===!0&&m("NATIVE_DYNAMIC_ROUTE_PINNED_FORBIDDEN",`${i}/pinned`),l&&f==="session"&&m("NATIVE_DYNAMIC_ROUTE_TAB_PERSISTENCE_FORBIDDEN",`${i}/tabPersistence`),l&&g==="memory"&&m("NATIVE_DYNAMIC_ROUTE_KEEP_ALIVE_FORBIDDEN",`${i}/keepAlive`),{code:F(s.code,`${i}/code`),path:a,label:S(s.label,`${i}/label`,255),surface:s.surface,...s.parentCode===void 0?{}:{parentCode:F(s.parentCode,`${i}/parentCode`)},...p,...d===void 0?{}:{pinned:d},tabPersistence:f,keepAlive:g}}),o=>o.code)}function Qi(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 Zi(e){let t=[];for(let o of Z(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:Mt(n.surface,i.code)}}))])){let{resource:n,viewCode:i}=o,s=`/admin/resources/${n.code}${i?`/views/${i}`:""}`,a=Qi(n),r=[{operation:"list",kind:"resource-list",path:`${s}`,label:n.name,capability:n.capabilities.read,navigationEligible:!0},{operation:"detail",kind:"resource-detail",path:`${s}/:id`,label:`${n.name}\u8BE6\u60C5`,capability:n.capabilities.read,navigationEligible:!1},{operation:"create",kind:"resource-create",path:`${s}/new`,label:`\u65B0\u589E${n.name}`,capability:n.capabilities.create,navigationEligible:!1},{operation:"update",kind:"resource-update",path:`${s}/:id/edit`,label:`\u7F16\u8F91${n.name}`,capability:n.capabilities.update,navigationEligible:!1}];for(let c of r)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 gn(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)=>ue(o.code,n.code))}function es(e){return e.kind==="resource"?`resource:${e.resourceCode}${e.viewCode?`:view:${e.viewCode}`:""}:list`:`operation:${e.routeCode}`}function Ja(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:es(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||ue(n.pageCode,i.pageCode))})).sort((t,o)=>t.order-o.order||ue(t.code,o.code))}function za(e,t){let o=w(e,t,Y.adminNavigationGroups),n=0;o.forEach((i,s)=>{let a=`${t}/${s}`,r=T(i,a);R(r,["code","label","icon","order","items"],a,!0),F(r.code,`${a}/code`),S(r.label,`${a}/label`,255),pn(r.icon,`${a}/icon`),vi(r.order,`${a}/order`);let c=w(r.items,`${a}/items`,500);c.length===0&&m("NATIVE_ADMIN_GROUP_ORPHANED",`${a}/items`),n+=c.length,n>Y.adminNavigationItems&&m("NATIVE_ARRAY_LIMIT_EXCEEDED",t),c.forEach((l,p)=>{let d=`${a}/items/${p}`,f=T(l,d);R(f,["page","label","icon","order"],d,!0),Ya(f.page,`${d}/page`),f.label!==void 0&&S(f.label,`${d}/label`,255),pn(f.icon,`${d}/icon`),vi(f.order,`${d}/order`)})})}function Ya(e,t){let o=T(e,t),n=S(o.kind,`${t}/kind`,64);if(n==="resource"){R(o,["kind","resourceCode"],t,["viewCode"]),o.viewCode!==void 0&&F(o.viewCode,`${t}/viewCode`),J(o.resourceCode,`${t}/resourceCode`);return}if(n==="operation"){R(o,["kind","routeCode"],t),F(o.routeCode,`${t}/routeCode`);return}m("NATIVE_ADMIN_PAGE_REFERENCE_KIND_INVALID",`${t}/kind`)}function Ha(e){let t=new Map(Zi(e).map(i=>[String(i.code),i])),o=new Set,n=new Set;e.frontend.admin.navigation.forEach((i,s)=>{let a=`/config/frontend/admin/navigation/${s}`;o.has(i.code)&&m("NATIVE_ADMIN_GROUP_DUPLICATE",`${a}/code`),o.add(i.code),i.label===i.code&&m("NATIVE_ADMIN_USER_LABEL_REQUIRED",`${a}/label`),i.items.forEach((r,c)=>{let l=`${a}/items/${c}`,p=es(r.page),d=t.get(p);(!d||d.navigationEligible!==!0)&&m("NATIVE_ADMIN_PAGE_NOT_FOUND",`${l}/page`),n.has(p)&&m("NATIVE_ADMIN_PAGE_DUPLICATE",`${l}/page`),n.add(p);let f=r.page.resourceCode||r.page.routeCode||r.page.workflowCode||p,g=r.label||d.label;(!g||g===f||g===p)&&m("NATIVE_ADMIN_USER_LABEL_REQUIRED",`${l}/label`)})})}function Xa(e,t){let o=w(e,t,Y.adminPages),n=new Set;o.forEach((i,s)=>{let a=`${t}/${s}`,r=T(i,a);R(r,["code","kind","path","label","navigationEligible","capability","access","resourceCode","viewCode","routeCode"],a,!0);let c=S(r.code,`${a}/code`,255);n.has(c)&&m("NATIVE_ADMIN_PAGE_DUPLICATE",`${a}/code`),n.add(c);let l=S(r.kind,`${a}/kind`,64);if(["resource-list","resource-detail","resource-create","resource-update","operation"].includes(l)||m("NATIVE_ADMIN_PAGE_KIND_INVALID",`${a}/kind`),Ae(r.path,`${a}/path`),S(r.label,`${a}/label`,255),st(r.navigationEligible,`${a}/navigationEligible`),r.capability!==void 0&&r.access!==void 0&&m("NATIVE_ROUTE_ACCESS_CONFLICT",`${a}/access`),r.capability!==void 0&&S(r.capability,`${a}/capability`,255),r.access!==void 0){let p=T(r.access,`${a}/access`);R(p,["allOf","anyOf"],`${a}/access`,!0);for(let d of["allOf","anyOf"])p[d]!==void 0&&v(p[d],`${a}/access/${d}`,50)}for(let p of["resourceCode","viewCode","routeCode"])r[p]!==void 0&&F(r[p],`${a}/${p}`)})}function Qa(e,t){let o=w(e,t,Y.adminNavigationGroups),n=0;o.forEach((i,s)=>{let a=`${t}/${s}`,r=T(i,a);R(r,["code","label","icon","order","items"],a,!0),F(r.code,`${a}/code`),S(r.label,`${a}/label`,255),pn(r.icon,`${a}/icon`),te(r.order,`${a}/order`,-1e4,1e4);let c=w(r.items,`${a}/items`,500);c.length===0&&m("NATIVE_ADMIN_GROUP_ORPHANED",`${a}/items`),n+=c.length,n>Y.adminNavigationItems&&m("NATIVE_ARRAY_LIMIT_EXCEEDED",t),c.forEach((l,p)=>{let d=`${a}/items/${p}`,f=T(l,d);R(f,["pageCode","label","icon","order"],d,!0),S(f.pageCode,`${d}/pageCode`,255),f.label!==void 0&&S(f.label,`${d}/label`,255),pn(f.icon,`${d}/icon`),te(f.order,`${d}/order`,-1e4,1e4)})})}var Za=new Set(["application-todo-center","workflow-work-center","workflow-launch","workflow-task","workflow-instance","resource-records","resource-submit"]);function ec(e,t,o){let n=T(e,t);R(n,["schemaVersion","appCode","devicePolicy","rootEntry","authentication","routes","digest"],t),j(n.schemaVersion,Gi,`${t}/schemaVersion`),j(n.appCode,o,`${t}/appCode`),No(n.devicePolicy,`${t}/devicePolicy`),tc(n.rootEntry,`${t}/rootEntry`),nc(n.authentication,`${t}/authentication`),bo(n.digest,`${t}/digest`);let i=w(n.routes,`${t}/routes`,Y.routes),s=new Set;i.forEach((a,r)=>{let c=`${t}/routes/${r}`,l=T(a,c),p=l.kind==="resource-records"||l.kind==="resource-submit";R(l,["code","kind","desktop","mobile"],c,["workflowCode",...p?["resourceCode"]:[]]);let d=S(l.code,`${c}/code`,255);s.has(d)&&m("NATIVE_ROUTE_MANIFEST_DUPLICATE",`${c}/code`),s.add(d);let f=S(l.kind,`${c}/kind`,64);if(Za.has(f)||m("NATIVE_ROUTE_MANIFEST_KIND_INVALID",`${c}/kind`),l.workflowCode!==void 0&&F(l.workflowCode,`${c}/workflowCode`),p){let A=J(l.resourceCode,`${c}/resourceCode`);j(d,`user.${A}.${l.kind==="resource-records"?"records":"submit"}`,`${c}/code`)}else l.resourceCode!==void 0&&m("NATIVE_PROPERTY_UNKNOWN",`${c}/resourceCode`);let g=ki(l.desktop,`${c}/desktop`,o),E=ki(l.mobile,`${c}/mobile`,o);g.surface!=="user"&&m("NATIVE_ROUTE_MANIFEST_DESKTOP_SURFACE_INVALID",`${c}/desktop/surface`),E.surface!=="user"&&m("NATIVE_ROUTE_MANIFEST_MOBILE_SURFACE_INVALID",`${c}/mobile/surface`),g.routeCode===E.routeCode&&m("NATIVE_ROUTE_MANIFEST_PAIR_DUPLICATE",c)}),j(n.digest,X({schemaVersion:n.schemaVersion,appCode:n.appCode,devicePolicy:n.devicePolicy,rootEntry:n.rootEntry,authentication:n.authentication,routes:n.routes}),`${t}/digest`)}function No(e,t){let o=T(e,t);R(o,["kind","mobileMaxWidthPx","desktopMinWidthPx"],t),j(o.kind,"viewport-family",`${t}/kind`);let n=te(o.mobileMaxWidthPx,`${t}/mobileMaxWidthPx`,320,1600),i=te(o.desktopMinWidthPx,`${t}/desktopMinWidthPx`,320,1600);return i!==n+1&&m("NATIVE_FRONTEND_DEVICE_POLICY_INVALID",t),{kind:"viewport-family",mobileMaxWidthPx:n,desktopMinWidthPx:i}}function tc(e,t){let o=T(e,t);R(o,["code","desktop","mobile"],t);let n=F(o.code,`${t}/code`),i=Io(o.desktop,`${t}/desktop`),s=Io(o.mobile,`${t}/mobile`);return(i===s||s==="/"||!s.startsWith("/m/"))&&m("NATIVE_ROUTE_MANIFEST_ROOT_ENTRY_INVALID",t),i.startsWith("/m/")&&m("NATIVE_ROUTE_MANIFEST_ROOT_ENTRY_INVALID",`${t}/desktop`),{code:n,desktop:i,mobile:s}}function nc(e,t){let o=T(e,t);R(o,["desktop","mobile"],t);let n=$i(o.desktop,`${t}/desktop`,!1),i=$i(o.mobile,`${t}/mobile`,!0);return(n.routeCode===i.routeCode||n.path===i.path)&&m("NATIVE_ROUTE_MANIFEST_AUTHENTICATION_DUPLICATE",t),{desktop:n,mobile:i}}function $i(e,t,o){let n=T(e,t);R(n,["routeCode","path"],t);let i=F(n.routeCode,`${t}/routeCode`),s=Io(n.path,`${t}/path`);return(o?!s.startsWith("/m/"):s.startsWith("/m/"))&&m("NATIVE_ROUTE_MANIFEST_AUTHENTICATION_PATH_INVALID",`${t}/path`),{routeCode:i,path:s}}function Io(e,t){let o=Ae(e,t);return/[:*?#\\\\]/.test(o)&&m("NATIVE_ROUTE_MANIFEST_STATIC_PATH_INVALID",t),o}function ki(e,t,o){let n=T(e,t);R(n,["routeCode","path","surface","pathParams","requiresAuthentication"],t,["capability","access"]),F(n.routeCode,`${t}/routeCode`);let i=Ae(n.path,`${t}/path`),s=S(n.surface,`${t}/surface`,16);["admin","user"].includes(s)||m("NATIVE_ROUTE_SURFACE_INVALID",`${t}/surface`);let a=v(n.pathParams,`${t}/pathParams`,8);return a.forEach((r,c)=>{(!/^[A-Za-z][A-Za-z0-9_]*$/.test(r)||r.length>64)&&m("NATIVE_ROUTE_PATH_PARAM_INVALID",`${t}/pathParams/${c}`)}),ee(a)!==ee(ts(i))&&m("NATIVE_ROUTE_PATH_PARAMS_MISMATCH",`${t}/pathParams`),To(n,t,o),n.requiresAuthentication!==!0&&m("NATIVE_ROUTE_AUTHENTICATION_REQUIRED",`${t}/requiresAuthentication`),n}function ts(e){return U([...e.matchAll(/:([A-Za-z][A-Za-z0-9_]*)/g)].map(t=>t[1]))}function Vi(e,t,o,n){return{routeCode:e,path:t,surface:o,pathParams:ts(t),...n?.capability?{capability:n.capability}:{},...n?.access?{access:n.access}:{},requiresAuthentication:!0}}function Fi(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 oc(e){let t=e.appCode,o=[],n=(g,E,A,b,I,_,u)=>{o.push({code:g,kind:E,...I?{workflowCode:I}:{},...u?{resourceCode:u}:{},desktop:Vi(Fi(E,"desktop",I,u),A,"user",_),mobile:Vi(Fi(E,"mobile",I,u),b,"user",_)})};e.frontend.user.applicationTodoCenter===!0&&n("application:todo-center","application-todo-center","/todos","/m/todos");let i=ns(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 g of i){if(!["standalone","hidden-handoff"].includes(g.launch.mode))continue;let E=U([g.launch.submission?.create?.requiredCapability,g.launch.submission?.existing?.requiredCapability].filter(A=>!!A));n(`workflow:${g.code}:launch`,"workflow-launch","/workflows/:workflowCode/start","/m/workflows/:workflowCode/start",g.code,E.length===1?{capability:E[0]}:E.length>1?{access:{anyOf:E}}:void 0)}let s=o.sort((g,E)=>ue(String(g.code),String(E.code))),a=gn(e),r=g=>{let E=g==="mobile"?"/m/":"/",A=a.filter(I=>I.surface==="user"&&!/[:*?#\\\\]/.test(I.path)&&I.path===E).sort((I,_)=>ue(I.code,_.code))[0];if(A)return{code:A.code,path:A.path};let b=a.filter(I=>I.surface==="user"&&!/[:*?#\\\\]/.test(I.path)&&(g==="mobile"?I.path.startsWith("/m/"):!I.path.startsWith("/m/"))).sort((I,_)=>ue(I.code,_.code))[0];return b?{code:b.code,path:b.path}:{code:g==="mobile"?"application-root-mobile":"application-root",path:E}},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"}},l=No(e.frontend.devicePolicy,"/config/frontend/devicePolicy"),p=r("desktop"),d=r("mobile"),f={schemaVersion:Gi,appCode:t,devicePolicy:l,rootEntry:{code:p.code,desktop:p.path,mobile:d.path},authentication:c,routes:s};return{...f,digest:X(f)}}function pn(e,t){if(e===void 0)return;let o=S(e,t,32);Aa.has(o)||m("NATIVE_ADMIN_ICON_INVALID",t)}function vi(e,t){e!==void 0&&te(e,t,-1e4,1e4)}function To(e,t,o){return e.capability!==void 0&&e.access!==void 0&&m("NATIVE_ROUTE_ACCESS_CONFLICT",`${t}/access`),e.capability!==void 0?{capability:$e(e.capability,`${t}/capability`,o)}:e.access===void 0?{}:{access:An(e.access,`${t}/access`,o)}}function An(e,t,o){let n=T(e,t);R(n,["allOf","anyOf"],t,!0);let i=n.allOf===void 0?void 0:U(v(n.allOf,`${t}/allOf`,50).map((a,r)=>$e(a,`${t}/allOf/${r}`,o))),s=n.anyOf===void 0?void 0:U(v(n.anyOf,`${t}/anyOf`,50).map((a,r)=>$e(a,`${t}/anyOf/${r}`,o)));return(i?.length||0)+(s?.length||0)===0&&m("NATIVE_ROUTE_ACCESS_EMPTY",t),{...i===void 0?{}:{allOf:i},...s===void 0?{}:{anyOf:s}}}function ns(e){let t=new Map(Yi(e).map(i=>[String(i.code),i])),o=e.workflows.definitions.map((i,s)=>{let a=`/config/workflows/definitions/${s}`,r=T(i,a);R(r,["version","definition","launch"],a,["detailRouteCode"]);let c=T(r.definition,`${a}/definition`),l=r.detailRouteCode===void 0?void 0:is(r.detailRouteCode,`${a}/detailRouteCode`);return{code:F(c.code,`${a}/definition/code`),title:S(c.title,`${a}/definition/title`,255),version:it(r.version,`${a}/version`),launch:ic(e,c,r.launch,`${a}/launch`,t),...l?{detailRouteCode:l}:{},definition:c}});return U(o.map(i=>i.code)).map(i=>{let s=o.filter(l=>l.code===i),a=e.workflows.activations.find(l=>l.workflowCode===i)?.definitionVersion,r=s.find(l=>l.version===a)||[...s].sort((l,p)=>p.version-l.version)[0],c=new Set;for(let l of s){let p=T(l.definition.nodes,"/config/workflows/definitions/nodes");for(let d of Object.values(p)){let f=T(d,"/config/workflows/definitions/nodes/*");if(f.kind==="approval")for(let g of v(f.allowedOperations||[],"/config/workflows/definitions/nodes/*/allowedOperations",20))c.add(g)}}return{code:i,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.${i}.submit`}:{},...r.detailRouteCode?{detailRouteCode:r.detailRouteCode}:{},definitionVersions:Bi(s.map(l=>l.version)),bindingVersions:Bi(e.workflows.bindings.map((l,p)=>{let d=`/config/workflows/bindings/${p}`,f=T(l,d),g=T(f.binding,`${d}/binding`);return{code:F(g.workflowCode,`${d}/binding/workflowCode`),version:it(f.version,`${d}/version`)}}).filter(l=>l.code===i).map(l=>l.version)),providerCodes:U(e.workflows.providers.map((l,p)=>F(T(l,`/config/workflows/providers/${p}`).code,`/config/workflows/providers/${p}/code`))),allowedOperations:[...c].sort(ue),editableParameterCodes:U(e.workflows.editableParameters.map((l,p)=>{let d=`/config/workflows/editableParameters/${p}`,f=T(l,d);return{code:F(f.code,`${d}/code`),workflowCode:F(f.workflowCode,`${d}/workflowCode`)}}).filter(l=>l.workflowCode===i).map(l=>l.code))}})}function os(e,t){let o=T(e,t);R(o,["mode"],t,["submission"]);let n=S(o.mode,`${t}/mode`,32);return["standalone","custom-page","hidden-handoff","work-center-only"].includes(n)||m("NATIVE_WORKFLOW_LAUNCH_MODE_INVALID",`${t}/mode`),{mode:n,...o.submission===void 0?{}:{submission:T(o.submission,`${t}/submission`)}}}function ic(e,t,o,n,i){let s=os(o,n);if(!s.submission)return{mode:s.mode};["standalone","hidden-handoff"].includes(s.mode)||m("NATIVE_WORKFLOW_NAMED_OPERATION_SUBMISSION_INVALID",`${n}/submission`);let a=T(s.submission,`${n}/submission`);R(a,["kind"],`${n}/submission`,["create","existing","context"]),j(a.kind,"named-operation",`${n}/submission/kind`);let r=n.endsWith("/launch")?n.slice(0,-7):n,c=T(t.subject,`${r}/definition/subject`),l=J(c.resourceCode,`${r}/definition/subject/resourceCode`),p=e.data.resources.findIndex(O=>O.code===l),d=e.data.resources[p];(p<0||!d)&&m("NATIVE_WORKFLOW_SUBJECT_RESOURCE_MISSING",`${r}/definition/subject/resourceCode`);let f=new Set(T(d.schema,`/config/data/resources/${p}/schema`).fields.map(O=>String(O.code))),g=new Map(e.backend.operations.map(O=>[String(O.code),O])),E=(O,h)=>{let C=`${n}/submission/${h}`,k=T(O,C);R(k,["operationCode","inputs","output"],C);let V=F(k.operationCode,`${C}/operationCode`),M=g.get(V),P=i.get(V),re=P?.platformAccess?.workflow?.codes;(!M||!P||P.method!=="POST"||!Array.isArray(re)||!re.includes(t.code))&&m("NATIVE_WORKFLOW_NAMED_OPERATION_INVALID",C);let Ee=T(M.requestSchema,`${C}/operation/requestSchema`),H=T(Ee.properties,`${C}/operation/requestSchema/properties`),Te=new Set(Ee.required===void 0?[]:v(Ee.required,`${C}/operation/requestSchema/required`,64)),ce=T(k.inputs,`${C}/inputs`),$=Object.entries(ce);(!$.length||$.length>64)&&m("NATIVE_WORKFLOW_NAMED_OPERATION_INPUT_INVALID",`${C}/inputs`);let W=new Set,L=new Map,G={};for(let[z,Q]of $){(!Si.test(z)||!Object.prototype.hasOwnProperty.call(H,z))&&m("NATIVE_WORKFLOW_NAMED_OPERATION_INPUT_INVALID",`${C}/inputs/${z}`);let Be=`${C}/inputs/${z}`,yn=T(Q,Be),ve=S(yn.source,`${Be}/source`,32);if(["field","idempotency-key","current-user-reference","subject-id","subject-revision","requested-at"].includes(ve)||m("NATIVE_WORKFLOW_NAMED_OPERATION_INPUT_INVALID",Be),R(yn,["source"],Be,ve==="field"?["fieldCode"]:!1),L.set(ve,(L.get(ve)||0)+1),ve==="field"){let St=K(yn.fieldCode,`${Be}/fieldCode`);(W.has(St)||!f.has(St))&&m("NATIVE_WORKFLOW_NAMED_OPERATION_INPUT_INVALID",`${Be}/fieldCode`),W.add(St),G[z]={source:ve,fieldCode:St}}else G[z]={source:ve}}([...Te].some(z=>!(z in ce))||(L.get("idempotency-key")||0)!==1||!$.some(([z,Q])=>T(Q,`${C}/inputs/${z}`).source==="idempotency-key"&&Te.has(z))||h==="create"&&((L.get("subject-id")||0)>0||(L.get("subject-revision")||0)>0)||h==="existing"&&((L.get("subject-id")||0)!==1||(L.get("subject-revision")||0)!==1))&&m("NATIVE_WORKFLOW_NAMED_OPERATION_INPUT_INVALID",`${C}/inputs`);let q=T(k.output,`${C}/output`);R(q,["subjectId"],`${C}/output`,["subjectRevision","processCommand"]);let Oe=T(T(M.responseSchema,`${C}/operation/responseSchema`).properties,`${C}/operation/responseSchema/properties`);for(let z of["subjectId","subjectRevision","processCommand"]){if(q[z]===void 0)continue;let Q=S(q[z],`${C}/output/${z}`,128);(!Si.test(Q)||!Object.prototype.hasOwnProperty.call(Oe,Q))&&m("NATIVE_WORKFLOW_NAMED_OPERATION_OUTPUT_INVALID",`${C}/output/${z}`)}return{operationCode:V,method:"POST",path:P.path,requiredCapability:P.requiredCapability,requestSchemaDigest:P.requestSchemaDigest,responseSchemaDigest:P.responseSchemaDigest,inputs:G,output:{...q},fieldCodes:W}},A=a.create===void 0?void 0:E(a.create,"create"),b=a.existing===void 0?void 0:E(a.existing,"existing");!A&&!b&&m("NATIVE_WORKFLOW_NAMED_OPERATION_SUBMISSION_INVALID",`${n}/submission`);let I=new Set([...A?.fieldCodes||[],...b?.fieldCodes||[]]),_=a.context===void 0?[]:w(a.context,`${n}/submission/context`,16),u=new Set,N=_.map((O,h)=>{let C=`${n}/submission/context/${h}`,k=T(O,C);R(k,["queryParameter","fieldCode"],C);let V=S(k.queryParameter,`${C}/queryParameter`,64),M=K(k.fieldCode,`${C}/fieldCode`);return(!/^[A-Za-z][A-Za-z0-9]{0,63}$/.test(V)||u.has(V)||!I.has(M))&&m("NATIVE_WORKFLOW_LAUNCH_CONTEXT_INVALID",C),u.add(V),{queryParameter:V,fieldCode:M}}),y=O=>{let{fieldCodes:h,...C}=O;return C};return{mode:s.mode,submission:{kind:"named-operation",...A?{create:y(A)}:{},...b?{existing:y(b)}:{},context:N}}}function is(e,t){let o=T(e,t);R(o,["desktop","mobile"],t);let n=F(o.desktop,`${t}/desktop`),i=F(o.mobile,`${t}/mobile`);return n===i&&m("NATIVE_WORKFLOW_DETAIL_ROUTE_DUPLICATE",t),{desktop:n,mobile:i}}function sc(e,t){let o=new Set(t.map(p=>p.code)),n=new Map;e.data.resources.forEach((p,d)=>{let f=`/config/data/resources/${d}`,g=T(p,f);for(let[b,I]of Object.entries(g.fieldPolicies||{})){if(!Ge(b))continue;let _=`${f}/fieldPolicies/${b}/read`,u=T(I,`${f}/fieldPolicies/${b}`);for(let N of v(u.read||[],_,2e3))o.has(N)||m("NATIVE_CAPABILITY_REFERENCE_MISSING",_)}let E=g.surface===void 0?{}:T(g.surface,`${f}/surface`);if(["native","queued-command"].includes(E.mutationOwner||"native"))return;let A=T(g.capabilities,`${f}/capabilities`);for(let b of["create","update","delete"])n.set(String(A[b]),b)});let i=new Set;for(let[p,d]of e.authz.roles.entries()){let f=`/config/authz/roles/${p}`,g=T(d,f);R(g,["code","name","description","capabilities"],f,!0);let E=F(g.code,`${f}/code`);i.has(E)&&m("NATIVE_ROLE_DUPLICATE",`${f}/code`),i.add(E),S(g.name,`${f}/name`,255);let A=v(g.capabilities,`${f}/capabilities`,2e3);for(let[b,I]of A.entries())n.has(I)&&m("NATIVE_DATA_SURFACE_MUTATION_GRANT_FORBIDDEN",`${f}/capabilities/${b}`,{operation:n.get(I)}),o.has(I)||m("NATIVE_CAPABILITY_REFERENCE_MISSING",`${f}/capabilities`)}let s=e.authz.authenticatedUserRoleCode===void 0?"":F(e.authz.authenticatedUserRoleCode,"/config/authz/authenticatedUserRoleCode");s&&!i.has(s)&&m("NATIVE_AUTHENTICATED_USER_ROLE_REFERENCE_MISSING","/config/authz/authenticatedUserRoleCode");let a=new Set,r=0;for(let[p,d]of e.perspectives.entries()){let f=`/config/perspectives/${p}`,g=T(d,f);R(g,["code","name","description","roleCodes","capabilityCodes","default"],f,!0);let E=F(g.code,`${f}/code`);a.has(E)&&m("NATIVE_PERSPECTIVE_DUPLICATE",`${f}/code`),a.add(E),S(g.name,`${f}/name`,255);let A=v(g.roleCodes,`${f}/roleCodes`,20);A.length<1&&m("NATIVE_PERSPECTIVE_ROLE_REQUIRED",`${f}/roleCodes`),A.forEach((_,u)=>{i.has(_)||m("NATIVE_PERSPECTIVE_ROLE_MISSING",`${f}/roleCodes/${u}`)});let b=U(e.authz.roles.filter(_=>A.includes(_.code)).flatMap(_=>_.capabilities)),I=v(g.capabilityCodes,`${f}/capabilityCodes`,2e3);ee(b)!==ee(I)&&m("NATIVE_PERSPECTIVE_CAPABILITY_PROJECTION_MISMATCH",`${f}/capabilityCodes`),g.default===!0?r+=1:g.default!==void 0&&m("NATIVE_PERSPECTIVE_DEFAULT_INVALID",`${f}/default`)}r>1&&m("NATIVE_PERSPECTIVE_DEFAULT_DUPLICATE","/config/perspectives");for(let[p,d]of e.backend.operations.entries()){let f=T(d,`/config/backend/operations/${p}`);o.has(f.capability)||m("NATIVE_CAPABILITY_REFERENCE_MISSING",`/config/backend/operations/${p}/capability`)}let c=new Set,l=new Set;for(let[p,d]of e.frontend.routes.entries()){let f=`/config/frontend/routes/${p}`,g=T(d,f),E=F(g.code,`${f}/code`);c.has(E)&&m("NATIVE_ROUTE_DUPLICATE",`${f}/code`),c.add(E);let A=Ae(g.path,`${f}/path`);l.has(A)&&m("NATIVE_ROUTE_PATH_DUPLICATE",`${f}/path`),l.add(A);let b=To(g,f,e.appCode);b.capability&&!o.has(b.capability)&&m("NATIVE_CAPABILITY_REFERENCE_MISSING",`${f}/capability`);let I=g.access===void 0?void 0:T(g.access,`${f}/access`);for(let _ of["allOf","anyOf"]){let u=I?.[_]===void 0?[]:w(I[_],`${f}/access/${_}`,50);for(let[N,y]of u.entries()){let O=$e(y,`${f}/access/${_}/${N}`,e.appCode);o.has(O)||m("NATIVE_CAPABILITY_REFERENCE_MISSING",`${f}/access/${_}/${N}`)}}}if(e.frontend.admin.access!==void 0){let p=An(e.frontend.admin.access,"/config/frontend/admin/access",e.appCode);for(let d of["allOf","anyOf"])for(let[f,g]of(p[d]||[]).entries())o.has(g)||m("NATIVE_CAPABILITY_REFERENCE_MISSING",`/config/frontend/admin/access/${d}/${f}`)}for(let[p,d]of e.frontend.routes.entries()){let f=T(d,`/config/frontend/routes/${p}`);f.parentCode&&!c.has(f.parentCode)&&m("NATIVE_ROUTE_PARENT_MISSING",`/config/frontend/routes/${p}/parentCode`)}}function rc(e){let t=new Set(e.authz.roles.map(l=>String(l.code))),o=e.authz.authenticatedUserRoleCode===void 0?"":F(e.authz.authenticatedUserRoleCode,"/config/authz/authenticatedUserRoleCode"),n=new Map(e.authz.scopeDimensions.map(l=>[String(l.code),{valueType:l.valueType==="uuid"?"uuid":"string",...l.valueSource?.resourceCode?{valueSourceResourceCode:String(l.valueSource.resourceCode)}:{}}])),i=new Set(n.keys()),s=new Map(e.data.resources.map((l,p)=>{let d=Me(l,`/config/data/resources/${p}`,e.appCode);return[d.code,new Map(d.schema.fields.map(f=>[String(f.code),f]))]}));for(let[l,p]of e.authz.scopeDimensions.entries()){let d=`/config/authz/scopeDimensions/${l}`,f=T(p,d);if(R(f,["code","name","resourceCode","valueType","hierarchyMode","valueSource"],d,!0),f.valueSource===void 0)continue;let g=T(f.valueSource,`${d}/valueSource`);R(g,["kind","resourceCode","labelField","enabledField"],`${d}/valueSource`,!0),g.kind!=="native_resource"&&m("NATIVE_SCOPE_VALUE_SOURCE_KIND_INVALID",`${d}/valueSource/kind`),f.valueType!=="uuid"&&m("NATIVE_SCOPE_VALUE_SOURCE_TYPE_INVALID",`${d}/valueType`);let E=J(g.resourceCode,`${d}/valueSource/resourceCode`),A=s.get(E);A||m("NATIVE_SCOPE_VALUE_SOURCE_RESOURCE_MISSING",`${d}/valueSource/resourceCode`);let b=K(g.labelField,`${d}/valueSource/labelField`);if(["text.short","text.long"].includes(String(A.get(b)?.type||""))||m("NATIVE_SCOPE_VALUE_SOURCE_LABEL_FIELD_INVALID",`${d}/valueSource/labelField`),g.enabledField!==void 0){let I=K(g.enabledField,`${d}/valueSource/enabledField`);A.get(I)?.type!=="boolean"&&m("NATIVE_SCOPE_VALUE_SOURCE_ENABLED_FIELD_INVALID",`${d}/valueSource/enabledField`)}}let a=new Set,r=new Set;for(let[l,p]of e.authz.scopeSources.entries()){let d=`/config/authz/scopeSources/${l}`,f=T(p,d);R(f,["code","name","resourceCode","subject","grants","operationField","enabledField","effectiveFromField","effectiveToField","failureMode"],d,!0);let g=F(f.code,`${d}/code`);a.has(g)&&m("NATIVE_SCOPE_SOURCE_DUPLICATE",`${d}/code`),a.add(g),S(f.name,`${d}/name`,255);let E=J(f.resourceCode,`${d}/resourceCode`),A=s.get(E);A||m("NATIVE_SCOPE_SOURCE_RESOURCE_MISSING",`${d}/resourceCode`);let b=T(f.subject,`${d}/subject`),I=S(b.type,`${d}/subject/type`,32);R(b,I==="role_membership"?["type","userIdField","roleCode"]:["type","userIdField"],`${d}/subject`),["user","role_membership"].includes(I)||m("NATIVE_SCOPE_SOURCE_SUBJECT_INVALID",`${d}/subject/type`);let _=He(b.userIdField,A);zt(_)||m("NATIVE_SCOPE_SOURCE_SUBJECT_PATH_INVALID",`${d}/subject/userIdField`),I==="role_membership"&&!t.has(String(b.roleCode))&&m("NATIVE_ROLE_REFERENCE_MISSING",`${d}/subject/roleCode`);let u=new Set;for(let[N,y]of w(f.grants,`${d}/grants`,100).entries()){let O=`${d}/grants/${N}`,h=T(y,O);R(h,["dimensionCode","valueField","parentValueField"],O,!0);let C=F(h.dimensionCode,`${O}/dimensionCode`);(!i.has(C)||u.has(C))&&m("NATIVE_SCOPE_SOURCE_DIMENSION_INVALID",`${O}/dimensionCode`),u.add(C),f.failureMode==="last_known_good"&&r.add(C);for(let k of["valueField","parentValueField"]){if(h[k]===void 0)continue;let V=He(h[k],A);Jn(V,n.get(C),s)||m("NATIVE_SCOPE_SOURCE_GRANT_PATH_INVALID",`${O}/${k}`)}}u.size===0&&m("NATIVE_SCOPE_SOURCE_GRANT_REQUIRED",`${d}/grants`),["strict","last_known_good"].includes(f.failureMode)||m("NATIVE_SCOPE_SOURCE_FAILURE_MODE_INVALID",`${d}/failureMode`);for(let N of["operationField","enabledField","effectiveFromField","effectiveToField"]){if(f[N]===void 0)continue;let y=K(f[N],`${d}/${N}`);A.has(y)||m("NATIVE_SCOPE_SOURCE_FIELD_MISSING",`${d}/${N}`)}}cc(e,t,s,o);let c=new Set;for(let[l,p]of e.authz.dataPolicies.entries()){let d=`/config/authz/dataPolicies/${l}`,f=T(p,d);R(f,["code","name","resourceCode","unrestrictedRoleCodes","operations","matchMode","rules","readExpression","writeBoundary"],d,!0);let g=F(f.code,`${d}/code`);c.has(g)&&m("NATIVE_DATA_POLICY_DUPLICATE",`${d}/code`),c.add(g);let E=f.readExpression!==void 0,A=v(f.operations||[],`${d}/operations`,4);f.operations!==void 0&&(A.length===0||A.some(y=>!["read","create","update","delete"].includes(y)))&&m("NATIVE_DATA_POLICY_OPERATIONS_INVALID",`${d}/operations`),["AND","OR"].includes(f.matchMode)||m("NATIVE_DATA_POLICY_MATCH_MODE_INVALID",`${d}/matchMode`),E&&f.operations!==void 0&&m("NATIVE_DATA_POLICY_READ_EXPRESSION_OPERATIONS_FORBIDDEN",`${d}/operations`);let b=e.data.resources.find(y=>y.dataPolicyCode===g),I=f.resourceCode||b?.code,_=I?s.get(J(I,`${d}/resourceCode`)):void 0;E&&!_&&m("NATIVE_DATA_POLICY_RESOURCE_MISSING",`${d}/resourceCode`);let u=v(f.unrestrictedRoleCodes||[],`${d}/unrestrictedRoleCodes`,100);f.unrestrictedRoleCodes!==void 0&&u.length===0&&m("NATIVE_DATA_POLICY_UNRESTRICTED_ROLES_INVALID",`${d}/unrestrictedRoleCodes`);for(let y of u)t.has(y)||m("NATIVE_ROLE_REFERENCE_MISSING",`${d}/unrestrictedRoleCodes`);let N;try{let y=w(f.rules,`${d}/rules`,100).map((O,h)=>({rule:T(O,`${d}/rules/${h}`),pointer:`${d}/rules/${h}`}));y.length===0?(!E||f.matchMode!=="AND"||f.writeBoundary!=="capability_only")&&m("NATIVE_DATA_POLICY_WRITE_BOUNDARY_REQUIRED",d):f.writeBoundary!==void 0&&m("NATIVE_DATA_POLICY_WRITE_BOUNDARY_INVALID",`${d}/writeBoundary`),N=[...y],E&&(N.push(...Ot(f.readExpression,`${d}/readExpression`)),go(f.readExpression,`${d}/readExpression`))}catch(y){throw y instanceof nt&&m(y.code,y.pointer),y}for(let{rule:y,pointer:O}of N){R(y,["subject","dimensionCode","relationCode","resourceCode","field","roleCodes","operation","valuePath","emptyMatchesAll","operator","value","operand"],O,!0);let h=K(y.field,`${O}/field`),C=_?.get(h);E&&!C&&m("NATIVE_DATA_POLICY_FIELD_MISSING",`${O}/field`);for(let H of v(y.roleCodes||[],`${O}/roleCodes`,100))t.has(H)||m("NATIVE_ROLE_REFERENCE_MISSING",`${O}/roleCodes`);let k=String(y.operator||""),V=y.operand==="db_now",M=["is_null","is_not_null"].includes(k),P=["eq","not_eq","in","not_in"].includes(k),re=!V&&(y.operator!==void 0||y.value!==void 0);if([y.subject==="current_user"?"current_user":"",typeof y.dimensionCode=="string"?"dimension":"",typeof y.relationCode=="string"?"relationship":"",re?"constant":"",V?"db_now":""].filter(Boolean).length!==1&&m("NATIVE_DATA_POLICY_RULE_SOURCE_INVALID",O),y.subject!==void 0&&y.subject!=="current_user"&&m("NATIVE_DATA_POLICY_SUBJECT_INVALID",`${O}/subject`),re){if(!P&&!M&&m("NATIVE_DATA_POLICY_OPERATOR_INVALID",`${O}/operator`),["in","not_in"].includes(k)){let H=w(y.value,`${O}/value`,100).map((Te,ce)=>S(Te,`${O}/value/${ce}`,2048));(H.length===0||new Set(H).size!==H.length)&&m("NATIVE_DATA_POLICY_VALUE_INVALID",`${O}/value`)}else["eq","not_eq"].includes(k)?S(y.value,`${O}/value`,2048):(y.value!==void 0||y.operand!==void 0)&&m("NATIVE_DATA_POLICY_VALUE_INVALID",`${O}/value`);for(let H of["operation","valuePath","emptyMatchesAll","resourceCode","operand"])y[H]!==void 0&&m("NATIVE_DATA_POLICY_CONSTANT_RULE_INVALID",`${O}/${H}`)}if(V){(!["lt","lte","gt","gte"].includes(k)||y.value!==void 0||C?.type!=="datetime")&&m("NATIVE_DATA_POLICY_DB_NOW_INVALID",O);for(let H of["operation","valuePath","emptyMatchesAll","resourceCode","value"])y[H]!==void 0&&m("NATIVE_DATA_POLICY_DB_NOW_INVALID",`${O}/${H}`)}y.dimensionCode&&!i.has(y.dimensionCode)&&m("NATIVE_SCOPE_DIMENSION_MISSING",`${O}/dimensionCode`),r.has(String(y.dimensionCode||""))&&y.operation!=="read"&&m("NATIVE_SCOPE_SOURCE_LAST_KNOWN_GOOD_UNSAFE",`${O}/operation`)}}for(let[l,p]of e.data.resources.entries()){let d=T(p,`/config/data/resources/${l}`);d.dataPolicyCode&&!c.has(d.dataPolicyCode)&&m("NATIVE_DATA_POLICY_REFERENCE_MISSING",`/config/data/resources/${l}/dataPolicyCode`)}}function ac(e){try{Cn(e.data.resources,"/config/data/resources")}catch(t){throw t instanceof _e&&m(t.code,t.pointer),t}}function cc(e,t,o,n){let i=new Set;for(let[s,a]of e.authz.roleMembershipSources.entries()){let r=`/config/authz/roleMembershipSources/${s}`,c=T(a,r);R(c,["code","name","resourceCode","userIdField","roleCode","enabledField","effectiveFromField","effectiveToField","failureMode"],r,!0);let l=F(c.code,`${r}/code`);l.length>100&&m("NATIVE_AUTHORIZATION_PROJECTION_SOURCE_CODE_INVALID",`${r}/code`),i.has(l)&&m("NATIVE_AUTHORIZATION_PROJECTION_SOURCE_DUPLICATE",`${r}/code`),i.add(l),S(c.name,`${r}/name`,255);let p=Pi(c.resourceCode,`${r}/resourceCode`,o);Li(c.userIdField,`${r}/userIdField`,p),t.has(String(c.roleCode||""))||m("NATIVE_ROLE_REFERENCE_MISSING",`${r}/roleCode`),n&&c.roleCode===n&&m("NATIVE_AUTHENTICATED_USER_ROLE_SOURCE_CONFLICT",`${r}/roleCode`),xi(c,r,p)}for(let[s,a]of e.authz.relationshipGrantSources.entries()){let r=`/config/authz/relationshipGrantSources/${s}`,c=T(a,r);R(c,["code","name","resourceCode","subject","relationCode","targetResourceCode","resourceIdField","operations","enabledField","effectiveFromField","effectiveToField","failureMode"],r,!0);let l=F(c.code,`${r}/code`);l.length>100&&m("NATIVE_AUTHORIZATION_PROJECTION_SOURCE_CODE_INVALID",`${r}/code`),i.has(l)&&m("NATIVE_AUTHORIZATION_PROJECTION_SOURCE_DUPLICATE",`${r}/code`),i.add(l),S(c.name,`${r}/name`,255);let p=Pi(c.resourceCode,`${r}/resourceCode`,o),d=T(c.subject,`${r}/subject`),f=S(d.type,`${r}/subject/type`,32);R(d,f==="role_membership"?["type","userIdField","roleCode"]:["type","userIdField"],`${r}/subject`),["user","role_membership"].includes(f)||m("NATIVE_AUTHORIZATION_PROJECTION_SUBJECT_INVALID",`${r}/subject/type`),Li(d.userIdField,`${r}/subject/userIdField`,p),f==="role_membership"&&!t.has(String(d.roleCode||""))&&m("NATIVE_ROLE_REFERENCE_MISSING",`${r}/subject/roleCode`),F(c.relationCode,`${r}/relationCode`);let g=J(c.targetResourceCode,`${r}/targetResourceCode`);o.has(g)||m("NATIVE_AUTHORIZATION_PROJECTION_TARGET_RESOURCE_MISSING",`${r}/targetResourceCode`);let E=He(c.resourceIdField,p),A=E?.field.type==="resource-ref.single"&&E.valuePath==="value"&&E.field.source?.resourceCode===g;(c.resourceIdField==="id"?g!==String(c.resourceCode):!A)&&m("NATIVE_AUTHORIZATION_PROJECTION_RESOURCE_ID_FIELD_INVALID",`${r}/resourceIdField`);let b=v(c.operations,`${r}/operations`,20);(b.length===0||b.some(I=>I.length>64||!/^[A-Za-z0-9][A-Za-z0-9:._*-]{0,63}$/.test(I)))&&m("NATIVE_AUTHORIZATION_PROJECTION_OPERATIONS_INVALID",`${r}/operations`),xi(c,r,p)}}function Pi(e,t,o){let n=J(e,t),i=o.get(n);return i||m("NATIVE_AUTHORIZATION_PROJECTION_RESOURCE_MISSING",t),i}function Li(e,t,o){let n=He(e,o);zt(n)||m("NATIVE_AUTHORIZATION_PROJECTION_USER_FIELD_INVALID",t)}function xi(e,t,o){if(e.failureMode!=="strict"&&m("NATIVE_AUTHORIZATION_PROJECTION_FAILURE_MODE_INVALID",`${t}/failureMode`),e.enabledField!==void 0){let n=K(e.enabledField,`${t}/enabledField`);o.get(n)?.type!=="boolean"&&m("NATIVE_AUTHORIZATION_PROJECTION_ENABLED_FIELD_INVALID",`${t}/enabledField`)}for(let n of["effectiveFromField","effectiveToField"]){if(e[n]===void 0)continue;let i=K(e[n],`${t}/${n}`);["date","datetime"].includes(String(o.get(i)?.type))||m("NATIVE_AUTHORIZATION_PROJECTION_EFFECTIVE_FIELD_INVALID",`${t}/${n}`)}}function dc(e){let t=new Set,o=new Set;e.forEach((n,i)=>{let s=`/config/backend/secrets/${i}`,a=T(n,s);R(a,["name","env","description","required","exposure"],s,!0);let r=S(a.name,`${s}/name`,128),c=S(a.env,`${s}/env`,128);da.test(r)||m("NATIVE_SECRET_NAME_INVALID",`${s}/name`),(!la.test(c)||c.startsWith("OPENXIANGDA_")||["NODE_ENV","PORT"].includes(c))&&m("NATIVE_SECRET_ENV_INVALID",`${s}/env`),t.has(r)&&m("NATIVE_SECRET_NAME_DUPLICATE",`${s}/name`),o.has(c)&&m("NATIVE_SECRET_ENV_DUPLICATE",`${s}/env`),t.add(r),o.add(c),j(a.exposure,"active_only",`${s}/exposure`),a.required!==void 0&&st(a.required,`${s}/required`),a.description!==void 0&&Oo(a.description,`${s}/description`,2e3)})}function lc(e){let t=new Set,o=new Map,n=new Map(e.data.resources.map(g=>[String(g.code),g])),i=new Map(e.frontend.routes.map((g,E)=>{let A=T(g,`/config/frontend/routes/${E}`);return[F(A.code,`/config/frontend/routes/${E}/code`),A]}));for(let[g,E]of e.workflows.definitions.entries()){let A=`/config/workflows/definitions/${g}`,b=T(E,A);if(R(b,["version","definition","launch"],A,["detailRouteCode"]),os(b.launch,`${A}/launch`),b.detailRouteCode!==void 0){let y=is(b.detailRouteCode,`${A}/detailRouteCode`);for(let[O,h,C]of[["desktop",y.desktop,["admin","user"]],["mobile",y.mobile,["user"]]]){let k=`${A}/detailRouteCode/${O}`,V=i.get(h);V||m("NATIVE_WORKFLOW_DETAIL_ROUTE_MISSING",k),C.some(re=>re===V.surface)||m("NATIVE_WORKFLOW_DETAIL_ROUTE_SURFACE_INVALID",k);let M=Ae(V.path,k),P=[...M.matchAll(/:([A-Za-z][A-Za-z0-9_]*)/g)].map(re=>re[1]);(M.includes("*")||P.length!==1||P[0]!=="instanceId")&&m("NATIVE_WORKFLOW_DETAIL_ROUTE_PATH_INVALID",k)}}let I=T(b.definition,`${A}/definition`),_=`${I.code}:${it(b.version,`${A}/version`)}`;t.has(_)&&m("NATIVE_WORKFLOW_DEFINITION_DUPLICATE",A),t.add(_),fc(I,`${A}/definition`),uc(I.subject,n,`${A}/definition/subject`);let u=It(I,new Map((n.get(I.subject.resourceCode)?.schema.fields||[]).map(y=>[y.code,{...n.get(I.subject.resourceCode)?.surface?.fields?.[y.code],...y,system:["id","revision","createdAt","updatedAt","createdBy","updatedBy"].includes(y.code)}])),new Map([...n].map(([y,O])=>[y,new Map(O.schema.fields.map(h=>[h.code,{...O.surface?.fields?.[h.code],...h,system:["id","revision","createdAt","updatedAt","createdBy","updatedBy"].includes(h.code)}]))])));u.length&&m(u[0],`${A}/definition/taskPages`);let N=eo(I,{appCode:e.appCode,capabilities:e.authz.capabilities.map(y=>y.code),fields:new Map((n.get(I.subject.resourceCode)?.schema.fields||[]).map(y=>[y.code,y]))});N.length&&m("NATIVE_WORKFLOW_INSTANCE_COMMAND_POLICY_INVALID",`${A}/definition/instanceCommands`,{errors:N}),I.title===I.code&&m("NATIVE_WORKFLOW_USER_TITLE_REQUIRED",`${A}/definition/title`),o.set(_,I)}let s=new Set,a=new Map;for(let[g,E]of e.workflows.bindings.entries()){let A=T(E,`/config/workflows/bindings/${g}`),b=T(A.binding,`/config/workflows/bindings/${g}/binding`),I=`${b.workflowCode}:${it(A.version,`/config/workflows/bindings/${g}/version`)}`;s.has(I)&&m("NATIVE_WORKFLOW_BINDING_DUPLICATE",`/config/workflows/bindings/${g}`),s.add(I),pc(b,`/config/workflows/bindings/${g}/binding`),a.set(I,b)}let r=new Set,c=new Map;for(let[g,E]of e.workflows.activations.entries()){let A=`/config/workflows/activations/${g}`,b=T(E,A);R(b,["workflowCode","definitionVersion","bindingVersion","acceptedCommandDeactivationPolicy"],A,["environmentKey"]);let I=F(b.workflowCode,`${A}/workflowCode`);r.has(I)&&m("NATIVE_WORKFLOW_ACTIVATION_DUPLICATE",A),r.add(I);let _=`${I}:${it(b.definitionVersion,`${A}/definitionVersion`)}`,u=`${I}:${it(b.bindingVersion,`${A}/bindingVersion`)}`;t.has(_)||m("NATIVE_WORKFLOW_DEFINITION_REFERENCE_MISSING",`${A}/definitionVersion`),s.has(u)||m("NATIVE_WORKFLOW_BINDING_REFERENCE_MISSING",`${A}/bindingVersion`);let N=o.get(_),y=a.get(u),O=sn(N,y);O.length&&m(O[0],A),(!["finish-pinned","cancel-on-deactivate"].includes(b.acceptedCommandDeactivationPolicy)||b.acceptedCommandDeactivationPolicy!==N.acceptedCommandDeactivationPolicy)&&m("NATIVE_WORKFLOW_COMMAND_DEACTIVATION_POLICY_MISMATCH",`${A}/acceptedCommandDeactivationPolicy`),_c(N,y,`/config/workflows/activations/${g}`),c.set(I,y)}let l=_o([...c.values()]);l.length&&m(l[0],"/config/workflows/activations");let p=new Set;e.workflows.providers.forEach((g,E)=>{let A=`/config/workflows/providers/${E}`,b=T(g,A);R(b,["code","endpointPath","timeoutMs"],A,!0);let I=F(b.code,`${A}/code`);p.has(I)&&m("NATIVE_WORKFLOW_PROVIDER_DUPLICATE",`${A}/code`),p.add(I),Ae(b.endpointPath,`${A}/endpointPath`),b.timeoutMs!==void 0&&te(b.timeoutMs,`${A}/timeoutMs`,100,1e4)});for(let[g,E]of c.entries())for(let[A,b]of Object.entries(T(E.bindings,"/config/workflows/bindings/*/binding/bindings"))){let I=T(b,`/config/workflows/${g}/bindings/${A}`);I.provider==="application_provider"&&!p.has(I.providerCode)&&m("NATIVE_WORKFLOW_PROVIDER_REFERENCE_MISSING",`/config/workflows/${g}/bindings/${A}/providerCode`)}let d=new Set(e.authz.roles.map(g=>g.code)),f=new Set;e.workflows.editableParameters.forEach((g,E)=>{let A=`/config/workflows/editableParameters/${E}`,b=T(g,A);R(b,["code","workflowCode","bindingKey","label","valueType","required","allowedRoleCodes","allowedProviderCodes","maxItems"],A,!0);let I=F(b.code,`${A}/code`);f.has(I)&&m("NATIVE_WORKFLOW_EDITABLE_PARAMETER_DUPLICATE",`${A}/code`),f.add(I);let _=En(b.workflowCode,`${A}/workflowCode`),u=_n(b.bindingKey,`${A}/bindingKey`),N=c.get(_);(!N||!T(N.bindings,`${A}/bindingKey`)[u])&&m("NATIVE_WORKFLOW_EDITABLE_BINDING_MISSING",`${A}/bindingKey`),S(b.label,`${A}/label`,255),["role_code","user_ids","provider_code"].includes(b.valueType)||m("NATIVE_WORKFLOW_EDITABLE_VALUE_TYPE_INVALID",`${A}/valueType`);for(let y of v(b.allowedRoleCodes||[],`${A}/allowedRoleCodes`,100))d.has(y)||m("NATIVE_ROLE_REFERENCE_MISSING",`${A}/allowedRoleCodes`);for(let y of v(b.allowedProviderCodes||[],`${A}/allowedProviderCodes`,100))p.has(y)||m("NATIVE_WORKFLOW_PROVIDER_REFERENCE_MISSING",`${A}/allowedProviderCodes`);b.required!==void 0&&st(b.required,`${A}/required`),b.maxItems!==void 0&&te(b.maxItems,`${A}/maxItems`,1,200)})}function uc(e,t,o){let n=T(e,o);R(n,["resourceCode","factProjection"],o,["summaryFields"]);let i=J(n.resourceCode,`${o}/resourceCode`),s=t.get(i);s||m("NATIVE_WORKFLOW_SUBJECT_RESOURCE_MISSING",`${o}/resourceCode`);let a=new Set(w(T(s.schema,`${o}/resourceCode`).fields,`${o}/resourceCode`,500).map((l,p)=>K(T(l,`${o}/resourceCode/${p}`).code,`${o}/resourceCode/${p}`))),r=T(n.factProjection,`${o}/factProjection`),c=Object.entries(r);(c.length<1||c.length>64)&&m("NATIVE_WORKFLOW_SUBJECT_FACT_PROJECTION_INVALID",`${o}/factProjection`);for(let[l,p]of c){pa.test(l)||m("NATIVE_WORKFLOW_SUBJECT_FACT_KEY_INVALID",`${o}/factProjection/${l}`);let d=K(p,`${o}/factProjection/${l}`);a.has(d)||m("NATIVE_WORKFLOW_SUBJECT_FIELD_MISSING",`${o}/factProjection/${l}`)}if(n.summaryFields!==void 0){let l=v(n.summaryFields,`${o}/summaryFields`,_a).map((E,A)=>K(E,`${o}/summaryFields/${A}`)),p=t.get(i),d=p.surface&&typeof p.surface=="object"&&!Array.isArray(p.surface)?p.surface:{},f=d.fields&&typeof d.fields=="object"&&!Array.isArray(d.fields)?d.fields:{},g=new Map(w(T(p.schema,`${o}/resourceCode`).fields,`${o}/resourceCode`,500).map((E,A)=>{let b=T(E,`${o}/resourceCode/${A}`);return[String(b.code),b]}));for(let[E,A]of l.entries()){let b=g.get(A),I=f[A],_=String(b?.type||""),u=b?.maxLength;(!b||b.system===!0||I&&typeof I=="object"&&!Array.isArray(I)&&I.system===!0||["id","revision","created_by","updated_by","created_at","updated_at"].includes(A)||!ga.has(_)||_==="text.long"&&typeof u=="number"&&Number.isFinite(u)&&u>ma)&&m("NATIVE_WORKFLOW_SUBJECT_SUMMARY_FIELDS_INVALID",`${o}/summaryFields/${E}`)}}}function fc(e,t){R(e,["schemaVersion","code","title","subject","acceptedCommandDeactivationPolicy","startAt","inputSchema","nodes"],t,["organizationContext","instanceCommands","readability","taskPages"]),j(e.schemaVersion,"openxiangda.workflow-definition/v2",`${t}/schemaVersion`),En(e.code,`${t}/code`),S(e.title,`${t}/title`,255),["finish-pinned","cancel-on-deactivate"].includes(e.acceptedCommandDeactivationPolicy)||m("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)&&m("NATIVE_WORKFLOW_NODE_COUNT_INVALID",`${t}/nodes`);let i=S(e.startAt,`${t}/startAt`,128),s=co(e);s.length&&m(s[0],`${t}/readability`);let a=sn(e);a.length&&m(a[0],`${t}/nodes`);let r=rn(e);r.length&&m(r[0],`${t}/nodes`);let c=It(e);c.length&&m(c[0],`${t}/taskPages`);let l=_t(e);l.length&&m(l[0],`${t}/nodes`),o[i]||m("NATIVE_WORKFLOW_START_NODE_MISSING",`${t}/startAt`);let p=new Map;for(let[E,A]of Object.entries(o)){let b=`${t}/nodes/${E}`,I=T(A,b);j(I.id,E,`${b}/id`),["approval","condition","end","cc","action"].includes(I.kind)||m("NATIVE_WORKFLOW_NODE_KIND_INVALID",`${b}/kind`);let _=[];if(I.kind==="approval"){S(I.title,`${b}/title`,255),_n(I.binding,`${b}/binding`),["single","any","all","sequence"].includes(I.mode)||m("NATIVE_WORKFLOW_APPROVAL_MODE_INVALID",`${b}/mode`),_.push(S(I.onApprove,`${b}/onApprove`,128),S(I.onReject,`${b}/onReject`,128));for(let u of v(I.returnTargets||[],`${b}/returnTargets`,200))o[u]||m("NATIVE_WORKFLOW_TARGET_MISSING",`${b}/returnTargets`);for(let u of v(I.allowedOperations||[],`${b}/allowedOperations`,20))Ea.has(u)||m("NATIVE_WORKFLOW_OPERATION_INVALID",`${b}/allowedOperations`)}else if(I.kind==="action")_.push(S(I.next,`${b}/next`,128));else if(I.kind==="cc")S(I.title,`${b}/title`,255),_n(I.binding,`${b}/binding`),_.push(S(I.next,`${b}/next`,128));else if(I.kind==="condition"){let u=w(I.branches,`${b}/branches`,100);u.length===0&&m("NATIVE_WORKFLOW_BRANCH_REQUIRED",`${b}/branches`),u.forEach((N,y)=>{let O=T(N,`${b}/branches/${y}`);ht(O.when,`${b}/branches/${y}/when`,0),_.push(S(O.target,`${b}/branches/${y}/target`,128))}),_.push(S(I.otherwise,`${b}/otherwise`,128))}else S(I.title,`${b}/title`,255),S(I.outcome,`${b}/outcome`,128);for(let u of _)o[u]||m("NATIVE_WORKFLOW_TARGET_MISSING",b);p.set(E,_)}let d=new Set,f=new Set,g=E=>{if(f.has(E)&&m("NATIVE_WORKFLOW_CYCLE_FORBIDDEN",`${t}/nodes/${E}`),!d.has(E)){d.add(E),f.add(E);for(let A of p.get(E)||[])g(A);f.delete(E)}};g(i),d.size!==n.length&&m("NATIVE_WORKFLOW_NODE_UNREACHABLE",`${t}/nodes`)}function ht(e,t,o){o>20&&m("NATIVE_WORKFLOW_EXPRESSION_DEPTH_EXCEEDED",t);let n=T(e,t),i=S(n.op,`${t}/op`,16);if(i!=="literal"){if(i==="path"){let s=S(n.path,`${t}/path`,255);(!/^[A-Za-z][A-Za-z0-9_.-]{0,254}$/.test(s)||s.split(".").some(a=>["__proto__","constructor","prototype"].includes(a)))&&m("NATIVE_WORKFLOW_EXPRESSION_PATH_INVALID",`${t}/path`);return}if(["eq","neq","gt","gte","lt","lte","in","contains"].includes(i)){ht(n.left,`${t}/left`,o+1),ht(n.right,`${t}/right`,o+1);return}if(["and","or"].includes(i)){let s=w(n.values,`${t}/values`,100);s.length===0&&m("NATIVE_WORKFLOW_EXPRESSION_EMPTY",`${t}/values`),s.forEach((a,r)=>ht(a,`${t}/values/${r}`,o+1));return}if(["not","exists"].includes(i)){ht(n.value,`${t}/value`,o+1);return}m("NATIVE_WORKFLOW_EXPRESSION_OPERATOR_INVALID",`${t}/op`)}}function pc(e,t){j(e.schemaVersion,"openxiangda.workflow-binding/v2",`${t}/schemaVersion`),En(e.workflowCode,`${t}/workflowCode`);let o=T(e.bindings,`${t}/bindings`);Object.keys(o).length>200&&m("NATIVE_WORKFLOW_BINDING_LIMIT_EXCEEDED",`${t}/bindings`);for(let[n,i]of Object.entries(o)){_n(n,`${t}/bindings/${n}`);let s=T(i,`${t}/bindings/${n}`),a=S(s.provider,`${t}/bindings/${n}/provider`,64);if(["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)||m("NATIVE_WORKFLOW_BINDING_PROVIDER_INVALID",`${t}/bindings/${n}/provider`),a==="fixed_users"&&w(s.users,`${t}/bindings/${n}/users`,200).length===0&&m("NATIVE_WORKFLOW_BINDING_USERS_REQUIRED",`${t}/bindings/${n}/users`),["input_users","form_field_users"].includes(a)&&S(s.inputPath,`${t}/bindings/${n}/inputPath`,255),["app_role","app_role_in_scope","initiator_select"].includes(a)&&F(s.roleCode,`${t}/bindings/${n}/roleCode`),a==="department_supervisor"&&S(s.departmentIdFrom,`${t}/bindings/${n}/departmentIdFrom`,255),a==="application_provider"&&F(s.providerCode,`${t}/bindings/${n}/providerCode`),s.routing!==void 0){let r=Nt(s.routing);r.length&&m(r[0],`${t}/bindings/${n}/routing`)}}}function _c(e,t,o){j(t.workflowCode,e.code,`${o}/workflowCode`);let n=T(t.bindings,`${o}/bindings`),i=rn(e,t);i.length&&m(i[0],o);let s=_t(e,t);s.length&&m(s[0],o);for(let[a,r]of Object.entries(T(e.nodes,`${o}/nodes`))){let c=T(r,`${o}/nodes/${a}`);["approval","cc"].includes(c.kind)&&!n[c.binding]&&m("NATIVE_WORKFLOW_BINDING_REFERENCE_MISSING",`${o}/nodes/${a}/binding`)}}function mc(e,t,o){let n=T(t.routeManifest,"/contracts/routeManifest"),i=T(e.routeManifest,"/contracts/routeManifest"),s=new Map;for(let p of w(o.data?.resources,"/config/data/resources",100)){let d=T(p,"/config/data/resources");s.set(String(d.code||""),d)}let a=new Set(w(i.routes,"/contracts/routeManifest/routes",1e3).map(p=>String(T(p,"/contracts/routeManifest/routes").code||""))),r=[];for(let p of w(n.routes,"/contracts/routeManifest/routes",1e3)){let d=T(p,"/contracts/routeManifest/routes"),f=String(d.kind||"");if(f!=="resource-records"&&f!=="resource-submit")continue;let g=String(d.resourceCode||""),E=s.get(g);E||m("NATIVE_ROUTE_MANIFEST_RESOURCE_UNKNOWN","/contracts/routeManifest/routes");let b=`user.${g}.${f==="resource-records"?"records":"submit"}`;j(String(d.code||""),b,"/contracts/routeManifest/routes/code");let I=f==="resource-records"?"read":"create",_=String(T(E.capabilities,"/config/data/resources/capabilities")[I]||"");for(let u of["desktop","mobile"]){let N=T(d[u],`/contracts/routeManifest/routes/${u}`),y=u==="mobile"?"/m/my/":"/my/",O=f==="resource-records"?`${y}${g}`:`${y}${g}/submit`;j(String(N.path||""),O,`/contracts/routeManifest/routes/${u}/path`),j(String(N.capability||""),_,`/contracts/routeManifest/routes/${u}/capability`),j(String(N.routeCode||""),`${b}.${u}`,`/contracts/routeManifest/routes/${u}/routeCode`)}(a.has(b)||r.some(u=>String(u.code)===b))&&m("NATIVE_ROUTE_MANIFEST_DUPLICATE","/contracts/routeManifest/routes/code"),r.push(d)}if(!r.length)return;i.routes=w([...i.routes,...r],"/contracts/routeManifest/routes",1e3).sort((p,d)=>ue(String(T(p,"x").code||""),String(T(d,"x").code||"")));let c=String(T(n.rootEntry,"x").code||"");if(r.find(p=>String(p.code)===c&&p.kind==="resource-records")){let p=T(n.rootEntry,"x");i.rootEntry={code:c,desktop:String(p.desktop||""),mobile:String(p.mobile||"")}}i.digest=X({schemaVersion:i.schemaVersion,appCode:i.appCode,devicePolicy:i.devicePolicy,rootEntry:i.rootEntry,authentication:i.authentication,routes:i.routes})}function Me(e,t,o){let n=T(e,t);R(n,["schemaVersion","appCode","code","name","schema","surface","invariants","decimalReservationLifecycle","uniqueKeys","capabilities","dataPolicyCode","fieldPolicies"],t,!0),j(n.schemaVersion,"openxiangda.data-resource/v2",`${t}/schemaVersion`),j(n.appCode,o,`${t}/appCode`);let i=J(n.code,`${t}/code`),s=S(n.name,`${t}/name`,255),a=T(n.schema,`${t}/schema`);R(a,["fields"],`${t}/schema`);let r,c,l,p;try{l=Kt(n.decimalReservationLifecycle,`${t}/decimalReservationLifecycle`),r=vt(a.fields,`${t}/schema/fields`),p=Xn(n.uniqueKeys,r,`${t}/uniqueKeys`),c=Sn(n.invariants,r,`${t}/invariants`),Wt(n.surface,r,`${t}/surface`)}catch(E){throw(E instanceof _e||E instanceof Pe||E instanceof Xe)&&m(E.code,E.pointer),E}let d=new Set(r.map(E=>E.code)),f=T(n.capabilities,`${t}/capabilities`);R(f,["read","create","update","delete"],`${t}/capabilities`);let g=T(n.fieldPolicies,`${t}/fieldPolicies`);for(let[E,A]of Object.entries(g)){!d.has(E)&&!Ge(E)&&m("NATIVE_DATA_FIELD_POLICY_FIELD_MISSING",`${t}/fieldPolicies/${E}`);let b=`${t}/fieldPolicies/${E}`,I=T(A,b);Ge(E)&&(R(I,["read"],b,!0),(!Array.isArray(I.read)||I.read.length>20||I.read.some(_=>typeof _!="string"||!_.trim())||new Set(I.read).size!==I.read.length)&&m("NATIVE_DATA_AUDIT_READ_POLICY_INVALID",`${b}/read`)),R(I,["read","create","update","mask"],b,!0),I.mask!==void 0&&!["omit","null"].includes(I.mask)&&m("NATIVE_DATA_FIELD_POLICY_MASK_INVALID",`${b}/mask`)}return{...n,code:i,name:s,schema:{fields:r},...n.invariants===void 0?{}:{invariants:c},...l?{decimalReservationLifecycle:l}:{},...p!==void 0?{uniqueKeys:p}:{},capabilities:f,fieldPolicies:g}}function ss(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 ji(e,t,o,n){let i=e.toString("utf8"),s;try{s=JSON.parse(i)}catch{m(o,t)}let a=T(s,t);return ee(a)!==i&&m(n,t),a}function Wi(e,t){let o=0,n=(i,s,a)=>{if(o+=1,o>Na&&m("NATIVE_ARTIFACT_NODE_LIMIT_EXCEEDED",s),a>ya&&m("NATIVE_ARTIFACT_DEPTH_LIMIT_EXCEEDED",s),typeof i=="string"){Buffer.byteLength(i)>Eo&&m("NATIVE_ARTIFACT_STRING_LIMIT_EXCEEDED",s);return}if(Array.isArray(i)){i.forEach((r,c)=>n(r,`${s}/${c}`,a+1));return}if(!(!i||typeof i!="object"))for(let[r,c]of Object.entries(i))["__proto__","prototype","constructor"].includes(r)&&m("NATIVE_ARTIFACT_DANGEROUS_KEY",`${s}/${r}`),gc(r)&&m("NATIVE_ARTIFACT_RUNTIME_FIELD_FORBIDDEN",`${s}/${r}`),n(c,`${s}/${r}`,a+1)};n(e,t,0)}function gc(e){return["environmentKey","environmentId","secretValue","ciphertext","oauthClient","oauthClientId","oauthClientSecret","signingSecret","kubernetesNamespace","nodePort","productionUrl"].includes(e)}function ot(e){return{value:e,digest:X(e)}}function Mi(e,t,o,n){typeof e!="string"&&!Buffer.isBuffer(e)&&!(e instanceof Uint8Array)&&m("NATIVE_ARTIFACT_BYTES_REQUIRED",o);let i=Buffer.isBuffer(e)?e:Buffer.from(e);return i.byteLength===0&&m("NATIVE_ARTIFACT_EMPTY",o),i.byteLength>t&&m(n,o),i}function Ui(e,t,o,n){let i=mn.createHash("sha256").update(e).digest("hex");mn.timingSafeEqual(Buffer.from(i),Buffer.from(t))||m(n,o)}function T(e,t){return(!e||typeof e!="object"||Array.isArray(e))&&m("NATIVE_OBJECT_REQUIRED",t),e}function w(e,t,o){return Array.isArray(e)||m("NATIVE_ARRAY_REQUIRED",t),e.length>o&&m("NATIVE_ARRAY_LIMIT_EXCEEDED",t),e}function v(e,t,o){let n=w(e,t,o).map((i,s)=>S(i,`${t}/${s}`,255));return new Set(n).size!==n.length&&m("NATIVE_ARRAY_DUPLICATE",t),n}function S(e,t,o){return(typeof e!="string"||e.length===0||e.length>o)&&m("NATIVE_STRING_INVALID",t),e}function Oo(e,t,o){return(typeof e!="string"||e.length>o)&&m("NATIVE_STRING_INVALID",t),e}function F(e,t){let o=S(e,t,128);return sa.test(o)||m("NATIVE_CODE_INVALID",t),o}function J(e,t){let o=S(e,t,64);return aa.test(o)||m("NATIVE_RESOURCE_CODE_INVALID",t),o}function K(e,t){let o=S(e,t,63);return ca.test(o)||m("NATIVE_FIELD_CODE_INVALID",t),o}function En(e,t){let o=S(e,t,128);return ua.test(o)||m("NATIVE_WORKFLOW_CODE_INVALID",t),o}function _n(e,t){let o=S(e,t,128);return fa.test(o)||m("NATIVE_WORKFLOW_BINDING_CODE_INVALID",t),o}function $e(e,t,o){let n=S(e,t,255);return ia.test(n)||m("NATIVE_CAPABILITY_CODE_INVALID",t),!n.startsWith(`app:${o}:`)&&!ss(o).some(i=>i.code===n)&&m("NATIVE_CAPABILITY_APP_MISMATCH",t),n}function Ae(e,t){let o=S(e,t,2048);return(!o.startsWith("/")||o.startsWith("//")||o.includes("..")||o.includes("?")||o.includes("#"))&&m("NATIVE_ABSOLUTE_PATH_INVALID",t),o}function it(e,t){return(!Number.isInteger(e)||Number(e)<1)&&m("NATIVE_POSITIVE_INTEGER_REQUIRED",t),Number(e)}function te(e,t,o,n){return(!Number.isInteger(e)||Number(e)<o||Number(e)>n)&&m("NATIVE_INTEGER_OUT_OF_RANGE",t),Number(e)}function st(e,t){return typeof e!="boolean"&&m("NATIVE_BOOLEAN_REQUIRED",t),e}function bo(e,t){let o=S(e,t,64).toLowerCase();return na.test(o)||m("NATIVE_DIGEST_INVALID",t),o}function j(e,t,o){e!==t&&m("NATIVE_VALUE_MISMATCH",o)}function R(e,t,o,n=!1){let i=new Set([...t,...Array.isArray(n)?n:[]]);for(let s of Object.keys(e))i.has(s)||m("NATIVE_PROPERTY_UNKNOWN",`${o}/${s}`);if(n!==!0)for(let s of t)Object.prototype.hasOwnProperty.call(e,s)||m("NATIVE_PROPERTY_REQUIRED",`${o}/${s}`)}function Z(e,t){return[...e].sort((o,n)=>ue(t(o),t(n)))}function U(e){return[...new Set(e)].sort(ue)}function Bi(e){return[...new Set(e)].sort((t,o)=>t-o)}function ue(e,t){return e===t?0:e<t?-1:1}function rs(e){return!e||typeof e!="object"||Object.isFrozen(e)||(Object.freeze(e),Object.values(e).forEach(t=>rs(t))),e}function yo(e,t,o){if(Ao(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(!Ao(e[i],t[i]))return yo(e[i],t[i],`${o}/${i}`)}if(e&&t&&typeof e=="object"&&typeof t=="object"&&!Array.isArray(e)&&!Array.isArray(t)){let n=U([...Object.keys(e),...Object.keys(t)]);for(let i of n){let s=e[i],a=t[i];if(!Ao(s,a))return yo(s,a,`${o}/${i}`)}}return o}function Ao(e,t){return e===void 0||t===void 0?e===t:ee(e)===ee(t)}function m(e,t,o={}){throw new un(e,t,o)}var Yd=50,Hd=131072,In=class extends Error{constructor(o){super("OPENXIANGDA_NATIVE_AUTHZ_BATCH_INPUT_INVALID");this.pointer=o}pointer;code="OPENXIANGDA_NATIVE_AUTHZ_BATCH_INPUT_INVALID";status=400};function Ac(e){let t=d=>{throw new In(d)},o=(d,f)=>((!d||typeof d!="object"||Array.isArray(d))&&t(f),d),n=(d,f,g)=>{for(let E of Object.keys(d))f.includes(E)||t(`${g}/${E}`)},i=(d,f,g)=>((typeof d!="string"||!d.trim()||d.length>f)&&t(g),d),s=(d,f)=>{let g=i(d,36,f);return/^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i.test(g)||t(f),g.toLowerCase()},a=o(e,""),r;try{r=new TextEncoder().encode(JSON.stringify(a)).byteLength}catch{t("")}r>131072&&t(""),n(a,["schemaVersion","environmentKey","items"],""),a.schemaVersion!=="openxiangda.native-role-membership-batch-request/v2"&&t("/schemaVersion"),a.environmentKey!==void 0&&!["preproduction","production"].includes(String(a.environmentKey))&&t("/environmentKey"),(!Array.isArray(a.items)||a.items.length<1||a.items.length>50)&&t("/items");let c=new Set,l=new Set,p;for(let[d,f]of a.items.entries()){let g=`/items/${d}`,E=o(f,g);["create","update","revoke"].includes(String(E.operation))||t(`${g}/operation`),p??=E.operation,p!==E.operation&&t(`${g}/operation`),n(E,["operation","operationId","reason",...p==="create"?["userId","roleCode"]:["membershipId","expectedRevision"],...p!=="revoke"?["scopeGrants","validFrom","validTo"]:[]],g);let A=s(E.operationId,`${g}/operationId`);c.has(A)&&t(`${g}/operationId`),c.add(A),i(E.reason,1e3,`${g}/reason`);let b;if(p==="create"){let I=i(E.userId,255,`${g}/userId`),_=i(E.roleCode,128,`${g}/roleCode`);/^[a-z][a-z0-9]*(?:[._-][a-z0-9]+)*$/.test(_)||t(`${g}/roleCode`),b=JSON.stringify([I,_])}else b=s(E.membershipId,`${g}/membershipId`),(!Number.isSafeInteger(E.expectedRevision)||Number(E.expectedRevision)<1)&&t(`${g}/expectedRevision`);l.has(b)&&t(g),l.add(b),E.scopeGrants!==void 0&&(!Array.isArray(E.scopeGrants)||E.scopeGrants.length>100)&&t(`${g}/scopeGrants`);for(let I of["validFrom","validTo"])E[I]!==void 0&&E[I]!==null&&i(E[I],64,`${g}/${I}`)}}var ls="openxiangda.workflow-delegation-administration/v2",us="openxiangda.workflow-delegation-mutation/v2",as="openxiangda.workflow-delegation-preview/v2";var Ct={type:"string",format:"uuid",pattern:"^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-5][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}$"},fe={type:"string",minLength:1,maxLength:255},Ue={type:"string",format:"date-time"},rt={type:"integer",minimum:1},Ec={anyOf:[Ue,{type:"null"}]},ho={anyOf:[fe,{type:"null"}]},bn={type:"string",pattern:"^membership:[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$"},fs={const:"future-assignments-only"},Ro={schemaVersion:{const:ls},id:Ct,appCode:fe,environmentKey:fe,workflowCode:ho,delegatorUserId:fe,delegateUserId:fe,delegatorRoleSubjectKey:bn,delegateRoleSubjectKey:bn,validFrom:Ue,validTo:Ue,status:{enum:["active","revoked","expired"]},reason:{type:"string",minLength:1,maxLength:4e3},createdBy:fe,createdAt:Ue,revokedAt:Ec,revision:rt,roleCode:fe,roleName:fe,delegatorDisplayName:fe,delegateDisplayName:fe,delegatorRoleSubjectRevision:rt,delegateRoleSubjectRevision:rt,effectiveState:{enum:["active","scheduled","expired","revoked","ineligible"]},evaluatedAt:Ue,issues:{type:"array",maxItems:20,uniqueItems:!0,items:fe},canRevoke:{type:"boolean"},revokedBy:ho,revokeReason:{type:["string","null"],maxLength:4e3},taskPolicy:fs},Co={type:"object",additionalProperties:!1,required:Object.keys(Ro),properties:Ro},Qd={$id:ls,...Co},ps={schemaVersion:{const:us},operationId:Ct,environmentKey:{enum:["preproduction","production"]},reason:{type:"string",minLength:1,maxLength:2e3,pattern:"\\S"}},cs={...ps,operation:{const:"create"},workflowCode:ho,delegatorRoleSubjectKey:bn,expectedDelegatorRevision:rt,delegateUserId:fe,delegateRoleSubjectKey:bn,expectedDelegateRevision:rt,validFrom:Ue,validTo:Ue},ds={...ps,operation:{const:"revoke"},delegationId:Ct,expectedRevision:rt},_s={$id:us,type:"object",oneOf:[{type:"object",additionalProperties:!1,required:Object.keys(cs),properties:cs},{type:"object",additionalProperties:!1,required:Object.keys(ds),properties:ds}]},Ic={type:"string",pattern:"^[0-9a-f]{64}$"},Zd={$id:as,type:"object",additionalProperties:!1,required:["schemaVersion","operationId","operation","requestDigest","before","after","taskPolicy"],properties:{schemaVersion:{const:as},operationId:Ct,operation:{enum:["create","revoke"]},requestDigest:Ic,before:{anyOf:[Co,{type:"null"}]},after:{...Co,properties:{...Ro,id:{anyOf:[Ct,{type:"null"}]}}},taskPolicy:fs}};function bc(e){return e===void 0?"":`
9
+ ${X(e)}`}function yc(e,t){let o=e.handlers.find(n=>n.code===t);return X(o?.workflowStep?o:e)}var Nc="67e2e7393d022709e99cdfe556814891b1777c2b09343ecaf45d57a6dc031299";0&&(module.exports={DATA_AUDIT_METADATA_FIELDS,DATA_EVENT_TYPES_V2,DATA_FORM_DRAFT_MAX_BYTES,DATA_SUBTABLE_MAX_ROWS,DATA_SUBTABLE_MAX_TOTAL_ROWS,DATA_SYSTEM_SORT_FIELD_CODES,DATA_TRANSACTION_MAX_BYTES,DATA_TRANSACTION_MAX_OPERATIONS,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_ROLE_MEMBERSHIP_BATCH_MAX_BYTES,NATIVE_ROLE_MEMBERSHIP_BATCH_MAX_ITEMS,NATIVE_UNIQUE_KEY_MAX_BYTES,NATIVE_UNIQUE_KEY_NORMALIZERS,NativeConfigurationCompilerError,NativeDataFieldContractV2Error,NativeDataPolicyExpressionV2Error,NativeDecimalLifecycleContractError,NativeEventActionContractError,NativeRoleMembershipBatchInputError,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_AUTOMATIC_CC_MAX_RECIPIENTS,WORKFLOW_AUTOMATIC_CC_PROVIDERS,WORKFLOW_BUSINESS_STEP_EVENT,WORKFLOW_BUSINESS_STEP_EVENTS,WORKFLOW_BUSINESS_STEP_FACTS_KEY,WORKFLOW_BUSINESS_STEP_MAX_BYTES,WORKFLOW_BUSINESS_STEP_MAX_RECEIPT_BYTES,WORKFLOW_CONFIGURABLE_OPERATIONS,WORKFLOW_CONFIGURABLE_PROVIDERS,WORKFLOW_EVENT_TYPES_V2,WORKFLOW_ROUTING_MAX_BYTES,WORKFLOW_ROUTING_MAX_MATCHED_RULES,WORKFLOW_ROUTING_MAX_RULES,WORKFLOW_TASK_PAGE_DEFINITION_MAX_BYTES,WORKFLOW_TASK_PAGE_MAX_BYTES,WORKFLOW_TASK_PAGE_MAX_FIELDS,WORKFLOW_TASK_SUBTABLE_MAX_ROWS,WORKFLOW_TASK_SUBTABLE_MAX_TOTAL_ROWS,WorkflowTaskPageError,applyWorkflowTaskPageValues,applyWorkflowTaskSubtableRows,assertNativeRoleMembershipBatchInput,compileNativeApplicationConfiguration,compileNativeEventAction,compileNativeEventCapturePlansV2,compileRequiredPlatformCapabilitiesV3,compileWorkflowBusinessStepHandlers,evaluateWorkflowTaskPageExpression,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,refreshWorkflowTaskPageFacts,resolveNativeScopeSourceFieldPathV2,selectWorkflowAssignmentRoutingRules,serializedDataBytes,validateDecimalReservationLifecycles,validateManagedConcurrency,validateNativeDataDraftStateV2,validateNativeDataResourceReferencesV2,validateNativeDataResourceSurfaceV2,validateWorkflowAdministration,validateWorkflowAssignmentRoutingBindings,validateWorkflowAssignmentRoutingPolicy,validateWorkflowAssignmentRoutingRules,validateWorkflowAutomaticCc,validateWorkflowBusinessStepHandlerContract,validateWorkflowBusinessStepRequest,validateWorkflowBusinessStepResult,validateWorkflowBusinessStepSchema,validateWorkflowBusinessStepSubscriptions,validateWorkflowBusinessSteps,validateWorkflowInstanceCommandPolicies,validateWorkflowNodeConfigurationPatch,validateWorkflowReadability,validateWorkflowTaskPages,workflowAssignmentRoutingFacts,workflowAssignmentRoutingPolicySchema,workflowAssignmentRoutingSemantic,workflowBusinessStepFactSchema,workflowBusinessStepHandlerDigest,workflowBusinessStepInput,workflowBusinessStepPath,workflowBusinessStepReceiptSignatureSuffix,workflowBusinessStepValueMatches,workflowDelegationMutationRequestSchema,workflowExpressionPaths,workflowInstanceCommandDeadlineError,workflowInstanceTerminateCapabilityAllowed,workflowNodeAllowedOperations,workflowPolicyTimestamp,workflowTaskPageFieldState,workflowTaskPageReplayCoversInvalidation,workflowTaskSubtableRows});