openxiangda-contracts 2.70.0 → 2.71.1

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 (36) hide show
  1. package/dist/native-compiler/compiler.d.ts.map +1 -1
  2. package/dist/native-compiler/compiler.js +6 -1
  3. package/dist/native-compiler/compiler.js.map +1 -1
  4. package/dist/native-compiler/index.cjs +3 -3
  5. package/dist/native-compiler/index.js +3 -3
  6. package/dist/native-compiler/workflow-correction.d.ts +3 -0
  7. package/dist/native-compiler/workflow-correction.d.ts.map +1 -1
  8. package/dist/native-compiler/workflow-correction.js +4 -1
  9. package/dist/native-compiler/workflow-correction.js.map +1 -1
  10. package/dist/native-compiler/workflow-graph.d.ts +2 -0
  11. package/dist/native-compiler/workflow-graph.d.ts.map +1 -1
  12. package/dist/native-compiler/workflow-graph.js +23 -1
  13. package/dist/native-compiler/workflow-graph.js.map +1 -1
  14. package/dist/native-compiler/workflow-node-administration.d.ts +1 -0
  15. package/dist/native-compiler/workflow-node-administration.d.ts.map +1 -1
  16. package/dist/native-compiler/workflow-node-administration.js +2 -0
  17. package/dist/native-compiler/workflow-node-administration.js.map +1 -1
  18. package/dist/native-compiler/workflow-role-union.d.ts +17 -0
  19. package/dist/native-compiler/workflow-role-union.d.ts.map +1 -1
  20. package/dist/native-compiler/workflow-role-union.js +16 -0
  21. package/dist/native-compiler/workflow-role-union.js.map +1 -1
  22. package/dist/native-version.d.ts +1 -0
  23. package/dist/native-version.d.ts.map +1 -1
  24. package/dist/native-version.js +1 -0
  25. package/dist/native-version.js.map +1 -1
  26. package/dist/schemas.d.ts +64 -4
  27. package/dist/schemas.d.ts.map +1 -1
  28. package/dist/schemas.js +8 -2
  29. package/dist/schemas.js.map +1 -1
  30. package/dist/types.d.ts +2 -0
  31. package/dist/types.d.ts.map +1 -1
  32. package/dist/types.js.map +1 -1
  33. package/dist/validation.d.ts.map +1 -1
  34. package/dist/validation.js +3 -2
  35. package/dist/validation.js.map +1 -1
  36. package/package.json +1 -1
@@ -1,9 +1,9 @@
1
- "use strict";var Ys=Object.create;var Xt=Object.defineProperty;var Xs=Object.getOwnPropertyDescriptor;var Zs=Object.getOwnPropertyNames;var Qs=Object.getPrototypeOf,ea=Object.prototype.hasOwnProperty;var ta=(e,t)=>{for(var o in t)Xt(e,o,{get:t[o],enumerable:!0})},$i=(e,t,o,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of Zs(t))!ea.call(e,i)&&i!==o&&Xt(e,i,{get:()=>t[i],enumerable:!(n=Xs(t,i))||n.enumerable});return e};var na=(e,t,o)=>(o=e!=null?Ys(Qs(e)):{},$i(t||!e||!e.__esModule?Xt(o,"default",{value:e,enumerable:!0}):o,e)),oa=e=>$i(Xt({},"__esModule",{value:!0}),e);var Gl={};ta(Gl,{AuthenticatedPublicReadContractError:()=>dt,DATA_AUDIT_METADATA_FIELDS:()=>Rt,DATA_BUSINESS_COMMAND_INTENT_MAX_BYTES:()=>bp,DATA_BUSINESS_COMMAND_RESOLUTION_SCHEMA:()=>Us,DATA_BUSINESS_COMMAND_SCHEMA:()=>Nl,DATA_EVENT_TYPES_V2:()=>xn,DATA_FORM_DRAFT_MAX_BYTES:()=>Ql,DATA_SUBTABLE_DEFAULT_TOTAL_ROWS:()=>Xl,DATA_SUBTABLE_MAX_ROWS:()=>Me,DATA_SUBTABLE_MAX_TOTAL_ROWS:()=>Qt,DATA_SYSTEM_SORT_FIELD_CODES:()=>qi,DATA_TRANSACTION_MAX_BYTES:()=>Zl,DATA_TRANSACTION_MAX_OPERATIONS:()=>ji,DATA_TRANSACTION_RECORD_SET_MAX_RECORDS:()=>Tp,DATE_EVENT_RESERVED_DATA_FIELDS_V2:()=>Wd,DEVELOPMENT_BACKEND_CONNECTION_TTL_SECONDS:()=>Lp,DEVELOPMENT_BACKEND_ENDPOINT_PATTERN:()=>xl,DEVELOPMENT_BACKEND_FEATURE:()=>Ll,DEVELOPMENT_BACKEND_INVOCATION_FEATURE:()=>Fl,DEVELOPMENT_BACKEND_INVOCATION_MAX_REQUEST_BYTES:()=>Dp,DEVELOPMENT_BACKEND_INVOCATION_MAX_RESPONSE_BYTES:()=>kp,DEVELOPMENT_BACKEND_INVOCATION_SCHEMA:()=>qs,DEVELOPMENT_BACKEND_MAX_INFLIGHT:()=>Pp,DEVELOPMENT_BACKEND_MAX_REQUEST_BYTES:()=>vp,DEVELOPMENT_BACKEND_MAX_RESPONSE_BYTES:()=>$p,DEVELOPMENT_BACKEND_SCHEMA:()=>Vl,DEVELOPMENT_CONFIGURATION_ENDPOINT:()=>kl,DEVELOPMENT_CONFIGURATION_FEATURE:()=>Dl,DEVELOPMENT_CONFIGURATION_MANIFEST_SCHEMA:()=>ki,DEVELOPMENT_CONFIGURATION_SCHEMA:()=>Ks,DateEventProjectionV2Error:()=>Lt,DevelopmentConfigurationContractError:()=>Xn,ManagedConcurrencyContractError:()=>st,NATIVE_ARTIFACT_CAPACITY_V2:()=>Ae,NATIVE_CONFIGURATION_VALIDATOR_DIGEST:()=>Kl,NATIVE_CONTRACT_CAPACITY_V2:()=>B,NATIVE_DATA_POLICY_EXPRESSION_MAX_CLAUSES:()=>Af,NATIVE_DATA_POLICY_EXPRESSION_MAX_DEPTH:()=>mf,NATIVE_DATA_POLICY_EXPRESSION_MAX_GROUP_ITEMS:()=>_f,NATIVE_DATA_POLICY_EXPRESSION_MAX_LEAVES:()=>gf,NATIVE_DATA_POLICY_EXPRESSION_MAX_OCCURRENCES:()=>Ef,NATIVE_DATA_QUERY_OPERATORS_V2:()=>Hi,NATIVE_ROLE_MEMBERSHIP_BATCH_MAX_BYTES:()=>mp,NATIVE_ROLE_MEMBERSHIP_BATCH_MAX_ITEMS:()=>pp,NATIVE_UNIQUE_KEY_MAX_BYTES:()=>Du,NATIVE_UNIQUE_KEY_NORMALIZERS:()=>vo,NativeConfigurationCompilerError:()=>Wn,NativeDataFieldContractV2Error:()=>ye,NativeDataPolicyExpressionV2Error:()=>_t,NativeDecimalLifecycleContractError:()=>Ke,NativeEventActionContractError:()=>Tn,NativeRoleMembershipBatchInputError:()=>Jn,NativeScopeSourceFieldPathV2Error:()=>yn,NativeUniqueKeyContractError:()=>ct,OPENXIANGDA_NATIVE_DATA_FIELD_TYPES_V2:()=>Ki,OPENXIANGDA_NATIVE_DATA_SURFACE_KEYS_V2:()=>Se,OPENXIANGDA_NATIVE_DRAFT_STATE_KEYS_V2:()=>fn,OPENXIANGDA_NATIVE_SYSTEM_FIELDS_V2:()=>an,OPENXIANGDA_NATIVE_SYSTEM_FIELD_MAP_V2:()=>Ot,USER_CANDIDATE_MAX_SELECTIONS:()=>Hl,USER_CANDIDATE_SCOPE_FIELD_TYPES:()=>Li,UserCandidateContractError:()=>Le,WORKFLOW_APPROVAL_EMPTY_PROVIDERS:()=>Ho,WORKFLOW_APPROVED_DELEGATION_MAX_BYTES:()=>ef,WORKFLOW_APPROVED_DELEGATION_MAX_REQUESTS:()=>Qu,WORKFLOW_AUTOMATIC_CC_MAX_RECIPIENTS:()=>Gu,WORKFLOW_AUTOMATIC_CC_PROVIDERS:()=>Dr,WORKFLOW_BUSINESS_STEP_EVENT:()=>lt,WORKFLOW_BUSINESS_STEP_EVENTS:()=>Uo,WORKFLOW_BUSINESS_STEP_FACTS_KEY:()=>bd,WORKFLOW_BUSINESS_STEP_MAX_BYTES:()=>Rn,WORKFLOW_BUSINESS_STEP_MAX_RECEIPT_BYTES:()=>yr,WORKFLOW_CONFIGURABLE_OPERATIONS:()=>Sn,WORKFLOW_CONFIGURABLE_PROVIDERS:()=>Dn,WORKFLOW_EVENT_TYPES_V2:()=>jn,WORKFLOW_LAUNCH_PREFLIGHT_PROVIDERS:()=>Pr,WORKFLOW_REJECTION_NOTIFICATION_MAX_BYTES:()=>Hu,WORKFLOW_REJECTION_NOTIFICATION_SCHEMA:()=>$r,WORKFLOW_ROLE_UNION_MAX_ROLES:()=>Wu,WORKFLOW_ROUTING_MAX_BYTES:()=>cf,WORKFLOW_ROUTING_MAX_MATCHED_RULES:()=>df,WORKFLOW_ROUTING_MAX_RULES:()=>af,WORKFLOW_STEP_DATA_COMMAND_SCHEMA:()=>gl,WORKFLOW_STEP_DATA_RESOLUTION_SCHEMA:()=>ks,WORKFLOW_TASK_PAGE_DEFINITION_MAX_BYTES:()=>jr,WORKFLOW_TASK_PAGE_MAX_BYTES:()=>Ln,WORKFLOW_TASK_PAGE_MAX_FIELDS:()=>xr,WORKFLOW_TASK_SUBTABLE_MAX_ROWS:()=>ai,WORKFLOW_TASK_SUBTABLE_MAX_TOTAL_ROWS:()=>ri,WorkflowTaskPageError:()=>Oe,applyWorkflowTaskPageValues:()=>Mr,applyWorkflowTaskSubtableRows:()=>Bd,assertDevelopmentConfigurationManifest:()=>Gs,assertDevelopmentConfigurationResult:()=>Pl,assertNativeRoleMembershipBatchInput:()=>El,assertWorkflowNativeStageGuard:()=>md,assertWorkflowNativeStagePolicy:()=>Do,assertWorkflowNativeStageSourceGuard:()=>_d,assertWorkflowOwnedSubjectCreate:()=>Bt,assertWorkflowOwnedSubjectCreateResources:()=>fi,canonicalDataBusinessIntent:()=>Tl,compileNativeApplicationConfiguration:()=>Tc,compileNativeEventAction:()=>Vo,compileNativeEventCapturePlansV2:()=>Es,compileRequiredPlatformCapabilitiesV3:()=>As,compileWorkflowBusinessStepHandlers:()=>Cn,createDevelopmentConfigurationManifest:()=>$l,dataOwnedRowLimit:()=>bt,dateEventProjectionEnvelopeSchemaV2:()=>Ud,dateEventProjectionFieldsV2:()=>ii,developmentBackendBase64Bytes:()=>zs,developmentBackendInvocationHeadersValid:()=>Hs,developmentBackendInvocationRequestValid:()=>Bl,developmentBackendInvocationRevision:()=>Wl,developmentBackendOperationMatches:()=>Js,developmentConfigurationKey:()=>vl,evaluateWorkflowTaskPageExpression:()=>$e,formatWorkflowCompletionDeadline:()=>vd,formatWorkflowExpression:()=>vt,generatedCrudCapabilityOperations:()=>gi,hasDataAuditReadPolicy:()=>uo,isDataAuditMetadataField:()=>nt,isDataOwnedRowLimit:()=>tt,isDataSystemSortField:()=>fo,isDataTransactionActorAuthorityGuard:()=>Cl,isDataTransactionRecordSetMatchGuard:()=>Sl,isNativeDataQueryOperatorV2:()=>Ea,isNativeMultiValueFieldV2:()=>Nt,isWorkflowRejectionNotificationSnapshot:()=>Pd,matchesDataActorAuthorityMembership:()=>hl,materializeNativeDataQueryPathTypesV2:()=>ud,nativeDataPolicyExpressionLeavesV2:()=>Gt,nativeDataPolicyExpressionToCnfV2:()=>_i,nativeDataQueryPathPlanV2:()=>fd,nativeFieldAggregatePlanV2:()=>Ca,nativeFieldColumnDefinitionV2:()=>Ua,nativeFieldDefaultSqlV2:()=>Ma,nativeFieldHasDefaultV2:()=>Ka,nativeFieldIndexStatementsV2:()=>Ja,nativeFieldRequiresCreateInputV2:()=>Tt,nativeFieldSequenceGrantStatementsV2:()=>za,nativeFieldSequenceOwnershipStatementsV2:()=>qa,nativeFieldSequenceStatementsV2:()=>Ga,nativeFieldSupportsFilterV2:()=>Ao,nativeFieldSupportsOperatorV2:()=>Na,nativeFieldSupportsSearchV2:()=>ln,nativeFieldSupportsSortV2:()=>it,nativeOperatorsForFieldV2:()=>go,nativePhysicalFieldV2:()=>rr,nativePhysicalFieldsV2:()=>Wa,nativePhysicalObjectNameV2:()=>ke,nativeScopeSourceFieldValueV2:()=>td,nativeScopeSourceGrantPathSupportedV2:()=>wo,nativeScopeSourceSubjectPathSupportedV2:()=>bn,nativeSubtableConstraintStatementsV2:()=>Ha,nativeUniqueKeysContractVersion:()=>Lo,nativeUniqueKeysJsonSchema:()=>Ad,normalizeWorkflowOwnedSubjectCreate:()=>ec,parseDataBusinessCommandResolution:()=>Rl,parseDataFieldUserCandidates:()=>yt,parseDecimalReservationLifecycle:()=>An,parseNativeDataFieldsV2:()=>dn,parseNativeDataResourceInvariantsV2:()=>lo,parseNativeUniqueKeys:()=>Po,parseWorkflowStepDataResolution:()=>Al,projectDataResourceView:()=>Bs,projectNativeDataResourceViewV2:()=>mn,projectWorkflowGraph:()=>Cd,projectWorkflowNodePolicy:()=>Jo,quoteNativeIdentifierV2:()=>se,refreshWorkflowTaskPageFacts:()=>Kd,requiresAggregateOwnedSubtableCapacity:()=>en,requiresDateTimeMinutePrecision:()=>rn,requiresDevelopmentBackendCredential:()=>jl,requiresExtendedArtifactCapacity:()=>qt,requiresExtendedDeclarationCapacity:()=>Fn,requiresExtendedOwnedSubtableCapacity:()=>tn,requiresOwnedSubtableMinimumRows:()=>sn,requiresUserCandidateLaunchScope:()=>Zt,requiresWorkflowRoleUnion:()=>zo,resolveNativeScopeSourceFieldPathV2:()=>at,resolveWorkflowUserCandidates:()=>xi,selectWorkflowAssignmentRoutingRules:()=>Zd,serializedDataBytes:()=>sa,userCandidateScopeValue:()=>ra,validateAuthenticatedPublicRead:()=>ko,validateDecimalReservationLifecycles:()=>Co,validateManagedConcurrency:()=>Oo,validateNativeDataDraftStateV2:()=>Io,validateNativeDataResourceReferencesV2:()=>co,validateNativeDataResourceSurfaceV2:()=>pn,validateUserCandidateReferences:()=>oo,validateWorkflowAdministration:()=>kn,validateWorkflowApprovalEmptyPolicy:()=>vn,validateWorkflowApprovedDelegation:()=>ni,validateWorkflowAssignmentRoutingBindings:()=>li,validateWorkflowAssignmentRoutingPolicy:()=>Mt,validateWorkflowAssignmentRoutingRules:()=>Yd,validateWorkflowAutomaticCc:()=>$n,validateWorkflowBusinessStepHandlerContract:()=>Nd,validateWorkflowBusinessStepRequest:()=>Od,validateWorkflowBusinessStepResult:()=>Nr,validateWorkflowBusinessStepSchema:()=>Dt,validateWorkflowBusinessStepSubscriptions:()=>Bo,validateWorkflowBusinessSteps:()=>$t,validateWorkflowCommandHandlers:()=>ei,validateWorkflowCompletionDeadlines:()=>Xo,validateWorkflowCorrections:()=>oi,validateWorkflowInitiatorApprovalPolicy:()=>ft,validateWorkflowInstanceCommandPolicies:()=>xo,validateWorkflowLaunchPreflight:()=>Pn,validateWorkflowNodeConfigurationPatch:()=>kd,validateWorkflowReadability:()=>qo,validateWorkflowRejectionNotification:()=>Qo,validateWorkflowRoleUnion:()=>Pt,validateWorkflowTaskPages:()=>jt,validateWorkflowUserCandidateBindings:()=>io,workflowApprovalCanSkip:()=>$d,workflowApprovedDelegationRequests:()=>xd,workflowAssignmentRoutingFacts:()=>Xd,workflowAssignmentRoutingPolicySchema:()=>Hd,workflowAssignmentRoutingSemantic:()=>qr,workflowBindingAllowsEmptyUsers:()=>Yo,workflowBindingRoleCodes:()=>Sd,workflowBusinessCommandInvocationSchema:()=>Ld,workflowBusinessStepFactSchema:()=>kt,workflowBusinessStepHandlerDigest:()=>Ol,workflowBusinessStepInput:()=>Td,workflowBusinessStepPath:()=>Tr,workflowBusinessStepReceiptSignatureSuffix:()=>bl,workflowBusinessStepValueMatches:()=>St,workflowDelegationMutationRequestSchema:()=>Ws,workflowExpressionPaths:()=>Go,workflowInitiatorApprovalCanComplete:()=>hd,workflowInstanceCommandDeadlineError:()=>yd,workflowInstanceTerminateCapabilityAllowed:()=>Ed,workflowInstanceWithdrawalReasonRequired:()=>Id,workflowNativeStagePolicySchema:()=>gd,workflowNodeAllowedOperations:()=>pt,workflowOperationCommentRequired:()=>hr,workflowOperationReasonRequired:()=>wr,workflowOwnedSubjectCreateSchema:()=>Qd,workflowPolicyTimestamp:()=>Fo,workflowRoleCodesSchema:()=>wd,workflowTaskPageFieldState:()=>di,workflowTaskPageReplayCoversInvalidation:()=>Gd,workflowTaskSubtableRows:()=>Md});module.exports=oa(Gl);var vi=require("node:crypto");function ia(e){if(!e||typeof e!="object")return!1;let t=Object.getPrototypeOf(e);return t===Object.prototype||t===null}function eo(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)=>eo(n,`${t}[${i}]`)).join(",")}]`;if(ia(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)}:${eo(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 eo(e,"$")}function Z(e){return(0,vi.createHash)("sha256").update(Q(e)).digest("hex")}var Hl=200,Li=["text.short","uuid","option.single","resource-ref.single"],to=/^[a-z][a-z0-9]*(?:[-_.][a-z0-9]+)*$/,Vi=/^[A-Za-z][A-Za-z0-9_]{0,62}$/,Fi=new Set(["__proto__","prototype","constructor"]),no=e=>!!e&&typeof e=="object"&&!Array.isArray(e)&&[Object.prototype,null].includes(Object.getPrototypeOf(e)),Pi=(e,t)=>Object.keys(e).every(o=>t.includes(o)),et=(e,t)=>typeof e=="string"&&e.length>0&&e.trim()===e&&e.length<=t,Le=class extends Error{constructor(o,n){super(`${o}: ${n}`);this.code=o;this.pointer=n}code;pointer};function te(e,t){throw new Le(e,t)}function yt(e,t,o){if(e===void 0)return;["user.single","user.multiple"].includes(t)||te("DATA_USER_CANDIDATES_FIELD_TYPE_INVALID",o),(!no(e)||!Pi(e,["kind","roleCode","scope","pageSize"])||e.kind!=="app-role"||!et(e.roleCode,128)||!to.test(String(e.roleCode)))&&te("DATA_USER_CANDIDATES_SOURCE_INVALID",o),e.pageSize!==void 0&&(!Number.isSafeInteger(e.pageSize)||Number(e.pageSize)<1||Number(e.pageSize)>50)&&te("DATA_USER_CANDIDATES_PAGE_SIZE_INVALID",`${o}/pageSize`);let n;if(e.scope!==void 0){let i=e.scope;(!no(i)||!Pi(i,["dimensionCode","operation","field","value","creation"])||!et(i.dimensionCode,128)||!to.test(String(i.dimensionCode))||!et(i.operation,64)||!to.test(String(i.operation))||Object.hasOwn(i,"field")===Object.hasOwn(i,"value"))&&te("DATA_USER_CANDIDATES_SCOPE_INVALID",`${o}/scope`),i.creation!==void 0&&(i.creation!=="prospective"||!Object.hasOwn(i,"field"))&&te("DATA_USER_CANDIDATES_SCOPE_INVALID",`${o}/scope/creation`),Object.hasOwn(i,"field")?((!et(i.field,63)||!Vi.test(String(i.field))||Fi.has(String(i.field)))&&te("DATA_USER_CANDIDATES_SCOPE_FIELD_INVALID",`${o}/scope/field`),n={dimensionCode:String(i.dimensionCode),operation:String(i.operation),field:String(i.field),...i.creation==="prospective"?{creation:"prospective"}:{}}):(et(i.value,255)||te("DATA_USER_CANDIDATES_SCOPE_VALUE_INVALID",`${o}/scope/value`),n={dimensionCode:String(i.dimensionCode),operation:String(i.operation),value:String(i.value)})}return{kind:"app-role",roleCode:String(e.roleCode),...n?{scope:n}:{},...e.pageSize===void 0?{}:{pageSize:Number(e.pageSize)}}}function Zt(e){return e.some(t=>t.schema.fields.some(o=>{let n=o.userCandidates?.scope;return n?.creation==="prospective"||!!(n?.field&&t.schema.fields.find(i=>i.code===n.field)?.type==="resource-ref.single")}))}function oo(e,t,o,n){for(let[i,r]of e.entries()){let d=`${n}/${i}/userCandidates`,s=yt(r.userCandidates,r.type,d);if(s&&(t.has(s.roleCode)||te("DATA_USER_CANDIDATES_ROLE_UNDECLARED",`${d}/roleCode`),s.scope&&!o.has(s.scope.dimensionCode)&&te("DATA_USER_CANDIDATES_DIMENSION_UNDECLARED",`${d}/scope/dimensionCode`),s.scope?.field)){let a=e.find(c=>c.code===s.scope.field);(!a||!Li.some(c=>c===a.type))&&te("DATA_USER_CANDIDATES_SCOPE_FIELD_INVALID",`${d}/scope/field`)}}}function xi(e,t,o,n){let i=e.subject.factProjection,r=typeof t.inputPath=="string"&&Object.entries(i).some(([c,f])=>(t.inputPath===c||t.inputPath.startsWith(`${c}.`))&&o.get(f)?.userCandidates!==void 0);if(t.candidateField===void 0&&!r)return;(t.provider!=="form_field_users"||!t.candidateField||!Vi.test(t.candidateField)||Fi.has(t.candidateField)||!t.inputPath||i[t.inputPath]!==t.candidateField)&&te("WORKFLOW_USER_CANDIDATES_FIELD_BINDING_REQUIRED",n),(t.roleCode!==void 0||t.scope!==void 0||t.routing!==void 0)&&te("WORKFLOW_USER_CANDIDATES_SOURCE_OVERRIDE_FORBIDDEN",n);let d=o.get(t.candidateField),s=d&&yt(d.userCandidates,d.type,`${n}/candidateField`);s||te("WORKFLOW_USER_CANDIDATES_FIELD_UNDECLARED",`${n}/candidateField`);let a;if(s.scope?.field){let c=Object.entries(i).filter(([,f])=>f===s.scope.field).map(([f])=>f);c.length!==1&&te("WORKFLOW_USER_CANDIDATES_SCOPE_PROJECTION_REQUIRED",n),a=c[0]}return{fieldCode:d.code,inputPath:t.inputPath,source:s,...a?{scopeInputPath:a}:{}}}function io(e,t,o,n,i=new Map){for(let[r,d]of Object.entries(t.bindings))xi(e,d,o,`${n}/${r}`);for(let[r,d]of Object.entries(e.taskPages||{})){let s=new Set(d.fields.filter(a=>a.readonly!==!0).map(a=>a.code));for(let a of d.fields){let c=o.get(a.code)?.userCandidates?.scope;if(s.has(a.code)&&c?.field&&s.has(c.field)&&te("WORKFLOW_USER_CANDIDATES_SCOPE_WRITE_FORBIDDEN",`${n}/taskPages/${r}/${a.code}`),!s.has(a.code)||!a.subtable)continue;let f=o.get(a.code)?.subtable?.resourceCode,u=f?i.get(f):void 0;a.subtable.fields.some(p=>p.readonly!==!0&&u?.get(p.code)?.userCandidates)&&te("WORKFLOW_USER_CANDIDATES_OWNED_FIELD_UNSUPPORTED",`${n}/taskPages/${r}/${a.code}`)}}}function ra(e,t){if(!e.scope)return;let o=e.scope.field?t[e.scope.field]:e.scope.value,n=no(o)?o.value:o;return et(n,255)||te("DATA_USER_CANDIDATES_SCOPE_VALUE_REQUIRED",e.scope.field||"scope"),String(n)}var Me=500,Xl=500,Qt=1e3,ji=2016,Zl=2097152,Ql=2097152;function tt(e){return typeof e=="number"&&Number.isSafeInteger(e)&&e>=1&&e<=1e3}function bt(e){if(e.ownedRowLimit===void 0)return 500;if(!tt(e.ownedRowLimit))throw new Error("NATIVE_DATA_OWNED_ROW_LIMIT_INVALID");return e.ownedRowLimit}function en(e){return e.some(t=>(t.schema.ownedRowLimit??500)>500)}function tn(e){return e.some(t=>{let o=t.schema.fields.filter(n=>n.type==="subtable").map(n=>n.subtable?.maxRows??20);return o.some(n=>n>100)||o.reduce((n,i)=>n+i,0)>400})}function sa(e){try{return new TextEncoder().encode(JSON.stringify(e)).byteLength}catch{return 1/0}}var Bi=/^[A-Za-z][A-Za-z0-9_]{0,62}$/,ao=/^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/,Ki=["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"];function rn(e){return e.some(t=>t.schema.fields.some(o=>(o.type==="datetime"||o.type==="datetime-range")&&o.timePrecision==="minute"))}function sn(e){return e.some(t=>t.schema.fields.some(o=>o.type==="subtable"&&(o.subtable?.minRows??0)>0))}var aa=new Set(Ki),Gi=new Set(["option.multiple","cascade.multiple","user.multiple","department.multiple","resource-ref.multiple","file","image","subtable"]),Wi=new Set(["option.single","option.multiple","cascade.single","cascade.multiple"]),Ui=new Set(["resource-ref.single","resource-ref.multiple"]),an=[{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}],Ot=new Map(an.map(e=>[e.code,e])),ye=class extends Error{constructor(o,n){super(o);this.code=o;this.pointer=n;this.name="NativeDataFieldContractV2Error"}code;pointer};function Nt(e){return Gi.has(e)}function Tt(e,t={}){return e.type!=="serial-number"&&t.system!==!0&&e.nullable===!1&&(!Nt(e.type)||t.requiredHint===!0)}function dn(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 d=`${t}/${r}`,s=ge(i,d);Ie(s,["code","type","nullable","indexed","options","source","userCandidates","maxLength","precision","scale","exactDecimal","min","max","rangeBoundary","timePrecision","file","serial","subtable"],d);let a=be(s.code,`${d}/code`,63);Bi.test(a)||D("NATIVE_FIELD_CODE_INVALID",`${d}/code`),n.has(a)&&D("NATIVE_DATA_FIELD_DUPLICATE",`${d}/code`),n.add(a);let c=be(s.type,`${d}/type`,32);aa.has(c)||D("NATIVE_DATA_FIELD_TYPE_INVALID",`${d}/type`);let f=c,u=so(s.nullable,`${d}/nullable`),p=so(s.indexed,`${d}/indexed`);u===!0&&Gi.has(f)&&D("NATIVE_DATA_MULTI_FIELD_NULLABLE_INVALID",`${d}/nullable`);let _=la(s.options,f,d),E=ua(s.source,f,d),A=yt(s.userCandidates,f,`${d}/userCandidates`),O=pa(s,f,d),b=so(s.exactDecimal,`${d}/exactDecimal`);b!==void 0&&f!=="number.decimal"&&D("NATIVE_DATA_FIELD_EXACT_DECIMAL_TYPE_INVALID",`${d}/exactDecimal`);let g=da(s.rangeBoundary,f,d),I=ma(s.file,f,d),T=_a(s.serial,f,d),l=ga(s.subtable,f,d);return{code:a,type:f,...u===void 0?{}:{nullable:u},...p===void 0?{}:{indexed:p},..._?{options:_}:{},...E?{source:E}:{},...A?{userCandidates:A}:{},...O,...b===void 0?{}:{exactDecimal:b},...g?{rangeBoundary:g}:{},...I?{file:I}:{},...T?{serial:T}:{},...l?{subtable:l}:{}}})}function da(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 co(e,t){Array.isArray(e)||D("NATIVE_ARRAY_REQUIRED",t);let o=new Map;e.forEach((n,i)=>{let r=`${t}/${i}`,d=ge(n,r),s=be(d.code,`${r}/code`,64);(!ao.test(s)||o.has(s))&&D("NATIVE_RESOURCE_CODE_INVALID",`${r}/code`);let a=ge(d.schema,`${r}/schema`);a.ownedRowLimit!==void 0&&!tt(a.ownedRowLimit)&&D("NATIVE_DATA_OWNED_ROW_LIMIT_INVALID",`${r}/schema/ownedRowLimit`),o.set(s,{pointer:r,ownedRowLimit:bt(a),fields:dn(a.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,a)=>s+(a.subtable?.maxRows??20),0)>i.ownedRowLimit&&D("NATIVE_DATA_FIELD_SUBTABLE_AGGREGATE_MAX_ROWS_EXCEEDED",`${i.pointer}/schema/fields`),i.fields.forEach((s,a)=>{let c=`${i.pointer}/schema/fields/${a}`;if(s.source&&ca(s.source,r,o,`${c}/source`),s.subtable){let f=o.get(s.subtable.resourceCode);(!f||s.subtable.resourceCode===n)&&D("NATIVE_DATA_FIELD_SUBTABLE_TARGET_MISSING",`${c}/subtable/resourceCode`);let u=f.fields.find(_=>_.code===s.subtable?.foreignKey);(!u||u.type!=="uuid"||u.nullable!==!1)&&D("NATIVE_DATA_FIELD_SUBTABLE_FOREIGN_KEY_INVALID",`${c}/subtable/foreignKey`);let p=f.fields.find(_=>_.code===s.subtable?.orderField);(!p||p.type!=="number.integer"||p.nullable!==!1)&&D("NATIVE_DATA_FIELD_SUBTABLE_ORDER_FIELD_INVALID",`${c}/subtable/orderField`)}})}}function lo(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,d)=>{let s=`${o}/${d}`,a=ge(r,s);Ie(a,["code","message","expression"],s);let c=be(a.code,`${s}/code`,128);(!/^[a-z][a-z0-9]*(?:[._-][a-z0-9]+)*$/.test(c)||i.has(c))&&D("NATIVE_DATA_RESOURCE_INVARIANT_CODE_INVALID",`${s}/code`),i.add(c);let f=on(a.message,`${s}/message`,500);f!==void 0&&f.length===0&&D("NATIVE_DATA_RESOURCE_INVARIANT_MESSAGE_INVALID",`${s}/message`);let u=ge(a.expression,`${s}/expression`);if(u.kind==="nonBlankTextWhenOption"){Ie(u,["kind","optionField","optionValue","textField"],`${s}/expression`);let g=Re(u.optionField,`${s}/expression/optionField`),I=Re(u.textField,`${s}/expression/textField`),T=be(u.optionValue,`${s}/expression/optionValue`,128),l=n.get(g),y=n.get(I);return(!l||!y)&&D("NATIVE_DATA_RESOURCE_INVARIANT_FIELD_UNKNOWN",`${s}/expression`),(l.type!=="option.single"||!["text.short","text.long"].includes(y.type)||!l.options?.some(R=>R.value===T))&&D("NATIVE_DATA_RESOURCE_INVARIANT_FIELD_TYPES_INVALID",`${s}/expression`),{code:c,...f===void 0?{}:{message:f},expression:{kind:"nonBlankTextWhenOption",optionField:g,optionValue:T,textField:I}}}Ie(u,["leftField","operator","rightField"],`${s}/expression`);let p=Re(u.leftField,`${s}/expression/leftField`),_=Re(u.rightField,`${s}/expression/rightField`),E=n.get(p),A=n.get(_);(!E||!A)&&D("NATIVE_DATA_RESOURCE_INVARIANT_FIELD_UNKNOWN",`${s}/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",`${s}/expression`);let b=String(u.operator);return["eq","neq","gt","gte","lt","lte"].includes(b)||D("NATIVE_DATA_RESOURCE_INVARIANT_OPERATOR_INVALID",`${s}/expression/operator`),!["eq","neq"].includes(b)&&!["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",`${s}/expression`),{code:c,...f===void 0?{}:{message:f},expression:{leftField:p,operator:b,rightField:_}}})}function ca(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])),d=r.get(e.labelField);(!d||!["text.short","text.long"].includes(d.type))&&D("NATIVE_DATA_FIELD_SOURCE_LABEL_INVALID",`${n}/labelField`);for(let s of["searchFields","descriptionFields","snapshotFields"])for(let a of e[s]||[])r.has(a)||D("NATIVE_DATA_FIELD_SOURCE_FIELD_MISSING",`${n}/${s}`);for(let[s,a]of(e.filters||[]).entries())r.has(a.field)||D("NATIVE_DATA_FIELD_SOURCE_FILTER_FIELD_MISSING",`${n}/filters/${s}/field`),"binding"in a&&!t.has(a.binding.field)&&D("NATIVE_DATA_FIELD_SOURCE_BINDING_FIELD_MISSING",`${n}/filters/${s}/binding/field`)}function la(e,t,o){let n=`${o}/options`;if(e===void 0){Wi.has(t)&&D("NATIVE_DATA_FIELD_OPTIONS_REQUIRED",n);return}(!Wi.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=(d,s,a)=>{a>5&&D("NATIVE_DATA_FIELD_OPTIONS_DEPTH_EXCEEDED",s);let c=new Set;return d.map((f,u)=>{i+=1,i>1e3&&D("NATIVE_DATA_FIELD_OPTIONS_COUNT_EXCEEDED",n);let p=`${s}/${u}`,_=ge(f,p);Ie(_,["label","value","description","color","children"],p);let E=be(_.label,`${p}/label`,500),A=be(_.value,`${p}/value`,500);c.has(A)&&D("NATIVE_DATA_FIELD_OPTION_VALUE_DUPLICATE",`${p}/value`),c.add(A);let O=on(_.description,`${p}/description`,2e3),b=on(_.color,`${p}/color`,64),g;return _.children!==void 0&&((!t.startsWith("cascade.")||!Array.isArray(_.children))&&D("NATIVE_DATA_FIELD_OPTION_CHILDREN_INVALID",`${p}/children`),(_.children.length<1||_.children.length>100)&&D("NATIVE_DATA_FIELD_OPTION_CHILDREN_INVALID",`${p}/children`),g=r(_.children,`${p}/children`,a+1)),{label:E,value:A,...O===void 0?{}:{description:O},...b===void 0?{}:{color:b},...g?{children:g}:{}}})};return r(e,n,1)}function ua(e,t,o){let n=`${o}/source`;if(e===void 0){Ui.has(t)&&D("NATIVE_DATA_FIELD_SOURCE_REQUIRED",n);return}Ui.has(t)||D("NATIVE_DATA_FIELD_SOURCE_TYPE_INVALID",n);let i=ge(e,n);Ie(i,["kind","resourceCode","labelField","searchFields","descriptionFields","snapshotFields","filters","pageSize","loadMode","clearOnBindingChange"],n),i.kind!=="resource"&&D("NATIVE_DATA_FIELD_SOURCE_KIND_INVALID",`${n}/kind`);let r=be(i.resourceCode,`${n}/resourceCode`,64);ao.test(r)||D("NATIVE_RESOURCE_CODE_INVALID",`${n}/resourceCode`);let d=Re(i.labelField,`${n}/labelField`),s=ro(i.searchFields,`${n}/searchFields`,10),a=ro(i.descriptionFields,`${n}/descriptionFields`,10),c=ro(i.snapshotFields,`${n}/snapshotFields`,50),f=Be(i.pageSize,`${n}/pageSize`,1,100),u;i.loadMode!==void 0&&(["search","all"].includes(String(i.loadMode))||D("NATIVE_DATA_FIELD_SOURCE_LOAD_MODE_INVALID",`${n}/loadMode`),u=i.loadMode);let p=fa(i.filters,`${n}/filters`);return i.clearOnBindingChange!==void 0&&typeof i.clearOnBindingChange!="boolean"&&D("NATIVE_DATA_FIELD_SOURCE_BINDING_RESET_INVALID",`${n}/clearOnBindingChange`),{kind:"resource",resourceCode:r,labelField:d,...s?{searchFields:s}:{},...a?{descriptionFields:a}:{},...c?{snapshotFields:c}:{},...p?{filters:p}:{},...f===void 0?{}:{pageSize:f},...u?{loadMode:u}:{},...i.clearOnBindingChange===void 0?{}:{clearOnBindingChange:i.clearOnBindingChange}}}function fa(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=ge(o,i),d=Object.prototype.hasOwnProperty.call(r,"value"),s=Object.prototype.hasOwnProperty.call(r,"binding");Ie(r,d?["field","operator","value"]:["field","operator","binding"],i),d===s&&D("NATIVE_DATA_FIELD_SOURCE_FILTER_VALUE_INVALID",i);let a=Re(r.field,`${i}/field`);["eq","in"].includes(String(r.operator))||D("NATIVE_DATA_FIELD_SOURCE_FILTER_OPERATOR_INVALID",`${i}/operator`);let c=r.operator;if(d)return{field:a,operator:c,value:r.value};let f=ge(r.binding,`${i}/binding`);return Ie(f,["kind","field"],`${i}/binding`),f.kind!=="field"&&D("NATIVE_DATA_FIELD_SOURCE_BINDING_KIND_INVALID",`${i}/binding/kind`),{field:a,operator:c,binding:{kind:"field",field:Re(f.field,`${i}/binding/field`)}}})}function pa(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=nn(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=nn(e.precision,`${o}/precision`,1,1e3),n.scale=e.scale===void 0?0:nn(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=Mi(e.min,`${o}/min`),r=Mi(e.max,`${o}/max`);t==="number.integer"&&[i,r].some(d=>d!==void 0&&!Number.isSafeInteger(d))&&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&&((!["time","datetime","datetime-range"].includes(t)||!["minute","second"].includes(e.timePrecision))&&D("NATIVE_DATA_FIELD_TIME_PRECISION_INVALID",`${o}/timePrecision`),n.timePrecision=e.timePrecision),n}function ma(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=ge(e,n);Ie(i,["maxCount","maxSizeMb","accept"],n);let r=Be(i.maxCount,`${n}/maxCount`,1,100);t==="signature"&&r!==void 0&&r!==1&&D("NATIVE_DATA_FIELD_SIGNATURE_COUNT_INVALID",`${n}/maxCount`);let d=Be(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((a,c)=>be(a,`${n}/accept/${c}`,255)),new Set(s).size!==s.length&&D("NATIVE_DATA_FIELD_FILE_ACCEPT_INVALID",`${n}/accept`)),{...r===void 0?{}:{maxCount:r},...d===void 0?{}:{maxSizeMb:d},...s===void 0?{}:{accept:s}}}function _a(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=ge(e,n);Ie(i,["prefix","digits","start"],n);let r=on(i.prefix,`${n}/prefix`,64),d=Be(i.digits,`${n}/digits`,1,32),s=Be(i.start,`${n}/start`,0,Number.MAX_SAFE_INTEGER);return{...r===void 0?{}:{prefix:r},...d===void 0?{}:{digits:d},...s===void 0?{}:{start:s}}}function ga(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=ge(e,n);Ie(i,["resourceCode","foreignKey","orderField","minRows","maxRows"],n);let r=be(i.resourceCode,`${n}/resourceCode`,64);ao.test(r)||D("NATIVE_RESOURCE_CODE_INVALID",`${n}/resourceCode`);let d=Re(i.foreignKey,`${n}/foreignKey`),s=Re(i.orderField,`${n}/orderField`);s===d&&D("NATIVE_DATA_FIELD_SUBTABLE_ORDER_FIELD_INVALID",`${n}/orderField`);let a=Be(i.maxRows,`${n}/maxRows`,1,500),c=Be(i.minRows,`${n}/minRows`,0,500);return(c??0)>(a??20)&&D("NATIVE_DATA_FIELD_SUBTABLE_MIN_ROWS_INVALID",`${n}/minRows`),{resourceCode:r,foreignKey:d,orderField:s,...c===void 0?{}:{minRows:c},...a===void 0?{}:{maxRows:a}}}function ro(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)=>Re(i,`${t}/${r}`));return new Set(n).size!==n.length&&D("NATIVE_DATA_FIELD_SOURCE_FIELDS_INVALID",t),n}function Re(e,t){let o=be(e,t,63);return Bi.test(o)||D("NATIVE_FIELD_CODE_INVALID",t),o}function ge(e,t){return(!e||typeof e!="object"||Array.isArray(e))&&D("NATIVE_OBJECT_REQUIRED",t),e}function Ie(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 be(e,t,o){return(typeof e!="string"||e.length===0||e.length>o)&&D("NATIVE_STRING_INVALID",t),e}function on(e,t,o){if(e!==void 0)return(typeof e!="string"||e.length>o)&&D("NATIVE_STRING_INVALID",t),e}function so(e,t){if(e!==void 0)return typeof e!="boolean"&&D("NATIVE_BOOLEAN_REQUIRED",t),e}function Be(e,t,o,n){if(e!==void 0)return nn(e,t,o,n)}function Mi(e,t){if(e!==void 0)return(typeof e!="number"||!Number.isFinite(e))&&D("NATIVE_NUMBER_REQUIRED",t),e}function nn(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 ye(e,t)}var Rt=["created_by","updated_by","created_at","updated_at"];function nt(e){return Rt.includes(e)}function uo(e){return Rt.some(t=>Object.prototype.hasOwnProperty.call(e.fieldPolicies||{},t))}var qi=an.map(e=>e.code);function fo(e){return qi.includes(e)}var Hi=["eq","neq","gt","gte","lt","lte","contains","startsWith","endsWith","in","between","has","hasAny","hasAll","overlaps","containedBy","jsonContains","isEmpty","isNotEmpty"],Aa=new Set(Hi);function Ea(e){return Aa.has(String(e))}var po=["eq","neq","contains","startsWith","endsWith","in","isEmpty","isNotEmpty"],Ct=["eq","neq","gt","gte","lt","lte","between","in","isEmpty"],Ia=["eq","neq","in","isEmpty"],cn=["eq","neq","in","isEmpty","isNotEmpty"],ot=["has","hasAny","hasAll","isEmpty","isNotEmpty"],zi=["overlaps","contains","containedBy","isEmpty"],mo=["jsonContains","isEmpty","isNotEmpty"],_o=["isEmpty","isNotEmpty"],ya={"text.short":po,"text.long":po,"text.rich":po,"number.integer":Ct,"number.decimal":Ct,boolean:Ia,date:Ct,time:Ct,datetime:Ct,"date-range":zi,"datetime-range":zi,"option.single":cn,"option.multiple":ot,"cascade.single":ot,"cascade.multiple":ot,"user.single":cn,"user.multiple":ot,"department.single":cn,"department.multiple":ot,"resource-ref.single":cn,"resource-ref.multiple":ot,file:_o,image:_o,signature:_o,address:mo,location:mo,uuid:["eq","neq","in","isEmpty"],json:mo,"serial-number":["eq","neq","in","contains","startsWith"],subtable:[]},ba=new Set(["text.short","text.long","text.rich","option.single","user.single","department.single","resource-ref.single","serial-number"]),Oa=new Set(["option.multiple","cascade.single","cascade.multiple","user.multiple","department.multiple","resource-ref.multiple","file","image","signature","address","location","json","subtable"]);function go(e){return ya[e]}function Na(e,t){return go(e).includes(t)}function ln(e){return ba.has(e)}function it(e){return!Oa.has(e)}function Ao(e){return go(e).length>0}var Ji=new Set(["number.integer","number.decimal"]),Yi=new Set(["text.short","text.long","number.integer","number.decimal","date","time","datetime","serial-number"]),Ta=new Set([...Yi,"boolean","uuid"]),Ra=new Set(["option.single","user.single","department.single","resource-ref.single"]);function Ca(e,t){return t==="sum"||t==="avg"?Ji.has(e)?{valueExpression:"column",numericResult:!0}:null:t==="min"||t==="max"?Yi.has(e)?{valueExpression:"column",numericResult:Ji.has(e)}:null:Ra.has(e)?{valueExpression:"snapshot-value",numericResult:!0}:Ta.has(e)?{valueExpression:"column",numericResult:!0}:null}var fn=["version","maxBytes","fields"];function Io(e,t){if(e===void 0)return;let o=Eo(e,t);Xi(o,fn,t);let n=un(o.version,`${t}/version`,1,1e6),i=un(o.maxBytes,`${t}/maxBytes`,2,196608);(!n||!i)&&de("NATIVE_DATA_DRAFT_STATE_SCHEMA_INVALID",t);let r=Eo(o.fields,`${t}/fields`),d=Object.entries(r);(!d.length||d.length>50)&&de("NATIVE_DATA_DRAFT_STATE_FIELDS_INVALID",`${t}/fields`);for(let[s,a]of d){let c=`${t}/fields/${s}`;/^[A-Za-z][A-Za-z0-9_]{0,62}$/.test(s)||de("NATIVE_DATA_DRAFT_STATE_FIELD_CODE_INVALID",c);let f=Eo(a,c),u=Zi(f.type,`${c}/type`,32),p=u==="string"?["type","required","maxLength","enum"]:u==="json.object"?["type","required","maxBytes"]:["type","required"];if(["string","number","integer","boolean","json.object"].includes(u)||de("NATIVE_DATA_DRAFT_STATE_FIELD_TYPE_INVALID",`${c}/type`),Xi(f,p,c),wa(f.required,`${c}/required`),u==="string"){let _=un(f.maxLength,`${c}/maxLength`,1,196608);_||de("NATIVE_DATA_DRAFT_STATE_FIELD_INVALID",c),f.enum!==void 0&&ha(f.enum,`${c}/enum`,100,!1).some(A=>A.length>_)&&de("NATIVE_DATA_DRAFT_STATE_FIELD_INVALID",`${c}/enum`)}else if(u==="json.object"){let _=un(f.maxBytes,`${c}/maxBytes`,2,65536);(!_||_>i)&&de("NATIVE_DATA_DRAFT_STATE_FIELD_INVALID",c)}}}function ha(e,t,o,n){(!Array.isArray(e)||!n&&e.length===0||e.length>o)&&de("NATIVE_DATA_SURFACE_STRING_ARRAY_INVALID",t);let i=e.map((r,d)=>Zi(r,`${t}/${d}`,255));return new Set(i).size!==i.length&&de("NATIVE_DATA_SURFACE_STRING_ARRAY_INVALID",t),i}function Eo(e,t){return(!e||typeof e!="object"||Array.isArray(e))&&de("NATIVE_OBJECT_REQUIRED",t),e}function Xi(e,t,o){let n=new Set(t);for(let i of Object.keys(e))n.has(i)||de("NATIVE_PROPERTY_UNKNOWN",`${o}/${i}`)}function Zi(e,t,o){return(typeof e!="string"||e.length===0||e.length>o)&&de("NATIVE_STRING_INVALID",t),e}function wa(e,t){e!==void 0&&typeof e!="boolean"&&de("NATIVE_BOOLEAN_REQUIRED",t)}function un(e,t,o,n){return(!Number.isSafeInteger(e)||Number(e)<o||Number(e)>n)&&de("NATIVE_INTEGER_INVALID",t),Number(e)}function de(e,t){throw new ye(e,t)}var Sa=500,Se={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","userCandidates","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:fn,mobile:["enabled"]},Da={"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 pn(e,t,o){if(e===void 0)return;let n=re(e,o);Ce(n,Se.surface,o);let i=n.mutationOwner===void 0?"native":De(n.mutationOwner,`${o}/mutationOwner`,16);["native","action","readonly","workflow","queued-command"].includes(i)||j("NATIVE_DATA_SURFACE_MUTATION_OWNER_INVALID",`${o}/mutationOwner`);let r=n.generated===void 0?{}:re(n.generated,`${o}/generated`);Ce(r,Se.generated,`${o}/generated`);for(let a of Se.generated)bo(r[a],`${o}/generated/${a}`);if(i!=="native")for(let a of["create","update","delete"])r[a]===!0&&j("NATIVE_DATA_SURFACE_MUTATION_OWNER_CONFLICT",`${o}/generated/${a}`);let d=new Map(t.map(a=>[a.code,a])),s=re(n.fields,`${o}/fields`);for(let a of Object.keys(s))d.has(a)||j("NATIVE_DATA_SURFACE_FIELD_MISSING",`${o}/fields/${a}`);for(let a of t)Object.prototype.hasOwnProperty.call(s,a.code)||j("NATIVE_DATA_SURFACE_FIELD_REQUIRED",`${o}/fields/${a.code}`),$a(s[a.code],a,`${o}/fields/${a.code}`);for(let a of["create","update"]){let c=r[a]??i==="native",f=t.some(u=>{let p=re(s[u.code],`${o}/fields/${u.code}`);return er(u,p,a)});c&&!f&&j("NATIVE_DATA_SURFACE_WRITABLE_FIELDS_REQUIRED",`${o}/generated/${a}`)}if(va(n.list,d,`${o}/list`),Qi(n.form,d,`${o}/form`,"form"),Qi(n.detail,d,`${o}/detail`,"detail"),n.mobile!==void 0){let a=re(n.mobile,`${o}/mobile`);Ce(a,Se.mobile,`${o}/mobile`),bo(a.enabled,`${o}/mobile/enabled`)}ka(n,t,o)}function mn(e,t){let o=e.views?.find(i=>i.code===t);o||j("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 d={...r};delete d.section;let s=n.get(i);return[i,{...d,...s?{section:s}:{},list:o.list.fieldOrder.includes(i)}]}))}}function ka(e,t,o){if(e.views===void 0)return;(!Array.isArray(e.views)||e.views.length>20)&&j("NATIVE_DATA_VIEWS_LIMIT_INVALID",`${o}/views`);let n=new Set;e.views.forEach((i,r)=>{let d=`${o}/views/${r}`,s=re(i,d);Ce(s,["code","name","generated","list","form","detail","mobile","sections"],d);let a=De(s.code,`${d}/code`,64);(!/^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/.test(a)||n.has(a))&&j("NATIVE_DATA_VIEW_CODE_INVALID",`${d}/code`),n.add(a),De(s.name,`${d}/name`,255),re(s.generated,`${d}/generated`),re(s.mobile,`${d}/mobile`);for(let f of["list","detail","create","update","delete"])typeof s.generated[f]!="boolean"&&j("NATIVE_DATA_VIEW_OPERATION_INVALID",`${d}/generated/${f}`);typeof s.mobile.enabled!="boolean"&&j("NATIVE_DATA_VIEW_MOBILE_INVALID",`${d}/mobile/enabled`);for(let f of["list","form","detail"]){let u=re(s[f],`${d}/${f}`),p=rt(u.fieldOrder,`${d}/${f}/fieldOrder`,500,!0);for(let _ of p){let E=e.fields[_];(!E||(E.hidden??E.system)===!0)&&j("NATIVE_DATA_VIEW_FIELD_INVALID",`${d}/${f}/fieldOrder`)}}if(s.sections!==void 0){(!Array.isArray(s.sections)||s.sections.length>100)&&j("NATIVE_DATA_VIEW_SECTIONS_INVALID",`${d}/sections`);let f=new Set;s.sections.forEach((u,p)=>{let _=`${d}/sections/${p}`,E=re(u,_);Ce(E,["title","fields"],_),De(E.title,`${_}/title`,255);for(let A of rt(E.fields,`${_}/fields`,100,!0)){let O=e.fields[A];(!O||(O.hidden??O.system)===!0||f.has(A))&&j("NATIVE_DATA_VIEW_FIELD_INVALID",`${_}/fields`),f.add(A)}})}let c=mn(e,a);if(pn(c,t,d),s.generated.create!==!1&&(e.mutationOwner||"native")==="native")for(let f of t)Tt(f,e.fields[f.code])&&er(f,e.fields[f.code],"create")&&!s.form.fieldOrder.includes(f.code)&&j("NATIVE_DATA_VIEW_CREATE_REQUIRED_FIELD_MISSING",`${d}/form/fieldOrder`)})}function er(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 $a(e,t,o){let n=re(e,o);Ce(n,Se.field,o),De(n.label,`${o}/label`,500),n.type!==t.type&&j("NATIVE_DATA_SURFACE_FIELD_TYPE_MISMATCH",`${o}/type`);let i=De(n.widget,`${o}/widget`,64);Da[t.type].includes(i)||j("NATIVE_DATA_SURFACE_WIDGET_INCOMPATIBLE",`${o}/widget`),Va(n.section,`${o}/section`,255);for(let r of["requiredHint","system","hidden","list","searchable","sortable"])bo(n[r],`${o}/${r}`);n.searchable===!0&&!ln(t.type)&&j("NATIVE_DATA_SURFACE_SEARCH_UNSUPPORTED",`${o}/searchable`),n.sortable===!0&&!it(t.type)&&j("NATIVE_DATA_SURFACE_SORT_UNSUPPORTED",`${o}/sortable`);for(let r of["readCapabilities","createCapabilities","updateCapabilities"])rt(n[r],`${o}/${r}`,100,!0);if(n.maxCount!==void 0&&(!Number.isSafeInteger(n.maxCount)||Number(n.maxCount)<1||Number(n.maxCount)>100)&&j("NATIVE_DATA_SURFACE_MAX_COUNT_INVALID",`${o}/maxCount`),n.maxSizeMb!==void 0&&(!Number.isSafeInteger(n.maxSizeMb)||Number(n.maxSizeMb)<1||Number(n.maxSizeMb)>1024)&&j("NATIVE_DATA_SURFACE_MAX_SIZE_INVALID",`${o}/maxSizeMb`),n.accept!==void 0){let r=Array.isArray(n.accept)?n.accept:[n.accept];rt(r,`${o}/accept`,50,!1)}for(let r of["maxLength","precision","scale","exactDecimal","min","max","rangeBoundary","options","source","userCandidates","timePrecision","serial","subtable"])Pa(n,t,r,o);La(n,t,o)}function va(e,t,o){if(e===void 0)return;let n=re(e,o);if(Ce(n,Se.list,o),n.actions!==void 0){let i=re(n.actions,`${o}/actions`);Ce(i,["import","export"],`${o}/actions`);for(let r of["import","export"])i[r]!==void 0&&typeof i[r]!="boolean"&&j("NATIVE_DATA_SURFACE_LIST_ACTION_INVALID",`${o}/actions/${r}`)}if(n.fieldOrder!==void 0)for(let i of rt(n.fieldOrder,`${o}/fieldOrder`,500,!0))t.has(i)||j("NATIVE_DATA_SURFACE_LIST_FIELD_INVALID",`${o}/fieldOrder`);n.defaultPageSize!==void 0&&(!Number.isSafeInteger(n.defaultPageSize)||Number(n.defaultPageSize)<1||Number(n.defaultPageSize)>200)&&j("NATIVE_DATA_SURFACE_PAGE_SIZE_INVALID",`${o}/defaultPageSize`);for(let[i,r]of[["searchableFields",ln],["filterFields",Ao]]){if(n[i]===void 0)continue;let d=rt(n[i],`${o}/${i}`,100,!0);for(let s of d){let a=t.get(s);(!a||!r(a.type))&&j("NATIVE_DATA_SURFACE_LIST_FIELD_INVALID",`${o}/${i}`)}}if(n.defaultSort!==void 0){let i=re(n.defaultSort,`${o}/defaultSort`);Ce(i,Se.defaultSort,`${o}/defaultSort`);let r=De(i.field,`${o}/defaultSort/field`,63),d=t.get(r);!fo(r)&&(!d||!it(d.type))&&j("NATIVE_DATA_SURFACE_SORT_UNSUPPORTED",`${o}/defaultSort/field`),i.order!==void 0&&!["asc","desc"].includes(i.order)&&j("NATIVE_DATA_SURFACE_SORT_ORDER_INVALID",`${o}/defaultSort/order`)}}function Qi(e,t,o,n){if(e===void 0)return;let i=re(e,o);if(Ce(i,Se[n],o),i.layout!==void 0&&!["flat","sections"].includes(i.layout)&&j("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>Sa)&&j("NATIVE_DATA_SURFACE_FIELD_ORDER_INVALID",r);let d=i.fieldOrder.map((s,a)=>De(s,`${r}/${a}`,63));new Set(d).size!==d.length&&j("NATIVE_DATA_SURFACE_FIELD_ORDER_INVALID",r),d.forEach((s,a)=>{t.has(s)||j("NATIVE_DATA_SURFACE_FIELD_ORDER_FIELD_MISSING",`${r}/${a}`)})}n==="form"&&Io(i.draftState,`${o}/draftState`)}function Pa(e,t,o,n){e[o]===void 0&&t[o]===void 0||((e[o]===void 0||t[o]===void 0)&&j("NATIVE_DATA_SURFACE_FIELD_PROJECTION_MISMATCH",`${n}/${o}`),Q(e[o])!==Q(t[o])&&j("NATIVE_DATA_SURFACE_FIELD_PROJECTION_MISMATCH",`${n}/${o}`))}function La(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:yo(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)&&j("NATIVE_DATA_SURFACE_FIELD_PROJECTION_MISMATCH",`${o}/${r}`);let d=r==="accept"?yo(i[r]):i[r],s=r==="accept"?yo(n[r]):n[r];Q(d)!==Q(s)&&j("NATIVE_DATA_SURFACE_FIELD_PROJECTION_MISMATCH",`${o}/${r}`)}}function yo(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 rt(e,t,o,n){(!Array.isArray(e)||!n&&e.length===0||e.length>o)&&j("NATIVE_DATA_SURFACE_STRING_ARRAY_INVALID",t);let i=e.map((r,d)=>De(r,`${t}/${d}`,255));return new Set(i).size!==i.length&&j("NATIVE_DATA_SURFACE_STRING_ARRAY_INVALID",t),i}function re(e,t){return(!e||typeof e!="object"||Array.isArray(e))&&j("NATIVE_OBJECT_REQUIRED",t),e}function Ce(e,t,o){let n=new Set(t);for(let i of Object.keys(e))n.has(i)||j("NATIVE_PROPERTY_UNKNOWN",`${o}/${i}`)}function De(e,t,o){return(typeof e!="string"||e.length===0||e.length>o)&&j("NATIVE_STRING_INVALID",t),e}function Va(e,t,o){e!==void 0&&(typeof e!="string"||e.length>o)&&j("NATIVE_STRING_INVALID",t)}function bo(e,t){e!==void 0&&typeof e!="boolean"&&j("NATIVE_BOOLEAN_REQUIRED",t)}function j(e,t){throw new ye(e,t)}var st=class extends Error{constructor(o,n){super(`${o}: ${n}`);this.pointer=o;this.reason=n}pointer;reason;code="NATIVE_MANAGED_CONCURRENCY_INVALID"};function Oo(e,t,o){if(e===void 0)return;let n=(g,I)=>{throw new st(g,I)},i=(g,I,T)=>((!g||typeof g!="object"||Array.isArray(g)||Object.keys(g).some(l=>!T.includes(l)))&&n(I,"object contains unsupported properties"),g),r=(g,I,T,l)=>{(!Number.isSafeInteger(g)||g<I||g>T)&&n(l,`expected integer ${I}..${T}`)},d=(g,I)=>{(typeof g!="string"||!/^[a-z][a-z0-9_-]{0,63}$/.test(g))&&n(I,"invalid code")},s=(g,I,T)=>((!Array.isArray(g)||g.length>I)&&n(T,"array exceeds bound"),g),a=(g,I)=>{let T=t.find(l=>l.code===g);return T||n(I,"unknown resource"),T},c=(g,I,T)=>{let l=g.schema.fields.find(y=>y.code===I);return!l&&I!=="id"&&n(T,"unknown field"),l},f=(g,I,T=!1)=>{i(g,I,Object.keys(g||{})),Object.keys(g).length>8&&n(I,"at most eight parameters");for(let[l,y]of Object.entries(g))if(d(l,I),i(y,I,["type","values","minimum","maximum","minLength","maxLength"]),y.type==="uuid")Object.keys(y).length!==1&&n(I,"uuid has no options");else if(T&&y.type==="boolean")i(y,I,["type"]);else if(T&&y.type==="string"&&y.values===void 0)i(y,I,["type","minLength","maxLength"]),r(y.maxLength,1,256,I),y.minLength!==void 0&&r(y.minLength,0,y.maxLength,I);else if(y.type==="string"){i(y,I,["type","values"]);let R=s(y.values,100,I);(!R.length||R.some(h=>typeof h!="string"||h.length>128)||new Set(R).size!==R.length)&&n(I,"finite string values required")}else y.type==="integer"?(i(y,I,["type","minimum","maximum"]),r(y.minimum,0,1e6,I),r(y.maximum,y.minimum,y.minimum+1e3,I)):n(I,"unsupported parameter type")},u=(g,I,T,l=!1)=>{i(g,T,["from","key","value"]),!(g.from==="input"&&Object.keys(g).length===2&&Object.hasOwn(I,g.key))&&((g.from==="actor"||l&&g.from==="allocation")&&Object.keys(g).length===1||g.from==="literal"&&Object.keys(g).length===2&&Object.hasOwn(g,"value")&&(g.value===null||["string","boolean"].includes(typeof g.value)||typeof g.value=="number"&&Number.isFinite(g.value))&&JSON.stringify(g.value).length<=512||n(T,"invalid binding"))},p=(g,I,T)=>{u(g,I,T),!(g.from==="input"&&I[g.key].type==="uuid")&&(g.from==="literal"&&typeof g.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(g.value)||n(T,"record and allocation identifiers require a UUID binding"))},_=(g,I,T)=>{u(g,I,T),!(g.from==="input"&&I[g.key].type==="integer"&&I[g.key].minimum>=1)&&(g.from==="literal"&&Number.isSafeInteger(g.value)&&g.value>=1||n(T,"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"]),r(A.admission.perSecond,1,1e3,E),r(A.admission.burst,1,1e3,E),r(A.admission.maxInFlight,1,1e3,E);let O=(g,I)=>{let T=new Set;for(let l of g)d(l?.code,I),T.has(l.code)&&n(I,"duplicate code"),T.add(l.code)};O(s(A.reads,32,E),E),O(s(A.quotas,16,E),E),O(s(A.commands,32,E),E);for(let g of A.reads){let I=`${E}/reads/${g.code}`;i(g,I,["code","resourceCode","parameters","select","where","limit","scope","freshSeconds","staleSeconds","maxKeys","sourcePerSecond","dependencies"]);let T=a(g.resourceCode,I);f(g.parameters,I),["subject","application"].includes(g.scope)||n(I,"invalid cache scope"),g.scope==="application"&&T.dataPolicyCode&&n(I,"shared cache cannot bypass a row policy");let l=s(g.select,32,I);l.length||n(I,"select required"),l.forEach(R=>c(T,R,I));let y=s(g.dependencies,64,I);y.forEach(R=>c(T,R,I));for(let R of s(g.where||[],8,I))i(R,I,["field","value"]),c(T,R.field,I),u(R.value,g.parameters,I),g.scope==="application"&&R.value.from==="actor"&&n(I,"actor requires subject cache"),y.includes(R.field)||n(I,"filter dependency missing");l.some(R=>!y.includes(R))&&n(I,"selected field dependency missing"),r(g.limit,1,100,I),r(g.freshSeconds,1,300,I),r(g.staleSeconds,0,300,I),r(g.maxKeys,1,1e4,I),r(g.sourcePerSecond,1,20,I)}for(let g of A.quotas){let I=`${E}/quotas/${g.code}`;i(g,I,["code","sourceResource","capacityField","allocationResource","allocationField","reservationSeconds"]);let T=a(g.sourceResource,I),l=a(g.allocationResource,I);c(T,g.capacityField,I)?.type!=="number.integer"&&n(I,"capacity must be an integer"),(c(l,g.allocationField,I)?.type!=="uuid"||c(l,g.allocationField,I)?.nullable!==!1)&&n(I,"allocation reference must be a uuid"),l.surface?.mutationOwner!=="queued-command"&&n(I,"allocation model must be command owned"),g.reservationSeconds!==void 0&&r(g.reservationSeconds,10,86400,I)}new Set(A.quotas.map(g=>g.allocationResource)).size!==A.quotas.length&&n(E,"an allocation model has exactly one pool owner");for(let g of A.commands){let I=`${E}/commands/${g.code}`;i(g,I,["code","mode","intake","execution","capability","parameters","resourceKey","admission","deadlineSeconds","guards","operations","quota"]),g.mode!==void 0&&!["permit","durable"].includes(g.mode)&&n(I,"unsupported mode");let T=g.mode==="durable";if(f(g.parameters,I,T),u(g.resourceKey,g.parameters,I),o.some(l=>l.code===g.capability)||n(I,"command capability must be declared"),i(g.admission,I,["perSecond","burst","maxInFlight","maxQueue","maxWaitSeconds","permitSeconds"]),r(g.admission.perSecond,1,A.admission.perSecond,I),r(g.admission.burst,1,A.admission.burst,I),r(g.admission.maxInFlight,1,A.admission.maxInFlight,I),r(g.admission.maxQueue,1,1e4,I),r(g.admission.maxWaitSeconds,1,3600,I),(!T||g.admission.permitSeconds!==void 0)&&r(g.admission.permitSeconds,5,60,I),r(g.deadlineSeconds,10,3600,I),T){(g.operations!==void 0||g.guards!==void 0||g.quota!==void 0)&&n(I,"backend-plan does not accept static operations, guards or quota"),i(g.intake,I,["perSecond","burst","maxInFlight"]);for(let R of["perSecond","burst","maxInFlight"])r(g.intake[R],1,1e3,I);let l=i(g.execution,I,["kind","handlerCode","timeoutMs","resources","directory"]);l.kind!=="backend-plan"&&n(I,"durable requires backend-plan"),d(l.handlerCode,I),r(l.timeoutMs,100,3e4,I);let y=s(l.resources,32,I);y.length||n(I,"execution resources required"),new Set(y.map(R=>R.resourceCode)).size!==y.length&&n(I,"duplicate execution resource");for(let R of y){i(R,I,["resourceCode","readFields","writeOperations","writeFields"]);let h=a(R.resourceCode,I);for(let k of["readFields","writeFields"]){let M=s(R[k],64,I);new Set(M).size!==M.length&&n(I,"duplicate field"),M.forEach(V=>{k==="readFields"&&Ot.has(V)||c(h,V,I)})}let $=s(R.writeOperations,3,I);(new Set($).size!==$.length||$.some(k=>!["create","update","increment"].includes(k)))&&n(I,"unsupported execution operation"),R.writeFields.some(k=>["id","revision","created_by","updated_by","created_at","updated_at"].includes(k))&&n(I,"record metadata is platform owned"),!$.length&&R.writeFields.length&&n(I,"write fields require an operation"),$.length&&!R.writeFields.length&&n(I,"write operations require fields"),A.quotas.some(k=>k.allocationResource===R.resourceCode)&&$.length&&n(I,"allocation references remain owned by their pool command")}if(l.directory!==void 0){i(l.directory,I,["mode","fields"]),l.directory.mode!=="current-initiator"&&n(I,"only current initiator allowed");let R=s(l.directory.fields,5,I);(!R.length||new Set(R).size!==R.length||R.some(h=>!["displayName","employeeNumber","primaryDepartment","departments","phone"].includes(h)))&&n(I,"unsupported directory fields")}continue}(g.execution!==void 0||g.intake!==void 0)&&n(I,"execution and intake require durable mode");for(let l of s(g.guards||[],8,I)){i(l,I,["resourceCode","id","conditions"]);let y=a(l.resourceCode,I);p(l.id,g.parameters,I);for(let R of s(l.conditions,16,I)){i(R,I,["kind","field","operator","value"]);let h=c(y,R.field,I);["eq","neq","lt","lte","gt","gte"].includes(R.operator)||n(I,"unsupported guard"),R.kind==="database-now"?(h?.type!=="datetime"||!["lt","lte","gt","gte"].includes(R.operator)||R.value!==void 0)&&n(I,"database-now requires datetime and an ordering operator"):(R.kind!==void 0&&R.kind!=="value"&&n(I,"unsupported condition kind"),u(R.value,g.parameters,I))}}for(let l of s(g.operations,8,I)){i(l,I,["operation","resourceCode","id","expectedRevision","data"]);let y=a(l.resourceCode,I);y.surface?.mutationOwner!=="queued-command"&&n(I,"command mutations require command owned models");let R=A.quotas.find(h=>h.allocationResource===l.resourceCode);R&&(l.operation==="create"?g.quota?.action!=="allocate"||g.quota.pool!==R.code:Object.hasOwn(l.data||{},R.allocationField))&&n(I,"allocation references are owned by their pool command"),["create","update"].includes(l.operation)||n(I,"unsupported operation"),l.operation==="update"?(p(l.id,g.parameters,I),_(l.expectedRevision,g.parameters,I)):(l.id!==void 0||l.expectedRevision!==void 0)&&n(I,"create has no caller supplied id/revision"),i(l.data,I,Object.keys(l.data||{})),Object.keys(l.data).length>32&&n(I,"too many fields");for(let[h,$]of Object.entries(l.data))h==="id"&&n(I,"record identifiers are platform owned"),c(y,h,I),u($,g.parameters,I,g.quota?.action==="allocate")}if(g.quota){let l=i(g.quota,I,["pool","action","units","mode","allocation"]),y=A.quotas.find(R=>R.code===l.pool);y||n(I,"unknown quota pool"),p(g.resourceKey,g.parameters,I),l.action==="allocate"?(i(l,I,["pool","action","units","mode"]),r(l.units,1,1e3,I),(!["committed","reserved"].includes(l.mode)||l.mode==="reserved"&&!y.reservationSeconds)&&n(I,"invalid allocation mode"),(g.operations.length!==1||g.operations[0].operation!=="create"||g.operations[0].resourceCode!==y.allocationResource||g.operations[0].data[y.allocationField]?.from!=="allocation")&&n(I,"allocation must atomically create its bound business record")):["confirm","release"].includes(l.action)?(i(l,I,["pool","action","allocation"]),p(l.allocation,g.parameters,I),g.operations.length&&n(I,"lifecycle owns allocation state; business reference remains immutable")):n(I,"invalid quota action")}else g.operations.length||n(I,"operations required")}let b=A.commands.filter(g=>g.mode==="durable").map(g=>g.execution.handlerCode);return new Set(b).size!==b.length&&n(E,"handler code must be unique"),JSON.parse(JSON.stringify(A))}var Ke=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"},Ro=["parentTransitions","childTransitions","fulfilledChildStatuses","lockedParentStatuses"],tr=["amountFieldCode","currencyFieldCode","relationFieldCode","parentFieldCode","rootFieldCode","statusFieldCode","parentRelationValue","childRelationValue"],gn=e=>!!(e&&typeof e=="object"&&!Array.isArray(e)),_n=e=>Array.isArray(e)?e.filter(gn):[],he=(e,t)=>{throw new Ke(e,t)},No=e=>typeof e=="string"&&/^[A-Za-z0-9._:-]{1,128}$/.test(e),To=(e,t)=>e<t?-1:e>t?1:0;function An(e,t="/decimalReservationLifecycle"){if(e===void 0)return;if(!gn(e)||Object.keys(e).some(i=>!Ro.includes(i))||Ro.some(i=>!Object.prototype.hasOwnProperty.call(e,i)))return he(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 he(`${t}/${i}`,"\u72B6\u6001\u8FB9\u6700\u591A 64 \u6761");let d=new Set;return r.map((s,a)=>{let c=`${t}/${i}/${a}`;if(!gn(s)||Object.keys(s).some(u=>u!=="from"&&u!=="to")||!No(s.from)||!No(s.to)||s.from===s.to)return he(c,"\u72B6\u6001\u8FB9\u5FC5\u987B\u5305\u542B\u4E0D\u540C\u7684\u6709\u6548 from/to");let f=JSON.stringify([s.from,s.to]);return d.has(f)?he(c,"\u72B6\u6001\u8FB9\u4E0D\u80FD\u91CD\u590D"):(d.add(f),{from:s.from,to:s.to})}).sort((s,a)=>To(s.from,a.from)||To(s.to,a.to))},n=i=>{let r=e[i];return!Array.isArray(r)||r.length<1||r.length>16||r.some(d=>!No(d))||new Set(r).size!==r.length?he(`${t}/${i}`,"\u72B6\u6001\u96C6\u5408\u5FC5\u987B\u5305\u542B 1 \u5230 16 \u4E2A\u4E0D\u91CD\u590D\u7684\u6709\u6548\u72B6\u6001"):[...r].sort(To)};return{parentTransitions:o("parentTransitions"),childTransitions:o("childTransitions"),fulfilledChildStatuses:n("fulfilledChildStatuses"),lockedParentStatuses:n("lockedParentStatuses")}}function Co(e,t,o="/config/data/resources"){_n(e).forEach((n,i)=>{let r=`${o}/${i}/decimalReservationLifecycle`,d=An(n.decimalReservationLifecycle,r);if(!d)return;let s=_n(t).map(u=>u.platformAccess?.decimalReservation).filter(u=>gn(u)&&u.resourceCode===n.code),a=s.find(u=>u.mode==="reserve");if(!a)return he(r,"\u9700\u8981\u540C\u8D44\u6E90\u5DF2\u58F0\u660E\u7684 reserve \u52A8\u4F5C\u6620\u5C04");if(tr.some(u=>typeof a[u]!="string")||s.some(u=>tr.some(p=>u[p]!==a[p])))return he(r,"\u540C\u8D44\u6E90\u989D\u5EA6\u52A8\u4F5C\u7684\u5B57\u6BB5\u6620\u5C04\u5FC5\u987B\u4E00\u81F4");let c=_n(n.schema?.fields).find(u=>u.code===a.statusFieldCode);if(c?.type!=="option.single")return he(r,"\u989D\u5EA6\u72B6\u6001\u5B57\u6BB5\u5FC5\u987B\u4E3A option.single");let f=new Set(_n(c.options).map(u=>u.value));for(let u of Ro)if((u==="parentTransitions"||u==="childTransitions"?d[u].flatMap(_=>[_.from,_.to]):d[u]).some(_=>!f.has(_)))return he(`${r}/${u}`,"\u72B6\u6001\u5FC5\u987B\u6765\u81EA\u989D\u5EA6\u72B6\u6001\u5B57\u6BB5\u7684\u9009\u9879");if(s.some(u=>u.mode==="reserve"&&Array.isArray(u.eligibleParentStatuses)&&u.eligibleParentStatuses.some(p=>d.lockedParentStatuses.includes(String(p)))))return he(`${r}/lockedParentStatuses`,"\u9501\u5B9A\u7236\u72B6\u6001\u4E0D\u80FD\u5141\u8BB8\u65B0\u9884\u7559")})}var or=require("crypto");var ho=new Set(["option.single","user.single","department.single","resource-ref.single"]),Fa=new Set(["option.multiple","cascade.single","cascade.multiple","user.multiple","department.multiple","resource-ref.multiple","address","location","json"]),ir=new Set(["option.multiple","cascade.single","cascade.multiple","user.multiple","department.multiple","resource-ref.multiple","file","image"]),xa=new Set(["option.single","user.single","department.single","resource-ref.single","signature","address","location"]),ja=new Set([...ho,...ir,"signature","address","location","json"]);function Wa(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=>rr(n,o.has(n.code))).sort((n,i)=>n.code.localeCompare(i.code))}function rr(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:Xa(e),index:Ya(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 Ua(e,t){if(t.type==="subtable")return null;let o=se(t.code),n=sr(e,t),i=[n?` DEFAULT ${n}`:"",Za(o,t),Ba(o,t)].join("");return`${o} ${t.storage}${i}`}function Ma(e,t){return sr(e,t)}function Ba(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 Ka(e){return e.type==="serial-number"||Nt(e.type)&&e.type!=="subtable"}function Ga(e,t){return t.filter(o=>o.type==="serial-number").map(o=>{let n=In(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 qa(e,t){let o=En(e);return t.filter(n=>n.type==="serial-number").map(n=>`ALTER SEQUENCE ${In(e,n.code)} OWNED BY ${o}.${se(n.code)}`)}function za(e,t){return t.filter(o=>o.type==="serial-number").map(o=>`GRANT USAGE, SELECT ON SEQUENCE ${In(e,o.code)} TO "openxiangda_data_api"`)}function Ja(e,t){let o=En(e),n=[];for(let i of t){if(i.type==="subtable")continue;let r=se(i.code),d=se(ke("idx",e,i.code,i.index));switch(i.index){case"btree":n.push(`CREATE INDEX IF NOT EXISTS ${d} ON ${o} (${r})`);break;case"btree-snapshot-expressions":{let s=se(ke("idx",e,i.code,"snapshot-value")),a=se(ke("idx",e,i.code,"snapshot-label"));n.push(`CREATE INDEX IF NOT EXISTS ${s} ON ${o} ((${r} ->> 'value'))`,`CREATE INDEX IF NOT EXISTS ${a} ON ${o} ((${r} ->> 'label'))`);break}case"gin-jsonb-path":n.push(`CREATE INDEX IF NOT EXISTS ${d} ON ${o} USING GIN (${r} jsonb_path_ops)`);break;case"gist-range":n.push(`CREATE INDEX IF NOT EXISTS ${d} ON ${o} USING GIST (${r})`);break;case"gin-trigram":{let s=ho.has(i.type)?`((${r} ->> 'label')) gin_trgm_ops`:`${r} gin_trgm_ops`;n.push(`CREATE INDEX IF NOT EXISTS ${d} ON ${o} USING GIN (${s})`);break}case"none":break}if(i.type==="serial-number"){let s=se(ke("uidx",e,i.code,"serial"));n.push(`CREATE UNIQUE INDEX IF NOT EXISTS ${s} ON ${o} (${r})`)}}return n}function Ha(e,t,o,n){let i=En(e),r=En(t),d=se(ke("uidx",e,"environment_id","subtable-parent")),s=se(ke("idx",t,o,n,"subtable-child")),a=se(ke("fk",t,o,e)),c=se(o),f=se(n);return[`CREATE UNIQUE INDEX IF NOT EXISTS ${d} ON ${i} ("tenant_id", "app_code", "environment_key", "id")`,`CREATE INDEX IF NOT EXISTS ${s} ON ${r} ("tenant_id", "app_code", "environment_key", ${c}, ${f}, "id")`,`DO $native_subtable$ BEGIN
1
+ "use strict";var Qs=Object.create;var Xt=Object.defineProperty;var ea=Object.getOwnPropertyDescriptor;var ta=Object.getOwnPropertyNames;var na=Object.getPrototypeOf,oa=Object.prototype.hasOwnProperty;var ia=(e,t)=>{for(var o in t)Xt(e,o,{get:t[o],enumerable:!0})},Pi=(e,t,o,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of ta(t))!oa.call(e,i)&&i!==o&&Xt(e,i,{get:()=>t[i],enumerable:!(n=ea(t,i))||n.enumerable});return e};var ra=(e,t,o)=>(o=e!=null?Qs(na(e)):{},Pi(t||!e||!e.__esModule?Xt(o,"default",{value:e,enumerable:!0}):o,e)),sa=e=>Pi(Xt({},"__esModule",{value:!0}),e);var Jl={};ia(Jl,{AuthenticatedPublicReadContractError:()=>dt,DATA_AUDIT_METADATA_FIELDS:()=>Rt,DATA_BUSINESS_COMMAND_INTENT_MAX_BYTES:()=>Tp,DATA_BUSINESS_COMMAND_RESOLUTION_SCHEMA:()=>Ks,DATA_BUSINESS_COMMAND_SCHEMA:()=>Cl,DATA_EVENT_TYPES_V2:()=>xn,DATA_FORM_DRAFT_MAX_BYTES:()=>nu,DATA_SUBTABLE_DEFAULT_TOTAL_ROWS:()=>eu,DATA_SUBTABLE_MAX_ROWS:()=>Me,DATA_SUBTABLE_MAX_TOTAL_ROWS:()=>Qt,DATA_SYSTEM_SORT_FIELD_CODES:()=>Ji,DATA_TRANSACTION_MAX_BYTES:()=>tu,DATA_TRANSACTION_MAX_OPERATIONS:()=>Ui,DATA_TRANSACTION_RECORD_SET_MAX_RECORDS:()=>hp,DATE_EVENT_RESERVED_DATA_FIELDS_V2:()=>Bd,DEVELOPMENT_BACKEND_CONNECTION_TTL_SECONDS:()=>xp,DEVELOPMENT_BACKEND_ENDPOINT_PATTERN:()=>Ul,DEVELOPMENT_BACKEND_FEATURE:()=>xl,DEVELOPMENT_BACKEND_INVOCATION_FEATURE:()=>Wl,DEVELOPMENT_BACKEND_INVOCATION_MAX_REQUEST_BYTES:()=>vp,DEVELOPMENT_BACKEND_INVOCATION_MAX_RESPONSE_BYTES:()=>Pp,DEVELOPMENT_BACKEND_INVOCATION_SCHEMA:()=>Hs,DEVELOPMENT_BACKEND_MAX_INFLIGHT:()=>Fp,DEVELOPMENT_BACKEND_MAX_REQUEST_BYTES:()=>Vp,DEVELOPMENT_BACKEND_MAX_RESPONSE_BYTES:()=>Lp,DEVELOPMENT_BACKEND_SCHEMA:()=>jl,DEVELOPMENT_CONFIGURATION_ENDPOINT:()=>Pl,DEVELOPMENT_CONFIGURATION_FEATURE:()=>vl,DEVELOPMENT_CONFIGURATION_MANIFEST_SCHEMA:()=>vi,DEVELOPMENT_CONFIGURATION_SCHEMA:()=>zs,DateEventProjectionV2Error:()=>Lt,DevelopmentConfigurationContractError:()=>Xn,ManagedConcurrencyContractError:()=>st,NATIVE_ARTIFACT_CAPACITY_V2:()=>Ae,NATIVE_CONFIGURATION_VALIDATOR_DIGEST:()=>zl,NATIVE_CONTRACT_CAPACITY_V2:()=>B,NATIVE_DATA_POLICY_EXPRESSION_MAX_CLAUSES:()=>yf,NATIVE_DATA_POLICY_EXPRESSION_MAX_DEPTH:()=>Af,NATIVE_DATA_POLICY_EXPRESSION_MAX_GROUP_ITEMS:()=>Ef,NATIVE_DATA_POLICY_EXPRESSION_MAX_LEAVES:()=>If,NATIVE_DATA_POLICY_EXPRESSION_MAX_OCCURRENCES:()=>bf,NATIVE_DATA_QUERY_OPERATORS_V2:()=>Xi,NATIVE_ROLE_MEMBERSHIP_BATCH_MAX_BYTES:()=>Ap,NATIVE_ROLE_MEMBERSHIP_BATCH_MAX_ITEMS:()=>gp,NATIVE_UNIQUE_KEY_MAX_BYTES:()=>vu,NATIVE_UNIQUE_KEY_NORMALIZERS:()=>vo,NativeConfigurationCompilerError:()=>Wn,NativeDataFieldContractV2Error:()=>ye,NativeDataPolicyExpressionV2Error:()=>_t,NativeDecimalLifecycleContractError:()=>Ke,NativeEventActionContractError:()=>Tn,NativeRoleMembershipBatchInputError:()=>Jn,NativeScopeSourceFieldPathV2Error:()=>yn,NativeUniqueKeyContractError:()=>ct,OPENXIANGDA_NATIVE_DATA_FIELD_TYPES_V2:()=>qi,OPENXIANGDA_NATIVE_DATA_SURFACE_KEYS_V2:()=>Se,OPENXIANGDA_NATIVE_DRAFT_STATE_KEYS_V2:()=>fn,OPENXIANGDA_NATIVE_SYSTEM_FIELDS_V2:()=>an,OPENXIANGDA_NATIVE_SYSTEM_FIELD_MAP_V2:()=>Ot,USER_CANDIDATE_MAX_SELECTIONS:()=>Zl,USER_CANDIDATE_SCOPE_FIELD_TYPES:()=>Fi,UserCandidateContractError:()=>Le,WORKFLOW_APPROVAL_EMPTY_PROVIDERS:()=>Xo,WORKFLOW_APPROVED_DELEGATION_MAX_BYTES:()=>of,WORKFLOW_APPROVED_DELEGATION_MAX_REQUESTS:()=>nf,WORKFLOW_AUTOMATIC_CC_MAX_RECIPIENTS:()=>Ju,WORKFLOW_AUTOMATIC_CC_PROVIDERS:()=>vr,WORKFLOW_BUSINESS_STEP_EVENT:()=>lt,WORKFLOW_BUSINESS_STEP_EVENTS:()=>Uo,WORKFLOW_BUSINESS_STEP_FACTS_KEY:()=>Td,WORKFLOW_BUSINESS_STEP_MAX_BYTES:()=>Rn,WORKFLOW_BUSINESS_STEP_MAX_RECEIPT_BYTES:()=>Or,WORKFLOW_CONFIGURABLE_OPERATIONS:()=>Sn,WORKFLOW_CONFIGURABLE_PROVIDERS:()=>Dn,WORKFLOW_EVENT_TYPES_V2:()=>jn,WORKFLOW_LAUNCH_PREFLIGHT_PROVIDERS:()=>Fr,WORKFLOW_REJECTION_NOTIFICATION_MAX_BYTES:()=>Zu,WORKFLOW_REJECTION_NOTIFICATION_SCHEMA:()=>Lr,WORKFLOW_ROLE_UNION_MAX_ROLES:()=>Bu,WORKFLOW_ROUTING_MAX_BYTES:()=>ff,WORKFLOW_ROUTING_MAX_MATCHED_RULES:()=>uf,WORKFLOW_ROUTING_MAX_RULES:()=>lf,WORKFLOW_STEP_DATA_COMMAND_SCHEMA:()=>Il,WORKFLOW_STEP_DATA_RESOLUTION_SCHEMA:()=>Ps,WORKFLOW_TASK_PAGE_DEFINITION_MAX_BYTES:()=>Mr,WORKFLOW_TASK_PAGE_MAX_BYTES:()=>Ln,WORKFLOW_TASK_PAGE_MAX_FIELDS:()=>Ur,WORKFLOW_TASK_SUBTABLE_MAX_ROWS:()=>ci,WORKFLOW_TASK_SUBTABLE_MAX_TOTAL_ROWS:()=>ai,WorkflowTaskPageError:()=>Oe,applyWorkflowTaskPageValues:()=>Gr,applyWorkflowTaskSubtableRows:()=>qd,assertDevelopmentConfigurationManifest:()=>Js,assertDevelopmentConfigurationResult:()=>Fl,assertNativeRoleMembershipBatchInput:()=>bl,assertWorkflowNativeStageGuard:()=>Ad,assertWorkflowNativeStagePolicy:()=>Do,assertWorkflowNativeStageSourceGuard:()=>Ed,assertWorkflowOwnedSubjectCreate:()=>Bt,assertWorkflowOwnedSubjectCreateResources:()=>mi,canonicalDataBusinessIntent:()=>hl,compileNativeApplicationConfiguration:()=>hc,compileNativeEventAction:()=>Vo,compileNativeEventCapturePlansV2:()=>bs,compileRequiredPlatformCapabilitiesV3:()=>ys,compileWorkflowBusinessStepHandlers:()=>Cn,createDevelopmentConfigurationManifest:()=>Ll,dataOwnedRowLimit:()=>bt,dateEventProjectionEnvelopeSchemaV2:()=>Kd,dateEventProjectionFieldsV2:()=>si,developmentBackendBase64Bytes:()=>Ys,developmentBackendInvocationHeadersValid:()=>Zs,developmentBackendInvocationRequestValid:()=>ql,developmentBackendInvocationRevision:()=>Bl,developmentBackendOperationMatches:()=>Xs,developmentConfigurationKey:()=>Vl,evaluateWorkflowTaskPageExpression:()=>$e,formatWorkflowCompletionDeadline:()=>Vd,formatWorkflowExpression:()=>vt,generatedCrudCapabilityOperations:()=>Ei,hasDataAuditReadPolicy:()=>uo,isDataAuditMetadataField:()=>nt,isDataOwnedRowLimit:()=>tt,isDataSystemSortField:()=>fo,isDataTransactionActorAuthorityGuard:()=>Sl,isDataTransactionRecordSetMatchGuard:()=>$l,isNativeDataQueryOperatorV2:()=>ba,isNativeMultiValueFieldV2:()=>Nt,isWorkflowRejectionNotificationSnapshot:()=>Fd,matchesDataActorAuthorityMembership:()=>Dl,materializeNativeDataQueryPathTypesV2:()=>md,nativeDataPolicyExpressionLeavesV2:()=>Gt,nativeDataPolicyExpressionToCnfV2:()=>Ai,nativeDataQueryPathPlanV2:()=>_d,nativeFieldAggregatePlanV2:()=>Sa,nativeFieldColumnDefinitionV2:()=>Ka,nativeFieldDefaultSqlV2:()=>Ga,nativeFieldHasDefaultV2:()=>za,nativeFieldIndexStatementsV2:()=>Xa,nativeFieldRequiresCreateInputV2:()=>Tt,nativeFieldSequenceGrantStatementsV2:()=>Ya,nativeFieldSequenceOwnershipStatementsV2:()=>Ha,nativeFieldSequenceStatementsV2:()=>Ja,nativeFieldSupportsFilterV2:()=>Ao,nativeFieldSupportsOperatorV2:()=>Ca,nativeFieldSupportsSearchV2:()=>ln,nativeFieldSupportsSortV2:()=>it,nativeOperatorsForFieldV2:()=>go,nativePhysicalFieldV2:()=>ar,nativePhysicalFieldsV2:()=>Ba,nativePhysicalObjectNameV2:()=>ke,nativeScopeSourceFieldValueV2:()=>id,nativeScopeSourceGrantPathSupportedV2:()=>wo,nativeScopeSourceSubjectPathSupportedV2:()=>bn,nativeSubtableConstraintStatementsV2:()=>Za,nativeUniqueKeysContractVersion:()=>Lo,nativeUniqueKeysJsonSchema:()=>yd,normalizeWorkflowOwnedSubjectCreate:()=>oc,parseDataBusinessCommandResolution:()=>wl,parseDataFieldUserCandidates:()=>yt,parseDecimalReservationLifecycle:()=>An,parseNativeDataFieldsV2:()=>dn,parseNativeDataResourceInvariantsV2:()=>lo,parseNativeUniqueKeys:()=>Po,parseWorkflowStepDataResolution:()=>yl,projectDataResourceView:()=>qs,projectNativeDataResourceViewV2:()=>mn,projectWorkflowGraph:()=>Sd,projectWorkflowNodePolicy:()=>Yo,quoteNativeIdentifierV2:()=>se,refreshWorkflowTaskPageFacts:()=>zd,requiresAggregateOwnedSubtableCapacity:()=>en,requiresDateTimeMinutePrecision:()=>rn,requiresDevelopmentBackendCredential:()=>Ml,requiresExtendedArtifactCapacity:()=>qt,requiresExtendedDeclarationCapacity:()=>Fn,requiresExtendedOwnedSubtableCapacity:()=>tn,requiresOwnedSubtableMinimumRows:()=>sn,requiresUserCandidateLaunchScope:()=>Zt,requiresWorkflowRoleInputSelection:()=>Ho,requiresWorkflowRoleUnion:()=>zo,resolveNativeScopeSourceFieldPathV2:()=>at,resolveWorkflowUserCandidates:()=>Wi,selectWorkflowAssignmentRoutingRules:()=>tc,serializedDataBytes:()=>ca,userCandidateScopeValue:()=>da,validateAuthenticatedPublicRead:()=>ko,validateDecimalReservationLifecycles:()=>Co,validateManagedConcurrency:()=>Oo,validateNativeDataDraftStateV2:()=>Io,validateNativeDataResourceReferencesV2:()=>co,validateNativeDataResourceSurfaceV2:()=>pn,validateUserCandidateReferences:()=>oo,validateWorkflowAdministration:()=>kn,validateWorkflowApprovalEmptyPolicy:()=>vn,validateWorkflowApprovedDelegation:()=>ii,validateWorkflowAssignmentRoutingBindings:()=>fi,validateWorkflowAssignmentRoutingPolicy:()=>Mt,validateWorkflowAssignmentRoutingRules:()=>Qd,validateWorkflowAutomaticCc:()=>$n,validateWorkflowBusinessStepHandlerContract:()=>Cd,validateWorkflowBusinessStepRequest:()=>Rd,validateWorkflowBusinessStepResult:()=>Rr,validateWorkflowBusinessStepSchema:()=>Dt,validateWorkflowBusinessStepSubscriptions:()=>Bo,validateWorkflowBusinessSteps:()=>$t,validateWorkflowCommandHandlers:()=>ni,validateWorkflowCompletionDeadlines:()=>Qo,validateWorkflowCorrections:()=>ri,validateWorkflowInitiatorApprovalPolicy:()=>ft,validateWorkflowInstanceCommandPolicies:()=>xo,validateWorkflowLaunchPreflight:()=>Pn,validateWorkflowNodeConfigurationPatch:()=>Pd,validateWorkflowReadability:()=>qo,validateWorkflowRejectionNotification:()=>ti,validateWorkflowRoleInputSelection:()=>Jo,validateWorkflowRoleUnion:()=>Pt,validateWorkflowTaskPages:()=>jt,validateWorkflowUserCandidateBindings:()=>io,workflowApprovalCanSkip:()=>Ld,workflowApprovedDelegationRequests:()=>Ud,workflowAssignmentRoutingFacts:()=>ec,workflowAssignmentRoutingPolicySchema:()=>Zd,workflowAssignmentRoutingSemantic:()=>Hr,workflowBindingAllowsEmptyUsers:()=>Zo,workflowBindingRoleCodes:()=>$d,workflowBusinessCommandInvocationSchema:()=>xd,workflowBusinessStepFactSchema:()=>kt,workflowBusinessStepHandlerDigest:()=>Rl,workflowBusinessStepInput:()=>hd,workflowBusinessStepPath:()=>Cr,workflowBusinessStepReceiptSignatureSuffix:()=>Tl,workflowBusinessStepValueMatches:()=>St,workflowDelegationMutationRequestSchema:()=>Bs,workflowExpressionPaths:()=>Go,workflowInitiatorApprovalCanComplete:()=>Dd,workflowInstanceCommandDeadlineError:()=>Nd,workflowInstanceTerminateCapabilityAllowed:()=>bd,workflowInstanceWithdrawalReasonRequired:()=>Od,workflowNativeStagePolicySchema:()=>Id,workflowNodeAllowedOperations:()=>pt,workflowOperationCommentRequired:()=>Dr,workflowOperationReasonRequired:()=>kr,workflowOwnedSubjectCreateSchema:()=>nc,workflowPolicyTimestamp:()=>Fo,workflowRoleCodesSchema:()=>kd,workflowTaskPageFieldState:()=>li,workflowTaskPageReplayCoversInvalidation:()=>Jd,workflowTaskSubtableRows:()=>Gd,workflowVariableLabel:()=>wr});module.exports=sa(Jl);var Li=require("node:crypto");function aa(e){if(!e||typeof e!="object")return!1;let t=Object.getPrototypeOf(e);return t===Object.prototype||t===null}function eo(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)=>eo(n,`${t}[${i}]`)).join(",")}]`;if(aa(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)}:${eo(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 eo(e,"$")}function Z(e){return(0,Li.createHash)("sha256").update(Q(e)).digest("hex")}var Zl=200,Fi=["text.short","uuid","option.single","resource-ref.single"],to=/^[a-z][a-z0-9]*(?:[-_.][a-z0-9]+)*$/,xi=/^[A-Za-z][A-Za-z0-9_]{0,62}$/,ji=new Set(["__proto__","prototype","constructor"]),no=e=>!!e&&typeof e=="object"&&!Array.isArray(e)&&[Object.prototype,null].includes(Object.getPrototypeOf(e)),Vi=(e,t)=>Object.keys(e).every(o=>t.includes(o)),et=(e,t)=>typeof e=="string"&&e.length>0&&e.trim()===e&&e.length<=t,Le=class extends Error{constructor(o,n){super(`${o}: ${n}`);this.code=o;this.pointer=n}code;pointer};function te(e,t){throw new Le(e,t)}function yt(e,t,o){if(e===void 0)return;["user.single","user.multiple"].includes(t)||te("DATA_USER_CANDIDATES_FIELD_TYPE_INVALID",o),(!no(e)||!Vi(e,["kind","roleCode","scope","pageSize"])||e.kind!=="app-role"||!et(e.roleCode,128)||!to.test(String(e.roleCode)))&&te("DATA_USER_CANDIDATES_SOURCE_INVALID",o),e.pageSize!==void 0&&(!Number.isSafeInteger(e.pageSize)||Number(e.pageSize)<1||Number(e.pageSize)>50)&&te("DATA_USER_CANDIDATES_PAGE_SIZE_INVALID",`${o}/pageSize`);let n;if(e.scope!==void 0){let i=e.scope;(!no(i)||!Vi(i,["dimensionCode","operation","field","value","creation"])||!et(i.dimensionCode,128)||!to.test(String(i.dimensionCode))||!et(i.operation,64)||!to.test(String(i.operation))||Object.hasOwn(i,"field")===Object.hasOwn(i,"value"))&&te("DATA_USER_CANDIDATES_SCOPE_INVALID",`${o}/scope`),i.creation!==void 0&&(i.creation!=="prospective"||!Object.hasOwn(i,"field"))&&te("DATA_USER_CANDIDATES_SCOPE_INVALID",`${o}/scope/creation`),Object.hasOwn(i,"field")?((!et(i.field,63)||!xi.test(String(i.field))||ji.has(String(i.field)))&&te("DATA_USER_CANDIDATES_SCOPE_FIELD_INVALID",`${o}/scope/field`),n={dimensionCode:String(i.dimensionCode),operation:String(i.operation),field:String(i.field),...i.creation==="prospective"?{creation:"prospective"}:{}}):(et(i.value,255)||te("DATA_USER_CANDIDATES_SCOPE_VALUE_INVALID",`${o}/scope/value`),n={dimensionCode:String(i.dimensionCode),operation:String(i.operation),value:String(i.value)})}return{kind:"app-role",roleCode:String(e.roleCode),...n?{scope:n}:{},...e.pageSize===void 0?{}:{pageSize:Number(e.pageSize)}}}function Zt(e){return e.some(t=>t.schema.fields.some(o=>{let n=o.userCandidates?.scope;return n?.creation==="prospective"||!!(n?.field&&t.schema.fields.find(i=>i.code===n.field)?.type==="resource-ref.single")}))}function oo(e,t,o,n){for(let[i,r]of e.entries()){let d=`${n}/${i}/userCandidates`,s=yt(r.userCandidates,r.type,d);if(s&&(t.has(s.roleCode)||te("DATA_USER_CANDIDATES_ROLE_UNDECLARED",`${d}/roleCode`),s.scope&&!o.has(s.scope.dimensionCode)&&te("DATA_USER_CANDIDATES_DIMENSION_UNDECLARED",`${d}/scope/dimensionCode`),s.scope?.field)){let a=e.find(c=>c.code===s.scope.field);(!a||!Fi.some(c=>c===a.type))&&te("DATA_USER_CANDIDATES_SCOPE_FIELD_INVALID",`${d}/scope/field`)}}}function Wi(e,t,o,n){let i=e.subject.factProjection,r=typeof t.inputPath=="string"&&Object.entries(i).some(([c,f])=>(t.inputPath===c||t.inputPath.startsWith(`${c}.`))&&o.get(f)?.userCandidates!==void 0);if(t.candidateField===void 0&&!r)return;(t.provider!=="form_field_users"||!t.candidateField||!xi.test(t.candidateField)||ji.has(t.candidateField)||!t.inputPath||i[t.inputPath]!==t.candidateField)&&te("WORKFLOW_USER_CANDIDATES_FIELD_BINDING_REQUIRED",n),(t.roleCode!==void 0||t.scope!==void 0||t.routing!==void 0)&&te("WORKFLOW_USER_CANDIDATES_SOURCE_OVERRIDE_FORBIDDEN",n);let d=o.get(t.candidateField),s=d&&yt(d.userCandidates,d.type,`${n}/candidateField`);s||te("WORKFLOW_USER_CANDIDATES_FIELD_UNDECLARED",`${n}/candidateField`);let a;if(s.scope?.field){let c=Object.entries(i).filter(([,f])=>f===s.scope.field).map(([f])=>f);c.length!==1&&te("WORKFLOW_USER_CANDIDATES_SCOPE_PROJECTION_REQUIRED",n),a=c[0]}return{fieldCode:d.code,inputPath:t.inputPath,source:s,...a?{scopeInputPath:a}:{}}}function io(e,t,o,n,i=new Map){for(let[r,d]of Object.entries(t.bindings))Wi(e,d,o,`${n}/${r}`);for(let[r,d]of Object.entries(e.taskPages||{})){let s=new Set(d.fields.filter(a=>a.readonly!==!0).map(a=>a.code));for(let a of d.fields){let c=o.get(a.code)?.userCandidates?.scope;if(s.has(a.code)&&c?.field&&s.has(c.field)&&te("WORKFLOW_USER_CANDIDATES_SCOPE_WRITE_FORBIDDEN",`${n}/taskPages/${r}/${a.code}`),!s.has(a.code)||!a.subtable)continue;let f=o.get(a.code)?.subtable?.resourceCode,u=f?i.get(f):void 0;a.subtable.fields.some(p=>p.readonly!==!0&&u?.get(p.code)?.userCandidates)&&te("WORKFLOW_USER_CANDIDATES_OWNED_FIELD_UNSUPPORTED",`${n}/taskPages/${r}/${a.code}`)}}}function da(e,t){if(!e.scope)return;let o=e.scope.field?t[e.scope.field]:e.scope.value,n=no(o)?o.value:o;return et(n,255)||te("DATA_USER_CANDIDATES_SCOPE_VALUE_REQUIRED",e.scope.field||"scope"),String(n)}var Me=500,eu=500,Qt=1e3,Ui=2016,tu=2097152,nu=2097152;function tt(e){return typeof e=="number"&&Number.isSafeInteger(e)&&e>=1&&e<=1e3}function bt(e){if(e.ownedRowLimit===void 0)return 500;if(!tt(e.ownedRowLimit))throw new Error("NATIVE_DATA_OWNED_ROW_LIMIT_INVALID");return e.ownedRowLimit}function en(e){return e.some(t=>(t.schema.ownedRowLimit??500)>500)}function tn(e){return e.some(t=>{let o=t.schema.fields.filter(n=>n.type==="subtable").map(n=>n.subtable?.maxRows??20);return o.some(n=>n>100)||o.reduce((n,i)=>n+i,0)>400})}function ca(e){try{return new TextEncoder().encode(JSON.stringify(e)).byteLength}catch{return 1/0}}var Gi=/^[A-Za-z][A-Za-z0-9_]{0,62}$/,ao=/^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/,qi=["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"];function rn(e){return e.some(t=>t.schema.fields.some(o=>(o.type==="datetime"||o.type==="datetime-range")&&o.timePrecision==="minute"))}function sn(e){return e.some(t=>t.schema.fields.some(o=>o.type==="subtable"&&(o.subtable?.minRows??0)>0))}var la=new Set(qi),zi=new Set(["option.multiple","cascade.multiple","user.multiple","department.multiple","resource-ref.multiple","file","image","subtable"]),Mi=new Set(["option.single","option.multiple","cascade.single","cascade.multiple"]),Bi=new Set(["resource-ref.single","resource-ref.multiple"]),an=[{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}],Ot=new Map(an.map(e=>[e.code,e])),ye=class extends Error{constructor(o,n){super(o);this.code=o;this.pointer=n;this.name="NativeDataFieldContractV2Error"}code;pointer};function Nt(e){return zi.has(e)}function Tt(e,t={}){return e.type!=="serial-number"&&t.system!==!0&&e.nullable===!1&&(!Nt(e.type)||t.requiredHint===!0)}function dn(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 d=`${t}/${r}`,s=ge(i,d);Ie(s,["code","type","nullable","indexed","options","source","userCandidates","maxLength","precision","scale","exactDecimal","min","max","rangeBoundary","timePrecision","file","serial","subtable"],d);let a=be(s.code,`${d}/code`,63);Gi.test(a)||D("NATIVE_FIELD_CODE_INVALID",`${d}/code`),n.has(a)&&D("NATIVE_DATA_FIELD_DUPLICATE",`${d}/code`),n.add(a);let c=be(s.type,`${d}/type`,32);la.has(c)||D("NATIVE_DATA_FIELD_TYPE_INVALID",`${d}/type`);let f=c,u=so(s.nullable,`${d}/nullable`),p=so(s.indexed,`${d}/indexed`);u===!0&&zi.has(f)&&D("NATIVE_DATA_MULTI_FIELD_NULLABLE_INVALID",`${d}/nullable`);let _=pa(s.options,f,d),E=ma(s.source,f,d),A=yt(s.userCandidates,f,`${d}/userCandidates`),O=ga(s,f,d),b=so(s.exactDecimal,`${d}/exactDecimal`);b!==void 0&&f!=="number.decimal"&&D("NATIVE_DATA_FIELD_EXACT_DECIMAL_TYPE_INVALID",`${d}/exactDecimal`);let g=ua(s.rangeBoundary,f,d),I=Aa(s.file,f,d),T=Ea(s.serial,f,d),l=Ia(s.subtable,f,d);return{code:a,type:f,...u===void 0?{}:{nullable:u},...p===void 0?{}:{indexed:p},..._?{options:_}:{},...E?{source:E}:{},...A?{userCandidates:A}:{},...O,...b===void 0?{}:{exactDecimal:b},...g?{rangeBoundary:g}:{},...I?{file:I}:{},...T?{serial:T}:{},...l?{subtable:l}:{}}})}function ua(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 co(e,t){Array.isArray(e)||D("NATIVE_ARRAY_REQUIRED",t);let o=new Map;e.forEach((n,i)=>{let r=`${t}/${i}`,d=ge(n,r),s=be(d.code,`${r}/code`,64);(!ao.test(s)||o.has(s))&&D("NATIVE_RESOURCE_CODE_INVALID",`${r}/code`);let a=ge(d.schema,`${r}/schema`);a.ownedRowLimit!==void 0&&!tt(a.ownedRowLimit)&&D("NATIVE_DATA_OWNED_ROW_LIMIT_INVALID",`${r}/schema/ownedRowLimit`),o.set(s,{pointer:r,ownedRowLimit:bt(a),fields:dn(a.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,a)=>s+(a.subtable?.maxRows??20),0)>i.ownedRowLimit&&D("NATIVE_DATA_FIELD_SUBTABLE_AGGREGATE_MAX_ROWS_EXCEEDED",`${i.pointer}/schema/fields`),i.fields.forEach((s,a)=>{let c=`${i.pointer}/schema/fields/${a}`;if(s.source&&fa(s.source,r,o,`${c}/source`),s.subtable){let f=o.get(s.subtable.resourceCode);(!f||s.subtable.resourceCode===n)&&D("NATIVE_DATA_FIELD_SUBTABLE_TARGET_MISSING",`${c}/subtable/resourceCode`);let u=f.fields.find(_=>_.code===s.subtable?.foreignKey);(!u||u.type!=="uuid"||u.nullable!==!1)&&D("NATIVE_DATA_FIELD_SUBTABLE_FOREIGN_KEY_INVALID",`${c}/subtable/foreignKey`);let p=f.fields.find(_=>_.code===s.subtable?.orderField);(!p||p.type!=="number.integer"||p.nullable!==!1)&&D("NATIVE_DATA_FIELD_SUBTABLE_ORDER_FIELD_INVALID",`${c}/subtable/orderField`)}})}}function lo(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,d)=>{let s=`${o}/${d}`,a=ge(r,s);Ie(a,["code","message","expression"],s);let c=be(a.code,`${s}/code`,128);(!/^[a-z][a-z0-9]*(?:[._-][a-z0-9]+)*$/.test(c)||i.has(c))&&D("NATIVE_DATA_RESOURCE_INVARIANT_CODE_INVALID",`${s}/code`),i.add(c);let f=on(a.message,`${s}/message`,500);f!==void 0&&f.length===0&&D("NATIVE_DATA_RESOURCE_INVARIANT_MESSAGE_INVALID",`${s}/message`);let u=ge(a.expression,`${s}/expression`);if(u.kind==="nonBlankTextWhenOption"){Ie(u,["kind","optionField","optionValue","textField"],`${s}/expression`);let g=Re(u.optionField,`${s}/expression/optionField`),I=Re(u.textField,`${s}/expression/textField`),T=be(u.optionValue,`${s}/expression/optionValue`,128),l=n.get(g),y=n.get(I);return(!l||!y)&&D("NATIVE_DATA_RESOURCE_INVARIANT_FIELD_UNKNOWN",`${s}/expression`),(l.type!=="option.single"||!["text.short","text.long"].includes(y.type)||!l.options?.some(R=>R.value===T))&&D("NATIVE_DATA_RESOURCE_INVARIANT_FIELD_TYPES_INVALID",`${s}/expression`),{code:c,...f===void 0?{}:{message:f},expression:{kind:"nonBlankTextWhenOption",optionField:g,optionValue:T,textField:I}}}Ie(u,["leftField","operator","rightField"],`${s}/expression`);let p=Re(u.leftField,`${s}/expression/leftField`),_=Re(u.rightField,`${s}/expression/rightField`),E=n.get(p),A=n.get(_);(!E||!A)&&D("NATIVE_DATA_RESOURCE_INVARIANT_FIELD_UNKNOWN",`${s}/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",`${s}/expression`);let b=String(u.operator);return["eq","neq","gt","gte","lt","lte"].includes(b)||D("NATIVE_DATA_RESOURCE_INVARIANT_OPERATOR_INVALID",`${s}/expression/operator`),!["eq","neq"].includes(b)&&!["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",`${s}/expression`),{code:c,...f===void 0?{}:{message:f},expression:{leftField:p,operator:b,rightField:_}}})}function fa(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])),d=r.get(e.labelField);(!d||!["text.short","text.long"].includes(d.type))&&D("NATIVE_DATA_FIELD_SOURCE_LABEL_INVALID",`${n}/labelField`);for(let s of["searchFields","descriptionFields","snapshotFields"])for(let a of e[s]||[])r.has(a)||D("NATIVE_DATA_FIELD_SOURCE_FIELD_MISSING",`${n}/${s}`);for(let[s,a]of(e.filters||[]).entries())r.has(a.field)||D("NATIVE_DATA_FIELD_SOURCE_FILTER_FIELD_MISSING",`${n}/filters/${s}/field`),"binding"in a&&!t.has(a.binding.field)&&D("NATIVE_DATA_FIELD_SOURCE_BINDING_FIELD_MISSING",`${n}/filters/${s}/binding/field`)}function pa(e,t,o){let n=`${o}/options`;if(e===void 0){Mi.has(t)&&D("NATIVE_DATA_FIELD_OPTIONS_REQUIRED",n);return}(!Mi.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=(d,s,a)=>{a>5&&D("NATIVE_DATA_FIELD_OPTIONS_DEPTH_EXCEEDED",s);let c=new Set;return d.map((f,u)=>{i+=1,i>1e3&&D("NATIVE_DATA_FIELD_OPTIONS_COUNT_EXCEEDED",n);let p=`${s}/${u}`,_=ge(f,p);Ie(_,["label","value","description","color","children"],p);let E=be(_.label,`${p}/label`,500),A=be(_.value,`${p}/value`,500);c.has(A)&&D("NATIVE_DATA_FIELD_OPTION_VALUE_DUPLICATE",`${p}/value`),c.add(A);let O=on(_.description,`${p}/description`,2e3),b=on(_.color,`${p}/color`,64),g;return _.children!==void 0&&((!t.startsWith("cascade.")||!Array.isArray(_.children))&&D("NATIVE_DATA_FIELD_OPTION_CHILDREN_INVALID",`${p}/children`),(_.children.length<1||_.children.length>100)&&D("NATIVE_DATA_FIELD_OPTION_CHILDREN_INVALID",`${p}/children`),g=r(_.children,`${p}/children`,a+1)),{label:E,value:A,...O===void 0?{}:{description:O},...b===void 0?{}:{color:b},...g?{children:g}:{}}})};return r(e,n,1)}function ma(e,t,o){let n=`${o}/source`;if(e===void 0){Bi.has(t)&&D("NATIVE_DATA_FIELD_SOURCE_REQUIRED",n);return}Bi.has(t)||D("NATIVE_DATA_FIELD_SOURCE_TYPE_INVALID",n);let i=ge(e,n);Ie(i,["kind","resourceCode","labelField","searchFields","descriptionFields","snapshotFields","filters","pageSize","loadMode","clearOnBindingChange"],n),i.kind!=="resource"&&D("NATIVE_DATA_FIELD_SOURCE_KIND_INVALID",`${n}/kind`);let r=be(i.resourceCode,`${n}/resourceCode`,64);ao.test(r)||D("NATIVE_RESOURCE_CODE_INVALID",`${n}/resourceCode`);let d=Re(i.labelField,`${n}/labelField`),s=ro(i.searchFields,`${n}/searchFields`,10),a=ro(i.descriptionFields,`${n}/descriptionFields`,10),c=ro(i.snapshotFields,`${n}/snapshotFields`,50),f=Be(i.pageSize,`${n}/pageSize`,1,100),u;i.loadMode!==void 0&&(["search","all"].includes(String(i.loadMode))||D("NATIVE_DATA_FIELD_SOURCE_LOAD_MODE_INVALID",`${n}/loadMode`),u=i.loadMode);let p=_a(i.filters,`${n}/filters`);return i.clearOnBindingChange!==void 0&&typeof i.clearOnBindingChange!="boolean"&&D("NATIVE_DATA_FIELD_SOURCE_BINDING_RESET_INVALID",`${n}/clearOnBindingChange`),{kind:"resource",resourceCode:r,labelField:d,...s?{searchFields:s}:{},...a?{descriptionFields:a}:{},...c?{snapshotFields:c}:{},...p?{filters:p}:{},...f===void 0?{}:{pageSize:f},...u?{loadMode:u}:{},...i.clearOnBindingChange===void 0?{}:{clearOnBindingChange:i.clearOnBindingChange}}}function _a(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=ge(o,i),d=Object.prototype.hasOwnProperty.call(r,"value"),s=Object.prototype.hasOwnProperty.call(r,"binding");Ie(r,d?["field","operator","value"]:["field","operator","binding"],i),d===s&&D("NATIVE_DATA_FIELD_SOURCE_FILTER_VALUE_INVALID",i);let a=Re(r.field,`${i}/field`);["eq","in"].includes(String(r.operator))||D("NATIVE_DATA_FIELD_SOURCE_FILTER_OPERATOR_INVALID",`${i}/operator`);let c=r.operator;if(d)return{field:a,operator:c,value:r.value};let f=ge(r.binding,`${i}/binding`);return Ie(f,["kind","field"],`${i}/binding`),f.kind!=="field"&&D("NATIVE_DATA_FIELD_SOURCE_BINDING_KIND_INVALID",`${i}/binding/kind`),{field:a,operator:c,binding:{kind:"field",field:Re(f.field,`${i}/binding/field`)}}})}function ga(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=nn(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=nn(e.precision,`${o}/precision`,1,1e3),n.scale=e.scale===void 0?0:nn(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=Ki(e.min,`${o}/min`),r=Ki(e.max,`${o}/max`);t==="number.integer"&&[i,r].some(d=>d!==void 0&&!Number.isSafeInteger(d))&&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&&((!["time","datetime","datetime-range"].includes(t)||!["minute","second"].includes(e.timePrecision))&&D("NATIVE_DATA_FIELD_TIME_PRECISION_INVALID",`${o}/timePrecision`),n.timePrecision=e.timePrecision),n}function Aa(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=ge(e,n);Ie(i,["maxCount","maxSizeMb","accept"],n);let r=Be(i.maxCount,`${n}/maxCount`,1,100);t==="signature"&&r!==void 0&&r!==1&&D("NATIVE_DATA_FIELD_SIGNATURE_COUNT_INVALID",`${n}/maxCount`);let d=Be(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((a,c)=>be(a,`${n}/accept/${c}`,255)),new Set(s).size!==s.length&&D("NATIVE_DATA_FIELD_FILE_ACCEPT_INVALID",`${n}/accept`)),{...r===void 0?{}:{maxCount:r},...d===void 0?{}:{maxSizeMb:d},...s===void 0?{}:{accept:s}}}function Ea(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=ge(e,n);Ie(i,["prefix","digits","start"],n);let r=on(i.prefix,`${n}/prefix`,64),d=Be(i.digits,`${n}/digits`,1,32),s=Be(i.start,`${n}/start`,0,Number.MAX_SAFE_INTEGER);return{...r===void 0?{}:{prefix:r},...d===void 0?{}:{digits:d},...s===void 0?{}:{start:s}}}function Ia(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=ge(e,n);Ie(i,["resourceCode","foreignKey","orderField","minRows","maxRows"],n);let r=be(i.resourceCode,`${n}/resourceCode`,64);ao.test(r)||D("NATIVE_RESOURCE_CODE_INVALID",`${n}/resourceCode`);let d=Re(i.foreignKey,`${n}/foreignKey`),s=Re(i.orderField,`${n}/orderField`);s===d&&D("NATIVE_DATA_FIELD_SUBTABLE_ORDER_FIELD_INVALID",`${n}/orderField`);let a=Be(i.maxRows,`${n}/maxRows`,1,500),c=Be(i.minRows,`${n}/minRows`,0,500);return(c??0)>(a??20)&&D("NATIVE_DATA_FIELD_SUBTABLE_MIN_ROWS_INVALID",`${n}/minRows`),{resourceCode:r,foreignKey:d,orderField:s,...c===void 0?{}:{minRows:c},...a===void 0?{}:{maxRows:a}}}function ro(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)=>Re(i,`${t}/${r}`));return new Set(n).size!==n.length&&D("NATIVE_DATA_FIELD_SOURCE_FIELDS_INVALID",t),n}function Re(e,t){let o=be(e,t,63);return Gi.test(o)||D("NATIVE_FIELD_CODE_INVALID",t),o}function ge(e,t){return(!e||typeof e!="object"||Array.isArray(e))&&D("NATIVE_OBJECT_REQUIRED",t),e}function Ie(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 be(e,t,o){return(typeof e!="string"||e.length===0||e.length>o)&&D("NATIVE_STRING_INVALID",t),e}function on(e,t,o){if(e!==void 0)return(typeof e!="string"||e.length>o)&&D("NATIVE_STRING_INVALID",t),e}function so(e,t){if(e!==void 0)return typeof e!="boolean"&&D("NATIVE_BOOLEAN_REQUIRED",t),e}function Be(e,t,o,n){if(e!==void 0)return nn(e,t,o,n)}function Ki(e,t){if(e!==void 0)return(typeof e!="number"||!Number.isFinite(e))&&D("NATIVE_NUMBER_REQUIRED",t),e}function nn(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 ye(e,t)}var Rt=["created_by","updated_by","created_at","updated_at"];function nt(e){return Rt.includes(e)}function uo(e){return Rt.some(t=>Object.prototype.hasOwnProperty.call(e.fieldPolicies||{},t))}var Ji=an.map(e=>e.code);function fo(e){return Ji.includes(e)}var Xi=["eq","neq","gt","gte","lt","lte","contains","startsWith","endsWith","in","between","has","hasAny","hasAll","overlaps","containedBy","jsonContains","isEmpty","isNotEmpty"],ya=new Set(Xi);function ba(e){return ya.has(String(e))}var po=["eq","neq","contains","startsWith","endsWith","in","isEmpty","isNotEmpty"],Ct=["eq","neq","gt","gte","lt","lte","between","in","isEmpty"],Oa=["eq","neq","in","isEmpty"],cn=["eq","neq","in","isEmpty","isNotEmpty"],ot=["has","hasAny","hasAll","isEmpty","isNotEmpty"],Hi=["overlaps","contains","containedBy","isEmpty"],mo=["jsonContains","isEmpty","isNotEmpty"],_o=["isEmpty","isNotEmpty"],Na={"text.short":po,"text.long":po,"text.rich":po,"number.integer":Ct,"number.decimal":Ct,boolean:Oa,date:Ct,time:Ct,datetime:Ct,"date-range":Hi,"datetime-range":Hi,"option.single":cn,"option.multiple":ot,"cascade.single":ot,"cascade.multiple":ot,"user.single":cn,"user.multiple":ot,"department.single":cn,"department.multiple":ot,"resource-ref.single":cn,"resource-ref.multiple":ot,file:_o,image:_o,signature:_o,address:mo,location:mo,uuid:["eq","neq","in","isEmpty"],json:mo,"serial-number":["eq","neq","in","contains","startsWith"],subtable:[]},Ta=new Set(["text.short","text.long","text.rich","option.single","user.single","department.single","resource-ref.single","serial-number"]),Ra=new Set(["option.multiple","cascade.single","cascade.multiple","user.multiple","department.multiple","resource-ref.multiple","file","image","signature","address","location","json","subtable"]);function go(e){return Na[e]}function Ca(e,t){return go(e).includes(t)}function ln(e){return Ta.has(e)}function it(e){return!Ra.has(e)}function Ao(e){return go(e).length>0}var Yi=new Set(["number.integer","number.decimal"]),Zi=new Set(["text.short","text.long","number.integer","number.decimal","date","time","datetime","serial-number"]),ha=new Set([...Zi,"boolean","uuid"]),wa=new Set(["option.single","user.single","department.single","resource-ref.single"]);function Sa(e,t){return t==="sum"||t==="avg"?Yi.has(e)?{valueExpression:"column",numericResult:!0}:null:t==="min"||t==="max"?Zi.has(e)?{valueExpression:"column",numericResult:Yi.has(e)}:null:wa.has(e)?{valueExpression:"snapshot-value",numericResult:!0}:ha.has(e)?{valueExpression:"column",numericResult:!0}:null}var fn=["version","maxBytes","fields"];function Io(e,t){if(e===void 0)return;let o=Eo(e,t);Qi(o,fn,t);let n=un(o.version,`${t}/version`,1,1e6),i=un(o.maxBytes,`${t}/maxBytes`,2,196608);(!n||!i)&&de("NATIVE_DATA_DRAFT_STATE_SCHEMA_INVALID",t);let r=Eo(o.fields,`${t}/fields`),d=Object.entries(r);(!d.length||d.length>50)&&de("NATIVE_DATA_DRAFT_STATE_FIELDS_INVALID",`${t}/fields`);for(let[s,a]of d){let c=`${t}/fields/${s}`;/^[A-Za-z][A-Za-z0-9_]{0,62}$/.test(s)||de("NATIVE_DATA_DRAFT_STATE_FIELD_CODE_INVALID",c);let f=Eo(a,c),u=er(f.type,`${c}/type`,32),p=u==="string"?["type","required","maxLength","enum"]:u==="json.object"?["type","required","maxBytes"]:["type","required"];if(["string","number","integer","boolean","json.object"].includes(u)||de("NATIVE_DATA_DRAFT_STATE_FIELD_TYPE_INVALID",`${c}/type`),Qi(f,p,c),ka(f.required,`${c}/required`),u==="string"){let _=un(f.maxLength,`${c}/maxLength`,1,196608);_||de("NATIVE_DATA_DRAFT_STATE_FIELD_INVALID",c),f.enum!==void 0&&Da(f.enum,`${c}/enum`,100,!1).some(A=>A.length>_)&&de("NATIVE_DATA_DRAFT_STATE_FIELD_INVALID",`${c}/enum`)}else if(u==="json.object"){let _=un(f.maxBytes,`${c}/maxBytes`,2,65536);(!_||_>i)&&de("NATIVE_DATA_DRAFT_STATE_FIELD_INVALID",c)}}}function Da(e,t,o,n){(!Array.isArray(e)||!n&&e.length===0||e.length>o)&&de("NATIVE_DATA_SURFACE_STRING_ARRAY_INVALID",t);let i=e.map((r,d)=>er(r,`${t}/${d}`,255));return new Set(i).size!==i.length&&de("NATIVE_DATA_SURFACE_STRING_ARRAY_INVALID",t),i}function Eo(e,t){return(!e||typeof e!="object"||Array.isArray(e))&&de("NATIVE_OBJECT_REQUIRED",t),e}function Qi(e,t,o){let n=new Set(t);for(let i of Object.keys(e))n.has(i)||de("NATIVE_PROPERTY_UNKNOWN",`${o}/${i}`)}function er(e,t,o){return(typeof e!="string"||e.length===0||e.length>o)&&de("NATIVE_STRING_INVALID",t),e}function ka(e,t){e!==void 0&&typeof e!="boolean"&&de("NATIVE_BOOLEAN_REQUIRED",t)}function un(e,t,o,n){return(!Number.isSafeInteger(e)||Number(e)<o||Number(e)>n)&&de("NATIVE_INTEGER_INVALID",t),Number(e)}function de(e,t){throw new ye(e,t)}var $a=500,Se={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","userCandidates","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:fn,mobile:["enabled"]},va={"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 pn(e,t,o){if(e===void 0)return;let n=re(e,o);Ce(n,Se.surface,o);let i=n.mutationOwner===void 0?"native":De(n.mutationOwner,`${o}/mutationOwner`,16);["native","action","readonly","workflow","queued-command"].includes(i)||j("NATIVE_DATA_SURFACE_MUTATION_OWNER_INVALID",`${o}/mutationOwner`);let r=n.generated===void 0?{}:re(n.generated,`${o}/generated`);Ce(r,Se.generated,`${o}/generated`);for(let a of Se.generated)bo(r[a],`${o}/generated/${a}`);if(i!=="native")for(let a of["create","update","delete"])r[a]===!0&&j("NATIVE_DATA_SURFACE_MUTATION_OWNER_CONFLICT",`${o}/generated/${a}`);let d=new Map(t.map(a=>[a.code,a])),s=re(n.fields,`${o}/fields`);for(let a of Object.keys(s))d.has(a)||j("NATIVE_DATA_SURFACE_FIELD_MISSING",`${o}/fields/${a}`);for(let a of t)Object.prototype.hasOwnProperty.call(s,a.code)||j("NATIVE_DATA_SURFACE_FIELD_REQUIRED",`${o}/fields/${a.code}`),La(s[a.code],a,`${o}/fields/${a.code}`);for(let a of["create","update"]){let c=r[a]??i==="native",f=t.some(u=>{let p=re(s[u.code],`${o}/fields/${u.code}`);return nr(u,p,a)});c&&!f&&j("NATIVE_DATA_SURFACE_WRITABLE_FIELDS_REQUIRED",`${o}/generated/${a}`)}if(Va(n.list,d,`${o}/list`),tr(n.form,d,`${o}/form`,"form"),tr(n.detail,d,`${o}/detail`,"detail"),n.mobile!==void 0){let a=re(n.mobile,`${o}/mobile`);Ce(a,Se.mobile,`${o}/mobile`),bo(a.enabled,`${o}/mobile/enabled`)}Pa(n,t,o)}function mn(e,t){let o=e.views?.find(i=>i.code===t);o||j("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 d={...r};delete d.section;let s=n.get(i);return[i,{...d,...s?{section:s}:{},list:o.list.fieldOrder.includes(i)}]}))}}function Pa(e,t,o){if(e.views===void 0)return;(!Array.isArray(e.views)||e.views.length>20)&&j("NATIVE_DATA_VIEWS_LIMIT_INVALID",`${o}/views`);let n=new Set;e.views.forEach((i,r)=>{let d=`${o}/views/${r}`,s=re(i,d);Ce(s,["code","name","generated","list","form","detail","mobile","sections"],d);let a=De(s.code,`${d}/code`,64);(!/^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/.test(a)||n.has(a))&&j("NATIVE_DATA_VIEW_CODE_INVALID",`${d}/code`),n.add(a),De(s.name,`${d}/name`,255),re(s.generated,`${d}/generated`),re(s.mobile,`${d}/mobile`);for(let f of["list","detail","create","update","delete"])typeof s.generated[f]!="boolean"&&j("NATIVE_DATA_VIEW_OPERATION_INVALID",`${d}/generated/${f}`);typeof s.mobile.enabled!="boolean"&&j("NATIVE_DATA_VIEW_MOBILE_INVALID",`${d}/mobile/enabled`);for(let f of["list","form","detail"]){let u=re(s[f],`${d}/${f}`),p=rt(u.fieldOrder,`${d}/${f}/fieldOrder`,500,!0);for(let _ of p){let E=e.fields[_];(!E||(E.hidden??E.system)===!0)&&j("NATIVE_DATA_VIEW_FIELD_INVALID",`${d}/${f}/fieldOrder`)}}if(s.sections!==void 0){(!Array.isArray(s.sections)||s.sections.length>100)&&j("NATIVE_DATA_VIEW_SECTIONS_INVALID",`${d}/sections`);let f=new Set;s.sections.forEach((u,p)=>{let _=`${d}/sections/${p}`,E=re(u,_);Ce(E,["title","fields"],_),De(E.title,`${_}/title`,255);for(let A of rt(E.fields,`${_}/fields`,100,!0)){let O=e.fields[A];(!O||(O.hidden??O.system)===!0||f.has(A))&&j("NATIVE_DATA_VIEW_FIELD_INVALID",`${_}/fields`),f.add(A)}})}let c=mn(e,a);if(pn(c,t,d),s.generated.create!==!1&&(e.mutationOwner||"native")==="native")for(let f of t)Tt(f,e.fields[f.code])&&nr(f,e.fields[f.code],"create")&&!s.form.fieldOrder.includes(f.code)&&j("NATIVE_DATA_VIEW_CREATE_REQUIRED_FIELD_MISSING",`${d}/form/fieldOrder`)})}function nr(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 La(e,t,o){let n=re(e,o);Ce(n,Se.field,o),De(n.label,`${o}/label`,500),n.type!==t.type&&j("NATIVE_DATA_SURFACE_FIELD_TYPE_MISMATCH",`${o}/type`);let i=De(n.widget,`${o}/widget`,64);va[t.type].includes(i)||j("NATIVE_DATA_SURFACE_WIDGET_INCOMPATIBLE",`${o}/widget`),ja(n.section,`${o}/section`,255);for(let r of["requiredHint","system","hidden","list","searchable","sortable"])bo(n[r],`${o}/${r}`);n.searchable===!0&&!ln(t.type)&&j("NATIVE_DATA_SURFACE_SEARCH_UNSUPPORTED",`${o}/searchable`),n.sortable===!0&&!it(t.type)&&j("NATIVE_DATA_SURFACE_SORT_UNSUPPORTED",`${o}/sortable`);for(let r of["readCapabilities","createCapabilities","updateCapabilities"])rt(n[r],`${o}/${r}`,100,!0);if(n.maxCount!==void 0&&(!Number.isSafeInteger(n.maxCount)||Number(n.maxCount)<1||Number(n.maxCount)>100)&&j("NATIVE_DATA_SURFACE_MAX_COUNT_INVALID",`${o}/maxCount`),n.maxSizeMb!==void 0&&(!Number.isSafeInteger(n.maxSizeMb)||Number(n.maxSizeMb)<1||Number(n.maxSizeMb)>1024)&&j("NATIVE_DATA_SURFACE_MAX_SIZE_INVALID",`${o}/maxSizeMb`),n.accept!==void 0){let r=Array.isArray(n.accept)?n.accept:[n.accept];rt(r,`${o}/accept`,50,!1)}for(let r of["maxLength","precision","scale","exactDecimal","min","max","rangeBoundary","options","source","userCandidates","timePrecision","serial","subtable"])Fa(n,t,r,o);xa(n,t,o)}function Va(e,t,o){if(e===void 0)return;let n=re(e,o);if(Ce(n,Se.list,o),n.actions!==void 0){let i=re(n.actions,`${o}/actions`);Ce(i,["import","export"],`${o}/actions`);for(let r of["import","export"])i[r]!==void 0&&typeof i[r]!="boolean"&&j("NATIVE_DATA_SURFACE_LIST_ACTION_INVALID",`${o}/actions/${r}`)}if(n.fieldOrder!==void 0)for(let i of rt(n.fieldOrder,`${o}/fieldOrder`,500,!0))t.has(i)||j("NATIVE_DATA_SURFACE_LIST_FIELD_INVALID",`${o}/fieldOrder`);n.defaultPageSize!==void 0&&(!Number.isSafeInteger(n.defaultPageSize)||Number(n.defaultPageSize)<1||Number(n.defaultPageSize)>200)&&j("NATIVE_DATA_SURFACE_PAGE_SIZE_INVALID",`${o}/defaultPageSize`);for(let[i,r]of[["searchableFields",ln],["filterFields",Ao]]){if(n[i]===void 0)continue;let d=rt(n[i],`${o}/${i}`,100,!0);for(let s of d){let a=t.get(s);(!a||!r(a.type))&&j("NATIVE_DATA_SURFACE_LIST_FIELD_INVALID",`${o}/${i}`)}}if(n.defaultSort!==void 0){let i=re(n.defaultSort,`${o}/defaultSort`);Ce(i,Se.defaultSort,`${o}/defaultSort`);let r=De(i.field,`${o}/defaultSort/field`,63),d=t.get(r);!fo(r)&&(!d||!it(d.type))&&j("NATIVE_DATA_SURFACE_SORT_UNSUPPORTED",`${o}/defaultSort/field`),i.order!==void 0&&!["asc","desc"].includes(i.order)&&j("NATIVE_DATA_SURFACE_SORT_ORDER_INVALID",`${o}/defaultSort/order`)}}function tr(e,t,o,n){if(e===void 0)return;let i=re(e,o);if(Ce(i,Se[n],o),i.layout!==void 0&&!["flat","sections"].includes(i.layout)&&j("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>$a)&&j("NATIVE_DATA_SURFACE_FIELD_ORDER_INVALID",r);let d=i.fieldOrder.map((s,a)=>De(s,`${r}/${a}`,63));new Set(d).size!==d.length&&j("NATIVE_DATA_SURFACE_FIELD_ORDER_INVALID",r),d.forEach((s,a)=>{t.has(s)||j("NATIVE_DATA_SURFACE_FIELD_ORDER_FIELD_MISSING",`${r}/${a}`)})}n==="form"&&Io(i.draftState,`${o}/draftState`)}function Fa(e,t,o,n){e[o]===void 0&&t[o]===void 0||((e[o]===void 0||t[o]===void 0)&&j("NATIVE_DATA_SURFACE_FIELD_PROJECTION_MISMATCH",`${n}/${o}`),Q(e[o])!==Q(t[o])&&j("NATIVE_DATA_SURFACE_FIELD_PROJECTION_MISMATCH",`${n}/${o}`))}function xa(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:yo(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)&&j("NATIVE_DATA_SURFACE_FIELD_PROJECTION_MISMATCH",`${o}/${r}`);let d=r==="accept"?yo(i[r]):i[r],s=r==="accept"?yo(n[r]):n[r];Q(d)!==Q(s)&&j("NATIVE_DATA_SURFACE_FIELD_PROJECTION_MISMATCH",`${o}/${r}`)}}function yo(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 rt(e,t,o,n){(!Array.isArray(e)||!n&&e.length===0||e.length>o)&&j("NATIVE_DATA_SURFACE_STRING_ARRAY_INVALID",t);let i=e.map((r,d)=>De(r,`${t}/${d}`,255));return new Set(i).size!==i.length&&j("NATIVE_DATA_SURFACE_STRING_ARRAY_INVALID",t),i}function re(e,t){return(!e||typeof e!="object"||Array.isArray(e))&&j("NATIVE_OBJECT_REQUIRED",t),e}function Ce(e,t,o){let n=new Set(t);for(let i of Object.keys(e))n.has(i)||j("NATIVE_PROPERTY_UNKNOWN",`${o}/${i}`)}function De(e,t,o){return(typeof e!="string"||e.length===0||e.length>o)&&j("NATIVE_STRING_INVALID",t),e}function ja(e,t,o){e!==void 0&&(typeof e!="string"||e.length>o)&&j("NATIVE_STRING_INVALID",t)}function bo(e,t){e!==void 0&&typeof e!="boolean"&&j("NATIVE_BOOLEAN_REQUIRED",t)}function j(e,t){throw new ye(e,t)}var st=class extends Error{constructor(o,n){super(`${o}: ${n}`);this.pointer=o;this.reason=n}pointer;reason;code="NATIVE_MANAGED_CONCURRENCY_INVALID"};function Oo(e,t,o){if(e===void 0)return;let n=(g,I)=>{throw new st(g,I)},i=(g,I,T)=>((!g||typeof g!="object"||Array.isArray(g)||Object.keys(g).some(l=>!T.includes(l)))&&n(I,"object contains unsupported properties"),g),r=(g,I,T,l)=>{(!Number.isSafeInteger(g)||g<I||g>T)&&n(l,`expected integer ${I}..${T}`)},d=(g,I)=>{(typeof g!="string"||!/^[a-z][a-z0-9_-]{0,63}$/.test(g))&&n(I,"invalid code")},s=(g,I,T)=>((!Array.isArray(g)||g.length>I)&&n(T,"array exceeds bound"),g),a=(g,I)=>{let T=t.find(l=>l.code===g);return T||n(I,"unknown resource"),T},c=(g,I,T)=>{let l=g.schema.fields.find(y=>y.code===I);return!l&&I!=="id"&&n(T,"unknown field"),l},f=(g,I,T=!1)=>{i(g,I,Object.keys(g||{})),Object.keys(g).length>8&&n(I,"at most eight parameters");for(let[l,y]of Object.entries(g))if(d(l,I),i(y,I,["type","values","minimum","maximum","minLength","maxLength"]),y.type==="uuid")Object.keys(y).length!==1&&n(I,"uuid has no options");else if(T&&y.type==="boolean")i(y,I,["type"]);else if(T&&y.type==="string"&&y.values===void 0)i(y,I,["type","minLength","maxLength"]),r(y.maxLength,1,256,I),y.minLength!==void 0&&r(y.minLength,0,y.maxLength,I);else if(y.type==="string"){i(y,I,["type","values"]);let R=s(y.values,100,I);(!R.length||R.some(h=>typeof h!="string"||h.length>128)||new Set(R).size!==R.length)&&n(I,"finite string values required")}else y.type==="integer"?(i(y,I,["type","minimum","maximum"]),r(y.minimum,0,1e6,I),r(y.maximum,y.minimum,y.minimum+1e3,I)):n(I,"unsupported parameter type")},u=(g,I,T,l=!1)=>{i(g,T,["from","key","value"]),!(g.from==="input"&&Object.keys(g).length===2&&Object.hasOwn(I,g.key))&&((g.from==="actor"||l&&g.from==="allocation")&&Object.keys(g).length===1||g.from==="literal"&&Object.keys(g).length===2&&Object.hasOwn(g,"value")&&(g.value===null||["string","boolean"].includes(typeof g.value)||typeof g.value=="number"&&Number.isFinite(g.value))&&JSON.stringify(g.value).length<=512||n(T,"invalid binding"))},p=(g,I,T)=>{u(g,I,T),!(g.from==="input"&&I[g.key].type==="uuid")&&(g.from==="literal"&&typeof g.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(g.value)||n(T,"record and allocation identifiers require a UUID binding"))},_=(g,I,T)=>{u(g,I,T),!(g.from==="input"&&I[g.key].type==="integer"&&I[g.key].minimum>=1)&&(g.from==="literal"&&Number.isSafeInteger(g.value)&&g.value>=1||n(T,"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"]),r(A.admission.perSecond,1,1e3,E),r(A.admission.burst,1,1e3,E),r(A.admission.maxInFlight,1,1e3,E);let O=(g,I)=>{let T=new Set;for(let l of g)d(l?.code,I),T.has(l.code)&&n(I,"duplicate code"),T.add(l.code)};O(s(A.reads,32,E),E),O(s(A.quotas,16,E),E),O(s(A.commands,32,E),E);for(let g of A.reads){let I=`${E}/reads/${g.code}`;i(g,I,["code","resourceCode","parameters","select","where","limit","scope","freshSeconds","staleSeconds","maxKeys","sourcePerSecond","dependencies"]);let T=a(g.resourceCode,I);f(g.parameters,I),["subject","application"].includes(g.scope)||n(I,"invalid cache scope"),g.scope==="application"&&T.dataPolicyCode&&n(I,"shared cache cannot bypass a row policy");let l=s(g.select,32,I);l.length||n(I,"select required"),l.forEach(R=>c(T,R,I));let y=s(g.dependencies,64,I);y.forEach(R=>c(T,R,I));for(let R of s(g.where||[],8,I))i(R,I,["field","value"]),c(T,R.field,I),u(R.value,g.parameters,I),g.scope==="application"&&R.value.from==="actor"&&n(I,"actor requires subject cache"),y.includes(R.field)||n(I,"filter dependency missing");l.some(R=>!y.includes(R))&&n(I,"selected field dependency missing"),r(g.limit,1,100,I),r(g.freshSeconds,1,300,I),r(g.staleSeconds,0,300,I),r(g.maxKeys,1,1e4,I),r(g.sourcePerSecond,1,20,I)}for(let g of A.quotas){let I=`${E}/quotas/${g.code}`;i(g,I,["code","sourceResource","capacityField","allocationResource","allocationField","reservationSeconds"]);let T=a(g.sourceResource,I),l=a(g.allocationResource,I);c(T,g.capacityField,I)?.type!=="number.integer"&&n(I,"capacity must be an integer"),(c(l,g.allocationField,I)?.type!=="uuid"||c(l,g.allocationField,I)?.nullable!==!1)&&n(I,"allocation reference must be a uuid"),l.surface?.mutationOwner!=="queued-command"&&n(I,"allocation model must be command owned"),g.reservationSeconds!==void 0&&r(g.reservationSeconds,10,86400,I)}new Set(A.quotas.map(g=>g.allocationResource)).size!==A.quotas.length&&n(E,"an allocation model has exactly one pool owner");for(let g of A.commands){let I=`${E}/commands/${g.code}`;i(g,I,["code","mode","intake","execution","capability","parameters","resourceKey","admission","deadlineSeconds","guards","operations","quota"]),g.mode!==void 0&&!["permit","durable"].includes(g.mode)&&n(I,"unsupported mode");let T=g.mode==="durable";if(f(g.parameters,I,T),u(g.resourceKey,g.parameters,I),o.some(l=>l.code===g.capability)||n(I,"command capability must be declared"),i(g.admission,I,["perSecond","burst","maxInFlight","maxQueue","maxWaitSeconds","permitSeconds"]),r(g.admission.perSecond,1,A.admission.perSecond,I),r(g.admission.burst,1,A.admission.burst,I),r(g.admission.maxInFlight,1,A.admission.maxInFlight,I),r(g.admission.maxQueue,1,1e4,I),r(g.admission.maxWaitSeconds,1,3600,I),(!T||g.admission.permitSeconds!==void 0)&&r(g.admission.permitSeconds,5,60,I),r(g.deadlineSeconds,10,3600,I),T){(g.operations!==void 0||g.guards!==void 0||g.quota!==void 0)&&n(I,"backend-plan does not accept static operations, guards or quota"),i(g.intake,I,["perSecond","burst","maxInFlight"]);for(let R of["perSecond","burst","maxInFlight"])r(g.intake[R],1,1e3,I);let l=i(g.execution,I,["kind","handlerCode","timeoutMs","resources","directory"]);l.kind!=="backend-plan"&&n(I,"durable requires backend-plan"),d(l.handlerCode,I),r(l.timeoutMs,100,3e4,I);let y=s(l.resources,32,I);y.length||n(I,"execution resources required"),new Set(y.map(R=>R.resourceCode)).size!==y.length&&n(I,"duplicate execution resource");for(let R of y){i(R,I,["resourceCode","readFields","writeOperations","writeFields"]);let h=a(R.resourceCode,I);for(let k of["readFields","writeFields"]){let M=s(R[k],64,I);new Set(M).size!==M.length&&n(I,"duplicate field"),M.forEach(V=>{k==="readFields"&&Ot.has(V)||c(h,V,I)})}let $=s(R.writeOperations,3,I);(new Set($).size!==$.length||$.some(k=>!["create","update","increment"].includes(k)))&&n(I,"unsupported execution operation"),R.writeFields.some(k=>["id","revision","created_by","updated_by","created_at","updated_at"].includes(k))&&n(I,"record metadata is platform owned"),!$.length&&R.writeFields.length&&n(I,"write fields require an operation"),$.length&&!R.writeFields.length&&n(I,"write operations require fields"),A.quotas.some(k=>k.allocationResource===R.resourceCode)&&$.length&&n(I,"allocation references remain owned by their pool command")}if(l.directory!==void 0){i(l.directory,I,["mode","fields"]),l.directory.mode!=="current-initiator"&&n(I,"only current initiator allowed");let R=s(l.directory.fields,5,I);(!R.length||new Set(R).size!==R.length||R.some(h=>!["displayName","employeeNumber","primaryDepartment","departments","phone"].includes(h)))&&n(I,"unsupported directory fields")}continue}(g.execution!==void 0||g.intake!==void 0)&&n(I,"execution and intake require durable mode");for(let l of s(g.guards||[],8,I)){i(l,I,["resourceCode","id","conditions"]);let y=a(l.resourceCode,I);p(l.id,g.parameters,I);for(let R of s(l.conditions,16,I)){i(R,I,["kind","field","operator","value"]);let h=c(y,R.field,I);["eq","neq","lt","lte","gt","gte"].includes(R.operator)||n(I,"unsupported guard"),R.kind==="database-now"?(h?.type!=="datetime"||!["lt","lte","gt","gte"].includes(R.operator)||R.value!==void 0)&&n(I,"database-now requires datetime and an ordering operator"):(R.kind!==void 0&&R.kind!=="value"&&n(I,"unsupported condition kind"),u(R.value,g.parameters,I))}}for(let l of s(g.operations,8,I)){i(l,I,["operation","resourceCode","id","expectedRevision","data"]);let y=a(l.resourceCode,I);y.surface?.mutationOwner!=="queued-command"&&n(I,"command mutations require command owned models");let R=A.quotas.find(h=>h.allocationResource===l.resourceCode);R&&(l.operation==="create"?g.quota?.action!=="allocate"||g.quota.pool!==R.code:Object.hasOwn(l.data||{},R.allocationField))&&n(I,"allocation references are owned by their pool command"),["create","update"].includes(l.operation)||n(I,"unsupported operation"),l.operation==="update"?(p(l.id,g.parameters,I),_(l.expectedRevision,g.parameters,I)):(l.id!==void 0||l.expectedRevision!==void 0)&&n(I,"create has no caller supplied id/revision"),i(l.data,I,Object.keys(l.data||{})),Object.keys(l.data).length>32&&n(I,"too many fields");for(let[h,$]of Object.entries(l.data))h==="id"&&n(I,"record identifiers are platform owned"),c(y,h,I),u($,g.parameters,I,g.quota?.action==="allocate")}if(g.quota){let l=i(g.quota,I,["pool","action","units","mode","allocation"]),y=A.quotas.find(R=>R.code===l.pool);y||n(I,"unknown quota pool"),p(g.resourceKey,g.parameters,I),l.action==="allocate"?(i(l,I,["pool","action","units","mode"]),r(l.units,1,1e3,I),(!["committed","reserved"].includes(l.mode)||l.mode==="reserved"&&!y.reservationSeconds)&&n(I,"invalid allocation mode"),(g.operations.length!==1||g.operations[0].operation!=="create"||g.operations[0].resourceCode!==y.allocationResource||g.operations[0].data[y.allocationField]?.from!=="allocation")&&n(I,"allocation must atomically create its bound business record")):["confirm","release"].includes(l.action)?(i(l,I,["pool","action","allocation"]),p(l.allocation,g.parameters,I),g.operations.length&&n(I,"lifecycle owns allocation state; business reference remains immutable")):n(I,"invalid quota action")}else g.operations.length||n(I,"operations required")}let b=A.commands.filter(g=>g.mode==="durable").map(g=>g.execution.handlerCode);return new Set(b).size!==b.length&&n(E,"handler code must be unique"),JSON.parse(JSON.stringify(A))}var Ke=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"},Ro=["parentTransitions","childTransitions","fulfilledChildStatuses","lockedParentStatuses"],or=["amountFieldCode","currencyFieldCode","relationFieldCode","parentFieldCode","rootFieldCode","statusFieldCode","parentRelationValue","childRelationValue"],gn=e=>!!(e&&typeof e=="object"&&!Array.isArray(e)),_n=e=>Array.isArray(e)?e.filter(gn):[],he=(e,t)=>{throw new Ke(e,t)},No=e=>typeof e=="string"&&/^[A-Za-z0-9._:-]{1,128}$/.test(e),To=(e,t)=>e<t?-1:e>t?1:0;function An(e,t="/decimalReservationLifecycle"){if(e===void 0)return;if(!gn(e)||Object.keys(e).some(i=>!Ro.includes(i))||Ro.some(i=>!Object.prototype.hasOwnProperty.call(e,i)))return he(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 he(`${t}/${i}`,"\u72B6\u6001\u8FB9\u6700\u591A 64 \u6761");let d=new Set;return r.map((s,a)=>{let c=`${t}/${i}/${a}`;if(!gn(s)||Object.keys(s).some(u=>u!=="from"&&u!=="to")||!No(s.from)||!No(s.to)||s.from===s.to)return he(c,"\u72B6\u6001\u8FB9\u5FC5\u987B\u5305\u542B\u4E0D\u540C\u7684\u6709\u6548 from/to");let f=JSON.stringify([s.from,s.to]);return d.has(f)?he(c,"\u72B6\u6001\u8FB9\u4E0D\u80FD\u91CD\u590D"):(d.add(f),{from:s.from,to:s.to})}).sort((s,a)=>To(s.from,a.from)||To(s.to,a.to))},n=i=>{let r=e[i];return!Array.isArray(r)||r.length<1||r.length>16||r.some(d=>!No(d))||new Set(r).size!==r.length?he(`${t}/${i}`,"\u72B6\u6001\u96C6\u5408\u5FC5\u987B\u5305\u542B 1 \u5230 16 \u4E2A\u4E0D\u91CD\u590D\u7684\u6709\u6548\u72B6\u6001"):[...r].sort(To)};return{parentTransitions:o("parentTransitions"),childTransitions:o("childTransitions"),fulfilledChildStatuses:n("fulfilledChildStatuses"),lockedParentStatuses:n("lockedParentStatuses")}}function Co(e,t,o="/config/data/resources"){_n(e).forEach((n,i)=>{let r=`${o}/${i}/decimalReservationLifecycle`,d=An(n.decimalReservationLifecycle,r);if(!d)return;let s=_n(t).map(u=>u.platformAccess?.decimalReservation).filter(u=>gn(u)&&u.resourceCode===n.code),a=s.find(u=>u.mode==="reserve");if(!a)return he(r,"\u9700\u8981\u540C\u8D44\u6E90\u5DF2\u58F0\u660E\u7684 reserve \u52A8\u4F5C\u6620\u5C04");if(or.some(u=>typeof a[u]!="string")||s.some(u=>or.some(p=>u[p]!==a[p])))return he(r,"\u540C\u8D44\u6E90\u989D\u5EA6\u52A8\u4F5C\u7684\u5B57\u6BB5\u6620\u5C04\u5FC5\u987B\u4E00\u81F4");let c=_n(n.schema?.fields).find(u=>u.code===a.statusFieldCode);if(c?.type!=="option.single")return he(r,"\u989D\u5EA6\u72B6\u6001\u5B57\u6BB5\u5FC5\u987B\u4E3A option.single");let f=new Set(_n(c.options).map(u=>u.value));for(let u of Ro)if((u==="parentTransitions"||u==="childTransitions"?d[u].flatMap(_=>[_.from,_.to]):d[u]).some(_=>!f.has(_)))return he(`${r}/${u}`,"\u72B6\u6001\u5FC5\u987B\u6765\u81EA\u989D\u5EA6\u72B6\u6001\u5B57\u6BB5\u7684\u9009\u9879");if(s.some(u=>u.mode==="reserve"&&Array.isArray(u.eligibleParentStatuses)&&u.eligibleParentStatuses.some(p=>d.lockedParentStatuses.includes(String(p)))))return he(`${r}/lockedParentStatuses`,"\u9501\u5B9A\u7236\u72B6\u6001\u4E0D\u80FD\u5141\u8BB8\u65B0\u9884\u7559")})}var rr=require("crypto");var ho=new Set(["option.single","user.single","department.single","resource-ref.single"]),Wa=new Set(["option.multiple","cascade.single","cascade.multiple","user.multiple","department.multiple","resource-ref.multiple","address","location","json"]),sr=new Set(["option.multiple","cascade.single","cascade.multiple","user.multiple","department.multiple","resource-ref.multiple","file","image"]),Ua=new Set(["option.single","user.single","department.single","resource-ref.single","signature","address","location"]),Ma=new Set([...ho,...sr,"signature","address","location","json"]);function Ba(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=>ar(n,o.has(n.code))).sort((n,i)=>n.code.localeCompare(i.code))}function ar(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:ed(e),index:Qa(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 Ka(e,t){if(t.type==="subtable")return null;let o=se(t.code),n=dr(e,t),i=[n?` DEFAULT ${n}`:"",td(o,t),qa(o,t)].join("");return`${o} ${t.storage}${i}`}function Ga(e,t){return dr(e,t)}function qa(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 za(e){return e.type==="serial-number"||Nt(e.type)&&e.type!=="subtable"}function Ja(e,t){return t.filter(o=>o.type==="serial-number").map(o=>{let n=In(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 Ha(e,t){let o=En(e);return t.filter(n=>n.type==="serial-number").map(n=>`ALTER SEQUENCE ${In(e,n.code)} OWNED BY ${o}.${se(n.code)}`)}function Ya(e,t){return t.filter(o=>o.type==="serial-number").map(o=>`GRANT USAGE, SELECT ON SEQUENCE ${In(e,o.code)} TO "openxiangda_data_api"`)}function Xa(e,t){let o=En(e),n=[];for(let i of t){if(i.type==="subtable")continue;let r=se(i.code),d=se(ke("idx",e,i.code,i.index));switch(i.index){case"btree":n.push(`CREATE INDEX IF NOT EXISTS ${d} ON ${o} (${r})`);break;case"btree-snapshot-expressions":{let s=se(ke("idx",e,i.code,"snapshot-value")),a=se(ke("idx",e,i.code,"snapshot-label"));n.push(`CREATE INDEX IF NOT EXISTS ${s} ON ${o} ((${r} ->> 'value'))`,`CREATE INDEX IF NOT EXISTS ${a} ON ${o} ((${r} ->> 'label'))`);break}case"gin-jsonb-path":n.push(`CREATE INDEX IF NOT EXISTS ${d} ON ${o} USING GIN (${r} jsonb_path_ops)`);break;case"gist-range":n.push(`CREATE INDEX IF NOT EXISTS ${d} ON ${o} USING GIST (${r})`);break;case"gin-trigram":{let s=ho.has(i.type)?`((${r} ->> 'label')) gin_trgm_ops`:`${r} gin_trgm_ops`;n.push(`CREATE INDEX IF NOT EXISTS ${d} ON ${o} USING GIN (${s})`);break}case"none":break}if(i.type==="serial-number"){let s=se(ke("uidx",e,i.code,"serial"));n.push(`CREATE UNIQUE INDEX IF NOT EXISTS ${s} ON ${o} (${r})`)}}return n}function Za(e,t,o,n){let i=En(e),r=En(t),d=se(ke("uidx",e,"environment_id","subtable-parent")),s=se(ke("idx",t,o,n,"subtable-child")),a=se(ke("fk",t,o,e)),c=se(o),f=se(n);return[`CREATE UNIQUE INDEX IF NOT EXISTS ${d} ON ${i} ("tenant_id", "app_code", "environment_key", "id")`,`CREATE INDEX IF NOT EXISTS ${s} ON ${r} ("tenant_id", "app_code", "environment_key", ${c}, ${f}, "id")`,`DO $native_subtable$ BEGIN
2
2
  ALTER TABLE ${r}
3
3
  ADD CONSTRAINT ${a}
4
4
  FOREIGN KEY ("tenant_id", "app_code", "environment_key", ${c})
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 ke(e,...t){return`${e}_${(0,or.createHash)("sha256").update(t.join(":")).digest("hex").slice(0,32)}`}function se(e){if(!/^[A-Za-z_][A-Za-z0-9_]{0,62}$/.test(e))throw new Error("OPENXIANGDA_NATIVE_IDENTIFIER_INVALID");return`"${e}"`}function Ya(e,t){return e.type==="subtable"?"none":t?"gin-trigram":e.indexed?["date-range","datetime-range"].includes(e.type)?"gist-range":ho.has(e.type)?"btree-snapshot-expressions":Fa.has(e.type)?"gin-jsonb-path":"btree":"none"}function Xa(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 ja.has(e.type),"jsonb"}}function sr(e,t){if(Nt(t.type)&&t.type!=="subtable")return"'[]'::jsonb";if(t.type!=="serial-number")return"";let o=nr(t.serial?.prefix||""),n=t.serial?.digits??6;return`(${o} || lpad(nextval(${nr(In(e,t.code))})::text, ${n}, '0'))`}function Za(e,t){return ir.has(t.type)?` CHECK (${e} IS NULL OR jsonb_typeof(${e}) = 'array')`:xa.has(t.type)?` CHECK (${e} IS NULL OR jsonb_typeof(${e}) = 'object')`:""}function En(e){return`"app_data".${se(e)}`}function In(e,t){let o=ke("seq",e,t);return`"app_data".${se(o)}`}function nr(e){return`'${e.replace(/'/g,"''")}'`}var ar=new Set(["option.single","option.multiple","user.single","user.multiple","department.single","department.multiple","resource-ref.single","resource-ref.multiple"]),Qa=new Set([...ar,"cascade.single","cascade.multiple","file","image","signature","address","location","json"]),dr=/^[A-Za-z][A-Za-z0-9_]{0,62}$/,ed=new Set(["__proto__","prototype","constructor"]),yn=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 at(e,t){let o=cr(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 bn(e){return!!(e&&e.field.type==="user.single"&&e.valuePath==="value")}function wo(e,t,o){if(!e||!t||!nd(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 td(e,t){let o=cr(t);if(!o)throw new yn(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 nd(e){let{field:t,valuePath:o}=e;if(!o)return!Qa.has(t.type);if(o==="value")return ar.has(t.type);if(!o.startsWith("snapshot."))return!1;let n=o.slice(9);return dr.test(n)&&t.type.startsWith("resource-ref.")&&!!t.source?.snapshotFields?.includes(n)}function cr(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=>!dr.test(o)||ed.has(o))||t.length===2&&t[1]!=="value"||t.length===3&&t[1]!=="snapshot"?null:t}var od=new Set(["option.single","user.single","department.single","resource-ref.single"]),id=new Set(["text.short","text.long","text.rich","number.integer","number.decimal","boolean","date","time","datetime","uuid","serial-number"]),rd=new Set(["value","label","description","color"]),sd=new Set(["avatarUrl","employeeNo","title","mobile","email"]),ad=new Set(["fullPath","parent.value","parent.label"]),dd=new Set(["country.value","country.label","province.value","province.label","city.value","city.label","district.value","district.label","street.value","street.label","detail","fullAddress"]),cd=new Set(["longitude","latitude","accuracy"]),ld=new Set(["address","name","province","city","district","source"]);function ud(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=pd(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 fd(e,t){if(od.has(e.type)&&rd.has(t)||e.type==="user.single"&&sd.has(t)||e.type==="department.single"&&ad.has(t))return ht(t);if(e.type==="resource-ref.single"){let o=e.queryPathTypes?.[t];return o?{parts:t.split("."),type:o}:null}if(e.type==="address"&&dd.has(t))return ht(t);if(e.type==="location"){if(cd.has(t))return{parts:[t],type:"number.decimal"};if(ld.has(t))return ht(t);if(t==="capturedAt")return{parts:[t],type:"datetime"}}return null}function pd(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}`,id.has(i.type)?i.type:"json"]]:[]})):{}}function ht(e){return{parts:e.split("."),type:"text.short"}}var fr=e=>!!e&&typeof e=="object"&&!Array.isArray(e),pr=(e,t)=>Object.keys(e).length===t.length&&Object.keys(e).every(o=>t.includes(o)),lr=e=>typeof e=="string"&&/^[a-z][a-z0-9]*(?:[-_.][a-z0-9]+)*$/.test(e)&&e.length<=100,ur=e=>typeof e=="string"&&/^[a-f0-9]{8}(-[a-f0-9]{4}){3}-[a-f0-9]{12}$/i.test(e);function So(e){throw new Error(`OPENXIANGDA_WORKFLOW_STAGE_${e}`)}function Do(e){(!fr(e)||!pr(e,["workflowCode","resourceCode","actor","runningNodeIds","allowedStatuses"])||!lr(e.workflowCode)||!lr(e.resourceCode)||!["initiator","reader"].includes(String(e.actor))||!Array.isArray(e.runningNodeIds)||e.runningNodeIds.length>32||new Set(e.runningNodeIds).size!==e.runningNodeIds.length||e.runningNodeIds.some(t=>typeof t!="string"||!/^[A-Za-z0-9][A-Za-z0-9._-]{0,127}$/.test(t))||!Array.isArray(e.allowedStatuses)||e.allowedStatuses.length>5||new Set(e.allowedStatuses).size!==e.allowedStatuses.length||e.allowedStatuses.some(t=>!["approved","rejected","cancelled","terminated","returned"].includes(t))||e.runningNodeIds.length+e.allowedStatuses.length===0)&&So("POLICY_INVALID")}function md(e){(!fr(e)||!pr(e,["instanceId","subjectRecordId","expectedInstanceSequence"])||!ur(e.instanceId)||!ur(e.subjectRecordId)||!Number.isSafeInteger(e.expectedInstanceSequence)||e.expectedInstanceSequence<0)&&So("GUARD_INVALID")}function _d(e,t,o){o?.some(n=>(n.kind==="record-match"||n.kind==="record-assert")&&n.resourceCode===e.resourceCode&&n.id.toLowerCase()===t.subjectRecordId.toLowerCase()&&n.assertions.some(i=>i.kind==="value"&&i.field==="revision"&&i.operator==="eq"&&Number.isSafeInteger(i.value)&&Number(i.value)>0))||So("SOURCE_GUARD_REQUIRED")}var gd={type:"object",additionalProperties:!1,required:["workflowCode","resourceCode","actor","runningNodeIds","allowedStatuses"],properties:{workflowCode:{type:"string",pattern:"^[a-z][a-z0-9]*(?:[-_.][a-z0-9]+)*$",maxLength:100},resourceCode:{type:"string",pattern:"^[a-z][a-z0-9]*(?:[-_.][a-z0-9]+)*$",maxLength:100},actor:{enum:["initiator","reader"]},runningNodeIds:{type:"array",maxItems:32,uniqueItems:!0,items:{type:"string",pattern:"^[A-Za-z0-9][A-Za-z0-9._-]{0,127}$"}},allowedStatuses:{type:"array",maxItems:5,uniqueItems:!0,items:{enum:["approved","rejected","cancelled","terminated","returned"]}}},anyOf:[{properties:{runningNodeIds:{minItems:1}}},{properties:{allowedStatuses:{minItems:1}}}]};var dt=class extends Error{constructor(o,n){super(o);this.code=o;this.pointer=n}code;pointer},ue=e=>e&&typeof e=="object"&&!Array.isArray(e)?e:{},mr=(e,t)=>e===t||e==="*"||e.endsWith(":*")&&t.startsWith(e.slice(0,-1));function ko(e){let{policy:t,resource:o,baselineRoleCode:n,baselineCapabilities:i,pointer:r}=e,d=A=>A===void 0||A===!0||Array.isArray(A)&&A.length>0&&A.every(O=>typeof O=="string"&&O.length>0&&!e.baselineDeniedCapabilities?.some(b=>mr(b,O))&&i.some(b=>mr(b,O))),s=(A,O="")=>{throw new dt(A,`${r}/publicRead${O}`)},a=ue(t.publicRead);(!t.publicRead||Object.keys(a).length!==1||!Object.hasOwn(a,"fields")||!Array.isArray(a.fields)||a.fields.length<1||a.fields.length>1e3||a.fields.some(A=>typeof A!="string"||!/^[A-Za-z][A-Za-z0-9_]{0,62}$/.test(A))||new Set(a.fields).size!==a.fields.length)&&s("AUTHENTICATED_PUBLIC_READ_FIELDS_INVALID","/fields"),(!Array.isArray(t.operations)||t.operations.length!==1||t.operations[0]!=="read"||t.readExpression!==void 0||t.writeBoundary!==void 0)&&s("AUTHENTICATED_PUBLIC_READ_POLICY_NOT_READ_ONLY"),(!n||!o||o.code!==t.resourceCode||o.dataPolicyCode!==t.code||!d([ue(o.capabilities).read]))&&s("AUTHENTICATED_PUBLIC_READ_BASELINE_OR_RESOURCE_INVALID");let c=ue(o),f=ue(c.schema).fields;(!Array.isArray(f)||!f.length)&&s("AUTHENTICATED_PUBLIC_READ_RESOURCE_FIELDS_MISSING");let u=new Map(f.map(A=>[String(ue(A).code),ue(A)])),p=new Set(a.fields),_=ue(c.fieldPolicies);for(let A of p){let O=ue(u.get(A));(!u.has(A)||O.system===!0||ue(ue(c.surface).fields)[A]?.system===!0||Ot.has(A))&&s("AUTHENTICATED_PUBLIC_READ_FIELD_NOT_DECLARED",`/fields/${A}`),(O.type==="subtable"||O.subtable!==void 0)&&s("AUTHENTICATED_PUBLIC_READ_SUBTABLE_UNSUPPORTED",`/fields/${A}`),d(ue(_[A]).read)||s("AUTHENTICATED_PUBLIC_READ_FIELD_NOT_BASELINE_READABLE",`/fields/${A}`)}let E=[...u.keys()].filter(A=>!p.has(A));for(let A of E)d(ue(_[A]).read)&&s("AUTHENTICATED_PUBLIC_READ_PRIVATE_FIELD_ACCESSIBLE",`/fields/${A}`);E.length&&Rt.some(A=>d(ue(_[A]).read))&&s("AUTHENTICATED_PUBLIC_READ_PRIVATE_HISTORY_ACCESSIBLE")}var vo=["exact-v1","nfkc-space-v1","nfkc-upper-ascii-v1"],Du=256,ct=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"},$o=e=>!!(e&&typeof e=="object"&&!Array.isArray(e)),oe=(e,t)=>{throw new ct(e,t)},On=(e,t)=>e<t?-1:e>t?1:0,wt=(e,t,o)=>{Object.keys(e).some(n=>!t.includes(n))&&oe(o,"\u4E0D\u652F\u6301\u672A\u77E5\u5C5E\u6027")};function Po(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,d)=>{let s=`${o}/${d}`;if(!$o(r))return oe(s,"\u89C4\u5219\u5FC5\u987B\u662F\u5BF9\u8C61");if(wt(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 a=new Set,c=r.fields.map((_,E)=>{let A=`${s}/fields/${E}`;if(!$o(_))return oe(A,"\u5B57\u6BB5\u5FC5\u987B\u662F\u5BF9\u8C61");wt(_,["fieldCode","normalizer"],A);let O=n.get(_.fieldCode);if(!O||!["text.short","uuid","option.single","resource-ref.single","user.single"].includes(O.type)||a.has(_.fieldCode))return oe(`${A}/fieldCode`,"\u9700\u8981\u4E0D\u91CD\u590D\u7684\u77ED\u6587\u672C\u3001UUID\u3001\u5355\u9009\u3001\u5355\u8BB0\u5F55\u5F15\u7528\u6216\u5355\u4EBA\u5B57\u6BB5");a.add(_.fieldCode);let b=_.normalizer===void 0?"exact-v1":_.normalizer;return!vo.includes(b)||O.type!=="text.short"&&b!=="exact-v1"?oe(`${A}/normalizer`,"\u5F52\u4E00\u5316\u65B9\u5F0F\u4E0D\u652F\u6301\u6216\u4E0E\u5B57\u6BB5\u7C7B\u578B\u4E0D\u7B26"):{fieldCode:O.code,normalizer:b}}).sort((_,E)=>On(_.fieldCode,E.fieldCode)),f=r.when===void 0?[]:r.when;if(!Array.isArray(f)||f.length>4)return oe(`${s}/when`,"\u6700\u591A 4 \u4E2A\u5408\u53D6\u6761\u4EF6");let u=new Set,p=f.map((_,E)=>{let A=`${s}/when/${E}`;if(!$o(_))return oe(A,"\u6761\u4EF6\u5FC5\u987B\u662F\u5BF9\u8C61");let O=n.get(_.fieldCode);if(!O)return oe(`${A}/fieldCode`,"\u5B57\u6BB5\u4E0D\u5B58\u5728");let b;if(_.operator==="empty"||_.operator==="nonempty"){if(wt(_,["fieldCode","operator"],A),O.type!=="text.short")return oe(A,"\u7A7A\u503C\u6761\u4EF6\u4EC5\u652F\u6301\u77ED\u6587\u672C");b={fieldCode:O.code,operator:_.operator}}else if(_.operator==="in"||_.operator==="notIn"){wt(_,["fieldCode","operator","values"],A);let I=new Set((O.options??[]).map(T=>T.value));if(O.type!=="option.single"||!Array.isArray(_.values)||_.values.length<1||_.values.length>16||_.values.some(T=>typeof T!="string"||T.length<1||T.length>128||!I.has(T))||new Set(_.values).size!==_.values.length)return oe(A,"\u96C6\u5408\u6761\u4EF6\u9700\u8981 1 \u5230 16 \u4E2A\u4E0D\u91CD\u590D\u7684\u5DF2\u58F0\u660E\u5355\u9009\u503C");b={fieldCode:O.code,operator:_.operator,values:[..._.values].sort(On)}}else if(_.operator==="eq"||_.operator==="ne"){if(wt(_,["fieldCode","operator","value"],A),O.type!=="boolean"||typeof _.value!="boolean")return oe(A,"\u7B49\u503C\u6761\u4EF6\u4EC5\u652F\u6301\u5E03\u5C14\u5B57\u6BB5\u548C\u5E03\u5C14\u503C");b={fieldCode:O.code,operator:_.operator,value:_.value}}else return oe(`${A}/operator`,"\u53EA\u652F\u6301 empty\u3001nonempty\u3001in\u3001notIn \u548C\u5E03\u5C14 eq\u3001ne");let g=JSON.stringify(b);return u.has(g)?oe(A,"\u6761\u4EF6\u4E0D\u80FD\u91CD\u590D"):(u.add(g),b)}).sort((_,E)=>On(JSON.stringify(_),JSON.stringify(E)));return{code:r.code,fields:c,when:p}}).sort((r,d)=>On(r.code,d.code))}function Lo(e,t){let o=new Set(e.filter(n=>n.type==="user.single").map(n=>n.code));return t?.some(n=>n.fields.some(i=>o.has(i.fieldCode))||n.when?.some(i=>i.operator==="eq"||i.operator==="ne"))?"1.1.0":"1.0.0"}var Nn={type:"string",pattern:"^[A-Za-z_][A-Za-z0-9_]{0,62}$"},Ad={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:Nn,normalizer:{enum:[...vo]}}}},when:{type:"array",maxItems:4,uniqueItems:!0,items:{oneOf:[{type:"object",additionalProperties:!1,required:["fieldCode","operator"],properties:{fieldCode:Nn,operator:{enum:["empty","nonempty"]}}},{type:"object",additionalProperties:!1,required:["fieldCode","operator","values"],properties:{fieldCode:Nn,operator:{enum:["in","notIn"]},values:{type:"array",minItems:1,maxItems:16,uniqueItems:!0,items:{type:"string",minLength:1,maxLength:128}}}},{type:"object",additionalProperties:!1,required:["fieldCode","operator","value"],properties:{fieldCode:Nn,operator:{enum:["eq","ne"]},value:{type:"boolean"}}}]}}}}};var _r={"openxiangda.workflow.instance.completed.v2":"commit","openxiangda.workflow.instance.rejected.v2":"release","openxiangda.workflow.instance.withdrawn.v2":"release"};function gr(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),d=t.reservations.find(p=>p.mode==="reserve"&&p.resourceCode===i.resourceCode),s=t.workflows.find(p=>p.code===i.workflowCode);if(!r||!d||!s||s.resourceCode!==r.code)return o();let a=r.fields.find(p=>p.code===d.statusFieldCode);if(a?.type!=="option.single")return o();let c=new Set(a.options?.map(p=>p.value)),f=new Set,u=i.outcomes.map(p=>{let _=n(p),E=_.eventType;return Object.keys(_).some(A=>!["eventType","mode","eligibleChildStatuses"].includes(A))||typeof E!="string"||!Object.prototype.hasOwnProperty.call(_r,E)||!t.eventTypes.includes(E)||f.has(E)||_.mode!==_r[E]||!Array.isArray(_.eligibleChildStatuses)||!_.eligibleChildStatuses.length||_.eligibleChildStatuses.length>16||new Set(_.eligibleChildStatuses).size!==_.eligibleChildStatuses.length||_.eligibleChildStatuses.some(A=>typeof A!="string"||!/^[A-Za-z0-9._:-]{1,128}$/.test(A)||!c.has(A))?o():(f.add(E),{eventType:E,mode:_.mode,eligibleChildStatuses:[..._.eligibleChildStatuses].sort()})}).sort((p,_)=>p.eventType.localeCompare(_.eventType));return{resourceCode:i.resourceCode,workflowCode:i.workflowCode,outcomes:u}}function Ar(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 Tn=class extends Error{constructor(o,n){super(n);this.pointer=o}pointer;code="NATIVE_EVENT_ACTION_INVALID"};function Vo(e,t,o="/events/subscriptions"){if(e.execution===void 0)return;let n=(A,O)=>{throw new Tn(`${o}${A}`,O)},i=(A,O,b)=>((!A||typeof A!="object"||Array.isArray(A)||Object.keys(A).some(g=>!b.includes(g)))&&n(O,"Invalid action object or unsupported property"),A),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(A=>!/^openxiangda\.data\.record\.(created|updated|deleted)\.v2$/.test(A)))&&n("/eventTypes","Native data actions require declared data events");let d=e.filter?.resourceCodes;(!Array.isArray(d)||!d.length||d.length>20)&&n("/filter/resourceCodes","Native actions require explicit source resources");let s=new Map(t.map(A=>[A.code,A])),a=d.map(A=>{let O=s.get(A);return O||n("/filter/resourceCodes","Unknown source resource"),new Set((O.schema?.fields||[]).map(b=>b.code))}),c=new Set(e.payload?.fields||[]),f=e.payload?.includeChanges===!0,u=(A,O)=>{let b=i(A,O,["source","path","value"]);if(b.source==="literal"){(!Object.hasOwn(b,"value")||Object.hasOwn(b,"path"))&&n(O,"Literal binding requires only value");let l;try{l=JSON.stringify(b.value)}catch{n(O,"Literal must be JSON")}return(l===void 0||Buffer.byteLength(l)>65536)&&n(O,"Literal is too large or not JSON"),{source:"literal",value:JSON.parse(l)}}(b.source!=="event"||typeof b.path!="string"||Object.hasOwn(b,"value"))&&n(O,"Expected a literal or event binding");let g=b.path.split(".");(g.length>8||g.some(l=>!/^[A-Za-z0-9_-]+$/.test(l)||["__proto__","prototype","constructor"].includes(l)))&&n(O,"Invalid event path");let I=/^data\.projection\.([A-Za-z][A-Za-z0-9_]{0,62})$/.exec(b.path),T=/^data\.changes\.([A-Za-z][A-Za-z0-9_]{0,62})\.(before|after)$/.exec(b.path);if(I||T){let l=(I||T)[1];a.some(y=>!y.has(l))&&n(O,"Source field must exist on every filtered resource"),c.add(l),T&&(f=!0)}else["id","time","type","subject","data.recordId","data.revision","data.operation","data.resourceCode"].includes(b.path)||n(O,"Event path is not part of the data event contract");return{source:"event",path:b.path}};(!Array.isArray(r.operations)||r.operations.length<1||r.operations.length>16)&&n("/execution/operations","Expected 1 to 16 operations");let p={},_=r.operations.map((A,O)=>{let b=`/execution/operations/${O}`,g=i(A,b,["operation","resourceCode","data","id","expectedRevision"]);["create","update","delete"].includes(g.operation)||n(b,"Unsupported Native operation");let I=s.get(g.resourceCode);I||n(b,"Unknown action target resource");let T=new Map((I.schema?.fields||[]).map(y=>[y.code,y])),l=g.data===void 0?{}:i(g.data,`${b}/data`,[...T.keys()]);return Object.keys(l).length>32&&n(b,"Maximum 32 mapped fields per operation"),g.operation==="create"&&(g.id!==void 0||g.expectedRevision!==void 0)&&n(b,"Create does not accept id or expectedRevision"),g.operation==="delete"&&g.data!==void 0&&n(b,"Delete does not accept data"),Object.keys(l).some(y=>T.get(y)?.type==="serial-number")&&n(b,"Generated fields cannot be assigned"),p[g.resourceCode]=Z(I),{operation:g.operation,resourceCode:g.resourceCode,...g.operation==="create"?{}:{id:u(g.id,`${b}/id`),expectedRevision:u(g.expectedRevision,`${b}/expectedRevision`)},...g.operation==="delete"?{}:{data:Object.fromEntries(Object.entries(l).map(([y,R])=>[y,u(R,`${b}/data/${y}`)]))}}});(c.size>32||[...c].some(A=>a.some(O=>!O.has(A))))&&n("/payload/fields","Payload must contain at most 32 declared source fields");let E={kind:"native-data",version:1,operations:_,resourceDigests:p};return Buffer.byteLength(JSON.stringify(E))>65536&&n("/execution","Action plan exceeds 64 KiB"),{execution:{...E,digest:Z(E)},payload:{includeChanges:f,fields:[...c].sort()}}}function Ve(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)?e:void 0}function xo(e,t){if(e?.instanceCommands===void 0)return[];let o=Ve(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 d=Ve(r),s=i==="withdraw"?["beforeFact","reasonRequired"]:["beforeFact","capability"];if(!d||!Object.keys(d).length||Object.keys(d).some(a=>!s.includes(a))||Object.hasOwn(d,"reasonRequired")&&typeof d.reasonRequired!="boolean"){n.push(`WORKFLOW_INSTANCE_COMMAND_POLICY_INVALID:${i}`);continue}if(i==="terminate"){let a=d.capability;(typeof a!="string"||a.length>255||!/^app:[a-z][a-z0-9]*(?:-[a-z0-9]+)*:[A-Za-z0-9:._-]+$/.test(a)||t&&(!a.startsWith(`app:${t.appCode}:`)||!t.capabilities.includes(a)))&&n.push("WORKFLOW_INSTANCE_TERMINATE_CAPABILITY_INVALID")}if(Object.hasOwn(d,"beforeFact")){let a=d.beforeFact,c=Ve(e.inputSchema),f=Ve(Ve(c?.properties)?.[a]),u=Ve(Ve(e.subject)?.factProjection)?.[a],p=t?.fields.get(u);(typeof a!="string"||!/^[A-Za-z][A-Za-z0-9_]{0,62}$/.test(a)||!Array.isArray(c?.required)||!c.required.includes(a)||f?.type!=="string"||f?.format!=="date-time"||typeof u!="string"||t&&(p?.type!=="datetime"||p.nullable===!0))&&n.push(`WORKFLOW_INSTANCE_COMMAND_DEADLINE_FACT_INVALID:${i}`)}}return n}function Ed(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 Id(e){return e?.withdraw?.reasonRequired!==!1}function Fo(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,d,s]=t,a=t[8],c=new Date(Date.UTC(Number(o),Number(n),0)).getUTCDate();if(Number(n)<1||Number(n)>12||Number(i)<1||Number(i)>c||Number(r)>23||Number(d)>59||Number(s)>59||a!=="Z"&&(Number(a.slice(1,3))>23||Number(a.slice(4))>59))return null;let f=Date.parse(e);return Number.isFinite(f)?f:null}function yd(e,t,o,n){let i=e?.[t];if(!i||i.beforeFact===void 0)return null;let r=i.beforeFact,d=Ve(o),s=r&&d&&Object.hasOwn(d,r)?Fo(d[r]):null,a=n instanceof Date?n.getTime():Fo(n);return s===null||a===null||!Number.isFinite(a)?"WORKFLOW_V2_CANCELLATION_DEADLINE_INVALID":a<s?null:"WORKFLOW_V2_CANCELLATION_DEADLINE_PASSED"}var lt="openxiangda.workflow.step.requested.v2",Uo=[lt,"openxiangda.workflow.step.result_received.v2","openxiangda.workflow.step.completed.v2","openxiangda.workflow.step.continuation_failed.v2"],Rn=16384,yr=2048,bd="steps",Mo=/^[A-Za-z][A-Za-z0-9_-]{0,127}$/,br=/^[A-Za-z][A-Za-z0-9_]{0,62}$/,Ge=new Set(["__proto__","prototype","constructor"]),K=e=>!!e&&typeof e=="object"&&!Array.isArray(e)&&[Object.prototype,null].includes(Object.getPrototypeOf(e)),Or=e=>{try{let t=JSON.stringify(e);return t===void 0?1/0:new TextEncoder().encode(t).length}catch{return 1/0}},ut=(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((r,d)=>ut(r,t[d],o+1));if(!K(e)||!K(t))return!1;let n=Object.keys(e).filter(r=>e[r]!==void 0),i=Object.keys(t).filter(r=>t[r]!==void 0);return n.length===i.length&&n.every(r=>Object.hasOwn(t,r)&&ut(e[r],t[r],o+1))};function jo(e,t){let o=0,n=(i,r)=>++o>1e4||r>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(d=>n(d,r+1)):K(i)&&Object.keys(i).length<=32&&Object.keys(i).every(d=>!Ge.has(d))&&Object.values(i).every(d=>n(d,r+1));return Or(e)<=t&&n(e,0)}function Nr(e){return!K(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&&K(e.output)&&jo(e.output,Rn)&&(e.receipt===void 0||K(e.receipt)&&jo(e.receipt,yr))}function Od(e){return K(e)&&Object.keys(e).every(t=>["executionId","nodeId","handlerCode","handlerVersion","mode","dataTransaction","input","inputDigest","expectedFactRevision"].includes(t))&&typeof e.nodeId=="string"&&Mo.test(e.nodeId)&&!Ge.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)&&(e.dataTransaction===void 0||e.dataTransaction===!0&&e.mode==="reconciled-effect")&&Nr({executionId:e.executionId,handlerVersion:e.handlerVersion,inputDigest:e.inputDigest,expectedFactRevision:e.expectedFactRevision,output:e.input})}function St(e,t,o=Rn){if(!jo(t,o))return!1;let n=1e4,i=(r,d,s)=>{if(--n<0||s>8||!K(r))return!1;let a=d===null?"null":Array.isArray(d)?"array":typeof d=="number"&&Number.isSafeInteger(d)?"integer":typeof d,c=Array.isArray(r.type)?r.type:[r.type];if(!c.includes(a)&&!(a==="integer"&&c.includes("number"))||r.enum!==void 0&&(!Array.isArray(r.enum)||!r.enum.some(f=>ut(f,d)))||Object.hasOwn(r,"const")&&!ut(r.const,d))return!1;if(typeof d=="number")return Number.isFinite(d)&&(r.minimum===void 0||d>=r.minimum)&&(r.maximum===void 0||d<=r.maximum);if(typeof d=="string"){let f=Array.from(d).length;return(r.minLength===void 0||f>=r.minLength)&&(r.maxLength===void 0||f<=r.maxLength)}return Array.isArray(d)?d.length<=r.maxItems&&(r.minItems===void 0||d.length>=r.minItems)&&d.every(f=>i(r.items,f,s+1)):K(d)?!K(r.properties)||Object.keys(d).some(f=>Ge.has(f)||!Object.hasOwn(r.properties,f))||(Array.isArray(r.required)?r.required:[]).some(f=>!Object.hasOwn(d,f))||r.minProperties!==void 0&&Object.keys(d).length<r.minProperties||r.maxProperties!==void 0&&Object.keys(d).length>r.maxProperties?!1:Object.entries(d).every(([f,u])=>i(r.properties[f],u,s+1)):d===null||typeof d=="boolean"};return i(e,t,0)}function Tr(e){return typeof e=="string"&&e.length<=256&&e.split(".").length<=8&&e.split(".").every(t=>Mo.test(t)&&!Ge.has(t))}function Dt(e){let t=0,o=(n,i)=>{if(!K(n)||i>6||++t>256||Object.keys(n).some(s=>!["type","title","description","properties","required","additionalProperties","items","maxItems","minItems","maxLength","minLength","minimum","maximum","enum","const","maxProperties","minProperties"].includes(s)))return!1;let r=Array.isArray(n.type)?n.type:[n.type];if(!r.length||r.length>2||r.some(s=>!["object","array","string","integer","number","boolean","null"].includes(s))||r.length>1&&(!r.includes("null")||new Set(r).size!==r.length))return!1;for(let s of["title","description"])if(n[s]!==void 0&&(typeof n[s]!="string"||n[s].length>2e3))return!1;for(let s of["minimum","maximum"])if(n[s]!==void 0&&(typeof n[s]!="number"||!Number.isFinite(n[s])))return!1;for(let[s,a]of[["maxItems",200],["minItems",200],["maxLength",16384],["minLength",16384],["maxProperties",32],["minProperties",32]])if(n[s]!==void 0&&(!Number.isSafeInteger(n[s])||n[s]<0||n[s]>a))return!1;for(let[s,a]of[["minimum","maximum"],["minItems","maxItems"],["minLength","maxLength"],["minProperties","maxProperties"]])if(n[s]!==void 0&&n[a]!==void 0&&n[s]>n[a])return!1;if(["properties","required","additionalProperties","maxProperties","minProperties"].some(s=>n[s]!==void 0)&&!r.includes("object")||["items","maxItems","minItems"].some(s=>n[s]!==void 0)&&!r.includes("array")||["maxLength","minLength"].some(s=>n[s]!==void 0)&&!r.includes("string")||["minimum","maximum"].some(s=>n[s]!==void 0)&&!r.some(s=>s==="integer"||s==="number")||n.enum!==void 0&&(!Array.isArray(n.enum)||!n.enum.length||n.enum.length>100)||r.includes("object")&&(!K(n.properties)||n.additionalProperties!==!1||Object.keys(n.properties).length>32||Object.keys(n.properties).some(s=>!br.test(s)||Ge.has(s))||n.required!==void 0&&(!Array.isArray(n.required)||new Set(n.required).size!==n.required.length||n.required.some(s=>typeof s!="string"||!Object.hasOwn(n.properties,s)))||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(s=>o(s,i+1)))||r.includes("array")&&(!Number.isSafeInteger(n.maxItems)||!o(n.items,i+1)))return!1;let d={...n};return delete d.enum,delete d.const,!(n.enum!==void 0&&(!n.enum.every(s=>St(d,s))||n.enum.some((s,a)=>n.enum.slice(0,a).some(c=>ut(s,c))))||Object.hasOwn(n,"const")&&!St(d,n.const))};return K(e)&&e.type==="object"&&Or(e)<=Rn&&o(e,0)}function kt(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 Rr(e,t){let o=e;for(let n of t.split(".")){if(!K(o?.properties)||!Object.hasOwn(o.properties,n))return;o=o.properties[n]}return K(o)?o:void 0}var Er=(e,t)=>!!Rr(e,t);function Nd(e){return K(e)&&Object.keys(e).every(t=>["version","mode","dataTransaction","inputSchema","outputSchema"].includes(t))&&Number.isSafeInteger(e.version)&&e.version>=1&&e.version<=1e6&&["pure","reconciled-effect"].includes(e.mode)&&(e.dataTransaction===void 0||e.dataTransaction===!0&&e.mode==="reconciled-effect")&&Dt(e.inputSchema)&&Dt(e.outputSchema)}function Ir(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 Wo(e,t=0){return!K(e)||t>16?[]:e.op==="path"?typeof e.path=="string"?[e.path]:[]:["left","right","value"].flatMap(o=>Wo(e[o],t+1)).concat(Array.isArray(e.values)?e.values.flatMap(o=>Wo(o,t+1)):[])}function $t(e,t){if(!K(e)||!K(e.nodes))return["WORKFLOW_STEP_DEFINITION_INVALID"];let o=e.nodes,n=Object.entries(o).filter(([,s])=>s?.kind==="action");if(!n.length)return[];let i=[];Object.hasOwn(e.inputSchema?.properties||{},"steps")&&i.push("WORKFLOW_STEP_FACT_NAMESPACE_RESERVED");let r=kt(e);for(let[s,a]of n){(Object.keys(a).some(u=>!["id","kind","title","next","handler","inputSchema","outputSchema","inputs"].includes(u))||a.id!==s||!Mo.test(s)||Ge.has(s)||typeof a.title!="string"||!a.title.trim()||a.title.length>255||typeof a.next!="string"||!Object.hasOwn(o,a.next))&&i.push(`WORKFLOW_STEP_NODE_INVALID:${s}`);let c=a.handler;(!K(c)||Object.keys(c).some(u=>!["code","version","mode","dataTransaction"].includes(u))||!Number.isSafeInteger(c.version)||c.version<1||c.version>1e6||!/^[a-z][a-z0-9-]{0,100}$/.test(c.code||"")||!String(c.code).endsWith(`-v${c.version}`)||!["pure","reconciled-effect"].includes(c.mode)||c.dataTransaction!==void 0&&(c.dataTransaction!==!0||c.mode!=="reconciled-effect"))&&i.push(`WORKFLOW_STEP_HANDLER_INVALID:${s}`);let f=Dt(a.inputSchema);if((!f||!Dt(a.outputSchema))&&i.push(`WORKFLOW_STEP_SCHEMA_INVALID:${s}`),!K(a.inputs)||Object.keys(a.inputs).length>32){i.push(`WORKFLOW_STEP_INPUTS_INVALID:${s}`);continue}for(let u of Array.isArray(a.inputSchema?.required)?a.inputSchema.required:[])Object.hasOwn(a.inputs,u)||i.push(`WORKFLOW_STEP_INPUT_REQUIRED:${s}:${u}`);for(let[u,p]of Object.entries(a.inputs)){if(!br.test(u)||Ge.has(u)||!Object.hasOwn(a.inputSchema?.properties||{},u)||!K(p)){i.push(`WORKFLOW_STEP_INPUT_INVALID:${s}:${u}`);continue}if(p.source==="literal")(!f||Object.keys(p).some(_=>!["source","value"].includes(_))||!Object.hasOwn(p,"value")||!St(a.inputSchema.properties[u],p.value))&&i.push(`WORKFLOW_STEP_LITERAL_INVALID:${s}:${u}`);else if(p.source!=="fact"||Object.keys(p).some(_=>!["source","path"].includes(_))||!Tr(p.path)||!Er(r,p.path))i.push(`WORKFLOW_STEP_FACT_PATH_INVALID:${s}:${u}`);else if(f){let _=Rr(r,p.path),E=a.inputSchema.properties[u],A=Array.isArray(_.type)?_.type:[_.type],O=Array.isArray(E.type)?E.type:[E.type];A.some(b=>!O.includes(b)&&!(b==="integer"&&O.includes("number")))&&i.push(`WORKFLOW_STEP_FACT_TYPE_MISMATCH:${s}:${u}`)}}}let d=(s,a)=>{let c=new Set,f=[e.startAt||""];for(;f.length&&c.size<=200;){let u=f.shift();if(!(u===a||c.has(u)||!o[u])){if(u===s)return!0;c.add(u),f.push(...Ir(o[u]))}}return!1};for(let[s,a]of Object.entries(o)){if(!K(a))continue;let c=a.kind==="action"?Object.values(a.inputs||{}).flatMap(u=>u?.source==="fact"?[u.path]:[]):(Array.isArray(a.branches)?a.branches:[]).flatMap(u=>Wo(u?.when)),f=t?.bindings?.[a.binding];f&&c.push(...[f.inputPath,f.departmentIdFrom,f.resourceIdFrom,f.scope?.valueFrom].filter(u=>typeof u=="string"));for(let u of c.filter(p=>typeof p=="string"&&p.startsWith("steps."))){let p=u.split(".")[1];(o[p]?.kind!=="action"||p===s||!Er(r,u)||d(s,p))&&i.push(`WORKFLOW_STEP_OUTPUT_NOT_AVAILABLE:${s}:${u}`)}}if(t)for(let[,s]of n){let a=new Set,c=[s.next];for(;c.length&&a.size<=200;){let f=c.shift();if(a.has(f)||!K(o[f]))continue;a.add(f);let u=o[f];if(!(u.kind==="action"||u.kind==="end")){if(u.kind==="approval"){let p=t.bindings?.[u.binding];p&&["application_provider","initiator_select"].includes(p.provider)&&i.push(`WORKFLOW_STEP_NEXT_PROVIDER_REQUIRES_PREPARED_RESULT:${f}`);continue}c.push(...Ir(u))}}}return[...new Set(i)]}function Td(e,t){let o={};for(let[n,i]of Object.entries(e.inputs)){let r=i.source==="literal"?i.value:i.path.split(".").reduce((d,s)=>K(d)&&Object.hasOwn(d,s)?d[s]:void 0,t);r!==void 0&&(o[n]=r)}if(!St(e.inputSchema,o))throw new Error("WORKFLOW_STEP_INPUT_SCHEMA_INVALID");return o}function Bo(e,t,o){let n=Cn(e),i=[];Object.keys(n).length&&!o&&i.push("WORKFLOW_STEP_BACKEND_REQUIRED");for(let r of Object.keys(n)){let d=t.find(s=>s.code===r);(!d||d.execution||d.action||!Array.isArray(d.eventTypes)||d.eventTypes.length!==1||d.eventTypes[0]!==lt||!K(d.filter)||Object.keys(d.filter).length!==1||!K(d.filter.workflowStep)||Object.keys(d.filter.workflowStep).length!==1||d.filter.workflowStep.handlerCode!==r||!K(d.payload)||d.payload.includeChanges!==!1||!Array.isArray(d.payload.fields)||d.payload.fields.length)&&i.push(`WORKFLOW_STEP_SUBSCRIPTION_INVALID:${r}`)}for(let r of t)(r.eventTypes?.includes(lt)&&!n[r.code]||r.filter?.workflowStep&&!n[r.code])&&i.push(`WORKFLOW_STEP_HANDLER_NOT_DECLARED:${r.code}`);return i}function Cn(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 r={version:i.handler.version,mode:i.handler.mode,...i.handler.dataTransaction?{dataTransaction:!0}:{},inputSchema:i.inputSchema,outputSchema:i.outputSchema},d=t[i.handler.code];if(d&&!ut(d,r))throw new Error(`WORKFLOW_STEP_HANDLER_CONTRACT_CONFLICT:${i.handler.code}`);t[i.handler.code]=r}}return t}var fe=e=>e&&typeof e=="object"&&!Array.isArray(e)?e:{},qe=(e,t)=>typeof e=="string"&&!!e.trim()&&e.length<=t,Rd=/^[A-Za-z][A-Za-z0-9_-]*(?:\.[A-Za-z][A-Za-z0-9_-]*){0,15}$/,Ko=e=>typeof e=="string"&&e.length<=256&&Rd.test(e)&&!e.split(".").some(t=>["__proto__","prototype","constructor"].includes(t));function hn(e,t){let o=fe(e),n=!0;for(let i of t.split(".")){n&&=Array.isArray(o.required)&&o.required.includes(i);let r=fe(o.properties)[i];if(!r||typeof r!="object")return null;o=fe(r)}return{schema:o,required:n}}function Go(e){let t=new Set,o=[],n=2048,i=(r,d)=>{if(--n<0||d>20){o.push("WORKFLOW_EXPRESSION_BUDGET_EXCEEDED");return}let s=fe(r);if(s.op==="path")Ko(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 a of s.values){if(n<0)break;i(a,d+1)}else s.op==="not"||s.op==="exists"?i(s.value,d+1):["eq","neq","gt","gte","lt","lte","in","contains"].includes(String(s.op))?(i(s.left,d+1),i(s.right,d+1)):o.push("WORKFLOW_EXPRESSION_OPERATOR_INVALID")}};return i(e,0),{paths:[...t],errors:[...new Set(o)]}}function qo(e){if(e?.readability===void 0)return[];let t=[],o=kt(e),n=fe(e.readability);(Object.keys(n).some(s=>!["variables","logic"].includes(s))||!Object.keys(n).length)&&t.push("WORKFLOW_READABILITY_INVALID");let i=fe(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[s,a]of Object.entries(i)){let c=fe(a);(!Ko(s)||!hn(o,s))&&t.push(`WORKFLOW_VARIABLE_SOURCE_UNKNOWN:${s}`),(!qe(c.label,160)||Object.keys(c).some(f=>!["label","unit","description"].includes(f))||c.unit!==void 0&&!qe(c.unit,32)||c.description!==void 0&&!qe(c.description,2e3))&&t.push(`WORKFLOW_VARIABLE_METADATA_INVALID:${s}`)}let r=n.logic===void 0?[]:n.logic;(!Array.isArray(r)||r.length>32)&&t.push("WORKFLOW_LOGIC_LIMIT_INVALID");let d=new Set;for(let s of Array.isArray(r)?r.slice(0,32):[]){let a=fe(s),c=String(a.code||"");e.approvedDelegation&&c==="kernel-approved-delegation"&&t.push("WORKFLOW_LOGIC_PLATFORM_CODE_RESERVED"),(!/^[a-z][a-z0-9-]{2,63}$/.test(c)||d.has(c)||!qe(a.title,160)||!qe(a.description,4e3)||Object.keys(a).some(f=>!["code","title","description","phase","nodeId","inputPaths","outputPaths","source"].includes(f)))&&t.push(`WORKFLOW_LOGIC_METADATA_INVALID:${c}`),d.add(c),(!["submission","node_input","completion"].includes(String(a.phase))||a.phase==="node_input"&&!fe(e.nodes)[String(a.nodeId)]||a.phase!=="node_input"&&a.nodeId!==void 0)&&t.push(`WORKFLOW_LOGIC_ANCHOR_INVALID:${c}`);for(let f of["inputPaths","outputPaths"]){let u=a[f];if(!(f==="outputPaths"&&u===void 0))if(!Array.isArray(u)||u.length>32||new Set(u).size!==u.length)t.push(`WORKFLOW_LOGIC_PATHS_INVALID:${c}:${f}`);else for(let p of u)(!Ko(p)||!hn(o,p))&&t.push(`WORKFLOW_LOGIC_SOURCE_UNKNOWN:${c}:${String(p)}`)}if(a.source!==void 0){let f=fe(a.source);(!qe(f.path,256)||String(f.path).startsWith("/")||String(f.path).includes("..")||String(f.path).includes("://")||!/^sha256:[a-f0-9]{64}$/.test(String(f.digest))||f.symbol!==void 0&&!qe(f.symbol,160)||Object.keys(f).some(u=>!["path","symbol","digest"].includes(u)))&&t.push(`WORKFLOW_LOGIC_SOURCE_REFERENCE_INVALID:${c}`)}}for(let s of Object.values(fe(e.nodes))){let a=fe(s),c=Array.isArray(a.branches)?a.branches:[];for(let f of c){let u=Go(f.when);t.push(...u.errors.map(p=>`${p}:${a.id}`));for(let p of u.paths)hn(o,p)||t.push(`WORKFLOW_VARIABLE_SOURCE_UNKNOWN:${a.id}:${p}`)}}return[...new Set(t)]}function Cd(e,t){let o=kt(e),n=[],i=new Map,r=[];for(let c of Object.values(e.nodes)){if(c.kind==="approval")for(let[f,u,p]of[["approve",c.onApprove,"\u540C\u610F"],["reject",c.onReject,"\u62D2\u7EDD"]])u&&n.push({id:`${c.id}:${f}`,from:c.id,to:u,kind:f,label:p,variablePaths:[]});if(c.kind==="approval")for(let f of new Set(c.returnTargets||[]))e.nodes[f]?.kind==="correction"&&n.push({id:`${c.id}:return:${f}`,from:c.id,to:f,kind:"return",label:"\u9000\u56DE\u53D1\u8D77\u4EBA\u8865\u6B63",variablePaths:[]});if(c.kind==="correction"&&c.next&&n.push({id:`${c.id}:resubmit`,from:c.id,to:c.next,kind:"resubmit",label:"\u91CD\u65B0\u63D0\u4EA4\uFF0C\u4ECE\u8D77\u70B9\u91CD\u7B97",variablePaths:[]}),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 f=Object.values(c.inputs||{}).flatMap(u=>u.source==="fact"?[u.path]:[]);for(let u of f)i.has(u)||i.set(u,new Set),i.get(u).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:f})}if(c.kind==="condition"){for(let[f,u]of(c.branches||[]).entries()){let p=Go(u.when);for(let _ of p.paths)i.has(_)||i.set(_,new Set),i.get(_).add(c.id);n.push({id:`${c.id}:branch:${f}`,from:c.id,to:u.target,kind:"branch",label:u.label||`\u6761\u4EF6 ${f+1}`,priority:f+1,expression:u.when,variablePaths:p.paths}),r.push(...p.errors.map(_=>({code:_,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 d=[...e.readability?.logic||[]];if(e.approvedDelegation){let c=e.approvedDelegation,f=c.confirmer==="initiator"?"\u7533\u8BF7\u4EBA\u672C\u4EBA":"\u6240\u9009\u4EE3\u7406\u4EBA";d.push({code:"kernel-approved-delegation",title:"\u6279\u51C6\u540E\u6574\u6279\u6388\u6743\u4EE3\u7406",phase:"completion",inputPaths:[c.requestsField],description:`\u6279\u51C6\u65F6\u6838\u9A8C${f}\u5728\u5F53\u524D\u9000\u56DE\u5468\u671F\u5B8C\u6210\u201C${e.nodes[c.confirmationNodeId]?.title||c.confirmationNodeId}\u201D\u7684\u4EBA\u5DE5\u786E\u8BA4\uFF1B\u968F\u540E\u91CD\u65B0\u6838\u9A8C\u53CC\u65B9\u5F53\u524D\u8D26\u53F7\u3001\u804C\u8D23\u3001\u4FEE\u8BA2\u3001\u8303\u56F4\u4E0E\u5B8C\u6574\u6709\u6548\u671F\uFF0C\u6574\u6279\u6388\u6743\uFF08\u6700\u591A${c.maxRequests}\u884C\uFF09\u3002\u4EFB\u4E00\u884C\u5931\u8D25\uFF0C\u6279\u51C6\u4E0E\u5168\u90E8\u6388\u6743\u4E00\u8D77\u56DE\u6EDA\uFF1B\u539F\u547D\u4EE4\u6062\u590D\u4E0D\u91CD\u65B0\u6FC0\u6D3B\u5DF2\u64A4\u9500\u6388\u6743\u3002`})}let a=[...new Set([...i.keys(),...Object.keys(e.readability?.variables||{}),...d.flatMap(c=>[...c.inputPaths,...c.outputPaths||[]])])].slice(0,128).map(c=>{let f=hn(o,c),u=e.readability?.variables?.[c],p=c.split("."),_=e.subject?.factProjection[p[0]],E=p[0]==="steps"?e.nodes[p[1]]:void 0;return f||r.push({code:"WORKFLOW_VARIABLE_SOURCE_UNKNOWN",path:c}),{path:c,label:u?.label||String(f?.schema.title||c),type:String(f?.schema.type||"unknown"),...u,required:f?.required||!1,usedBy:[...i.get(c)||[]],source:f&&E?.handler?{kind:"step_output",nodeId:E.id,handlerCode:E.handler.code,handlerVersion:E.handler.version}:f&&_&&e.subject?{kind:"subject_field",resourceCode:e.subject.resourceCode,fieldPath:[_,...p.slice(1)].join(".")}:{kind:f?"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==="approval"?{emptyPolicy:c.emptyPolicy||"block",initiatorApprovalPolicy:c.initiatorApprovalPolicy||"manual",...c.completionDeadline?{completionDeadline:{...c.completionDeadline}}:{}}:{},...c.kind==="action"&&c.handler?{businessStep:{handler:c.handler,inputs:c.inputs||{},outputPaths:Object.keys(fe(c.outputSchema).properties||{}).map(f=>`steps.${c.id}.${f}`)}}:{}})),edges:n,variables:a,logic:d,diagnostics:r}}function vt(e,t=[],o=0){if(!e||o>20)return"\u65E0\u6CD5\u8BC6\u522B\u7684\u6761\u4EF6";if(e.op==="path")return t.find(d=>d.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(d=>`\uFF08${vt(d,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${vt(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(d=>d.path===i)?.unit:void 0;return`${vt(e.left,t,o+1)} ${n[e.op]} ${vt(e.right,t,o+1)}${r?` ${r}`:""}`}function Cr(e,t=0){return!Array.isArray(e)||e.length>64||t>1?!1:e.every(o=>{if(!o||typeof o!="object"||Array.isArray(o)||o.readonlyWhen!==void 0)return!1;if(o.subtable!==void 0){let n=o.subtable;return n&&n.create===!1&&n.delete===!1&&n.reorder===!1&&Cr(n.fields,t+1)}return o.readonly===!0})}function ft(e){let t=[];for(let[o,n]of Object.entries(e?.nodes||{}))if(n.initiatorApprovalPolicy!==void 0){if(n.kind!=="approval"||!["manual","auto_approve"].includes(n.initiatorApprovalPolicy)){t.push(`WORKFLOW_INITIATOR_APPROVAL_POLICY_INVALID:${o}`);continue}n.initiatorApprovalPolicy==="auto_approve"&&((n.taskPageCode!==void 0&&(typeof n.taskPageCode!="string"||!Cr(e.taskPages?.[n.taskPageCode]?.fields))||[n.fieldPolicy?.default,...Object.values(n.fieldPolicy?.fields||{})].some(i=>i==="edit"||i==="edit_required"))&&t.push(`WORKFLOW_INITIATOR_APPROVAL_INPUT_REQUIRED:${o}`),n.operationPolicy?.approve?.commentRequired===!0&&t.push(`WORKFLOW_INITIATOR_APPROVAL_COMMENT_REQUIRED:${o}`))}return t}function hd(e,t,o,n,i){return e.kind==="approval"&&e.initiatorApprovalPolicy==="auto_approve"&&ft({nodes:{node:e},...i?{taskPages:i}:{}}).length===0&&t!=="return_review"&&!!o&&n.user_id===o&&n.status==="active"&&n.participant_kind==="primary"&&["resolution","resolution_retry"].includes(n.source||"")&&!n.source_participant_id&&!n.delegate_authorization_id}var Wu=8,wd={type:"array",minItems:2,maxItems:8,uniqueItems:!0,items:{type:"string",maxLength:128,pattern:"^[a-z][a-z0-9]*(?:[-_.][a-z0-9]+)*$"}};function Pt(e){if(e.roleCodes===void 0)return[];let t=e.roleCodes;if(!["app_role","app_role_in_scope"].includes(e.provider||"")||e.roleCode!==void 0||e.candidateField!==void 0||!Array.isArray(t)||t.length<2||t.length>8||new Set(t).size!==t.length||t.some(o=>typeof o!="string"||o.length>128||!/^[a-z][a-z0-9]*(?:[-_.][a-z0-9]+)*$/.test(o)))return["WORKFLOW_V2_BINDING_ROLE_UNION_INVALID"];if(e.provider==="app_role_in_scope"){let o=e.scope,n=typeof o?.value=="string"&&o.value.length>0&&o.value.length<=255&&o.valueFrom===void 0,i=typeof o?.valueFrom=="string"&&o.valueFrom.length<=255&&/^[A-Za-z][A-Za-z0-9_-]*(?:\.[A-Za-z][A-Za-z0-9_-]*)*$/.test(o.valueFrom)&&!o.valueFrom.split(".").some(r=>["__proto__","prototype","constructor"].includes(r))&&o.value===void 0;if(!o||typeof o!="object"||Array.isArray(o)||Object.keys(o).some(r=>!["dimension","value","valueFrom"].includes(r))||typeof o.dimension!="string"||!/^[a-z][a-z0-9]*(?:[-_.][a-z0-9]+)*$/.test(o.dimension)||!n&&!i)return["WORKFLOW_V2_BINDING_ROLE_UNION_SCOPE_INVALID"]}else if(e.scope!==void 0)return["WORKFLOW_V2_BINDING_ROLE_UNION_SCOPE_INVALID"];return[]}function Sd(e){return e.roleCodes?[...e.roleCodes]:e.roleCode?[e.roleCode]:[]}function zo(e){return e.some(t=>Object.values(t.binding.bindings).some(o=>o.roleCodes!==void 0))}var Sn=["approve","reject","return","transfer","delegate","add_assignee"],Dn=["fixed_users","app_role","app_role_in_scope"],Dd=["single","any","all","sequence"],Fe=e=>!!e&&typeof e=="object"&&!Array.isArray(e),ze=(e,t)=>Object.keys(e).every(o=>t.includes(o)),wn=(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 pt(e){return e.allowedOperations||[...Sn]}function hr(e,t){return t?.commentRequired??e==="reject"}function wr(e,t){return!["transfer","delegate","add_assignee","return"].includes(e)||t?.reasonRequired!==!1}function Sr(e,t,o={},n=!1){return!(!Fe(e)||!Object.keys(e).length||!ze(e,n?["enabled","label","commentRequired","reasonRequired"]:["label","commentRequired","reasonRequired"])||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)||n&&hr(t,o)&&!e.commentRequired)||e.reasonRequired!==void 0&&(typeof e.reasonRequired!="boolean"||!["transfer","delegate","add_assignee","return"].includes(t)||n&&wr(t,o)&&!e.reasonRequired))}function kn(e,t){let o=[];for(let[n,i]of Object.entries(e?.nodes||{})){if(!Fe(i))continue;let r=i.administration,d=i.operationPolicy;if(i.kind==="cc"){(d!==void 0||r!==void 0&&(!Fe(r)||!ze(r,["assigneeProviders"])))&&o.push(`WORKFLOW_NODE_ADMINISTRATION_INVALID:${n}`),r?.assigneeProviders!==void 0&&!wn(r.assigneeProviders,Dn,3)&&o.push(`WORKFLOW_NODE_ADMINISTRATION_PROVIDERS_INVALID:${n}`),r?.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"){(r!==void 0||d!==void 0)&&o.push(`WORKFLOW_NODE_ADMINISTRATION_APPROVAL_REQUIRED:${n}`);continue}if(d!==void 0&&(!Fe(d)||Object.keys(d).length>8||Object.entries(d).some(([a,c])=>!Sn.includes(a)||!pt(i).includes(a)||!Sr(c,a)))&&o.push(`WORKFLOW_NODE_OPERATION_POLICY_INVALID:${n}`),r===void 0)continue;if(!Fe(r)||!ze(r,["modes","assigneeProviders","operations"])){o.push(`WORKFLOW_NODE_ADMINISTRATION_INVALID:${n}`);continue}r.modes!==void 0&&(!wn(r.modes,Dd,4)||!r.modes.includes(i.mode))&&o.push(`WORKFLOW_NODE_ADMINISTRATION_MODES_INVALID:${n}`),r.assigneeProviders!==void 0&&!wn(r.assigneeProviders,Dn,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&&(!wn(r.operations,Sn,8)||r.operations.some(a=>!pt(i).includes(a)))&&o.push(`WORKFLOW_NODE_ADMINISTRATION_OPERATIONS_INVALID:${n}`)}return o}function kd(e,t,o,n){let i=[];if(!e||!Fe(o)||!Object.keys(o).length||!ze(o,["title","description","assignee","mode","operations"]))return["WORKFLOW_V2_NODE_CONFIGURATION_PATCH_INVALID"];let r=o;for(let s of["title","description"])r[s]!==void 0&&(typeof r[s]!="string"||r[s].length>(s==="title"?255:1e3)||s==="title"&&!r[s].trim())&&i.push("WORKFLOW_V2_NODE_CONFIGURATION_PATCH_INVALID");let d=e.administration;if(r.mode!==void 0&&(e.kind!=="approval"||!d?.modes?.includes(r.mode))&&i.push("WORKFLOW_V2_NODE_CONFIGURATION_MODE_READONLY"),r.operations!==void 0&&(e.kind!=="approval"||!Fe(r.operations)||!Object.keys(r.operations).length||Object.keys(r.operations).length>8||Object.entries(r.operations).some(([s,a])=>!d?.operations?.includes(s)||!pt(e).includes(s)||!Sr(a,s,e.operationPolicy?.[s],!0)))&&i.push("WORKFLOW_V2_NODE_CONFIGURATION_OPERATION_INVALID"),r.assignee!==void 0){let s=r.assignee,a=d?.assigneeProviders||(e.kind==="approval"&&t&&Dn.includes(t.provider)?[t.provider]:[]);!Fe(s)||!["approval","cc"].includes(e.kind)||!a.includes(s.provider)||s.provider==="app_role_in_scope"&&!t?.scope?i.push("WORKFLOW_V2_NODE_CONFIGURATION_PROVIDER_READONLY"):s.provider==="fixed_users"?(!ze(s,["provider","users"])||!Array.isArray(s.users)||s.users.length<1&&!(e.kind==="approval"&&e.emptyPolicy==="skip")||s.users.length>(e.kind==="cc"?20:200)||new Set(s.users).size!==s.users.length||s.users.some(c=>typeof c!="string"||!c.trim()||c.length>255))&&i.push("WORKFLOW_V2_NODE_CONFIGURATION_USERS_INVALID"):s.roleCodes!==void 0?(!ze(s,["provider","roleCodes"])||Pt({...s,...s.provider==="app_role_in_scope"?{scope:t?.scope}:{}}).length)&&i.push("WORKFLOW_V2_NODE_CONFIGURATION_ROLE_INVALID"):(!ze(s,["provider","roleCode"])||typeof s.roleCode!="string"||!/^[a-z][a-z0-9_-]{0,127}$/.test(s.roleCode))&&i.push("WORKFLOW_V2_NODE_CONFIGURATION_ROLE_INVALID")}return i.push(...ft({nodes:{node:{...e,operationPolicy:Jo(e,r).operationPolicy}},...n?{taskPages:n}:{}})),e.completionDeadline&&Jo(e,r).operationPolicy.approve?.commentRequired===!0&&i.push("WORKFLOW_COMPLETION_DEADLINE_INPUT_REQUIRED:node"),i}function Jo(e,t){let o=Object.fromEntries(pt(e).flatMap(n=>{let i=n,r=t?.operations?.[i],d={...e.operationPolicy?.[i],...r?.label!==void 0?{label:r.label}:{},...r?.commentRequired!==void 0?{commentRequired:r.commentRequired}:{},...r?.reasonRequired!==void 0?{reasonRequired:r.reasonRequired}:{}};return Object.keys(d).length?[[i,d]]:[]}));return{mode:t?.mode||e.mode,initiatorApprovalPolicy:e.initiatorApprovalPolicy||"manual",allowedOperations:pt(e).filter(n=>t?.operations?.[n]?.enabled!==!1),operationPolicy:o,fieldPolicy:{default:e.fieldPolicy?.default||"readonly",fields:{...e.fieldPolicy?.fields}}}}var Gu=20,Dr=["fixed_users","initiator","input_users","form_field_users","app_role","app_role_in_scope","previous_node_actor"];function $n(e,t){let o=[];for(let[n,i]of Object.entries(e?.nodes||{})){if(i?.kind!=="cc"||((Object.keys(i).some(a=>!["id","kind","title","binding","next","emptyPolicy","notify","administration"].includes(a))||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 r=t.bindings?.[i.binding];if(!r){o.push(`WORKFLOW_CC_BINDING_NOT_FOUND:${n}`);continue}Dr.includes(r.provider)||o.push(`WORKFLOW_CC_PROVIDER_INVALID:${n}`);let d=r.min??1,s=r.max??20;(!Number.isSafeInteger(d)||!Number.isSafeInteger(s)||d<1||s<d||s>20||r.provider==="fixed_users"&&(!Array.isArray(r.users)||!r.users.length||r.users.length>s))&&o.push(`WORKFLOW_CC_RECIPIENT_LIMIT_INVALID:${n}`)}return[...new Set(o)]}var Ho=["fixed_users","input_users","form_field_users","app_role","app_role_in_scope"];function vn(e,t){let o=[];for(let[n,i]of Object.entries(e?.nodes||{}))i.kind==="cc"||i.emptyPolicy===void 0||(i.kind!=="approval"||!["block","skip"].includes(i.emptyPolicy)?o.push(`WORKFLOW_APPROVAL_EMPTY_POLICY_INVALID:${n}`):i.emptyPolicy==="skip"&&t&&!Ho.includes(t.bindings?.[i.binding||""]?.provider)&&o.push(`WORKFLOW_APPROVAL_EMPTY_PROVIDER_UNSUPPORTED:${n}`));return o}function $d(e,t){return e.kind==="approval"&&e.emptyPolicy==="skip"&&t?.emptyResult==="no_candidates"&&Ho.includes(t.provider)&&Array.isArray(t.candidates)&&t.candidates.length===0&&Array.isArray(t.selected)&&t.selected.length===0&&Array.isArray(t.warnings)&&t.warnings.length===0}function Yo(e,t){let o=Object.values(e.nodes||{}).filter(n=>n.binding===t);return o.length>0&&o.every(n=>n.kind==="approval"&&n.emptyPolicy==="skip")}function kr(e,t=0){return!Array.isArray(e)||e.length>64||t>1?!0:e.some(o=>!o||typeof o!="object"||Array.isArray(o)||o.required===!0||o.requiredWhen!==void 0||o.subtable!==void 0&&(!o.subtable||kr(o.subtable.fields,t+1)))}function vd(e){let t=e.afterSeconds;return`\u8FDB\u5165\u540E ${t%86400===0?`${t/86400} \u5929`:t%3600===0?`${t/3600} \u5C0F\u65F6`:t%60===0?`${t/60} \u5206\u949F`:`${t} \u79D2`}\u672A\u5B8C\u6210\uFF0C\u81EA\u52A8\u540C\u610F`}function Xo(e){let t=[];for(let[o,n]of Object.entries(e?.nodes||{})){if(!n||typeof n!="object"||n.completionDeadline===void 0)continue;let i=n.completionDeadline;if(n.kind!=="approval"||!i||typeof i!="object"||Array.isArray(i)||Object.keys(i).length!==2||Object.keys(i).some(d=>!["afterSeconds","action"].includes(d))||i.action!=="approve"||!Number.isInteger(i.afterSeconds)||i.afterSeconds<1||i.afterSeconds>2592e3){t.push(`WORKFLOW_COMPLETION_DEADLINE_INVALID:${o}`);continue}n.allowedOperations&&!n.allowedOperations.includes("approve")&&t.push(`WORKFLOW_COMPLETION_DEADLINE_APPROVE_UNAVAILABLE:${o}`);let r=n.taskPageCode?e.taskPages?.[n.taskPageCode]:void 0;(n.taskPageCode&&(!r||kr(r.fields))||[n.fieldPolicy?.default,...Object.values(n.fieldPolicy?.fields||{})].includes("edit_required")||n.operationPolicy?.approve?.commentRequired===!0||e.commandHandlers?.approve!==void 0)&&t.push(`WORKFLOW_COMPLETION_DEADLINE_INPUT_REQUIRED:${o}`)}return t}var $r="openxiangda.workflow-rejection-notification/v1",Hu=4096;function vr(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)}function mt(e,t){return typeof e=="string"&&e.trim().length>0&&e.length<=t}function Zo(e,t){return Object.keys(e).sort().join(",")===t.sort().join(",")}function Qo(e){let t=e?.rejectionNotification;return t===void 0?[]:!vr(t)||!Zo(t,["recipient","title","summary"])||t.recipient!=="record_last_modifier"||!mt(t.title,160)||!mt(t.summary,500)?["WORKFLOW_REJECTION_NOTIFICATION_INVALID"]:mt(e.subject?.resourceCode,63)?[]:["WORKFLOW_REJECTION_NOTIFICATION_SUBJECT_REQUIRED"]}function Pd(e){if(!vr(e)||e.schemaVersion!==$r||e.recipient!=="record_last_modifier"||!mt(e.title,160)||!mt(e.summary,500))return!1;let t=["schemaVersion","recipient","title","summary","status","sourceRevision"];if(e.status==="ready"){if(!Zo(e,[...t,"userId"])||!mt(e.userId,255)||!Number.isSafeInteger(e.sourceRevision)||Number(e.sourceRevision)<1)return!1}else if(e.status==="skipped"){if(!Zo(e,[...t,"reason"])||!["record_missing","modifier_missing","modifier_ineligible"].includes(String(e.reason))||(e.reason==="record_missing"?e.sourceRevision!==null:!Number.isSafeInteger(e.sourceRevision)||Number(e.sourceRevision)<1))return!1}else return!1;return new TextEncoder().encode(JSON.stringify(e)).byteLength<=4096}function ei(e,t){let o=e.commandHandlers;if(o===void 0)return[];if(!o||typeof o!="object"||Array.isArray(o)||!Object.keys(o).length||Object.keys(o).some(i=>!["approve","reject","withdraw","resubmit"].includes(i)))return["WORKFLOW_BUSINESS_COMMAND_HANDLERS_INVALID"];let n=[];o.resubmit&&!Object.values(e.nodes||{}).some(i=>i.kind==="correction")&&n.push("WORKFLOW_BUSINESS_CORRECTION_REQUIRED");for(let[i,r]of Object.entries(o)){if(!r||typeof r!="object"||Array.isArray(r)||Object.keys(r).join(",")!=="operationCode"||!/^[a-z][a-z0-9]*(?:[-_.][a-z0-9]+)*$/.test(r.operationCode||"")){n.push("WORKFLOW_BUSINESS_COMMAND_HANDLER_INVALID");continue}if(!t)continue;let d=t.find(s=>s.code===r.operationCode);if(!d){n.push("WORKFLOW_BUSINESS_COMMAND_OPERATION_MISSING");continue}(d.method!=="POST"||d.browser?.exposure!=="authenticated"||d.browser.behavior!=="controlled"||d.browser.idempotency!=="required"||d.browser.fileIntent||d.browser.subject?.resourceCode!==e.subject?.resourceCode||d.browser.subject?.inputField!=="recordId"||!d.platformAccess?.workflow?.codes?.includes(e.code)||!d.platformAccess.workflow.businessCommands?.includes(i))&&n.push("WORKFLOW_BUSINESS_COMMAND_OPERATION_INVALID")}return["approve","reject","withdraw"].some(i=>Object.hasOwn(o,i))&&Object.values(e.nodes||{}).some(i=>i.kind==="approval"&&(i.emptyPolicy==="skip"||i.initiatorApprovalPolicy==="auto_approve"))&&n.push("WORKFLOW_BUSINESS_COMMAND_AUTOMATIC_DECISION_FORBIDDEN"),[...new Set(n)]}var Ld={type:"object",additionalProperties:!1,required:["workflowCode","target","recordId","expectedRevision","commandToken","idempotencyKey","input"],properties:{workflowCode:{type:"string",pattern:"^[A-Za-z][A-Za-z0-9_-]{0,127}$"},target:{oneOf:[{type:"object",additionalProperties:!1,required:["kind","id","command"],properties:{kind:{const:"task"},id:{type:"string",format:"uuid"},command:{enum:["approve","reject","resubmit"]}}},{type:"object",additionalProperties:!1,required:["kind","id","command"],properties:{kind:{const:"instance"},id:{type:"string",format:"uuid"},command:{const:"withdraw"}}}]},recordId:{type:"string",format:"uuid"},expectedRevision:{type:"integer",minimum:1},commandToken:{type:"string",pattern:"^[A-Za-z0-9_-]{43}$"},idempotencyKey:{type:"string",minLength:1,maxLength:128},input:{type:"object",maxProperties:64}}};var Pr=["fixed_users","initiator","app_role","app_role_in_scope"],Vd=e=>!!e&&typeof e=="object"&&!Array.isArray(e);function Pn(e,t){let o=e?.launchPreflight;if(o===void 0)return[];if(!Vd(o)||Object.keys(o).join(",")!=="requiredApprovalNodes"||!Array.isArray(o.requiredApprovalNodes)||o.requiredApprovalNodes.length<1||o.requiredApprovalNodes.length>20||new Set(o.requiredApprovalNodes).size!==o.requiredApprovalNodes.length||o.requiredApprovalNodes.some(i=>typeof i!="string"||!/^[A-Za-z][A-Za-z0-9_-]{0,127}$/.test(i)))return["WORKFLOW_LAUNCH_PREFLIGHT_INVALID"];let n=[];for(let i of o.requiredApprovalNodes){let r=e.nodes?.[i];if(!r||r.kind!=="approval"){n.push(`WORKFLOW_LAUNCH_PREFLIGHT_NODE_INVALID:${i}`);continue}if(!t)continue;let d=t.bindings?.[r.binding||""];(!d||!Pr.includes(d.provider)||d.candidateField!==void 0)&&n.push(`WORKFLOW_LAUNCH_PREFLIGHT_PROVIDER_UNSUPPORTED:${i}`)}return n}var ti=e=>!!e&&typeof e=="object"&&!Array.isArray(e),Fd=/^[A-Za-z][A-Za-z0-9_]{0,62}$/,Vr=/^[A-Za-z][A-Za-z0-9_-]{0,127}$/,Lr=/^membership:[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i,Qu=500,ef=262144;function ni(e){if(e?.approvedDelegation===void 0)return[];let t=e.approvedDelegation;if(!ti(t)||Object.keys(t).some(a=>!["confirmationNodeId","confirmer","requestsField","maxRequests"].includes(a))||!Vr.test(t.confirmationNodeId||"")||!["initiator","delegate"].includes(t.confirmer)||!Fd.test(t.requestsField||"")||!Number.isSafeInteger(t.maxRequests)||t.maxRequests<1||t.maxRequests>500)return["WORKFLOW_APPROVED_DELEGATION_POLICY_INVALID"];let o=[],n=e.nodes?.[t.confirmationNodeId];(!n||n.kind!=="approval"||n.mode!=="single"||n.emptyPolicy==="skip"||n.initiatorApprovalPolicy==="auto_approve"||n.completionDeadline||n.administration?.assigneeProviders?.length||n.administration?.modes?.some(a=>a!=="single")||n.allowedOperations?.some(a=>["transfer","delegate","add_assignee","admin_override"].includes(a)))&&o.push("WORKFLOW_APPROVED_DELEGATION_CONFIRMATION_INVALID");let i=e.inputSchema?.properties?.[t.requestsField];(!i||i.type!=="array"||!Number.isSafeInteger(i.maxItems)||i.maxItems<1||i.maxItems>t.maxRequests||!i.items||i.items.type!=="object"||i.items.additionalProperties!==!1||!e.subject?.factProjection?.[t.requestsField])&&o.push("WORKFLOW_APPROVED_DELEGATION_REQUEST_SCHEMA_INVALID"),Object.values(e.nodes||{}).some(a=>a.kind==="end"&&a.outcome==="approved")||o.push("WORKFLOW_APPROVED_DELEGATION_APPROVED_END_REQUIRED");let d=[e.startAt],s=new Set;for(;d.length;){let a=d.pop();if(a===t.confirmationNodeId||s.has(a))continue;s.add(a);let c=e.nodes?.[a];c&&(c.kind==="end"&&c.outcome==="approved"&&o.push("WORKFLOW_APPROVED_DELEGATION_CONFIRMATION_BYPASS"),c.kind==="approval"&&d.push(c.onApprove,c.onReject),c.kind==="condition"&&d.push(c.otherwise,...(c.branches||[]).map(f=>f.target)),(c.kind==="cc"||c.kind==="action")&&d.push(c.next))}return[...new Set(o)]}function xd(e,t){let o=t?.data?.[e.requestsField],n=()=>{throw new Error("WORKFLOW_APPROVED_DELEGATION_REQUEST_INVALID")};(!Array.isArray(o)||!o.length||o.length>e.maxRequests||o.length>500||new TextEncoder().encode(JSON.stringify(o)).byteLength>262144)&&n();let i=["key","delegatorRoleSubjectKey","delegatorRoleSubjectRevision","delegate","delegateRoleSubjectKey","expectedDelegateRevision","workflowCode","nodeId","validFrom","validTo","reason"],r=(a,c)=>typeof a=="string"&&a.trim().length>0&&a.length<=c,d=a=>{if(typeof a!="string")return!1;let c=/^(\d{4})-(\d\d)-(\d\d)T(\d\d):(\d\d):(\d\d)(?:\.\d{1,3})?(?:Z|[+-](\d\d):(\d\d))$/.exec(a);if(!c)return!1;let[,f,u,p,_,E,A,O,b]=c,g=Number(f),I=Number(u),T=Number(p),y=[31,g%4===0&&(g%100!==0||g%400===0)?29:28,31,30,31,30,31,31,30,31,30,31];return I>=1&&I<=12&&T>=1&&T<=y[I-1]&&Number(_)<=23&&Number(E)<=59&&Number(A)<=59&&(O===void 0||Number(O)<=23&&Number(b)<=59)&&Number.isFinite(Date.parse(a))},s=o.map(a=>ti(a)?((Object.keys(a).some(c=>!i.includes(c))||!r(a.delegatorRoleSubjectKey,255)||!Lr.test(a.delegatorRoleSubjectKey)||!r(a.delegateRoleSubjectKey,255)||!Lr.test(a.delegateRoleSubjectKey)||!Number.isSafeInteger(a.delegatorRoleSubjectRevision)||a.delegatorRoleSubjectRevision<1||!Number.isSafeInteger(a.expectedDelegateRevision)||a.expectedDelegateRevision<1||!ti(a.delegate)||Object.keys(a.delegate).some(c=>!["value","label"].includes(c))||!r(a.delegate.value,255)||!r(a.delegate.label,200)||!(a.workflowCode===null||r(a.workflowCode,128)&&Vr.test(a.workflowCode))||!(a.nodeId===null||r(a.nodeId,128)&&/^[A-Za-z0-9._:-]{1,128}$/.test(a.nodeId)&&a.workflowCode)||!d(a.validFrom)||!d(a.validTo)||Date.parse(a.validFrom)>=Date.parse(a.validTo)||!r(a.reason,4e3)||a.key!==void 0&&!r(a.key,128))&&n(),{...a,delegate:{value:a.delegate.value,label:a.delegate.label},validFrom:new Date(a.validFrom).toISOString(),validTo:new Date(a.validTo).toISOString()}):n());return e.confirmer==="delegate"&&new Set(s.map(a=>a.delegate.value)).size!==1&&n(),s}var jd=e=>!!e&&typeof e=="object"&&!Array.isArray(e)&&[null,Object.prototype].includes(Object.getPrototypeOf(e));function oi(e){let t=e?.nodes||{},o=Object.values(t).filter(s=>s?.kind==="correction");if(!o.length)return[];let n=[],i=s=>s?.kind==="approval"?[s.onApprove,s.onReject]:s?.kind==="condition"?[...(Array.isArray(s.branches)?s.branches:[]).map(a=>a.target),s.otherwise]:s?.kind==="action"||s?.kind==="cc"?[s.next]:[],r=new Set,d=[e.startAt];for(;d.length;){let s=d.pop();r.has(s)||(r.add(s),d.push(...i(t[s])))}for(let s of o){(!jd(s)||Object.keys(s).some(c=>!["id","kind","title","taskPageCode","next"].includes(c))||typeof s.id!="string"||!/^[A-Za-z][A-Za-z0-9_-]{0,127}$/.test(s.id)||["__proto__","prototype","constructor"].includes(s.id)||t[s.id]!==s||typeof s.title!="string"||!s.title.trim()||s.title.length>255||typeof s.taskPageCode!="string"||!/^[A-Za-z][A-Za-z0-9_-]{0,63}$/.test(s.taskPageCode))&&n.push("WORKFLOW_CORRECTION_NODE_INVALID"),(s.next!==e.startAt||t[s.next]?.kind==="correction")&&n.push("WORKFLOW_CORRECTION_REPLAY_TARGET_INVALID"),(r.has(s.id)||Object.values(t).some(c=>i(c).includes(s.id)))&&n.push("WORKFLOW_CORRECTION_FORWARD_ENTRY_FORBIDDEN"),Object.values(t).some(c=>c?.kind==="approval"&&r.has(c.id)&&Array.isArray(c.returnTargets)&&c.returnTargets.includes(s.id))||n.push("WORKFLOW_CORRECTION_RETURN_SOURCE_REQUIRED");let a=e.taskPages?.[s.taskPageCode];!a||!Array.isArray(a.fields)?n.push("WORKFLOW_CORRECTION_PAGE_REQUIRED"):a.fields.some(c=>c?.subtable)&&n.push("WORKFLOW_CORRECTION_OWNED_FACTS_UNSUPPORTED")}return[...new Set(n)]}var Lt=class extends Error{constructor(o){super(o);this.code=o}code},Wd=["projection","triggerCode","resourceCode","recordId","recordRevision","field","dueAt"];function ii(e,t,o){let n=r=>{throw new Lt(r)};t.length>100&&n("DATE_TRIGGER_PROJECTION_LIMIT");let i=new Set;for(let r of t){let d=r.filter?.resourceCodes||[];if(Array.isArray(d)||n("DATE_TRIGGER_PROJECTION_INVALID"),d.length&&!d.includes(e))continue;let s=r.payload?.fields||[];(!Array.isArray(s)||s.length>32)&&n("DATE_TRIGGER_PROJECTION_LIMIT");for(let a of s)(typeof a!="string"||!/^[A-Za-z_][A-Za-z0-9_]{0,62}$/.test(a)||["__proto__","constructor","prototype"].includes(a))&&n("DATE_TRIGGER_PROJECTION_FIELD_INVALID"),i.add(a)}if(i.size>64&&n("DATE_TRIGGER_PROJECTION_LIMIT"),o!==void 0){let r=o?.schema?.fields??o?.fields;Array.isArray(r)||n("DATE_TRIGGER_PROJECTION_RESOURCE_INVALID");let d=new Map(r.map(s=>[s.code,s]));for(let s of i){let a=d.get(s);a||n("DATE_TRIGGER_PROJECTION_FIELD_UNKNOWN"),a.type==="subtable"&&n("DATE_TRIGGER_PROJECTION_SUBTABLE_FORBIDDEN"),o.fieldPolicies?.[s]?.mask==="omit"&&n("DATE_TRIGGER_PROJECTION_FIELD_SENSITIVE")}}return[...i].sort()}function Ud(e,t){if(!t.length)return e;let o=e?.properties?.projection;if(o?.type!=="object"||!o.properties||typeof o.properties!="object"||Array.isArray(o.properties)||o.additionalProperties!==!1||o.required!==void 0&&!Array.isArray(o.required)||t.some(n=>!Object.hasOwn(o.properties,n))||(o.required||[]).some(n=>!t.includes(n)))throw new Lt("DATE_TRIGGER_PROJECTION_SCHEMA_INVALID");return{...e,properties:{...e.properties,projection:{}}}}var xr=64,Ln=1024*1024,jr=65536,ai=500,ri=1e3,Je=new Set(["__proto__","prototype","constructor"]),Wr=/^[A-Za-z][A-Za-z0-9_-]{0,63}$/,Ft=/^[A-Za-z][A-Za-z0-9_]{0,62}$/,Fr=/^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/,ae=e=>!!e&&typeof e=="object"&&!Array.isArray(e)&&[null,Object.prototype].includes(Object.getPrototypeOf(e)),ve=(e,t)=>ae(e)&&Object.keys(e).every(o=>t.includes(o)&&!Je.has(o)),Vn=e=>{try{return new TextEncoder().encode(JSON.stringify(e)).length}catch{return 1/0}},Ur=e=>e==null||typeof e=="string"&&!e.trim()||Array.isArray(e)&&e.length===0;function xe(e,t){if(e===t)return!0;if(Array.isArray(e)&&Array.isArray(t))return e.length===t.length&&e.every((n,i)=>xe(n,t[i]));if(!ae(e)||!ae(t))return!1;let o=Object.keys(e);return o.length===Object.keys(t).length&&o.every(n=>Object.hasOwn(t,n)&&xe(e[n],t[n]))}function si(e,t){let o=t.split(".");if(!(o.some(n=>!Wr.test(n)||Je.has(n))||o.length>12))return o.reduce((n,i)=>ae(n)&&Object.hasOwn(n,i)?n[i]:void 0,e)}function $e(e,t){switch(e.op){case"literal":return e.value;case"path":return si({values:t},e.path);case"and":return e.values.every(o=>!!$e(o,t));case"or":return e.values.some(o=>!!$e(o,t));case"not":return!$e(e.value,t);case"exists":return!Ur($e(e.value,t));default:{let o=$e(e.left,t),n=$e(e.right,t);return e.op==="eq"?xe(o,n):e.op==="neq"?!xe(o,n):e.op==="in"?Array.isArray(n)&&n.some(i=>xe(i,o)):e.op==="contains"?Array.isArray(o)?o.some(i=>xe(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 Vt(e,t,o=0,n={nodes:0}){if(o>8||++n.nodes>64||!ae(e))return!1;if(e.op==="literal")return ve(e,["op","value"])&&Object.hasOwn(e,"value")&&Vn(e.value)<=4096&&xt(e.value);if(e.op==="path"){if(!ve(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(r=>Ft.test(r)&&!Je.has(r))}return["not","exists"].includes(e.op)?ve(e,["op","value"])&&Vt(e.value,t,o+1,n):["and","or"].includes(e.op)?ve(e,["op","values"])&&Array.isArray(e.values)&&e.values.length>0&&e.values.length<=16&&e.values.every(i=>Vt(i,t,o+1,n)):["eq","neq","gt","gte","lt","lte","in","contains"].includes(e.op)&&ve(e,["op","left","right"])&&Vt(e.left,t,o+1,n)&&Vt(e.right,t,o+1,n)}function jt(e,t,o,n=ri){let i=[],r=e.taskPages;if(r!==void 0&&(!ae(r)||Object.keys(r).length===0||Object.keys(r).length>16||Vn(r)>jr))return["WORKFLOW_TASK_PAGES_INVALID"];for(let[d,s]of Object.entries(r||{})){let a=`taskPages.${d}`;if(!Wr.test(d)||Je.has(d)||!ve(s,["title","fields"])||typeof s.title!="string"||!s.title.trim()||s.title.length>160||!Array.isArray(s.fields)||!s.fields.length||s.fields.length>xr){i.push(`WORKFLOW_TASK_PAGE_INVALID:${a}`);continue}let c=new Set(s.fields.map(p=>p?.code));c.size!==s.fields.length&&i.push(`WORKFLOW_TASK_PAGE_DUPLICATE_FIELD:${a}`);let f=0,u=new Set;for(let p of s.fields){if(!ve(p,["code","readonly","required","visibleWhen","requiredWhen","subtable"])||!Ft.test(p.code)||Je.has(p.code)||["readonly","required"].some(_=>p[_]!==void 0&&typeof p[_]!="boolean")||p.readonly&&(p.required||p.requiredWhen)){i.push(`WORKFLOW_TASK_PAGE_FIELD_INVALID:${a}`);continue}for(let _ of["visibleWhen","requiredWhen"])p[_]!==void 0&&!Vt(p[_],c)&&i.push(`WORKFLOW_TASK_PAGE_EXPRESSION_INVALID:${a}.${p.code}.${_}`);if(t){let _=t.get(p.code);if((!_||_.system||_.hidden||_.type==="serial-number"||!p.readonly&&_.widget==="readonly"||!p.readonly&&_.type==="subtable"&&!p.subtable||p.subtable&&_.type!=="subtable")&&i.push(`WORKFLOW_TASK_PAGE_RESOURCE_FIELD_INVALID:${a}.${p.code}`),p.subtable&&_?.subtable){let E=_.subtable;f+=E.maxRows??20,(u.has(E.resourceCode)||!Number.isSafeInteger(E.maxRows??20)||(E.maxRows??20)<1||(E.maxRows??20)>ai||!Ft.test(E.foreignKey)||!Ft.test(E.orderField)||E.foreignKey===E.orderField)&&i.push(`WORKFLOW_TASK_SUBTABLE_RELATION_INVALID:${a}.${p.code}`),u.add(E.resourceCode);let A=o?.get(E.resourceCode);o&&(!A||!["uuid","resource-ref.single"].includes(A.get(E.foreignKey)?.type||"")||A.get(E.orderField)?.type!=="number.integer")&&i.push(`WORKFLOW_TASK_SUBTABLE_RELATION_INVALID:${a}.${p.code}`);for(let O of Array.isArray(p.subtable.fields)?p.subtable.fields:[]){if(!O||typeof O.code!="string")continue;let b=A?.get(O.code);(O.code===E.foreignKey||O.code===E.orderField||A&&(!b||b.system||b.hidden||b.type==="subtable"||!O.readonly&&(b.widget==="readonly"||b.type==="serial-number")))&&i.push(`WORKFLOW_TASK_SUBTABLE_FIELD_UNSUPPORTED:${a}.${p.code}.${O.code}`)}}else p.subtable&&t&&i.push(`WORKFLOW_TASK_SUBTABLE_RELATION_INVALID:${a}.${p.code}`)}p.subtable&&(p.readonly||!ve(p.subtable,["fields","create","delete","reorder"])||["create","delete","reorder"].some(_=>p.subtable?.[_]!==void 0&&typeof p.subtable[_]!="boolean")||!Array.isArray(p.subtable.fields)||p.subtable.fields.some(_=>_?.subtable)?i.push(`WORKFLOW_TASK_SUBTABLE_PAGE_INVALID:${a}.${p.code}`):i.push(...jt({taskPages:{child:{title:"\u5B50\u884C",fields:p.subtable.fields}}},o?.get(t?.get(p.code)?.subtable?.resourceCode||"")).map(_=>`${_}:${a}.${p.code}`)))}(f>Math.min(n,ri)||f<0||!Number.isSafeInteger(f)||!Number.isSafeInteger(n)||n<1)&&i.push(`WORKFLOW_TASK_SUBTABLE_BUDGET_EXCEEDED:${a}`)}for(let[d,s]of Object.entries(e.nodes||{}))ae(s)&&s.taskPageCode!==void 0&&(!["approval","correction"].includes(s.kind)||typeof s.taskPageCode!="string"||!ae(r)||!Object.hasOwn(r,s.taskPageCode)?i.push(`WORKFLOW_TASK_PAGE_NOT_FOUND:${d}`):Array.isArray(r[s.taskPageCode]?.fields)&&r[s.taskPageCode].fields.some(a=>a&&(s.fieldPolicy?.fields?.[a.code]||s.fieldPolicy?.default)==="hidden")&&i.push(`WORKFLOW_TASK_PAGE_FIELD_HIDDEN:${d}`));return i}function di(e,t){return e.fields.map(o=>({code:o.code,visible:o.visibleWhen===void 0||!!$e(o.visibleWhen,t),readonly:o.readonly===!0,required:o.required===!0||o.requiredWhen!==void 0&&!!$e(o.requiredWhen,t)}))}var Oe=class extends Error{constructor(o,n){super(o);this.code=o;this.field=n}code;field;rowIndex;childField};function Md(e,t){return t.map(o=>({key:String(o.id),id:String(o.id),revision:Number(o.revision),state:"persisted",values:Object.fromEntries(di({title:"\u5B50\u884C",fields:e.fields},o).filter(n=>n.visible&&!n.readonly).map(n=>[n.code,o[n.code]??null]))}))}function Bd(e,t,o,n,i,r=!0,d=0){let s=e.subtable,a=_=>{throw new Oe(_,e.code)};if(!s||!Number.isSafeInteger(t)||t<1||t>ai||!Number.isSafeInteger(d)||d<0||d>t||!Array.isArray(n)||n.length>2*t||Vn(n)>Ln||!xt(n))return a("WORKFLOW_TASK_SUBTABLE_VALUES_INVALID");let c=new Map(o.map(_=>[String(_.id),_])),f=new Set,u=new Set,p=[];for(let _ of n){if(!ve(_,["key","state","id","revision","values"])||typeof _.key!="string"||!Fr.test(_.key)||f.has(_.key)||!["created","persisted","deleted"].includes(_.state)||!ae(_.values))return a("WORKFLOW_TASK_SUBTABLE_ROW_INVALID");if(f.add(_.key),_.state==="created"){if(!s.create||_.id!==void 0||_.revision!==void 0||c.has(_.key))return a("WORKFLOW_TASK_SUBTABLE_CREATE_FORBIDDEN")}else{if(typeof _.id!="string"||_.id!==_.key||!Fr.test(_.id)||u.has(_.id)||!Number.isSafeInteger(_.revision)||_.revision<1||!c.has(_.id))return a("WORKFLOW_TASK_SUBTABLE_SCOPE_CONFLICT");if(u.add(_.id),r&&Number(c.get(_.id).revision)!==_.revision)return a("WORKFLOW_TASK_SUBTABLE_REVISION_CONFLICT")}if(_.state==="deleted"){if(!s.delete||Object.keys(_.values).length)return a("WORKFLOW_TASK_SUBTABLE_DELETE_FORBIDDEN");continue}try{Mr({title:e.code,fields:s.fields},_.id?c.get(_.id):{},_.values,i)}catch(E){if(!(E instanceof Oe))throw E;let A=new Oe(E.code,e.code);throw A.rowIndex=p.length,E.field!==void 0&&(A.childField=E.field),A}p.push(_)}if(u.size!==c.size)return a("WORKFLOW_TASK_SUBTABLE_SCOPE_CONFLICT");if(p.length>t)return a("WORKFLOW_TASK_SUBTABLE_MAX_ROWS_EXCEEDED");if(i&&p.length<d)return a("WORKFLOW_TASK_SUBTABLE_MIN_ROWS_NOT_MET");if(!s.reorder){let _=o.filter(A=>p.some(O=>O.id===String(A.id))).map(A=>String(A.id)),E=p.filter(A=>A.state==="persisted").map(A=>A.id);if(!xe(_,E)||p.some((A,O)=>A.state==="created"&&p.slice(O+1).some(b=>b.state==="persisted")))return a("WORKFLOW_TASK_SUBTABLE_REORDER_FORBIDDEN")}return n}function xt(e,t={members:0},o=0){return++t.members>5e4||o>12?!1:e===null||typeof e=="boolean"?!0:typeof e=="string"?e.length<=Ln:typeof e=="number"?Number.isFinite(e):Array.isArray(e)?e.length<=1e3&&e.every(n=>xt(n,t,o+1)):ae(e)&&Object.entries(e).every(([n,i])=>!Je.has(n)&&xt(i,t,o+1))}function Mr(e,t,o,n){if(!ae(o)||Vn(o)>Ln||!xt(o))throw new Oe("WORKFLOW_TASK_FORM_VALUES_INVALID");let i={...t,...o},r=new Map(di(e,i).map(d=>[d.code,d]));for(let d of Object.keys(o)){let s=r.get(d);if(!s||s.readonly||!s.visible)throw new Oe("WORKFLOW_TASK_FORM_FIELD_NOT_EDITABLE",d)}if(n)for(let d of r.values()){let s=i[d.code],a=e.fields.find(c=>c.code===d.code)?.subtable&&Array.isArray(s)?s.every(c=>ae(c)&&c.state==="deleted"):Ur(s);if(d.visible&&!d.readonly&&d.required&&a)throw new Oe("WORKFLOW_TASK_FORM_REQUIRED",d.code)}return i}function Kd(e,t,o){let n=JSON.parse(JSON.stringify(t));for(let[d,s]of Object.entries(e.subject?.factProjection||{})){let a=d.split(".");if(!a.length||a.length>12||d.length>128||a[0]==="steps"||a.some(f=>!Ft.test(f)||Je.has(f)))throw new Oe("WORKFLOW_TASK_FORM_FACT_PROJECTION_INVALID");if(!Object.hasOwn(o,s))throw new Oe("WORKFLOW_TASK_FORM_FACT_FIELD_MISSING",s);let c=n;for(let f of a.slice(0,-1))c=c[f]=ae(c[f])?c[f]:{};c[a.at(-1)]=o[s]===void 0?void 0:JSON.parse(JSON.stringify(o[s]))}let i=new Set,r=Object.values(e.nodes||{}).filter(d=>d.kind==="action");for(let d=0;d<=r.length;d++){let s=!1;for(let a of r)ae(n.steps)&&Object.hasOwn(n.steps,a.id)&&Object.values(a.inputs||{}).some(c=>c.source==="fact"&&!xe(si(t,c.path),si(n,c.path)))&&(delete n.steps[a.id],i.add(a.id),s=!0);if(!s)break}return{facts:n,invalidatedNodeIds:[...i].sort()}}function Gd(e,t,o){let n=e.nodes||{};for(let i of o){let r=new Set,d=new Map,s=a=>{if(a===i)return!0;if(d.has(a))return d.get(a);if(r.has(a)||r.size>200)return!1;let c=n[a];if(!ae(c)||c.kind==="end")return!1;r.add(a);let f=c.kind==="approval"?[c.onApprove]:c.kind==="condition"?[...(c.branches||[]).map(p=>p.target),c.otherwise]:[c.next],u=f.length>0&&f.every(p=>typeof p=="string"&&s(p));return r.delete(a),d.set(a,u),u};if(!s(t))return!1}return!0}var af=256,df=64,cf=262144,qd=/^[a-z][a-z0-9_-]{0,127}$/,zd=/^[A-Za-z][A-Za-z0-9_]*(?:\.[A-Za-z][A-Za-z0-9_]*)*$/,Kr=new Set(["__proto__","prototype","constructor"]),we=e=>!!e&&typeof e=="object"&&!Array.isArray(e),Ut=(e,t)=>Object.keys(e).every(o=>t.includes(o)),He=(e,t)=>typeof e=="string"&&e.trim().length>0&&e.length<=t&&!/[\u0000-\u001f\u007f]/.test(e),Pe=e=>typeof e=="string"&&qd.test(e)&&!Kr.has(e),Gr=e=>typeof e=="string"&&e.length<=255&&zd.test(e)&&!e.split(".").some(t=>Kr.has(t)),Jd=e=>we(e)&&Ut(e,["dimension","valueFrom","value"])&&Pe(e.dimension)&&(He(e.value,255)&&e.valueFrom===void 0||Gr(e.valueFrom)&&e.value===void 0),Br=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)),Wt={type:"string",pattern:"^[a-z][a-z0-9_-]{0,127}$"},ci={type:"string",minLength:1,maxLength:128},Hd={type:"object",additionalProperties:!1,required:["policyCode","title","strategy","dimensions","sources"],properties:{policyCode:Wt,title:ci,strategy:{enum:["replace_then_append","replace_only"]},dimensions:{type:"object",maxProperties:8,propertyNames:Wt,additionalProperties:{type:"object",additionalProperties:!1,required:["title","valueFrom"],properties:{title:ci,valueFrom:{type:"string",minLength:1,maxLength:255}}}},sources:{type:"object",minProperties:1,maxProperties:16,propertyNames:Wt,additionalProperties:{type:"object",additionalProperties:!1,required:["title","provider","roleCode"],properties:{title:ci,provider:{enum:["app_role","app_role_in_scope"]},roleCode:Wt,scope:{type:"object",additionalProperties:!1,required:["dimension"],properties:{dimension:Wt,value:{type:"string",minLength:1,maxLength:255},valueFrom:{type:"string",minLength:1,maxLength:255}}}}}}}};function Mt(e){if(!we(e)||!Ut(e,["policyCode","title","strategy","dimensions","sources"])||!Pe(e.policyCode)||!He(e.title,128)||!["replace_then_append","replace_only"].includes(e.strategy))return["WORKFLOW_V2_ROUTING_POLICY_INVALID"];let t=[];return(!we(e.dimensions)||Object.keys(e.dimensions).length>8||Object.entries(e.dimensions).some(([o,n])=>!Pe(o)||!we(n)||!Ut(n,["title","valueFrom"])||!He(n.title,128)||!Gr(n.valueFrom)))&&t.push("WORKFLOW_V2_ROUTING_DIMENSIONS_INVALID"),(!we(e.sources)||Object.keys(e.sources).length<1||Object.keys(e.sources).length>16||Object.entries(e.sources).some(([o,n])=>!Pe(o)||!we(n)||!Ut(n,["title","provider","roleCode","scope"])||!He(n.title,128)||!Pe(n.roleCode)||!["app_role","app_role_in_scope"].includes(n.provider)||(n.provider==="app_role_in_scope"?!Jd(n.scope):n.scope!==void 0)))&&t.push("WORKFLOW_V2_ROUTING_SOURCES_INVALID"),t}function Yd(e,t){if(Mt(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(!we(i)||!Ut(i,["ruleCode","title","enabled","workflowCode","nodeId","matches","sourceCode","effect","priority","validFrom","validTo"])||!Pe(i.ruleCode)||!He(i.title,128)||typeof i.enabled!="boolean"||!Pe(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&&!Pe(i.workflowCode)||i.nodeId!==void 0&&(!Pe(i.nodeId)||i.workflowCode===void 0)||i.validFrom!==void 0&&!Br(i.validFrom)||i.validTo!==void 0&&!Br(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),(!we(i.matches)||Object.entries(i.matches).some(([r,d])=>!Object.hasOwn(e.dimensions,r)||!Array.isArray(d)||d.length<1||d.length>64||new Set(d).size!==d.length||d.some(s=>!He(s,255))))&&o.push(`WORKFLOW_V2_ROUTING_MATCH_INVALID:${i.ruleCode}`)}return[...new Set(o)]}function qr(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 li(e){let t=[],o=new Map;for(let n of e)for(let[i,r]of Object.entries(n.bindings||{})){if(!we(r)||r.routing===void 0)continue;let d=Mt(r.routing);if(d.length){t.push(...d.map(c=>`${c}:${i}`));continue}let s=qr(r.routing),a=o.get(r.routing.policyCode);a&&a!==s&&t.push(`WORKFLOW_V2_ROUTING_POLICY_CONFLICT:${r.routing.policyCode}`),o.set(r.routing.policyCode,s)}return[...new Set(t)]}function Xd(e,t){let o={};for(let[n,i]of Object.entries(e.dimensions)){let r=t;for(let d of i.valueFrom.split("."))r=we(r)&&Object.hasOwn(r,d)?r[d]:void 0;if(!(typeof r=="string"&&He(r,255)||typeof r=="number"&&Number.isFinite(r)||typeof r=="boolean"))throw new Error(`WORKFLOW_V2_ROUTING_FACT_REQUIRED:${n}`);o[n]=String(r)}return o}function Zd(e,t,o){let n=t.filter(c=>c.enabled&&(!c.validFrom||Date.parse(c.validFrom)<=o.at)&&(!c.validTo||Date.parse(c.validTo)>o.at)&&(!c.workflowCode||c.workflowCode===o.workflowCode)&&(!c.nodeId||c.nodeId===o.nodeId)&&Object.entries(c.matches).every(([f,u])=>u.includes(o.facts[f])));if(n.length>64)throw new Error("WORKFLOW_V2_ROUTING_MATCH_LIMIT_EXCEEDED");let i=(c,f)=>f.priority-c.priority||+!!c.workflowCode-+!!f.workflowCode||+!!c.nodeId-+!!f.nodeId||(c.ruleCode<f.ruleCode?-1:c.ruleCode>f.ruleCode?1:0),r=n.filter(c=>c.effect==="replace").sort(i);if(r.length>1&&r[0].priority===r[1].priority)throw new Error("WORKFLOW_V2_ROUTING_REPLACE_CONFLICT");let d=r[0],s=d&&e.strategy==="replace_only"?[]:n.filter(c=>c.effect==="append").sort(i),a=[...d?[d]:[],...s];return{matched:n.sort(i),replacement:d,applied:a,ignored:n.filter(c=>!a.includes(c))}}var ui="^[A-Za-z][A-Za-z0-9_]{0,62}$",zr="^[a-z][a-z0-9]*(?:[-_.][a-z0-9]+)*$",Qd={type:"object",additionalProperties:!1,required:["mode","resourceCode","subtables"],properties:{mode:{const:"create"},resourceCode:{type:"string",maxLength:64,pattern:zr},subtables:{type:"array",minItems:1,maxItems:16,items:{type:"object",additionalProperties:!1,required:["fieldCode","fieldCodes"],properties:{fieldCode:{type:"string",pattern:ui},fieldCodes:{type:"array",minItems:1,maxItems:200,uniqueItems:!0,items:{type:"string",pattern:ui}}}}}}};function Bt(e){let t=n=>!!(n&&typeof n=="object"&&!Array.isArray(n)),o=n=>typeof n=="string"&&new RegExp(ui).test(n)&&!["__proto__","prototype","constructor"].includes(n);if(!t(e)||Object.keys(e).some(n=>!["mode","resourceCode","subtables"].includes(n))||e.mode!=="create"||typeof e.resourceCode!="string"||e.resourceCode.length>64||!new RegExp(zr).test(e.resourceCode)||!Array.isArray(e.subtables)||e.subtables.length<1||e.subtables.length>16||e.subtables.some(n=>!t(n)||Object.keys(n).some(i=>!["fieldCode","fieldCodes"].includes(i))||!o(n.fieldCode)||!Array.isArray(n.fieldCodes)||n.fieldCodes.length<1||n.fieldCodes.length>200||new Set(n.fieldCodes).size!==n.fieldCodes.length||n.fieldCodes.some(i=>!o(i)))||new Set(e.subtables.map(n=>n.fieldCode)).size!==e.subtables.length)throw new Error("WORKFLOW_OWNED_SUBJECT_CREATE_INVALID")}function ec(e){return Bt(e),{mode:"create",resourceCode:e.resourceCode,subtables:e.subtables.map(t=>({fieldCode:t.fieldCode,fieldCodes:[...t.fieldCodes].sort()})).sort((t,o)=>t.fieldCode.localeCompare(o.fieldCode))}}function fi(e,t,o){Bt(e);let n=s=>{throw new Error(`WORKFLOW_OWNED_SUBJECT_${s}`)},i=t.get(e.resourceCode);i||n("RESOURCE_MISSING");let r=new Set,d=0;for(let s of e.subtables){let a=i.get(s.fieldCode),c=a?.subtable,f=t.get(c?.resourceCode);(a?.type!=="subtable"||!f||c.resourceCode===e.resourceCode||r.has(c.resourceCode))&&n("RELATION_INVALID"),r.add(c.resourceCode);let u=c.maxRows??20;(!Number.isSafeInteger(u)||u<1||u>500)&&n("BUDGET_EXCEEDED"),d+=u;for(let p of s.fieldCodes){let _=f.get(p);(!_||["serial-number","subtable"].includes(_.type)||[c.foreignKey,c.orderField].includes(p))&&n("FIELD_INVALID"),["file","image","signature","text.rich"].includes(_.type)&&!o.some(E=>E.resourceCode===c.resourceCode&&E.fieldCodes.includes(p)&&E.intents.includes("create"))&&n("FILE_ACCESS_REQUIRED")}}d>1e3&&n("BUDGET_EXCEEDED")}var Kn=na(require("crypto"),1);var Jr="native-4",pi="2.0.0-alpha.5",Hr={"application-native-2":"1.0.0","application.extended-declaration-capacity":"1.0.0","application.extended-artifact-capacity":"1.0.0","application.development-configuration":"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.extended-owned-subtable-capacity":"1.0.0","data.aggregate-owned-subtable-capacity":"1.0.0","data.business-commands":"1.0.0","data.record-edit":"1.0.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.1.0","data.user-candidates":"1.0.0","data.user-candidate-launch-scope":"1.0.0","data.datetime-minute-precision":"1.0.0","data.subtable-minimum-rows":"1.0.0","data.managed-concurrency":"1.0.0","data.managed-concurrency.durable":"1.0.0","workflow.named-input-sources":"1.0.0","workflow.approved-delegation":"1.0.0","directory-v2":"1.0.0","directory.selected-user":"1.0.0","directory.current-initiator-phone":"1.0.0","events-v2":"1.0.0","events.durable-receipts":"1.0.0","events.capture-policy":"1.0.0","events.date-source-projection":"1.0.0","events.native-data-actions":"1.0.0","workflow-kernel-v2":"1.0.0","workflow.business-data-command":"1.0.0","workflow.native-stage-guard":"1.0.0","workflow.launch-preflight":"1.0.0","workflow.optional-rejection-comment":"1.0.0","workflow.optional-operation-reason":"1.0.0","workflow.optional-withdrawal-reason":"1.0.0","data.transaction-actor-authority":"1.0.0","data.authenticated-public-projection":"1.0.0","data.record-print":"1.0.0","data.workflow-record-deletion":"1.0.0","data.record-comments":"1.0.0","workflow.record-history-read":"1.0.0","workflow.rejection-notification":"1.0.0","workflow.instance-cancellation-policy":"1.0.0","workflow.node-administration":"1.0.0","workflow.assignment-routing":"1.0.0","workflow.role-union":"1.0.0","workflow.named-owned-create":"1.0.0","workflow.owned-initial-facts":"1.0.0","workflow.initiator-correction":"1.0.0","workflow.correction-business-command":"1.0.0","workflow.role-references":"1.0.0","workflow.delegation-management":"1.0.0","workflow.automatic-cc":"1.0.0","workflow.approval-empty-policy":"1.0.0","workflow.initiator-approval-policy":"1.0.0","workflow.completion-deadline":"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","workflow.step-data-transaction":"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 mf=5,_f=20,gf=50,Af=50,Ef=100,_t=class extends Error{constructor(o,n){super(o);this.code=o;this.pointer=n;this.name="NativeDataPolicyExpressionV2Error"}code;pointer};function Gt(e,t){let o=[],n=(i,r,d)=>{d>5&&Kt("NATIVE_DATA_POLICY_EXPRESSION_DEPTH_EXCEEDED",r);let s=Yr(i,r),a=["allOf","anyOf"].filter(u=>u in s);if(a.length===0){o.push({rule:s,pointer:r}),o.length>50&&Kt("NATIVE_DATA_POLICY_EXPRESSION_LEAVES_EXCEEDED",r);return}let c=a[0],f=s[c];(a.length!==1||Object.keys(s).length!==1||!Array.isArray(f)||f.length<1||f.length>20)&&Kt("NATIVE_DATA_POLICY_EXPRESSION_GROUP_INVALID",r),f.forEach((u,p)=>n(u,`${r}/${c}/${p}`,d+1))};return n(e,t,1),o}function _i(e,t){Gt(e,t);let o=(n,i)=>{let r=Yr(n,i);if(Array.isArray(r.allOf))return mi(r.allOf.flatMap((d,s)=>o(d,`${i}/allOf/${s}`)),i);if(Array.isArray(r.anyOf)){let d=[[]];return r.anyOf.forEach((s,a)=>{let c=o(s,`${i}/anyOf/${a}`);d=mi(d.flatMap(f=>c.map(u=>[...f,...u])),i)}),d}return[[r]]};return mi(o(e,t),t)}function mi(e,t){let o=e.reduce((n,i)=>n+i.length,0);return(e.length>50||o>100)&&Kt("NATIVE_DATA_POLICY_EXPRESSION_EXPANSION_EXCEEDED",t),e}function Yr(e,t){return(!e||typeof e!="object"||Array.isArray(e))&&Kt("NATIVE_DATA_POLICY_EXPRESSION_NODE_INVALID",t),e}function Kt(e,t){throw new _t(e,t)}var B=Object.freeze({perspectives:100,resources:512,dataPolicies:512,roles:256,subjectReadSurfaces:50,capabilities:4096,operations:500,eventConsumers:100,eventProducers:1e3,eventSchemas:100,eventTypes:500,workflows:512,routes:2048,adminPages:2048,adminNavigationGroups:100,adminNavigationItems:1024});function gi(e){let t=(e.surface?.mutationOwner||"native")==="native";return["query","get","create","update","delete"].filter(o=>{let n=e.surface?.generated;return o==="query"?n?.list??!0:o==="get"?n?.detail??!0:n?.[o]??t})}function Fn(e){let t=(e.data?.resources||[]).filter(o=>o.status!=="retired").reduce((o,n)=>o+gi(n).length,0)+(e.backend?.operations||[]).filter(o=>o.ai).length;return(e.data?.resources?.length||0)>100||(e.authz?.dataPolicies?.length||0)>100||(e.authz?.roles?.length||0)>100||(e.authz?.capabilities?.length||0)>2e3||[e.workflows?.definitions,e.workflows?.bindings,e.workflows?.activations].some(o=>(o?.length||0)>100)||(e.frontend?.routes?.length||0)>500||t>500||(e.frontend?.admin?.navigation||[]).reduce((o,n)=>o+n.items.length,0)>500}var Ae=Object.freeze({configBytes:4194304,contractBytes:8388608,depth:40,stringBytes:1048576,legacyNodes:1e5,extendedNodes:25e4});function qt(e){let t=0,o=[[e][Symbol.iterator]()];for(;o.length;){let n=o[o.length-1].next();if(n.done){o.pop();continue}if(++t>Ae.legacyNodes)return!0;if(Array.isArray(n.value))o.push(n.value.values());else if(n.value&&typeof n.value=="object"){let i=n.value;o.push((function*(){for(let r of Object.keys(i))i[r]!==void 0&&(yield i[r])})())}}return!1}var tc="openxiangda.config-bundle/v3",ms="openxiangda.contract-bundle/v3",Xr="openxiangda.native-configuration-projection/v1",Jt=Jr,nc=/^[a-f0-9]{64}$/,oc=/^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/,ic=/^app:[a-z][a-z0-9]*(?:-[a-z0-9]+)*:[A-Za-z0-9:._*-]+$/,rc=/^[a-z][a-z0-9]*(?:[-_.][a-z0-9]+)*$/,sc=/^[a-z][a-z0-9]*(?:[-.][a-z0-9]+)*$/,ac=/^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/,dc=/^[A-Za-z][A-Za-z0-9_]{0,62}$/,Zr=/^[A-Za-z][A-Za-z0-9_]{0,127}$/,cc=/^[a-z][a-z0-9]*(?:[-_][a-z0-9]+)*$/,lc=/^[A-Z][A-Z0-9_]*$/,uc=/^[a-z][a-z0-9-]{2,63}$/,fc=/^[A-Za-z][A-Za-z0-9_-]{0,127}$/,pc=/^[A-Za-z][A-Za-z0-9_.]{0,127}$/,mc=16,_c=2*1024,gc=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"]),Ac=new Set(["overview","database","operations","workflow","members","calendar","document","folder","settings"]),Ec=new Set(["approve","reject","return","transfer","delegate","add_assignee","resubmit","withdraw","terminate","admin_reassign","admin_override","retry_resolution"]),Ic=Ae.configBytes,yc=Ae.contractBytes,bc=Ae.depth,Ii=Ae.stringBytes,Oc="openxiangda.event-handler-manifest/v2",_s="openxiangda.application-route-manifest/v3",Qr=64,gs=new Set(["id","revision","created_by","updated_by","created_at","updated_at"]),xn=["openxiangda.data.record.created.v2","openxiangda.data.record.updated.v2","openxiangda.data.record.deleted.v2"],jn=["openxiangda.workflow.node.skipped.v2",lt,"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"],Nc=new Set(jn),Wn=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 Tc(e){let t=w(e.appCode,"/appCode",128);oc.test(t)||m("NATIVE_CONFIG_APP_CODE_INVALID","/appCode");let o=bi(e.expectedConfigDigest,"/expectedConfigDigest"),n=bi(e.expectedContractDigest,"/expectedContractDigest"),i=us(e.configBytes,Ic,"/configBytes","NATIVE_CONFIG_ARTIFACT_TOO_LARGE"),r=us(e.contractBytes,yc,"/contractBytes","NATIVE_CONTRACT_ARTIFACT_TOO_LARGE");fs(i,o,"/configBytes","NATIVE_CONFIG_DIGEST_MISMATCH"),fs(r,n,"/contractBytes","NATIVE_CONTRACT_DIGEST_MISMATCH");let d=ls(i,"/configBytes","NATIVE_CONFIG_JSON_INVALID","NATIVE_CONFIG_NOT_CANONICAL"),s=ls(r,"/contractBytes","NATIVE_CONTRACT_JSON_INVALID","NATIVE_CONTRACT_NOT_CANONICAL");Ai(d,"/config",Ae.extendedNodes),Ai(s,"/contracts",Ae.extendedNodes),qt(d)||Ai(s,"/contracts",Ae.legacyNodes);let a=d,c=s;Cc(a,t),hc(c,t,o);let f=wc(a,o,c.generatorVersion);ml(f,c,a),Q(f)!==Q(c)&&m("NATIVE_CONTRACT_CLOSURE_MISMATCH",Oi(f,c,"/contracts"));let u={authz:{appCode:t,...a.authz,perspectives:a.perspectives,capabilityCatalog:f.capabilities},data:{appCode:t,resources:a.data.resources,resourceContracts:f.resources,...f.concurrency?{concurrency:f.concurrency}:{},...f.subjectReadSurfaces?{subjectReadSurfaces:f.subjectReadSurfaces}:{}},events:{appCode:t,...a.events,consumers:f.eventConsumers,producers:f.eventProducers,handlerManifest:f.eventHandlerManifest,eventTypes:f.eventTypes,capturePlans:Es({resources:a.data.resources,dataPolicies:a.authz.dataPolicies,subscriptions:f.eventConsumers,capturePolicies:a.events.capturePolicies})},workflows:{appCode:t,...a.workflows,contracts:f.workflows},runtime:{appCode:t,requirements:a.runtime,backend:a.backend,frontend:a.frontend},contracts:f},p={authz:gt(u.authz),data:gt(u.data),events:gt(u.events),workflows:gt(u.workflows),runtime:gt(u.runtime),contracts:gt(u.contracts)},_={configDigest:o,contractDigest:n,generatorVersion:c.generatorVersion},E=As(a),A={schemaVersion:Xr,compilerContractVersion:Jt,appCode:t,source:_,projections:p,requiredPlatformCapabilities:E,aggregateDigest:Z({schemaVersion:Xr,compilerContractVersion:Jt,appCode:t,source:_,requiredPlatformCapabilities:E,projectionDigests:Object.fromEntries(Object.entries(p).map(([O,b])=>[O,b.digest]))})};return Ds(A)}function es(e,t){let o=e.subject,n=t.find(r=>r.code===o?.resourceCode),i=new Set(Object.values(o?.factProjection||{}));return!!n?.schema?.fields?.some(r=>r.type==="subtable"&&i.has(r.code))}function As(e){let t=e.authz.roles,o=e.data.resources,n=e.backend.operations,i=n.filter(l=>l.platformAccess?.directory?.mode==="current-initiator"&&l.platformAccess.directory.fields.includes("phone")),r=(e.data.concurrency?.commands||[]).filter(l=>l.execution?.directory?.mode==="current-initiator"&&l.execution.directory.fields.includes("phone")),d=t.some(l=>l.capabilities.some(y=>y.endsWith(":directory:read")))||o.some(l=>l.schema.fields.some(y=>["user.single","user.multiple","department.single","department.multiple"].includes(y.type)))||n.some(l=>l.platformAccess?.directory),s=!!(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),c=e.workflows.definitions.some(l=>l.definition.rejectionNotification!==void 0)||n.some(l=>l.platformAccess?.notification)||e.events.subscriptions.some(l=>l.platformAccess?.notification),f=(l,y,R=!1)=>{let h=o.find($=>$.code===l.definition.subject?.resourceCode)?.schema.fields||[];return Object.values(l.definition.taskPages||{}).some($=>$.fields.some(k=>{if(k.readonly)return!1;let M=h.find(Y=>Y.code===k.code);if(!R&&M&&y.includes(M.type))return!0;if(!k.subtable||!M?.subtable)return!1;let V=o.find(Y=>Y.code===M.subtable.resourceCode)?.schema.fields||[];return k.subtable.fields.some(Y=>!Y.readonly&&V.some(ne=>ne.code===Y.code&&y.includes(ne.type)))}))},u=e.workflows.definitions.filter(l=>f(l,["file","image","signature","text.rich"])),p=e.workflows.definitions.filter(l=>f(l,["signature","text.rich"])),_=e.workflows.definitions.filter(l=>f(l,["file","image","signature","text.rich"],!0)),E=e.workflows.definitions.filter(l=>l.launch.mode==="standalone"||l.launch.mode==="hidden-handoff"),A=n.some(l=>l.platformAccess?.workflow)||E.length>0,O=E.filter(l=>{let y=l.launch.submission;if(!y)return!1;let R=o.find(h=>h.code===l.definition.subject.resourceCode);return[y.create,y.existing].some(h=>h&&Object.values(h.inputs).some($=>$.source==="field"&&R?.schema.fields.some(k=>k.code===$.fieldCode&&k.type.startsWith("resource-ref.")&&k.source)))}),b={resources:o},g={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(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[...qt(e)?[{code:"application.extended-artifact-capacity",declaration:Ae}]:[],...Fn(e)?[{code:"application.extended-declaration-capacity",declaration:{resources:e.data.resources.length,policies:e.authz.dataPolicies.length,roles:e.authz.roles.length,capabilities:e.authz.capabilities.length,definitions:e.workflows.definitions.length,bindings:e.workflows.bindings.length,activations:e.workflows.activations.length,routes:e.frontend.routes.length,navigationItems:e.frontend.admin.navigation.reduce((l,y)=>l+y.items.length,0)}}]:[],...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?.dataCommands)?[{code:"data.business-commands",declaration:n.filter(l=>l.platformAccess?.dataCommands)}]:[],...e.authz.dataPolicies.some(l=>l.publicRead)?[{code:"data.authenticated-public-projection",declaration:e.authz.dataPolicies.filter(l=>l.publicRead)}]:[],...n.some(l=>l.platformAccess?.roleAssertions?.actorAuthority)?[{code:"data.transaction-actor-authority",declaration:n.filter(l=>l.platformAccess?.roleAssertions?.actorAuthority)}]:[],...n.some(l=>l.platformAccess?.workflowStage)?[{code:"workflow.native-stage-guard",declaration:n.filter(l=>l.platformAccess?.workflowStage)}]:[],...n.some(l=>l.platformAccess?.recordEdit)?[{code:"data.record-edit",declaration:n.filter(l=>l.platformAccess?.recordEdit)}]:[],...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:I},{code:"authz.native-batch-explain",declaration:g},{code:"authz.native-management",declaration:g},{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:b},{code:"data.native-golden-crud",declaration:b}]:[],...o.some(l=>l.recordComments!==void 0)?[{code:"data.record-comments",declaration:b}]:[],...o.some(l=>l.recordDeletion!==void 0)?[{code:"data.workflow-record-deletion",declaration:b}]:[],...o.some(l=>l.recordPrint!==void 0)?[{code:"data.record-print",declaration:b}]:[],...o.some(l=>l.workflowHistory!==void 0)?[{code:"workflow.record-history-read",declaration:b}]:[],...o.some(uo)?[{code:"data.audit-read-access",declaration:b}]:[],...d?[{code:"directory-v2",declaration:{roles:t.map(l=>({code:l.code,capabilities:l.capabilities.filter(y=>y.endsWith(":directory:read"))})),resources:o.map(l=>({code:l.code,fields:l.schema.fields.filter(y=>["user.single","user.multiple","department.single","department.multiple"].includes(y.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}))}]:[],...i.length||r.length?[{code:"directory.current-initiator-phone",declaration:{operations:i.map(l=>({code:l.code,directory:l.platformAccess.directory})),commands:r.map(l=>({code:l.code,directory:l.execution.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}]:[],...e.events.dateTriggers.some(l=>ii(l.resourceCode,e.events.subscriptions.filter(y=>y.eventTypes.includes(l.eventType)),e.data.resources.find(y=>y.code===l.resourceCode)).length>0)?[{code:"events.date-source-projection",declaration:{triggers:e.events.dateTriggers,subscriptions:e.events.subscriptions}}]:[],...s?[{code:"events-v2",declaration:e.events},{code:"events.durable-receipts",declaration:e.events}]:[],...tn(e.data.resources)?[{code:"data.extended-owned-subtable-capacity",declaration:e.data.resources.filter(l=>tn([l]))}]:[],...en(e.data.resources)?[{code:"data.aggregate-owned-subtable-capacity",declaration:e.data.resources.filter(l=>en([l]))}]:[],...e.data.resources.some(l=>l.schema.fields.some(y=>y.userCandidates!==void 0))?[{code:"data.user-candidates",declaration:e.data.resources.filter(l=>l.schema.fields.some(y=>y.userCandidates!==void 0))}]:[],...zo(e.workflows.bindings)?[{code:"workflow.role-union",declaration:e.workflows.bindings.filter(l=>Object.values(l.binding.bindings).some(y=>y.roleCodes!==void 0))}]:[],...e.backend.operations.some(l=>l.platformAccess?.ownedSubject)?[{code:"workflow.named-owned-create",declaration:e.backend.operations.filter(l=>l.platformAccess?.ownedSubject)}]:[],...Zt(e.data.resources)?[{code:"data.user-candidate-launch-scope",declaration:e.data.resources.filter(l=>Zt([l]))}]:[],...sn(e.data.resources)?[{code:"data.subtable-minimum-rows",declaration:e.data.resources.filter(l=>sn([l]))}]:[],...rn(e.data.resources)?[{code:"data.datetime-minute-precision",declaration:e.data.resources.filter(l=>rn([l]))}]:[],...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=>l.definition.instanceCommands?.withdraw?.reasonRequired===!1)?[{code:"workflow.optional-withdrawal-reason",declaration:e.workflows.definitions.filter(l=>l.definition.instanceCommands?.withdraw?.reasonRequired===!1)}]:[],...e.workflows.definitions.some(l=>l.definition.rejectionNotification!==void 0)?[{code:"workflow.rejection-notification",declaration:e.workflows.definitions.filter(l=>l.definition.rejectionNotification!==void 0)}]:[],...e.workflows.definitions.some(l=>l.definition.commandHandlers!==void 0)||n.some(l=>l.platformAccess?.workflow?.businessCommands)?[{code:"workflow.business-data-command",declaration:{definitions:e.workflows.definitions.filter(l=>l.definition.commandHandlers!==void 0),operations:n.filter(l=>l.platformAccess?.workflow?.businessCommands)}}]:[],...e.workflows.definitions.some(l=>l.definition.commandHandlers?.resubmit)||n.some(l=>l.platformAccess?.workflow?.businessCommands?.includes("resubmit"))?[{code:"workflow.correction-business-command",declaration:{definitions:e.workflows.definitions.filter(l=>l.definition.commandHandlers?.resubmit),operations:n.filter(l=>l.platformAccess?.workflow?.businessCommands?.includes("resubmit"))}}]:[],...e.workflows.definitions.some(l=>l.definition.launchPreflight!==void 0)?[{code:"workflow.launch-preflight",declaration:e.workflows.definitions.filter(l=>l.definition.launchPreflight!==void 0)}]:[],...e.workflows.definitions.some(l=>l.definition.approvedDelegation!==void 0)?[{code:"workflow.approved-delegation",declaration:e.workflows.definitions.filter(l=>l.definition.approvedDelegation!==void 0)}]:[],...e.workflows.definitions.some(l=>es(l.definition,e.data.resources))?[{code:"workflow.owned-initial-facts",declaration:e.workflows.definitions.filter(l=>es(l.definition,e.data.resources))}]:[],...e.workflows.definitions.some(l=>Object.values(l.definition.nodes).some(y=>y.kind==="correction"))?[{code:"workflow.initiator-correction",declaration:e.workflows.definitions.filter(l=>Object.values(l.definition.nodes).some(y=>y.kind==="correction"))}]:[],...e.workflows.definitions.some(l=>Object.values(l.definition.nodes).some(y=>y.operationPolicy?.reject?.commentRequired===!1))?[{code:"workflow.optional-rejection-comment",declaration:e.workflows.definitions.filter(l=>Object.values(l.definition.nodes).some(y=>y.operationPolicy?.reject?.commentRequired===!1))}]:[],...e.workflows.definitions.some(l=>Object.values(l.definition.nodes).some(y=>Object.values(y.operationPolicy||{}).some(R=>R.reasonRequired===!1)))?[{code:"workflow.optional-operation-reason",declaration:e.workflows.definitions.filter(l=>Object.values(l.definition.nodes).some(y=>Object.values(y.operationPolicy||{}).some(R=>R.reasonRequired===!1)))}]:[],...O.length?[{code:"workflow.named-input-sources",declaration:O}]:[],...e.workflows.definitions.some(l=>Object.values(l.definition.nodes).some(y=>y.administration!==void 0||y.operationPolicy!==void 0))?[{code:"workflow.node-administration",declaration:e.workflows.definitions.filter(l=>Object.values(l.definition.nodes).some(y=>y.administration!==void 0||y.operationPolicy!==void 0))}]:[],...e.workflows.definitions.some(l=>Object.values(l.definition.nodes).some(y=>y.kind==="approval"&&y.emptyPolicy!==void 0))?[{code:"workflow.approval-empty-policy",declaration:e.workflows.definitions.filter(l=>Object.values(l.definition.nodes).some(y=>y.kind==="approval"&&y.emptyPolicy!==void 0))}]:[],...e.workflows.definitions.some(l=>Object.values(l.definition.nodes).some(y=>y.completionDeadline!==void 0))?[{code:"workflow.completion-deadline",declaration:e.workflows.definitions.filter(l=>Object.values(l.definition.nodes).some(y=>y.completionDeadline!==void 0))}]:[],...e.workflows.definitions.some(l=>Object.values(l.definition.nodes).some(y=>y.initiatorApprovalPolicy!==void 0))?[{code:"workflow.initiator-approval-policy",declaration:e.workflows.definitions.filter(l=>Object.values(l.definition.nodes).some(y=>y.initiatorApprovalPolicy!==void 0))}]:[],...e.workflows.definitions.some(l=>Object.values(l.definition.nodes).some(y=>y.kind==="cc"))?[{code:"workflow.automatic-cc",declaration:e.workflows.definitions.filter(l=>Object.values(l.definition.nodes).some(y=>y.kind==="cc"))}]:[],...e.workflows.definitions.some(l=>l.definition.taskPages!==void 0)?["workflow.task-page-submit","workflow.task-private-drafts"].map(l=>({code:l,declaration:e.workflows.definitions.filter(y=>y.definition.taskPages!==void 0)})):[],...u.length?[{code:"workflow.task-managed-files",declaration:u}]:[],..._.length?[{code:"workflow.task-owned-files",declaration:_}]:[],...p.length?[{code:"workflow.task-rich-fields",declaration:p}]:[],...e.workflows.definitions.some(l=>Object.values(l.definition.taskPages||{}).some(y=>y.fields.some(R=>R.subtable)))?[{code:"workflow.task-owned-subtables",declaration:e.workflows.definitions.filter(l=>Object.values(l.definition.taskPages||{}).some(y=>y.fields.some(R=>R.subtable)))}]:[],...e.workflows.definitions.some(l=>Object.values(l.definition.nodes).some(y=>y.kind==="action"))?[{code:"workflow.durable-business-step",declaration:e.workflows.definitions.filter(l=>Object.values(l.definition.nodes).some(y=>y.kind==="action"))}]:[],...e.workflows.definitions.some(l=>Object.values(l.definition.nodes).some(y=>y.kind==="action"&&y.handler.dataTransaction))?[{code:"workflow.step-data-transaction",declaration:e.workflows.definitions.filter(l=>Object.values(l.definition.nodes).some(y=>y.kind==="action"&&y.handler.dataTransaction))}]:[],...e.workflows.bindings.some(l=>Object.values(l.binding.bindings).some(y=>y.routing!==void 0))?[{code:"workflow.assignment-routing",declaration:e.workflows.bindings.filter(l=>Object.values(l.binding.bindings).some(y=>y.routing!==void 0))}]:[],...A?[{code:"business-process.durable-command",declaration:{operations:n.filter(l=>l.platformAccess?.workflow).map(l=>({code:l.code,workflow:l.platformAccess.workflow})),definitions:E,activations:e.workflows.activations.filter(l=>E.some(y=>y.definition.code===l.workflowCode))}}]:[],...c?[{code:"notification-hub-v2",declaration:{...e.workflows.definitions.some(l=>l.definition.rejectionNotification!==void 0)?{rejectionNotifications:e.workflows.definitions.filter(l=>l.definition.rejectionNotification!==void 0)}:{},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:y})=>({code:l,contractVersion:l==="data.unique-keys"?o.some(R=>Lo(R.schema.fields,R.uniqueKeys)==="1.1.0")?"1.1.0":"1.0.0":Hr[l],usageDigest:`sha256:${Z(y)}`})).sort((l,y)=>l.code===y.code?0:l.code<y.code?-1:1)}function Es(e){let t=new Map,o=new Set(e.resources.map(r=>String(r.code)));for(let[r,d]of S(e.capturePolicies===void 0?[]:e.capturePolicies,"/capturePlan/capturePolicies",100).entries()){let s=`/capturePlan/capturePolicies/${r}`,a=N(d,s);C(a,["resourceCode","mode"],s);let c=H(a.resourceCode,`${s}/resourceCode`);o.has(c)||m("NATIVE_EVENT_CAPTURE_RESOURCE_NOT_FOUND",s,{resourceCode:c}),t.has(c)&&m("NATIVE_EVENT_CAPTURE_POLICY_DUPLICATE",s,{resourceCode:c}),a.mode!=="all"&&a.mode!=="subscribed"&&m("NATIVE_EVENT_CAPTURE_MODE_INVALID",`${s}/mode`),t.set(c,a.mode)}let n=new Map(e.dataPolicies.map((r,d)=>{let s=N(r,`/capturePlan/dataPolicies/${d}`);return[String(s.code),s]})),i=e.subscriptions.map((r,d)=>N(r,`/capturePlan/subscriptions/${d}`));return e.resources.map((r,d)=>{let s=`/capturePlan/resources/${d}`,a=N(r,s),c=H(a.code,`${s}/code`),f=a.schema?N(a.schema,`${s}/schema`):a,u=new Set(S(f.fields||[],`${s}/schema/fields`,500).map((y,R)=>G(N(y,`${s}/schema/fields/${R}`).code,`${s}/schema/fields/${R}/code`))),p=a.dataPolicyCode?P(a.dataPolicyCode,`${s}/dataPolicyCode`):null,_=p?n.get(p):void 0;p&&!_&&m("NATIVE_EVENT_CAPTURE_AUTHZ_POLICY_NOT_FOUND",s,{resourceCode:c,dataPolicyCode:p});let E=new Set;for(let y of _?.rules||[])E.add(String(y.field));if(_?.readExpression)for(let y of Gt(_.readExpression,`${s}/readExpression`))E.add(String(y.rule.field));let A=new Set,O=new Set,b=new Set;for(let[y,R]of i.entries()){let h=S(R.eventTypes,`/capturePlan/subscriptions/${y}/eventTypes`,20).map(String);if(!h.some(V=>V.startsWith("openxiangda.data.")))continue;let $=N(R.filter||{},`/capturePlan/subscriptions/${y}/filter`),k=Array.isArray($.resourceCodes)?$.resourceCodes.map(String):[];if(k.length&&!k.includes(c))continue;for(let V of h)xn.includes(V)&&b.add(V);for(let V of Rc($,`/capturePlan/subscriptions/${y}/filter`))A.add(V);let M=N(R.payload||{},`/capturePlan/subscriptions/${y}/payload`);for(let V of S(M.fields||[],`/capturePlan/subscriptions/${y}/payload/fields`,32))O.add(G(V,`/capturePlan/subscriptions/${y}/payload/fields`))}let g=new Set([...A,...O]),I=new Set([...g,...E]);I.size>Qr&&m("NATIVE_EVENT_CAPTURE_FIELDS_LIMIT",s,{resourceCode:c,maximum:Qr});for(let y of I)!u.has(y)&&!(E.has(y)&&gs.has(y))&&m("NATIVE_EVENT_CAPTURE_FIELD_NOT_FOUND",s,{resourceCode:c,field:y});let T=N(a.fieldPolicies||{},`${s}/fieldPolicies`);for(let y of g)T[y]?.mask==="omit"&&m("NATIVE_EVENT_CAPTURE_FIELD_SENSITIVE",s,{resourceCode:c,field:y});let l={resourceCode:c,...t.get(c)==="subscribed"?{capturedEventTypes:[...b].sort()}:{},filterFields:[...A].sort(),projectionFields:[...O].sort(),authorizationFields:[...E].sort(),captureFields:[...I].sort()};return{...l,digest:Z(l)}}).sort((r,d)=>r.resourceCode.localeCompare(d.resourceCode))}function Rc(e,t){let o=new Set;for(let[d,s]of S(e.changes||[],`${t}/changes`,16).entries()){let a=N(s,`${t}/changes/${d}`);o.add(G(a.field,`${t}/changes/${d}/field`))}let n=N(e.changedFields||{},`${t}/changedFields`);for(let d of["anyOf","allOf","noneOf"])for(let[s,a]of S(n[d]||[],`${t}/changedFields/${d}`,32).entries())o.add(G(a,`${t}/changedFields/${d}/${s}`));let i=0,r=(d,s,a)=>{a>3&&m("NATIVE_EVENT_FILTER_DEPTH_LIMIT",s);let c=N(d,s);if(c.change){let u=N(c.change,`${s}/change`);o.add(G(u.field,`${s}/change/field`)),i+=1;return}if(c.not){r(c.not,`${s}/not`,a+1);return}let f=c.all?"all":c.any?"any":null;f||m("NATIVE_EVENT_FILTER_CONDITION_INVALID",s);for(let[u,p]of S(c[f],`${s}/${f}`,16).entries())r(p,`${s}/${f}/${u}`,a+1)};return e.where&&r(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 Cc(e,t){C(e,["schemaVersion","compilerContractVersion","appCode","perspectives","authz","backend","data","events","workflows","frontend","runtime"],"/config"),F(e.schemaVersion,tc,"/config/schemaVersion"),F(e.compilerContractVersion,Jt,"/config/compilerContractVersion"),F(e.appCode,t,"/config/appCode"),S(e.perspectives,"/config/perspectives",100);let o=N(e.authz,"/config/authz");C(o,["capabilities","roles","scopeDimensions","scopeSources","roleMembershipSources","relationshipGrantSources","dataPolicies","authorizationTransitions"],"/config/authz",["authenticatedUserRoleCode"]),S(o.capabilities,"/config/authz/capabilities",B.capabilities),S(o.roles,"/config/authz/roles",B.roles),S(o.scopeDimensions,"/config/authz/scopeDimensions",100),S(o.scopeSources,"/config/authz/scopeSources",100),S(o.roleMembershipSources,"/config/authz/roleMembershipSources",100),S(o.relationshipGrantSources,"/config/authz/relationshipGrantSources",100),S(o.dataPolicies,"/config/authz/dataPolicies",B.dataPolicies),S(o.authorizationTransitions,"/config/authz/authorizationTransitions",100);let n=N(e.backend,"/config/backend");C(n,["secrets","operations"],"/config/backend"),S(n.secrets,"/config/backend/secrets",100),S(n.operations,"/config/backend/operations",500),dl(n.secrets);let i=N(e.data,"/config/data");C(i,["resources"],"/config/data",["resourceDetailRoutes","subjectReadSurfaces","concurrency"]),S(i.resources,"/config/data/resources",B.resources),i.subjectReadSurfaces!==void 0&&S(i.subjectReadSurfaces,"/config/data/subjectReadSurfaces",B.subjectReadSurfaces),i.resourceDetailRoutes!==void 0&&S(i.resourceDetailRoutes,"/config/data/resourceDetailRoutes",100);let r=N(e.events,"/config/events");C(r,["schemas","subscriptions","timers","dateTriggers"],"/config/events",["capturePolicies"]),S(r.schemas,"/config/events/schemas",100),S(r.subscriptions,"/config/events/subscriptions",100),S(r.timers,"/config/events/timers",100),S(r.dateTriggers,"/config/events/dateTriggers",100);let d=N(e.workflows,"/config/workflows");C(d,["definitions","bindings","activations","providers","editableParameters"],"/config/workflows"),S(d.definitions,"/config/workflows/definitions",B.workflows),S(d.bindings,"/config/workflows/bindings",B.workflows),S(d.activations,"/config/workflows/activations",B.workflows),S(d.providers,"/config/workflows/providers",100),S(d.editableParameters,"/config/workflows/editableParameters",100);let s=N(e.frontend,"/config/frontend");C(s,["routes","user","admin","devicePolicy"],"/config/frontend",["authentication","publicAccess"]),S(s.routes,"/config/frontend/routes",B.routes);let a=N(s.user,"/config/frontend/user");C(a,["applicationTodoCenter"],"/config/frontend/user"),Et(a.applicationTodoCenter,"/config/frontend/user/applicationTodoCenter"),Ni(s.devicePolicy,"/config/frontend/devicePolicy"),Object.prototype.hasOwnProperty.call(s,"authentication")&&ys(s.authentication,s.routes,e,"/config/frontend/authentication"),Object.prototype.hasOwnProperty.call(s,"publicAccess")&&Bc(s.publicAccess,e,"/config/frontend/publicAccess");let c=N(s.admin,"/config/frontend/admin");C(c,["navigation"],"/config/frontend/admin",["access"]),c.access!==void 0&&qn(c.access,"/config/frontend/admin/access",e.appCode),zc(c.navigation,"/config/frontend/admin/navigation");let f=N(e.runtime,"/config/runtime");C(f,["protocolCapabilities","health"],"/config/runtime"),L(f.protocolCapabilities,"/config/runtime/protocolCapabilities",100),C(N(f.health,"/config/runtime/health"),["livePath","readyPath","versionPath"],"/config/runtime/health"),F(f.health.livePath,"/__platform/health","/config/runtime/health/livePath"),F(f.health.readyPath,"/__platform/ready","/config/runtime/health/readyPath"),F(f.health.versionPath,"/__platform/version","/config/runtime/health/versionPath")}function hc(e,t,o){C(e,["schemaVersion","compilerContractVersion","generatorVersion","appCode","configDigest","perspectives","resources","capabilities","operations","eventConsumers","eventProducers","eventSchemas","eventHandlerManifest","eventTypes","workflows","routes","routeManifest","adminPages","adminNavigation"],"/contracts",["authentication","publicAccess","adminAccess","subjectReadSurfaces","concurrency"]),F(e.schemaVersion,ms,"/contracts/schemaVersion"),F(e.compilerContractVersion,Jt,"/contracts/compilerContractVersion"),w(e.generatorVersion,"/contracts/generatorVersion",128),F(e.appCode,t,"/contracts/appCode"),F(e.configDigest,o,"/contracts/configDigest"),S(e.perspectives,"/contracts/perspectives",B.perspectives),S(e.resources,"/contracts/resources",B.resources),e.subjectReadSurfaces!==void 0&&S(e.subjectReadSurfaces,"/contracts/subjectReadSurfaces",B.subjectReadSurfaces),S(e.capabilities,"/contracts/capabilities",B.capabilities),S(e.operations,"/contracts/operations",B.operations),S(e.eventConsumers,"/contracts/eventConsumers",B.eventConsumers),S(e.eventProducers,"/contracts/eventProducers",B.eventProducers),S(e.eventSchemas,"/contracts/eventSchemas",B.eventSchemas),N(e.eventHandlerManifest,"/contracts/eventHandlerManifest"),L(e.eventTypes,"/contracts/eventTypes",B.eventTypes),S(e.workflows,"/contracts/workflows",B.workflows),S(e.routes,"/contracts/routes",B.routes),Object.prototype.hasOwnProperty.call(e,"authentication")&&Wc(e.authentication,"/contracts/authentication"),Object.prototype.hasOwnProperty.call(e,"publicAccess")&&Kc(e.publicAccess,"/contracts/publicAccess"),Object.prototype.hasOwnProperty.call(e,"adminAccess")&&qn(e.adminAccess,"/contracts/adminAccess",t),Qc(e.routeManifest,"/contracts/routeManifest",t),Yc(e.adminPages,"/contracts/adminPages"),Xc(e.adminNavigation,"/contracts/adminNavigation")}function wc(e,t,o){let n=kc(e);il(e,n),sl(e),rl(e),cl(e);let i=e.events.schemas.map((g,I)=>{let T=`/config/events/schemas/${I}`,l=N(g,T),y=w(l.eventType,`${T}/eventType`,255);return y.startsWith("openxiangda.")&&m("NATIVE_EVENT_SCHEMA_RESERVED",`${T}/eventType`,{eventType:y}),F(l.schemaDigest,Z(N(l.jsonSchema,`${T}/jsonSchema`)),`${T}/schemaDigest`),l}),r=new Set([...xn,...jn,...i.map(g=>String(g.eventType))]),d=new Map(e.data.resources.map(g=>[String(g.code),new Map(g.schema.fields.map(I=>[String(I.code),String(I.type)]))])),s=ee(e.events.subscriptions.map((g,I)=>{let T=`/config/events/subscriptions/${I}`,l=N(g,T),y=L(l.eventTypes,`${T}/eventTypes`,20);y.forEach((k,M)=>{r.has(k)||m("NATIVE_EVENT_TYPE_NOT_REGISTERED",`${T}/eventTypes/${M}`,{eventType:k})});let R=Vo(l,e.data.resources,T),h=Dc(l.delivery,y,`${T}/delivery`),$=Sc(l.platformAccess,`${T}/platformAccess`,d,e,l);return{code:P(l.code,`${T}/code`),endpointPath:Ne(l.endpointPath,`${T}/endpointPath`),eventTypes:y,filter:N(l.filter,`${T}/filter`),payload:R?.payload||N(l.payload,`${T}/payload`),...R?{execution:R.execution}:{},...$?{platformAccess:$}:{},delivery:h}}),g=>g.code),a=new Map(i.map(g=>[String(g.eventType),String(g.dataSchemaVersion)])),c=ee([...e.data.resources.flatMap(g=>xn.map(I=>({code:`data:${g.code}:${I}`,source:"data",eventType:I,dataSchemaVersion:"2.0.0",resourceCode:g.code}))),...i.map(g=>({code:`app:${g.eventType}`,source:"app",eventType:g.eventType,dataSchemaVersion:g.dataSchemaVersion})),...e.events.timers.map(g=>({code:g.code,source:"timer",eventType:g.eventType,dataSchemaVersion:a.get(String(g.eventType))||"2.0.0"})),...e.events.dateTriggers.map(g=>({code:g.code,source:"date",eventType:g.eventType,dataSchemaVersion:a.get(String(g.eventType))||"2.0.0",resourceCode:g.resourceCode,field:g.field})),...e.workflows.activations.length?jn.filter(g=>!Uo.includes(g)||e.workflows.definitions.some(I=>Object.values(I.definition.nodes).some(T=>T.kind==="action"))).filter(g=>g!=="openxiangda.workflow.node.skipped.v2"||e.workflows.definitions.some(I=>Object.values(I.definition.nodes).some(T=>T.kind==="approval"&&T.emptyPolicy==="skip"))).map(g=>({code:`workflow:${g}`,source:"workflow",eventType:g,dataSchemaVersion:"2.0.0"})):[]],g=>`${g.source}:${g.code}:${g.eventType}`),f=U([...s.flatMap(g=>g.eventTypes),...c.map(g=>String(g.eventType))]);Hc(e);let u=Ns(e),p;try{p=Oo(e.data.concurrency,e.data.resources,n)}catch(g){throw g instanceof st&&m(g.code,g.pointer,{reason:g.reason}),g}p?.commands.some(g=>g.mode==="durable")&&e.backend?.enabled===!1&&m("NATIVE_MANAGED_CONCURRENCY_INVALID","/data/concurrency",{reason:"durable commands require backend runtime"});let _=vc(e,n),E=Is(e),A=e.workflows.definitions.map(g=>g.definition),O=Cn(A),b=Bo(A,s,!0);b.length&&m(b[0],"/config/events/subscriptions");try{Co(e.data.resources,E)}catch(g){throw g instanceof Ke&&m(g.code,g.pointer,{reason:g.reason}),g}return{schemaVersion:ms,compilerContractVersion:Jt,generatorVersion:o,appCode:e.appCode,configDigest:t,perspectives:e.perspectives,resources:$c(e),..._.length?{subjectReadSurfaces:_}:{},...p?{concurrency:p}:{},capabilities:ee(n,g=>g.code),operations:E,eventConsumers:s,eventProducers:c,eventSchemas:i,eventHandlerManifest:{schemaVersion:Oc,appCode:e.appCode,handlers:s.filter(g=>!g.execution).map(g=>({code:g.code,endpointPath:g.endpointPath,eventTypes:g.eventTypes,dataSchemaVersions:U(g.eventTypes.map(I=>I.startsWith("openxiangda.")?"2.0.0":a.get(I)||"2.0.0")),maxBodyBytes:65536,receiptProtocolVersion:2,...O[g.code]?{workflowStep:O[g.code]}:{}}))},eventTypes:f,workflows:Cs(e),routes:Gn(e),...Object.prototype.hasOwnProperty.call(e.frontend,"authentication")?{authentication:Uc(e)}:{},...Object.prototype.hasOwnProperty.call(e.frontend,"publicAccess")?{publicAccess:Gc(e)}:{},...e.frontend.admin.access?{adminAccess:e.frontend.admin.access}:{},routeManifest:nl(e),adminPages:u,adminNavigation:qc(e)}}function Sc(e,t,o,n,i){if(e===void 0)return;let r=N(e,t);C(r,["notification","managedFileCopies","decimalReservation"],t,!0);let d={};if(r.decimalReservation!==void 0)try{d.decimalReservation=gr(r.decimalReservation,Ar(n,i))}catch{m("NATIVE_EVENT_DECIMAL_RESERVATION_INVALID",`${t}/decimalReservation`)}if(r.notification!==void 0){let s=N(r.notification,`${t}/notification`);C(s,["mode"],`${t}/notification`),F(s.mode,"business-standard",`${t}/notification/mode`),d.notification={mode:"business-standard"}}if(r.managedFileCopies!==void 0){let s=S(r.managedFileCopies,`${t}/managedFileCopies`,16);s.length||m("NATIVE_EVENT_MANAGED_FILE_COPIES_REQUIRED",`${t}/managedFileCopies`);let a=new Set;d.managedFileCopies=ee(s.map((c,f)=>{let u=`${t}/managedFileCopies/${f}`,p=N(c,u);C(p,["mode","sourceResourceCode","sourceFieldCodes","targetResourceCode","targetFieldCodes"],u),F(p.mode,"copy",`${u}/mode`);let _=H(p.sourceResourceCode,`${u}/sourceResourceCode`),E=H(p.targetResourceCode,`${u}/targetResourceCode`),A=o.get(_),O=o.get(E);(!A||!O)&&m("NATIVE_EVENT_MANAGED_FILE_COPY_RESOURCE_INVALID",u);let b=L(p.sourceFieldCodes,`${u}/sourceFieldCodes`,16),g=L(p.targetFieldCodes,`${u}/targetFieldCodes`,16);(!b.length||b.length!==g.length)&&m("NATIVE_EVENT_MANAGED_FILE_COPY_FIELDS_INVALID",u),b.forEach((T,l)=>{let y=A.get(T),R=O.get(g[l]);(!["file","image"].includes(String(y))||y!==R)&&m("NATIVE_EVENT_MANAGED_FILE_COPY_FIELD_INVALID",`${u}/sourceFieldCodes/${l}`)});let I=`${_}:${b.join(",")}=>${E}:${g.join(",")}`;return a.has(I)&&m("NATIVE_EVENT_MANAGED_FILE_COPY_DUPLICATE",u),a.add(I),{mode:"copy",sourceResourceCode:_,sourceFieldCodes:U(b),targetResourceCode:E,targetFieldCodes:U(g)}}),c=>`${c.sourceResourceCode}:${c.sourceFieldCodes.join(",")}=>${c.targetResourceCode}:${c.targetFieldCodes.join(",")}`)}return Object.keys(d).length||m("NATIVE_EVENT_PLATFORM_ACCESS_EMPTY",t),d}function Dc(e,t,o){let n=N(e,o);C(n,["timeoutMs","maxAttempts","initialBackoffMs","maxBackoffMs","ordering","concurrency"],o),ie(n.timeoutMs,`${o}/timeoutMs`,1e3,3e4),ie(n.maxAttempts,`${o}/maxAttempts`,1,12);let i=ie(n.initialBackoffMs,`${o}/initialBackoffMs`,1e3,3e5);ie(n.maxBackoffMs,`${o}/maxBackoffMs`,i,18e5),ie(n.concurrency,`${o}/concurrency`,1,50);let r=w(n.ordering,`${o}/ordering`,32);return["none","record","workflow-instance"].includes(r)||m("NATIVE_EVENT_DELIVERY_ORDERING_INVALID",`${o}/ordering`),r==="workflow-instance"&&t.some(d=>!Nc.has(d))&&m("NATIVE_EVENT_WORKFLOW_ORDERING_REQUIRES_WORKFLOW_FACTS",`${o}/ordering`),n}function kc(e){let t=new Map;for(let r of Ss(e.appCode))t.set(r.code,r);for(let[r,d]of e.authz.capabilities.entries()){let s=`/config/authz/capabilities/${r}`,a=N(d,s);C(a,["code","kind","name","description"],s,!0);let c=pe(a.code,`${s}/code`,e.appCode);t.has(c)&&m("NATIVE_CAPABILITY_DUPLICATE",`${s}/code`),["backend","ui"].includes(a.kind)||m("NATIVE_CAPABILITY_KIND_INVALID",`${s}/kind`);let f={code:c,kind:a.kind,name:w(a.name,`${s}/name`,255),source:"explicit",...a.description===void 0?{}:{description:Ri(a.description,`${s}/description`,2e3)}};t.set(c,f)}let o=e.data.resources.map((r,d)=>({pointer:`/config/data/resources/${d}`,resource:Ye(r,`/config/data/resources/${d}`,e.appCode)}));for(let{pointer:r,resource:d}of o){let s={read:`\u8BFB\u53D6${d.name}`,create:`\u65B0\u5EFA${d.name}`,update:`\u66F4\u65B0${d.name}`,delete:`\u5220\u9664${d.name}`};for(let a of["read","create","update","delete"]){let c=pe(d.capabilities[a],`${r}/capabilities/${a}`,e.appCode);t.has(c)&&m("NATIVE_CAPABILITY_DUPLICATE",`${r}/capabilities/${a}`),t.set(c,{code:c,kind:"data",name:s[a],source:"data"})}}let n=new Set(t.keys()),i=new Map;for(let{pointer:r,resource:d}of o)for(let[s,a]of Object.entries(d.fieldPolicies)){if(nt(s))continue;let c=N(a,`${r}/fieldPolicies/${s}`);for(let f of["read","create","update"])if(Array.isArray(c[f]))for(let u of L(c[f],`${r}/fieldPolicies/${s}/${f}`,2e3)){if(pe(u,`${r}/fieldPolicies/${s}/${f}`,e.appCode),n.has(u))continue;let p=i.get(u);p&&p!==d.code&&m("NATIVE_CAPABILITY_DUPLICATE",`${r}/fieldPolicies/${s}/${f}`),i.set(u,d.code),!t.has(u)&&t.set(u,{code:u,kind:"data",name:`${d.name}.${s}.${f}`,source:"data"})}}return[...t.values()]}function $c(e){let t=Pc(e);return ee(e.data.resources.map((o,n)=>{let i=Ye(o,`/config/data/resources/${n}`,e.appCode),r=t.get(i.code);return{code:i.code,schemaDigest:Z(i.schema),fields:ee(i.schema.fields.map(d=>({code:d.code,type:d.type})),d=>d.code),...r?{detailRouteCode:r}:{}}}),o=>o.code)}function vc(e,t){if(e.data.subjectReadSurfaces===void 0)return[];let o=S(e.data.subjectReadSurfaces,"/config/data/subjectReadSurfaces",B.subjectReadSurfaces),n=new Set(t.map(d=>String(d.code))),i=new Map(e.data.resources.map((d,s)=>{let a=`/config/data/resources/${s}`,c=Ye(d,a,e.appCode);return[String(c.code),{resource:c,fields:new Map(S(N(c.schema,`${a}/schema`).fields,`${a}/schema/fields`,500).map(f=>{let u=N(f,`${a}/schema/fields`);return[String(u.code),u]}))}]})),r=new Set;return ee(o.map((d,s)=>{let a=`/config/data/subjectReadSurfaces/${s}`,c=N(d,a);C(c,["code","name","capability","subject","relations"],a);let f=P(c.code,`${a}/code`);r.has(f)&&m("NATIVE_SUBJECT_READ_SURFACE_CODE_DUPLICATE",`${a}/code`),r.add(f);let u=pe(c.capability,`${a}/capability`,e.appCode);n.has(u)||m("NATIVE_SUBJECT_READ_SURFACE_CAPABILITY_NOT_DECLARED",`${a}/capability`);let p=N(c.subject,`${a}/subject`);C(p,["resourceCode","fields"],`${a}/subject`);let _=H(p.resourceCode,`${a}/subject/resourceCode`),E=i.get(_);E||m("NATIVE_SUBJECT_READ_SURFACE_RESOURCE_NOT_DECLARED",`${a}/subject/resourceCode`);let A=L(p.fields,`${a}/subject/fields`,100).map((T,l)=>G(T,`${a}/subject/fields/${l}`));A.length||m("NATIVE_SUBJECT_READ_SURFACE_FIELDS_REQUIRED",`${a}/subject/fields`);for(let[T,l]of A.entries()){let y=E.fields.get(l);(!y||y.type==="subtable")&&m("NATIVE_SUBJECT_READ_SURFACE_FIELD_INVALID",`${a}/subject/fields/${T}`)}let O=S(c.relations,`${a}/relations`,8);O.length||m("NATIVE_SUBJECT_READ_SURFACE_RELATIONS_REQUIRED",`${a}/relations`);let b=new Set,g=0,I=ee(O.map((T,l)=>{let y=`${a}/relations/${l}`,R=N(T,y);C(R,["code","resourceCode","foreignKeyField","fields","limit"],y,["order"]);let h=P(R.code,`${y}/code`);b.has(h)&&m("NATIVE_SUBJECT_READ_SURFACE_RELATION_CODE_DUPLICATE",`${y}/code`),b.add(h);let $=H(R.resourceCode,`${y}/resourceCode`),k=i.get($);k||m("NATIVE_SUBJECT_READ_SURFACE_RESOURCE_NOT_DECLARED",`${y}/resourceCode`);let M=G(R.foreignKeyField,`${y}/foreignKeyField`),V=k.fields.get(M),Y=N(V?.source||{},`${y}/foreignKeyField/source`);(!V||!["uuid","resource-ref.single"].includes(String(V.type))||V.type==="resource-ref.single"&&(Y.kind!=="resource"||Y.resourceCode!==_))&&m("NATIVE_SUBJECT_READ_SURFACE_RELATION_INVALID",`${y}/foreignKeyField`);let ne=L(R.fields,`${y}/fields`,100).map((le,v)=>G(le,`${y}/fields/${v}`));ne.length||m("NATIVE_SUBJECT_READ_SURFACE_FIELDS_REQUIRED",`${y}/fields`);for(let[le,v]of ne.entries()){let W=k.fields.get(v);(!W||W.type==="subtable")&&m("NATIVE_SUBJECT_READ_SURFACE_FIELD_INVALID",`${y}/fields/${le}`)}let X=S(R.order||[],`${y}/order`,10).map((le,v)=>{let W=`${y}/order/${v}`,x=N(le,W);C(x,["field","direction"],W);let q=G(x.field,`${W}/field`),z=k.fields.get(q);return(!gs.has(q)&&!z||z?.type==="subtable"||z&&!it(z.type))&&m("NATIVE_SUBJECT_READ_SURFACE_ORDER_FIELD_INVALID",`${W}/field`),["asc","desc"].includes(String(x.direction))||m("NATIVE_SUBJECT_READ_SURFACE_ORDER_DIRECTION_INVALID",`${W}/direction`),{field:q,direction:x.direction}}),ce=ie(R.limit,`${y}/limit`,1,100);return g+=ce,{code:h,resourceCode:$,foreignKeyField:M,fields:U(ne),...X.length?{order:X}:{},limit:ce}}),T=>T.code);return g>400&&m("NATIVE_SUBJECT_READ_SURFACE_ROW_LIMIT_EXCEEDED",`${a}/relations`),{code:f,name:w(c.name,`${a}/name`,255),capability:u,subject:{resourceCode:_,fields:U(A)},relations:I}}),d=>d.code)}function Pc(e){let t=e.data.resourceDetailRoutes===void 0?[]:S(e.data.resourceDetailRoutes,"/config/data/resourceDetailRoutes",100),o=new Map(e.data.resources.map((r,d)=>{let s=`/config/data/resources/${d}`,a=Ye(r,s,e.appCode);return[a.code,a]})),n=new Map(Gn(e).map(r=>[String(r.code),r])),i=new Map;for(let[r,d]of t.entries()){let s=`/config/data/resourceDetailRoutes/${r}`,a=N(d,s);C(a,["resourceCode","desktop","mobile"],s);let c=H(a.resourceCode,`${s}/resourceCode`);i.has(c)&&m("NATIVE_DATA_RESOURCE_DETAIL_ROUTE_DUPLICATE",`${s}/resourceCode`);let f=o.get(c);f||m("NATIVE_DATA_RESOURCE_DETAIL_ROUTE_RESOURCE_MISSING",`${s}/resourceCode`);let u=P(a.desktop,`${s}/desktop`),p=P(a.mobile,`${s}/mobile`);u===p&&m("NATIVE_DATA_RESOURCE_DETAIL_ROUTE_INVALID",s);let _=String(f.capabilities.read);for(let[E,A]of[["desktop",u],["mobile",p]]){let O=`${s}/${E}`,b=n.get(A);b||m("NATIVE_DATA_RESOURCE_DETAIL_ROUTE_REFERENCE_MISSING",O),b.surface!=="user"&&m("NATIVE_DATA_RESOURCE_DETAIL_ROUTE_SURFACE_INVALID",O);let g=Ne(b.path,`${O}/path`),I=[...g.matchAll(/:([A-Za-z][A-Za-z0-9_]*)/g)],T=E==="mobile"?!g.startsWith("/m/"):g==="/m"||g.startsWith("/m/");(g.includes("*")||g.includes("?")||g.includes("#")||g.split("/").includes("..")||I.length!==1||T)&&m("NATIVE_DATA_RESOURCE_DETAIL_ROUTE_PATH_INVALID",O);let l=Array.isArray(b.access?.allOf)?b.access.allOf:[];b.capability!==_&&!l.includes(_)&&m("NATIVE_DATA_RESOURCE_DETAIL_ROUTE_CAPABILITY_INVALID",O)}i.set(c,{desktop:u,mobile:p})}return i}function Is(e){let t=new Map(e.data.resources.map((d,s)=>{let a=`/config/data/resources/${s}`,c=Ye(d,a,e.appCode);return[c.code,new Map(c.schema.fields.map(f=>[String(f.code),f]))]})),o=new Map(e.data.resources.map((d,s)=>{let a=`/config/data/resources/${s}`,c=Ye(d,a,e.appCode);return[c.code,new Map(c.schema.fields.map(f=>[String(f.code),String(f.type)]))]})),n=new Set(o.keys()),i=new Set(e.workflows.activations.map((d,s)=>zn(N(d,`/config/workflows/activations/${s}`).workflowCode,`/config/workflows/activations/${s}/workflowCode`))),r=new Map;return ee(e.backend.operations.map((d,s)=>{let a=`/config/backend/operations/${s}`,c=N(d,a);C(c,["code","method","path","capability","requestSchema","responseSchema","description","platformAccess","browser","ai"],a,!0);let f=w(c.method,`${a}/method`,16);["GET","POST","PUT","PATCH","DELETE"].includes(f)||m("NATIVE_OPERATION_METHOD_INVALID",`${a}/method`);let u=P(c.code,`${a}/code`);xc(c.ai,a,u,f,n);let p=Fc(c.platformAccess,`${a}/platformAccess`,o,t,i,new Set(e.authz.roles.map(E=>String(E.code))));if(p?.workflowStage){let E=p.workflowStage,A=e.workflows.definitions.find(O=>O.definition.code===E.workflowCode);(!A||A.definition.subject?.resourceCode!==E.resourceCode||E.runningNodeIds.some(O=>!A.definition.nodes[O]))&&m("NATIVE_WORKFLOW_STAGE_NODE_INVALID",`${a}/platformAccess/workflowStage/runningNodeIds`)}if(p?.recordEdit){let E=e.data.resources.find(A=>A.code===p.recordEdit.resourceCode);E?.surface?.mutationOwner!=="action"&&m("NATIVE_RECORD_EDIT_ACTION_OWNER_REQUIRED",`${a}/platformAccess/recordEdit`);for(let A of p.recordEdit.fieldCodes)(!E.fieldPolicies?.[A]?.update?.length||E.surface?.fields?.[A]?.system===!0)&&m("NATIVE_RECORD_EDIT_FIELD_INVALID",`${a}/platformAccess/recordEdit/fieldCodes`)}if(p?.decimalReservation){let E=p.decimalReservation,A=String(E.resourceCode),O=JSON.stringify([E.amountFieldCode,E.currencyFieldCode,E.relationFieldCode,E.parentFieldCode,E.rootFieldCode,E.statusFieldCode,E.parentRelationValue,E.childRelationValue]),b=r.get(A);b&&b!==O&&m("NATIVE_DECIMAL_RESERVATION_MAPPING_CONFLICT",`${a}/platformAccess/decimalReservation`),r.set(A,O)}let _=Lc(c.browser,`${a}/browser`,f,c.requestSchema,c.responseSchema,o,t,e.data.subjectReadSurfaces||[]);return{code:u,method:f,path:Ne(c.path,`${a}/path`),requiredCapability:pe(c.capability,`${a}/capability`,e.appCode),requestSchemaDigest:Z(N(c.requestSchema,`${a}/requestSchema`)),responseSchemaDigest:Z(N(c.responseSchema,`${a}/responseSchema`)),...c.description===void 0?{}:{description:Ri(c.description,`${a}/description`,2e3)},...p?{platformAccess:p}:{},..._?{browser:_}:{}}}),d=>d.code)}function Lc(e,t,o,n,i,r,d,s){if(e===void 0)return null;let a=N(e,t);C(a,["exposure","behavior","idempotency","subject"],t,["refreshTargets","fileIntent"]),F(a.exposure,"authenticated",`${t}/exposure`);let c=w(a.behavior,`${t}/behavior`,32);["read","controlled"].includes(c)||m("NATIVE_OPERATION_BROWSER_BEHAVIOR_INVALID",`${t}/behavior`);let f=w(a.idempotency,`${t}/idempotency`,32);(!["none","required"].includes(f)||c==="controlled"&&f!=="required"||c==="read"&&f!=="none")&&m("NATIVE_OPERATION_BROWSER_IDEMPOTENCY_INVALID",`${t}/idempotency`);let u=N(a.subject,`${t}/subject`);C(u,["resourceCode","inputField"],`${t}/subject`);let p=H(u.resourceCode,`${t}/subject/resourceCode`);r.has(p)||m("NATIVE_OPERATION_BROWSER_SUBJECT_RESOURCE_NOT_DECLARED",`${t}/subject/resourceCode`);let _=G(u.inputField,`${t}/subject/inputField`),E=N(n,`${t}/requestSchema`),A=N(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 O=N(E.properties,`${t}/requestSchema/properties`),b=new Set(E.required===void 0?[]:L(E.required,`${t}/requestSchema/required`,200));(!(_ in O)||!b.has(_))&&m("NATIVE_OPERATION_BROWSER_SUBJECT_INPUT_INVALID",`${t}/subject/inputField`);let g=N(O[_],`${t}/requestSchema/properties/${_}`);(g.type!=="string"||g.format!=="uuid")&&m("NATIVE_OPERATION_BROWSER_SUBJECT_INPUT_INVALID",`${t}/subject/inputField`);let I=new Map((Array.isArray(s)?s:[]).map((h,$)=>{let k=N(h,`/config/data/subjectReadSurfaces/${$}`);return[String(k.code),String(N(k.subject,`/config/data/subjectReadSurfaces/${$}/subject`).resourceCode)]})),T=a.refreshTargets===void 0?[]:S(a.refreshTargets,`${t}/refreshTargets`,16),l=new Set,y=ee(T.map((h,$)=>{let k=`${t}/refreshTargets/${$}`,M=N(h,k);C(M,["kind","code"],k),F(M.kind,"subject-surface",`${k}/kind`);let V=P(M.code,`${k}/code`);return(l.has(V)||!I.has(V)||I.get(V)!==p)&&m("NATIVE_OPERATION_BROWSER_REFRESH_TARGET_INVALID",`${k}/code`),l.add(V),{kind:"subject-surface",code:V}}),h=>`${h.kind}:${h.code}`),R=Vc(a.fileIntent,`${t}/fileIntent`,o,c,f,p,O,b,d);return{exposure:"authenticated",behavior:c,idempotency:f,subject:{resourceCode:p,inputField:_},...y.length?{refreshTargets:y}:{},...R?{fileIntent:R}:{}}}function Vc(e,t,o,n,i,r,d,s,a){if(e===void 0)return null;let c=N(e,t);C(c,["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 f=H(c.recordResourceCode,`${t}/recordResourceCode`),u=a.get(f);u||m("NATIVE_OPERATION_FILE_INTENT_RESOURCE_NOT_DECLARED",`${t}/recordResourceCode`);let p=G(c.recordIdInputField,`${t}/recordIdInputField`),_=N(d[p],`${t}/recordIdInputField`);(!s.has(p)||_.type!=="string"||_.format!=="uuid")&&m("NATIVE_OPERATION_FILE_INTENT_RECORD_INPUT_INVALID",`${t}/recordIdInputField`);let E=G(c.relationField,`${t}/relationField`),A=u.get(E);(!A||!["uuid","resource-ref.single"].includes(String(A.type))||String(A.type)==="resource-ref.single"&&(String(N(A.source,`${t}/relationField`).kind||"")!=="resource"||String(N(A.source,`${t}/relationField`).resourceCode||"")!==r))&&m("NATIVE_OPERATION_FILE_INTENT_RELATION_INVALID",`${t}/relationField`);let O=[["fileNameField",["text.short","text.long"]],["contentTypeField",["text.short","text.long"]],["sizeField",["number.integer"]]],b={};for(let[l,y]of O){let R=G(c[l],`${t}/${l}`);y.includes(String(u.get(R)?.type))||m("NATIVE_OPERATION_FILE_INTENT_METADATA_INVALID",`${t}/${l}`),b[l]=R}let g=ee(L(c.purposes,`${t}/purposes`,2),l=>l);(!g.length||g.some(l=>!["preview","download"].includes(l)))&&m("NATIVE_OPERATION_FILE_INTENT_PURPOSE_INVALID",`${t}/purposes`);let I=Number(c.maxTtlSeconds);(!Number.isSafeInteger(I)||I<1||I>300)&&m("NATIVE_OPERATION_FILE_INTENT_TTL_INVALID",`${t}/maxTtlSeconds`);let T=Number(c.maxBytes);return(!Number.isSafeInteger(T)||T<1||T>104857600)&&m("NATIVE_OPERATION_FILE_INTENT_SIZE_INVALID",`${t}/maxBytes`),{recordResourceCode:f,recordIdInputField:p,relationField:E,fileNameField:b.fileNameField,contentTypeField:b.contentTypeField,sizeField:b.sizeField,purposes:g,maxTtlSeconds:I,maxBytes:T}}function Fc(e,t,o,n,i,r){if(e===void 0)return null;let d=N(e,t);C(d,["directory","managedFiles","managedFileCopies","notification","workflow","roleAssertions","decimalReservation","dataCommands","recordEdit","ownedSubject","workflowStage"],t,!0),Object.keys(d).length===0&&m("NATIVE_OPERATION_PLATFORM_ACCESS_EMPTY",t);let s={};if(d.dataCommands!==void 0){let a=N(d.dataCommands,`${t}/dataCommands`);C(a,["mode"],`${t}/dataCommands`),F(a.mode,"recoverable-native",`${t}/dataCommands/mode`),s.dataCommands={mode:"recoverable-native"}}if(d.workflowStage!==void 0){try{Do(d.workflowStage)}catch{m("NATIVE_WORKFLOW_STAGE_DECLARATION_INVALID",`${t}/workflowStage`)}let a=d.workflowStage;(!s.dataCommands||d.decimalReservation!==void 0||!o.has(a.resourceCode)||!i.has(a.workflowCode)||!d.workflow?.codes?.includes(a.workflowCode))&&m("NATIVE_WORKFLOW_STAGE_DECLARATION_INVALID",`${t}/workflowStage`),s.workflowStage={...a,runningNodeIds:U([...a.runningNodeIds]),allowedStatuses:U([...a.allowedStatuses])}}if(d.recordEdit!==void 0){let a=`${t}/recordEdit`,c=N(d.recordEdit,a);C(c,["resourceCode","fieldCodes"],a);let f=H(c.resourceCode,`${a}/resourceCode`),u=n.get(f),p=L(c.fieldCodes,`${a}/fieldCodes`,200);(!u||!p.length||!s.dataCommands)&&m("NATIVE_RECORD_EDIT_DECLARATION_INVALID",a);for(let _ of p){let E=u.get(_);(!E||E.type==="serial-number"||E.type==="subtable")&&m("NATIVE_RECORD_EDIT_FIELD_INVALID",`${a}/fieldCodes`)}s.recordEdit={resourceCode:f,fieldCodes:U(p)}}if(d.roleAssertions!==void 0){let a=N(d.roleAssertions,`${t}/roleAssertions`);C(a,["roleCodes","actorAuthority"],`${t}/roleAssertions`,!0),a.actorAuthority!==void 0&&F(a.actorAuthority,!0,`${t}/roleAssertions/actorAuthority`);let c=L(a.roleCodes,`${t}/roleAssertions/roleCodes`,20);c.length||m("NATIVE_OPERATION_ROLE_ASSERTIONS_REQUIRED",`${t}/roleAssertions/roleCodes`),c.forEach((f,u)=>{r.has(f)||m("NATIVE_ROLE_REFERENCE_MISSING",`${t}/roleAssertions/roleCodes/${u}`)}),s.roleAssertions={roleCodes:U(c),...a.actorAuthority===!0?{actorAuthority:!0}:{}}}if(d.directory!==void 0){let a=N(d.directory,`${t}/directory`);C(a,["mode","fields"],`${t}/directory`),["current-initiator","selected-user"].includes(String(a.mode))||m("NATIVE_OPERATION_DIRECTORY_MODE_INVALID",`${t}/directory/mode`);let c=new Set(["displayName","employeeNumber","primaryDepartment","departments",...a.mode==="current-initiator"?["phone"]:[]]),f=L(a.fields,`${t}/directory/fields`,c.size);(!f.length||f.some(u=>!c.has(u)))&&m("NATIVE_OPERATION_DIRECTORY_FIELDS_INVALID",`${t}/directory/fields`),s.directory={mode:String(a.mode),fields:U(f)}}if(d.managedFiles!==void 0){let a=S(d.managedFiles,`${t}/managedFiles`,16);a.length||m("NATIVE_OPERATION_MANAGED_FILES_REQUIRED",`${t}/managedFiles`);let c=new Set;s.managedFiles=ee(a.map((f,u)=>{let p=`${t}/managedFiles/${u}`,_=N(f,p);C(_,["resourceCode","fieldCodes","intents"],p);let E=H(_.resourceCode,`${p}/resourceCode`);(c.has(E)||!o.has(E))&&m("NATIVE_OPERATION_MANAGED_FILE_RESOURCE_INVALID",`${p}/resourceCode`),c.add(E);let A=L(_.fieldCodes,`${p}/fieldCodes`,16);(!A.length||A.some(b=>!["file","image","signature","text.rich"].includes(String(o.get(E)?.get(b)||""))))&&m("NATIVE_OPERATION_MANAGED_FILE_FIELD_INVALID",`${p}/fieldCodes`);let O=L(_.intents,`${p}/intents`,2);return(!O.length||O.some(b=>!["create","update"].includes(b)))&&m("NATIVE_OPERATION_MANAGED_FILE_INTENT_INVALID",`${p}/intents`),{resourceCode:E,fieldCodes:U(A),intents:U(O)}}),f=>f.resourceCode)}if(d.managedFileCopies!==void 0){let a=S(d.managedFileCopies,`${t}/managedFileCopies`,16);a.length||m("NATIVE_OPERATION_MANAGED_FILE_COPIES_REQUIRED",`${t}/managedFileCopies`);let c=new Set;s.managedFileCopies=ee(a.map((f,u)=>{let p=`${t}/managedFileCopies/${u}`,_=N(f,p);C(_,["mode","sourceResourceCode","sourceFieldCodes","targetResourceCode","targetFieldCodes"],p),F(_.mode,"copy",`${p}/mode`);let E=H(_.sourceResourceCode,`${p}/sourceResourceCode`),A=H(_.targetResourceCode,`${p}/targetResourceCode`),O=o.get(E),b=o.get(A);(!O||!b)&&m("NATIVE_OPERATION_MANAGED_FILE_COPY_RESOURCE_INVALID",p);let g=L(_.sourceFieldCodes,`${p}/sourceFieldCodes`,16),I=L(_.targetFieldCodes,`${p}/targetFieldCodes`,16);(!g.length||g.length!==I.length)&&m("NATIVE_OPERATION_MANAGED_FILE_COPY_FIELDS_INVALID",p),g.forEach((l,y)=>{let R=O.get(l),h=b.get(I[y]);(!["file","image"].includes(String(R))||R!==h)&&m("NATIVE_OPERATION_MANAGED_FILE_COPY_FIELD_INVALID",`${p}/sourceFieldCodes/${y}`)});let T=`${E}:${g.join(",")}=>${A}:${I.join(",")}`;return c.has(T)&&m("NATIVE_OPERATION_MANAGED_FILE_COPY_DUPLICATE",p),c.add(T),{mode:"copy",sourceResourceCode:E,sourceFieldCodes:U(g),targetResourceCode:A,targetFieldCodes:U(I)}}),f=>`${f.sourceResourceCode}:${f.sourceFieldCodes.join(",")}=>${f.targetResourceCode}:${f.targetFieldCodes.join(",")}`)}if(d.notification!==void 0){let a=N(d.notification,`${t}/notification`);C(a,["mode"],`${t}/notification`),a.mode!=="business-standard"&&m("NATIVE_OPERATION_NOTIFICATION_MODE_INVALID",`${t}/notification/mode`),s.notification={mode:"business-standard"}}if(d.workflow!==void 0){let a=N(d.workflow,`${t}/workflow`);C(a,["codes"],`${t}/workflow`,["businessCommands"]);let c=L(a.codes,`${t}/workflow/codes`,16);(!c.length||c.some(u=>!i.has(u)))&&m("NATIVE_OPERATION_WORKFLOW_CODE_INVALID",`${t}/workflow/codes`);let f=a.businessCommands===void 0?void 0:L(a.businessCommands,`${t}/workflow/businessCommands`,4);f&&(!f.length||f.some(u=>!["approve","reject","withdraw","resubmit"].includes(u)))&&m("NATIVE_OPERATION_WORKFLOW_BUSINESS_COMMAND_INVALID",`${t}/workflow/businessCommands`),s.workflow={codes:U(c),...f?{businessCommands:U(f)}:{}}}if(d.ownedSubject!==void 0){let a=`${t}/ownedSubject`,c=d.ownedSubject;try{Bt(c)}catch{m("NATIVE_WORKFLOW_OWNED_SUBJECT_INVALID",a)}(!s.workflow||d.decimalReservation!==void 0)&&m("NATIVE_WORKFLOW_OWNED_SUBJECT_INVALID",a);try{fi(c,n,s.managedFiles||[])}catch(f){m(`NATIVE_${f.message}`,a)}s.ownedSubject={mode:"create",resourceCode:c.resourceCode,subtables:ee(c.subtables.map(f=>({fieldCode:f.fieldCode,fieldCodes:U([...f.fieldCodes])})),f=>f.fieldCode)}}if(d.decimalReservation!==void 0){let a=`${t}/decimalReservation`,c=N(d.decimalReservation,a);C(c,["mode","resourceCode","amountFieldCode","currencyFieldCode","relationFieldCode","parentFieldCode","rootFieldCode","statusFieldCode","parentRelationValue","childRelationValue","eligibleParentStatuses","eligibleChildStatuses"],a);let f=w(c.mode,`${a}/mode`,16);["reserve","commit","release"].includes(f)||m("NATIVE_DECIMAL_RESERVATION_MODE_INVALID",`${a}/mode`);let u=H(c.resourceCode,`${a}/resourceCode`),p=n.get(u);p||m("NATIVE_DECIMAL_RESERVATION_RESOURCE_MISSING",`${a}/resourceCode`);let E=Object.fromEntries(["amountFieldCode","currencyFieldCode","relationFieldCode","parentFieldCode","rootFieldCode","statusFieldCode"].map(l=>[l,G(c[l],`${a}/${l}`)])),A=l=>p.get(E[l]),O=l=>new Set((A(l)?.options||[]).map(y=>String(y.value))),b=P(c.parentRelationValue,`${a}/parentRelationValue`),g=P(c.childRelationValue,`${a}/childRelationValue`),I=L(c.eligibleParentStatuses,`${a}/eligibleParentStatuses`,16),T=L(c.eligibleChildStatuses,`${a}/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!==u||A("rootFieldCode")?.type!=="uuid"||A("statusFieldCode")?.type!=="option.single"||b===g||!O("relationFieldCode").has(b)||!O("relationFieldCode").has(g)||!I.length||!T.length||I.some(l=>!O("statusFieldCode").has(l))||T.some(l=>!O("statusFieldCode").has(l)))&&m("NATIVE_DECIMAL_RESERVATION_FIELD_INVALID",a),s.decimalReservation={mode:f,resourceCode:u,...E,parentRelationValue:b,childRelationValue:g,eligibleParentStatuses:U(I),eligibleChildStatuses:U(T)}}return s}function xc(e,t,o,n,i){if(e===void 0)return;let r=`${t}/ai`,d=N(e,r);sc.test(o)||m("NATIVE_OPERATION_AI_CODE_INVALID",`${t}/code`),C(d,["name","description","risk","resources","sideEffects","concurrency","timeoutMs"],r,!0),w(d.name,`${r}/name`,Ii),w(d.description,`${r}/description`,Ii);let s=w(d.risk,`${r}/risk`,16);["read","write","destructive","external"].includes(s)||m("NATIVE_OPERATION_AI_RISK_INVALID",`${r}/risk`),s==="read"!=(n==="GET")&&m("NATIVE_OPERATION_AI_METHOD_RISK_MISMATCH",`${r}/risk`),n==="DELETE"&&!["destructive","external"].includes(s)&&m("NATIVE_OPERATION_AI_METHOD_RISK_MISMATCH",`${r}/risk`);let a=L(d.resources,`${r}/resources`,16);a.length===0&&m("NATIVE_OPERATION_AI_RESOURCE_REQUIRED",`${r}/resources`),a.forEach((f,u)=>{let p=H(f,`${r}/resources/${u}`);i.has(p)||m("NATIVE_OPERATION_AI_RESOURCE_MISSING",`${r}/resources/${u}`)});let c=L(d.sideEffects,`${r}/sideEffects`,20);(s==="read"&&c.length!==0||s!=="read"&&c.length===0)&&m("NATIVE_OPERATION_AI_SIDE_EFFECT_INVALID",`${r}/sideEffects`),d.concurrency!==void 0&&!["none","revision"].includes(w(d.concurrency,`${r}/concurrency`,16))&&m("NATIVE_OPERATION_AI_CONCURRENCY_INVALID",`${r}/concurrency`),d.timeoutMs!==void 0&&ie(d.timeoutMs,`${r}/timeoutMs`,100,3e4)}function Un(e){return(e.replace(/\/{2,}/g,"/").replace(/\/$/,"")||"/").split("/").map(o=>o.startsWith(":")?":":o.includes("*")?"*":o).join("/")}function jc(e,t){let o=N(e,t),n=w(o.type,`${t}/type`,32),i=["code","type","label","presentation","required"],r=n==="sso"?[...i,"provider"]:n==="dingtalk"?[...i,"flow"]:i;C(o,r,t);let d=P(o.code,`${t}/code`),s=w(o.label,`${t}/label`,255),a=w(o.presentation,`${t}/presentation`,16);["primary","secondary"].includes(a)||m("NATIVE_APPLICATION_AUTH_METHOD_PRESENTATION_INVALID",`${t}/presentation`);let c=Et(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(w(o.flow,`${t}/flow`,16))&&m("NATIVE_APPLICATION_AUTH_DINGTALK_FLOW_INVALID",`${t}/flow`),{code:d,type:n,label:s,presentation:a,required:c,...n==="sso"?{provider:"tenant-default"}:{},...n==="dingtalk"?{flow:o.flow}:{}}}function ts(e,t,o){let n=N(e,o);C(n,["routeCode","path","defaultRouteCode"],o);let i=P(n.routeCode,`${o}/routeCode`),r=Ne(n.path,`${o}/path`),d=t==="desktop"?"/login":"/m/login";return(r!==d||/[:*?#\\]/.test(r))&&m("NATIVE_APPLICATION_AUTH_SURFACE_PATH_INVALID",`${o}/path`,{device:t,expectedPath:d}),{routeCode:i,path:r,defaultRouteCode:P(n.defaultRouteCode,`${o}/defaultRouteCode`)}}function ys(e,t,o,n){if(e===null)return;let i=N(e,n);C(i,["accountMode","registration","methods","surfaces"],n),F(i.accountMode,"existing-platform-users-only",`${n}/accountMode`);let r=N(i.registration,`${n}/registration`);C(r,["mode"],`${n}/registration`),F(r.mode,"reject",`${n}/registration/mode`);let d=S(i.methods,`${n}/methods`,8);d.length===0&&m("NATIVE_APPLICATION_AUTH_METHOD_REQUIRED",`${n}/methods`);let s=d.map((b,g)=>jc(b,`${n}/methods/${g}`)),a=new Set,c=new Set;for(let[b,g]of s.entries())a.has(g.code)&&m("NATIVE_APPLICATION_AUTH_METHOD_CODE_DUPLICATE",`${n}/methods/${b}/code`),c.has(g.type)&&m("NATIVE_APPLICATION_AUTH_METHOD_TYPE_DUPLICATE",`${n}/methods/${b}/type`),a.add(g.code),c.add(g.type);s.filter(b=>b.presentation==="primary").length!==1&&m("NATIVE_APPLICATION_AUTH_PRIMARY_METHOD_INVALID",`${n}/methods`);let f=N(i.surfaces,`${n}/surfaces`);C(f,["desktop","mobile"],`${n}/surfaces`);let u=ts(f.desktop,"desktop",`${n}/surfaces/desktop`),p=ts(f.mobile,"mobile",`${n}/surfaces/mobile`);u.routeCode===p.routeCode&&m("NATIVE_APPLICATION_AUTH_SURFACE_CODE_DUPLICATE",`${n}/surfaces/mobile/routeCode`);let _=S(t,"/config/frontend/routes",500),E=new Map;for(let[b,g]of _.entries()){let I=N(g,`/config/frontend/routes/${b}`);E.set(String(I.code||""),I)}let A=new Set((Array.isArray(o.data?.resources)?o.data.resources:[]).map(b=>String(b.code||"")).filter(b=>/^[a-z][a-z0-9-]{0,62}$/.test(b)));for(let[b,g]of[["desktop",u],["mobile",p]]){E.has(g.routeCode)&&m("NATIVE_APPLICATION_AUTH_SURFACE_CODE_CONFLICT",`${n}/surfaces/${b}/routeCode`);let I=/^user\.([a-z][a-z0-9-]{0,62})\.(records|submit)$/.exec(String(g.defaultRouteCode||"")),T=E.get(g.defaultRouteCode),l=String(T?.path||"");if(I&&A.has(I[1])){let R=I[2]==="records"?`/my/${I[1]}`:`/my/${I[1]}/submit`;T={surface:"user",path:b==="mobile"?`/m${R}`:R},l=String(T.path)}let y=b==="desktop"?l==="/m"||l.startsWith("/m/"):!(l==="/m"||l.startsWith("/m/"));(!T||T.surface!=="user"||/[:*]/.test(l)||y)&&m("NATIVE_APPLICATION_AUTH_DEFAULT_ROUTE_INVALID",`${n}/surfaces/${b}/defaultRouteCode`)}let O=bs(o).filter(b=>!b.owner.startsWith("authentication:"));for(let[b,g]of[["desktop",u],["mobile",p]]){let I=O.find(T=>Un(T.path)===Un(g.path));I&&m("NATIVE_APPLICATION_AUTH_SURFACE_PATH_CONFLICT",`${n}/surfaces/${b}/path`,{owner:I.owner})}}function Wc(e,t){if(e===null)return;let o={data:{resources:[]},workflows:{definitions:[]},frontend:{routes:[{code:"auth-desktop-default",path:"/auth-desktop-default",surface:"user"},{code:"auth-mobile-default",path:"/m/auth-mobile-default",surface:"user"}],user:{applicationTodoCenter:!1},admin:{navigation:[]},authentication:e}},n=N(e,t),i=N(n.surfaces,`${t}/surfaces`),r={...n,surfaces:{...i,desktop:{...N(i.desktop,`${t}/surfaces/desktop`),defaultRouteCode:"auth-desktop-default"},mobile:{...N(i.mobile,`${t}/surfaces/mobile`),defaultRouteCode:"auth-mobile-default"}}};ys(r,o.frontend.routes,{...o,frontend:{...o.frontend,authentication:r}},t)}function Uc(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 Mc=new Set(["draft.read","draft.update","validate","create","own.list","own.read","public.list","public.read"]);function Bc(e,t,o){let n=N(e,o);C(n,["policies"],o);let i=S(n.policies,`${o}/policies`,16);i.length<1&&m("NATIVE_PUBLIC_POLICY_REQUIRED",o);let r=new Map(t.frontend.routes.map(c=>[c.code,c])),d=new Map(t.data.resources.map(c=>[c.code,c])),s=new Set,a=new Set(i.map(c=>String(c?.code||"")));i.forEach((c,f)=>{let u=`${o}/policies/${f}`,p=N(c,u);C(p,["code","routeCode","mode","resourceCode","operations","fields"],u,["requiredFields","ownRecordFields","publicRecordFields","publicFilters","serverGeneratedFields","schedule","publicSubtableFields","draft","validations"]);let _=P(p.code,`${u}/code`);s.has(_)&&m("NATIVE_PUBLIC_POLICY_DUPLICATE",`${u}/code`);let E=P(p.routeCode,`${u}/routeCode`),A=r.get(E);(!A||A.surface!=="user"||A.capability!==void 0||A.access!==void 0||/[:*]/.test(String(A.path)))&&m("NATIVE_PUBLIC_ROUTE_INVALID",`${u}/routeCode`),F(p.mode,"anonymous",`${u}/mode`);let O=H(p.resourceCode,`${u}/resourceCode`),b=d.get(O);b||m("NATIVE_PUBLIC_RESOURCE_MISSING",`${u}/resourceCode`);let g=new Map(b.schema.fields.map(v=>[String(v.code),String(v.type)])),I=L(p.operations,`${u}/operations`,8);(I.length<1||I.some(v=>!Mc.has(v)))&&m("NATIVE_PUBLIC_OPERATION_INVALID",`${u}/operations`),I.includes("draft.read")!==I.includes("draft.update")&&m("NATIVE_PUBLIC_DRAFT_OPERATION_INCOMPLETE",`${u}/operations`);let T=L(p.fields,`${u}/fields`,64);(T.length<1||T.some(v=>!g.has(v)))&&m("NATIVE_PUBLIC_FIELD_INVALID",`${u}/fields`);for(let v of["requiredFields","ownRecordFields","publicRecordFields"]){if(!Object.prototype.hasOwnProperty.call(p,v))continue;L(p[v],`${u}/${v}`,64).some(x=>!T.includes(x))&&m("NATIVE_PUBLIC_FIELD_SCOPE_INVALID",`${u}/${v}`)}let l=Object.prototype.hasOwnProperty.call(p,"serverGeneratedFields")?S(p.serverGeneratedFields,`${u}/serverGeneratedFields`,16):[],y=new Set;l.forEach((v,W)=>{let x=`${u}/serverGeneratedFields/${W}`,q=N(v,x);C(q,["field","kind"],x);let z=G(q.field,`${x}/field`);(y.has(z)||!g.has(z)||T.includes(z)||g.get(z)!=="text.short"&&g.get(z)!=="text.long")&&m("NATIVE_PUBLIC_SERVER_GENERATED_FIELD_INVALID",`${x}/field`),F(q.kind,"random-token",`${x}/kind`),y.add(z)});let R=Object.prototype.hasOwnProperty.call(p,"schedule")?N(p.schedule,`${u}/schedule`):null;if(R){let v=["campusPolicyCode","rulePolicyCode","campusField","ruleCampusField","ruleWeekdaysField","ruleOpenAtField","ruleCloseAtField","ruleSlotMinutesField","ruleAdvanceHoursField","ruleAdvanceDaysField","campusEnabledField","ruleEnabledField","dateField","timeField"];C(R,v,`${u}/schedule`);for(let W of["campusPolicyCode","rulePolicyCode"])P(R[W],`${u}/schedule/${W}`);for(let W of v.filter(x=>!["campusPolicyCode","rulePolicyCode"].includes(x)))G(R[W],`${u}/schedule/${W}`);for(let W of[R.campusField,R.dateField,R.timeField])T.includes(String(W))||m("NATIVE_PUBLIC_SCHEDULE_FIELD_INVALID",`${u}/schedule`);(!a.has(String(R.campusPolicyCode))||!a.has(String(R.rulePolicyCode)))&&m("NATIVE_PUBLIC_SCHEDULE_POLICY_INVALID",`${u}/schedule`)}let h=Object.prototype.hasOwnProperty.call(p,"publicFilters")?S(p.publicFilters,`${u}/publicFilters`,16):[],$=new Set;h.forEach((v,W)=>{let x=`${u}/publicFilters/${W}`,q=N(v,x);C(q,["field","operator","value"],x);let z=G(q.field,`${x}/field`);$.has(z)&&m("NATIVE_PUBLIC_FILTER_DUPLICATE",`${x}/field`),T.includes(z)||m("NATIVE_PUBLIC_FILTER_FIELD_INVALID",`${x}/field`),F(q.operator,"eq",`${x}/operator`),["boolean","text.short","text.long","number.integer","number.decimal","date","time"].includes(g.get(z)||"")||m("NATIVE_PUBLIC_FILTER_FIELD_INVALID",`${x}/field`),q.value!==null&&typeof q.value!="string"&&typeof q.value!="number"&&typeof q.value!="boolean"&&m("NATIVE_PUBLIC_FILTER_VALUE_INVALID",`${x}/value`),$.add(z)});let k=Object.prototype.hasOwnProperty.call(p,"publicSubtableFields")?N(p.publicSubtableFields,`${u}/publicSubtableFields`):null;if(k){Object.keys(k).length>64&&m("NATIVE_PUBLIC_SUBTABLE_FIELDS_INVALID",`${u}/publicSubtableFields`);for(let[v,W]of Object.entries(k)){let x=b.schema.fields.find(J=>String(J.code)===v),q=String(x?.subtable?.resourceCode||""),z=d.get(q),_e=new Map((z?.schema?.fields||[]).map(J=>[String(J.code),String(J.type)])),Te=L(W,`${u}/publicSubtableFields/${v}`,64);(!T.includes(v)||g.get(v)!=="subtable"||!z||Te.length<1||Te.some(J=>!_e.has(J))||Te.some(J=>_e.get(J)==="subtable")||Te.some(J=>_e.get(J)==="signature"))&&m("NATIVE_PUBLIC_SUBTABLE_FIELDS_INVALID",`${u}/publicSubtableFields/${v}`)}}if(I.some(v=>v.startsWith("public."))){Object.prototype.hasOwnProperty.call(p,"publicRecordFields")||m("NATIVE_PUBLIC_RECORD_FIELDS_REQUIRED",`${u}/publicRecordFields`);let v=L(p.publicRecordFields,`${u}/publicRecordFields`,64);(v.length<1||v.some(W=>!T.includes(W))||v.some(W=>g.get(W)==="signature"||g.get(W)==="subtable"&&!k?.[W]))&&m("NATIVE_PUBLIC_RECORD_FIELDS_INVALID",`${u}/publicRecordFields`)}let M=Object.prototype.hasOwnProperty.call(p,"requiredFields")?L(p.requiredFields,`${u}/requiredFields`,64):[],V=b.surface||{},Y=V.fields||{},ne=String(V.mutationOwner||"native")==="native"&&V.generated?.create!==!1,X=b.schema.fields.filter(v=>Tt(v,Y[v.code])).map(v=>String(v.code));if(I.includes("create")&&!ne&&m("NATIVE_PUBLIC_CREATE_FIELDS_INCOMPLETE",`${u}/fields`),I.includes("create")&&!Object.prototype.hasOwnProperty.call(p,"draft")&&m("NATIVE_PUBLIC_DRAFT_REQUIRED",`${u}/draft`),I.includes("create"))for(let v of X){let W=T.includes(v)?M.includes(v)?null:"requiredFields":"fields";W&&m("NATIVE_PUBLIC_CREATE_FIELDS_INCOMPLETE",`${u}/${W}`,{resourceCode:H,fieldCode:v})}if(Object.prototype.hasOwnProperty.call(p,"draft")){let v=N(p.draft,`${u}/draft`);C(v,["enabled","inactivityTtlSeconds","maxBytes"],`${u}/draft`),F(v.enabled,!0,`${u}/draft/enabled`),ie(v.inactivityTtlSeconds,`${u}/draft/inactivityTtlSeconds`,3600,7776e3),ie(v.maxBytes,`${u}/draft/maxBytes`,4096,262144)}else I.includes("draft.read")&&m("NATIVE_PUBLIC_DRAFT_REQUIRED",`${u}/draft`);let ce=Object.prototype.hasOwnProperty.call(p,"validations")?S(p.validations,`${u}/validations`,16):[],le=new Set;ce.forEach((v,W)=>{let x=`${u}/validations/${W}`,q=N(v,x);C(q,["code","kind","fields","result"],x);let z=P(q.code,`${x}/code`);le.has(z)&&m("NATIVE_PUBLIC_VALIDATION_DUPLICATE",`${x}/code`),F(q.kind,"duplicate",`${x}/kind`),F(q.result,"availability",`${x}/result`);let _e=L(q.fields,`${x}/fields`,8);(_e.length<1||_e.some(Te=>!T.includes(Te))||_e.some(Te=>["file","subtable"].includes(g.get(Te)||"")))&&m("NATIVE_PUBLIC_VALIDATION_FIELD_INVALID",`${x}/fields`),le.add(z)}),s.add(_)})}function Kc(e,t){let o=N(e,t);C(o,["policies"],t),S(o.policies,`${t}/policies`,16).length<1&&m("NATIVE_PUBLIC_POLICY_REQUIRED",t)}function Gc(e){return{policies:ee(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)=>Ee(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)=>Ee(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:ee(t.validations.map(o=>({code:o.code,kind:o.kind,fields:U(o.fields),result:o.result})),o=>o.code)}:{}})),t=>t.code)}}function bs(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=Os(o),i=`/admin/resources/${o.code}`,r=[["list",i],["detail",`${i}/:id`],["create",`${i}/new`],["update",`${i}/:id/edit`]];for(let[d,s]of r)n[d]&&t.push({owner:`resource:${o.code}:${d}`,path:s},{owner:`resource:${o.code}:${d}: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 Gn(e){let t=new Map(bs(e).map(o=>[Un(o.path),o]));return ee(e.frontend.routes.map((o,n)=>{let i=`/config/frontend/routes/${n}`,r=N(o,i);C(r,["code","path","label","surface","parentCode","capability","access","pinned","tabPersistence","keepAlive"],i,!0),["admin","user"].includes(r.surface)||m("NATIVE_ROUTE_SURFACE_INVALID",`${i}/surface`);let d=Ne(r.path,`${i}/path`);r.surface==="admin"&&d!=="/admin"&&!d.startsWith("/admin/")&&m("NATIVE_ADMIN_ROUTE_PATH_INVALID",`${i}/path`),r.surface==="user"&&(d==="/admin"||d.startsWith("/admin/"))&&m("NATIVE_USER_ROUTE_PATH_RESERVED",`${i}/path`);let s=Un(d),a=t.get(s);a&&m("NATIVE_ROUTE_PATH_CONFLICT",`${i}/path`,{path:d,owner:a.owner}),t.set(s,{owner:`frontend:${String(r.code||n)}`,path:d});let c=/[:*]/.test(d),f=Ti(r,i,e.appCode),u=r.pinned===void 0?void 0:Et(r.pinned,`${i}/pinned`),p=r.tabPersistence===void 0?c?"none":"session":w(r.tabPersistence,`${i}/tabPersistence`,16),_=r.keepAlive===void 0?"none":w(r.keepAlive,`${i}/keepAlive`,16);return["session","none"].includes(p)||m("NATIVE_ROUTE_TAB_PERSISTENCE_INVALID",`${i}/tabPersistence`),["none","memory"].includes(_)||m("NATIVE_ROUTE_KEEP_ALIVE_INVALID",`${i}/keepAlive`),c&&u===!0&&m("NATIVE_DYNAMIC_ROUTE_PINNED_FORBIDDEN",`${i}/pinned`),c&&p==="session"&&m("NATIVE_DYNAMIC_ROUTE_TAB_PERSISTENCE_FORBIDDEN",`${i}/tabPersistence`),c&&_==="memory"&&m("NATIVE_DYNAMIC_ROUTE_KEEP_ALIVE_FORBIDDEN",`${i}/keepAlive`),{code:P(r.code,`${i}/code`),path:d,label:w(r.label,`${i}/label`,255),surface:r.surface,...r.parentCode===void 0?{}:{parentCode:P(r.parentCode,`${i}/parentCode`)},...f,...u===void 0?{}:{pinned:u},tabPersistence:p,keepAlive:_}}),o=>o.code)}function Os(e){let t=e.surface===void 0?{}:N(e.surface,"/surface"),o=t.mutationOwner||"native",n=t.generated===void 0?{}:N(t.generated,"/surface/generated"),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 Ns(e){let t=[];for(let o of ee(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:mn(n.surface,i.code)}}))])){let{resource:n,viewCode:i}=o,r=`/admin/resources/${n.code}${i?`/views/${i}`:""}`,d=Os(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 a of s)d[a.operation]&&t.push({code:`resource:${n.code}${i?`:view:${i}`:""}:${a.operation}`,kind:a.kind,path:a.path,label:a.label,navigationEligible:a.navigationEligible,capability:a.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)=>Ee(o.code,n.code))}function Ts(e){return e.kind==="resource"?`resource:${e.resourceCode}${e.viewCode?`:view:${e.viewCode}`:""}:list`:`operation:${e.routeCode}`}function qc(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:Ts(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||Ee(n.pageCode,i.pageCode))})).sort((t,o)=>t.order-o.order||Ee(t.code,o.code))}function zc(e,t){let o=S(e,t,B.adminNavigationGroups);o.reduce((i,r)=>i+(Array.isArray(r?.items)?r.items.length:0),0)>B.adminNavigationItems&&m("NATIVE_ARRAY_LIMIT_EXCEEDED",t);let n=0;o.forEach((i,r)=>{let d=`${t}/${r}`,s=N(i,d);C(s,["code","label","icon","order","items"],d,!0),P(s.code,`${d}/code`),w(s.label,`${d}/label`,255),Mn(s.icon,`${d}/icon`),ss(s.order,`${d}/order`);let a=S(s.items,`${d}/items`,500);a.length===0&&m("NATIVE_ADMIN_GROUP_ORPHANED",`${d}/items`),n+=a.length,n>B.adminNavigationItems&&m("NATIVE_ARRAY_LIMIT_EXCEEDED",t),a.forEach((c,f)=>{let u=`${d}/items/${f}`,p=N(c,u);C(p,["page","label","icon","order"],u,!0),Jc(p.page,`${u}/page`),p.label!==void 0&&w(p.label,`${u}/label`,255),Mn(p.icon,`${u}/icon`),ss(p.order,`${u}/order`)})})}function Jc(e,t){let o=N(e,t),n=w(o.kind,`${t}/kind`,64);if(n==="resource"){C(o,["kind","resourceCode"],t,["viewCode"]),o.viewCode!==void 0&&P(o.viewCode,`${t}/viewCode`),H(o.resourceCode,`${t}/resourceCode`);return}if(n==="operation"){C(o,["kind","routeCode"],t),P(o.routeCode,`${t}/routeCode`);return}m("NATIVE_ADMIN_PAGE_REFERENCE_KIND_INVALID",`${t}/kind`)}function Hc(e){let t=new Map(Ns(e).map(i=>[String(i.code),i])),o=new Set,n=new Set;e.frontend.admin.navigation.forEach((i,r)=>{let d=`/config/frontend/admin/navigation/${r}`;o.has(i.code)&&m("NATIVE_ADMIN_GROUP_DUPLICATE",`${d}/code`),o.add(i.code),i.label===i.code&&m("NATIVE_ADMIN_USER_LABEL_REQUIRED",`${d}/label`),i.items.forEach((s,a)=>{let c=`${d}/items/${a}`,f=Ts(s.page),u=t.get(f);(!u||u.navigationEligible!==!0)&&m("NATIVE_ADMIN_PAGE_NOT_FOUND",`${c}/page`),n.has(f)&&m("NATIVE_ADMIN_PAGE_DUPLICATE",`${c}/page`),n.add(f);let p=s.page.resourceCode||s.page.routeCode||s.page.workflowCode||f,_=s.label||u.label;(!_||_===p||_===f)&&m("NATIVE_ADMIN_USER_LABEL_REQUIRED",`${c}/label`)})})}function Yc(e,t){let o=S(e,t,B.adminPages),n=new Set;o.forEach((i,r)=>{let d=`${t}/${r}`,s=N(i,d);C(s,["code","kind","path","label","navigationEligible","capability","access","resourceCode","viewCode","routeCode"],d,!0);let a=w(s.code,`${d}/code`,255);n.has(a)&&m("NATIVE_ADMIN_PAGE_DUPLICATE",`${d}/code`),n.add(a);let c=w(s.kind,`${d}/kind`,64);if(["resource-list","resource-detail","resource-create","resource-update","operation"].includes(c)||m("NATIVE_ADMIN_PAGE_KIND_INVALID",`${d}/kind`),Ne(s.path,`${d}/path`),w(s.label,`${d}/label`,255),Et(s.navigationEligible,`${d}/navigationEligible`),s.capability!==void 0&&s.access!==void 0&&m("NATIVE_ROUTE_ACCESS_CONFLICT",`${d}/access`),s.capability!==void 0&&w(s.capability,`${d}/capability`,255),s.access!==void 0){let f=N(s.access,`${d}/access`);C(f,["allOf","anyOf"],`${d}/access`,!0);for(let u of["allOf","anyOf"])f[u]!==void 0&&L(f[u],`${d}/access/${u}`,50)}for(let f of["resourceCode","viewCode","routeCode"])s[f]!==void 0&&P(s[f],`${d}/${f}`)})}function Xc(e,t){let o=S(e,t,B.adminNavigationGroups);o.reduce((i,r)=>i+(Array.isArray(r?.items)?r.items.length:0),0)>B.adminNavigationItems&&m("NATIVE_ARRAY_LIMIT_EXCEEDED",t);let n=0;o.forEach((i,r)=>{let d=`${t}/${r}`,s=N(i,d);C(s,["code","label","icon","order","items"],d,!0),P(s.code,`${d}/code`),w(s.label,`${d}/label`,255),Mn(s.icon,`${d}/icon`),ie(s.order,`${d}/order`,-1e4,1e4);let a=S(s.items,`${d}/items`,500);a.length===0&&m("NATIVE_ADMIN_GROUP_ORPHANED",`${d}/items`),n+=a.length,n>B.adminNavigationItems&&m("NATIVE_ARRAY_LIMIT_EXCEEDED",t),a.forEach((c,f)=>{let u=`${d}/items/${f}`,p=N(c,u);C(p,["pageCode","label","icon","order"],u,!0),w(p.pageCode,`${u}/pageCode`,255),p.label!==void 0&&w(p.label,`${u}/label`,255),Mn(p.icon,`${u}/icon`),ie(p.order,`${u}/order`,-1e4,1e4)})})}var Zc=new Set(["application-todo-center","workflow-work-center","workflow-launch","workflow-task","workflow-instance","resource-records","resource-submit"]);function Qc(e,t,o){let n=N(e,t);C(n,["schemaVersion","appCode","devicePolicy","rootEntry","authentication","routes","digest"],t),F(n.schemaVersion,_s,`${t}/schemaVersion`),F(n.appCode,o,`${t}/appCode`),Ni(n.devicePolicy,`${t}/devicePolicy`),el(n.rootEntry,`${t}/rootEntry`),tl(n.authentication,`${t}/authentication`),bi(n.digest,`${t}/digest`);let i=S(n.routes,`${t}/routes`,B.routes),r=new Set;i.forEach((d,s)=>{let a=`${t}/routes/${s}`,c=N(d,a),f=c.kind==="resource-records"||c.kind==="resource-submit";C(c,["code","kind","desktop","mobile"],a,["workflowCode",...f?["resourceCode"]:[]]);let u=w(c.code,`${a}/code`,255);r.has(u)&&m("NATIVE_ROUTE_MANIFEST_DUPLICATE",`${a}/code`),r.add(u);let p=w(c.kind,`${a}/kind`,64);if(Zc.has(p)||m("NATIVE_ROUTE_MANIFEST_KIND_INVALID",`${a}/kind`),c.workflowCode!==void 0&&P(c.workflowCode,`${a}/workflowCode`),f){let A=H(c.resourceCode,`${a}/resourceCode`);F(u,`user.${A}.${c.kind==="resource-records"?"records":"submit"}`,`${a}/code`)}else c.resourceCode!==void 0&&m("NATIVE_PROPERTY_UNKNOWN",`${a}/resourceCode`);let _=os(c.desktop,`${a}/desktop`,o),E=os(c.mobile,`${a}/mobile`,o);_.surface!=="user"&&m("NATIVE_ROUTE_MANIFEST_DESKTOP_SURFACE_INVALID",`${a}/desktop/surface`),E.surface!=="user"&&m("NATIVE_ROUTE_MANIFEST_MOBILE_SURFACE_INVALID",`${a}/mobile/surface`),_.routeCode===E.routeCode&&m("NATIVE_ROUTE_MANIFEST_PAIR_DUPLICATE",a)}),F(n.digest,Z({schemaVersion:n.schemaVersion,appCode:n.appCode,devicePolicy:n.devicePolicy,rootEntry:n.rootEntry,authentication:n.authentication,routes:n.routes}),`${t}/digest`)}function Ni(e,t){let o=N(e,t);C(o,["kind","mobileMaxWidthPx","desktopMinWidthPx"],t),F(o.kind,"viewport-family",`${t}/kind`);let n=ie(o.mobileMaxWidthPx,`${t}/mobileMaxWidthPx`,320,1600),i=ie(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 el(e,t){let o=N(e,t);C(o,["code","desktop","mobile"],t);let n=P(o.code,`${t}/code`),i=yi(o.desktop,`${t}/desktop`),r=yi(o.mobile,`${t}/mobile`);return(i===r||r==="/"||!r.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:r}}function tl(e,t){let o=N(e,t);C(o,["desktop","mobile"],t);let n=ns(o.desktop,`${t}/desktop`,!1),i=ns(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 ns(e,t,o){let n=N(e,t);C(n,["routeCode","path"],t);let i=P(n.routeCode,`${t}/routeCode`),r=yi(n.path,`${t}/path`);return(o?!r.startsWith("/m/"):r.startsWith("/m/"))&&m("NATIVE_ROUTE_MANIFEST_AUTHENTICATION_PATH_INVALID",`${t}/path`),{routeCode:i,path:r}}function yi(e,t){let o=Ne(e,t);return/[:*?#\\\\]/.test(o)&&m("NATIVE_ROUTE_MANIFEST_STATIC_PATH_INVALID",t),o}function os(e,t,o){let n=N(e,t);C(n,["routeCode","path","surface","pathParams","requiresAuthentication"],t,["capability","access"]),P(n.routeCode,`${t}/routeCode`);let i=Ne(n.path,`${t}/path`),r=w(n.surface,`${t}/surface`,16);["admin","user"].includes(r)||m("NATIVE_ROUTE_SURFACE_INVALID",`${t}/surface`);let d=L(n.pathParams,`${t}/pathParams`,8);return d.forEach((s,a)=>{(!/^[A-Za-z][A-Za-z0-9_]*$/.test(s)||s.length>64)&&m("NATIVE_ROUTE_PATH_PARAM_INVALID",`${t}/pathParams/${a}`)}),Q(d)!==Q(Rs(i))&&m("NATIVE_ROUTE_PATH_PARAMS_MISMATCH",`${t}/pathParams`),Ti(n,t,o),n.requiresAuthentication!==!0&&m("NATIVE_ROUTE_AUTHENTICATION_REQUIRED",`${t}/requiresAuthentication`),n}function Rs(e){return U([...e.matchAll(/:([A-Za-z][A-Za-z0-9_]*)/g)].map(t=>t[1]))}function is(e,t,o,n){return{routeCode:e,path:t,surface:o,pathParams:Rs(t),...n?.capability?{capability:n.capability}:{},...n?.access?{access:n.access}:{},requiresAuthentication:!0}}function rs(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 nl(e){let t=e.appCode,o=[],n=(_,E,A,O,b,g,I)=>{o.push({code:_,kind:E,...b?{workflowCode:b}:{},...I?{resourceCode:I}:{},desktop:is(rs(E,"desktop",b,I),A,"user",g),mobile:is(rs(E,"mobile",b,I),O,"user",g)})};e.frontend.user.applicationTodoCenter===!0&&n("application:todo-center","application-todo-center","/todos","/m/todos");let i=Cs(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 _ of i){if(!["standalone","hidden-handoff"].includes(_.launch.mode))continue;let E=U([_.launch.submission?.create?.requiredCapability,_.launch.submission?.existing?.requiredCapability].filter(A=>!!A));n(`workflow:${_.code}:launch`,"workflow-launch","/workflows/:workflowCode/start","/m/workflows/:workflowCode/start",_.code,E.length===1?{capability:E[0]}:E.length>1?{access:{anyOf:E}}:void 0)}let r=o.sort((_,E)=>Ee(String(_.code),String(E.code))),d=Gn(e),s=_=>{let E=_==="mobile"?"/m/":"/",A=d.filter(b=>b.surface==="user"&&!/[:*?#\\\\]/.test(b.path)&&b.path===E).sort((b,g)=>Ee(b.code,g.code))[0];if(A)return{code:A.code,path:A.path};let O=d.filter(b=>b.surface==="user"&&!/[:*?#\\\\]/.test(b.path)&&(_==="mobile"?b.path.startsWith("/m/"):!b.path.startsWith("/m/"))).sort((b,g)=>Ee(b.code,g.code))[0];return O?{code:O.code,path:O.path}:{code:_==="mobile"?"application-root-mobile":"application-root",path:E}},a=e.frontend.authentication?{desktop:{routeCode:e.frontend.authentication.surfaces.desktop.routeCode,path:e.frontend.authentication.surfaces.desktop.path},mobile:{routeCode:e.frontend.authentication.surfaces.mobile.routeCode,path:e.frontend.authentication.surfaces.mobile.path}}:{desktop:{routeCode:"application-login",path:"/login"},mobile:{routeCode:"application-login-mobile",path:"/m/login"}},c=Ni(e.frontend.devicePolicy,"/config/frontend/devicePolicy"),f=s("desktop"),u=s("mobile"),p={schemaVersion:_s,appCode:t,devicePolicy:c,rootEntry:{code:f.code,desktop:f.path,mobile:u.path},authentication:a,routes:r};return{...p,digest:Z(p)}}function Mn(e,t){if(e===void 0)return;let o=w(e,t,32);Ac.has(o)||m("NATIVE_ADMIN_ICON_INVALID",t)}function ss(e,t){e!==void 0&&ie(e,t,-1e4,1e4)}function Ti(e,t,o){return e.capability!==void 0&&e.access!==void 0&&m("NATIVE_ROUTE_ACCESS_CONFLICT",`${t}/access`),e.capability!==void 0?{capability:pe(e.capability,`${t}/capability`,o)}:e.access===void 0?{}:{access:qn(e.access,`${t}/access`,o)}}function qn(e,t,o){let n=N(e,t);C(n,["allOf","anyOf"],t,!0);let i=n.allOf===void 0?void 0:U(L(n.allOf,`${t}/allOf`,50).map((d,s)=>pe(d,`${t}/allOf/${s}`,o))),r=n.anyOf===void 0?void 0:U(L(n.anyOf,`${t}/anyOf`,50).map((d,s)=>pe(d,`${t}/anyOf/${s}`,o)));return(i?.length||0)+(r?.length||0)===0&&m("NATIVE_ROUTE_ACCESS_EMPTY",t),{...i===void 0?{}:{allOf:i},...r===void 0?{}:{anyOf:r}}}function Cs(e){let t=new Map(Is(e).map(i=>[String(i.code),i])),o=e.workflows.definitions.map((i,r)=>{let d=`/config/workflows/definitions/${r}`,s=N(i,d);C(s,["version","definition","launch"],d,["detailRouteCode"]);let a=N(s.definition,`${d}/definition`),c=s.detailRouteCode===void 0?void 0:ws(s.detailRouteCode,`${d}/detailRouteCode`);return{code:P(a.code,`${d}/definition/code`),title:w(a.title,`${d}/definition/title`,255),version:At(s.version,`${d}/version`),launch:ol(e,a,s.launch,`${d}/launch`,t),...c?{detailRouteCode:c}:{},definition:a}});return U(o.map(i=>i.code)).map(i=>{let r=o.filter(c=>c.code===i),d=e.workflows.activations.find(c=>c.workflowCode===i)?.definitionVersion,s=r.find(c=>c.version===d)||[...r].sort((c,f)=>f.version-c.version)[0],a=new Set;for(let c of r){let f=N(c.definition.nodes,"/config/workflows/definitions/nodes");for(let u of Object.values(f)){let p=N(u,"/config/workflows/definitions/nodes/*");if(p.kind==="approval")for(let _ of L(p.allowedOperations||[],"/config/workflows/definitions/nodes/*/allowedOperations",20))a.add(_)}}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:ps(r.map(c=>c.version)),bindingVersions:ps(e.workflows.bindings.map((c,f)=>{let u=`/config/workflows/bindings/${f}`,p=N(c,u),_=N(p.binding,`${u}/binding`);return{code:P(_.workflowCode,`${u}/binding/workflowCode`),version:At(p.version,`${u}/version`)}}).filter(c=>c.code===i).map(c=>c.version)),providerCodes:U(e.workflows.providers.map((c,f)=>P(N(c,`/config/workflows/providers/${f}`).code,`/config/workflows/providers/${f}/code`))),allowedOperations:[...a].sort(Ee),editableParameterCodes:U(e.workflows.editableParameters.map((c,f)=>{let u=`/config/workflows/editableParameters/${f}`,p=N(c,u);return{code:P(p.code,`${u}/code`),workflowCode:P(p.workflowCode,`${u}/workflowCode`)}}).filter(c=>c.workflowCode===i).map(c=>c.code))}})}function hs(e,t){let o=N(e,t);C(o,["mode"],t,["submission"]);let n=w(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:N(o.submission,`${t}/submission`)}}}function ol(e,t,o,n,i){let r=hs(o,n);if(!r.submission)return{mode:r.mode};["standalone","hidden-handoff"].includes(r.mode)||m("NATIVE_WORKFLOW_NAMED_OPERATION_SUBMISSION_INVALID",`${n}/submission`);let d=N(r.submission,`${n}/submission`);C(d,["kind"],`${n}/submission`,["create","existing","context"]),F(d.kind,"named-operation",`${n}/submission/kind`);let s=n.endsWith("/launch")?n.slice(0,-7):n,a=N(t.subject,`${s}/definition/subject`),c=H(a.resourceCode,`${s}/definition/subject/resourceCode`),f=e.data.resources.findIndex(y=>y.code===c),u=e.data.resources[f];(f<0||!u)&&m("NATIVE_WORKFLOW_SUBJECT_RESOURCE_MISSING",`${s}/definition/subject/resourceCode`);let p=new Set(N(u.schema,`/config/data/resources/${f}/schema`).fields.map(y=>String(y.code))),_=new Map(e.backend.operations.map(y=>[String(y.code),y])),E=(y,R)=>{let h=`${n}/submission/${R}`,$=N(y,h);C($,["operationCode","inputs","output"],h);let k=P($.operationCode,`${h}/operationCode`),M=_.get(k),V=i.get(k),Y=V?.platformAccess?.workflow?.codes;(!M||!V||V.method!=="POST"||!Array.isArray(Y)||!Y.includes(t.code))&&m("NATIVE_WORKFLOW_NAMED_OPERATION_INVALID",h);let ne=N(M.requestSchema,`${h}/operation/requestSchema`),X=N(ne.properties,`${h}/operation/requestSchema/properties`),ce=new Set(ne.required===void 0?[]:L(ne.required,`${h}/operation/requestSchema/required`,64)),le=N($.inputs,`${h}/inputs`),v=Object.entries(le);(!v.length||v.length>64)&&m("NATIVE_WORKFLOW_NAMED_OPERATION_INPUT_INVALID",`${h}/inputs`);let W=new Set,x=new Map,q={},z=V.platformAccess?.ownedSubject;z&&(R!=="create"||z.resourceCode!==c)&&m("NATIVE_WORKFLOW_OWNED_SUBJECT_LAUNCH_MISMATCH",h);for(let[J,Ze]of v){(!Zr.test(J)||!Object.prototype.hasOwnProperty.call(X,J))&&m("NATIVE_WORKFLOW_NAMED_OPERATION_INPUT_INVALID",`${h}/inputs/${J}`);let We=`${h}/inputs/${J}`,Zn=N(Ze,We),Ue=w(Zn.source,`${We}/source`,32);if(["field","idempotency-key","current-user-reference","subject-id","subject-revision","requested-at"].includes(Ue)||m("NATIVE_WORKFLOW_NAMED_OPERATION_INPUT_INVALID",We),C(Zn,["source"],We,Ue==="field"?["fieldCode"]:!1),x.set(Ue,(x.get(Ue)||0)+1),Ue==="field"){let Qe=G(Zn.fieldCode,`${We}/fieldCode`);(W.has(Qe)||!p.has(Qe))&&m("NATIVE_WORKFLOW_NAMED_OPERATION_INPUT_INVALID",`${We}/fieldCode`),W.add(Qe),u.schema.fields.find(Qn=>Qn.code===Qe)?.type==="subtable"&&(!z||!z.subtables.some(Qn=>Qn.fieldCode===Qe))&&m("NATIVE_WORKFLOW_OWNED_SUBJECT_LAUNCH_REQUIRED",We),q[J]={source:Ue,fieldCode:Qe}}else q[J]={source:Ue}}([...ce].some(J=>!(J in le))||(x.get("idempotency-key")||0)!==1||!v.some(([J,Ze])=>N(Ze,`${h}/inputs/${J}`).source==="idempotency-key"&&ce.has(J))||R==="create"&&((x.get("subject-id")||0)>0||(x.get("subject-revision")||0)>0)||R==="existing"&&((x.get("subject-id")||0)!==1||(x.get("subject-revision")||0)!==1))&&m("NATIVE_WORKFLOW_NAMED_OPERATION_INPUT_INVALID",`${h}/inputs`);let _e=N($.output,`${h}/output`);C(_e,["subjectId"],`${h}/output`,["subjectRevision","processCommand"]);let Te=N(N(M.responseSchema,`${h}/operation/responseSchema`).properties,`${h}/operation/responseSchema/properties`);for(let J of["subjectId","subjectRevision","processCommand"]){if(_e[J]===void 0)continue;let Ze=w(_e[J],`${h}/output/${J}`,128);(!Zr.test(Ze)||!Object.prototype.hasOwnProperty.call(Te,Ze))&&m("NATIVE_WORKFLOW_NAMED_OPERATION_OUTPUT_INVALID",`${h}/output/${J}`)}return{operationCode:k,method:"POST",path:V.path,requiredCapability:V.requiredCapability,requestSchemaDigest:V.requestSchemaDigest,responseSchemaDigest:V.responseSchemaDigest,inputs:q,output:{..._e},fieldCodes:W}},A=d.create===void 0?void 0:E(d.create,"create"),O=d.existing===void 0?void 0:E(d.existing,"existing");!A&&!O&&m("NATIVE_WORKFLOW_NAMED_OPERATION_SUBMISSION_INVALID",`${n}/submission`);let b=new Set([...A?.fieldCodes||[],...O?.fieldCodes||[]]),g=d.context===void 0?[]:S(d.context,`${n}/submission/context`,16),I=new Set,T=g.map((y,R)=>{let h=`${n}/submission/context/${R}`,$=N(y,h);C($,["queryParameter","fieldCode"],h);let k=w($.queryParameter,`${h}/queryParameter`,64),M=G($.fieldCode,`${h}/fieldCode`);return(!/^[A-Za-z][A-Za-z0-9]{0,63}$/.test(k)||I.has(k)||!b.has(M))&&m("NATIVE_WORKFLOW_LAUNCH_CONTEXT_INVALID",h),I.add(k),{queryParameter:k,fieldCode:M}}),l=y=>{let{fieldCodes:R,...h}=y;return h};return{mode:r.mode,submission:{kind:"named-operation",...A?{create:l(A)}:{},...O?{existing:l(O)}:{},context:T}}}function ws(e,t){let o=N(e,t);C(o,["desktop","mobile"],t);let n=P(o.desktop,`${t}/desktop`),i=P(o.mobile,`${t}/mobile`);return n===i&&m("NATIVE_WORKFLOW_DETAIL_ROUTE_DUPLICATE",t),{desktop:n,mobile:i}}function il(e,t){let o=new Set(t.map(f=>f.code)),n=new Map;e.data.resources.forEach((f,u)=>{let p=`/config/data/resources/${u}`,_=N(f,p);if(_.recordDeletion!==void 0){let O=`${p}/recordDeletion/delete`;for(let b of _.recordDeletion.delete)pe(b,O,e.appCode),o.has(b)||m("NATIVE_CAPABILITY_REFERENCE_MISSING",O)}if(_.recordComments!==void 0)for(let O of["read","create"]){let b=`${p}/recordComments/${O}`;for(let g of _.recordComments[O])pe(g,b,e.appCode),o.has(g)||m("NATIVE_CAPABILITY_REFERENCE_MISSING",b)}if(_.recordPrint!==void 0){let O=`${p}/recordPrint/read`;for(let b of _.recordPrint.read)pe(b,O,e.appCode),o.has(b)||m("NATIVE_CAPABILITY_REFERENCE_MISSING",O)}if(_.workflowHistory!==void 0){let O=`${p}/workflowHistory/read`;for(let b of _.workflowHistory.read)pe(b,O,e.appCode),o.has(b)||m("NATIVE_CAPABILITY_REFERENCE_MISSING",O)}for(let[O,b]of Object.entries(_.fieldPolicies||{})){if(!nt(O))continue;let g=`${p}/fieldPolicies/${O}/read`,I=N(b,`${p}/fieldPolicies/${O}`);for(let T of L(I.read||[],g,2e3))o.has(T)||m("NATIVE_CAPABILITY_REFERENCE_MISSING",g)}let E=_.surface===void 0?{}:N(_.surface,`${p}/surface`);if(["native","queued-command"].includes(E.mutationOwner||"native"))return;let A=N(_.capabilities,`${p}/capabilities`);for(let O of["create","update","delete"])O==="delete"&&Array.isArray(_.recordDeletion?.delete)&&_.recordDeletion.delete.length>0||n.set(String(A[O]),O)});let i=new Set;for(let[f,u]of e.authz.roles.entries()){let p=`/config/authz/roles/${f}`,_=N(u,p);C(_,["code","name","description","capabilities"],p,!0);let E=P(_.code,`${p}/code`);i.has(E)&&m("NATIVE_ROLE_DUPLICATE",`${p}/code`),i.add(E),w(_.name,`${p}/name`,255);let A=L(_.capabilities,`${p}/capabilities`,2e3);for(let[O,b]of A.entries())n.has(b)&&m("NATIVE_DATA_SURFACE_MUTATION_GRANT_FORBIDDEN",`${p}/capabilities/${O}`,{operation:n.get(b)}),o.has(b)||m("NATIVE_CAPABILITY_REFERENCE_MISSING",`${p}/capabilities`)}let r=e.authz.authenticatedUserRoleCode===void 0?"":P(e.authz.authenticatedUserRoleCode,"/config/authz/authenticatedUserRoleCode");r&&!i.has(r)&&m("NATIVE_AUTHENTICATED_USER_ROLE_REFERENCE_MISSING","/config/authz/authenticatedUserRoleCode");let d=new Set,s=0;for(let[f,u]of e.perspectives.entries()){let p=`/config/perspectives/${f}`,_=N(u,p);C(_,["code","name","description","roleCodes","capabilityCodes","default"],p,!0);let E=P(_.code,`${p}/code`);d.has(E)&&m("NATIVE_PERSPECTIVE_DUPLICATE",`${p}/code`),d.add(E),w(_.name,`${p}/name`,255);let A=L(_.roleCodes,`${p}/roleCodes`,20);A.length<1&&m("NATIVE_PERSPECTIVE_ROLE_REQUIRED",`${p}/roleCodes`),A.forEach((g,I)=>{i.has(g)||m("NATIVE_PERSPECTIVE_ROLE_MISSING",`${p}/roleCodes/${I}`)});let O=U(e.authz.roles.filter(g=>A.includes(g.code)).flatMap(g=>g.capabilities)),b=L(_.capabilityCodes,`${p}/capabilityCodes`,2e3);Q(O)!==Q(b)&&m("NATIVE_PERSPECTIVE_CAPABILITY_PROJECTION_MISMATCH",`${p}/capabilityCodes`),_.default===!0?s+=1:_.default!==void 0&&m("NATIVE_PERSPECTIVE_DEFAULT_INVALID",`${p}/default`)}s>1&&m("NATIVE_PERSPECTIVE_DEFAULT_DUPLICATE","/config/perspectives");for(let[f,u]of e.backend.operations.entries()){let p=N(u,`/config/backend/operations/${f}`);o.has(p.capability)||m("NATIVE_CAPABILITY_REFERENCE_MISSING",`/config/backend/operations/${f}/capability`)}let a=new Set,c=new Set;for(let[f,u]of e.frontend.routes.entries()){let p=`/config/frontend/routes/${f}`,_=N(u,p),E=P(_.code,`${p}/code`);a.has(E)&&m("NATIVE_ROUTE_DUPLICATE",`${p}/code`),a.add(E);let A=Ne(_.path,`${p}/path`);c.has(A)&&m("NATIVE_ROUTE_PATH_DUPLICATE",`${p}/path`),c.add(A);let O=Ti(_,p,e.appCode);O.capability&&!o.has(O.capability)&&m("NATIVE_CAPABILITY_REFERENCE_MISSING",`${p}/capability`);let b=_.access===void 0?void 0:N(_.access,`${p}/access`);for(let g of["allOf","anyOf"]){let I=b?.[g]===void 0?[]:S(b[g],`${p}/access/${g}`,50);for(let[T,l]of I.entries()){let y=pe(l,`${p}/access/${g}/${T}`,e.appCode);o.has(y)||m("NATIVE_CAPABILITY_REFERENCE_MISSING",`${p}/access/${g}/${T}`)}}}if(e.frontend.admin.access!==void 0){let f=qn(e.frontend.admin.access,"/config/frontend/admin/access",e.appCode);for(let u of["allOf","anyOf"])for(let[p,_]of(f[u]||[]).entries())o.has(_)||m("NATIVE_CAPABILITY_REFERENCE_MISSING",`/config/frontend/admin/access/${u}/${p}`)}for(let[f,u]of e.frontend.routes.entries()){let p=N(u,`/config/frontend/routes/${f}`);p.parentCode&&!a.has(p.parentCode)&&m("NATIVE_ROUTE_PARENT_MISSING",`/config/frontend/routes/${f}/parentCode`)}}function rl(e){let t=new Set(e.authz.roles.map(c=>String(c.code))),o=e.authz.authenticatedUserRoleCode===void 0?"":P(e.authz.authenticatedUserRoleCode,"/config/authz/authenticatedUserRoleCode"),n=new Map(e.authz.scopeDimensions.map(c=>[String(c.code),{valueType:c.valueType==="uuid"?"uuid":"string",...c.valueSource?.resourceCode?{valueSourceResourceCode:String(c.valueSource.resourceCode)}:{}}])),i=new Set(n.keys()),r=new Map(e.data.resources.map((c,f)=>{let u=Ye(c,`/config/data/resources/${f}`,e.appCode);return[u.code,new Map(u.schema.fields.map(p=>[String(p.code),p]))]}));for(let[c,f]of e.authz.scopeDimensions.entries()){let u=`/config/authz/scopeDimensions/${c}`,p=N(f,u);if(C(p,["code","name","resourceCode","valueType","hierarchyMode","valueSource"],u,!0),p.valueSource===void 0)continue;let _=N(p.valueSource,`${u}/valueSource`);C(_,["kind","resourceCode","labelField","enabledField"],`${u}/valueSource`,!0),_.kind!=="native_resource"&&m("NATIVE_SCOPE_VALUE_SOURCE_KIND_INVALID",`${u}/valueSource/kind`),p.valueType!=="uuid"&&m("NATIVE_SCOPE_VALUE_SOURCE_TYPE_INVALID",`${u}/valueType`);let E=H(_.resourceCode,`${u}/valueSource/resourceCode`),A=r.get(E);A||m("NATIVE_SCOPE_VALUE_SOURCE_RESOURCE_MISSING",`${u}/valueSource/resourceCode`);let O=G(_.labelField,`${u}/valueSource/labelField`);if(["text.short","text.long"].includes(String(A.get(O)?.type||""))||m("NATIVE_SCOPE_VALUE_SOURCE_LABEL_FIELD_INVALID",`${u}/valueSource/labelField`),_.enabledField!==void 0){let b=G(_.enabledField,`${u}/valueSource/enabledField`);A.get(b)?.type!=="boolean"&&m("NATIVE_SCOPE_VALUE_SOURCE_ENABLED_FIELD_INVALID",`${u}/valueSource/enabledField`)}}let d=new Set,s=new Set;for(let[c,f]of e.authz.scopeSources.entries()){let u=`/config/authz/scopeSources/${c}`,p=N(f,u);C(p,["code","name","resourceCode","subject","grants","operationField","enabledField","effectiveFromField","effectiveToField","failureMode"],u,!0);let _=P(p.code,`${u}/code`);d.has(_)&&m("NATIVE_SCOPE_SOURCE_DUPLICATE",`${u}/code`),d.add(_),w(p.name,`${u}/name`,255);let E=H(p.resourceCode,`${u}/resourceCode`),A=r.get(E);A||m("NATIVE_SCOPE_SOURCE_RESOURCE_MISSING",`${u}/resourceCode`);let O=N(p.subject,`${u}/subject`),b=w(O.type,`${u}/subject/type`,32);C(O,b==="role_membership"?["type","userIdField","roleCode"]:["type","userIdField"],`${u}/subject`),["user","role_membership"].includes(b)||m("NATIVE_SCOPE_SOURCE_SUBJECT_INVALID",`${u}/subject/type`);let g=at(O.userIdField,A);bn(g)||m("NATIVE_SCOPE_SOURCE_SUBJECT_PATH_INVALID",`${u}/subject/userIdField`),b==="role_membership"&&!t.has(String(O.roleCode))&&m("NATIVE_ROLE_REFERENCE_MISSING",`${u}/subject/roleCode`);let I=new Set;for(let[T,l]of S(p.grants,`${u}/grants`,100).entries()){let y=`${u}/grants/${T}`,R=N(l,y);C(R,["dimensionCode","valueField","parentValueField"],y,!0);let h=P(R.dimensionCode,`${y}/dimensionCode`);(!i.has(h)||I.has(h))&&m("NATIVE_SCOPE_SOURCE_DIMENSION_INVALID",`${y}/dimensionCode`),I.add(h),p.failureMode==="last_known_good"&&s.add(h);for(let $ of["valueField","parentValueField"]){if(R[$]===void 0)continue;let k=at(R[$],A);wo(k,n.get(h),r)||m("NATIVE_SCOPE_SOURCE_GRANT_PATH_INVALID",`${y}/${$}`)}}I.size===0&&m("NATIVE_SCOPE_SOURCE_GRANT_REQUIRED",`${u}/grants`),["strict","last_known_good"].includes(p.failureMode)||m("NATIVE_SCOPE_SOURCE_FAILURE_MODE_INVALID",`${u}/failureMode`);for(let T of["operationField","enabledField","effectiveFromField","effectiveToField"]){if(p[T]===void 0)continue;let l=G(p[T],`${u}/${T}`);A.has(l)||m("NATIVE_SCOPE_SOURCE_FIELD_MISSING",`${u}/${T}`)}}al(e,t,r,o);let a=new Set;for(let[c,f]of e.authz.dataPolicies.entries()){let u=`/config/authz/dataPolicies/${c}`,p=N(f,u);C(p,["code","name","resourceCode","unrestrictedRoleCodes","publicRead","operations","matchMode","rules","readExpression","writeBoundary"],u,!0);let _=P(p.code,`${u}/code`);a.has(_)&&m("NATIVE_DATA_POLICY_DUPLICATE",`${u}/code`),a.add(_);let E=p.readExpression!==void 0,A=L(p.operations||[],`${u}/operations`,4);p.operations!==void 0&&(A.length===0||A.some(l=>!["read","create","update","delete"].includes(l)))&&m("NATIVE_DATA_POLICY_OPERATIONS_INVALID",`${u}/operations`),["AND","OR"].includes(p.matchMode)||m("NATIVE_DATA_POLICY_MATCH_MODE_INVALID",`${u}/matchMode`),E&&p.operations!==void 0&&m("NATIVE_DATA_POLICY_READ_EXPRESSION_OPERATIONS_FORBIDDEN",`${u}/operations`);let O=e.data.resources.find(l=>l.dataPolicyCode===_),b=p.resourceCode||O?.code,g=b?r.get(H(b,`${u}/resourceCode`)):void 0;if(E&&!g&&m("NATIVE_DATA_POLICY_RESOURCE_MISSING",`${u}/resourceCode`),p.publicRead!==void 0){try{let l=e.authz.roles.find(y=>y.code===o);ko({policy:p,resource:e.data.resources.find(y=>y.code===b),baselineRoleCode:o,baselineCapabilities:l?.capabilities||[],baselineDeniedCapabilities:l?.deniedCapabilities||[],pointer:u})}catch(l){if(!(l instanceof dt))throw l;m(l.code,l.pointer)}(p.unrestrictedRoleCodes||[]).includes(o)||m("AUTHENTICATED_PUBLIC_READ_CANONICAL_BASELINE_MISSING",`${u}/unrestrictedRoleCodes`)}else o&&(p.unrestrictedRoleCodes||[]).includes(o)&&m("NATIVE_DATA_POLICY_BASELINE_UNRESTRICTED",`${u}/unrestrictedRoleCodes`);let I=L(p.unrestrictedRoleCodes||[],`${u}/unrestrictedRoleCodes`,100);p.unrestrictedRoleCodes!==void 0&&I.length===0&&m("NATIVE_DATA_POLICY_UNRESTRICTED_ROLES_INVALID",`${u}/unrestrictedRoleCodes`);for(let l of I)t.has(l)||m("NATIVE_ROLE_REFERENCE_MISSING",`${u}/unrestrictedRoleCodes`);let T;try{let l=S(p.rules,`${u}/rules`,100).map((y,R)=>({rule:N(y,`${u}/rules/${R}`),pointer:`${u}/rules/${R}`}));l.length===0?(!E||p.matchMode!=="AND"||p.writeBoundary!=="capability_only")&&m("NATIVE_DATA_POLICY_WRITE_BOUNDARY_REQUIRED",u):p.writeBoundary!==void 0&&m("NATIVE_DATA_POLICY_WRITE_BOUNDARY_INVALID",`${u}/writeBoundary`),T=[...l],E&&(T.push(...Gt(p.readExpression,`${u}/readExpression`)),_i(p.readExpression,`${u}/readExpression`))}catch(l){throw l instanceof _t&&m(l.code,l.pointer),l}for(let{rule:l,pointer:y}of T){C(l,["subject","dimensionCode","relationCode","resourceCode","field","roleCodes","operation","valuePath","emptyMatchesAll","operator","value","operand"],y,!0);let R=G(l.field,`${y}/field`),h=g?.get(R);E&&!h&&m("NATIVE_DATA_POLICY_FIELD_MISSING",`${y}/field`);for(let X of L(l.roleCodes||[],`${y}/roleCodes`,100))t.has(X)||m("NATIVE_ROLE_REFERENCE_MISSING",`${y}/roleCodes`);let $=String(l.operator||""),k=l.operand==="db_now",M=["is_null","is_not_null"].includes($),V=["eq","not_eq","in","not_in"].includes($),Y=!k&&(l.operator!==void 0||l.value!==void 0);if([l.subject==="current_user"?"current_user":"",typeof l.dimensionCode=="string"?"dimension":"",typeof l.relationCode=="string"?"relationship":"",Y?"constant":"",k?"db_now":""].filter(Boolean).length!==1&&m("NATIVE_DATA_POLICY_RULE_SOURCE_INVALID",y),l.subject!==void 0&&l.subject!=="current_user"&&m("NATIVE_DATA_POLICY_SUBJECT_INVALID",`${y}/subject`),Y){if(!V&&!M&&m("NATIVE_DATA_POLICY_OPERATOR_INVALID",`${y}/operator`),["in","not_in"].includes($)){let X=S(l.value,`${y}/value`,100).map((ce,le)=>w(ce,`${y}/value/${le}`,2048));(X.length===0||new Set(X).size!==X.length)&&m("NATIVE_DATA_POLICY_VALUE_INVALID",`${y}/value`)}else["eq","not_eq"].includes($)?w(l.value,`${y}/value`,2048):(l.value!==void 0||l.operand!==void 0)&&m("NATIVE_DATA_POLICY_VALUE_INVALID",`${y}/value`);for(let X of["operation","valuePath","emptyMatchesAll","resourceCode","operand"])l[X]!==void 0&&m("NATIVE_DATA_POLICY_CONSTANT_RULE_INVALID",`${y}/${X}`)}if(k){(!["lt","lte","gt","gte"].includes($)||l.value!==void 0||h?.type!=="datetime")&&m("NATIVE_DATA_POLICY_DB_NOW_INVALID",y);for(let X of["operation","valuePath","emptyMatchesAll","resourceCode","value"])l[X]!==void 0&&m("NATIVE_DATA_POLICY_DB_NOW_INVALID",`${y}/${X}`)}l.dimensionCode&&!i.has(l.dimensionCode)&&m("NATIVE_SCOPE_DIMENSION_MISSING",`${y}/dimensionCode`),s.has(String(l.dimensionCode||""))&&l.operation!=="read"&&m("NATIVE_SCOPE_SOURCE_LAST_KNOWN_GOOD_UNSAFE",`${y}/operation`)}}for(let[c,f]of e.data.resources.entries()){let u=N(f,`/config/data/resources/${c}`);u.dataPolicyCode&&!a.has(u.dataPolicyCode)&&m("NATIVE_DATA_POLICY_REFERENCE_MISSING",`/config/data/resources/${c}/dataPolicyCode`)}}function sl(e){try{co(e.data.resources,"/config/data/resources"),e.data.resources.forEach((t,o)=>oo(t.schema.fields,new Set(e.authz.roles.map(n=>n.code)),new Set(e.authz.scopeDimensions.map(n=>n.code)),`/config/data/resources/${o}/schema/fields`))}catch(t){throw(t instanceof ye||t instanceof Le)&&m(t.code,t.pointer),t}}function al(e,t,o,n){let i=new Set;for(let[r,d]of e.authz.roleMembershipSources.entries()){let s=`/config/authz/roleMembershipSources/${r}`,a=N(d,s);C(a,["code","name","resourceCode","userIdField","roleCode","enabledField","effectiveFromField","effectiveToField","failureMode"],s,!0);let c=P(a.code,`${s}/code`);c.length>100&&m("NATIVE_AUTHORIZATION_PROJECTION_SOURCE_CODE_INVALID",`${s}/code`),i.has(c)&&m("NATIVE_AUTHORIZATION_PROJECTION_SOURCE_DUPLICATE",`${s}/code`),i.add(c),w(a.name,`${s}/name`,255);let f=as(a.resourceCode,`${s}/resourceCode`,o);ds(a.userIdField,`${s}/userIdField`,f),t.has(String(a.roleCode||""))||m("NATIVE_ROLE_REFERENCE_MISSING",`${s}/roleCode`),n&&a.roleCode===n&&m("NATIVE_AUTHENTICATED_USER_ROLE_SOURCE_CONFLICT",`${s}/roleCode`),cs(a,s,f)}for(let[r,d]of e.authz.relationshipGrantSources.entries()){let s=`/config/authz/relationshipGrantSources/${r}`,a=N(d,s);C(a,["code","name","resourceCode","subject","relationCode","targetResourceCode","resourceIdField","operations","enabledField","effectiveFromField","effectiveToField","failureMode"],s,!0);let c=P(a.code,`${s}/code`);c.length>100&&m("NATIVE_AUTHORIZATION_PROJECTION_SOURCE_CODE_INVALID",`${s}/code`),i.has(c)&&m("NATIVE_AUTHORIZATION_PROJECTION_SOURCE_DUPLICATE",`${s}/code`),i.add(c),w(a.name,`${s}/name`,255);let f=as(a.resourceCode,`${s}/resourceCode`,o),u=N(a.subject,`${s}/subject`),p=w(u.type,`${s}/subject/type`,32);C(u,p==="role_membership"?["type","userIdField","roleCode"]:["type","userIdField"],`${s}/subject`),["user","role_membership"].includes(p)||m("NATIVE_AUTHORIZATION_PROJECTION_SUBJECT_INVALID",`${s}/subject/type`),ds(u.userIdField,`${s}/subject/userIdField`,f),p==="role_membership"&&!t.has(String(u.roleCode||""))&&m("NATIVE_ROLE_REFERENCE_MISSING",`${s}/subject/roleCode`),P(a.relationCode,`${s}/relationCode`);let _=H(a.targetResourceCode,`${s}/targetResourceCode`);o.has(_)||m("NATIVE_AUTHORIZATION_PROJECTION_TARGET_RESOURCE_MISSING",`${s}/targetResourceCode`);let E=at(a.resourceIdField,f),A=E?.field.type==="resource-ref.single"&&E.valuePath==="value"&&E.field.source?.resourceCode===_;(a.resourceIdField==="id"?_!==String(a.resourceCode):!A)&&m("NATIVE_AUTHORIZATION_PROJECTION_RESOURCE_ID_FIELD_INVALID",`${s}/resourceIdField`);let O=L(a.operations,`${s}/operations`,20);(O.length===0||O.some(b=>b.length>64||!/^[A-Za-z0-9][A-Za-z0-9:._*-]{0,63}$/.test(b)))&&m("NATIVE_AUTHORIZATION_PROJECTION_OPERATIONS_INVALID",`${s}/operations`),cs(a,s,f)}}function as(e,t,o){let n=H(e,t),i=o.get(n);return i||m("NATIVE_AUTHORIZATION_PROJECTION_RESOURCE_MISSING",t),i}function ds(e,t,o){let n=at(e,o);bn(n)||m("NATIVE_AUTHORIZATION_PROJECTION_USER_FIELD_INVALID",t)}function cs(e,t,o){if(e.failureMode!=="strict"&&m("NATIVE_AUTHORIZATION_PROJECTION_FAILURE_MODE_INVALID",`${t}/failureMode`),e.enabledField!==void 0){let n=G(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=G(e[n],`${t}/${n}`);["date","datetime"].includes(String(o.get(i)?.type))||m("NATIVE_AUTHORIZATION_PROJECTION_EFFECTIVE_FIELD_INVALID",`${t}/${n}`)}}function dl(e){let t=new Set,o=new Set;e.forEach((n,i)=>{let r=`/config/backend/secrets/${i}`,d=N(n,r);C(d,["name","env","description","required","exposure"],r,!0);let s=w(d.name,`${r}/name`,128),a=w(d.env,`${r}/env`,128);cc.test(s)||m("NATIVE_SECRET_NAME_INVALID",`${r}/name`),(!lc.test(a)||a.startsWith("OPENXIANGDA_")||["NODE_ENV","PORT"].includes(a))&&m("NATIVE_SECRET_ENV_INVALID",`${r}/env`),t.has(s)&&m("NATIVE_SECRET_NAME_DUPLICATE",`${r}/name`),o.has(a)&&m("NATIVE_SECRET_ENV_DUPLICATE",`${r}/env`),t.add(s),o.add(a),F(d.exposure,"active_only",`${r}/exposure`),d.required!==void 0&&Et(d.required,`${r}/required`),d.description!==void 0&&Ri(d.description,`${r}/description`,2e3)})}function cl(e){let t=new Set,o=new Map,n=new Map(e.data.resources.map(_=>[String(_.code),_])),i=new Map(e.frontend.routes.map((_,E)=>{let A=N(_,`/config/frontend/routes/${E}`);return[P(A.code,`/config/frontend/routes/${E}/code`),A]}));for(let[_,E]of e.workflows.definitions.entries()){let A=`/config/workflows/definitions/${_}`,O=N(E,A);if(C(O,["version","definition","launch"],A,["detailRouteCode"]),hs(O.launch,`${A}/launch`),O.detailRouteCode!==void 0){let h=ws(O.detailRouteCode,`${A}/detailRouteCode`);for(let[$,k,M]of[["desktop",h.desktop,["admin","user"]],["mobile",h.mobile,["user"]]]){let V=`${A}/detailRouteCode/${$}`,Y=i.get(k);Y||m("NATIVE_WORKFLOW_DETAIL_ROUTE_MISSING",V),M.some(ce=>ce===Y.surface)||m("NATIVE_WORKFLOW_DETAIL_ROUTE_SURFACE_INVALID",V);let ne=Ne(Y.path,V),X=[...ne.matchAll(/:([A-Za-z][A-Za-z0-9_]*)/g)].map(ce=>ce[1]);(ne.includes("*")||X.length!==1||X[0]!=="instanceId")&&m("NATIVE_WORKFLOW_DETAIL_ROUTE_PATH_INVALID",V)}}let b=N(O.definition,`${A}/definition`),g=`${b.code}:${At(O.version,`${A}/version`)}`;t.has(g)&&m("NATIVE_WORKFLOW_DEFINITION_DUPLICATE",A),t.add(g),ul(b,`${A}/definition`);let I=Pn(b);I.length&&m(I[0],`${A}/definition/launchPreflight`);let T=ni(b);T.length&&m(T[0],`${A}/definition/approvedDelegation`);let l=ei(b,e.backend.operations);l.length&&m(l[0],`${A}/definition/commandHandlers`),ll(b.subject,n,`${A}/definition/subject`);let y=jt(b,new Map((n.get(b.subject.resourceCode)?.schema.fields||[]).map(h=>[h.code,{...n.get(b.subject.resourceCode)?.surface?.fields?.[h.code],...h,system:["id","revision","createdAt","updatedAt","createdBy","updatedBy"].includes(h.code)}])),new Map([...n].map(([h,$])=>[h,new Map($.schema.fields.map(k=>[k.code,{...$.surface?.fields?.[k.code],...k,system:["id","revision","createdAt","updatedAt","createdBy","updatedBy"].includes(k.code)}]))])),bt(n.get(b.subject.resourceCode)?.schema||{}));y.length&&m(y[0],`${A}/definition/taskPages`);let R=xo(b,{appCode:e.appCode,capabilities:e.authz.capabilities.map(h=>h.code),fields:new Map((n.get(b.subject.resourceCode)?.schema.fields||[]).map(h=>[h.code,h]))});R.length&&m("NATIVE_WORKFLOW_INSTANCE_COMMAND_POLICY_INVALID",`${A}/definition/instanceCommands`,{errors:R}),b.title===b.code&&m("NATIVE_WORKFLOW_USER_TITLE_REQUIRED",`${A}/definition/title`),o.set(g,b)}let r=new Set,d=new Map;for(let[_,E]of e.workflows.bindings.entries()){let A=N(E,`/config/workflows/bindings/${_}`),O=N(A.binding,`/config/workflows/bindings/${_}/binding`),b=`${O.workflowCode}:${At(A.version,`/config/workflows/bindings/${_}/version`)}`;r.has(b)&&m("NATIVE_WORKFLOW_BINDING_DUPLICATE",`/config/workflows/bindings/${_}`),r.add(b),fl(O,`/config/workflows/bindings/${_}/binding`),d.set(b,O)}let s=new Set,a=new Map;for(let[_,E]of e.workflows.activations.entries()){let A=`/config/workflows/activations/${_}`,O=N(E,A);C(O,["workflowCode","definitionVersion","bindingVersion","acceptedCommandDeactivationPolicy"],A,["environmentKey"]);let b=P(O.workflowCode,`${A}/workflowCode`);s.has(b)&&m("NATIVE_WORKFLOW_ACTIVATION_DUPLICATE",A),s.add(b);let g=`${b}:${At(O.definitionVersion,`${A}/definitionVersion`)}`,I=`${b}:${At(O.bindingVersion,`${A}/bindingVersion`)}`;t.has(g)||m("NATIVE_WORKFLOW_DEFINITION_REFERENCE_MISSING",`${A}/definitionVersion`),r.has(I)||m("NATIVE_WORKFLOW_BINDING_REFERENCE_MISSING",`${A}/bindingVersion`);let T=o.get(g),l=d.get(I),y=Pn(T,l);y.length&&m(y[0],A);let R=kn(T,l);R.length&&m(R[0],A),(!["finish-pinned","cancel-on-deactivate"].includes(O.acceptedCommandDeactivationPolicy)||O.acceptedCommandDeactivationPolicy!==T.acceptedCommandDeactivationPolicy)&&m("NATIVE_WORKFLOW_COMMAND_DEACTIVATION_POLICY_MISMATCH",`${A}/acceptedCommandDeactivationPolicy`),pl(T,l,`/config/workflows/activations/${_}`);try{let h=n.get(T.subject.resourceCode)?.schema.fields||[];io(T,l,new Map(h.map($=>[$.code,$])),`${A}/bindings`,new Map([...n].map(([$,k])=>[$,new Map(k.schema.fields.map(M=>[M.code,M]))])))}catch(h){throw h instanceof Le&&m(h.code,h.pointer),h}a.set(b,l)}let c=li([...a.values()]);c.length&&m(c[0],"/config/workflows/activations");let f=new Set;e.workflows.providers.forEach((_,E)=>{let A=`/config/workflows/providers/${E}`,O=N(_,A);C(O,["code","endpointPath","timeoutMs"],A,!0);let b=P(O.code,`${A}/code`);f.has(b)&&m("NATIVE_WORKFLOW_PROVIDER_DUPLICATE",`${A}/code`),f.add(b),Ne(O.endpointPath,`${A}/endpointPath`),O.timeoutMs!==void 0&&ie(O.timeoutMs,`${A}/timeoutMs`,100,1e4)});for(let[_,E]of a.entries())for(let[A,O]of Object.entries(N(E.bindings,"/config/workflows/bindings/*/binding/bindings"))){let b=N(O,`/config/workflows/${_}/bindings/${A}`);b.provider==="application_provider"&&!f.has(b.providerCode)&&m("NATIVE_WORKFLOW_PROVIDER_REFERENCE_MISSING",`/config/workflows/${_}/bindings/${A}/providerCode`)}let u=new Set(e.authz.roles.map(_=>_.code)),p=new Set;e.workflows.editableParameters.forEach((_,E)=>{let A=`/config/workflows/editableParameters/${E}`,O=N(_,A);C(O,["code","workflowCode","bindingKey","label","valueType","required","allowedRoleCodes","allowedProviderCodes","maxItems"],A,!0);let b=P(O.code,`${A}/code`);p.has(b)&&m("NATIVE_WORKFLOW_EDITABLE_PARAMETER_DUPLICATE",`${A}/code`),p.add(b);let g=zn(O.workflowCode,`${A}/workflowCode`),I=Bn(O.bindingKey,`${A}/bindingKey`),T=a.get(g);(!T||!N(T.bindings,`${A}/bindingKey`)[I])&&m("NATIVE_WORKFLOW_EDITABLE_BINDING_MISSING",`${A}/bindingKey`),w(O.label,`${A}/label`,255),["role_code","user_ids","provider_code"].includes(O.valueType)||m("NATIVE_WORKFLOW_EDITABLE_VALUE_TYPE_INVALID",`${A}/valueType`);for(let l of L(O.allowedRoleCodes||[],`${A}/allowedRoleCodes`,100))u.has(l)||m("NATIVE_ROLE_REFERENCE_MISSING",`${A}/allowedRoleCodes`);for(let l of L(O.allowedProviderCodes||[],`${A}/allowedProviderCodes`,100))f.has(l)||m("NATIVE_WORKFLOW_PROVIDER_REFERENCE_MISSING",`${A}/allowedProviderCodes`);O.required!==void 0&&Et(O.required,`${A}/required`),O.maxItems!==void 0&&ie(O.maxItems,`${A}/maxItems`,1,200)})}function ll(e,t,o){let n=N(e,o);C(n,["resourceCode","factProjection"],o,["summaryFields"]);let i=H(n.resourceCode,`${o}/resourceCode`),r=t.get(i);r||m("NATIVE_WORKFLOW_SUBJECT_RESOURCE_MISSING",`${o}/resourceCode`);let d=new Set(S(N(r.schema,`${o}/resourceCode`).fields,`${o}/resourceCode`,500).map((c,f)=>G(N(c,`${o}/resourceCode/${f}`).code,`${o}/resourceCode/${f}`))),s=N(n.factProjection,`${o}/factProjection`),a=Object.entries(s);(a.length<1||a.length>64)&&m("NATIVE_WORKFLOW_SUBJECT_FACT_PROJECTION_INVALID",`${o}/factProjection`);for(let[c,f]of a){pc.test(c)||m("NATIVE_WORKFLOW_SUBJECT_FACT_KEY_INVALID",`${o}/factProjection/${c}`);let u=G(f,`${o}/factProjection/${c}`);d.has(u)||m("NATIVE_WORKFLOW_SUBJECT_FIELD_MISSING",`${o}/factProjection/${c}`)}if(n.summaryFields!==void 0){let c=L(n.summaryFields,`${o}/summaryFields`,mc).map((E,A)=>G(E,`${o}/summaryFields/${A}`)),f=t.get(i),u=f.surface&&typeof f.surface=="object"&&!Array.isArray(f.surface)?f.surface:{},p=u.fields&&typeof u.fields=="object"&&!Array.isArray(u.fields)?u.fields:{},_=new Map(S(N(f.schema,`${o}/resourceCode`).fields,`${o}/resourceCode`,500).map((E,A)=>{let O=N(E,`${o}/resourceCode/${A}`);return[String(O.code),O]}));for(let[E,A]of c.entries()){let O=_.get(A),b=p[A],g=String(O?.type||""),I=O?.maxLength;(!O||O.system===!0||b&&typeof b=="object"&&!Array.isArray(b)&&b.system===!0||["id","revision","created_by","updated_by","created_at","updated_at"].includes(A)||!gc.has(g)||g==="text.long"&&typeof I=="number"&&Number.isFinite(I)&&I>_c)&&m("NATIVE_WORKFLOW_SUBJECT_SUMMARY_FIELDS_INVALID",`${o}/summaryFields/${E}`)}}}function ul(e,t){C(e,["schemaVersion","code","title","subject","acceptedCommandDeactivationPolicy","startAt","inputSchema","nodes"],t,["organizationContext","instanceCommands","readability","taskPages","rejectionNotification","commandHandlers","launchPreflight","approvedDelegation"]),F(e.schemaVersion,"openxiangda.workflow-definition/v2",`${t}/schemaVersion`),zn(e.code,`${t}/code`),w(e.title,`${t}/title`,255),["finish-pinned","cancel-on-deactivate"].includes(e.acceptedCommandDeactivationPolicy)||m("NATIVE_WORKFLOW_COMMAND_DEACTIVATION_POLICY_REQUIRED",`${t}/acceptedCommandDeactivationPolicy`);let o=N(e.nodes,`${t}/nodes`),n=Object.keys(o);(n.length===0||n.length>200)&&m("NATIVE_WORKFLOW_NODE_COUNT_INVALID",`${t}/nodes`);let i=w(e.startAt,`${t}/startAt`,128),r=qo(e);r.length&&m(r[0],`${t}/readability`);let d=kn(e);d.length&&m(d[0],`${t}/nodes`);let s=vn(e);s.length&&m(s[0],`${t}/nodes`);let a=ft(e);a.length&&m(a[0],`${t}/nodes`);let c=Xo(e);c.length&&m(c[0],`${t}/nodes`);let f=Qo(e);f.length&&m(f[0],`${t}/rejectionNotification`);let u=$n(e);u.length&&m(u[0],`${t}/nodes`);let p=jt(e);p.length&&m(p[0],`${t}/taskPages`);let _=$t(e);_.length&&m(_[0],`${t}/nodes`),o[i]||m("NATIVE_WORKFLOW_START_NODE_MISSING",`${t}/startAt`);let E=new Map;for(let[g,I]of Object.entries(o)){let T=`${t}/nodes/${g}`,l=N(I,T);F(l.id,g,`${T}/id`),["approval","condition","end","cc","action","correction"].includes(l.kind)||m("NATIVE_WORKFLOW_NODE_KIND_INVALID",`${T}/kind`);let y=[];if(l.kind==="approval"){w(l.title,`${T}/title`,255),Bn(l.binding,`${T}/binding`),["single","any","all","sequence"].includes(l.mode)||m("NATIVE_WORKFLOW_APPROVAL_MODE_INVALID",`${T}/mode`),y.push(w(l.onApprove,`${T}/onApprove`,128),w(l.onReject,`${T}/onReject`,128));for(let R of L(l.returnTargets||[],`${T}/returnTargets`,200))o[R]||m("NATIVE_WORKFLOW_TARGET_MISSING",`${T}/returnTargets`);for(let R of L(l.allowedOperations||[],`${T}/allowedOperations`,20))Ec.has(R)||m("NATIVE_WORKFLOW_OPERATION_INVALID",`${T}/allowedOperations`)}else if(l.kind==="correction"){let R=oi(e);R.length&&m(R[0],T)}else if(l.kind==="action")y.push(w(l.next,`${T}/next`,128));else if(l.kind==="cc")w(l.title,`${T}/title`,255),Bn(l.binding,`${T}/binding`),y.push(w(l.next,`${T}/next`,128));else if(l.kind==="condition"){let R=S(l.branches,`${T}/branches`,100);R.length===0&&m("NATIVE_WORKFLOW_BRANCH_REQUIRED",`${T}/branches`),R.forEach((h,$)=>{let k=N(h,`${T}/branches/${$}`);zt(k.when,`${T}/branches/${$}/when`,0),y.push(w(k.target,`${T}/branches/${$}/target`,128))}),y.push(w(l.otherwise,`${T}/otherwise`,128))}else w(l.title,`${T}/title`,255),w(l.outcome,`${T}/outcome`,128);for(let R of y)o[R]||m("NATIVE_WORKFLOW_TARGET_MISSING",T);E.set(g,y)}let A=new Set,O=new Set,b=g=>{if(O.has(g)&&m("NATIVE_WORKFLOW_CYCLE_FORBIDDEN",`${t}/nodes/${g}`),!A.has(g)){A.add(g),O.add(g);for(let I of E.get(g)||[])b(I);O.delete(g)}};b(i);for(let g of[...A]){let I=o[g];if(I?.kind==="approval")for(let T of I.returnTargets||[])o[T]?.kind==="correction"&&A.add(T)}A.size!==n.length&&m("NATIVE_WORKFLOW_NODE_UNREACHABLE",`${t}/nodes`)}function zt(e,t,o){o>20&&m("NATIVE_WORKFLOW_EXPRESSION_DEPTH_EXCEEDED",t);let n=N(e,t),i=w(n.op,`${t}/op`,16);if(i!=="literal"){if(i==="path"){let r=w(n.path,`${t}/path`,255);(!/^[A-Za-z][A-Za-z0-9_.-]{0,254}$/.test(r)||r.split(".").some(d=>["__proto__","constructor","prototype"].includes(d)))&&m("NATIVE_WORKFLOW_EXPRESSION_PATH_INVALID",`${t}/path`);return}if(["eq","neq","gt","gte","lt","lte","in","contains"].includes(i)){zt(n.left,`${t}/left`,o+1),zt(n.right,`${t}/right`,o+1);return}if(["and","or"].includes(i)){let r=S(n.values,`${t}/values`,100);r.length===0&&m("NATIVE_WORKFLOW_EXPRESSION_EMPTY",`${t}/values`),r.forEach((d,s)=>zt(d,`${t}/values/${s}`,o+1));return}if(["not","exists"].includes(i)){zt(n.value,`${t}/value`,o+1);return}m("NATIVE_WORKFLOW_EXPRESSION_OPERATOR_INVALID",`${t}/op`)}}function fl(e,t){F(e.schemaVersion,"openxiangda.workflow-binding/v2",`${t}/schemaVersion`),zn(e.workflowCode,`${t}/workflowCode`);let o=N(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)){Bn(n,`${t}/bindings/${n}`);let r=N(i,`${t}/bindings/${n}`),d=Pt(r);d.length&&m(d[0],`${t}/bindings/${n}/roleCodes`);let s=w(r.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(s)||m("NATIVE_WORKFLOW_BINDING_PROVIDER_INVALID",`${t}/bindings/${n}/provider`),s==="fixed_users"&&(Array.isArray(r.users)||m("NATIVE_WORKFLOW_BINDING_USERS_REQUIRED",`${t}/bindings/${n}/users`),S(r.users,`${t}/bindings/${n}/users`,200)),["input_users","form_field_users"].includes(s)&&w(r.inputPath,`${t}/bindings/${n}/inputPath`,255),["app_role","app_role_in_scope","initiator_select"].includes(s)&&r.roleCodes===void 0&&P(r.roleCode,`${t}/bindings/${n}/roleCode`),s==="department_supervisor"&&w(r.departmentIdFrom,`${t}/bindings/${n}/departmentIdFrom`,255),s==="application_provider"&&P(r.providerCode,`${t}/bindings/${n}/providerCode`),r.routing!==void 0){let a=Mt(r.routing);a.length&&m(a[0],`${t}/bindings/${n}/routing`)}}}function pl(e,t,o){F(t.workflowCode,e.code,`${o}/workflowCode`);let n=N(t.bindings,`${o}/bindings`);for(let[s,a]of Object.entries(n))a.provider==="fixed_users"&&!a.users.length&&!Yo(e,s)&&m("NATIVE_WORKFLOW_BINDING_USERS_REQUIRED",`${o}/bindings/${s}/users`);let i=vn(e,t);i.length&&m(i[0],o);let r=$n(e,t);r.length&&m(r[0],o);let d=$t(e,t);d.length&&m(d[0],o);for(let[s,a]of Object.entries(N(e.nodes,`${o}/nodes`))){let c=N(a,`${o}/nodes/${s}`);["approval","cc"].includes(c.kind)&&!n[c.binding]&&m("NATIVE_WORKFLOW_BINDING_REFERENCE_MISSING",`${o}/nodes/${s}/binding`)}}function ml(e,t,o){let n=N(t.routeManifest,"/contracts/routeManifest"),i=N(e.routeManifest,"/contracts/routeManifest"),r=new Map;for(let f of S(o.data?.resources,"/config/data/resources",B.resources)){let u=N(f,"/config/data/resources");r.set(String(u.code||""),u)}let d=new Set(S(i.routes,"/contracts/routeManifest/routes",B.routes).map(f=>String(N(f,"/contracts/routeManifest/routes").code||""))),s=[];for(let f of S(n.routes,"/contracts/routeManifest/routes",B.routes)){let u=N(f,"/contracts/routeManifest/routes"),p=String(u.kind||"");if(p!=="resource-records"&&p!=="resource-submit")continue;let _=String(u.resourceCode||""),E=r.get(_);E||m("NATIVE_ROUTE_MANIFEST_RESOURCE_UNKNOWN","/contracts/routeManifest/routes");let O=`user.${_}.${p==="resource-records"?"records":"submit"}`;F(String(u.code||""),O,"/contracts/routeManifest/routes/code");let b=p==="resource-records"?"read":"create",g=String(N(E.capabilities,"/config/data/resources/capabilities")[b]||"");for(let I of["desktop","mobile"]){let T=N(u[I],`/contracts/routeManifest/routes/${I}`),l=I==="mobile"?"/m/my/":"/my/",y=p==="resource-records"?`${l}${_}`:`${l}${_}/submit`;F(String(T.path||""),y,`/contracts/routeManifest/routes/${I}/path`),F(String(T.capability||""),g,`/contracts/routeManifest/routes/${I}/capability`),F(String(T.routeCode||""),`${O}.${I}`,`/contracts/routeManifest/routes/${I}/routeCode`)}(d.has(O)||s.some(I=>String(I.code)===O))&&m("NATIVE_ROUTE_MANIFEST_DUPLICATE","/contracts/routeManifest/routes/code"),s.push(u)}if(!s.length)return;i.routes=S([...i.routes,...s],"/contracts/routeManifest/routes",1e3).sort((f,u)=>Ee(String(N(f,"x").code||""),String(N(u,"x").code||"")));let a=String(N(n.rootEntry,"x").code||"");if(s.find(f=>String(f.code)===a&&f.kind==="resource-records")){let f=N(n.rootEntry,"x");i.rootEntry={code:a,desktop:String(f.desktop||""),mobile:String(f.mobile||"")}}i.digest=Z({schemaVersion:i.schemaVersion,appCode:i.appCode,devicePolicy:i.devicePolicy,rootEntry:i.rootEntry,authentication:i.authentication,routes:i.routes})}function Ye(e,t,o){let n=N(e,t);C(n,["schemaVersion","appCode","code","name","schema","surface","invariants","decimalReservationLifecycle","uniqueKeys","workflowHistory","recordPrint","recordComments","recordDeletion","capabilities","dataPolicyCode","fieldPolicies"],t,!0),F(n.schemaVersion,"openxiangda.data-resource/v2",`${t}/schemaVersion`),F(n.appCode,o,`${t}/appCode`);let i=H(n.code,`${t}/code`),r=w(n.name,`${t}/name`,255),d=N(n.schema,`${t}/schema`);C(d,["fields","ownedRowLimit"],`${t}/schema`,!0),d.ownedRowLimit!==void 0&&!tt(d.ownedRowLimit)&&m("NATIVE_DATA_OWNED_ROW_LIMIT_INVALID",`${t}/schema/ownedRowLimit`);let s,a,c,f;try{c=An(n.decimalReservationLifecycle,`${t}/decimalReservationLifecycle`),s=dn(d.fields,`${t}/schema/fields`),f=Po(n.uniqueKeys,s,`${t}/uniqueKeys`),a=lo(n.invariants,s,`${t}/invariants`),pn(n.surface,s,`${t}/surface`)}catch(E){throw(E instanceof ye||E instanceof Le||E instanceof Ke||E instanceof ct)&&m(E.code,E.pointer),E}if(n.recordComments!==void 0){let E=N(n.recordComments,`${t}/recordComments`);C(E,["read","create"],`${t}/recordComments`);for(let A of["read","create"]){let O=E[A];(!Array.isArray(O)||O.length>20||O.some(b=>typeof b!="string"||!b.trim())||new Set(O).size!==O.length)&&m("NATIVE_RECORD_COMMENTS_POLICY_INVALID",`${t}/recordComments/${A}`)}}if(n.recordDeletion!==void 0){let E=N(n.recordDeletion,`${t}/recordDeletion`);C(E,["delete"],`${t}/recordDeletion`);let A=E.delete;(!Array.isArray(A)||A.length>20||A.some(O=>typeof O!="string"||!O.trim())||new Set(A).size!==A.length)&&m("NATIVE_RECORD_DELETION_DELETE_INVALID",`${t}/recordDeletion/delete`)}if(n.recordPrint!==void 0){let E=N(n.recordPrint,`${t}/recordPrint`);C(E,["read"],`${t}/recordPrint`);let A=E.read;(!Array.isArray(A)||A.length>20||A.some(O=>typeof O!="string"||!O.trim())||new Set(A).size!==A.length)&&m("NATIVE_RECORD_PRINT_READ_INVALID",`${t}/recordPrint/read`)}if(n.workflowHistory!==void 0){let E=N(n.workflowHistory,`${t}/workflowHistory`);C(E,["read"],`${t}/workflowHistory`);let A=E.read;(!Array.isArray(A)||A.length>20||A.some(O=>typeof O!="string"||!O.trim())||new Set(A).size!==A.length)&&m("NATIVE_WORKFLOW_HISTORY_READ_INVALID",`${t}/workflowHistory/read`)}let u=new Set(s.map(E=>E.code)),p=N(n.capabilities,`${t}/capabilities`);C(p,["read","create","update","delete"],`${t}/capabilities`);let _=N(n.fieldPolicies,`${t}/fieldPolicies`);for(let[E,A]of Object.entries(_)){!u.has(E)&&!nt(E)&&m("NATIVE_DATA_FIELD_POLICY_FIELD_MISSING",`${t}/fieldPolicies/${E}`);let O=`${t}/fieldPolicies/${E}`,b=N(A,O);nt(E)&&(C(b,["read"],O,!0),(!Array.isArray(b.read)||b.read.length>20||b.read.some(g=>typeof g!="string"||!g.trim())||new Set(b.read).size!==b.read.length)&&m("NATIVE_DATA_AUDIT_READ_POLICY_INVALID",`${O}/read`)),C(b,["read","create","update","mask"],O,!0),b.mask!==void 0&&!["omit","null"].includes(b.mask)&&m("NATIVE_DATA_FIELD_POLICY_MASK_INVALID",`${O}/mask`)}return{...n,code:i,name:r,schema:{fields:s,...d.ownedRowLimit!==void 0?{ownedRowLimit:d.ownedRowLimit}:{}},...n.invariants===void 0?{}:{invariants:a},...c?{decimalReservationLifecycle:c}:{},...f!==void 0?{uniqueKeys:f}:{},capabilities:p,fieldPolicies:_}}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 ls(e,t,o,n){let i=e.toString("utf8"),r;try{r=JSON.parse(i)}catch{m(o,t)}let d=N(r,t);return Q(d)!==i&&m(n,t),d}function Ai(e,t,o){let n=0,i=(r,d,s)=>{if(n+=1,n>o&&m("NATIVE_ARTIFACT_NODE_LIMIT_EXCEEDED",d),s>bc&&m("NATIVE_ARTIFACT_DEPTH_LIMIT_EXCEEDED",d),typeof r=="string"){Buffer.byteLength(r)>Ii&&m("NATIVE_ARTIFACT_STRING_LIMIT_EXCEEDED",d);return}if(Array.isArray(r)){r.forEach((a,c)=>i(a,`${d}/${c}`,s+1));return}if(!(!r||typeof r!="object"))for(let[a,c]of Object.entries(r))["__proto__","prototype","constructor"].includes(a)&&m("NATIVE_ARTIFACT_DANGEROUS_KEY",`${d}/${a}`),_l(a)&&m("NATIVE_ARTIFACT_RUNTIME_FIELD_FORBIDDEN",`${d}/${a}`),i(c,`${d}/${a}`,s+1)};i(e,t,0)}function _l(e){return["environmentKey","environmentId","secretValue","ciphertext","oauthClient","oauthClientId","oauthClientSecret","signingSecret","kubernetesNamespace","nodePort","productionUrl"].includes(e)}function gt(e){return{value:e,digest:Z(e)}}function us(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 fs(e,t,o,n){let i=Kn.createHash("sha256").update(e).digest("hex");Kn.timingSafeEqual(Buffer.from(i),Buffer.from(t))||m(n,o)}function N(e,t){return(!e||typeof e!="object"||Array.isArray(e))&&m("NATIVE_OBJECT_REQUIRED",t),e}function S(e,t,o){return Array.isArray(e)||m("NATIVE_ARRAY_REQUIRED",t),e.length>o&&m("NATIVE_ARRAY_LIMIT_EXCEEDED",t),e}function L(e,t,o){let n=S(e,t,o).map((i,r)=>w(i,`${t}/${r}`,255));return new Set(n).size!==n.length&&m("NATIVE_ARRAY_DUPLICATE",t),n}function w(e,t,o){return(typeof e!="string"||e.length===0||e.length>o)&&m("NATIVE_STRING_INVALID",t),e}function Ri(e,t,o){return(typeof e!="string"||e.length>o)&&m("NATIVE_STRING_INVALID",t),e}function P(e,t){let o=w(e,t,128);return rc.test(o)||m("NATIVE_CODE_INVALID",t),o}function H(e,t){let o=w(e,t,64);return ac.test(o)||m("NATIVE_RESOURCE_CODE_INVALID",t),o}function G(e,t){let o=w(e,t,63);return dc.test(o)||m("NATIVE_FIELD_CODE_INVALID",t),o}function zn(e,t){let o=w(e,t,128);return uc.test(o)||m("NATIVE_WORKFLOW_CODE_INVALID",t),o}function Bn(e,t){let o=w(e,t,128);return fc.test(o)||m("NATIVE_WORKFLOW_BINDING_CODE_INVALID",t),o}function pe(e,t,o){let n=w(e,t,255);return ic.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 Ne(e,t){let o=w(e,t,2048);return(!o.startsWith("/")||o.startsWith("//")||o.includes("..")||o.includes("?")||o.includes("#"))&&m("NATIVE_ABSOLUTE_PATH_INVALID",t),o}function At(e,t){return(!Number.isInteger(e)||Number(e)<1)&&m("NATIVE_POSITIVE_INTEGER_REQUIRED",t),Number(e)}function ie(e,t,o,n){return(!Number.isInteger(e)||Number(e)<o||Number(e)>n)&&m("NATIVE_INTEGER_OUT_OF_RANGE",t),Number(e)}function Et(e,t){return typeof e!="boolean"&&m("NATIVE_BOOLEAN_REQUIRED",t),e}function bi(e,t){let o=w(e,t,64).toLowerCase();return nc.test(o)||m("NATIVE_DIGEST_INVALID",t),o}function F(e,t,o){e!==t&&m("NATIVE_VALUE_MISMATCH",o)}function C(e,t,o,n=!1){let i=new Set([...t,...Array.isArray(n)?n:[]]);for(let r of Object.keys(e))i.has(r)||m("NATIVE_PROPERTY_UNKNOWN",`${o}/${r}`);if(n!==!0)for(let r of t)Object.prototype.hasOwnProperty.call(e,r)||m("NATIVE_PROPERTY_REQUIRED",`${o}/${r}`)}function ee(e,t){return[...e].sort((o,n)=>Ee(t(o),t(n)))}function U(e){return[...new Set(e)].sort(Ee)}function ps(e){return[...new Set(e)].sort((t,o)=>t-o)}function Ee(e,t){return e===t?0:e<t?-1:1}function Ds(e){return!e||typeof e!="object"||Object.isFrozen(e)||(Object.freeze(e),Object.values(e).forEach(t=>Ds(t))),e}function Oi(e,t,o){if(Ei(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(!Ei(e[i],t[i]))return Oi(e[i],t[i],`${o}/${i}`)}if(e&&t&&typeof e=="object"&&typeof t=="object"&&!Array.isArray(e)&&!Array.isArray(t)){let n=U([...Object.keys(e),...Object.keys(t)]);for(let i of n){let r=e[i],d=t[i];if(!Ei(r,d))return Oi(r,d,`${o}/${i}`)}}return o}function Ei(e,t){return e===void 0||t===void 0?e===t:Q(e)===Q(t)}function m(e,t,o={}){throw new Wn(e,t,o)}var gl="openxiangda.workflow-step-data-command/v1",ks="openxiangda.workflow-step-data-resolution/v1";function Al(e,t,o=!1){let n=s=>!!s&&typeof s=="object"&&!Array.isArray(s),i=s=>typeof s=="string"&&/^[a-f0-9]{8}(-[a-f0-9]{4}){3}-[a-f0-9]{12}$/i.test(s),r=()=>{throw new Error("WORKFLOW_STEP_DATA_RESPONSE_INVALID")};if(!n(e)||e.schemaVersion!==ks||e.executionId!==t||Object.keys(e).some(s=>!["schemaVersion","executionId","outcome","transaction"].includes(s)))return r();if(e.outcome==="not_observed"&&!Object.hasOwn(e,"transaction")&&!o)return e;let d=e.transaction;if(e.outcome!=="committed"||!n(d)||d.schemaVersion!=="openxiangda.data-transaction-result/v2"||d.idempotencyKey!==`workflow-step:${t}`||typeof d.replayed!="boolean"||!Array.isArray(d.items)||d.items.length<1||d.items.length>2016||d.evaluatedAt!==void 0&&(typeof d.evaluatedAt!="string"||!Number.isFinite(Date.parse(d.evaluatedAt))))return r();for(let[s,a]of d.items.entries()){if(!n(a)||a.index!==s)return r();if(a.operation==="emitEvent"){if(typeof a.eventType!="string"||!a.eventType||!i(a.eventId))return r()}else if(!["create","update","delete","increment"].includes(a.operation)||typeof a.resourceCode!="string"||!a.resourceCode||!i(a.id)||!Number.isSafeInteger(a.revision)||a.revision<1)return r()}return e}var pp=50,mp=131072,Jn=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 El(e){let t=u=>{throw new Jn(u)},o=(u,p)=>((!u||typeof u!="object"||Array.isArray(u))&&t(p),u),n=(u,p,_)=>{for(let E of Object.keys(u))p.includes(E)||t(`${_}/${E}`)},i=(u,p,_)=>((typeof u!="string"||!u.trim()||u.length>p)&&t(_),u),r=(u,p)=>{let _=i(u,36,p);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(_)||t(p),_.toLowerCase()},d=o(e,""),s;try{s=new TextEncoder().encode(JSON.stringify(d)).byteLength}catch{t("")}s>131072&&t(""),n(d,["schemaVersion","environmentKey","items"],""),d.schemaVersion!=="openxiangda.native-role-membership-batch-request/v2"&&t("/schemaVersion"),d.environmentKey!==void 0&&!["preproduction","production"].includes(String(d.environmentKey))&&t("/environmentKey"),(!Array.isArray(d.items)||d.items.length<1||d.items.length>50)&&t("/items");let a=new Set,c=new Set,f;for(let[u,p]of d.items.entries()){let _=`/items/${u}`,E=o(p,_);["create","update","revoke"].includes(String(E.operation))||t(`${_}/operation`),f??=E.operation,f!==E.operation&&t(`${_}/operation`),n(E,["operation","operationId","reason",...f==="create"?["userId","roleCode"]:["membershipId","expectedRevision"],...f!=="revoke"?["scopeGrants","validFrom","validTo"]:[]],_);let A=r(E.operationId,`${_}/operationId`);a.has(A)&&t(`${_}/operationId`),a.add(A),i(E.reason,1e3,`${_}/reason`);let O;if(f==="create"){let b=i(E.userId,255,`${_}/userId`),g=i(E.roleCode,128,`${_}/roleCode`);/^[a-z][a-z0-9]*(?:[._-][a-z0-9]+)*$/.test(g)||t(`${_}/roleCode`),O=JSON.stringify([b,g])}else O=r(E.membershipId,`${_}/membershipId`),(!Number.isSafeInteger(E.expectedRevision)||Number(E.expectedRevision)<1)&&t(`${_}/expectedRevision`);c.has(O)&&t(_),c.add(O),E.scopeGrants!==void 0&&(!Array.isArray(E.scopeGrants)||E.scopeGrants.length>100)&&t(`${_}/scopeGrants`);for(let b of["validFrom","validTo"])E[b]!==void 0&&E[b]!==null&&i(E[b],64,`${_}/${b}`)}}var Ls="openxiangda.workflow-delegation-administration/v2",Vs="openxiangda.workflow-delegation-mutation/v2",$s="openxiangda.workflow-delegation-preview/v2";var Ht={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}$"},me={type:"string",minLength:1,maxLength:255},Xe={type:"string",format:"date-time"},It={type:"integer",minimum:1},Il={anyOf:[Xe,{type:"null"}]},Ci={anyOf:[me,{type:"null"}]},Fs={anyOf:[{type:"string",pattern:"^[A-Za-z0-9._:-]{1,128}$"},{type:"null"}]},Hn={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}$"},xs={const:"future-assignments-only"},hi={schemaVersion:{const:Ls},id:Ht,appCode:me,environmentKey:me,workflowCode:Ci,nodeId:Fs,delegatorUserId:me,delegateUserId:me,delegatorRoleSubjectKey:Hn,delegateRoleSubjectKey:Hn,validFrom:Xe,validTo:Xe,status:{enum:["active","revoked","expired"]},reason:{type:"string",minLength:1,maxLength:4e3},createdBy:me,createdAt:Xe,revokedAt:Il,revision:It,roleCode:me,roleName:me,delegatorDisplayName:me,delegateDisplayName:me,delegatorRoleSubjectRevision:It,delegateRoleSubjectRevision:It,effectiveState:{enum:["active","scheduled","expired","revoked","ineligible"]},evaluatedAt:Xe,issues:{type:"array",maxItems:20,uniqueItems:!0,items:me},canRevoke:{type:"boolean"},revokedBy:Ci,revokeReason:{type:["string","null"],maxLength:4e3},taskPolicy:xs},wi={type:"object",additionalProperties:!1,required:Object.keys(hi).filter(e=>e!=="nodeId"),properties:hi},gp={$id:Ls,...wi},js={schemaVersion:{const:Vs},operationId:Ht,environmentKey:{enum:["preproduction","production"]},reason:{type:"string",minLength:1,maxLength:2e3,pattern:"\\S"}},vs={...js,operation:{const:"create"},workflowCode:Ci,nodeId:Fs,delegatorRoleSubjectKey:Hn,expectedDelegatorRevision:It,delegateUserId:me,delegateRoleSubjectKey:Hn,expectedDelegateRevision:It,validFrom:Xe,validTo:Xe},Ps={...js,operation:{const:"revoke"},delegationId:Ht,expectedRevision:It},Ws={$id:Vs,type:"object",oneOf:[{type:"object",additionalProperties:!1,required:Object.keys(vs).filter(e=>e!=="nodeId"),properties:vs,if:{required:["nodeId"],properties:{nodeId:{type:"string"}}},then:{properties:{workflowCode:me}}},{type:"object",additionalProperties:!1,required:Object.keys(Ps),properties:Ps}]},yl={type:"string",pattern:"^[0-9a-f]{64}$"},Ap={$id:$s,type:"object",additionalProperties:!1,required:["schemaVersion","operationId","operation","requestDigest","before","after","taskPolicy"],properties:{schemaVersion:{const:$s},operationId:Ht,operation:{enum:["create","revoke"]},requestDigest:yl,before:{anyOf:[wi,{type:"null"}]},after:{...wi,properties:{...hi,id:{anyOf:[Ht,{type:"null"}]}}},taskPolicy:xs}};function bl(e){return e===void 0?"":`
9
- ${Z(e)}`}function Ol(e,t){let o=e.handlers.find(n=>n.code===t);return Z(o?.workflowStep?o:e)}var Nl="openxiangda.data-business-command/v1",Us="openxiangda.data-business-command-resolution/v1",bp=65536;function Tl(e){let t=0,o=0,n=new Set,i=new TextEncoder,r=()=>{throw new Error("OPENXIANGDA_DATA_COMMAND_INTENT_INVALID")},d=a=>(o+=i.encode(a).byteLength,o>65536&&r(),a),s=(a,c)=>{if(++t>1e4||c>32)return r();if(a===null||typeof a=="string"||typeof a=="boolean")return d(JSON.stringify(a));if(typeof a=="number")return Number.isFinite(a)?d(JSON.stringify(a)):r();if(!a||typeof a!="object"||n.has(a)||Object.getOwnPropertySymbols(a).length)return r();n.add(a);let f;if(Array.isArray(a))return Object.keys(a).length!==a.length?r():(f=d("[")+a.map((p,_)=>(_?d(","):"")+s(p,c+1)).join("")+d("]"),n.delete(a),f);let u=Object.getPrototypeOf(a);return u!==Object.prototype&&u!==null?r():(f=d("{")+Object.keys(a).sort().map((p,_)=>(_?d(","):"")+d(JSON.stringify(p))+d(":")+s(a[p],c+1)).join("")+d("}"),n.delete(a),f)};return!e||typeof e!="object"||Array.isArray(e)?r():s(e,0)}function Rl(e,t,o=!1){let n=e,i=()=>{throw new Error("OPENXIANGDA_DATA_COMMAND_RESPONSE_INVALID")};if(!n||typeof n!="object"||n.schemaVersion!==Us)return i();for(let a of["appCode","environmentKey","operationCode","idempotencyKey","intentDigest"])if(n[a]!==t[a])return i();if(typeof n.observedAt!="string"||!Number.isFinite(Date.parse(n.observedAt)))return i();if(n.outcome==="not_observed"&&n.receipt===null&&!o)return n;if(n.outcome!=="committed"||!n.receipt)return i();let r=n.receipt,d=a=>typeof a=="string"&&/^[a-f0-9]{8}(-[a-f0-9]{4}){3}-[a-f0-9]{12}$/i.test(a);if(!d(r.id)||!d(r.appVersionId)||!Number.isSafeInteger(r.environmentHeadRevision)||r.environmentHeadRevision<1||typeof r.completedAt!="string"||!Number.isFinite(Date.parse(r.completedAt)))return i();let s=r.transaction;if(!s||s.schemaVersion!=="openxiangda.data-transaction-result/v2"||s.idempotencyKey!==t.idempotencyKey||typeof s.replayed!="boolean"||!Array.isArray(s.items)||!s.items.length||s.items.length>1e3)return i();for(let[a,c]of s.items.entries()){if(!c||c.index!==a)return i();if(c.operation==="emitEvent"){if(!d(c.eventId)||typeof c.eventType!="string"||!c.eventType)return i()}else if(!["create","update","delete","increment"].includes(c.operation)||!d(c.id)||typeof c.resourceCode!="string"||!c.resourceCode||!Number.isSafeInteger(c.revision)||c.revision<1)return i()}return n}var Ms=/^[a-z][a-z0-9]*(?:[-_.][a-z0-9]+)*$/,Yn=e=>!!e&&typeof e=="object"&&!Array.isArray(e),Yt=(e,t)=>typeof e=="string"&&e.length<=t&&e.trim().length>0&&e===e.trim(),Si=(e,t,o=[])=>t.every(n=>Object.hasOwn(e,n))&&Object.keys(e).every(n=>[...t,...o].includes(n));function Cl(e){if(!Yn(e)||!Si(e,["kind","errorCode","anyOf"],["allowAppSuperAdmin"])||e.kind!=="actor-authority"||!Yt(e.errorCode,110)||!/^OPENXIANGDA_[A-Z0-9_]{1,96}$/.test(e.errorCode)||Object.hasOwn(e,"allowAppSuperAdmin")&&typeof e.allowAppSuperAdmin!="boolean"||!Array.isArray(e.anyOf)||e.anyOf.length<1||e.anyOf.length>20)return!1;let t=new Set;return e.anyOf.every(o=>{if(!Yn(o)||!Si(o,["roleCode"],["scope"])||!Yt(o.roleCode,100)||!Ms.test(o.roleCode))return!1;if(Object.hasOwn(o,"scope")){let r=o.scope;if(!Yn(r)||!Si(r,["dimensionCode","value","operation"])||!Yt(r.dimensionCode,100)||!Ms.test(r.dimensionCode)||!Yt(r.value,255)||!Yt(r.operation,64)||!/^[A-Za-z0-9*][A-Za-z0-9*._:-]*$/.test(r.operation))return!1}let n=o.scope,i=JSON.stringify([o.roleCode,n?.dimensionCode,n?.value,n?.operation]);return t.has(i)?!1:(t.add(i),!0)})}function hl(e,t,o){if(t.roleSource!=="package"||t.roleCode!==e.roleCode||!o||!t.capabilityCodes.includes(o))return!1;if(!e.scope)return!0;let n;try{n=JSON.parse(t.scopeGrantsJson)}catch{return!1}if(!Array.isArray(n))return!1;let i=e.scope;return n.some(r=>Yn(r)&&r.dimensionCode===i.dimensionCode&&Array.isArray(r.values)&&r.values.includes(i.value)&&(r.operations===void 0||r.operations===null||Array.isArray(r.operations)&&(!r.operations.length||r.operations.includes("*")||r.operations.includes(i.operation))))}var Tp=500,wl=/^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i,Di=e=>!!e&&typeof e=="object"&&!Array.isArray(e);function Sl(e){if(!Di(e)||e.kind!=="record-set-match"||Object.keys(e).some(o=>!["kind","resourceCode","errorCode","records","where"].includes(o))||typeof e.resourceCode!="string"||e.resourceCode.length>64||!/^[a-z][a-z0-9]*(?:[-_.][a-z0-9]+)*$/.test(e.resourceCode)||typeof e.errorCode!="string"||!/^OPENXIANGDA_[A-Z0-9_]{1,96}$/.test(e.errorCode)||!Array.isArray(e.records)||!e.records.length||e.records.length>500||Object.hasOwn(e,"where")&&!Di(e.where))return!1;let t=new Set;return e.records.every(o=>{if(!Di(o)||Object.keys(o).length!==2||typeof o.id!="string"||!wl.test(o.id)||!Number.isSafeInteger(o.expectedRevision)||Number(o.expectedRevision)<1)return!1;let n=o.id.toLowerCase();return t.has(n)?!1:(t.add(n),!0)})}function Bs(e,t){if(t===void 0)return e;let o=e.views?.find(d=>d.code===t);if(!o)throw new Error(`DATA_RESOURCE_VIEW_NOT_FOUND: ${t}`);let n=new Map(o.sections?.flatMap(d=>d.fields.map(s=>[s,d.title]))),{views:i,...r}=e;return{...r,generated:o.generated,list:o.list,form:o.form,detail:o.detail,mobile:o.mobile,fields:Object.fromEntries(Object.entries(e.fields).map(([d,s])=>{let{section:a,...c}=s,f=n.get(d);return[d,{...c,...f?{section:f}:{},list:o.list.fieldOrder?.includes(d)??!1}]}))}}var Ks="openxiangda.development-configuration/v1",ki="openxiangda.development-configuration-manifest/v1",Dl="application.development-configuration",kl="/openxiangda-api/v2/applications/{appCode}/dev-sessions/configuration",Xn=class extends Error{constructor(o,n){super(o);this.code=o;this.pointer=n;this.data={pointer:n}}code;pointer;status=400;data};function je(e){throw new Xn("OPENXIANGDA_CONNECTED_DEV_CONFIGURATION_INVALID",e)}function Gs(e){(!e||typeof e!="object"||Array.isArray(e))&&je("/packageManifest");let t=e,o=["schemaVersion","appCode","version","configDigest","contractDigest","source","toolchain","artifacts"];(Object.keys(t).some(i=>!o.includes(i))||t.schemaVersion!==ki||typeof t.appCode!="string"||!/^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/.test(t.appCode)||!/^[a-f0-9]{64}$/.test(t.configDigest)||!/^[a-f0-9]{64}$/.test(t.contractDigest)||t.version!==`development-${t.configDigest}`)&&je("/packageManifest"),(!t.source||typeof t.source!="object"||Array.isArray(t.source)||Object.keys(t.source).some(i=>!["repository","commit","dirty"].includes(i))||![null,"string"].includes(t.source.repository===null?null:typeof t.source.repository)||t.source.repository!==null&&(t.source.repository.length>1024||/[\r\n\0]/.test(t.source.repository))||t.source.commit!==null&&(typeof t.source.commit!="string"||!/^(?:[a-f0-9]{40}|[a-f0-9]{64})$/.test(t.source.commit))||typeof t.source.dirty!="boolean")&&je("/packageManifest/source"),(!t.toolchain||Object.keys(t.toolchain).some(i=>!["version","contractVersion"].includes(i))||typeof t.toolchain.version!="string"||!/^[A-Za-z0-9][A-Za-z0-9.+_-]{0,127}$/.test(t.toolchain.version)||t.toolchain.contractVersion!==pi)&&je("/packageManifest/toolchain");let n=[{kind:"config",digest:t.configDigest,mediaType:"application/json"},{kind:"contracts",digest:t.contractDigest,mediaType:"application/json"}];return Q(t.artifacts)!==Q(n)&&je("/packageManifest/artifacts"),t}function $l(e,t){return Gs({schemaVersion:ki,appCode:e,version:`development-${t.configDigest}`,configDigest:t.configDigest,contractDigest:t.contractDigest,source:{...t.source},toolchain:{version:t.toolchainVersion,contractVersion:pi},artifacts:[{kind:"config",digest:t.configDigest,mediaType:"application/json"},{kind:"contracts",digest:t.contractDigest,mediaType:"application/json"}]})}function vl(e,t){return(!Number.isSafeInteger(t)||t<1)&&je("/expectedHeadRevision"),`development:${Z({manifest:e,expectedHeadRevision:t})}`}function Pl(e,t,o){(!e||typeof e!="object"||Array.isArray(e))&&je("/result");let n=e,i=["schemaVersion","appCode","environmentKey","environmentId","appVersionId","configurationRunId","headRevision","configDigest","contractDigest","reused","runtimeArtifactsDeployed","backendEventsAvailable"],r=/^[a-f0-9]{8}-[a-f0-9]{4}-[1-5][a-f0-9]{3}-[89ab][a-f0-9]{3}-[a-f0-9]{12}$/i;return(Object.keys(n).some(d=>!i.includes(d))||n.schemaVersion!==Ks||n.appCode!==t||n.environmentKey!=="preproduction"||n.configDigest!==o.configDigest||n.contractDigest!==o.contractDigest||!r.test(n.environmentId)||!r.test(n.appVersionId)||!r.test(n.configurationRunId)||typeof n.reused!="boolean"||!Number.isSafeInteger(n.headRevision)||n.headRevision<1||!n.reused&&n.headRevision!==o.expectedHeadRevision+1||n.runtimeArtifactsDeployed!==!1||n.backendEventsAvailable!==!1)&&je("/result"),n}var Ll="application.development-backend-events",Vl="openxiangda.development-backend/v1",Fl="application.development-backend-invocations",qs="openxiangda.development-backend-invocation/v1",Dp=262144,kp=1048576,$p=131072,vp=131072,Pp=8,Lp=45,xl=/^\/__platform\/events\/[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/;function jl(e){return(e.backend?.operations?.length||0)>0||(e.workflows?.providers?.length||0)>0||(e.events?.subscriptions||[]).some(t=>t.execution?.kind!=="native-data")}function Wl(e){return`connected-development:${e}`}function zs(e){if(typeof e!="string"||e.length%4!==0||!/^[A-Za-z0-9+/]*={0,2}$/.test(e))return null;let t="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",o=e.endsWith("==")?2:e.endsWith("=")?1:0;return o&&t.indexOf(e[e.length-o-1])%(o===2?16:4)!==0?null:e.length/4*3-o}function Js(e,t,o){if(!["GET","POST","PUT","PATCH","DELETE","HEAD","OPTIONS"].includes(e)||o.method!==e||typeof t!="string"||t.length>2048||!t.startsWith("/")||t.startsWith("//")||t.startsWith("/__platform")||/[\\?#\s\u0000-\u001f\u007f]/.test(t))return!1;let n=t.split("/"),i=String(o.path||"").split("/");return n.length!==i.length?!1:n.every((r,d)=>{if(d===0)return i[d]==="";let s;try{s=decodeURIComponent(r)}catch{return!1}return!s||[".",".."].includes(s)||/[\/\\\s\u0000-\u001f\u007f]/.test(s)?!1:/^:[A-Za-z][A-Za-z0-9_]*$/.test(i[d]||"")||r===i[d]})}var Ul=/^(?:authorization|content-type|content-length|accept|if-match|idempotency-key|x-request-id|x-openxiangda-(?:gateway-assertion|forwarded-by|perspective|csrf-token|mcp-bus-token))$/i,Ml=/^(?:content-type|content-disposition|cache-control|etag|last-modified|retry-after)$/i;function Hs(e,t=!1){if(!e||typeof e!="object"||Array.isArray(e))return!1;let o=Object.entries(e),n=o.map(([i])=>i.toLowerCase());return o.length<=24&&new Set(n).size===n.length&&o.every(([i,r])=>(t?Ml:Ul).test(i)&&typeof r=="string"&&r.length<=8192&&!/[\r\n\u0000]/.test(r))}function Bl(e){let t=zs(e.body);return e.schemaVersion===qs&&!!e.operation&&typeof e.operation.code=="string"&&e.operation.code.length<=128&&e.operation.code.length>0&&Js(e.method,e.endpointPath,e.operation)&&typeof e.canonicalQuery=="string"&&e.canonicalQuery.length<=8192&&!/[\s#\u0000-\u001f\u007f]/.test(e.canonicalQuery)&&t!==null&&t<=262144&&Hs(e.headers)&&Object.entries(e.headers).some(([o,n])=>o.toLowerCase()==="authorization"&&/^Bearer \S+$/.test(n))&&Object.entries(e.headers).some(([o,n])=>o.toLowerCase()==="x-openxiangda-gateway-assertion"&&!!n)}var Kl="f93c57bf0be91792a7b632f690577715185945a1b71139480fb4f3fb05262e9d";0&&(module.exports={AuthenticatedPublicReadContractError,DATA_AUDIT_METADATA_FIELDS,DATA_BUSINESS_COMMAND_INTENT_MAX_BYTES,DATA_BUSINESS_COMMAND_RESOLUTION_SCHEMA,DATA_BUSINESS_COMMAND_SCHEMA,DATA_EVENT_TYPES_V2,DATA_FORM_DRAFT_MAX_BYTES,DATA_SUBTABLE_DEFAULT_TOTAL_ROWS,DATA_SUBTABLE_MAX_ROWS,DATA_SUBTABLE_MAX_TOTAL_ROWS,DATA_SYSTEM_SORT_FIELD_CODES,DATA_TRANSACTION_MAX_BYTES,DATA_TRANSACTION_MAX_OPERATIONS,DATA_TRANSACTION_RECORD_SET_MAX_RECORDS,DATE_EVENT_RESERVED_DATA_FIELDS_V2,DEVELOPMENT_BACKEND_CONNECTION_TTL_SECONDS,DEVELOPMENT_BACKEND_ENDPOINT_PATTERN,DEVELOPMENT_BACKEND_FEATURE,DEVELOPMENT_BACKEND_INVOCATION_FEATURE,DEVELOPMENT_BACKEND_INVOCATION_MAX_REQUEST_BYTES,DEVELOPMENT_BACKEND_INVOCATION_MAX_RESPONSE_BYTES,DEVELOPMENT_BACKEND_INVOCATION_SCHEMA,DEVELOPMENT_BACKEND_MAX_INFLIGHT,DEVELOPMENT_BACKEND_MAX_REQUEST_BYTES,DEVELOPMENT_BACKEND_MAX_RESPONSE_BYTES,DEVELOPMENT_BACKEND_SCHEMA,DEVELOPMENT_CONFIGURATION_ENDPOINT,DEVELOPMENT_CONFIGURATION_FEATURE,DEVELOPMENT_CONFIGURATION_MANIFEST_SCHEMA,DEVELOPMENT_CONFIGURATION_SCHEMA,DateEventProjectionV2Error,DevelopmentConfigurationContractError,ManagedConcurrencyContractError,NATIVE_ARTIFACT_CAPACITY_V2,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,USER_CANDIDATE_MAX_SELECTIONS,USER_CANDIDATE_SCOPE_FIELD_TYPES,UserCandidateContractError,WORKFLOW_APPROVAL_EMPTY_PROVIDERS,WORKFLOW_APPROVED_DELEGATION_MAX_BYTES,WORKFLOW_APPROVED_DELEGATION_MAX_REQUESTS,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_LAUNCH_PREFLIGHT_PROVIDERS,WORKFLOW_REJECTION_NOTIFICATION_MAX_BYTES,WORKFLOW_REJECTION_NOTIFICATION_SCHEMA,WORKFLOW_ROLE_UNION_MAX_ROLES,WORKFLOW_ROUTING_MAX_BYTES,WORKFLOW_ROUTING_MAX_MATCHED_RULES,WORKFLOW_ROUTING_MAX_RULES,WORKFLOW_STEP_DATA_COMMAND_SCHEMA,WORKFLOW_STEP_DATA_RESOLUTION_SCHEMA,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,assertDevelopmentConfigurationManifest,assertDevelopmentConfigurationResult,assertNativeRoleMembershipBatchInput,assertWorkflowNativeStageGuard,assertWorkflowNativeStagePolicy,assertWorkflowNativeStageSourceGuard,assertWorkflowOwnedSubjectCreate,assertWorkflowOwnedSubjectCreateResources,canonicalDataBusinessIntent,compileNativeApplicationConfiguration,compileNativeEventAction,compileNativeEventCapturePlansV2,compileRequiredPlatformCapabilitiesV3,compileWorkflowBusinessStepHandlers,createDevelopmentConfigurationManifest,dataOwnedRowLimit,dateEventProjectionEnvelopeSchemaV2,dateEventProjectionFieldsV2,developmentBackendBase64Bytes,developmentBackendInvocationHeadersValid,developmentBackendInvocationRequestValid,developmentBackendInvocationRevision,developmentBackendOperationMatches,developmentConfigurationKey,evaluateWorkflowTaskPageExpression,formatWorkflowCompletionDeadline,formatWorkflowExpression,generatedCrudCapabilityOperations,hasDataAuditReadPolicy,isDataAuditMetadataField,isDataOwnedRowLimit,isDataSystemSortField,isDataTransactionActorAuthorityGuard,isDataTransactionRecordSetMatchGuard,isNativeDataQueryOperatorV2,isNativeMultiValueFieldV2,isWorkflowRejectionNotificationSnapshot,matchesDataActorAuthorityMembership,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,nativeUniqueKeysContractVersion,nativeUniqueKeysJsonSchema,normalizeWorkflowOwnedSubjectCreate,parseDataBusinessCommandResolution,parseDataFieldUserCandidates,parseDecimalReservationLifecycle,parseNativeDataFieldsV2,parseNativeDataResourceInvariantsV2,parseNativeUniqueKeys,parseWorkflowStepDataResolution,projectDataResourceView,projectNativeDataResourceViewV2,projectWorkflowGraph,projectWorkflowNodePolicy,quoteNativeIdentifierV2,refreshWorkflowTaskPageFacts,requiresAggregateOwnedSubtableCapacity,requiresDateTimeMinutePrecision,requiresDevelopmentBackendCredential,requiresExtendedArtifactCapacity,requiresExtendedDeclarationCapacity,requiresExtendedOwnedSubtableCapacity,requiresOwnedSubtableMinimumRows,requiresUserCandidateLaunchScope,requiresWorkflowRoleUnion,resolveNativeScopeSourceFieldPathV2,resolveWorkflowUserCandidates,selectWorkflowAssignmentRoutingRules,serializedDataBytes,userCandidateScopeValue,validateAuthenticatedPublicRead,validateDecimalReservationLifecycles,validateManagedConcurrency,validateNativeDataDraftStateV2,validateNativeDataResourceReferencesV2,validateNativeDataResourceSurfaceV2,validateUserCandidateReferences,validateWorkflowAdministration,validateWorkflowApprovalEmptyPolicy,validateWorkflowApprovedDelegation,validateWorkflowAssignmentRoutingBindings,validateWorkflowAssignmentRoutingPolicy,validateWorkflowAssignmentRoutingRules,validateWorkflowAutomaticCc,validateWorkflowBusinessStepHandlerContract,validateWorkflowBusinessStepRequest,validateWorkflowBusinessStepResult,validateWorkflowBusinessStepSchema,validateWorkflowBusinessStepSubscriptions,validateWorkflowBusinessSteps,validateWorkflowCommandHandlers,validateWorkflowCompletionDeadlines,validateWorkflowCorrections,validateWorkflowInitiatorApprovalPolicy,validateWorkflowInstanceCommandPolicies,validateWorkflowLaunchPreflight,validateWorkflowNodeConfigurationPatch,validateWorkflowReadability,validateWorkflowRejectionNotification,validateWorkflowRoleUnion,validateWorkflowTaskPages,validateWorkflowUserCandidateBindings,workflowApprovalCanSkip,workflowApprovedDelegationRequests,workflowAssignmentRoutingFacts,workflowAssignmentRoutingPolicySchema,workflowAssignmentRoutingSemantic,workflowBindingAllowsEmptyUsers,workflowBindingRoleCodes,workflowBusinessCommandInvocationSchema,workflowBusinessStepFactSchema,workflowBusinessStepHandlerDigest,workflowBusinessStepInput,workflowBusinessStepPath,workflowBusinessStepReceiptSignatureSuffix,workflowBusinessStepValueMatches,workflowDelegationMutationRequestSchema,workflowExpressionPaths,workflowInitiatorApprovalCanComplete,workflowInstanceCommandDeadlineError,workflowInstanceTerminateCapabilityAllowed,workflowInstanceWithdrawalReasonRequired,workflowNativeStagePolicySchema,workflowNodeAllowedOperations,workflowOperationCommentRequired,workflowOperationReasonRequired,workflowOwnedSubjectCreateSchema,workflowPolicyTimestamp,workflowRoleCodesSchema,workflowTaskPageFieldState,workflowTaskPageReplayCoversInvalidation,workflowTaskSubtableRows});
8
+ END $native_subtable$`]}function ke(e,...t){return`${e}_${(0,rr.createHash)("sha256").update(t.join(":")).digest("hex").slice(0,32)}`}function se(e){if(!/^[A-Za-z_][A-Za-z0-9_]{0,62}$/.test(e))throw new Error("OPENXIANGDA_NATIVE_IDENTIFIER_INVALID");return`"${e}"`}function Qa(e,t){return e.type==="subtable"?"none":t?"gin-trigram":e.indexed?["date-range","datetime-range"].includes(e.type)?"gist-range":ho.has(e.type)?"btree-snapshot-expressions":Wa.has(e.type)?"gin-jsonb-path":"btree":"none"}function ed(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 Ma.has(e.type),"jsonb"}}function dr(e,t){if(Nt(t.type)&&t.type!=="subtable")return"'[]'::jsonb";if(t.type!=="serial-number")return"";let o=ir(t.serial?.prefix||""),n=t.serial?.digits??6;return`(${o} || lpad(nextval(${ir(In(e,t.code))})::text, ${n}, '0'))`}function td(e,t){return sr.has(t.type)?` CHECK (${e} IS NULL OR jsonb_typeof(${e}) = 'array')`:Ua.has(t.type)?` CHECK (${e} IS NULL OR jsonb_typeof(${e}) = 'object')`:""}function En(e){return`"app_data".${se(e)}`}function In(e,t){let o=ke("seq",e,t);return`"app_data".${se(o)}`}function ir(e){return`'${e.replace(/'/g,"''")}'`}var cr=new Set(["option.single","option.multiple","user.single","user.multiple","department.single","department.multiple","resource-ref.single","resource-ref.multiple"]),nd=new Set([...cr,"cascade.single","cascade.multiple","file","image","signature","address","location","json"]),lr=/^[A-Za-z][A-Za-z0-9_]{0,62}$/,od=new Set(["__proto__","prototype","constructor"]),yn=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 at(e,t){let o=ur(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 bn(e){return!!(e&&e.field.type==="user.single"&&e.valuePath==="value")}function wo(e,t,o){if(!e||!t||!rd(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 id(e,t){let o=ur(t);if(!o)throw new yn(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 rd(e){let{field:t,valuePath:o}=e;if(!o)return!nd.has(t.type);if(o==="value")return cr.has(t.type);if(!o.startsWith("snapshot."))return!1;let n=o.slice(9);return lr.test(n)&&t.type.startsWith("resource-ref.")&&!!t.source?.snapshotFields?.includes(n)}function ur(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=>!lr.test(o)||od.has(o))||t.length===2&&t[1]!=="value"||t.length===3&&t[1]!=="snapshot"?null:t}var sd=new Set(["option.single","user.single","department.single","resource-ref.single"]),ad=new Set(["text.short","text.long","text.rich","number.integer","number.decimal","boolean","date","time","datetime","uuid","serial-number"]),dd=new Set(["value","label","description","color"]),cd=new Set(["avatarUrl","employeeNo","title","mobile","email"]),ld=new Set(["fullPath","parent.value","parent.label"]),ud=new Set(["country.value","country.label","province.value","province.label","city.value","city.label","district.value","district.label","street.value","street.label","detail","fullAddress"]),fd=new Set(["longitude","latitude","accuracy"]),pd=new Set(["address","name","province","city","district","source"]);function md(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=gd(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 _d(e,t){if(sd.has(e.type)&&dd.has(t)||e.type==="user.single"&&cd.has(t)||e.type==="department.single"&&ld.has(t))return ht(t);if(e.type==="resource-ref.single"){let o=e.queryPathTypes?.[t];return o?{parts:t.split("."),type:o}:null}if(e.type==="address"&&ud.has(t))return ht(t);if(e.type==="location"){if(fd.has(t))return{parts:[t],type:"number.decimal"};if(pd.has(t))return ht(t);if(t==="capturedAt")return{parts:[t],type:"datetime"}}return null}function gd(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}`,ad.has(i.type)?i.type:"json"]]:[]})):{}}function ht(e){return{parts:e.split("."),type:"text.short"}}var mr=e=>!!e&&typeof e=="object"&&!Array.isArray(e),_r=(e,t)=>Object.keys(e).length===t.length&&Object.keys(e).every(o=>t.includes(o)),fr=e=>typeof e=="string"&&/^[a-z][a-z0-9]*(?:[-_.][a-z0-9]+)*$/.test(e)&&e.length<=100,pr=e=>typeof e=="string"&&/^[a-f0-9]{8}(-[a-f0-9]{4}){3}-[a-f0-9]{12}$/i.test(e);function So(e){throw new Error(`OPENXIANGDA_WORKFLOW_STAGE_${e}`)}function Do(e){(!mr(e)||!_r(e,["workflowCode","resourceCode","actor","runningNodeIds","allowedStatuses"])||!fr(e.workflowCode)||!fr(e.resourceCode)||!["initiator","reader"].includes(String(e.actor))||!Array.isArray(e.runningNodeIds)||e.runningNodeIds.length>32||new Set(e.runningNodeIds).size!==e.runningNodeIds.length||e.runningNodeIds.some(t=>typeof t!="string"||!/^[A-Za-z0-9][A-Za-z0-9._-]{0,127}$/.test(t))||!Array.isArray(e.allowedStatuses)||e.allowedStatuses.length>5||new Set(e.allowedStatuses).size!==e.allowedStatuses.length||e.allowedStatuses.some(t=>!["approved","rejected","cancelled","terminated","returned"].includes(t))||e.runningNodeIds.length+e.allowedStatuses.length===0)&&So("POLICY_INVALID")}function Ad(e){(!mr(e)||!_r(e,["instanceId","subjectRecordId","expectedInstanceSequence"])||!pr(e.instanceId)||!pr(e.subjectRecordId)||!Number.isSafeInteger(e.expectedInstanceSequence)||e.expectedInstanceSequence<0)&&So("GUARD_INVALID")}function Ed(e,t,o){o?.some(n=>(n.kind==="record-match"||n.kind==="record-assert")&&n.resourceCode===e.resourceCode&&n.id.toLowerCase()===t.subjectRecordId.toLowerCase()&&n.assertions.some(i=>i.kind==="value"&&i.field==="revision"&&i.operator==="eq"&&Number.isSafeInteger(i.value)&&Number(i.value)>0))||So("SOURCE_GUARD_REQUIRED")}var Id={type:"object",additionalProperties:!1,required:["workflowCode","resourceCode","actor","runningNodeIds","allowedStatuses"],properties:{workflowCode:{type:"string",pattern:"^[a-z][a-z0-9]*(?:[-_.][a-z0-9]+)*$",maxLength:100},resourceCode:{type:"string",pattern:"^[a-z][a-z0-9]*(?:[-_.][a-z0-9]+)*$",maxLength:100},actor:{enum:["initiator","reader"]},runningNodeIds:{type:"array",maxItems:32,uniqueItems:!0,items:{type:"string",pattern:"^[A-Za-z0-9][A-Za-z0-9._-]{0,127}$"}},allowedStatuses:{type:"array",maxItems:5,uniqueItems:!0,items:{enum:["approved","rejected","cancelled","terminated","returned"]}}},anyOf:[{properties:{runningNodeIds:{minItems:1}}},{properties:{allowedStatuses:{minItems:1}}}]};var dt=class extends Error{constructor(o,n){super(o);this.code=o;this.pointer=n}code;pointer},ue=e=>e&&typeof e=="object"&&!Array.isArray(e)?e:{},gr=(e,t)=>e===t||e==="*"||e.endsWith(":*")&&t.startsWith(e.slice(0,-1));function ko(e){let{policy:t,resource:o,baselineRoleCode:n,baselineCapabilities:i,pointer:r}=e,d=A=>A===void 0||A===!0||Array.isArray(A)&&A.length>0&&A.every(O=>typeof O=="string"&&O.length>0&&!e.baselineDeniedCapabilities?.some(b=>gr(b,O))&&i.some(b=>gr(b,O))),s=(A,O="")=>{throw new dt(A,`${r}/publicRead${O}`)},a=ue(t.publicRead);(!t.publicRead||Object.keys(a).length!==1||!Object.hasOwn(a,"fields")||!Array.isArray(a.fields)||a.fields.length<1||a.fields.length>1e3||a.fields.some(A=>typeof A!="string"||!/^[A-Za-z][A-Za-z0-9_]{0,62}$/.test(A))||new Set(a.fields).size!==a.fields.length)&&s("AUTHENTICATED_PUBLIC_READ_FIELDS_INVALID","/fields"),(!Array.isArray(t.operations)||t.operations.length!==1||t.operations[0]!=="read"||t.readExpression!==void 0||t.writeBoundary!==void 0)&&s("AUTHENTICATED_PUBLIC_READ_POLICY_NOT_READ_ONLY"),(!n||!o||o.code!==t.resourceCode||o.dataPolicyCode!==t.code||!d([ue(o.capabilities).read]))&&s("AUTHENTICATED_PUBLIC_READ_BASELINE_OR_RESOURCE_INVALID");let c=ue(o),f=ue(c.schema).fields;(!Array.isArray(f)||!f.length)&&s("AUTHENTICATED_PUBLIC_READ_RESOURCE_FIELDS_MISSING");let u=new Map(f.map(A=>[String(ue(A).code),ue(A)])),p=new Set(a.fields),_=ue(c.fieldPolicies);for(let A of p){let O=ue(u.get(A));(!u.has(A)||O.system===!0||ue(ue(c.surface).fields)[A]?.system===!0||Ot.has(A))&&s("AUTHENTICATED_PUBLIC_READ_FIELD_NOT_DECLARED",`/fields/${A}`),(O.type==="subtable"||O.subtable!==void 0)&&s("AUTHENTICATED_PUBLIC_READ_SUBTABLE_UNSUPPORTED",`/fields/${A}`),d(ue(_[A]).read)||s("AUTHENTICATED_PUBLIC_READ_FIELD_NOT_BASELINE_READABLE",`/fields/${A}`)}let E=[...u.keys()].filter(A=>!p.has(A));for(let A of E)d(ue(_[A]).read)&&s("AUTHENTICATED_PUBLIC_READ_PRIVATE_FIELD_ACCESSIBLE",`/fields/${A}`);E.length&&Rt.some(A=>d(ue(_[A]).read))&&s("AUTHENTICATED_PUBLIC_READ_PRIVATE_HISTORY_ACCESSIBLE")}var vo=["exact-v1","nfkc-space-v1","nfkc-upper-ascii-v1"],vu=256,ct=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"},$o=e=>!!(e&&typeof e=="object"&&!Array.isArray(e)),oe=(e,t)=>{throw new ct(e,t)},On=(e,t)=>e<t?-1:e>t?1:0,wt=(e,t,o)=>{Object.keys(e).some(n=>!t.includes(n))&&oe(o,"\u4E0D\u652F\u6301\u672A\u77E5\u5C5E\u6027")};function Po(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,d)=>{let s=`${o}/${d}`;if(!$o(r))return oe(s,"\u89C4\u5219\u5FC5\u987B\u662F\u5BF9\u8C61");if(wt(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 a=new Set,c=r.fields.map((_,E)=>{let A=`${s}/fields/${E}`;if(!$o(_))return oe(A,"\u5B57\u6BB5\u5FC5\u987B\u662F\u5BF9\u8C61");wt(_,["fieldCode","normalizer"],A);let O=n.get(_.fieldCode);if(!O||!["text.short","uuid","option.single","resource-ref.single","user.single"].includes(O.type)||a.has(_.fieldCode))return oe(`${A}/fieldCode`,"\u9700\u8981\u4E0D\u91CD\u590D\u7684\u77ED\u6587\u672C\u3001UUID\u3001\u5355\u9009\u3001\u5355\u8BB0\u5F55\u5F15\u7528\u6216\u5355\u4EBA\u5B57\u6BB5");a.add(_.fieldCode);let b=_.normalizer===void 0?"exact-v1":_.normalizer;return!vo.includes(b)||O.type!=="text.short"&&b!=="exact-v1"?oe(`${A}/normalizer`,"\u5F52\u4E00\u5316\u65B9\u5F0F\u4E0D\u652F\u6301\u6216\u4E0E\u5B57\u6BB5\u7C7B\u578B\u4E0D\u7B26"):{fieldCode:O.code,normalizer:b}}).sort((_,E)=>On(_.fieldCode,E.fieldCode)),f=r.when===void 0?[]:r.when;if(!Array.isArray(f)||f.length>4)return oe(`${s}/when`,"\u6700\u591A 4 \u4E2A\u5408\u53D6\u6761\u4EF6");let u=new Set,p=f.map((_,E)=>{let A=`${s}/when/${E}`;if(!$o(_))return oe(A,"\u6761\u4EF6\u5FC5\u987B\u662F\u5BF9\u8C61");let O=n.get(_.fieldCode);if(!O)return oe(`${A}/fieldCode`,"\u5B57\u6BB5\u4E0D\u5B58\u5728");let b;if(_.operator==="empty"||_.operator==="nonempty"){if(wt(_,["fieldCode","operator"],A),O.type!=="text.short")return oe(A,"\u7A7A\u503C\u6761\u4EF6\u4EC5\u652F\u6301\u77ED\u6587\u672C");b={fieldCode:O.code,operator:_.operator}}else if(_.operator==="in"||_.operator==="notIn"){wt(_,["fieldCode","operator","values"],A);let I=new Set((O.options??[]).map(T=>T.value));if(O.type!=="option.single"||!Array.isArray(_.values)||_.values.length<1||_.values.length>16||_.values.some(T=>typeof T!="string"||T.length<1||T.length>128||!I.has(T))||new Set(_.values).size!==_.values.length)return oe(A,"\u96C6\u5408\u6761\u4EF6\u9700\u8981 1 \u5230 16 \u4E2A\u4E0D\u91CD\u590D\u7684\u5DF2\u58F0\u660E\u5355\u9009\u503C");b={fieldCode:O.code,operator:_.operator,values:[..._.values].sort(On)}}else if(_.operator==="eq"||_.operator==="ne"){if(wt(_,["fieldCode","operator","value"],A),O.type!=="boolean"||typeof _.value!="boolean")return oe(A,"\u7B49\u503C\u6761\u4EF6\u4EC5\u652F\u6301\u5E03\u5C14\u5B57\u6BB5\u548C\u5E03\u5C14\u503C");b={fieldCode:O.code,operator:_.operator,value:_.value}}else return oe(`${A}/operator`,"\u53EA\u652F\u6301 empty\u3001nonempty\u3001in\u3001notIn \u548C\u5E03\u5C14 eq\u3001ne");let g=JSON.stringify(b);return u.has(g)?oe(A,"\u6761\u4EF6\u4E0D\u80FD\u91CD\u590D"):(u.add(g),b)}).sort((_,E)=>On(JSON.stringify(_),JSON.stringify(E)));return{code:r.code,fields:c,when:p}}).sort((r,d)=>On(r.code,d.code))}function Lo(e,t){let o=new Set(e.filter(n=>n.type==="user.single").map(n=>n.code));return t?.some(n=>n.fields.some(i=>o.has(i.fieldCode))||n.when?.some(i=>i.operator==="eq"||i.operator==="ne"))?"1.1.0":"1.0.0"}var Nn={type:"string",pattern:"^[A-Za-z_][A-Za-z0-9_]{0,62}$"},yd={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:Nn,normalizer:{enum:[...vo]}}}},when:{type:"array",maxItems:4,uniqueItems:!0,items:{oneOf:[{type:"object",additionalProperties:!1,required:["fieldCode","operator"],properties:{fieldCode:Nn,operator:{enum:["empty","nonempty"]}}},{type:"object",additionalProperties:!1,required:["fieldCode","operator","values"],properties:{fieldCode:Nn,operator:{enum:["in","notIn"]},values:{type:"array",minItems:1,maxItems:16,uniqueItems:!0,items:{type:"string",minLength:1,maxLength:128}}}},{type:"object",additionalProperties:!1,required:["fieldCode","operator","value"],properties:{fieldCode:Nn,operator:{enum:["eq","ne"]},value:{type:"boolean"}}}]}}}}};var Ar={"openxiangda.workflow.instance.completed.v2":"commit","openxiangda.workflow.instance.rejected.v2":"release","openxiangda.workflow.instance.withdrawn.v2":"release"};function Er(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),d=t.reservations.find(p=>p.mode==="reserve"&&p.resourceCode===i.resourceCode),s=t.workflows.find(p=>p.code===i.workflowCode);if(!r||!d||!s||s.resourceCode!==r.code)return o();let a=r.fields.find(p=>p.code===d.statusFieldCode);if(a?.type!=="option.single")return o();let c=new Set(a.options?.map(p=>p.value)),f=new Set,u=i.outcomes.map(p=>{let _=n(p),E=_.eventType;return Object.keys(_).some(A=>!["eventType","mode","eligibleChildStatuses"].includes(A))||typeof E!="string"||!Object.prototype.hasOwnProperty.call(Ar,E)||!t.eventTypes.includes(E)||f.has(E)||_.mode!==Ar[E]||!Array.isArray(_.eligibleChildStatuses)||!_.eligibleChildStatuses.length||_.eligibleChildStatuses.length>16||new Set(_.eligibleChildStatuses).size!==_.eligibleChildStatuses.length||_.eligibleChildStatuses.some(A=>typeof A!="string"||!/^[A-Za-z0-9._:-]{1,128}$/.test(A)||!c.has(A))?o():(f.add(E),{eventType:E,mode:_.mode,eligibleChildStatuses:[..._.eligibleChildStatuses].sort()})}).sort((p,_)=>p.eventType.localeCompare(_.eventType));return{resourceCode:i.resourceCode,workflowCode:i.workflowCode,outcomes:u}}function Ir(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 Tn=class extends Error{constructor(o,n){super(n);this.pointer=o}pointer;code="NATIVE_EVENT_ACTION_INVALID"};function Vo(e,t,o="/events/subscriptions"){if(e.execution===void 0)return;let n=(A,O)=>{throw new Tn(`${o}${A}`,O)},i=(A,O,b)=>((!A||typeof A!="object"||Array.isArray(A)||Object.keys(A).some(g=>!b.includes(g)))&&n(O,"Invalid action object or unsupported property"),A),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(A=>!/^openxiangda\.data\.record\.(created|updated|deleted)\.v2$/.test(A)))&&n("/eventTypes","Native data actions require declared data events");let d=e.filter?.resourceCodes;(!Array.isArray(d)||!d.length||d.length>20)&&n("/filter/resourceCodes","Native actions require explicit source resources");let s=new Map(t.map(A=>[A.code,A])),a=d.map(A=>{let O=s.get(A);return O||n("/filter/resourceCodes","Unknown source resource"),new Set((O.schema?.fields||[]).map(b=>b.code))}),c=new Set(e.payload?.fields||[]),f=e.payload?.includeChanges===!0,u=(A,O)=>{let b=i(A,O,["source","path","value"]);if(b.source==="literal"){(!Object.hasOwn(b,"value")||Object.hasOwn(b,"path"))&&n(O,"Literal binding requires only value");let l;try{l=JSON.stringify(b.value)}catch{n(O,"Literal must be JSON")}return(l===void 0||Buffer.byteLength(l)>65536)&&n(O,"Literal is too large or not JSON"),{source:"literal",value:JSON.parse(l)}}(b.source!=="event"||typeof b.path!="string"||Object.hasOwn(b,"value"))&&n(O,"Expected a literal or event binding");let g=b.path.split(".");(g.length>8||g.some(l=>!/^[A-Za-z0-9_-]+$/.test(l)||["__proto__","prototype","constructor"].includes(l)))&&n(O,"Invalid event path");let I=/^data\.projection\.([A-Za-z][A-Za-z0-9_]{0,62})$/.exec(b.path),T=/^data\.changes\.([A-Za-z][A-Za-z0-9_]{0,62})\.(before|after)$/.exec(b.path);if(I||T){let l=(I||T)[1];a.some(y=>!y.has(l))&&n(O,"Source field must exist on every filtered resource"),c.add(l),T&&(f=!0)}else["id","time","type","subject","data.recordId","data.revision","data.operation","data.resourceCode"].includes(b.path)||n(O,"Event path is not part of the data event contract");return{source:"event",path:b.path}};(!Array.isArray(r.operations)||r.operations.length<1||r.operations.length>16)&&n("/execution/operations","Expected 1 to 16 operations");let p={},_=r.operations.map((A,O)=>{let b=`/execution/operations/${O}`,g=i(A,b,["operation","resourceCode","data","id","expectedRevision"]);["create","update","delete"].includes(g.operation)||n(b,"Unsupported Native operation");let I=s.get(g.resourceCode);I||n(b,"Unknown action target resource");let T=new Map((I.schema?.fields||[]).map(y=>[y.code,y])),l=g.data===void 0?{}:i(g.data,`${b}/data`,[...T.keys()]);return Object.keys(l).length>32&&n(b,"Maximum 32 mapped fields per operation"),g.operation==="create"&&(g.id!==void 0||g.expectedRevision!==void 0)&&n(b,"Create does not accept id or expectedRevision"),g.operation==="delete"&&g.data!==void 0&&n(b,"Delete does not accept data"),Object.keys(l).some(y=>T.get(y)?.type==="serial-number")&&n(b,"Generated fields cannot be assigned"),p[g.resourceCode]=Z(I),{operation:g.operation,resourceCode:g.resourceCode,...g.operation==="create"?{}:{id:u(g.id,`${b}/id`),expectedRevision:u(g.expectedRevision,`${b}/expectedRevision`)},...g.operation==="delete"?{}:{data:Object.fromEntries(Object.entries(l).map(([y,R])=>[y,u(R,`${b}/data/${y}`)]))}}});(c.size>32||[...c].some(A=>a.some(O=>!O.has(A))))&&n("/payload/fields","Payload must contain at most 32 declared source fields");let E={kind:"native-data",version:1,operations:_,resourceDigests:p};return Buffer.byteLength(JSON.stringify(E))>65536&&n("/execution","Action plan exceeds 64 KiB"),{execution:{...E,digest:Z(E)},payload:{includeChanges:f,fields:[...c].sort()}}}function Ve(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)?e:void 0}function xo(e,t){if(e?.instanceCommands===void 0)return[];let o=Ve(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 d=Ve(r),s=i==="withdraw"?["beforeFact","reasonRequired"]:["beforeFact","capability"];if(!d||!Object.keys(d).length||Object.keys(d).some(a=>!s.includes(a))||Object.hasOwn(d,"reasonRequired")&&typeof d.reasonRequired!="boolean"){n.push(`WORKFLOW_INSTANCE_COMMAND_POLICY_INVALID:${i}`);continue}if(i==="terminate"){let a=d.capability;(typeof a!="string"||a.length>255||!/^app:[a-z][a-z0-9]*(?:-[a-z0-9]+)*:[A-Za-z0-9:._-]+$/.test(a)||t&&(!a.startsWith(`app:${t.appCode}:`)||!t.capabilities.includes(a)))&&n.push("WORKFLOW_INSTANCE_TERMINATE_CAPABILITY_INVALID")}if(Object.hasOwn(d,"beforeFact")){let a=d.beforeFact,c=Ve(e.inputSchema),f=Ve(Ve(c?.properties)?.[a]),u=Ve(Ve(e.subject)?.factProjection)?.[a],p=t?.fields.get(u);(typeof a!="string"||!/^[A-Za-z][A-Za-z0-9_]{0,62}$/.test(a)||!Array.isArray(c?.required)||!c.required.includes(a)||f?.type!=="string"||f?.format!=="date-time"||typeof u!="string"||t&&(p?.type!=="datetime"||p.nullable===!0))&&n.push(`WORKFLOW_INSTANCE_COMMAND_DEADLINE_FACT_INVALID:${i}`)}}return n}function bd(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 Od(e){return e?.withdraw?.reasonRequired!==!1}function Fo(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,d,s]=t,a=t[8],c=new Date(Date.UTC(Number(o),Number(n),0)).getUTCDate();if(Number(n)<1||Number(n)>12||Number(i)<1||Number(i)>c||Number(r)>23||Number(d)>59||Number(s)>59||a!=="Z"&&(Number(a.slice(1,3))>23||Number(a.slice(4))>59))return null;let f=Date.parse(e);return Number.isFinite(f)?f:null}function Nd(e,t,o,n){let i=e?.[t];if(!i||i.beforeFact===void 0)return null;let r=i.beforeFact,d=Ve(o),s=r&&d&&Object.hasOwn(d,r)?Fo(d[r]):null,a=n instanceof Date?n.getTime():Fo(n);return s===null||a===null||!Number.isFinite(a)?"WORKFLOW_V2_CANCELLATION_DEADLINE_INVALID":a<s?null:"WORKFLOW_V2_CANCELLATION_DEADLINE_PASSED"}var lt="openxiangda.workflow.step.requested.v2",Uo=[lt,"openxiangda.workflow.step.result_received.v2","openxiangda.workflow.step.completed.v2","openxiangda.workflow.step.continuation_failed.v2"],Rn=16384,Or=2048,Td="steps",Mo=/^[A-Za-z][A-Za-z0-9_-]{0,127}$/,Nr=/^[A-Za-z][A-Za-z0-9_]{0,62}$/,Ge=new Set(["__proto__","prototype","constructor"]),K=e=>!!e&&typeof e=="object"&&!Array.isArray(e)&&[Object.prototype,null].includes(Object.getPrototypeOf(e)),Tr=e=>{try{let t=JSON.stringify(e);return t===void 0?1/0:new TextEncoder().encode(t).length}catch{return 1/0}},ut=(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((r,d)=>ut(r,t[d],o+1));if(!K(e)||!K(t))return!1;let n=Object.keys(e).filter(r=>e[r]!==void 0),i=Object.keys(t).filter(r=>t[r]!==void 0);return n.length===i.length&&n.every(r=>Object.hasOwn(t,r)&&ut(e[r],t[r],o+1))};function jo(e,t){let o=0,n=(i,r)=>++o>1e4||r>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(d=>n(d,r+1)):K(i)&&Object.keys(i).length<=32&&Object.keys(i).every(d=>!Ge.has(d))&&Object.values(i).every(d=>n(d,r+1));return Tr(e)<=t&&n(e,0)}function Rr(e){return!K(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&&K(e.output)&&jo(e.output,Rn)&&(e.receipt===void 0||K(e.receipt)&&jo(e.receipt,Or))}function Rd(e){return K(e)&&Object.keys(e).every(t=>["executionId","nodeId","handlerCode","handlerVersion","mode","dataTransaction","input","inputDigest","expectedFactRevision"].includes(t))&&typeof e.nodeId=="string"&&Mo.test(e.nodeId)&&!Ge.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)&&(e.dataTransaction===void 0||e.dataTransaction===!0&&e.mode==="reconciled-effect")&&Rr({executionId:e.executionId,handlerVersion:e.handlerVersion,inputDigest:e.inputDigest,expectedFactRevision:e.expectedFactRevision,output:e.input})}function St(e,t,o=Rn){if(!jo(t,o))return!1;let n=1e4,i=(r,d,s)=>{if(--n<0||s>8||!K(r))return!1;let a=d===null?"null":Array.isArray(d)?"array":typeof d=="number"&&Number.isSafeInteger(d)?"integer":typeof d,c=Array.isArray(r.type)?r.type:[r.type];if(!c.includes(a)&&!(a==="integer"&&c.includes("number"))||r.enum!==void 0&&(!Array.isArray(r.enum)||!r.enum.some(f=>ut(f,d)))||Object.hasOwn(r,"const")&&!ut(r.const,d))return!1;if(typeof d=="number")return Number.isFinite(d)&&(r.minimum===void 0||d>=r.minimum)&&(r.maximum===void 0||d<=r.maximum);if(typeof d=="string"){let f=Array.from(d).length;return(r.minLength===void 0||f>=r.minLength)&&(r.maxLength===void 0||f<=r.maxLength)}return Array.isArray(d)?d.length<=r.maxItems&&(r.minItems===void 0||d.length>=r.minItems)&&d.every(f=>i(r.items,f,s+1)):K(d)?!K(r.properties)||Object.keys(d).some(f=>Ge.has(f)||!Object.hasOwn(r.properties,f))||(Array.isArray(r.required)?r.required:[]).some(f=>!Object.hasOwn(d,f))||r.minProperties!==void 0&&Object.keys(d).length<r.minProperties||r.maxProperties!==void 0&&Object.keys(d).length>r.maxProperties?!1:Object.entries(d).every(([f,u])=>i(r.properties[f],u,s+1)):d===null||typeof d=="boolean"};return i(e,t,0)}function Cr(e){return typeof e=="string"&&e.length<=256&&e.split(".").length<=8&&e.split(".").every(t=>Mo.test(t)&&!Ge.has(t))}function Dt(e){let t=0,o=(n,i)=>{if(!K(n)||i>6||++t>256||Object.keys(n).some(s=>!["type","title","description","properties","required","additionalProperties","items","maxItems","minItems","maxLength","minLength","minimum","maximum","enum","const","maxProperties","minProperties"].includes(s)))return!1;let r=Array.isArray(n.type)?n.type:[n.type];if(!r.length||r.length>2||r.some(s=>!["object","array","string","integer","number","boolean","null"].includes(s))||r.length>1&&(!r.includes("null")||new Set(r).size!==r.length))return!1;for(let s of["title","description"])if(n[s]!==void 0&&(typeof n[s]!="string"||n[s].length>2e3))return!1;for(let s of["minimum","maximum"])if(n[s]!==void 0&&(typeof n[s]!="number"||!Number.isFinite(n[s])))return!1;for(let[s,a]of[["maxItems",200],["minItems",200],["maxLength",16384],["minLength",16384],["maxProperties",32],["minProperties",32]])if(n[s]!==void 0&&(!Number.isSafeInteger(n[s])||n[s]<0||n[s]>a))return!1;for(let[s,a]of[["minimum","maximum"],["minItems","maxItems"],["minLength","maxLength"],["minProperties","maxProperties"]])if(n[s]!==void 0&&n[a]!==void 0&&n[s]>n[a])return!1;if(["properties","required","additionalProperties","maxProperties","minProperties"].some(s=>n[s]!==void 0)&&!r.includes("object")||["items","maxItems","minItems"].some(s=>n[s]!==void 0)&&!r.includes("array")||["maxLength","minLength"].some(s=>n[s]!==void 0)&&!r.includes("string")||["minimum","maximum"].some(s=>n[s]!==void 0)&&!r.some(s=>s==="integer"||s==="number")||n.enum!==void 0&&(!Array.isArray(n.enum)||!n.enum.length||n.enum.length>100)||r.includes("object")&&(!K(n.properties)||n.additionalProperties!==!1||Object.keys(n.properties).length>32||Object.keys(n.properties).some(s=>!Nr.test(s)||Ge.has(s))||n.required!==void 0&&(!Array.isArray(n.required)||new Set(n.required).size!==n.required.length||n.required.some(s=>typeof s!="string"||!Object.hasOwn(n.properties,s)))||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(s=>o(s,i+1)))||r.includes("array")&&(!Number.isSafeInteger(n.maxItems)||!o(n.items,i+1)))return!1;let d={...n};return delete d.enum,delete d.const,!(n.enum!==void 0&&(!n.enum.every(s=>St(d,s))||n.enum.some((s,a)=>n.enum.slice(0,a).some(c=>ut(s,c))))||Object.hasOwn(n,"const")&&!St(d,n.const))};return K(e)&&e.type==="object"&&Tr(e)<=Rn&&o(e,0)}function kt(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 hr(e,t){let o=e;for(let n of t.split(".")){if(!K(o?.properties)||!Object.hasOwn(o.properties,n))return;o=o.properties[n]}return K(o)?o:void 0}var yr=(e,t)=>!!hr(e,t);function Cd(e){return K(e)&&Object.keys(e).every(t=>["version","mode","dataTransaction","inputSchema","outputSchema"].includes(t))&&Number.isSafeInteger(e.version)&&e.version>=1&&e.version<=1e6&&["pure","reconciled-effect"].includes(e.mode)&&(e.dataTransaction===void 0||e.dataTransaction===!0&&e.mode==="reconciled-effect")&&Dt(e.inputSchema)&&Dt(e.outputSchema)}function br(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 Wo(e,t=0){return!K(e)||t>16?[]:e.op==="path"?typeof e.path=="string"?[e.path]:[]:["left","right","value"].flatMap(o=>Wo(e[o],t+1)).concat(Array.isArray(e.values)?e.values.flatMap(o=>Wo(o,t+1)):[])}function $t(e,t){if(!K(e)||!K(e.nodes))return["WORKFLOW_STEP_DEFINITION_INVALID"];let o=e.nodes,n=Object.entries(o).filter(([,s])=>s?.kind==="action");if(!n.length)return[];let i=[];Object.hasOwn(e.inputSchema?.properties||{},"steps")&&i.push("WORKFLOW_STEP_FACT_NAMESPACE_RESERVED");let r=kt(e);for(let[s,a]of n){(Object.keys(a).some(u=>!["id","kind","title","next","handler","inputSchema","outputSchema","inputs"].includes(u))||a.id!==s||!Mo.test(s)||Ge.has(s)||typeof a.title!="string"||!a.title.trim()||a.title.length>255||typeof a.next!="string"||!Object.hasOwn(o,a.next))&&i.push(`WORKFLOW_STEP_NODE_INVALID:${s}`);let c=a.handler;(!K(c)||Object.keys(c).some(u=>!["code","version","mode","dataTransaction"].includes(u))||!Number.isSafeInteger(c.version)||c.version<1||c.version>1e6||!/^[a-z][a-z0-9-]{0,100}$/.test(c.code||"")||!String(c.code).endsWith(`-v${c.version}`)||!["pure","reconciled-effect"].includes(c.mode)||c.dataTransaction!==void 0&&(c.dataTransaction!==!0||c.mode!=="reconciled-effect"))&&i.push(`WORKFLOW_STEP_HANDLER_INVALID:${s}`);let f=Dt(a.inputSchema);if((!f||!Dt(a.outputSchema))&&i.push(`WORKFLOW_STEP_SCHEMA_INVALID:${s}`),!K(a.inputs)||Object.keys(a.inputs).length>32){i.push(`WORKFLOW_STEP_INPUTS_INVALID:${s}`);continue}for(let u of Array.isArray(a.inputSchema?.required)?a.inputSchema.required:[])Object.hasOwn(a.inputs,u)||i.push(`WORKFLOW_STEP_INPUT_REQUIRED:${s}:${u}`);for(let[u,p]of Object.entries(a.inputs)){if(!Nr.test(u)||Ge.has(u)||!Object.hasOwn(a.inputSchema?.properties||{},u)||!K(p)){i.push(`WORKFLOW_STEP_INPUT_INVALID:${s}:${u}`);continue}if(p.source==="literal")(!f||Object.keys(p).some(_=>!["source","value"].includes(_))||!Object.hasOwn(p,"value")||!St(a.inputSchema.properties[u],p.value))&&i.push(`WORKFLOW_STEP_LITERAL_INVALID:${s}:${u}`);else if(p.source!=="fact"||Object.keys(p).some(_=>!["source","path"].includes(_))||!Cr(p.path)||!yr(r,p.path))i.push(`WORKFLOW_STEP_FACT_PATH_INVALID:${s}:${u}`);else if(f){let _=hr(r,p.path),E=a.inputSchema.properties[u],A=Array.isArray(_.type)?_.type:[_.type],O=Array.isArray(E.type)?E.type:[E.type];A.some(b=>!O.includes(b)&&!(b==="integer"&&O.includes("number")))&&i.push(`WORKFLOW_STEP_FACT_TYPE_MISMATCH:${s}:${u}`)}}}let d=(s,a)=>{let c=new Set,f=[e.startAt||""];for(;f.length&&c.size<=200;){let u=f.shift();if(!(u===a||c.has(u)||!o[u])){if(u===s)return!0;c.add(u),f.push(...br(o[u]))}}return!1};for(let[s,a]of Object.entries(o)){if(!K(a))continue;let c=a.kind==="action"?Object.values(a.inputs||{}).flatMap(u=>u?.source==="fact"?[u.path]:[]):(Array.isArray(a.branches)?a.branches:[]).flatMap(u=>Wo(u?.when)),f=t?.bindings?.[a.binding];f&&c.push(...[f.inputPath,f.departmentIdFrom,f.resourceIdFrom,f.scope?.valueFrom].filter(u=>typeof u=="string"));for(let u of c.filter(p=>typeof p=="string"&&p.startsWith("steps."))){let p=u.split(".")[1];(o[p]?.kind!=="action"||p===s||!yr(r,u)||d(s,p))&&i.push(`WORKFLOW_STEP_OUTPUT_NOT_AVAILABLE:${s}:${u}`)}}if(t)for(let[,s]of n){let a=new Set,c=[s.next];for(;c.length&&a.size<=200;){let f=c.shift();if(a.has(f)||!K(o[f]))continue;a.add(f);let u=o[f];if(!(u.kind==="action"||u.kind==="end")){if(u.kind==="approval"){let p=t.bindings?.[u.binding];p&&["application_provider","initiator_select"].includes(p.provider)&&i.push(`WORKFLOW_STEP_NEXT_PROVIDER_REQUIRES_PREPARED_RESULT:${f}`);continue}c.push(...br(u))}}}return[...new Set(i)]}function hd(e,t){let o={};for(let[n,i]of Object.entries(e.inputs)){let r=i.source==="literal"?i.value:i.path.split(".").reduce((d,s)=>K(d)&&Object.hasOwn(d,s)?d[s]:void 0,t);r!==void 0&&(o[n]=r)}if(!St(e.inputSchema,o))throw new Error("WORKFLOW_STEP_INPUT_SCHEMA_INVALID");return o}function Bo(e,t,o){let n=Cn(e),i=[];Object.keys(n).length&&!o&&i.push("WORKFLOW_STEP_BACKEND_REQUIRED");for(let r of Object.keys(n)){let d=t.find(s=>s.code===r);(!d||d.execution||d.action||!Array.isArray(d.eventTypes)||d.eventTypes.length!==1||d.eventTypes[0]!==lt||!K(d.filter)||Object.keys(d.filter).length!==1||!K(d.filter.workflowStep)||Object.keys(d.filter.workflowStep).length!==1||d.filter.workflowStep.handlerCode!==r||!K(d.payload)||d.payload.includeChanges!==!1||!Array.isArray(d.payload.fields)||d.payload.fields.length)&&i.push(`WORKFLOW_STEP_SUBSCRIPTION_INVALID:${r}`)}for(let r of t)(r.eventTypes?.includes(lt)&&!n[r.code]||r.filter?.workflowStep&&!n[r.code])&&i.push(`WORKFLOW_STEP_HANDLER_NOT_DECLARED:${r.code}`);return i}function Cn(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 r={version:i.handler.version,mode:i.handler.mode,...i.handler.dataTransaction?{dataTransaction:!0}:{},inputSchema:i.inputSchema,outputSchema:i.outputSchema},d=t[i.handler.code];if(d&&!ut(d,r))throw new Error(`WORKFLOW_STEP_HANDLER_CONTRACT_CONFLICT:${i.handler.code}`);t[i.handler.code]=r}}return t}var fe=e=>e&&typeof e=="object"&&!Array.isArray(e)?e:{},qe=(e,t)=>typeof e=="string"&&!!e.trim()&&e.length<=t,wd=/^[A-Za-z][A-Za-z0-9_-]*(?:\.[A-Za-z][A-Za-z0-9_-]*){0,15}$/,Ko=e=>typeof e=="string"&&e.length<=256&&wd.test(e)&&!e.split(".").some(t=>["__proto__","prototype","constructor"].includes(t));function hn(e,t){let o=fe(e),n=!0;for(let i of t.split(".")){n&&=Array.isArray(o.required)&&o.required.includes(i);let r=fe(o.properties)[i];if(!r||typeof r!="object")return null;o=fe(r)}return{schema:o,required:n}}function Go(e){let t=new Set,o=[],n=2048,i=(r,d)=>{if(--n<0||d>20){o.push("WORKFLOW_EXPRESSION_BUDGET_EXCEEDED");return}let s=fe(r);if(s.op==="path")Ko(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 a of s.values){if(n<0)break;i(a,d+1)}else s.op==="not"||s.op==="exists"?i(s.value,d+1):["eq","neq","gt","gte","lt","lte","in","contains"].includes(String(s.op))?(i(s.left,d+1),i(s.right,d+1)):o.push("WORKFLOW_EXPRESSION_OPERATOR_INVALID")}};return i(e,0),{paths:[...t],errors:[...new Set(o)]}}function qo(e){if(e?.readability===void 0)return[];let t=[],o=kt(e),n=fe(e.readability);(Object.keys(n).some(s=>!["variables","logic"].includes(s))||!Object.keys(n).length)&&t.push("WORKFLOW_READABILITY_INVALID");let i=fe(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[s,a]of Object.entries(i)){let c=fe(a);(!Ko(s)||!hn(o,s))&&t.push(`WORKFLOW_VARIABLE_SOURCE_UNKNOWN:${s}`),(!qe(c.label,160)||Object.keys(c).some(f=>!["label","unit","description"].includes(f))||c.unit!==void 0&&!qe(c.unit,32)||c.description!==void 0&&!qe(c.description,2e3))&&t.push(`WORKFLOW_VARIABLE_METADATA_INVALID:${s}`)}let r=n.logic===void 0?[]:n.logic;(!Array.isArray(r)||r.length>32)&&t.push("WORKFLOW_LOGIC_LIMIT_INVALID");let d=new Set;for(let s of Array.isArray(r)?r.slice(0,32):[]){let a=fe(s),c=String(a.code||"");e.approvedDelegation&&c==="kernel-approved-delegation"&&t.push("WORKFLOW_LOGIC_PLATFORM_CODE_RESERVED"),(!/^[a-z][a-z0-9-]{2,63}$/.test(c)||d.has(c)||!qe(a.title,160)||!qe(a.description,4e3)||Object.keys(a).some(f=>!["code","title","description","phase","nodeId","inputPaths","outputPaths","source"].includes(f)))&&t.push(`WORKFLOW_LOGIC_METADATA_INVALID:${c}`),d.add(c),(!["submission","node_input","completion"].includes(String(a.phase))||a.phase==="node_input"&&!fe(e.nodes)[String(a.nodeId)]||a.phase!=="node_input"&&a.nodeId!==void 0)&&t.push(`WORKFLOW_LOGIC_ANCHOR_INVALID:${c}`);for(let f of["inputPaths","outputPaths"]){let u=a[f];if(!(f==="outputPaths"&&u===void 0))if(!Array.isArray(u)||u.length>32||new Set(u).size!==u.length)t.push(`WORKFLOW_LOGIC_PATHS_INVALID:${c}:${f}`);else for(let p of u)(!Ko(p)||!hn(o,p))&&t.push(`WORKFLOW_LOGIC_SOURCE_UNKNOWN:${c}:${String(p)}`)}if(a.source!==void 0){let f=fe(a.source);(!qe(f.path,256)||String(f.path).startsWith("/")||String(f.path).includes("..")||String(f.path).includes("://")||!/^sha256:[a-f0-9]{64}$/.test(String(f.digest))||f.symbol!==void 0&&!qe(f.symbol,160)||Object.keys(f).some(u=>!["path","symbol","digest"].includes(u)))&&t.push(`WORKFLOW_LOGIC_SOURCE_REFERENCE_INVALID:${c}`)}}for(let s of Object.values(fe(e.nodes))){let a=fe(s),c=Array.isArray(a.branches)?a.branches:[];for(let f of c){let u=Go(f.when);t.push(...u.errors.map(p=>`${p}:${a.id}`));for(let p of u.paths)hn(o,p)||t.push(`WORKFLOW_VARIABLE_SOURCE_UNKNOWN:${a.id}:${p}`)}}return[...new Set(t)]}function Sd(e,t){let o=kt(e),n=[],i=new Map,r=[];for(let c of Object.values(e.nodes)){if(c.kind==="approval")for(let[f,u,p]of[["approve",c.onApprove,"\u540C\u610F"],["reject",c.onReject,"\u62D2\u7EDD"]])u&&n.push({id:`${c.id}:${f}`,from:c.id,to:u,kind:f,label:p,variablePaths:[]});if(c.kind==="approval")for(let f of new Set(c.returnTargets||[]))e.nodes[f]?.kind==="correction"&&n.push({id:`${c.id}:return:${f}`,from:c.id,to:f,kind:"return",label:"\u9000\u56DE\u53D1\u8D77\u4EBA\u8865\u6B63",variablePaths:[]});if(c.kind==="correction"&&c.next&&n.push({id:`${c.id}:resubmit`,from:c.id,to:c.next,kind:"resubmit",label:"\u91CD\u65B0\u63D0\u4EA4\uFF0C\u4ECE\u8D77\u70B9\u91CD\u7B97",variablePaths:[]}),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 f=Object.values(c.inputs||{}).flatMap(u=>u.source==="fact"?[u.path]:[]);for(let u of f)i.has(u)||i.set(u,new Set),i.get(u).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:f})}if(c.kind==="condition"){for(let[f,u]of(c.branches||[]).entries()){let p=Go(u.when);for(let _ of p.paths)i.has(_)||i.set(_,new Set),i.get(_).add(c.id);n.push({id:`${c.id}:branch:${f}`,from:c.id,to:u.target,kind:"branch",label:u.label||`\u6761\u4EF6 ${f+1}`,priority:f+1,expression:u.when,variablePaths:p.paths}),r.push(...p.errors.map(_=>({code:_,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 d=[...e.readability?.logic||[]];if(e.approvedDelegation){let c=e.approvedDelegation,f=c.confirmer==="initiator"?"\u7533\u8BF7\u4EBA\u672C\u4EBA":"\u6240\u9009\u4EE3\u7406\u4EBA";d.push({code:"kernel-approved-delegation",title:"\u6279\u51C6\u540E\u6574\u6279\u6388\u6743\u4EE3\u7406",phase:"completion",inputPaths:[c.requestsField],description:`\u6279\u51C6\u65F6\u6838\u9A8C${f}\u5728\u5F53\u524D\u9000\u56DE\u5468\u671F\u5B8C\u6210\u201C${e.nodes[c.confirmationNodeId]?.title||c.confirmationNodeId}\u201D\u7684\u4EBA\u5DE5\u786E\u8BA4\uFF1B\u968F\u540E\u91CD\u65B0\u6838\u9A8C\u53CC\u65B9\u5F53\u524D\u8D26\u53F7\u3001\u804C\u8D23\u3001\u4FEE\u8BA2\u3001\u8303\u56F4\u4E0E\u5B8C\u6574\u6709\u6548\u671F\uFF0C\u6574\u6279\u6388\u6743\uFF08\u6700\u591A${c.maxRequests}\u884C\uFF09\u3002\u4EFB\u4E00\u884C\u5931\u8D25\uFF0C\u6279\u51C6\u4E0E\u5168\u90E8\u6388\u6743\u4E00\u8D77\u56DE\u6EDA\uFF1B\u539F\u547D\u4EE4\u6062\u590D\u4E0D\u91CD\u65B0\u6FC0\u6D3B\u5DF2\u64A4\u9500\u6388\u6743\u3002`})}let a=[...new Set([...i.keys(),...Object.keys(e.readability?.variables||{}),...d.flatMap(c=>[...c.inputPaths,...c.outputPaths||[]])])].slice(0,128).map(c=>{let f=hn(o,c),u=e.readability?.variables?.[c],p=c.split("."),_=e.subject?.factProjection[p[0]],E=p[0]==="steps"?e.nodes[p[1]]:void 0;return f||r.push({code:"WORKFLOW_VARIABLE_SOURCE_UNKNOWN",path:c}),{path:c,label:u?.label||String(f?.schema.title||c),type:String(f?.schema.type||"unknown"),...u,required:f?.required||!1,usedBy:[...i.get(c)||[]],source:f&&E?.handler?{kind:"step_output",nodeId:E.id,handlerCode:E.handler.code,handlerVersion:E.handler.version}:f&&_&&e.subject?{kind:"subject_field",resourceCode:e.subject.resourceCode,fieldPath:[_,...p.slice(1)].join(".")}:{kind:f?"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==="approval"?{emptyPolicy:c.emptyPolicy||"block",initiatorApprovalPolicy:c.initiatorApprovalPolicy||"manual",...c.completionDeadline?{completionDeadline:{...c.completionDeadline}}:{}}:{},...c.kind==="action"&&c.handler?{businessStep:{handler:c.handler,inputs:c.inputs||{},outputPaths:Object.keys(fe(c.outputSchema).properties||{}).map(f=>`steps.${c.id}.${f}`)}}:{}})),edges:n,variables:a,logic:d,diagnostics:r}}function wr(e,t=[]){let o=i=>{let r=t.find(d=>d.path===i)?.label;return r&&r!==i?r:void 0},n=o(e);if(n)return n;for(let i=e.lastIndexOf(".");i>0;i=e.lastIndexOf(".",i-1)){let r=o(e.slice(0,i));if(!r)continue;let d=e.slice(i+1);return d==="value"?`${r}\uFF08\u503C\uFF09`:d==="label"?`${r}\uFF08\u663E\u793A\u540D\u79F0\uFF09`:`${r}.${d}`}return e}function vt(e,t=[],o=0){if(!e||o>20)return"\u65E0\u6CD5\u8BC6\u522B\u7684\u6761\u4EF6";if(e.op==="path")return wr(e.path,t);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(d=>`\uFF08${vt(d,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${vt(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(d=>d.path===i)?.unit:void 0;return`${vt(e.left,t,o+1)} ${n[e.op]} ${vt(e.right,t,o+1)}${r?` ${r}`:""}`}function Sr(e,t=0){return!Array.isArray(e)||e.length>64||t>1?!1:e.every(o=>{if(!o||typeof o!="object"||Array.isArray(o)||o.readonlyWhen!==void 0)return!1;if(o.subtable!==void 0){let n=o.subtable;return n&&n.create===!1&&n.delete===!1&&n.reorder===!1&&Sr(n.fields,t+1)}return o.readonly===!0})}function ft(e){let t=[];for(let[o,n]of Object.entries(e?.nodes||{}))if(n.initiatorApprovalPolicy!==void 0){if(n.kind!=="approval"||!["manual","auto_approve"].includes(n.initiatorApprovalPolicy)){t.push(`WORKFLOW_INITIATOR_APPROVAL_POLICY_INVALID:${o}`);continue}n.initiatorApprovalPolicy==="auto_approve"&&((n.taskPageCode!==void 0&&(typeof n.taskPageCode!="string"||!Sr(e.taskPages?.[n.taskPageCode]?.fields))||[n.fieldPolicy?.default,...Object.values(n.fieldPolicy?.fields||{})].some(i=>i==="edit"||i==="edit_required"))&&t.push(`WORKFLOW_INITIATOR_APPROVAL_INPUT_REQUIRED:${o}`),n.operationPolicy?.approve?.commentRequired===!0&&t.push(`WORKFLOW_INITIATOR_APPROVAL_COMMENT_REQUIRED:${o}`))}return t}function Dd(e,t,o,n,i){return e.kind==="approval"&&e.initiatorApprovalPolicy==="auto_approve"&&ft({nodes:{node:e},...i?{taskPages:i}:{}}).length===0&&t!=="return_review"&&!!o&&n.user_id===o&&n.status==="active"&&n.participant_kind==="primary"&&["resolution","resolution_retry"].includes(n.source||"")&&!n.source_participant_id&&!n.delegate_authorization_id}var Bu=8,kd={type:"array",minItems:2,maxItems:8,uniqueItems:!0,items:{type:"string",maxLength:128,pattern:"^[a-z][a-z0-9]*(?:[-_.][a-z0-9]+)*$"}};function Pt(e){if(e.roleCodes===void 0)return[];let t=e.roleCodes;if(!["app_role","app_role_in_scope"].includes(e.provider||"")||e.roleCode!==void 0||e.candidateField!==void 0||!Array.isArray(t)||t.length<2||t.length>8||new Set(t).size!==t.length||t.some(o=>typeof o!="string"||o.length>128||!/^[a-z][a-z0-9]*(?:[-_.][a-z0-9]+)*$/.test(o)))return["WORKFLOW_V2_BINDING_ROLE_UNION_INVALID"];if(e.provider==="app_role_in_scope"){let o=e.scope,n=typeof o?.value=="string"&&o.value.length>0&&o.value.length<=255&&o.valueFrom===void 0,i=typeof o?.valueFrom=="string"&&o.valueFrom.length<=255&&/^[A-Za-z][A-Za-z0-9_-]*(?:\.[A-Za-z][A-Za-z0-9_-]*)*$/.test(o.valueFrom)&&!o.valueFrom.split(".").some(r=>["__proto__","prototype","constructor"].includes(r))&&o.value===void 0;if(!o||typeof o!="object"||Array.isArray(o)||Object.keys(o).some(r=>!["dimension","value","valueFrom"].includes(r))||typeof o.dimension!="string"||!/^[a-z][a-z0-9]*(?:[-_.][a-z0-9]+)*$/.test(o.dimension)||!n&&!i)return["WORKFLOW_V2_BINDING_ROLE_UNION_SCOPE_INVALID"]}else if(e.scope!==void 0)return["WORKFLOW_V2_BINDING_ROLE_UNION_SCOPE_INVALID"];return[]}function $d(e){return e.roleCodes?[...e.roleCodes]:e.roleCode?[e.roleCode]:[]}function zo(e){return e.some(t=>Object.values(t.binding.bindings).some(o=>o.roleCodes!==void 0))}function Jo(e){if(e.selectedInputPath===void 0)return[];let t=e.selectedInputPath;return!["app_role","app_role_in_scope"].includes(e.provider||"")||e.candidateField!==void 0||e.inputPath!==void 0||e.routing!==void 0||e.roleCode===void 0&&e.roleCodes===void 0||typeof t!="string"||t.length>255||!/^[A-Za-z][A-Za-z0-9_-]*(?:\.[A-Za-z][A-Za-z0-9_-]*)*$/.test(t)||t.split(".").some(o=>["__proto__","constructor","prototype"].includes(o))?["WORKFLOW_V2_ROLE_INPUT_SELECTION_INVALID"]:[]}function Ho(e){return e.some(t=>Object.values(t.binding.bindings).some(o=>o.selectedInputPath!==void 0))}var Sn=["approve","reject","return","transfer","delegate","add_assignee"],Dn=["fixed_users","app_role","app_role_in_scope"],vd=["single","any","all","sequence"],Fe=e=>!!e&&typeof e=="object"&&!Array.isArray(e),ze=(e,t)=>Object.keys(e).every(o=>t.includes(o)),wn=(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 pt(e){return e.allowedOperations||[...Sn]}function Dr(e,t){return t?.commentRequired??e==="reject"}function kr(e,t){return!["transfer","delegate","add_assignee","return"].includes(e)||t?.reasonRequired!==!1}function $r(e,t,o={},n=!1){return!(!Fe(e)||!Object.keys(e).length||!ze(e,n?["enabled","label","commentRequired","reasonRequired"]:["label","commentRequired","reasonRequired"])||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)||n&&Dr(t,o)&&!e.commentRequired)||e.reasonRequired!==void 0&&(typeof e.reasonRequired!="boolean"||!["transfer","delegate","add_assignee","return"].includes(t)||n&&kr(t,o)&&!e.reasonRequired))}function kn(e,t){let o=[];for(let[n,i]of Object.entries(e?.nodes||{})){if(!Fe(i))continue;let r=i.administration,d=i.operationPolicy;if(i.kind==="cc"){(d!==void 0||r!==void 0&&(!Fe(r)||!ze(r,["assigneeProviders"])))&&o.push(`WORKFLOW_NODE_ADMINISTRATION_INVALID:${n}`),r?.assigneeProviders!==void 0&&!wn(r.assigneeProviders,Dn,3)&&o.push(`WORKFLOW_NODE_ADMINISTRATION_PROVIDERS_INVALID:${n}`),r?.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"){(r!==void 0||d!==void 0)&&o.push(`WORKFLOW_NODE_ADMINISTRATION_APPROVAL_REQUIRED:${n}`);continue}if(d!==void 0&&(!Fe(d)||Object.keys(d).length>8||Object.entries(d).some(([a,c])=>!Sn.includes(a)||!pt(i).includes(a)||!$r(c,a)))&&o.push(`WORKFLOW_NODE_OPERATION_POLICY_INVALID:${n}`),r===void 0)continue;if(!Fe(r)||!ze(r,["modes","assigneeProviders","operations"])){o.push(`WORKFLOW_NODE_ADMINISTRATION_INVALID:${n}`);continue}r.modes!==void 0&&(!wn(r.modes,vd,4)||!r.modes.includes(i.mode))&&o.push(`WORKFLOW_NODE_ADMINISTRATION_MODES_INVALID:${n}`),r.assigneeProviders!==void 0&&!wn(r.assigneeProviders,Dn,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&&(!wn(r.operations,Sn,8)||r.operations.some(a=>!pt(i).includes(a)))&&o.push(`WORKFLOW_NODE_ADMINISTRATION_OPERATIONS_INVALID:${n}`)}return o}function Pd(e,t,o,n){let i=[];if(!e||!Fe(o)||!Object.keys(o).length||!ze(o,["title","description","assignee","mode","operations"]))return["WORKFLOW_V2_NODE_CONFIGURATION_PATCH_INVALID"];let r=o;for(let s of["title","description"])r[s]!==void 0&&(typeof r[s]!="string"||r[s].length>(s==="title"?255:1e3)||s==="title"&&!r[s].trim())&&i.push("WORKFLOW_V2_NODE_CONFIGURATION_PATCH_INVALID");let d=e.administration;if(r.mode!==void 0&&(e.kind!=="approval"||!d?.modes?.includes(r.mode))&&i.push("WORKFLOW_V2_NODE_CONFIGURATION_MODE_READONLY"),r.operations!==void 0&&(e.kind!=="approval"||!Fe(r.operations)||!Object.keys(r.operations).length||Object.keys(r.operations).length>8||Object.entries(r.operations).some(([s,a])=>!d?.operations?.includes(s)||!pt(e).includes(s)||!$r(a,s,e.operationPolicy?.[s],!0)))&&i.push("WORKFLOW_V2_NODE_CONFIGURATION_OPERATION_INVALID"),r.assignee!==void 0){let s=r.assignee,a=d?.assigneeProviders||(e.kind==="approval"&&t&&Dn.includes(t.provider)?[t.provider]:[]);t?.selectedInputPath&&!["app_role","app_role_in_scope"].includes(s?.provider||"")&&i.push("WORKFLOW_V2_NODE_CONFIGURATION_PROVIDER_READONLY"),!Fe(s)||!["approval","cc"].includes(e.kind)||!a.includes(s.provider)||s.provider==="app_role_in_scope"&&!t?.scope?i.push("WORKFLOW_V2_NODE_CONFIGURATION_PROVIDER_READONLY"):s.provider==="fixed_users"?(!ze(s,["provider","users"])||!Array.isArray(s.users)||s.users.length<1&&!(e.kind==="approval"&&e.emptyPolicy==="skip")||s.users.length>(e.kind==="cc"?20:200)||new Set(s.users).size!==s.users.length||s.users.some(c=>typeof c!="string"||!c.trim()||c.length>255))&&i.push("WORKFLOW_V2_NODE_CONFIGURATION_USERS_INVALID"):s.roleCodes!==void 0?(!ze(s,["provider","roleCodes"])||Pt({...s,...s.provider==="app_role_in_scope"?{scope:t?.scope}:{}}).length)&&i.push("WORKFLOW_V2_NODE_CONFIGURATION_ROLE_INVALID"):(!ze(s,["provider","roleCode"])||typeof s.roleCode!="string"||!/^[a-z][a-z0-9_-]{0,127}$/.test(s.roleCode))&&i.push("WORKFLOW_V2_NODE_CONFIGURATION_ROLE_INVALID")}return i.push(...ft({nodes:{node:{...e,operationPolicy:Yo(e,r).operationPolicy}},...n?{taskPages:n}:{}})),e.completionDeadline&&Yo(e,r).operationPolicy.approve?.commentRequired===!0&&i.push("WORKFLOW_COMPLETION_DEADLINE_INPUT_REQUIRED:node"),i}function Yo(e,t){let o=Object.fromEntries(pt(e).flatMap(n=>{let i=n,r=t?.operations?.[i],d={...e.operationPolicy?.[i],...r?.label!==void 0?{label:r.label}:{},...r?.commentRequired!==void 0?{commentRequired:r.commentRequired}:{},...r?.reasonRequired!==void 0?{reasonRequired:r.reasonRequired}:{}};return Object.keys(d).length?[[i,d]]:[]}));return{mode:t?.mode||e.mode,initiatorApprovalPolicy:e.initiatorApprovalPolicy||"manual",allowedOperations:pt(e).filter(n=>t?.operations?.[n]?.enabled!==!1),operationPolicy:o,fieldPolicy:{default:e.fieldPolicy?.default||"readonly",fields:{...e.fieldPolicy?.fields}}}}var Ju=20,vr=["fixed_users","initiator","input_users","form_field_users","app_role","app_role_in_scope","previous_node_actor"];function $n(e,t){let o=[];for(let[n,i]of Object.entries(e?.nodes||{})){if(i?.kind!=="cc"||((Object.keys(i).some(a=>!["id","kind","title","binding","next","emptyPolicy","notify","administration"].includes(a))||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 r=t.bindings?.[i.binding];if(!r){o.push(`WORKFLOW_CC_BINDING_NOT_FOUND:${n}`);continue}vr.includes(r.provider)||o.push(`WORKFLOW_CC_PROVIDER_INVALID:${n}`);let d=r.min??1,s=r.max??20;(!Number.isSafeInteger(d)||!Number.isSafeInteger(s)||d<1||s<d||s>20||r.provider==="fixed_users"&&(!Array.isArray(r.users)||!r.users.length||r.users.length>s))&&o.push(`WORKFLOW_CC_RECIPIENT_LIMIT_INVALID:${n}`)}return[...new Set(o)]}var Xo=["fixed_users","input_users","form_field_users","app_role","app_role_in_scope"];function vn(e,t){let o=[];for(let[n,i]of Object.entries(e?.nodes||{}))i.kind==="cc"||i.emptyPolicy===void 0||(i.kind!=="approval"||!["block","skip"].includes(i.emptyPolicy)?o.push(`WORKFLOW_APPROVAL_EMPTY_POLICY_INVALID:${n}`):i.emptyPolicy==="skip"&&t&&!Xo.includes(t.bindings?.[i.binding||""]?.provider)&&o.push(`WORKFLOW_APPROVAL_EMPTY_PROVIDER_UNSUPPORTED:${n}`));return o}function Ld(e,t){return e.kind==="approval"&&e.emptyPolicy==="skip"&&t?.emptyResult==="no_candidates"&&Xo.includes(t.provider)&&Array.isArray(t.candidates)&&t.candidates.length===0&&Array.isArray(t.selected)&&t.selected.length===0&&Array.isArray(t.warnings)&&t.warnings.length===0}function Zo(e,t){let o=Object.values(e.nodes||{}).filter(n=>n.binding===t);return o.length>0&&o.every(n=>n.kind==="approval"&&n.emptyPolicy==="skip")}function Pr(e,t=0){return!Array.isArray(e)||e.length>64||t>1?!0:e.some(o=>!o||typeof o!="object"||Array.isArray(o)||o.required===!0||o.requiredWhen!==void 0||o.subtable!==void 0&&(!o.subtable||Pr(o.subtable.fields,t+1)))}function Vd(e){let t=e.afterSeconds;return`\u8FDB\u5165\u540E ${t%86400===0?`${t/86400} \u5929`:t%3600===0?`${t/3600} \u5C0F\u65F6`:t%60===0?`${t/60} \u5206\u949F`:`${t} \u79D2`}\u672A\u5B8C\u6210\uFF0C\u81EA\u52A8\u540C\u610F`}function Qo(e){let t=[];for(let[o,n]of Object.entries(e?.nodes||{})){if(!n||typeof n!="object"||n.completionDeadline===void 0)continue;let i=n.completionDeadline;if(n.kind!=="approval"||!i||typeof i!="object"||Array.isArray(i)||Object.keys(i).length!==2||Object.keys(i).some(d=>!["afterSeconds","action"].includes(d))||i.action!=="approve"||!Number.isInteger(i.afterSeconds)||i.afterSeconds<1||i.afterSeconds>2592e3){t.push(`WORKFLOW_COMPLETION_DEADLINE_INVALID:${o}`);continue}n.allowedOperations&&!n.allowedOperations.includes("approve")&&t.push(`WORKFLOW_COMPLETION_DEADLINE_APPROVE_UNAVAILABLE:${o}`);let r=n.taskPageCode?e.taskPages?.[n.taskPageCode]:void 0;(n.taskPageCode&&(!r||Pr(r.fields))||[n.fieldPolicy?.default,...Object.values(n.fieldPolicy?.fields||{})].includes("edit_required")||n.operationPolicy?.approve?.commentRequired===!0||e.commandHandlers?.approve!==void 0)&&t.push(`WORKFLOW_COMPLETION_DEADLINE_INPUT_REQUIRED:${o}`)}return t}var Lr="openxiangda.workflow-rejection-notification/v1",Zu=4096;function Vr(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)}function mt(e,t){return typeof e=="string"&&e.trim().length>0&&e.length<=t}function ei(e,t){return Object.keys(e).sort().join(",")===t.sort().join(",")}function ti(e){let t=e?.rejectionNotification;return t===void 0?[]:!Vr(t)||!ei(t,["recipient","title","summary"])||t.recipient!=="record_last_modifier"||!mt(t.title,160)||!mt(t.summary,500)?["WORKFLOW_REJECTION_NOTIFICATION_INVALID"]:mt(e.subject?.resourceCode,63)?[]:["WORKFLOW_REJECTION_NOTIFICATION_SUBJECT_REQUIRED"]}function Fd(e){if(!Vr(e)||e.schemaVersion!==Lr||e.recipient!=="record_last_modifier"||!mt(e.title,160)||!mt(e.summary,500))return!1;let t=["schemaVersion","recipient","title","summary","status","sourceRevision"];if(e.status==="ready"){if(!ei(e,[...t,"userId"])||!mt(e.userId,255)||!Number.isSafeInteger(e.sourceRevision)||Number(e.sourceRevision)<1)return!1}else if(e.status==="skipped"){if(!ei(e,[...t,"reason"])||!["record_missing","modifier_missing","modifier_ineligible"].includes(String(e.reason))||(e.reason==="record_missing"?e.sourceRevision!==null:!Number.isSafeInteger(e.sourceRevision)||Number(e.sourceRevision)<1))return!1}else return!1;return new TextEncoder().encode(JSON.stringify(e)).byteLength<=4096}function ni(e,t){let o=e.commandHandlers;if(o===void 0)return[];if(!o||typeof o!="object"||Array.isArray(o)||!Object.keys(o).length||Object.keys(o).some(i=>!["approve","reject","withdraw","resubmit"].includes(i)))return["WORKFLOW_BUSINESS_COMMAND_HANDLERS_INVALID"];let n=[];o.resubmit&&!Object.values(e.nodes||{}).some(i=>i.kind==="correction")&&n.push("WORKFLOW_BUSINESS_CORRECTION_REQUIRED");for(let[i,r]of Object.entries(o)){if(!r||typeof r!="object"||Array.isArray(r)||Object.keys(r).join(",")!=="operationCode"||!/^[a-z][a-z0-9]*(?:[-_.][a-z0-9]+)*$/.test(r.operationCode||"")){n.push("WORKFLOW_BUSINESS_COMMAND_HANDLER_INVALID");continue}if(!t)continue;let d=t.find(s=>s.code===r.operationCode);if(!d){n.push("WORKFLOW_BUSINESS_COMMAND_OPERATION_MISSING");continue}(d.method!=="POST"||d.browser?.exposure!=="authenticated"||d.browser.behavior!=="controlled"||d.browser.idempotency!=="required"||d.browser.fileIntent||d.browser.subject?.resourceCode!==e.subject?.resourceCode||d.browser.subject?.inputField!=="recordId"||!d.platformAccess?.workflow?.codes?.includes(e.code)||!d.platformAccess.workflow.businessCommands?.includes(i))&&n.push("WORKFLOW_BUSINESS_COMMAND_OPERATION_INVALID")}return["approve","reject","withdraw"].some(i=>Object.hasOwn(o,i))&&Object.values(e.nodes||{}).some(i=>i.kind==="approval"&&(i.emptyPolicy==="skip"||i.initiatorApprovalPolicy==="auto_approve"))&&n.push("WORKFLOW_BUSINESS_COMMAND_AUTOMATIC_DECISION_FORBIDDEN"),[...new Set(n)]}var xd={type:"object",additionalProperties:!1,required:["workflowCode","target","recordId","expectedRevision","commandToken","idempotencyKey","input"],properties:{workflowCode:{type:"string",pattern:"^[A-Za-z][A-Za-z0-9_-]{0,127}$"},target:{oneOf:[{type:"object",additionalProperties:!1,required:["kind","id","command"],properties:{kind:{const:"task"},id:{type:"string",format:"uuid"},command:{enum:["approve","reject","resubmit"]}}},{type:"object",additionalProperties:!1,required:["kind","id","command"],properties:{kind:{const:"instance"},id:{type:"string",format:"uuid"},command:{const:"withdraw"}}}]},recordId:{type:"string",format:"uuid"},expectedRevision:{type:"integer",minimum:1},commandToken:{type:"string",pattern:"^[A-Za-z0-9_-]{43}$"},idempotencyKey:{type:"string",minLength:1,maxLength:128},input:{type:"object",maxProperties:64}}};var Fr=["fixed_users","initiator","app_role","app_role_in_scope"],jd=e=>!!e&&typeof e=="object"&&!Array.isArray(e);function Pn(e,t){let o=e?.launchPreflight;if(o===void 0)return[];if(!jd(o)||Object.keys(o).join(",")!=="requiredApprovalNodes"||!Array.isArray(o.requiredApprovalNodes)||o.requiredApprovalNodes.length<1||o.requiredApprovalNodes.length>20||new Set(o.requiredApprovalNodes).size!==o.requiredApprovalNodes.length||o.requiredApprovalNodes.some(i=>typeof i!="string"||!/^[A-Za-z][A-Za-z0-9_-]{0,127}$/.test(i)))return["WORKFLOW_LAUNCH_PREFLIGHT_INVALID"];let n=[];for(let i of o.requiredApprovalNodes){let r=e.nodes?.[i];if(!r||r.kind!=="approval"){n.push(`WORKFLOW_LAUNCH_PREFLIGHT_NODE_INVALID:${i}`);continue}if(!t)continue;let d=t.bindings?.[r.binding||""];(!d||!Fr.includes(d.provider)||d.candidateField!==void 0)&&n.push(`WORKFLOW_LAUNCH_PREFLIGHT_PROVIDER_UNSUPPORTED:${i}`)}return n}var oi=e=>!!e&&typeof e=="object"&&!Array.isArray(e),Wd=/^[A-Za-z][A-Za-z0-9_]{0,62}$/,jr=/^[A-Za-z][A-Za-z0-9_-]{0,127}$/,xr=/^membership:[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i,nf=500,of=262144;function ii(e){if(e?.approvedDelegation===void 0)return[];let t=e.approvedDelegation;if(!oi(t)||Object.keys(t).some(a=>!["confirmationNodeId","confirmer","requestsField","maxRequests"].includes(a))||!jr.test(t.confirmationNodeId||"")||!["initiator","delegate"].includes(t.confirmer)||!Wd.test(t.requestsField||"")||!Number.isSafeInteger(t.maxRequests)||t.maxRequests<1||t.maxRequests>500)return["WORKFLOW_APPROVED_DELEGATION_POLICY_INVALID"];let o=[],n=e.nodes?.[t.confirmationNodeId];(!n||n.kind!=="approval"||n.mode!=="single"||n.emptyPolicy==="skip"||n.initiatorApprovalPolicy==="auto_approve"||n.completionDeadline||n.administration?.assigneeProviders?.length||n.administration?.modes?.some(a=>a!=="single")||n.allowedOperations?.some(a=>["transfer","delegate","add_assignee","admin_override"].includes(a)))&&o.push("WORKFLOW_APPROVED_DELEGATION_CONFIRMATION_INVALID");let i=e.inputSchema?.properties?.[t.requestsField];(!i||i.type!=="array"||!Number.isSafeInteger(i.maxItems)||i.maxItems<1||i.maxItems>t.maxRequests||!i.items||i.items.type!=="object"||i.items.additionalProperties!==!1||!e.subject?.factProjection?.[t.requestsField])&&o.push("WORKFLOW_APPROVED_DELEGATION_REQUEST_SCHEMA_INVALID"),Object.values(e.nodes||{}).some(a=>a.kind==="end"&&a.outcome==="approved")||o.push("WORKFLOW_APPROVED_DELEGATION_APPROVED_END_REQUIRED");let d=[e.startAt],s=new Set;for(;d.length;){let a=d.pop();if(a===t.confirmationNodeId||s.has(a))continue;s.add(a);let c=e.nodes?.[a];c&&(c.kind==="end"&&c.outcome==="approved"&&o.push("WORKFLOW_APPROVED_DELEGATION_CONFIRMATION_BYPASS"),c.kind==="approval"&&d.push(c.onApprove,c.onReject),c.kind==="condition"&&d.push(c.otherwise,...(c.branches||[]).map(f=>f.target)),(c.kind==="cc"||c.kind==="action")&&d.push(c.next))}return[...new Set(o)]}function Ud(e,t){let o=t?.data?.[e.requestsField],n=()=>{throw new Error("WORKFLOW_APPROVED_DELEGATION_REQUEST_INVALID")};(!Array.isArray(o)||!o.length||o.length>e.maxRequests||o.length>500||new TextEncoder().encode(JSON.stringify(o)).byteLength>262144)&&n();let i=["key","delegatorRoleSubjectKey","delegatorRoleSubjectRevision","delegate","delegateRoleSubjectKey","expectedDelegateRevision","workflowCode","nodeId","validFrom","validTo","reason"],r=(a,c)=>typeof a=="string"&&a.trim().length>0&&a.length<=c,d=a=>{if(typeof a!="string")return!1;let c=/^(\d{4})-(\d\d)-(\d\d)T(\d\d):(\d\d):(\d\d)(?:\.\d{1,3})?(?:Z|[+-](\d\d):(\d\d))$/.exec(a);if(!c)return!1;let[,f,u,p,_,E,A,O,b]=c,g=Number(f),I=Number(u),T=Number(p),y=[31,g%4===0&&(g%100!==0||g%400===0)?29:28,31,30,31,30,31,31,30,31,30,31];return I>=1&&I<=12&&T>=1&&T<=y[I-1]&&Number(_)<=23&&Number(E)<=59&&Number(A)<=59&&(O===void 0||Number(O)<=23&&Number(b)<=59)&&Number.isFinite(Date.parse(a))},s=o.map(a=>oi(a)?((Object.keys(a).some(c=>!i.includes(c))||!r(a.delegatorRoleSubjectKey,255)||!xr.test(a.delegatorRoleSubjectKey)||!r(a.delegateRoleSubjectKey,255)||!xr.test(a.delegateRoleSubjectKey)||!Number.isSafeInteger(a.delegatorRoleSubjectRevision)||a.delegatorRoleSubjectRevision<1||!Number.isSafeInteger(a.expectedDelegateRevision)||a.expectedDelegateRevision<1||!oi(a.delegate)||Object.keys(a.delegate).some(c=>!["value","label"].includes(c))||!r(a.delegate.value,255)||!r(a.delegate.label,200)||!(a.workflowCode===null||r(a.workflowCode,128)&&jr.test(a.workflowCode))||!(a.nodeId===null||r(a.nodeId,128)&&/^[A-Za-z0-9._:-]{1,128}$/.test(a.nodeId)&&a.workflowCode)||!d(a.validFrom)||!d(a.validTo)||Date.parse(a.validFrom)>=Date.parse(a.validTo)||!r(a.reason,4e3)||a.key!==void 0&&!r(a.key,128))&&n(),{...a,delegate:{value:a.delegate.value,label:a.delegate.label},validFrom:new Date(a.validFrom).toISOString(),validTo:new Date(a.validTo).toISOString()}):n());return e.confirmer==="delegate"&&new Set(s.map(a=>a.delegate.value)).size!==1&&n(),s}var Md=e=>!!e&&typeof e=="object"&&!Array.isArray(e)&&[null,Object.prototype].includes(Object.getPrototypeOf(e));function ri(e){let t=e?.nodes||{},o=Object.values(t).filter(s=>s?.kind==="correction");if(!o.length)return[];let n=[],i=s=>s?.kind==="approval"?[s.onApprove,s.onReject]:s?.kind==="condition"?[...(Array.isArray(s.branches)?s.branches:[]).map(a=>a.target),s.otherwise]:s?.kind==="action"||s?.kind==="cc"?[s.next]:[],r=new Set,d=[e.startAt];for(;d.length;){let s=d.pop();r.has(s)||(r.add(s),d.push(...i(t[s])))}for(let s of o){(!Md(s)||Object.keys(s).some(c=>!["id","kind","title","taskPageCode","next"].includes(c))||typeof s.id!="string"||!/^[A-Za-z][A-Za-z0-9_-]{0,127}$/.test(s.id)||["__proto__","prototype","constructor"].includes(s.id)||t[s.id]!==s||typeof s.title!="string"||!s.title.trim()||s.title.length>255||typeof s.taskPageCode!="string"||!/^[A-Za-z][A-Za-z0-9_-]{0,63}$/.test(s.taskPageCode))&&n.push("WORKFLOW_CORRECTION_NODE_INVALID"),(s.next!==e.startAt||t[s.next]?.kind==="correction")&&n.push("WORKFLOW_CORRECTION_REPLAY_TARGET_INVALID"),(r.has(s.id)||Object.values(t).some(c=>i(c).includes(s.id)))&&n.push("WORKFLOW_CORRECTION_FORWARD_ENTRY_FORBIDDEN"),Object.values(t).some(c=>c?.kind==="approval"&&r.has(c.id)&&Array.isArray(c.returnTargets)&&c.returnTargets.includes(s.id))||n.push("WORKFLOW_CORRECTION_RETURN_SOURCE_REQUIRED");let a=e.taskPages?.[s.taskPageCode];!a||!Array.isArray(a.fields)?n.push("WORKFLOW_CORRECTION_PAGE_REQUIRED"):a.fields.some(c=>c?.subtable&&Object.values(e.subject?.factProjection||{}).some(f=>f===c.code||f.startsWith(`${c.code}.`)))&&n.push("WORKFLOW_CORRECTION_OWNED_FACTS_UNSUPPORTED")}return[...new Set(n)]}var Lt=class extends Error{constructor(o){super(o);this.code=o}code},Bd=["projection","triggerCode","resourceCode","recordId","recordRevision","field","dueAt"];function si(e,t,o){let n=r=>{throw new Lt(r)};t.length>100&&n("DATE_TRIGGER_PROJECTION_LIMIT");let i=new Set;for(let r of t){let d=r.filter?.resourceCodes||[];if(Array.isArray(d)||n("DATE_TRIGGER_PROJECTION_INVALID"),d.length&&!d.includes(e))continue;let s=r.payload?.fields||[];(!Array.isArray(s)||s.length>32)&&n("DATE_TRIGGER_PROJECTION_LIMIT");for(let a of s)(typeof a!="string"||!/^[A-Za-z_][A-Za-z0-9_]{0,62}$/.test(a)||["__proto__","constructor","prototype"].includes(a))&&n("DATE_TRIGGER_PROJECTION_FIELD_INVALID"),i.add(a)}if(i.size>64&&n("DATE_TRIGGER_PROJECTION_LIMIT"),o!==void 0){let r=o?.schema?.fields??o?.fields;Array.isArray(r)||n("DATE_TRIGGER_PROJECTION_RESOURCE_INVALID");let d=new Map(r.map(s=>[s.code,s]));for(let s of i){let a=d.get(s);a||n("DATE_TRIGGER_PROJECTION_FIELD_UNKNOWN"),a.type==="subtable"&&n("DATE_TRIGGER_PROJECTION_SUBTABLE_FORBIDDEN"),o.fieldPolicies?.[s]?.mask==="omit"&&n("DATE_TRIGGER_PROJECTION_FIELD_SENSITIVE")}}return[...i].sort()}function Kd(e,t){if(!t.length)return e;let o=e?.properties?.projection;if(o?.type!=="object"||!o.properties||typeof o.properties!="object"||Array.isArray(o.properties)||o.additionalProperties!==!1||o.required!==void 0&&!Array.isArray(o.required)||t.some(n=>!Object.hasOwn(o.properties,n))||(o.required||[]).some(n=>!t.includes(n)))throw new Lt("DATE_TRIGGER_PROJECTION_SCHEMA_INVALID");return{...e,properties:{...e.properties,projection:{}}}}var Ur=64,Ln=1024*1024,Mr=65536,ci=500,ai=1e3,Je=new Set(["__proto__","prototype","constructor"]),Br=/^[A-Za-z][A-Za-z0-9_-]{0,63}$/,Ft=/^[A-Za-z][A-Za-z0-9_]{0,62}$/,Wr=/^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/,ae=e=>!!e&&typeof e=="object"&&!Array.isArray(e)&&[null,Object.prototype].includes(Object.getPrototypeOf(e)),ve=(e,t)=>ae(e)&&Object.keys(e).every(o=>t.includes(o)&&!Je.has(o)),Vn=e=>{try{return new TextEncoder().encode(JSON.stringify(e)).length}catch{return 1/0}},Kr=e=>e==null||typeof e=="string"&&!e.trim()||Array.isArray(e)&&e.length===0;function xe(e,t){if(e===t)return!0;if(Array.isArray(e)&&Array.isArray(t))return e.length===t.length&&e.every((n,i)=>xe(n,t[i]));if(!ae(e)||!ae(t))return!1;let o=Object.keys(e);return o.length===Object.keys(t).length&&o.every(n=>Object.hasOwn(t,n)&&xe(e[n],t[n]))}function di(e,t){let o=t.split(".");if(!(o.some(n=>!Br.test(n)||Je.has(n))||o.length>12))return o.reduce((n,i)=>ae(n)&&Object.hasOwn(n,i)?n[i]:void 0,e)}function $e(e,t){switch(e.op){case"literal":return e.value;case"path":return di({values:t},e.path);case"and":return e.values.every(o=>!!$e(o,t));case"or":return e.values.some(o=>!!$e(o,t));case"not":return!$e(e.value,t);case"exists":return!Kr($e(e.value,t));default:{let o=$e(e.left,t),n=$e(e.right,t);return e.op==="eq"?xe(o,n):e.op==="neq"?!xe(o,n):e.op==="in"?Array.isArray(n)&&n.some(i=>xe(i,o)):e.op==="contains"?Array.isArray(o)?o.some(i=>xe(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 Vt(e,t,o=0,n={nodes:0}){if(o>8||++n.nodes>64||!ae(e))return!1;if(e.op==="literal")return ve(e,["op","value"])&&Object.hasOwn(e,"value")&&Vn(e.value)<=4096&&xt(e.value);if(e.op==="path"){if(!ve(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(r=>Ft.test(r)&&!Je.has(r))}return["not","exists"].includes(e.op)?ve(e,["op","value"])&&Vt(e.value,t,o+1,n):["and","or"].includes(e.op)?ve(e,["op","values"])&&Array.isArray(e.values)&&e.values.length>0&&e.values.length<=16&&e.values.every(i=>Vt(i,t,o+1,n)):["eq","neq","gt","gte","lt","lte","in","contains"].includes(e.op)&&ve(e,["op","left","right"])&&Vt(e.left,t,o+1,n)&&Vt(e.right,t,o+1,n)}function jt(e,t,o,n=ai){let i=[],r=e.taskPages;if(r!==void 0&&(!ae(r)||Object.keys(r).length===0||Object.keys(r).length>16||Vn(r)>Mr))return["WORKFLOW_TASK_PAGES_INVALID"];for(let[d,s]of Object.entries(r||{})){let a=`taskPages.${d}`;if(!Br.test(d)||Je.has(d)||!ve(s,["title","fields"])||typeof s.title!="string"||!s.title.trim()||s.title.length>160||!Array.isArray(s.fields)||!s.fields.length||s.fields.length>Ur){i.push(`WORKFLOW_TASK_PAGE_INVALID:${a}`);continue}let c=new Set(s.fields.map(p=>p?.code));c.size!==s.fields.length&&i.push(`WORKFLOW_TASK_PAGE_DUPLICATE_FIELD:${a}`);let f=0,u=new Set;for(let p of s.fields){if(!ve(p,["code","readonly","required","visibleWhen","requiredWhen","subtable"])||!Ft.test(p.code)||Je.has(p.code)||["readonly","required"].some(_=>p[_]!==void 0&&typeof p[_]!="boolean")||p.readonly&&(p.required||p.requiredWhen)){i.push(`WORKFLOW_TASK_PAGE_FIELD_INVALID:${a}`);continue}for(let _ of["visibleWhen","requiredWhen"])p[_]!==void 0&&!Vt(p[_],c)&&i.push(`WORKFLOW_TASK_PAGE_EXPRESSION_INVALID:${a}.${p.code}.${_}`);if(t){let _=t.get(p.code);if((!_||_.system||_.hidden||_.type==="serial-number"||!p.readonly&&_.widget==="readonly"||!p.readonly&&_.type==="subtable"&&!p.subtable||p.subtable&&_.type!=="subtable")&&i.push(`WORKFLOW_TASK_PAGE_RESOURCE_FIELD_INVALID:${a}.${p.code}`),p.subtable&&_?.subtable){let E=_.subtable;f+=E.maxRows??20,(u.has(E.resourceCode)||!Number.isSafeInteger(E.maxRows??20)||(E.maxRows??20)<1||(E.maxRows??20)>ci||!Ft.test(E.foreignKey)||!Ft.test(E.orderField)||E.foreignKey===E.orderField)&&i.push(`WORKFLOW_TASK_SUBTABLE_RELATION_INVALID:${a}.${p.code}`),u.add(E.resourceCode);let A=o?.get(E.resourceCode);o&&(!A||!["uuid","resource-ref.single"].includes(A.get(E.foreignKey)?.type||"")||A.get(E.orderField)?.type!=="number.integer")&&i.push(`WORKFLOW_TASK_SUBTABLE_RELATION_INVALID:${a}.${p.code}`);for(let O of Array.isArray(p.subtable.fields)?p.subtable.fields:[]){if(!O||typeof O.code!="string")continue;let b=A?.get(O.code);(O.code===E.foreignKey||O.code===E.orderField||A&&(!b||b.system||b.hidden||b.type==="subtable"||!O.readonly&&(b.widget==="readonly"||b.type==="serial-number")))&&i.push(`WORKFLOW_TASK_SUBTABLE_FIELD_UNSUPPORTED:${a}.${p.code}.${O.code}`)}}else p.subtable&&t&&i.push(`WORKFLOW_TASK_SUBTABLE_RELATION_INVALID:${a}.${p.code}`)}p.subtable&&(p.readonly||!ve(p.subtable,["fields","create","delete","reorder"])||["create","delete","reorder"].some(_=>p.subtable?.[_]!==void 0&&typeof p.subtable[_]!="boolean")||!Array.isArray(p.subtable.fields)||p.subtable.fields.some(_=>_?.subtable)?i.push(`WORKFLOW_TASK_SUBTABLE_PAGE_INVALID:${a}.${p.code}`):i.push(...jt({taskPages:{child:{title:"\u5B50\u884C",fields:p.subtable.fields}}},o?.get(t?.get(p.code)?.subtable?.resourceCode||"")).map(_=>`${_}:${a}.${p.code}`)))}(f>Math.min(n,ai)||f<0||!Number.isSafeInteger(f)||!Number.isSafeInteger(n)||n<1)&&i.push(`WORKFLOW_TASK_SUBTABLE_BUDGET_EXCEEDED:${a}`)}for(let[d,s]of Object.entries(e.nodes||{}))ae(s)&&s.taskPageCode!==void 0&&(!["approval","correction"].includes(s.kind)||typeof s.taskPageCode!="string"||!ae(r)||!Object.hasOwn(r,s.taskPageCode)?i.push(`WORKFLOW_TASK_PAGE_NOT_FOUND:${d}`):Array.isArray(r[s.taskPageCode]?.fields)&&r[s.taskPageCode].fields.some(a=>a&&(s.fieldPolicy?.fields?.[a.code]||s.fieldPolicy?.default)==="hidden")&&i.push(`WORKFLOW_TASK_PAGE_FIELD_HIDDEN:${d}`));return i}function li(e,t){return e.fields.map(o=>({code:o.code,visible:o.visibleWhen===void 0||!!$e(o.visibleWhen,t),readonly:o.readonly===!0,required:o.required===!0||o.requiredWhen!==void 0&&!!$e(o.requiredWhen,t)}))}var Oe=class extends Error{constructor(o,n){super(o);this.code=o;this.field=n}code;field;rowIndex;childField};function Gd(e,t){return t.map(o=>({key:String(o.id),id:String(o.id),revision:Number(o.revision),state:"persisted",values:Object.fromEntries(li({title:"\u5B50\u884C",fields:e.fields},o).filter(n=>n.visible&&!n.readonly).map(n=>[n.code,o[n.code]??null]))}))}function qd(e,t,o,n,i,r=!0,d=0){let s=e.subtable,a=_=>{throw new Oe(_,e.code)};if(!s||!Number.isSafeInteger(t)||t<1||t>ci||!Number.isSafeInteger(d)||d<0||d>t||!Array.isArray(n)||n.length>2*t||Vn(n)>Ln||!xt(n))return a("WORKFLOW_TASK_SUBTABLE_VALUES_INVALID");let c=new Map(o.map(_=>[String(_.id),_])),f=new Set,u=new Set,p=[];for(let _ of n){if(!ve(_,["key","state","id","revision","values"])||typeof _.key!="string"||!Wr.test(_.key)||f.has(_.key)||!["created","persisted","deleted"].includes(_.state)||!ae(_.values))return a("WORKFLOW_TASK_SUBTABLE_ROW_INVALID");if(f.add(_.key),_.state==="created"){if(!s.create||_.id!==void 0||_.revision!==void 0||c.has(_.key))return a("WORKFLOW_TASK_SUBTABLE_CREATE_FORBIDDEN")}else{if(typeof _.id!="string"||_.id!==_.key||!Wr.test(_.id)||u.has(_.id)||!Number.isSafeInteger(_.revision)||_.revision<1||!c.has(_.id))return a("WORKFLOW_TASK_SUBTABLE_SCOPE_CONFLICT");if(u.add(_.id),r&&Number(c.get(_.id).revision)!==_.revision)return a("WORKFLOW_TASK_SUBTABLE_REVISION_CONFLICT")}if(_.state==="deleted"){if(!s.delete||Object.keys(_.values).length)return a("WORKFLOW_TASK_SUBTABLE_DELETE_FORBIDDEN");continue}try{Gr({title:e.code,fields:s.fields},_.id?c.get(_.id):{},_.values,i)}catch(E){if(!(E instanceof Oe))throw E;let A=new Oe(E.code,e.code);throw A.rowIndex=p.length,E.field!==void 0&&(A.childField=E.field),A}p.push(_)}if(u.size!==c.size)return a("WORKFLOW_TASK_SUBTABLE_SCOPE_CONFLICT");if(p.length>t)return a("WORKFLOW_TASK_SUBTABLE_MAX_ROWS_EXCEEDED");if(i&&p.length<d)return a("WORKFLOW_TASK_SUBTABLE_MIN_ROWS_NOT_MET");if(!s.reorder){let _=o.filter(A=>p.some(O=>O.id===String(A.id))).map(A=>String(A.id)),E=p.filter(A=>A.state==="persisted").map(A=>A.id);if(!xe(_,E)||p.some((A,O)=>A.state==="created"&&p.slice(O+1).some(b=>b.state==="persisted")))return a("WORKFLOW_TASK_SUBTABLE_REORDER_FORBIDDEN")}return n}function xt(e,t={members:0},o=0){return++t.members>5e4||o>12?!1:e===null||typeof e=="boolean"?!0:typeof e=="string"?e.length<=Ln:typeof e=="number"?Number.isFinite(e):Array.isArray(e)?e.length<=1e3&&e.every(n=>xt(n,t,o+1)):ae(e)&&Object.entries(e).every(([n,i])=>!Je.has(n)&&xt(i,t,o+1))}function Gr(e,t,o,n){if(!ae(o)||Vn(o)>Ln||!xt(o))throw new Oe("WORKFLOW_TASK_FORM_VALUES_INVALID");let i={...t,...o},r=new Map(li(e,i).map(d=>[d.code,d]));for(let d of Object.keys(o)){let s=r.get(d);if(!s||s.readonly||!s.visible)throw new Oe("WORKFLOW_TASK_FORM_FIELD_NOT_EDITABLE",d)}if(n)for(let d of r.values()){let s=i[d.code],a=e.fields.find(c=>c.code===d.code)?.subtable&&Array.isArray(s)?s.every(c=>ae(c)&&c.state==="deleted"):Kr(s);if(d.visible&&!d.readonly&&d.required&&a)throw new Oe("WORKFLOW_TASK_FORM_REQUIRED",d.code)}return i}function zd(e,t,o){let n=JSON.parse(JSON.stringify(t));for(let[d,s]of Object.entries(e.subject?.factProjection||{})){let a=d.split(".");if(!a.length||a.length>12||d.length>128||a[0]==="steps"||a.some(f=>!Ft.test(f)||Je.has(f)))throw new Oe("WORKFLOW_TASK_FORM_FACT_PROJECTION_INVALID");if(!Object.hasOwn(o,s))throw new Oe("WORKFLOW_TASK_FORM_FACT_FIELD_MISSING",s);let c=n;for(let f of a.slice(0,-1))c=c[f]=ae(c[f])?c[f]:{};c[a.at(-1)]=o[s]===void 0?void 0:JSON.parse(JSON.stringify(o[s]))}let i=new Set,r=Object.values(e.nodes||{}).filter(d=>d.kind==="action");for(let d=0;d<=r.length;d++){let s=!1;for(let a of r)ae(n.steps)&&Object.hasOwn(n.steps,a.id)&&Object.values(a.inputs||{}).some(c=>c.source==="fact"&&!xe(di(t,c.path),di(n,c.path)))&&(delete n.steps[a.id],i.add(a.id),s=!0);if(!s)break}return{facts:n,invalidatedNodeIds:[...i].sort()}}function Jd(e,t,o){let n=e.nodes||{};for(let i of o){let r=new Set,d=new Map,s=a=>{if(a===i)return!0;if(d.has(a))return d.get(a);if(r.has(a)||r.size>200)return!1;let c=n[a];if(!ae(c)||c.kind==="end")return!1;r.add(a);let f=c.kind==="approval"?[c.onApprove]:c.kind==="condition"?[...(c.branches||[]).map(p=>p.target),c.otherwise]:[c.next],u=f.length>0&&f.every(p=>typeof p=="string"&&s(p));return r.delete(a),d.set(a,u),u};if(!s(t))return!1}return!0}var lf=256,uf=64,ff=262144,Hd=/^[a-z][a-z0-9_-]{0,127}$/,Yd=/^[A-Za-z][A-Za-z0-9_]*(?:\.[A-Za-z][A-Za-z0-9_]*)*$/,zr=new Set(["__proto__","prototype","constructor"]),we=e=>!!e&&typeof e=="object"&&!Array.isArray(e),Ut=(e,t)=>Object.keys(e).every(o=>t.includes(o)),He=(e,t)=>typeof e=="string"&&e.trim().length>0&&e.length<=t&&!/[\u0000-\u001f\u007f]/.test(e),Pe=e=>typeof e=="string"&&Hd.test(e)&&!zr.has(e),Jr=e=>typeof e=="string"&&e.length<=255&&Yd.test(e)&&!e.split(".").some(t=>zr.has(t)),Xd=e=>we(e)&&Ut(e,["dimension","valueFrom","value"])&&Pe(e.dimension)&&(He(e.value,255)&&e.valueFrom===void 0||Jr(e.valueFrom)&&e.value===void 0),qr=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)),Wt={type:"string",pattern:"^[a-z][a-z0-9_-]{0,127}$"},ui={type:"string",minLength:1,maxLength:128},Zd={type:"object",additionalProperties:!1,required:["policyCode","title","strategy","dimensions","sources"],properties:{policyCode:Wt,title:ui,strategy:{enum:["replace_then_append","replace_only"]},dimensions:{type:"object",maxProperties:8,propertyNames:Wt,additionalProperties:{type:"object",additionalProperties:!1,required:["title","valueFrom"],properties:{title:ui,valueFrom:{type:"string",minLength:1,maxLength:255}}}},sources:{type:"object",minProperties:1,maxProperties:16,propertyNames:Wt,additionalProperties:{type:"object",additionalProperties:!1,required:["title","provider","roleCode"],properties:{title:ui,provider:{enum:["app_role","app_role_in_scope"]},roleCode:Wt,scope:{type:"object",additionalProperties:!1,required:["dimension"],properties:{dimension:Wt,value:{type:"string",minLength:1,maxLength:255},valueFrom:{type:"string",minLength:1,maxLength:255}}}}}}}};function Mt(e){if(!we(e)||!Ut(e,["policyCode","title","strategy","dimensions","sources"])||!Pe(e.policyCode)||!He(e.title,128)||!["replace_then_append","replace_only"].includes(e.strategy))return["WORKFLOW_V2_ROUTING_POLICY_INVALID"];let t=[];return(!we(e.dimensions)||Object.keys(e.dimensions).length>8||Object.entries(e.dimensions).some(([o,n])=>!Pe(o)||!we(n)||!Ut(n,["title","valueFrom"])||!He(n.title,128)||!Jr(n.valueFrom)))&&t.push("WORKFLOW_V2_ROUTING_DIMENSIONS_INVALID"),(!we(e.sources)||Object.keys(e.sources).length<1||Object.keys(e.sources).length>16||Object.entries(e.sources).some(([o,n])=>!Pe(o)||!we(n)||!Ut(n,["title","provider","roleCode","scope"])||!He(n.title,128)||!Pe(n.roleCode)||!["app_role","app_role_in_scope"].includes(n.provider)||(n.provider==="app_role_in_scope"?!Xd(n.scope):n.scope!==void 0)))&&t.push("WORKFLOW_V2_ROUTING_SOURCES_INVALID"),t}function Qd(e,t){if(Mt(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(!we(i)||!Ut(i,["ruleCode","title","enabled","workflowCode","nodeId","matches","sourceCode","effect","priority","validFrom","validTo"])||!Pe(i.ruleCode)||!He(i.title,128)||typeof i.enabled!="boolean"||!Pe(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&&!Pe(i.workflowCode)||i.nodeId!==void 0&&(!Pe(i.nodeId)||i.workflowCode===void 0)||i.validFrom!==void 0&&!qr(i.validFrom)||i.validTo!==void 0&&!qr(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),(!we(i.matches)||Object.entries(i.matches).some(([r,d])=>!Object.hasOwn(e.dimensions,r)||!Array.isArray(d)||d.length<1||d.length>64||new Set(d).size!==d.length||d.some(s=>!He(s,255))))&&o.push(`WORKFLOW_V2_ROUTING_MATCH_INVALID:${i.ruleCode}`)}return[...new Set(o)]}function Hr(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 fi(e){let t=[],o=new Map;for(let n of e)for(let[i,r]of Object.entries(n.bindings||{})){if(!we(r)||r.routing===void 0)continue;let d=Mt(r.routing);if(d.length){t.push(...d.map(c=>`${c}:${i}`));continue}let s=Hr(r.routing),a=o.get(r.routing.policyCode);a&&a!==s&&t.push(`WORKFLOW_V2_ROUTING_POLICY_CONFLICT:${r.routing.policyCode}`),o.set(r.routing.policyCode,s)}return[...new Set(t)]}function ec(e,t){let o={};for(let[n,i]of Object.entries(e.dimensions)){let r=t;for(let d of i.valueFrom.split("."))r=we(r)&&Object.hasOwn(r,d)?r[d]:void 0;if(!(typeof r=="string"&&He(r,255)||typeof r=="number"&&Number.isFinite(r)||typeof r=="boolean"))throw new Error(`WORKFLOW_V2_ROUTING_FACT_REQUIRED:${n}`);o[n]=String(r)}return o}function tc(e,t,o){let n=t.filter(c=>c.enabled&&(!c.validFrom||Date.parse(c.validFrom)<=o.at)&&(!c.validTo||Date.parse(c.validTo)>o.at)&&(!c.workflowCode||c.workflowCode===o.workflowCode)&&(!c.nodeId||c.nodeId===o.nodeId)&&Object.entries(c.matches).every(([f,u])=>u.includes(o.facts[f])));if(n.length>64)throw new Error("WORKFLOW_V2_ROUTING_MATCH_LIMIT_EXCEEDED");let i=(c,f)=>f.priority-c.priority||+!!c.workflowCode-+!!f.workflowCode||+!!c.nodeId-+!!f.nodeId||(c.ruleCode<f.ruleCode?-1:c.ruleCode>f.ruleCode?1:0),r=n.filter(c=>c.effect==="replace").sort(i);if(r.length>1&&r[0].priority===r[1].priority)throw new Error("WORKFLOW_V2_ROUTING_REPLACE_CONFLICT");let d=r[0],s=d&&e.strategy==="replace_only"?[]:n.filter(c=>c.effect==="append").sort(i),a=[...d?[d]:[],...s];return{matched:n.sort(i),replacement:d,applied:a,ignored:n.filter(c=>!a.includes(c))}}var pi="^[A-Za-z][A-Za-z0-9_]{0,62}$",Yr="^[a-z][a-z0-9]*(?:[-_.][a-z0-9]+)*$",nc={type:"object",additionalProperties:!1,required:["mode","resourceCode","subtables"],properties:{mode:{const:"create"},resourceCode:{type:"string",maxLength:64,pattern:Yr},subtables:{type:"array",minItems:1,maxItems:16,items:{type:"object",additionalProperties:!1,required:["fieldCode","fieldCodes"],properties:{fieldCode:{type:"string",pattern:pi},fieldCodes:{type:"array",minItems:1,maxItems:200,uniqueItems:!0,items:{type:"string",pattern:pi}}}}}}};function Bt(e){let t=n=>!!(n&&typeof n=="object"&&!Array.isArray(n)),o=n=>typeof n=="string"&&new RegExp(pi).test(n)&&!["__proto__","prototype","constructor"].includes(n);if(!t(e)||Object.keys(e).some(n=>!["mode","resourceCode","subtables"].includes(n))||e.mode!=="create"||typeof e.resourceCode!="string"||e.resourceCode.length>64||!new RegExp(Yr).test(e.resourceCode)||!Array.isArray(e.subtables)||e.subtables.length<1||e.subtables.length>16||e.subtables.some(n=>!t(n)||Object.keys(n).some(i=>!["fieldCode","fieldCodes"].includes(i))||!o(n.fieldCode)||!Array.isArray(n.fieldCodes)||n.fieldCodes.length<1||n.fieldCodes.length>200||new Set(n.fieldCodes).size!==n.fieldCodes.length||n.fieldCodes.some(i=>!o(i)))||new Set(e.subtables.map(n=>n.fieldCode)).size!==e.subtables.length)throw new Error("WORKFLOW_OWNED_SUBJECT_CREATE_INVALID")}function oc(e){return Bt(e),{mode:"create",resourceCode:e.resourceCode,subtables:e.subtables.map(t=>({fieldCode:t.fieldCode,fieldCodes:[...t.fieldCodes].sort()})).sort((t,o)=>t.fieldCode.localeCompare(o.fieldCode))}}function mi(e,t,o){Bt(e);let n=s=>{throw new Error(`WORKFLOW_OWNED_SUBJECT_${s}`)},i=t.get(e.resourceCode);i||n("RESOURCE_MISSING");let r=new Set,d=0;for(let s of e.subtables){let a=i.get(s.fieldCode),c=a?.subtable,f=t.get(c?.resourceCode);(a?.type!=="subtable"||!f||c.resourceCode===e.resourceCode||r.has(c.resourceCode))&&n("RELATION_INVALID"),r.add(c.resourceCode);let u=c.maxRows??20;(!Number.isSafeInteger(u)||u<1||u>500)&&n("BUDGET_EXCEEDED"),d+=u;for(let p of s.fieldCodes){let _=f.get(p);(!_||["serial-number","subtable"].includes(_.type)||[c.foreignKey,c.orderField].includes(p))&&n("FIELD_INVALID"),["file","image","signature","text.rich"].includes(_.type)&&!o.some(E=>E.resourceCode===c.resourceCode&&E.fieldCodes.includes(p)&&E.intents.includes("create"))&&n("FILE_ACCESS_REQUIRED")}}d>1e3&&n("BUDGET_EXCEEDED")}var Kn=ra(require("crypto"),1);var Xr="native-4",_i="2.0.0-alpha.5",Zr={"application-native-2":"1.0.0","application.extended-declaration-capacity":"1.0.0","application.extended-artifact-capacity":"1.0.0","application.development-configuration":"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.extended-owned-subtable-capacity":"1.0.0","data.aggregate-owned-subtable-capacity":"1.0.0","data.business-commands":"1.0.0","data.record-edit":"1.0.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.1.0","data.user-candidates":"1.0.0","data.user-candidate-launch-scope":"1.0.0","data.datetime-minute-precision":"1.0.0","data.subtable-minimum-rows":"1.0.0","data.managed-concurrency":"1.0.0","data.managed-concurrency.durable":"1.0.0","workflow.named-input-sources":"1.0.0","workflow.approved-delegation":"1.0.0","directory-v2":"1.0.0","directory.selected-user":"1.0.0","directory.current-initiator-phone":"1.0.0","events-v2":"1.0.0","events.durable-receipts":"1.0.0","events.capture-policy":"1.0.0","events.date-source-projection":"1.0.0","events.native-data-actions":"1.0.0","workflow-kernel-v2":"1.0.0","workflow.business-data-command":"1.0.0","workflow.native-stage-guard":"1.0.0","workflow.launch-preflight":"1.0.0","workflow.optional-rejection-comment":"1.0.0","workflow.optional-operation-reason":"1.0.0","workflow.optional-withdrawal-reason":"1.0.0","data.transaction-actor-authority":"1.0.0","data.authenticated-public-projection":"1.0.0","data.record-print":"1.0.0","data.workflow-record-deletion":"1.0.0","data.record-comments":"1.0.0","workflow.record-history-read":"1.0.0","workflow.rejection-notification":"1.0.0","workflow.instance-cancellation-policy":"1.0.0","workflow.node-administration":"1.0.0","workflow.assignment-routing":"1.0.0","workflow.role-union":"1.0.0","workflow.role-input-selection":"1.0.0","workflow.named-owned-create":"1.0.0","workflow.owned-initial-facts":"1.0.0","workflow.initiator-correction":"1.0.0","workflow.correction-business-command":"1.0.0","workflow.role-references":"1.0.0","workflow.delegation-management":"1.0.0","workflow.automatic-cc":"1.0.0","workflow.approval-empty-policy":"1.0.0","workflow.initiator-approval-policy":"1.0.0","workflow.completion-deadline":"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","workflow.step-data-transaction":"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 Af=5,Ef=20,If=50,yf=50,bf=100,_t=class extends Error{constructor(o,n){super(o);this.code=o;this.pointer=n;this.name="NativeDataPolicyExpressionV2Error"}code;pointer};function Gt(e,t){let o=[],n=(i,r,d)=>{d>5&&Kt("NATIVE_DATA_POLICY_EXPRESSION_DEPTH_EXCEEDED",r);let s=Qr(i,r),a=["allOf","anyOf"].filter(u=>u in s);if(a.length===0){o.push({rule:s,pointer:r}),o.length>50&&Kt("NATIVE_DATA_POLICY_EXPRESSION_LEAVES_EXCEEDED",r);return}let c=a[0],f=s[c];(a.length!==1||Object.keys(s).length!==1||!Array.isArray(f)||f.length<1||f.length>20)&&Kt("NATIVE_DATA_POLICY_EXPRESSION_GROUP_INVALID",r),f.forEach((u,p)=>n(u,`${r}/${c}/${p}`,d+1))};return n(e,t,1),o}function Ai(e,t){Gt(e,t);let o=(n,i)=>{let r=Qr(n,i);if(Array.isArray(r.allOf))return gi(r.allOf.flatMap((d,s)=>o(d,`${i}/allOf/${s}`)),i);if(Array.isArray(r.anyOf)){let d=[[]];return r.anyOf.forEach((s,a)=>{let c=o(s,`${i}/anyOf/${a}`);d=gi(d.flatMap(f=>c.map(u=>[...f,...u])),i)}),d}return[[r]]};return gi(o(e,t),t)}function gi(e,t){let o=e.reduce((n,i)=>n+i.length,0);return(e.length>50||o>100)&&Kt("NATIVE_DATA_POLICY_EXPRESSION_EXPANSION_EXCEEDED",t),e}function Qr(e,t){return(!e||typeof e!="object"||Array.isArray(e))&&Kt("NATIVE_DATA_POLICY_EXPRESSION_NODE_INVALID",t),e}function Kt(e,t){throw new _t(e,t)}var B=Object.freeze({perspectives:100,resources:512,dataPolicies:512,roles:256,subjectReadSurfaces:50,capabilities:4096,operations:500,eventConsumers:100,eventProducers:1e3,eventSchemas:100,eventTypes:500,workflows:512,routes:2048,adminPages:2048,adminNavigationGroups:100,adminNavigationItems:1024});function Ei(e){let t=(e.surface?.mutationOwner||"native")==="native";return["query","get","create","update","delete"].filter(o=>{let n=e.surface?.generated;return o==="query"?n?.list??!0:o==="get"?n?.detail??!0:n?.[o]??t})}function Fn(e){let t=(e.data?.resources||[]).filter(o=>o.status!=="retired").reduce((o,n)=>o+Ei(n).length,0)+(e.backend?.operations||[]).filter(o=>o.ai).length;return(e.data?.resources?.length||0)>100||(e.authz?.dataPolicies?.length||0)>100||(e.authz?.roles?.length||0)>100||(e.authz?.capabilities?.length||0)>2e3||[e.workflows?.definitions,e.workflows?.bindings,e.workflows?.activations].some(o=>(o?.length||0)>100)||(e.frontend?.routes?.length||0)>500||t>500||(e.frontend?.admin?.navigation||[]).reduce((o,n)=>o+n.items.length,0)>500}var Ae=Object.freeze({configBytes:4194304,contractBytes:8388608,depth:40,stringBytes:1048576,legacyNodes:1e5,extendedNodes:25e4});function qt(e){let t=0,o=[[e][Symbol.iterator]()];for(;o.length;){let n=o[o.length-1].next();if(n.done){o.pop();continue}if(++t>Ae.legacyNodes)return!0;if(Array.isArray(n.value))o.push(n.value.values());else if(n.value&&typeof n.value=="object"){let i=n.value;o.push((function*(){for(let r of Object.keys(i))i[r]!==void 0&&(yield i[r])})())}}return!1}var ic="openxiangda.config-bundle/v3",As="openxiangda.contract-bundle/v3",es="openxiangda.native-configuration-projection/v1",Jt=Xr,rc=/^[a-f0-9]{64}$/,sc=/^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/,ac=/^app:[a-z][a-z0-9]*(?:-[a-z0-9]+)*:[A-Za-z0-9:._*-]+$/,dc=/^[a-z][a-z0-9]*(?:[-_.][a-z0-9]+)*$/,cc=/^[a-z][a-z0-9]*(?:[-.][a-z0-9]+)*$/,lc=/^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/,uc=/^[A-Za-z][A-Za-z0-9_]{0,62}$/,ts=/^[A-Za-z][A-Za-z0-9_]{0,127}$/,fc=/^[a-z][a-z0-9]*(?:[-_][a-z0-9]+)*$/,pc=/^[A-Z][A-Z0-9_]*$/,mc=/^[a-z][a-z0-9-]{2,63}$/,_c=/^[A-Za-z][A-Za-z0-9_-]{0,127}$/,gc=/^[A-Za-z][A-Za-z0-9_.]{0,127}$/,Ac=16,Ec=2*1024,Ic=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"]),yc=new Set(["overview","database","operations","workflow","members","calendar","document","folder","settings"]),bc=new Set(["approve","reject","return","transfer","delegate","add_assignee","resubmit","withdraw","terminate","admin_reassign","admin_override","retry_resolution"]),Oc=Ae.configBytes,Nc=Ae.contractBytes,Tc=Ae.depth,bi=Ae.stringBytes,Rc="openxiangda.event-handler-manifest/v2",Es="openxiangda.application-route-manifest/v3",ns=64,Is=new Set(["id","revision","created_by","updated_by","created_at","updated_at"]),xn=["openxiangda.data.record.created.v2","openxiangda.data.record.updated.v2","openxiangda.data.record.deleted.v2"],jn=["openxiangda.workflow.node.skipped.v2",lt,"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"],Cc=new Set(jn),Wn=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 hc(e){let t=w(e.appCode,"/appCode",128);sc.test(t)||m("NATIVE_CONFIG_APP_CODE_INVALID","/appCode");let o=Ni(e.expectedConfigDigest,"/expectedConfigDigest"),n=Ni(e.expectedContractDigest,"/expectedContractDigest"),i=ms(e.configBytes,Oc,"/configBytes","NATIVE_CONFIG_ARTIFACT_TOO_LARGE"),r=ms(e.contractBytes,Nc,"/contractBytes","NATIVE_CONTRACT_ARTIFACT_TOO_LARGE");_s(i,o,"/configBytes","NATIVE_CONFIG_DIGEST_MISMATCH"),_s(r,n,"/contractBytes","NATIVE_CONTRACT_DIGEST_MISMATCH");let d=ps(i,"/configBytes","NATIVE_CONFIG_JSON_INVALID","NATIVE_CONFIG_NOT_CANONICAL"),s=ps(r,"/contractBytes","NATIVE_CONTRACT_JSON_INVALID","NATIVE_CONTRACT_NOT_CANONICAL");Ii(d,"/config",Ae.extendedNodes),Ii(s,"/contracts",Ae.extendedNodes),qt(d)||Ii(s,"/contracts",Ae.legacyNodes);let a=d,c=s;Sc(a,t),Dc(c,t,o);let f=kc(a,o,c.generatorVersion);Al(f,c,a),Q(f)!==Q(c)&&m("NATIVE_CONTRACT_CLOSURE_MISMATCH",Ti(f,c,"/contracts"));let u={authz:{appCode:t,...a.authz,perspectives:a.perspectives,capabilityCatalog:f.capabilities},data:{appCode:t,resources:a.data.resources,resourceContracts:f.resources,...f.concurrency?{concurrency:f.concurrency}:{},...f.subjectReadSurfaces?{subjectReadSurfaces:f.subjectReadSurfaces}:{}},events:{appCode:t,...a.events,consumers:f.eventConsumers,producers:f.eventProducers,handlerManifest:f.eventHandlerManifest,eventTypes:f.eventTypes,capturePlans:bs({resources:a.data.resources,dataPolicies:a.authz.dataPolicies,subscriptions:f.eventConsumers,capturePolicies:a.events.capturePolicies})},workflows:{appCode:t,...a.workflows,contracts:f.workflows},runtime:{appCode:t,requirements:a.runtime,backend:a.backend,frontend:a.frontend},contracts:f},p={authz:gt(u.authz),data:gt(u.data),events:gt(u.events),workflows:gt(u.workflows),runtime:gt(u.runtime),contracts:gt(u.contracts)},_={configDigest:o,contractDigest:n,generatorVersion:c.generatorVersion},E=ys(a),A={schemaVersion:es,compilerContractVersion:Jt,appCode:t,source:_,projections:p,requiredPlatformCapabilities:E,aggregateDigest:Z({schemaVersion:es,compilerContractVersion:Jt,appCode:t,source:_,requiredPlatformCapabilities:E,projectionDigests:Object.fromEntries(Object.entries(p).map(([O,b])=>[O,b.digest]))})};return vs(A)}function os(e,t){let o=e.subject,n=t.find(r=>r.code===o?.resourceCode),i=new Set(Object.values(o?.factProjection||{}));return!!n?.schema?.fields?.some(r=>r.type==="subtable"&&i.has(r.code))}function ys(e){let t=e.authz.roles,o=e.data.resources,n=e.backend.operations,i=n.filter(l=>l.platformAccess?.directory?.mode==="current-initiator"&&l.platformAccess.directory.fields.includes("phone")),r=(e.data.concurrency?.commands||[]).filter(l=>l.execution?.directory?.mode==="current-initiator"&&l.execution.directory.fields.includes("phone")),d=t.some(l=>l.capabilities.some(y=>y.endsWith(":directory:read")))||o.some(l=>l.schema.fields.some(y=>["user.single","user.multiple","department.single","department.multiple"].includes(y.type)))||n.some(l=>l.platformAccess?.directory),s=!!(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),c=e.workflows.definitions.some(l=>l.definition.rejectionNotification!==void 0)||n.some(l=>l.platformAccess?.notification)||e.events.subscriptions.some(l=>l.platformAccess?.notification),f=(l,y,R=!1)=>{let h=o.find($=>$.code===l.definition.subject?.resourceCode)?.schema.fields||[];return Object.values(l.definition.taskPages||{}).some($=>$.fields.some(k=>{if(k.readonly)return!1;let M=h.find(Y=>Y.code===k.code);if(!R&&M&&y.includes(M.type))return!0;if(!k.subtable||!M?.subtable)return!1;let V=o.find(Y=>Y.code===M.subtable.resourceCode)?.schema.fields||[];return k.subtable.fields.some(Y=>!Y.readonly&&V.some(ne=>ne.code===Y.code&&y.includes(ne.type)))}))},u=e.workflows.definitions.filter(l=>f(l,["file","image","signature","text.rich"])),p=e.workflows.definitions.filter(l=>f(l,["signature","text.rich"])),_=e.workflows.definitions.filter(l=>f(l,["file","image","signature","text.rich"],!0)),E=e.workflows.definitions.filter(l=>l.launch.mode==="standalone"||l.launch.mode==="hidden-handoff"),A=n.some(l=>l.platformAccess?.workflow)||E.length>0,O=E.filter(l=>{let y=l.launch.submission;if(!y)return!1;let R=o.find(h=>h.code===l.definition.subject.resourceCode);return[y.create,y.existing].some(h=>h&&Object.values(h.inputs).some($=>$.source==="field"&&R?.schema.fields.some(k=>k.code===$.fieldCode&&k.type.startsWith("resource-ref.")&&k.source)))}),b={resources:o},g={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(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[...qt(e)?[{code:"application.extended-artifact-capacity",declaration:Ae}]:[],...Fn(e)?[{code:"application.extended-declaration-capacity",declaration:{resources:e.data.resources.length,policies:e.authz.dataPolicies.length,roles:e.authz.roles.length,capabilities:e.authz.capabilities.length,definitions:e.workflows.definitions.length,bindings:e.workflows.bindings.length,activations:e.workflows.activations.length,routes:e.frontend.routes.length,navigationItems:e.frontend.admin.navigation.reduce((l,y)=>l+y.items.length,0)}}]:[],...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?.dataCommands)?[{code:"data.business-commands",declaration:n.filter(l=>l.platformAccess?.dataCommands)}]:[],...e.authz.dataPolicies.some(l=>l.publicRead)?[{code:"data.authenticated-public-projection",declaration:e.authz.dataPolicies.filter(l=>l.publicRead)}]:[],...n.some(l=>l.platformAccess?.roleAssertions?.actorAuthority)?[{code:"data.transaction-actor-authority",declaration:n.filter(l=>l.platformAccess?.roleAssertions?.actorAuthority)}]:[],...n.some(l=>l.platformAccess?.workflowStage)?[{code:"workflow.native-stage-guard",declaration:n.filter(l=>l.platformAccess?.workflowStage)}]:[],...n.some(l=>l.platformAccess?.recordEdit)?[{code:"data.record-edit",declaration:n.filter(l=>l.platformAccess?.recordEdit)}]:[],...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:I},{code:"authz.native-batch-explain",declaration:g},{code:"authz.native-management",declaration:g},{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:b},{code:"data.native-golden-crud",declaration:b}]:[],...o.some(l=>l.recordComments!==void 0)?[{code:"data.record-comments",declaration:b}]:[],...o.some(l=>l.recordDeletion!==void 0)?[{code:"data.workflow-record-deletion",declaration:b}]:[],...o.some(l=>l.recordPrint!==void 0)?[{code:"data.record-print",declaration:b}]:[],...o.some(l=>l.workflowHistory!==void 0)?[{code:"workflow.record-history-read",declaration:b}]:[],...o.some(uo)?[{code:"data.audit-read-access",declaration:b}]:[],...d?[{code:"directory-v2",declaration:{roles:t.map(l=>({code:l.code,capabilities:l.capabilities.filter(y=>y.endsWith(":directory:read"))})),resources:o.map(l=>({code:l.code,fields:l.schema.fields.filter(y=>["user.single","user.multiple","department.single","department.multiple"].includes(y.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}))}]:[],...i.length||r.length?[{code:"directory.current-initiator-phone",declaration:{operations:i.map(l=>({code:l.code,directory:l.platformAccess.directory})),commands:r.map(l=>({code:l.code,directory:l.execution.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}]:[],...e.events.dateTriggers.some(l=>si(l.resourceCode,e.events.subscriptions.filter(y=>y.eventTypes.includes(l.eventType)),e.data.resources.find(y=>y.code===l.resourceCode)).length>0)?[{code:"events.date-source-projection",declaration:{triggers:e.events.dateTriggers,subscriptions:e.events.subscriptions}}]:[],...s?[{code:"events-v2",declaration:e.events},{code:"events.durable-receipts",declaration:e.events}]:[],...tn(e.data.resources)?[{code:"data.extended-owned-subtable-capacity",declaration:e.data.resources.filter(l=>tn([l]))}]:[],...en(e.data.resources)?[{code:"data.aggregate-owned-subtable-capacity",declaration:e.data.resources.filter(l=>en([l]))}]:[],...e.data.resources.some(l=>l.schema.fields.some(y=>y.userCandidates!==void 0))?[{code:"data.user-candidates",declaration:e.data.resources.filter(l=>l.schema.fields.some(y=>y.userCandidates!==void 0))}]:[],...Ho(e.workflows.bindings)?[{code:"workflow.role-input-selection",declaration:e.workflows.bindings.filter(l=>Object.values(l.binding.bindings).some(y=>y.selectedInputPath!==void 0))}]:[],...zo(e.workflows.bindings)?[{code:"workflow.role-union",declaration:e.workflows.bindings.filter(l=>Object.values(l.binding.bindings).some(y=>y.roleCodes!==void 0))}]:[],...e.backend.operations.some(l=>l.platformAccess?.ownedSubject)?[{code:"workflow.named-owned-create",declaration:e.backend.operations.filter(l=>l.platformAccess?.ownedSubject)}]:[],...Zt(e.data.resources)?[{code:"data.user-candidate-launch-scope",declaration:e.data.resources.filter(l=>Zt([l]))}]:[],...sn(e.data.resources)?[{code:"data.subtable-minimum-rows",declaration:e.data.resources.filter(l=>sn([l]))}]:[],...rn(e.data.resources)?[{code:"data.datetime-minute-precision",declaration:e.data.resources.filter(l=>rn([l]))}]:[],...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=>l.definition.instanceCommands?.withdraw?.reasonRequired===!1)?[{code:"workflow.optional-withdrawal-reason",declaration:e.workflows.definitions.filter(l=>l.definition.instanceCommands?.withdraw?.reasonRequired===!1)}]:[],...e.workflows.definitions.some(l=>l.definition.rejectionNotification!==void 0)?[{code:"workflow.rejection-notification",declaration:e.workflows.definitions.filter(l=>l.definition.rejectionNotification!==void 0)}]:[],...e.workflows.definitions.some(l=>l.definition.commandHandlers!==void 0)||n.some(l=>l.platformAccess?.workflow?.businessCommands)?[{code:"workflow.business-data-command",declaration:{definitions:e.workflows.definitions.filter(l=>l.definition.commandHandlers!==void 0),operations:n.filter(l=>l.platformAccess?.workflow?.businessCommands)}}]:[],...e.workflows.definitions.some(l=>l.definition.commandHandlers?.resubmit)||n.some(l=>l.platformAccess?.workflow?.businessCommands?.includes("resubmit"))?[{code:"workflow.correction-business-command",declaration:{definitions:e.workflows.definitions.filter(l=>l.definition.commandHandlers?.resubmit),operations:n.filter(l=>l.platformAccess?.workflow?.businessCommands?.includes("resubmit"))}}]:[],...e.workflows.definitions.some(l=>l.definition.launchPreflight!==void 0)?[{code:"workflow.launch-preflight",declaration:e.workflows.definitions.filter(l=>l.definition.launchPreflight!==void 0)}]:[],...e.workflows.definitions.some(l=>l.definition.approvedDelegation!==void 0)?[{code:"workflow.approved-delegation",declaration:e.workflows.definitions.filter(l=>l.definition.approvedDelegation!==void 0)}]:[],...e.workflows.definitions.some(l=>os(l.definition,e.data.resources))?[{code:"workflow.owned-initial-facts",declaration:e.workflows.definitions.filter(l=>os(l.definition,e.data.resources))}]:[],...e.workflows.definitions.some(l=>Object.values(l.definition.nodes).some(y=>y.kind==="correction"))?[{code:"workflow.initiator-correction",declaration:e.workflows.definitions.filter(l=>Object.values(l.definition.nodes).some(y=>y.kind==="correction"))}]:[],...e.workflows.definitions.some(l=>Object.values(l.definition.nodes).some(y=>y.operationPolicy?.reject?.commentRequired===!1))?[{code:"workflow.optional-rejection-comment",declaration:e.workflows.definitions.filter(l=>Object.values(l.definition.nodes).some(y=>y.operationPolicy?.reject?.commentRequired===!1))}]:[],...e.workflows.definitions.some(l=>Object.values(l.definition.nodes).some(y=>Object.values(y.operationPolicy||{}).some(R=>R.reasonRequired===!1)))?[{code:"workflow.optional-operation-reason",declaration:e.workflows.definitions.filter(l=>Object.values(l.definition.nodes).some(y=>Object.values(y.operationPolicy||{}).some(R=>R.reasonRequired===!1)))}]:[],...O.length?[{code:"workflow.named-input-sources",declaration:O}]:[],...e.workflows.definitions.some(l=>Object.values(l.definition.nodes).some(y=>y.administration!==void 0||y.operationPolicy!==void 0))?[{code:"workflow.node-administration",declaration:e.workflows.definitions.filter(l=>Object.values(l.definition.nodes).some(y=>y.administration!==void 0||y.operationPolicy!==void 0))}]:[],...e.workflows.definitions.some(l=>Object.values(l.definition.nodes).some(y=>y.kind==="approval"&&y.emptyPolicy!==void 0))?[{code:"workflow.approval-empty-policy",declaration:e.workflows.definitions.filter(l=>Object.values(l.definition.nodes).some(y=>y.kind==="approval"&&y.emptyPolicy!==void 0))}]:[],...e.workflows.definitions.some(l=>Object.values(l.definition.nodes).some(y=>y.completionDeadline!==void 0))?[{code:"workflow.completion-deadline",declaration:e.workflows.definitions.filter(l=>Object.values(l.definition.nodes).some(y=>y.completionDeadline!==void 0))}]:[],...e.workflows.definitions.some(l=>Object.values(l.definition.nodes).some(y=>y.initiatorApprovalPolicy!==void 0))?[{code:"workflow.initiator-approval-policy",declaration:e.workflows.definitions.filter(l=>Object.values(l.definition.nodes).some(y=>y.initiatorApprovalPolicy!==void 0))}]:[],...e.workflows.definitions.some(l=>Object.values(l.definition.nodes).some(y=>y.kind==="cc"))?[{code:"workflow.automatic-cc",declaration:e.workflows.definitions.filter(l=>Object.values(l.definition.nodes).some(y=>y.kind==="cc"))}]:[],...e.workflows.definitions.some(l=>l.definition.taskPages!==void 0)?["workflow.task-page-submit","workflow.task-private-drafts"].map(l=>({code:l,declaration:e.workflows.definitions.filter(y=>y.definition.taskPages!==void 0)})):[],...u.length?[{code:"workflow.task-managed-files",declaration:u}]:[],..._.length?[{code:"workflow.task-owned-files",declaration:_}]:[],...p.length?[{code:"workflow.task-rich-fields",declaration:p}]:[],...e.workflows.definitions.some(l=>Object.values(l.definition.taskPages||{}).some(y=>y.fields.some(R=>R.subtable)))?[{code:"workflow.task-owned-subtables",declaration:e.workflows.definitions.filter(l=>Object.values(l.definition.taskPages||{}).some(y=>y.fields.some(R=>R.subtable)))}]:[],...e.workflows.definitions.some(l=>Object.values(l.definition.nodes).some(y=>y.kind==="action"))?[{code:"workflow.durable-business-step",declaration:e.workflows.definitions.filter(l=>Object.values(l.definition.nodes).some(y=>y.kind==="action"))}]:[],...e.workflows.definitions.some(l=>Object.values(l.definition.nodes).some(y=>y.kind==="action"&&y.handler.dataTransaction))?[{code:"workflow.step-data-transaction",declaration:e.workflows.definitions.filter(l=>Object.values(l.definition.nodes).some(y=>y.kind==="action"&&y.handler.dataTransaction))}]:[],...e.workflows.bindings.some(l=>Object.values(l.binding.bindings).some(y=>y.routing!==void 0))?[{code:"workflow.assignment-routing",declaration:e.workflows.bindings.filter(l=>Object.values(l.binding.bindings).some(y=>y.routing!==void 0))}]:[],...A?[{code:"business-process.durable-command",declaration:{operations:n.filter(l=>l.platformAccess?.workflow).map(l=>({code:l.code,workflow:l.platformAccess.workflow})),definitions:E,activations:e.workflows.activations.filter(l=>E.some(y=>y.definition.code===l.workflowCode))}}]:[],...c?[{code:"notification-hub-v2",declaration:{...e.workflows.definitions.some(l=>l.definition.rejectionNotification!==void 0)?{rejectionNotifications:e.workflows.definitions.filter(l=>l.definition.rejectionNotification!==void 0)}:{},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:y})=>({code:l,contractVersion:l==="data.unique-keys"?o.some(R=>Lo(R.schema.fields,R.uniqueKeys)==="1.1.0")?"1.1.0":"1.0.0":Zr[l],usageDigest:`sha256:${Z(y)}`})).sort((l,y)=>l.code===y.code?0:l.code<y.code?-1:1)}function bs(e){let t=new Map,o=new Set(e.resources.map(r=>String(r.code)));for(let[r,d]of S(e.capturePolicies===void 0?[]:e.capturePolicies,"/capturePlan/capturePolicies",100).entries()){let s=`/capturePlan/capturePolicies/${r}`,a=N(d,s);C(a,["resourceCode","mode"],s);let c=H(a.resourceCode,`${s}/resourceCode`);o.has(c)||m("NATIVE_EVENT_CAPTURE_RESOURCE_NOT_FOUND",s,{resourceCode:c}),t.has(c)&&m("NATIVE_EVENT_CAPTURE_POLICY_DUPLICATE",s,{resourceCode:c}),a.mode!=="all"&&a.mode!=="subscribed"&&m("NATIVE_EVENT_CAPTURE_MODE_INVALID",`${s}/mode`),t.set(c,a.mode)}let n=new Map(e.dataPolicies.map((r,d)=>{let s=N(r,`/capturePlan/dataPolicies/${d}`);return[String(s.code),s]})),i=e.subscriptions.map((r,d)=>N(r,`/capturePlan/subscriptions/${d}`));return e.resources.map((r,d)=>{let s=`/capturePlan/resources/${d}`,a=N(r,s),c=H(a.code,`${s}/code`),f=a.schema?N(a.schema,`${s}/schema`):a,u=new Set(S(f.fields||[],`${s}/schema/fields`,500).map((y,R)=>G(N(y,`${s}/schema/fields/${R}`).code,`${s}/schema/fields/${R}/code`))),p=a.dataPolicyCode?P(a.dataPolicyCode,`${s}/dataPolicyCode`):null,_=p?n.get(p):void 0;p&&!_&&m("NATIVE_EVENT_CAPTURE_AUTHZ_POLICY_NOT_FOUND",s,{resourceCode:c,dataPolicyCode:p});let E=new Set;for(let y of _?.rules||[])E.add(String(y.field));if(_?.readExpression)for(let y of Gt(_.readExpression,`${s}/readExpression`))E.add(String(y.rule.field));let A=new Set,O=new Set,b=new Set;for(let[y,R]of i.entries()){let h=S(R.eventTypes,`/capturePlan/subscriptions/${y}/eventTypes`,20).map(String);if(!h.some(V=>V.startsWith("openxiangda.data.")))continue;let $=N(R.filter||{},`/capturePlan/subscriptions/${y}/filter`),k=Array.isArray($.resourceCodes)?$.resourceCodes.map(String):[];if(k.length&&!k.includes(c))continue;for(let V of h)xn.includes(V)&&b.add(V);for(let V of wc($,`/capturePlan/subscriptions/${y}/filter`))A.add(V);let M=N(R.payload||{},`/capturePlan/subscriptions/${y}/payload`);for(let V of S(M.fields||[],`/capturePlan/subscriptions/${y}/payload/fields`,32))O.add(G(V,`/capturePlan/subscriptions/${y}/payload/fields`))}let g=new Set([...A,...O]),I=new Set([...g,...E]);I.size>ns&&m("NATIVE_EVENT_CAPTURE_FIELDS_LIMIT",s,{resourceCode:c,maximum:ns});for(let y of I)!u.has(y)&&!(E.has(y)&&Is.has(y))&&m("NATIVE_EVENT_CAPTURE_FIELD_NOT_FOUND",s,{resourceCode:c,field:y});let T=N(a.fieldPolicies||{},`${s}/fieldPolicies`);for(let y of g)T[y]?.mask==="omit"&&m("NATIVE_EVENT_CAPTURE_FIELD_SENSITIVE",s,{resourceCode:c,field:y});let l={resourceCode:c,...t.get(c)==="subscribed"?{capturedEventTypes:[...b].sort()}:{},filterFields:[...A].sort(),projectionFields:[...O].sort(),authorizationFields:[...E].sort(),captureFields:[...I].sort()};return{...l,digest:Z(l)}}).sort((r,d)=>r.resourceCode.localeCompare(d.resourceCode))}function wc(e,t){let o=new Set;for(let[d,s]of S(e.changes||[],`${t}/changes`,16).entries()){let a=N(s,`${t}/changes/${d}`);o.add(G(a.field,`${t}/changes/${d}/field`))}let n=N(e.changedFields||{},`${t}/changedFields`);for(let d of["anyOf","allOf","noneOf"])for(let[s,a]of S(n[d]||[],`${t}/changedFields/${d}`,32).entries())o.add(G(a,`${t}/changedFields/${d}/${s}`));let i=0,r=(d,s,a)=>{a>3&&m("NATIVE_EVENT_FILTER_DEPTH_LIMIT",s);let c=N(d,s);if(c.change){let u=N(c.change,`${s}/change`);o.add(G(u.field,`${s}/change/field`)),i+=1;return}if(c.not){r(c.not,`${s}/not`,a+1);return}let f=c.all?"all":c.any?"any":null;f||m("NATIVE_EVENT_FILTER_CONDITION_INVALID",s);for(let[u,p]of S(c[f],`${s}/${f}`,16).entries())r(p,`${s}/${f}/${u}`,a+1)};return e.where&&r(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 Sc(e,t){C(e,["schemaVersion","compilerContractVersion","appCode","perspectives","authz","backend","data","events","workflows","frontend","runtime"],"/config"),F(e.schemaVersion,ic,"/config/schemaVersion"),F(e.compilerContractVersion,Jt,"/config/compilerContractVersion"),F(e.appCode,t,"/config/appCode"),S(e.perspectives,"/config/perspectives",100);let o=N(e.authz,"/config/authz");C(o,["capabilities","roles","scopeDimensions","scopeSources","roleMembershipSources","relationshipGrantSources","dataPolicies","authorizationTransitions"],"/config/authz",["authenticatedUserRoleCode"]),S(o.capabilities,"/config/authz/capabilities",B.capabilities),S(o.roles,"/config/authz/roles",B.roles),S(o.scopeDimensions,"/config/authz/scopeDimensions",100),S(o.scopeSources,"/config/authz/scopeSources",100),S(o.roleMembershipSources,"/config/authz/roleMembershipSources",100),S(o.relationshipGrantSources,"/config/authz/relationshipGrantSources",100),S(o.dataPolicies,"/config/authz/dataPolicies",B.dataPolicies),S(o.authorizationTransitions,"/config/authz/authorizationTransitions",100);let n=N(e.backend,"/config/backend");C(n,["secrets","operations"],"/config/backend"),S(n.secrets,"/config/backend/secrets",100),S(n.operations,"/config/backend/operations",500),ul(n.secrets);let i=N(e.data,"/config/data");C(i,["resources"],"/config/data",["resourceDetailRoutes","subjectReadSurfaces","concurrency"]),S(i.resources,"/config/data/resources",B.resources),i.subjectReadSurfaces!==void 0&&S(i.subjectReadSurfaces,"/config/data/subjectReadSurfaces",B.subjectReadSurfaces),i.resourceDetailRoutes!==void 0&&S(i.resourceDetailRoutes,"/config/data/resourceDetailRoutes",100);let r=N(e.events,"/config/events");C(r,["schemas","subscriptions","timers","dateTriggers"],"/config/events",["capturePolicies"]),S(r.schemas,"/config/events/schemas",100),S(r.subscriptions,"/config/events/subscriptions",100),S(r.timers,"/config/events/timers",100),S(r.dateTriggers,"/config/events/dateTriggers",100);let d=N(e.workflows,"/config/workflows");C(d,["definitions","bindings","activations","providers","editableParameters"],"/config/workflows"),S(d.definitions,"/config/workflows/definitions",B.workflows),S(d.bindings,"/config/workflows/bindings",B.workflows),S(d.activations,"/config/workflows/activations",B.workflows),S(d.providers,"/config/workflows/providers",100),S(d.editableParameters,"/config/workflows/editableParameters",100);let s=N(e.frontend,"/config/frontend");C(s,["routes","user","admin","devicePolicy"],"/config/frontend",["authentication","publicAccess"]),S(s.routes,"/config/frontend/routes",B.routes);let a=N(s.user,"/config/frontend/user");C(a,["applicationTodoCenter"],"/config/frontend/user"),Et(a.applicationTodoCenter,"/config/frontend/user/applicationTodoCenter"),Ri(s.devicePolicy,"/config/frontend/devicePolicy"),Object.prototype.hasOwnProperty.call(s,"authentication")&&Ns(s.authentication,s.routes,e,"/config/frontend/authentication"),Object.prototype.hasOwnProperty.call(s,"publicAccess")&&qc(s.publicAccess,e,"/config/frontend/publicAccess");let c=N(s.admin,"/config/frontend/admin");C(c,["navigation"],"/config/frontend/admin",["access"]),c.access!==void 0&&qn(c.access,"/config/frontend/admin/access",e.appCode),Yc(c.navigation,"/config/frontend/admin/navigation");let f=N(e.runtime,"/config/runtime");C(f,["protocolCapabilities","health"],"/config/runtime"),L(f.protocolCapabilities,"/config/runtime/protocolCapabilities",100),C(N(f.health,"/config/runtime/health"),["livePath","readyPath","versionPath"],"/config/runtime/health"),F(f.health.livePath,"/__platform/health","/config/runtime/health/livePath"),F(f.health.readyPath,"/__platform/ready","/config/runtime/health/readyPath"),F(f.health.versionPath,"/__platform/version","/config/runtime/health/versionPath")}function Dc(e,t,o){C(e,["schemaVersion","compilerContractVersion","generatorVersion","appCode","configDigest","perspectives","resources","capabilities","operations","eventConsumers","eventProducers","eventSchemas","eventHandlerManifest","eventTypes","workflows","routes","routeManifest","adminPages","adminNavigation"],"/contracts",["authentication","publicAccess","adminAccess","subjectReadSurfaces","concurrency"]),F(e.schemaVersion,As,"/contracts/schemaVersion"),F(e.compilerContractVersion,Jt,"/contracts/compilerContractVersion"),w(e.generatorVersion,"/contracts/generatorVersion",128),F(e.appCode,t,"/contracts/appCode"),F(e.configDigest,o,"/contracts/configDigest"),S(e.perspectives,"/contracts/perspectives",B.perspectives),S(e.resources,"/contracts/resources",B.resources),e.subjectReadSurfaces!==void 0&&S(e.subjectReadSurfaces,"/contracts/subjectReadSurfaces",B.subjectReadSurfaces),S(e.capabilities,"/contracts/capabilities",B.capabilities),S(e.operations,"/contracts/operations",B.operations),S(e.eventConsumers,"/contracts/eventConsumers",B.eventConsumers),S(e.eventProducers,"/contracts/eventProducers",B.eventProducers),S(e.eventSchemas,"/contracts/eventSchemas",B.eventSchemas),N(e.eventHandlerManifest,"/contracts/eventHandlerManifest"),L(e.eventTypes,"/contracts/eventTypes",B.eventTypes),S(e.workflows,"/contracts/workflows",B.workflows),S(e.routes,"/contracts/routes",B.routes),Object.prototype.hasOwnProperty.call(e,"authentication")&&Bc(e.authentication,"/contracts/authentication"),Object.prototype.hasOwnProperty.call(e,"publicAccess")&&zc(e.publicAccess,"/contracts/publicAccess"),Object.prototype.hasOwnProperty.call(e,"adminAccess")&&qn(e.adminAccess,"/contracts/adminAccess",t),nl(e.routeManifest,"/contracts/routeManifest",t),Qc(e.adminPages,"/contracts/adminPages"),el(e.adminNavigation,"/contracts/adminNavigation")}function kc(e,t,o){let n=Pc(e);al(e,n),cl(e),dl(e),fl(e);let i=e.events.schemas.map((g,I)=>{let T=`/config/events/schemas/${I}`,l=N(g,T),y=w(l.eventType,`${T}/eventType`,255);return y.startsWith("openxiangda.")&&m("NATIVE_EVENT_SCHEMA_RESERVED",`${T}/eventType`,{eventType:y}),F(l.schemaDigest,Z(N(l.jsonSchema,`${T}/jsonSchema`)),`${T}/schemaDigest`),l}),r=new Set([...xn,...jn,...i.map(g=>String(g.eventType))]),d=new Map(e.data.resources.map(g=>[String(g.code),new Map(g.schema.fields.map(I=>[String(I.code),String(I.type)]))])),s=ee(e.events.subscriptions.map((g,I)=>{let T=`/config/events/subscriptions/${I}`,l=N(g,T),y=L(l.eventTypes,`${T}/eventTypes`,20);y.forEach((k,M)=>{r.has(k)||m("NATIVE_EVENT_TYPE_NOT_REGISTERED",`${T}/eventTypes/${M}`,{eventType:k})});let R=Vo(l,e.data.resources,T),h=vc(l.delivery,y,`${T}/delivery`),$=$c(l.platformAccess,`${T}/platformAccess`,d,e,l);return{code:P(l.code,`${T}/code`),endpointPath:Ne(l.endpointPath,`${T}/endpointPath`),eventTypes:y,filter:N(l.filter,`${T}/filter`),payload:R?.payload||N(l.payload,`${T}/payload`),...R?{execution:R.execution}:{},...$?{platformAccess:$}:{},delivery:h}}),g=>g.code),a=new Map(i.map(g=>[String(g.eventType),String(g.dataSchemaVersion)])),c=ee([...e.data.resources.flatMap(g=>xn.map(I=>({code:`data:${g.code}:${I}`,source:"data",eventType:I,dataSchemaVersion:"2.0.0",resourceCode:g.code}))),...i.map(g=>({code:`app:${g.eventType}`,source:"app",eventType:g.eventType,dataSchemaVersion:g.dataSchemaVersion})),...e.events.timers.map(g=>({code:g.code,source:"timer",eventType:g.eventType,dataSchemaVersion:a.get(String(g.eventType))||"2.0.0"})),...e.events.dateTriggers.map(g=>({code:g.code,source:"date",eventType:g.eventType,dataSchemaVersion:a.get(String(g.eventType))||"2.0.0",resourceCode:g.resourceCode,field:g.field})),...e.workflows.activations.length?jn.filter(g=>!Uo.includes(g)||e.workflows.definitions.some(I=>Object.values(I.definition.nodes).some(T=>T.kind==="action"))).filter(g=>g!=="openxiangda.workflow.node.skipped.v2"||e.workflows.definitions.some(I=>Object.values(I.definition.nodes).some(T=>T.kind==="approval"&&T.emptyPolicy==="skip"))).map(g=>({code:`workflow:${g}`,source:"workflow",eventType:g,dataSchemaVersion:"2.0.0"})):[]],g=>`${g.source}:${g.code}:${g.eventType}`),f=U([...s.flatMap(g=>g.eventTypes),...c.map(g=>String(g.eventType))]);Zc(e);let u=Cs(e),p;try{p=Oo(e.data.concurrency,e.data.resources,n)}catch(g){throw g instanceof st&&m(g.code,g.pointer,{reason:g.reason}),g}p?.commands.some(g=>g.mode==="durable")&&e.backend?.enabled===!1&&m("NATIVE_MANAGED_CONCURRENCY_INVALID","/data/concurrency",{reason:"durable commands require backend runtime"});let _=Vc(e,n),E=Os(e),A=e.workflows.definitions.map(g=>g.definition),O=Cn(A),b=Bo(A,s,!0);b.length&&m(b[0],"/config/events/subscriptions");try{Co(e.data.resources,E)}catch(g){throw g instanceof Ke&&m(g.code,g.pointer,{reason:g.reason}),g}return{schemaVersion:As,compilerContractVersion:Jt,generatorVersion:o,appCode:e.appCode,configDigest:t,perspectives:e.perspectives,resources:Lc(e),..._.length?{subjectReadSurfaces:_}:{},...p?{concurrency:p}:{},capabilities:ee(n,g=>g.code),operations:E,eventConsumers:s,eventProducers:c,eventSchemas:i,eventHandlerManifest:{schemaVersion:Rc,appCode:e.appCode,handlers:s.filter(g=>!g.execution).map(g=>({code:g.code,endpointPath:g.endpointPath,eventTypes:g.eventTypes,dataSchemaVersions:U(g.eventTypes.map(I=>I.startsWith("openxiangda.")?"2.0.0":a.get(I)||"2.0.0")),maxBodyBytes:65536,receiptProtocolVersion:2,...O[g.code]?{workflowStep:O[g.code]}:{}}))},eventTypes:f,workflows:Ss(e),routes:Gn(e),...Object.prototype.hasOwnProperty.call(e.frontend,"authentication")?{authentication:Kc(e)}:{},...Object.prototype.hasOwnProperty.call(e.frontend,"publicAccess")?{publicAccess:Jc(e)}:{},...e.frontend.admin.access?{adminAccess:e.frontend.admin.access}:{},routeManifest:rl(e),adminPages:u,adminNavigation:Hc(e)}}function $c(e,t,o,n,i){if(e===void 0)return;let r=N(e,t);C(r,["notification","managedFileCopies","decimalReservation"],t,!0);let d={};if(r.decimalReservation!==void 0)try{d.decimalReservation=Er(r.decimalReservation,Ir(n,i))}catch{m("NATIVE_EVENT_DECIMAL_RESERVATION_INVALID",`${t}/decimalReservation`)}if(r.notification!==void 0){let s=N(r.notification,`${t}/notification`);C(s,["mode"],`${t}/notification`),F(s.mode,"business-standard",`${t}/notification/mode`),d.notification={mode:"business-standard"}}if(r.managedFileCopies!==void 0){let s=S(r.managedFileCopies,`${t}/managedFileCopies`,16);s.length||m("NATIVE_EVENT_MANAGED_FILE_COPIES_REQUIRED",`${t}/managedFileCopies`);let a=new Set;d.managedFileCopies=ee(s.map((c,f)=>{let u=`${t}/managedFileCopies/${f}`,p=N(c,u);C(p,["mode","sourceResourceCode","sourceFieldCodes","targetResourceCode","targetFieldCodes"],u),F(p.mode,"copy",`${u}/mode`);let _=H(p.sourceResourceCode,`${u}/sourceResourceCode`),E=H(p.targetResourceCode,`${u}/targetResourceCode`),A=o.get(_),O=o.get(E);(!A||!O)&&m("NATIVE_EVENT_MANAGED_FILE_COPY_RESOURCE_INVALID",u);let b=L(p.sourceFieldCodes,`${u}/sourceFieldCodes`,16),g=L(p.targetFieldCodes,`${u}/targetFieldCodes`,16);(!b.length||b.length!==g.length)&&m("NATIVE_EVENT_MANAGED_FILE_COPY_FIELDS_INVALID",u),b.forEach((T,l)=>{let y=A.get(T),R=O.get(g[l]);(!["file","image"].includes(String(y))||y!==R)&&m("NATIVE_EVENT_MANAGED_FILE_COPY_FIELD_INVALID",`${u}/sourceFieldCodes/${l}`)});let I=`${_}:${b.join(",")}=>${E}:${g.join(",")}`;return a.has(I)&&m("NATIVE_EVENT_MANAGED_FILE_COPY_DUPLICATE",u),a.add(I),{mode:"copy",sourceResourceCode:_,sourceFieldCodes:U(b),targetResourceCode:E,targetFieldCodes:U(g)}}),c=>`${c.sourceResourceCode}:${c.sourceFieldCodes.join(",")}=>${c.targetResourceCode}:${c.targetFieldCodes.join(",")}`)}return Object.keys(d).length||m("NATIVE_EVENT_PLATFORM_ACCESS_EMPTY",t),d}function vc(e,t,o){let n=N(e,o);C(n,["timeoutMs","maxAttempts","initialBackoffMs","maxBackoffMs","ordering","concurrency"],o),ie(n.timeoutMs,`${o}/timeoutMs`,1e3,3e4),ie(n.maxAttempts,`${o}/maxAttempts`,1,12);let i=ie(n.initialBackoffMs,`${o}/initialBackoffMs`,1e3,3e5);ie(n.maxBackoffMs,`${o}/maxBackoffMs`,i,18e5),ie(n.concurrency,`${o}/concurrency`,1,50);let r=w(n.ordering,`${o}/ordering`,32);return["none","record","workflow-instance"].includes(r)||m("NATIVE_EVENT_DELIVERY_ORDERING_INVALID",`${o}/ordering`),r==="workflow-instance"&&t.some(d=>!Cc.has(d))&&m("NATIVE_EVENT_WORKFLOW_ORDERING_REQUIRES_WORKFLOW_FACTS",`${o}/ordering`),n}function Pc(e){let t=new Map;for(let r of $s(e.appCode))t.set(r.code,r);for(let[r,d]of e.authz.capabilities.entries()){let s=`/config/authz/capabilities/${r}`,a=N(d,s);C(a,["code","kind","name","description"],s,!0);let c=pe(a.code,`${s}/code`,e.appCode);t.has(c)&&m("NATIVE_CAPABILITY_DUPLICATE",`${s}/code`),["backend","ui"].includes(a.kind)||m("NATIVE_CAPABILITY_KIND_INVALID",`${s}/kind`);let f={code:c,kind:a.kind,name:w(a.name,`${s}/name`,255),source:"explicit",...a.description===void 0?{}:{description:hi(a.description,`${s}/description`,2e3)}};t.set(c,f)}let o=e.data.resources.map((r,d)=>({pointer:`/config/data/resources/${d}`,resource:Ye(r,`/config/data/resources/${d}`,e.appCode)}));for(let{pointer:r,resource:d}of o){let s={read:`\u8BFB\u53D6${d.name}`,create:`\u65B0\u5EFA${d.name}`,update:`\u66F4\u65B0${d.name}`,delete:`\u5220\u9664${d.name}`};for(let a of["read","create","update","delete"]){let c=pe(d.capabilities[a],`${r}/capabilities/${a}`,e.appCode);t.has(c)&&m("NATIVE_CAPABILITY_DUPLICATE",`${r}/capabilities/${a}`),t.set(c,{code:c,kind:"data",name:s[a],source:"data"})}}let n=new Set(t.keys()),i=new Map;for(let{pointer:r,resource:d}of o)for(let[s,a]of Object.entries(d.fieldPolicies)){if(nt(s))continue;let c=N(a,`${r}/fieldPolicies/${s}`);for(let f of["read","create","update"])if(Array.isArray(c[f]))for(let u of L(c[f],`${r}/fieldPolicies/${s}/${f}`,2e3)){if(pe(u,`${r}/fieldPolicies/${s}/${f}`,e.appCode),n.has(u))continue;let p=i.get(u);p&&p!==d.code&&m("NATIVE_CAPABILITY_DUPLICATE",`${r}/fieldPolicies/${s}/${f}`),i.set(u,d.code),!t.has(u)&&t.set(u,{code:u,kind:"data",name:`${d.name}.${s}.${f}`,source:"data"})}}return[...t.values()]}function Lc(e){let t=Fc(e);return ee(e.data.resources.map((o,n)=>{let i=Ye(o,`/config/data/resources/${n}`,e.appCode),r=t.get(i.code);return{code:i.code,schemaDigest:Z(i.schema),fields:ee(i.schema.fields.map(d=>({code:d.code,type:d.type})),d=>d.code),...r?{detailRouteCode:r}:{}}}),o=>o.code)}function Vc(e,t){if(e.data.subjectReadSurfaces===void 0)return[];let o=S(e.data.subjectReadSurfaces,"/config/data/subjectReadSurfaces",B.subjectReadSurfaces),n=new Set(t.map(d=>String(d.code))),i=new Map(e.data.resources.map((d,s)=>{let a=`/config/data/resources/${s}`,c=Ye(d,a,e.appCode);return[String(c.code),{resource:c,fields:new Map(S(N(c.schema,`${a}/schema`).fields,`${a}/schema/fields`,500).map(f=>{let u=N(f,`${a}/schema/fields`);return[String(u.code),u]}))}]})),r=new Set;return ee(o.map((d,s)=>{let a=`/config/data/subjectReadSurfaces/${s}`,c=N(d,a);C(c,["code","name","capability","subject","relations"],a);let f=P(c.code,`${a}/code`);r.has(f)&&m("NATIVE_SUBJECT_READ_SURFACE_CODE_DUPLICATE",`${a}/code`),r.add(f);let u=pe(c.capability,`${a}/capability`,e.appCode);n.has(u)||m("NATIVE_SUBJECT_READ_SURFACE_CAPABILITY_NOT_DECLARED",`${a}/capability`);let p=N(c.subject,`${a}/subject`);C(p,["resourceCode","fields"],`${a}/subject`);let _=H(p.resourceCode,`${a}/subject/resourceCode`),E=i.get(_);E||m("NATIVE_SUBJECT_READ_SURFACE_RESOURCE_NOT_DECLARED",`${a}/subject/resourceCode`);let A=L(p.fields,`${a}/subject/fields`,100).map((T,l)=>G(T,`${a}/subject/fields/${l}`));A.length||m("NATIVE_SUBJECT_READ_SURFACE_FIELDS_REQUIRED",`${a}/subject/fields`);for(let[T,l]of A.entries()){let y=E.fields.get(l);(!y||y.type==="subtable")&&m("NATIVE_SUBJECT_READ_SURFACE_FIELD_INVALID",`${a}/subject/fields/${T}`)}let O=S(c.relations,`${a}/relations`,8);O.length||m("NATIVE_SUBJECT_READ_SURFACE_RELATIONS_REQUIRED",`${a}/relations`);let b=new Set,g=0,I=ee(O.map((T,l)=>{let y=`${a}/relations/${l}`,R=N(T,y);C(R,["code","resourceCode","foreignKeyField","fields","limit"],y,["order"]);let h=P(R.code,`${y}/code`);b.has(h)&&m("NATIVE_SUBJECT_READ_SURFACE_RELATION_CODE_DUPLICATE",`${y}/code`),b.add(h);let $=H(R.resourceCode,`${y}/resourceCode`),k=i.get($);k||m("NATIVE_SUBJECT_READ_SURFACE_RESOURCE_NOT_DECLARED",`${y}/resourceCode`);let M=G(R.foreignKeyField,`${y}/foreignKeyField`),V=k.fields.get(M),Y=N(V?.source||{},`${y}/foreignKeyField/source`);(!V||!["uuid","resource-ref.single"].includes(String(V.type))||V.type==="resource-ref.single"&&(Y.kind!=="resource"||Y.resourceCode!==_))&&m("NATIVE_SUBJECT_READ_SURFACE_RELATION_INVALID",`${y}/foreignKeyField`);let ne=L(R.fields,`${y}/fields`,100).map((le,v)=>G(le,`${y}/fields/${v}`));ne.length||m("NATIVE_SUBJECT_READ_SURFACE_FIELDS_REQUIRED",`${y}/fields`);for(let[le,v]of ne.entries()){let W=k.fields.get(v);(!W||W.type==="subtable")&&m("NATIVE_SUBJECT_READ_SURFACE_FIELD_INVALID",`${y}/fields/${le}`)}let X=S(R.order||[],`${y}/order`,10).map((le,v)=>{let W=`${y}/order/${v}`,x=N(le,W);C(x,["field","direction"],W);let q=G(x.field,`${W}/field`),z=k.fields.get(q);return(!Is.has(q)&&!z||z?.type==="subtable"||z&&!it(z.type))&&m("NATIVE_SUBJECT_READ_SURFACE_ORDER_FIELD_INVALID",`${W}/field`),["asc","desc"].includes(String(x.direction))||m("NATIVE_SUBJECT_READ_SURFACE_ORDER_DIRECTION_INVALID",`${W}/direction`),{field:q,direction:x.direction}}),ce=ie(R.limit,`${y}/limit`,1,100);return g+=ce,{code:h,resourceCode:$,foreignKeyField:M,fields:U(ne),...X.length?{order:X}:{},limit:ce}}),T=>T.code);return g>400&&m("NATIVE_SUBJECT_READ_SURFACE_ROW_LIMIT_EXCEEDED",`${a}/relations`),{code:f,name:w(c.name,`${a}/name`,255),capability:u,subject:{resourceCode:_,fields:U(A)},relations:I}}),d=>d.code)}function Fc(e){let t=e.data.resourceDetailRoutes===void 0?[]:S(e.data.resourceDetailRoutes,"/config/data/resourceDetailRoutes",100),o=new Map(e.data.resources.map((r,d)=>{let s=`/config/data/resources/${d}`,a=Ye(r,s,e.appCode);return[a.code,a]})),n=new Map(Gn(e).map(r=>[String(r.code),r])),i=new Map;for(let[r,d]of t.entries()){let s=`/config/data/resourceDetailRoutes/${r}`,a=N(d,s);C(a,["resourceCode","desktop","mobile"],s);let c=H(a.resourceCode,`${s}/resourceCode`);i.has(c)&&m("NATIVE_DATA_RESOURCE_DETAIL_ROUTE_DUPLICATE",`${s}/resourceCode`);let f=o.get(c);f||m("NATIVE_DATA_RESOURCE_DETAIL_ROUTE_RESOURCE_MISSING",`${s}/resourceCode`);let u=P(a.desktop,`${s}/desktop`),p=P(a.mobile,`${s}/mobile`);u===p&&m("NATIVE_DATA_RESOURCE_DETAIL_ROUTE_INVALID",s);let _=String(f.capabilities.read);for(let[E,A]of[["desktop",u],["mobile",p]]){let O=`${s}/${E}`,b=n.get(A);b||m("NATIVE_DATA_RESOURCE_DETAIL_ROUTE_REFERENCE_MISSING",O),b.surface!=="user"&&m("NATIVE_DATA_RESOURCE_DETAIL_ROUTE_SURFACE_INVALID",O);let g=Ne(b.path,`${O}/path`),I=[...g.matchAll(/:([A-Za-z][A-Za-z0-9_]*)/g)],T=E==="mobile"?!g.startsWith("/m/"):g==="/m"||g.startsWith("/m/");(g.includes("*")||g.includes("?")||g.includes("#")||g.split("/").includes("..")||I.length!==1||T)&&m("NATIVE_DATA_RESOURCE_DETAIL_ROUTE_PATH_INVALID",O);let l=Array.isArray(b.access?.allOf)?b.access.allOf:[];b.capability!==_&&!l.includes(_)&&m("NATIVE_DATA_RESOURCE_DETAIL_ROUTE_CAPABILITY_INVALID",O)}i.set(c,{desktop:u,mobile:p})}return i}function Os(e){let t=new Map(e.data.resources.map((d,s)=>{let a=`/config/data/resources/${s}`,c=Ye(d,a,e.appCode);return[c.code,new Map(c.schema.fields.map(f=>[String(f.code),f]))]})),o=new Map(e.data.resources.map((d,s)=>{let a=`/config/data/resources/${s}`,c=Ye(d,a,e.appCode);return[c.code,new Map(c.schema.fields.map(f=>[String(f.code),String(f.type)]))]})),n=new Set(o.keys()),i=new Set(e.workflows.activations.map((d,s)=>zn(N(d,`/config/workflows/activations/${s}`).workflowCode,`/config/workflows/activations/${s}/workflowCode`))),r=new Map;return ee(e.backend.operations.map((d,s)=>{let a=`/config/backend/operations/${s}`,c=N(d,a);C(c,["code","method","path","capability","requestSchema","responseSchema","description","platformAccess","browser","ai"],a,!0);let f=w(c.method,`${a}/method`,16);["GET","POST","PUT","PATCH","DELETE"].includes(f)||m("NATIVE_OPERATION_METHOD_INVALID",`${a}/method`);let u=P(c.code,`${a}/code`);Uc(c.ai,a,u,f,n);let p=Wc(c.platformAccess,`${a}/platformAccess`,o,t,i,new Set(e.authz.roles.map(E=>String(E.code))));if(p?.workflowStage){let E=p.workflowStage,A=e.workflows.definitions.find(O=>O.definition.code===E.workflowCode);(!A||A.definition.subject?.resourceCode!==E.resourceCode||E.runningNodeIds.some(O=>!A.definition.nodes[O]))&&m("NATIVE_WORKFLOW_STAGE_NODE_INVALID",`${a}/platformAccess/workflowStage/runningNodeIds`)}if(p?.recordEdit){let E=e.data.resources.find(A=>A.code===p.recordEdit.resourceCode);E?.surface?.mutationOwner!=="action"&&m("NATIVE_RECORD_EDIT_ACTION_OWNER_REQUIRED",`${a}/platformAccess/recordEdit`);for(let A of p.recordEdit.fieldCodes)(!E.fieldPolicies?.[A]?.update?.length||E.surface?.fields?.[A]?.system===!0)&&m("NATIVE_RECORD_EDIT_FIELD_INVALID",`${a}/platformAccess/recordEdit/fieldCodes`)}if(p?.decimalReservation){let E=p.decimalReservation,A=String(E.resourceCode),O=JSON.stringify([E.amountFieldCode,E.currencyFieldCode,E.relationFieldCode,E.parentFieldCode,E.rootFieldCode,E.statusFieldCode,E.parentRelationValue,E.childRelationValue]),b=r.get(A);b&&b!==O&&m("NATIVE_DECIMAL_RESERVATION_MAPPING_CONFLICT",`${a}/platformAccess/decimalReservation`),r.set(A,O)}let _=xc(c.browser,`${a}/browser`,f,c.requestSchema,c.responseSchema,o,t,e.data.subjectReadSurfaces||[]);return{code:u,method:f,path:Ne(c.path,`${a}/path`),requiredCapability:pe(c.capability,`${a}/capability`,e.appCode),requestSchemaDigest:Z(N(c.requestSchema,`${a}/requestSchema`)),responseSchemaDigest:Z(N(c.responseSchema,`${a}/responseSchema`)),...c.description===void 0?{}:{description:hi(c.description,`${a}/description`,2e3)},...p?{platformAccess:p}:{},..._?{browser:_}:{}}}),d=>d.code)}function xc(e,t,o,n,i,r,d,s){if(e===void 0)return null;let a=N(e,t);C(a,["exposure","behavior","idempotency","subject"],t,["refreshTargets","fileIntent"]),F(a.exposure,"authenticated",`${t}/exposure`);let c=w(a.behavior,`${t}/behavior`,32);["read","controlled"].includes(c)||m("NATIVE_OPERATION_BROWSER_BEHAVIOR_INVALID",`${t}/behavior`);let f=w(a.idempotency,`${t}/idempotency`,32);(!["none","required"].includes(f)||c==="controlled"&&f!=="required"||c==="read"&&f!=="none")&&m("NATIVE_OPERATION_BROWSER_IDEMPOTENCY_INVALID",`${t}/idempotency`);let u=N(a.subject,`${t}/subject`);C(u,["resourceCode","inputField"],`${t}/subject`);let p=H(u.resourceCode,`${t}/subject/resourceCode`);r.has(p)||m("NATIVE_OPERATION_BROWSER_SUBJECT_RESOURCE_NOT_DECLARED",`${t}/subject/resourceCode`);let _=G(u.inputField,`${t}/subject/inputField`),E=N(n,`${t}/requestSchema`),A=N(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 O=N(E.properties,`${t}/requestSchema/properties`),b=new Set(E.required===void 0?[]:L(E.required,`${t}/requestSchema/required`,200));(!(_ in O)||!b.has(_))&&m("NATIVE_OPERATION_BROWSER_SUBJECT_INPUT_INVALID",`${t}/subject/inputField`);let g=N(O[_],`${t}/requestSchema/properties/${_}`);(g.type!=="string"||g.format!=="uuid")&&m("NATIVE_OPERATION_BROWSER_SUBJECT_INPUT_INVALID",`${t}/subject/inputField`);let I=new Map((Array.isArray(s)?s:[]).map((h,$)=>{let k=N(h,`/config/data/subjectReadSurfaces/${$}`);return[String(k.code),String(N(k.subject,`/config/data/subjectReadSurfaces/${$}/subject`).resourceCode)]})),T=a.refreshTargets===void 0?[]:S(a.refreshTargets,`${t}/refreshTargets`,16),l=new Set,y=ee(T.map((h,$)=>{let k=`${t}/refreshTargets/${$}`,M=N(h,k);C(M,["kind","code"],k),F(M.kind,"subject-surface",`${k}/kind`);let V=P(M.code,`${k}/code`);return(l.has(V)||!I.has(V)||I.get(V)!==p)&&m("NATIVE_OPERATION_BROWSER_REFRESH_TARGET_INVALID",`${k}/code`),l.add(V),{kind:"subject-surface",code:V}}),h=>`${h.kind}:${h.code}`),R=jc(a.fileIntent,`${t}/fileIntent`,o,c,f,p,O,b,d);return{exposure:"authenticated",behavior:c,idempotency:f,subject:{resourceCode:p,inputField:_},...y.length?{refreshTargets:y}:{},...R?{fileIntent:R}:{}}}function jc(e,t,o,n,i,r,d,s,a){if(e===void 0)return null;let c=N(e,t);C(c,["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 f=H(c.recordResourceCode,`${t}/recordResourceCode`),u=a.get(f);u||m("NATIVE_OPERATION_FILE_INTENT_RESOURCE_NOT_DECLARED",`${t}/recordResourceCode`);let p=G(c.recordIdInputField,`${t}/recordIdInputField`),_=N(d[p],`${t}/recordIdInputField`);(!s.has(p)||_.type!=="string"||_.format!=="uuid")&&m("NATIVE_OPERATION_FILE_INTENT_RECORD_INPUT_INVALID",`${t}/recordIdInputField`);let E=G(c.relationField,`${t}/relationField`),A=u.get(E);(!A||!["uuid","resource-ref.single"].includes(String(A.type))||String(A.type)==="resource-ref.single"&&(String(N(A.source,`${t}/relationField`).kind||"")!=="resource"||String(N(A.source,`${t}/relationField`).resourceCode||"")!==r))&&m("NATIVE_OPERATION_FILE_INTENT_RELATION_INVALID",`${t}/relationField`);let O=[["fileNameField",["text.short","text.long"]],["contentTypeField",["text.short","text.long"]],["sizeField",["number.integer"]]],b={};for(let[l,y]of O){let R=G(c[l],`${t}/${l}`);y.includes(String(u.get(R)?.type))||m("NATIVE_OPERATION_FILE_INTENT_METADATA_INVALID",`${t}/${l}`),b[l]=R}let g=ee(L(c.purposes,`${t}/purposes`,2),l=>l);(!g.length||g.some(l=>!["preview","download"].includes(l)))&&m("NATIVE_OPERATION_FILE_INTENT_PURPOSE_INVALID",`${t}/purposes`);let I=Number(c.maxTtlSeconds);(!Number.isSafeInteger(I)||I<1||I>300)&&m("NATIVE_OPERATION_FILE_INTENT_TTL_INVALID",`${t}/maxTtlSeconds`);let T=Number(c.maxBytes);return(!Number.isSafeInteger(T)||T<1||T>104857600)&&m("NATIVE_OPERATION_FILE_INTENT_SIZE_INVALID",`${t}/maxBytes`),{recordResourceCode:f,recordIdInputField:p,relationField:E,fileNameField:b.fileNameField,contentTypeField:b.contentTypeField,sizeField:b.sizeField,purposes:g,maxTtlSeconds:I,maxBytes:T}}function Wc(e,t,o,n,i,r){if(e===void 0)return null;let d=N(e,t);C(d,["directory","managedFiles","managedFileCopies","notification","workflow","roleAssertions","decimalReservation","dataCommands","recordEdit","ownedSubject","workflowStage"],t,!0),Object.keys(d).length===0&&m("NATIVE_OPERATION_PLATFORM_ACCESS_EMPTY",t);let s={};if(d.dataCommands!==void 0){let a=N(d.dataCommands,`${t}/dataCommands`);C(a,["mode"],`${t}/dataCommands`),F(a.mode,"recoverable-native",`${t}/dataCommands/mode`),s.dataCommands={mode:"recoverable-native"}}if(d.workflowStage!==void 0){try{Do(d.workflowStage)}catch{m("NATIVE_WORKFLOW_STAGE_DECLARATION_INVALID",`${t}/workflowStage`)}let a=d.workflowStage;(!s.dataCommands||d.decimalReservation!==void 0||!o.has(a.resourceCode)||!i.has(a.workflowCode)||!d.workflow?.codes?.includes(a.workflowCode))&&m("NATIVE_WORKFLOW_STAGE_DECLARATION_INVALID",`${t}/workflowStage`),s.workflowStage={...a,runningNodeIds:U([...a.runningNodeIds]),allowedStatuses:U([...a.allowedStatuses])}}if(d.recordEdit!==void 0){let a=`${t}/recordEdit`,c=N(d.recordEdit,a);C(c,["resourceCode","fieldCodes"],a);let f=H(c.resourceCode,`${a}/resourceCode`),u=n.get(f),p=L(c.fieldCodes,`${a}/fieldCodes`,200);(!u||!p.length||!s.dataCommands)&&m("NATIVE_RECORD_EDIT_DECLARATION_INVALID",a);for(let _ of p){let E=u.get(_);(!E||E.type==="serial-number"||E.type==="subtable")&&m("NATIVE_RECORD_EDIT_FIELD_INVALID",`${a}/fieldCodes`)}s.recordEdit={resourceCode:f,fieldCodes:U(p)}}if(d.roleAssertions!==void 0){let a=N(d.roleAssertions,`${t}/roleAssertions`);C(a,["roleCodes","actorAuthority"],`${t}/roleAssertions`,!0),a.actorAuthority!==void 0&&F(a.actorAuthority,!0,`${t}/roleAssertions/actorAuthority`);let c=L(a.roleCodes,`${t}/roleAssertions/roleCodes`,20);c.length||m("NATIVE_OPERATION_ROLE_ASSERTIONS_REQUIRED",`${t}/roleAssertions/roleCodes`),c.forEach((f,u)=>{r.has(f)||m("NATIVE_ROLE_REFERENCE_MISSING",`${t}/roleAssertions/roleCodes/${u}`)}),s.roleAssertions={roleCodes:U(c),...a.actorAuthority===!0?{actorAuthority:!0}:{}}}if(d.directory!==void 0){let a=N(d.directory,`${t}/directory`);C(a,["mode","fields"],`${t}/directory`),["current-initiator","selected-user"].includes(String(a.mode))||m("NATIVE_OPERATION_DIRECTORY_MODE_INVALID",`${t}/directory/mode`);let c=new Set(["displayName","employeeNumber","primaryDepartment","departments",...a.mode==="current-initiator"?["phone"]:[]]),f=L(a.fields,`${t}/directory/fields`,c.size);(!f.length||f.some(u=>!c.has(u)))&&m("NATIVE_OPERATION_DIRECTORY_FIELDS_INVALID",`${t}/directory/fields`),s.directory={mode:String(a.mode),fields:U(f)}}if(d.managedFiles!==void 0){let a=S(d.managedFiles,`${t}/managedFiles`,16);a.length||m("NATIVE_OPERATION_MANAGED_FILES_REQUIRED",`${t}/managedFiles`);let c=new Set;s.managedFiles=ee(a.map((f,u)=>{let p=`${t}/managedFiles/${u}`,_=N(f,p);C(_,["resourceCode","fieldCodes","intents"],p);let E=H(_.resourceCode,`${p}/resourceCode`);(c.has(E)||!o.has(E))&&m("NATIVE_OPERATION_MANAGED_FILE_RESOURCE_INVALID",`${p}/resourceCode`),c.add(E);let A=L(_.fieldCodes,`${p}/fieldCodes`,16);(!A.length||A.some(b=>!["file","image","signature","text.rich"].includes(String(o.get(E)?.get(b)||""))))&&m("NATIVE_OPERATION_MANAGED_FILE_FIELD_INVALID",`${p}/fieldCodes`);let O=L(_.intents,`${p}/intents`,2);return(!O.length||O.some(b=>!["create","update"].includes(b)))&&m("NATIVE_OPERATION_MANAGED_FILE_INTENT_INVALID",`${p}/intents`),{resourceCode:E,fieldCodes:U(A),intents:U(O)}}),f=>f.resourceCode)}if(d.managedFileCopies!==void 0){let a=S(d.managedFileCopies,`${t}/managedFileCopies`,16);a.length||m("NATIVE_OPERATION_MANAGED_FILE_COPIES_REQUIRED",`${t}/managedFileCopies`);let c=new Set;s.managedFileCopies=ee(a.map((f,u)=>{let p=`${t}/managedFileCopies/${u}`,_=N(f,p);C(_,["mode","sourceResourceCode","sourceFieldCodes","targetResourceCode","targetFieldCodes"],p),F(_.mode,"copy",`${p}/mode`);let E=H(_.sourceResourceCode,`${p}/sourceResourceCode`),A=H(_.targetResourceCode,`${p}/targetResourceCode`),O=o.get(E),b=o.get(A);(!O||!b)&&m("NATIVE_OPERATION_MANAGED_FILE_COPY_RESOURCE_INVALID",p);let g=L(_.sourceFieldCodes,`${p}/sourceFieldCodes`,16),I=L(_.targetFieldCodes,`${p}/targetFieldCodes`,16);(!g.length||g.length!==I.length)&&m("NATIVE_OPERATION_MANAGED_FILE_COPY_FIELDS_INVALID",p),g.forEach((l,y)=>{let R=O.get(l),h=b.get(I[y]);(!["file","image"].includes(String(R))||R!==h)&&m("NATIVE_OPERATION_MANAGED_FILE_COPY_FIELD_INVALID",`${p}/sourceFieldCodes/${y}`)});let T=`${E}:${g.join(",")}=>${A}:${I.join(",")}`;return c.has(T)&&m("NATIVE_OPERATION_MANAGED_FILE_COPY_DUPLICATE",p),c.add(T),{mode:"copy",sourceResourceCode:E,sourceFieldCodes:U(g),targetResourceCode:A,targetFieldCodes:U(I)}}),f=>`${f.sourceResourceCode}:${f.sourceFieldCodes.join(",")}=>${f.targetResourceCode}:${f.targetFieldCodes.join(",")}`)}if(d.notification!==void 0){let a=N(d.notification,`${t}/notification`);C(a,["mode"],`${t}/notification`),a.mode!=="business-standard"&&m("NATIVE_OPERATION_NOTIFICATION_MODE_INVALID",`${t}/notification/mode`),s.notification={mode:"business-standard"}}if(d.workflow!==void 0){let a=N(d.workflow,`${t}/workflow`);C(a,["codes"],`${t}/workflow`,["businessCommands"]);let c=L(a.codes,`${t}/workflow/codes`,16);(!c.length||c.some(u=>!i.has(u)))&&m("NATIVE_OPERATION_WORKFLOW_CODE_INVALID",`${t}/workflow/codes`);let f=a.businessCommands===void 0?void 0:L(a.businessCommands,`${t}/workflow/businessCommands`,4);f&&(!f.length||f.some(u=>!["approve","reject","withdraw","resubmit"].includes(u)))&&m("NATIVE_OPERATION_WORKFLOW_BUSINESS_COMMAND_INVALID",`${t}/workflow/businessCommands`),s.workflow={codes:U(c),...f?{businessCommands:U(f)}:{}}}if(d.ownedSubject!==void 0){let a=`${t}/ownedSubject`,c=d.ownedSubject;try{Bt(c)}catch{m("NATIVE_WORKFLOW_OWNED_SUBJECT_INVALID",a)}(!s.workflow||d.decimalReservation!==void 0)&&m("NATIVE_WORKFLOW_OWNED_SUBJECT_INVALID",a);try{mi(c,n,s.managedFiles||[])}catch(f){m(`NATIVE_${f.message}`,a)}s.ownedSubject={mode:"create",resourceCode:c.resourceCode,subtables:ee(c.subtables.map(f=>({fieldCode:f.fieldCode,fieldCodes:U([...f.fieldCodes])})),f=>f.fieldCode)}}if(d.decimalReservation!==void 0){let a=`${t}/decimalReservation`,c=N(d.decimalReservation,a);C(c,["mode","resourceCode","amountFieldCode","currencyFieldCode","relationFieldCode","parentFieldCode","rootFieldCode","statusFieldCode","parentRelationValue","childRelationValue","eligibleParentStatuses","eligibleChildStatuses"],a);let f=w(c.mode,`${a}/mode`,16);["reserve","commit","release"].includes(f)||m("NATIVE_DECIMAL_RESERVATION_MODE_INVALID",`${a}/mode`);let u=H(c.resourceCode,`${a}/resourceCode`),p=n.get(u);p||m("NATIVE_DECIMAL_RESERVATION_RESOURCE_MISSING",`${a}/resourceCode`);let E=Object.fromEntries(["amountFieldCode","currencyFieldCode","relationFieldCode","parentFieldCode","rootFieldCode","statusFieldCode"].map(l=>[l,G(c[l],`${a}/${l}`)])),A=l=>p.get(E[l]),O=l=>new Set((A(l)?.options||[]).map(y=>String(y.value))),b=P(c.parentRelationValue,`${a}/parentRelationValue`),g=P(c.childRelationValue,`${a}/childRelationValue`),I=L(c.eligibleParentStatuses,`${a}/eligibleParentStatuses`,16),T=L(c.eligibleChildStatuses,`${a}/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!==u||A("rootFieldCode")?.type!=="uuid"||A("statusFieldCode")?.type!=="option.single"||b===g||!O("relationFieldCode").has(b)||!O("relationFieldCode").has(g)||!I.length||!T.length||I.some(l=>!O("statusFieldCode").has(l))||T.some(l=>!O("statusFieldCode").has(l)))&&m("NATIVE_DECIMAL_RESERVATION_FIELD_INVALID",a),s.decimalReservation={mode:f,resourceCode:u,...E,parentRelationValue:b,childRelationValue:g,eligibleParentStatuses:U(I),eligibleChildStatuses:U(T)}}return s}function Uc(e,t,o,n,i){if(e===void 0)return;let r=`${t}/ai`,d=N(e,r);cc.test(o)||m("NATIVE_OPERATION_AI_CODE_INVALID",`${t}/code`),C(d,["name","description","risk","resources","sideEffects","concurrency","timeoutMs"],r,!0),w(d.name,`${r}/name`,bi),w(d.description,`${r}/description`,bi);let s=w(d.risk,`${r}/risk`,16);["read","write","destructive","external"].includes(s)||m("NATIVE_OPERATION_AI_RISK_INVALID",`${r}/risk`),s==="read"!=(n==="GET")&&m("NATIVE_OPERATION_AI_METHOD_RISK_MISMATCH",`${r}/risk`),n==="DELETE"&&!["destructive","external"].includes(s)&&m("NATIVE_OPERATION_AI_METHOD_RISK_MISMATCH",`${r}/risk`);let a=L(d.resources,`${r}/resources`,16);a.length===0&&m("NATIVE_OPERATION_AI_RESOURCE_REQUIRED",`${r}/resources`),a.forEach((f,u)=>{let p=H(f,`${r}/resources/${u}`);i.has(p)||m("NATIVE_OPERATION_AI_RESOURCE_MISSING",`${r}/resources/${u}`)});let c=L(d.sideEffects,`${r}/sideEffects`,20);(s==="read"&&c.length!==0||s!=="read"&&c.length===0)&&m("NATIVE_OPERATION_AI_SIDE_EFFECT_INVALID",`${r}/sideEffects`),d.concurrency!==void 0&&!["none","revision"].includes(w(d.concurrency,`${r}/concurrency`,16))&&m("NATIVE_OPERATION_AI_CONCURRENCY_INVALID",`${r}/concurrency`),d.timeoutMs!==void 0&&ie(d.timeoutMs,`${r}/timeoutMs`,100,3e4)}function Un(e){return(e.replace(/\/{2,}/g,"/").replace(/\/$/,"")||"/").split("/").map(o=>o.startsWith(":")?":":o.includes("*")?"*":o).join("/")}function Mc(e,t){let o=N(e,t),n=w(o.type,`${t}/type`,32),i=["code","type","label","presentation","required"],r=n==="sso"?[...i,"provider"]:n==="dingtalk"?[...i,"flow"]:i;C(o,r,t);let d=P(o.code,`${t}/code`),s=w(o.label,`${t}/label`,255),a=w(o.presentation,`${t}/presentation`,16);["primary","secondary"].includes(a)||m("NATIVE_APPLICATION_AUTH_METHOD_PRESENTATION_INVALID",`${t}/presentation`);let c=Et(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(w(o.flow,`${t}/flow`,16))&&m("NATIVE_APPLICATION_AUTH_DINGTALK_FLOW_INVALID",`${t}/flow`),{code:d,type:n,label:s,presentation:a,required:c,...n==="sso"?{provider:"tenant-default"}:{},...n==="dingtalk"?{flow:o.flow}:{}}}function is(e,t,o){let n=N(e,o);C(n,["routeCode","path","defaultRouteCode"],o);let i=P(n.routeCode,`${o}/routeCode`),r=Ne(n.path,`${o}/path`),d=t==="desktop"?"/login":"/m/login";return(r!==d||/[:*?#\\]/.test(r))&&m("NATIVE_APPLICATION_AUTH_SURFACE_PATH_INVALID",`${o}/path`,{device:t,expectedPath:d}),{routeCode:i,path:r,defaultRouteCode:P(n.defaultRouteCode,`${o}/defaultRouteCode`)}}function Ns(e,t,o,n){if(e===null)return;let i=N(e,n);C(i,["accountMode","registration","methods","surfaces"],n),F(i.accountMode,"existing-platform-users-only",`${n}/accountMode`);let r=N(i.registration,`${n}/registration`);C(r,["mode"],`${n}/registration`),F(r.mode,"reject",`${n}/registration/mode`);let d=S(i.methods,`${n}/methods`,8);d.length===0&&m("NATIVE_APPLICATION_AUTH_METHOD_REQUIRED",`${n}/methods`);let s=d.map((b,g)=>Mc(b,`${n}/methods/${g}`)),a=new Set,c=new Set;for(let[b,g]of s.entries())a.has(g.code)&&m("NATIVE_APPLICATION_AUTH_METHOD_CODE_DUPLICATE",`${n}/methods/${b}/code`),c.has(g.type)&&m("NATIVE_APPLICATION_AUTH_METHOD_TYPE_DUPLICATE",`${n}/methods/${b}/type`),a.add(g.code),c.add(g.type);s.filter(b=>b.presentation==="primary").length!==1&&m("NATIVE_APPLICATION_AUTH_PRIMARY_METHOD_INVALID",`${n}/methods`);let f=N(i.surfaces,`${n}/surfaces`);C(f,["desktop","mobile"],`${n}/surfaces`);let u=is(f.desktop,"desktop",`${n}/surfaces/desktop`),p=is(f.mobile,"mobile",`${n}/surfaces/mobile`);u.routeCode===p.routeCode&&m("NATIVE_APPLICATION_AUTH_SURFACE_CODE_DUPLICATE",`${n}/surfaces/mobile/routeCode`);let _=S(t,"/config/frontend/routes",500),E=new Map;for(let[b,g]of _.entries()){let I=N(g,`/config/frontend/routes/${b}`);E.set(String(I.code||""),I)}let A=new Set((Array.isArray(o.data?.resources)?o.data.resources:[]).map(b=>String(b.code||"")).filter(b=>/^[a-z][a-z0-9-]{0,62}$/.test(b)));for(let[b,g]of[["desktop",u],["mobile",p]]){E.has(g.routeCode)&&m("NATIVE_APPLICATION_AUTH_SURFACE_CODE_CONFLICT",`${n}/surfaces/${b}/routeCode`);let I=/^user\.([a-z][a-z0-9-]{0,62})\.(records|submit)$/.exec(String(g.defaultRouteCode||"")),T=E.get(g.defaultRouteCode),l=String(T?.path||"");if(I&&A.has(I[1])){let R=I[2]==="records"?`/my/${I[1]}`:`/my/${I[1]}/submit`;T={surface:"user",path:b==="mobile"?`/m${R}`:R},l=String(T.path)}let y=b==="desktop"?l==="/m"||l.startsWith("/m/"):!(l==="/m"||l.startsWith("/m/"));(!T||T.surface!=="user"||/[:*]/.test(l)||y)&&m("NATIVE_APPLICATION_AUTH_DEFAULT_ROUTE_INVALID",`${n}/surfaces/${b}/defaultRouteCode`)}let O=Ts(o).filter(b=>!b.owner.startsWith("authentication:"));for(let[b,g]of[["desktop",u],["mobile",p]]){let I=O.find(T=>Un(T.path)===Un(g.path));I&&m("NATIVE_APPLICATION_AUTH_SURFACE_PATH_CONFLICT",`${n}/surfaces/${b}/path`,{owner:I.owner})}}function Bc(e,t){if(e===null)return;let o={data:{resources:[]},workflows:{definitions:[]},frontend:{routes:[{code:"auth-desktop-default",path:"/auth-desktop-default",surface:"user"},{code:"auth-mobile-default",path:"/m/auth-mobile-default",surface:"user"}],user:{applicationTodoCenter:!1},admin:{navigation:[]},authentication:e}},n=N(e,t),i=N(n.surfaces,`${t}/surfaces`),r={...n,surfaces:{...i,desktop:{...N(i.desktop,`${t}/surfaces/desktop`),defaultRouteCode:"auth-desktop-default"},mobile:{...N(i.mobile,`${t}/surfaces/mobile`),defaultRouteCode:"auth-mobile-default"}}};Ns(r,o.frontend.routes,{...o,frontend:{...o.frontend,authentication:r}},t)}function Kc(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 Gc=new Set(["draft.read","draft.update","validate","create","own.list","own.read","public.list","public.read"]);function qc(e,t,o){let n=N(e,o);C(n,["policies"],o);let i=S(n.policies,`${o}/policies`,16);i.length<1&&m("NATIVE_PUBLIC_POLICY_REQUIRED",o);let r=new Map(t.frontend.routes.map(c=>[c.code,c])),d=new Map(t.data.resources.map(c=>[c.code,c])),s=new Set,a=new Set(i.map(c=>String(c?.code||"")));i.forEach((c,f)=>{let u=`${o}/policies/${f}`,p=N(c,u);C(p,["code","routeCode","mode","resourceCode","operations","fields"],u,["requiredFields","ownRecordFields","publicRecordFields","publicFilters","serverGeneratedFields","schedule","publicSubtableFields","draft","validations"]);let _=P(p.code,`${u}/code`);s.has(_)&&m("NATIVE_PUBLIC_POLICY_DUPLICATE",`${u}/code`);let E=P(p.routeCode,`${u}/routeCode`),A=r.get(E);(!A||A.surface!=="user"||A.capability!==void 0||A.access!==void 0||/[:*]/.test(String(A.path)))&&m("NATIVE_PUBLIC_ROUTE_INVALID",`${u}/routeCode`),F(p.mode,"anonymous",`${u}/mode`);let O=H(p.resourceCode,`${u}/resourceCode`),b=d.get(O);b||m("NATIVE_PUBLIC_RESOURCE_MISSING",`${u}/resourceCode`);let g=new Map(b.schema.fields.map(v=>[String(v.code),String(v.type)])),I=L(p.operations,`${u}/operations`,8);(I.length<1||I.some(v=>!Gc.has(v)))&&m("NATIVE_PUBLIC_OPERATION_INVALID",`${u}/operations`),I.includes("draft.read")!==I.includes("draft.update")&&m("NATIVE_PUBLIC_DRAFT_OPERATION_INCOMPLETE",`${u}/operations`);let T=L(p.fields,`${u}/fields`,64);(T.length<1||T.some(v=>!g.has(v)))&&m("NATIVE_PUBLIC_FIELD_INVALID",`${u}/fields`);for(let v of["requiredFields","ownRecordFields","publicRecordFields"]){if(!Object.prototype.hasOwnProperty.call(p,v))continue;L(p[v],`${u}/${v}`,64).some(x=>!T.includes(x))&&m("NATIVE_PUBLIC_FIELD_SCOPE_INVALID",`${u}/${v}`)}let l=Object.prototype.hasOwnProperty.call(p,"serverGeneratedFields")?S(p.serverGeneratedFields,`${u}/serverGeneratedFields`,16):[],y=new Set;l.forEach((v,W)=>{let x=`${u}/serverGeneratedFields/${W}`,q=N(v,x);C(q,["field","kind"],x);let z=G(q.field,`${x}/field`);(y.has(z)||!g.has(z)||T.includes(z)||g.get(z)!=="text.short"&&g.get(z)!=="text.long")&&m("NATIVE_PUBLIC_SERVER_GENERATED_FIELD_INVALID",`${x}/field`),F(q.kind,"random-token",`${x}/kind`),y.add(z)});let R=Object.prototype.hasOwnProperty.call(p,"schedule")?N(p.schedule,`${u}/schedule`):null;if(R){let v=["campusPolicyCode","rulePolicyCode","campusField","ruleCampusField","ruleWeekdaysField","ruleOpenAtField","ruleCloseAtField","ruleSlotMinutesField","ruleAdvanceHoursField","ruleAdvanceDaysField","campusEnabledField","ruleEnabledField","dateField","timeField"];C(R,v,`${u}/schedule`);for(let W of["campusPolicyCode","rulePolicyCode"])P(R[W],`${u}/schedule/${W}`);for(let W of v.filter(x=>!["campusPolicyCode","rulePolicyCode"].includes(x)))G(R[W],`${u}/schedule/${W}`);for(let W of[R.campusField,R.dateField,R.timeField])T.includes(String(W))||m("NATIVE_PUBLIC_SCHEDULE_FIELD_INVALID",`${u}/schedule`);(!a.has(String(R.campusPolicyCode))||!a.has(String(R.rulePolicyCode)))&&m("NATIVE_PUBLIC_SCHEDULE_POLICY_INVALID",`${u}/schedule`)}let h=Object.prototype.hasOwnProperty.call(p,"publicFilters")?S(p.publicFilters,`${u}/publicFilters`,16):[],$=new Set;h.forEach((v,W)=>{let x=`${u}/publicFilters/${W}`,q=N(v,x);C(q,["field","operator","value"],x);let z=G(q.field,`${x}/field`);$.has(z)&&m("NATIVE_PUBLIC_FILTER_DUPLICATE",`${x}/field`),T.includes(z)||m("NATIVE_PUBLIC_FILTER_FIELD_INVALID",`${x}/field`),F(q.operator,"eq",`${x}/operator`),["boolean","text.short","text.long","number.integer","number.decimal","date","time"].includes(g.get(z)||"")||m("NATIVE_PUBLIC_FILTER_FIELD_INVALID",`${x}/field`),q.value!==null&&typeof q.value!="string"&&typeof q.value!="number"&&typeof q.value!="boolean"&&m("NATIVE_PUBLIC_FILTER_VALUE_INVALID",`${x}/value`),$.add(z)});let k=Object.prototype.hasOwnProperty.call(p,"publicSubtableFields")?N(p.publicSubtableFields,`${u}/publicSubtableFields`):null;if(k){Object.keys(k).length>64&&m("NATIVE_PUBLIC_SUBTABLE_FIELDS_INVALID",`${u}/publicSubtableFields`);for(let[v,W]of Object.entries(k)){let x=b.schema.fields.find(J=>String(J.code)===v),q=String(x?.subtable?.resourceCode||""),z=d.get(q),_e=new Map((z?.schema?.fields||[]).map(J=>[String(J.code),String(J.type)])),Te=L(W,`${u}/publicSubtableFields/${v}`,64);(!T.includes(v)||g.get(v)!=="subtable"||!z||Te.length<1||Te.some(J=>!_e.has(J))||Te.some(J=>_e.get(J)==="subtable")||Te.some(J=>_e.get(J)==="signature"))&&m("NATIVE_PUBLIC_SUBTABLE_FIELDS_INVALID",`${u}/publicSubtableFields/${v}`)}}if(I.some(v=>v.startsWith("public."))){Object.prototype.hasOwnProperty.call(p,"publicRecordFields")||m("NATIVE_PUBLIC_RECORD_FIELDS_REQUIRED",`${u}/publicRecordFields`);let v=L(p.publicRecordFields,`${u}/publicRecordFields`,64);(v.length<1||v.some(W=>!T.includes(W))||v.some(W=>g.get(W)==="signature"||g.get(W)==="subtable"&&!k?.[W]))&&m("NATIVE_PUBLIC_RECORD_FIELDS_INVALID",`${u}/publicRecordFields`)}let M=Object.prototype.hasOwnProperty.call(p,"requiredFields")?L(p.requiredFields,`${u}/requiredFields`,64):[],V=b.surface||{},Y=V.fields||{},ne=String(V.mutationOwner||"native")==="native"&&V.generated?.create!==!1,X=b.schema.fields.filter(v=>Tt(v,Y[v.code])).map(v=>String(v.code));if(I.includes("create")&&!ne&&m("NATIVE_PUBLIC_CREATE_FIELDS_INCOMPLETE",`${u}/fields`),I.includes("create")&&!Object.prototype.hasOwnProperty.call(p,"draft")&&m("NATIVE_PUBLIC_DRAFT_REQUIRED",`${u}/draft`),I.includes("create"))for(let v of X){let W=T.includes(v)?M.includes(v)?null:"requiredFields":"fields";W&&m("NATIVE_PUBLIC_CREATE_FIELDS_INCOMPLETE",`${u}/${W}`,{resourceCode:H,fieldCode:v})}if(Object.prototype.hasOwnProperty.call(p,"draft")){let v=N(p.draft,`${u}/draft`);C(v,["enabled","inactivityTtlSeconds","maxBytes"],`${u}/draft`),F(v.enabled,!0,`${u}/draft/enabled`),ie(v.inactivityTtlSeconds,`${u}/draft/inactivityTtlSeconds`,3600,7776e3),ie(v.maxBytes,`${u}/draft/maxBytes`,4096,262144)}else I.includes("draft.read")&&m("NATIVE_PUBLIC_DRAFT_REQUIRED",`${u}/draft`);let ce=Object.prototype.hasOwnProperty.call(p,"validations")?S(p.validations,`${u}/validations`,16):[],le=new Set;ce.forEach((v,W)=>{let x=`${u}/validations/${W}`,q=N(v,x);C(q,["code","kind","fields","result"],x);let z=P(q.code,`${x}/code`);le.has(z)&&m("NATIVE_PUBLIC_VALIDATION_DUPLICATE",`${x}/code`),F(q.kind,"duplicate",`${x}/kind`),F(q.result,"availability",`${x}/result`);let _e=L(q.fields,`${x}/fields`,8);(_e.length<1||_e.some(Te=>!T.includes(Te))||_e.some(Te=>["file","subtable"].includes(g.get(Te)||"")))&&m("NATIVE_PUBLIC_VALIDATION_FIELD_INVALID",`${x}/fields`),le.add(z)}),s.add(_)})}function zc(e,t){let o=N(e,t);C(o,["policies"],t),S(o.policies,`${t}/policies`,16).length<1&&m("NATIVE_PUBLIC_POLICY_REQUIRED",t)}function Jc(e){return{policies:ee(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)=>Ee(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)=>Ee(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:ee(t.validations.map(o=>({code:o.code,kind:o.kind,fields:U(o.fields),result:o.result})),o=>o.code)}:{}})),t=>t.code)}}function Ts(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=Rs(o),i=`/admin/resources/${o.code}`,r=[["list",i],["detail",`${i}/:id`],["create",`${i}/new`],["update",`${i}/:id/edit`]];for(let[d,s]of r)n[d]&&t.push({owner:`resource:${o.code}:${d}`,path:s},{owner:`resource:${o.code}:${d}: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 Gn(e){let t=new Map(Ts(e).map(o=>[Un(o.path),o]));return ee(e.frontend.routes.map((o,n)=>{let i=`/config/frontend/routes/${n}`,r=N(o,i);C(r,["code","path","label","surface","parentCode","capability","access","pinned","tabPersistence","keepAlive"],i,!0),["admin","user"].includes(r.surface)||m("NATIVE_ROUTE_SURFACE_INVALID",`${i}/surface`);let d=Ne(r.path,`${i}/path`);r.surface==="admin"&&d!=="/admin"&&!d.startsWith("/admin/")&&m("NATIVE_ADMIN_ROUTE_PATH_INVALID",`${i}/path`),r.surface==="user"&&(d==="/admin"||d.startsWith("/admin/"))&&m("NATIVE_USER_ROUTE_PATH_RESERVED",`${i}/path`);let s=Un(d),a=t.get(s);a&&m("NATIVE_ROUTE_PATH_CONFLICT",`${i}/path`,{path:d,owner:a.owner}),t.set(s,{owner:`frontend:${String(r.code||n)}`,path:d});let c=/[:*]/.test(d),f=Ci(r,i,e.appCode),u=r.pinned===void 0?void 0:Et(r.pinned,`${i}/pinned`),p=r.tabPersistence===void 0?c?"none":"session":w(r.tabPersistence,`${i}/tabPersistence`,16),_=r.keepAlive===void 0?"none":w(r.keepAlive,`${i}/keepAlive`,16);return["session","none"].includes(p)||m("NATIVE_ROUTE_TAB_PERSISTENCE_INVALID",`${i}/tabPersistence`),["none","memory"].includes(_)||m("NATIVE_ROUTE_KEEP_ALIVE_INVALID",`${i}/keepAlive`),c&&u===!0&&m("NATIVE_DYNAMIC_ROUTE_PINNED_FORBIDDEN",`${i}/pinned`),c&&p==="session"&&m("NATIVE_DYNAMIC_ROUTE_TAB_PERSISTENCE_FORBIDDEN",`${i}/tabPersistence`),c&&_==="memory"&&m("NATIVE_DYNAMIC_ROUTE_KEEP_ALIVE_FORBIDDEN",`${i}/keepAlive`),{code:P(r.code,`${i}/code`),path:d,label:w(r.label,`${i}/label`,255),surface:r.surface,...r.parentCode===void 0?{}:{parentCode:P(r.parentCode,`${i}/parentCode`)},...f,...u===void 0?{}:{pinned:u},tabPersistence:p,keepAlive:_}}),o=>o.code)}function Rs(e){let t=e.surface===void 0?{}:N(e.surface,"/surface"),o=t.mutationOwner||"native",n=t.generated===void 0?{}:N(t.generated,"/surface/generated"),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 Cs(e){let t=[];for(let o of ee(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:mn(n.surface,i.code)}}))])){let{resource:n,viewCode:i}=o,r=`/admin/resources/${n.code}${i?`/views/${i}`:""}`,d=Rs(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 a of s)d[a.operation]&&t.push({code:`resource:${n.code}${i?`:view:${i}`:""}:${a.operation}`,kind:a.kind,path:a.path,label:a.label,navigationEligible:a.navigationEligible,capability:a.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)=>Ee(o.code,n.code))}function hs(e){return e.kind==="resource"?`resource:${e.resourceCode}${e.viewCode?`:view:${e.viewCode}`:""}:list`:`operation:${e.routeCode}`}function Hc(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:hs(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||Ee(n.pageCode,i.pageCode))})).sort((t,o)=>t.order-o.order||Ee(t.code,o.code))}function Yc(e,t){let o=S(e,t,B.adminNavigationGroups);o.reduce((i,r)=>i+(Array.isArray(r?.items)?r.items.length:0),0)>B.adminNavigationItems&&m("NATIVE_ARRAY_LIMIT_EXCEEDED",t);let n=0;o.forEach((i,r)=>{let d=`${t}/${r}`,s=N(i,d);C(s,["code","label","icon","order","items"],d,!0),P(s.code,`${d}/code`),w(s.label,`${d}/label`,255),Mn(s.icon,`${d}/icon`),cs(s.order,`${d}/order`);let a=S(s.items,`${d}/items`,500);a.length===0&&m("NATIVE_ADMIN_GROUP_ORPHANED",`${d}/items`),n+=a.length,n>B.adminNavigationItems&&m("NATIVE_ARRAY_LIMIT_EXCEEDED",t),a.forEach((c,f)=>{let u=`${d}/items/${f}`,p=N(c,u);C(p,["page","label","icon","order"],u,!0),Xc(p.page,`${u}/page`),p.label!==void 0&&w(p.label,`${u}/label`,255),Mn(p.icon,`${u}/icon`),cs(p.order,`${u}/order`)})})}function Xc(e,t){let o=N(e,t),n=w(o.kind,`${t}/kind`,64);if(n==="resource"){C(o,["kind","resourceCode"],t,["viewCode"]),o.viewCode!==void 0&&P(o.viewCode,`${t}/viewCode`),H(o.resourceCode,`${t}/resourceCode`);return}if(n==="operation"){C(o,["kind","routeCode"],t),P(o.routeCode,`${t}/routeCode`);return}m("NATIVE_ADMIN_PAGE_REFERENCE_KIND_INVALID",`${t}/kind`)}function Zc(e){let t=new Map(Cs(e).map(i=>[String(i.code),i])),o=new Set,n=new Set;e.frontend.admin.navigation.forEach((i,r)=>{let d=`/config/frontend/admin/navigation/${r}`;o.has(i.code)&&m("NATIVE_ADMIN_GROUP_DUPLICATE",`${d}/code`),o.add(i.code),i.label===i.code&&m("NATIVE_ADMIN_USER_LABEL_REQUIRED",`${d}/label`),i.items.forEach((s,a)=>{let c=`${d}/items/${a}`,f=hs(s.page),u=t.get(f);(!u||u.navigationEligible!==!0)&&m("NATIVE_ADMIN_PAGE_NOT_FOUND",`${c}/page`),n.has(f)&&m("NATIVE_ADMIN_PAGE_DUPLICATE",`${c}/page`),n.add(f);let p=s.page.resourceCode||s.page.routeCode||s.page.workflowCode||f,_=s.label||u.label;(!_||_===p||_===f)&&m("NATIVE_ADMIN_USER_LABEL_REQUIRED",`${c}/label`)})})}function Qc(e,t){let o=S(e,t,B.adminPages),n=new Set;o.forEach((i,r)=>{let d=`${t}/${r}`,s=N(i,d);C(s,["code","kind","path","label","navigationEligible","capability","access","resourceCode","viewCode","routeCode"],d,!0);let a=w(s.code,`${d}/code`,255);n.has(a)&&m("NATIVE_ADMIN_PAGE_DUPLICATE",`${d}/code`),n.add(a);let c=w(s.kind,`${d}/kind`,64);if(["resource-list","resource-detail","resource-create","resource-update","operation"].includes(c)||m("NATIVE_ADMIN_PAGE_KIND_INVALID",`${d}/kind`),Ne(s.path,`${d}/path`),w(s.label,`${d}/label`,255),Et(s.navigationEligible,`${d}/navigationEligible`),s.capability!==void 0&&s.access!==void 0&&m("NATIVE_ROUTE_ACCESS_CONFLICT",`${d}/access`),s.capability!==void 0&&w(s.capability,`${d}/capability`,255),s.access!==void 0){let f=N(s.access,`${d}/access`);C(f,["allOf","anyOf"],`${d}/access`,!0);for(let u of["allOf","anyOf"])f[u]!==void 0&&L(f[u],`${d}/access/${u}`,50)}for(let f of["resourceCode","viewCode","routeCode"])s[f]!==void 0&&P(s[f],`${d}/${f}`)})}function el(e,t){let o=S(e,t,B.adminNavigationGroups);o.reduce((i,r)=>i+(Array.isArray(r?.items)?r.items.length:0),0)>B.adminNavigationItems&&m("NATIVE_ARRAY_LIMIT_EXCEEDED",t);let n=0;o.forEach((i,r)=>{let d=`${t}/${r}`,s=N(i,d);C(s,["code","label","icon","order","items"],d,!0),P(s.code,`${d}/code`),w(s.label,`${d}/label`,255),Mn(s.icon,`${d}/icon`),ie(s.order,`${d}/order`,-1e4,1e4);let a=S(s.items,`${d}/items`,500);a.length===0&&m("NATIVE_ADMIN_GROUP_ORPHANED",`${d}/items`),n+=a.length,n>B.adminNavigationItems&&m("NATIVE_ARRAY_LIMIT_EXCEEDED",t),a.forEach((c,f)=>{let u=`${d}/items/${f}`,p=N(c,u);C(p,["pageCode","label","icon","order"],u,!0),w(p.pageCode,`${u}/pageCode`,255),p.label!==void 0&&w(p.label,`${u}/label`,255),Mn(p.icon,`${u}/icon`),ie(p.order,`${u}/order`,-1e4,1e4)})})}var tl=new Set(["application-todo-center","workflow-work-center","workflow-launch","workflow-task","workflow-instance","resource-records","resource-submit"]);function nl(e,t,o){let n=N(e,t);C(n,["schemaVersion","appCode","devicePolicy","rootEntry","authentication","routes","digest"],t),F(n.schemaVersion,Es,`${t}/schemaVersion`),F(n.appCode,o,`${t}/appCode`),Ri(n.devicePolicy,`${t}/devicePolicy`),ol(n.rootEntry,`${t}/rootEntry`),il(n.authentication,`${t}/authentication`),Ni(n.digest,`${t}/digest`);let i=S(n.routes,`${t}/routes`,B.routes),r=new Set;i.forEach((d,s)=>{let a=`${t}/routes/${s}`,c=N(d,a),f=c.kind==="resource-records"||c.kind==="resource-submit";C(c,["code","kind","desktop","mobile"],a,["workflowCode",...f?["resourceCode"]:[]]);let u=w(c.code,`${a}/code`,255);r.has(u)&&m("NATIVE_ROUTE_MANIFEST_DUPLICATE",`${a}/code`),r.add(u);let p=w(c.kind,`${a}/kind`,64);if(tl.has(p)||m("NATIVE_ROUTE_MANIFEST_KIND_INVALID",`${a}/kind`),c.workflowCode!==void 0&&P(c.workflowCode,`${a}/workflowCode`),f){let A=H(c.resourceCode,`${a}/resourceCode`);F(u,`user.${A}.${c.kind==="resource-records"?"records":"submit"}`,`${a}/code`)}else c.resourceCode!==void 0&&m("NATIVE_PROPERTY_UNKNOWN",`${a}/resourceCode`);let _=ss(c.desktop,`${a}/desktop`,o),E=ss(c.mobile,`${a}/mobile`,o);_.surface!=="user"&&m("NATIVE_ROUTE_MANIFEST_DESKTOP_SURFACE_INVALID",`${a}/desktop/surface`),E.surface!=="user"&&m("NATIVE_ROUTE_MANIFEST_MOBILE_SURFACE_INVALID",`${a}/mobile/surface`),_.routeCode===E.routeCode&&m("NATIVE_ROUTE_MANIFEST_PAIR_DUPLICATE",a)}),F(n.digest,Z({schemaVersion:n.schemaVersion,appCode:n.appCode,devicePolicy:n.devicePolicy,rootEntry:n.rootEntry,authentication:n.authentication,routes:n.routes}),`${t}/digest`)}function Ri(e,t){let o=N(e,t);C(o,["kind","mobileMaxWidthPx","desktopMinWidthPx"],t),F(o.kind,"viewport-family",`${t}/kind`);let n=ie(o.mobileMaxWidthPx,`${t}/mobileMaxWidthPx`,320,1600),i=ie(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 ol(e,t){let o=N(e,t);C(o,["code","desktop","mobile"],t);let n=P(o.code,`${t}/code`),i=Oi(o.desktop,`${t}/desktop`),r=Oi(o.mobile,`${t}/mobile`);return(i===r||r==="/"||!r.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:r}}function il(e,t){let o=N(e,t);C(o,["desktop","mobile"],t);let n=rs(o.desktop,`${t}/desktop`,!1),i=rs(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 rs(e,t,o){let n=N(e,t);C(n,["routeCode","path"],t);let i=P(n.routeCode,`${t}/routeCode`),r=Oi(n.path,`${t}/path`);return(o?!r.startsWith("/m/"):r.startsWith("/m/"))&&m("NATIVE_ROUTE_MANIFEST_AUTHENTICATION_PATH_INVALID",`${t}/path`),{routeCode:i,path:r}}function Oi(e,t){let o=Ne(e,t);return/[:*?#\\\\]/.test(o)&&m("NATIVE_ROUTE_MANIFEST_STATIC_PATH_INVALID",t),o}function ss(e,t,o){let n=N(e,t);C(n,["routeCode","path","surface","pathParams","requiresAuthentication"],t,["capability","access"]),P(n.routeCode,`${t}/routeCode`);let i=Ne(n.path,`${t}/path`),r=w(n.surface,`${t}/surface`,16);["admin","user"].includes(r)||m("NATIVE_ROUTE_SURFACE_INVALID",`${t}/surface`);let d=L(n.pathParams,`${t}/pathParams`,8);return d.forEach((s,a)=>{(!/^[A-Za-z][A-Za-z0-9_]*$/.test(s)||s.length>64)&&m("NATIVE_ROUTE_PATH_PARAM_INVALID",`${t}/pathParams/${a}`)}),Q(d)!==Q(ws(i))&&m("NATIVE_ROUTE_PATH_PARAMS_MISMATCH",`${t}/pathParams`),Ci(n,t,o),n.requiresAuthentication!==!0&&m("NATIVE_ROUTE_AUTHENTICATION_REQUIRED",`${t}/requiresAuthentication`),n}function ws(e){return U([...e.matchAll(/:([A-Za-z][A-Za-z0-9_]*)/g)].map(t=>t[1]))}function as(e,t,o,n){return{routeCode:e,path:t,surface:o,pathParams:ws(t),...n?.capability?{capability:n.capability}:{},...n?.access?{access:n.access}:{},requiresAuthentication:!0}}function ds(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 rl(e){let t=e.appCode,o=[],n=(_,E,A,O,b,g,I)=>{o.push({code:_,kind:E,...b?{workflowCode:b}:{},...I?{resourceCode:I}:{},desktop:as(ds(E,"desktop",b,I),A,"user",g),mobile:as(ds(E,"mobile",b,I),O,"user",g)})};e.frontend.user.applicationTodoCenter===!0&&n("application:todo-center","application-todo-center","/todos","/m/todos");let i=Ss(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 _ of i){if(!["standalone","hidden-handoff"].includes(_.launch.mode))continue;let E=U([_.launch.submission?.create?.requiredCapability,_.launch.submission?.existing?.requiredCapability].filter(A=>!!A));n(`workflow:${_.code}:launch`,"workflow-launch","/workflows/:workflowCode/start","/m/workflows/:workflowCode/start",_.code,E.length===1?{capability:E[0]}:E.length>1?{access:{anyOf:E}}:void 0)}let r=o.sort((_,E)=>Ee(String(_.code),String(E.code))),d=Gn(e),s=_=>{let E=_==="mobile"?"/m/":"/",A=d.filter(b=>b.surface==="user"&&!/[:*?#\\\\]/.test(b.path)&&b.path===E).sort((b,g)=>Ee(b.code,g.code))[0];if(A)return{code:A.code,path:A.path};let O=d.filter(b=>b.surface==="user"&&!/[:*?#\\\\]/.test(b.path)&&(_==="mobile"?b.path.startsWith("/m/"):!b.path.startsWith("/m/"))).sort((b,g)=>Ee(b.code,g.code))[0];return O?{code:O.code,path:O.path}:{code:_==="mobile"?"application-root-mobile":"application-root",path:E}},a=e.frontend.authentication?{desktop:{routeCode:e.frontend.authentication.surfaces.desktop.routeCode,path:e.frontend.authentication.surfaces.desktop.path},mobile:{routeCode:e.frontend.authentication.surfaces.mobile.routeCode,path:e.frontend.authentication.surfaces.mobile.path}}:{desktop:{routeCode:"application-login",path:"/login"},mobile:{routeCode:"application-login-mobile",path:"/m/login"}},c=Ri(e.frontend.devicePolicy,"/config/frontend/devicePolicy"),f=s("desktop"),u=s("mobile"),p={schemaVersion:Es,appCode:t,devicePolicy:c,rootEntry:{code:f.code,desktop:f.path,mobile:u.path},authentication:a,routes:r};return{...p,digest:Z(p)}}function Mn(e,t){if(e===void 0)return;let o=w(e,t,32);yc.has(o)||m("NATIVE_ADMIN_ICON_INVALID",t)}function cs(e,t){e!==void 0&&ie(e,t,-1e4,1e4)}function Ci(e,t,o){return e.capability!==void 0&&e.access!==void 0&&m("NATIVE_ROUTE_ACCESS_CONFLICT",`${t}/access`),e.capability!==void 0?{capability:pe(e.capability,`${t}/capability`,o)}:e.access===void 0?{}:{access:qn(e.access,`${t}/access`,o)}}function qn(e,t,o){let n=N(e,t);C(n,["allOf","anyOf"],t,!0);let i=n.allOf===void 0?void 0:U(L(n.allOf,`${t}/allOf`,50).map((d,s)=>pe(d,`${t}/allOf/${s}`,o))),r=n.anyOf===void 0?void 0:U(L(n.anyOf,`${t}/anyOf`,50).map((d,s)=>pe(d,`${t}/anyOf/${s}`,o)));return(i?.length||0)+(r?.length||0)===0&&m("NATIVE_ROUTE_ACCESS_EMPTY",t),{...i===void 0?{}:{allOf:i},...r===void 0?{}:{anyOf:r}}}function Ss(e){let t=new Map(Os(e).map(i=>[String(i.code),i])),o=e.workflows.definitions.map((i,r)=>{let d=`/config/workflows/definitions/${r}`,s=N(i,d);C(s,["version","definition","launch"],d,["detailRouteCode"]);let a=N(s.definition,`${d}/definition`),c=s.detailRouteCode===void 0?void 0:ks(s.detailRouteCode,`${d}/detailRouteCode`);return{code:P(a.code,`${d}/definition/code`),title:w(a.title,`${d}/definition/title`,255),version:At(s.version,`${d}/version`),launch:sl(e,a,s.launch,`${d}/launch`,t),...c?{detailRouteCode:c}:{},definition:a}});return U(o.map(i=>i.code)).map(i=>{let r=o.filter(c=>c.code===i),d=e.workflows.activations.find(c=>c.workflowCode===i)?.definitionVersion,s=r.find(c=>c.version===d)||[...r].sort((c,f)=>f.version-c.version)[0],a=new Set;for(let c of r){let f=N(c.definition.nodes,"/config/workflows/definitions/nodes");for(let u of Object.values(f)){let p=N(u,"/config/workflows/definitions/nodes/*");if(p.kind==="approval")for(let _ of L(p.allowedOperations||[],"/config/workflows/definitions/nodes/*/allowedOperations",20))a.add(_)}}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:gs(r.map(c=>c.version)),bindingVersions:gs(e.workflows.bindings.map((c,f)=>{let u=`/config/workflows/bindings/${f}`,p=N(c,u),_=N(p.binding,`${u}/binding`);return{code:P(_.workflowCode,`${u}/binding/workflowCode`),version:At(p.version,`${u}/version`)}}).filter(c=>c.code===i).map(c=>c.version)),providerCodes:U(e.workflows.providers.map((c,f)=>P(N(c,`/config/workflows/providers/${f}`).code,`/config/workflows/providers/${f}/code`))),allowedOperations:[...a].sort(Ee),editableParameterCodes:U(e.workflows.editableParameters.map((c,f)=>{let u=`/config/workflows/editableParameters/${f}`,p=N(c,u);return{code:P(p.code,`${u}/code`),workflowCode:P(p.workflowCode,`${u}/workflowCode`)}}).filter(c=>c.workflowCode===i).map(c=>c.code))}})}function Ds(e,t){let o=N(e,t);C(o,["mode"],t,["submission"]);let n=w(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:N(o.submission,`${t}/submission`)}}}function sl(e,t,o,n,i){let r=Ds(o,n);if(!r.submission)return{mode:r.mode};["standalone","hidden-handoff"].includes(r.mode)||m("NATIVE_WORKFLOW_NAMED_OPERATION_SUBMISSION_INVALID",`${n}/submission`);let d=N(r.submission,`${n}/submission`);C(d,["kind"],`${n}/submission`,["create","existing","context"]),F(d.kind,"named-operation",`${n}/submission/kind`);let s=n.endsWith("/launch")?n.slice(0,-7):n,a=N(t.subject,`${s}/definition/subject`),c=H(a.resourceCode,`${s}/definition/subject/resourceCode`),f=e.data.resources.findIndex(y=>y.code===c),u=e.data.resources[f];(f<0||!u)&&m("NATIVE_WORKFLOW_SUBJECT_RESOURCE_MISSING",`${s}/definition/subject/resourceCode`);let p=new Set(N(u.schema,`/config/data/resources/${f}/schema`).fields.map(y=>String(y.code))),_=new Map(e.backend.operations.map(y=>[String(y.code),y])),E=(y,R)=>{let h=`${n}/submission/${R}`,$=N(y,h);C($,["operationCode","inputs","output"],h);let k=P($.operationCode,`${h}/operationCode`),M=_.get(k),V=i.get(k),Y=V?.platformAccess?.workflow?.codes;(!M||!V||V.method!=="POST"||!Array.isArray(Y)||!Y.includes(t.code))&&m("NATIVE_WORKFLOW_NAMED_OPERATION_INVALID",h);let ne=N(M.requestSchema,`${h}/operation/requestSchema`),X=N(ne.properties,`${h}/operation/requestSchema/properties`),ce=new Set(ne.required===void 0?[]:L(ne.required,`${h}/operation/requestSchema/required`,64)),le=N($.inputs,`${h}/inputs`),v=Object.entries(le);(!v.length||v.length>64)&&m("NATIVE_WORKFLOW_NAMED_OPERATION_INPUT_INVALID",`${h}/inputs`);let W=new Set,x=new Map,q={},z=V.platformAccess?.ownedSubject;z&&(R!=="create"||z.resourceCode!==c)&&m("NATIVE_WORKFLOW_OWNED_SUBJECT_LAUNCH_MISMATCH",h);for(let[J,Ze]of v){(!ts.test(J)||!Object.prototype.hasOwnProperty.call(X,J))&&m("NATIVE_WORKFLOW_NAMED_OPERATION_INPUT_INVALID",`${h}/inputs/${J}`);let We=`${h}/inputs/${J}`,Zn=N(Ze,We),Ue=w(Zn.source,`${We}/source`,32);if(["field","idempotency-key","current-user-reference","subject-id","subject-revision","requested-at"].includes(Ue)||m("NATIVE_WORKFLOW_NAMED_OPERATION_INPUT_INVALID",We),C(Zn,["source"],We,Ue==="field"?["fieldCode"]:!1),x.set(Ue,(x.get(Ue)||0)+1),Ue==="field"){let Qe=G(Zn.fieldCode,`${We}/fieldCode`);(W.has(Qe)||!p.has(Qe))&&m("NATIVE_WORKFLOW_NAMED_OPERATION_INPUT_INVALID",`${We}/fieldCode`),W.add(Qe),u.schema.fields.find(Qn=>Qn.code===Qe)?.type==="subtable"&&(!z||!z.subtables.some(Qn=>Qn.fieldCode===Qe))&&m("NATIVE_WORKFLOW_OWNED_SUBJECT_LAUNCH_REQUIRED",We),q[J]={source:Ue,fieldCode:Qe}}else q[J]={source:Ue}}([...ce].some(J=>!(J in le))||(x.get("idempotency-key")||0)!==1||!v.some(([J,Ze])=>N(Ze,`${h}/inputs/${J}`).source==="idempotency-key"&&ce.has(J))||R==="create"&&((x.get("subject-id")||0)>0||(x.get("subject-revision")||0)>0)||R==="existing"&&((x.get("subject-id")||0)!==1||(x.get("subject-revision")||0)!==1))&&m("NATIVE_WORKFLOW_NAMED_OPERATION_INPUT_INVALID",`${h}/inputs`);let _e=N($.output,`${h}/output`);C(_e,["subjectId"],`${h}/output`,["subjectRevision","processCommand"]);let Te=N(N(M.responseSchema,`${h}/operation/responseSchema`).properties,`${h}/operation/responseSchema/properties`);for(let J of["subjectId","subjectRevision","processCommand"]){if(_e[J]===void 0)continue;let Ze=w(_e[J],`${h}/output/${J}`,128);(!ts.test(Ze)||!Object.prototype.hasOwnProperty.call(Te,Ze))&&m("NATIVE_WORKFLOW_NAMED_OPERATION_OUTPUT_INVALID",`${h}/output/${J}`)}return{operationCode:k,method:"POST",path:V.path,requiredCapability:V.requiredCapability,requestSchemaDigest:V.requestSchemaDigest,responseSchemaDigest:V.responseSchemaDigest,inputs:q,output:{..._e},fieldCodes:W}},A=d.create===void 0?void 0:E(d.create,"create"),O=d.existing===void 0?void 0:E(d.existing,"existing");!A&&!O&&m("NATIVE_WORKFLOW_NAMED_OPERATION_SUBMISSION_INVALID",`${n}/submission`);let b=new Set([...A?.fieldCodes||[],...O?.fieldCodes||[]]),g=d.context===void 0?[]:S(d.context,`${n}/submission/context`,16),I=new Set,T=g.map((y,R)=>{let h=`${n}/submission/context/${R}`,$=N(y,h);C($,["queryParameter","fieldCode"],h);let k=w($.queryParameter,`${h}/queryParameter`,64),M=G($.fieldCode,`${h}/fieldCode`);return(!/^[A-Za-z][A-Za-z0-9]{0,63}$/.test(k)||I.has(k)||!b.has(M))&&m("NATIVE_WORKFLOW_LAUNCH_CONTEXT_INVALID",h),I.add(k),{queryParameter:k,fieldCode:M}}),l=y=>{let{fieldCodes:R,...h}=y;return h};return{mode:r.mode,submission:{kind:"named-operation",...A?{create:l(A)}:{},...O?{existing:l(O)}:{},context:T}}}function ks(e,t){let o=N(e,t);C(o,["desktop","mobile"],t);let n=P(o.desktop,`${t}/desktop`),i=P(o.mobile,`${t}/mobile`);return n===i&&m("NATIVE_WORKFLOW_DETAIL_ROUTE_DUPLICATE",t),{desktop:n,mobile:i}}function al(e,t){let o=new Set(t.map(f=>f.code)),n=new Map;e.data.resources.forEach((f,u)=>{let p=`/config/data/resources/${u}`,_=N(f,p);if(_.recordDeletion!==void 0){let O=`${p}/recordDeletion/delete`;for(let b of _.recordDeletion.delete)pe(b,O,e.appCode),o.has(b)||m("NATIVE_CAPABILITY_REFERENCE_MISSING",O)}if(_.recordComments!==void 0)for(let O of["read","create"]){let b=`${p}/recordComments/${O}`;for(let g of _.recordComments[O])pe(g,b,e.appCode),o.has(g)||m("NATIVE_CAPABILITY_REFERENCE_MISSING",b)}if(_.recordPrint!==void 0){let O=`${p}/recordPrint/read`;for(let b of _.recordPrint.read)pe(b,O,e.appCode),o.has(b)||m("NATIVE_CAPABILITY_REFERENCE_MISSING",O)}if(_.workflowHistory!==void 0){let O=`${p}/workflowHistory/read`;for(let b of _.workflowHistory.read)pe(b,O,e.appCode),o.has(b)||m("NATIVE_CAPABILITY_REFERENCE_MISSING",O)}for(let[O,b]of Object.entries(_.fieldPolicies||{})){if(!nt(O))continue;let g=`${p}/fieldPolicies/${O}/read`,I=N(b,`${p}/fieldPolicies/${O}`);for(let T of L(I.read||[],g,2e3))o.has(T)||m("NATIVE_CAPABILITY_REFERENCE_MISSING",g)}let E=_.surface===void 0?{}:N(_.surface,`${p}/surface`);if(["native","queued-command"].includes(E.mutationOwner||"native"))return;let A=N(_.capabilities,`${p}/capabilities`);for(let O of["create","update","delete"])O==="delete"&&Array.isArray(_.recordDeletion?.delete)&&_.recordDeletion.delete.length>0||n.set(String(A[O]),O)});let i=new Set;for(let[f,u]of e.authz.roles.entries()){let p=`/config/authz/roles/${f}`,_=N(u,p);C(_,["code","name","description","capabilities"],p,!0);let E=P(_.code,`${p}/code`);i.has(E)&&m("NATIVE_ROLE_DUPLICATE",`${p}/code`),i.add(E),w(_.name,`${p}/name`,255);let A=L(_.capabilities,`${p}/capabilities`,2e3);for(let[O,b]of A.entries())n.has(b)&&m("NATIVE_DATA_SURFACE_MUTATION_GRANT_FORBIDDEN",`${p}/capabilities/${O}`,{operation:n.get(b)}),o.has(b)||m("NATIVE_CAPABILITY_REFERENCE_MISSING",`${p}/capabilities`)}let r=e.authz.authenticatedUserRoleCode===void 0?"":P(e.authz.authenticatedUserRoleCode,"/config/authz/authenticatedUserRoleCode");r&&!i.has(r)&&m("NATIVE_AUTHENTICATED_USER_ROLE_REFERENCE_MISSING","/config/authz/authenticatedUserRoleCode");let d=new Set,s=0;for(let[f,u]of e.perspectives.entries()){let p=`/config/perspectives/${f}`,_=N(u,p);C(_,["code","name","description","roleCodes","capabilityCodes","default"],p,!0);let E=P(_.code,`${p}/code`);d.has(E)&&m("NATIVE_PERSPECTIVE_DUPLICATE",`${p}/code`),d.add(E),w(_.name,`${p}/name`,255);let A=L(_.roleCodes,`${p}/roleCodes`,20);A.length<1&&m("NATIVE_PERSPECTIVE_ROLE_REQUIRED",`${p}/roleCodes`),A.forEach((g,I)=>{i.has(g)||m("NATIVE_PERSPECTIVE_ROLE_MISSING",`${p}/roleCodes/${I}`)});let O=U(e.authz.roles.filter(g=>A.includes(g.code)).flatMap(g=>g.capabilities)),b=L(_.capabilityCodes,`${p}/capabilityCodes`,2e3);Q(O)!==Q(b)&&m("NATIVE_PERSPECTIVE_CAPABILITY_PROJECTION_MISMATCH",`${p}/capabilityCodes`),_.default===!0?s+=1:_.default!==void 0&&m("NATIVE_PERSPECTIVE_DEFAULT_INVALID",`${p}/default`)}s>1&&m("NATIVE_PERSPECTIVE_DEFAULT_DUPLICATE","/config/perspectives");for(let[f,u]of e.backend.operations.entries()){let p=N(u,`/config/backend/operations/${f}`);o.has(p.capability)||m("NATIVE_CAPABILITY_REFERENCE_MISSING",`/config/backend/operations/${f}/capability`)}let a=new Set,c=new Set;for(let[f,u]of e.frontend.routes.entries()){let p=`/config/frontend/routes/${f}`,_=N(u,p),E=P(_.code,`${p}/code`);a.has(E)&&m("NATIVE_ROUTE_DUPLICATE",`${p}/code`),a.add(E);let A=Ne(_.path,`${p}/path`);c.has(A)&&m("NATIVE_ROUTE_PATH_DUPLICATE",`${p}/path`),c.add(A);let O=Ci(_,p,e.appCode);O.capability&&!o.has(O.capability)&&m("NATIVE_CAPABILITY_REFERENCE_MISSING",`${p}/capability`);let b=_.access===void 0?void 0:N(_.access,`${p}/access`);for(let g of["allOf","anyOf"]){let I=b?.[g]===void 0?[]:S(b[g],`${p}/access/${g}`,50);for(let[T,l]of I.entries()){let y=pe(l,`${p}/access/${g}/${T}`,e.appCode);o.has(y)||m("NATIVE_CAPABILITY_REFERENCE_MISSING",`${p}/access/${g}/${T}`)}}}if(e.frontend.admin.access!==void 0){let f=qn(e.frontend.admin.access,"/config/frontend/admin/access",e.appCode);for(let u of["allOf","anyOf"])for(let[p,_]of(f[u]||[]).entries())o.has(_)||m("NATIVE_CAPABILITY_REFERENCE_MISSING",`/config/frontend/admin/access/${u}/${p}`)}for(let[f,u]of e.frontend.routes.entries()){let p=N(u,`/config/frontend/routes/${f}`);p.parentCode&&!a.has(p.parentCode)&&m("NATIVE_ROUTE_PARENT_MISSING",`/config/frontend/routes/${f}/parentCode`)}}function dl(e){let t=new Set(e.authz.roles.map(c=>String(c.code))),o=e.authz.authenticatedUserRoleCode===void 0?"":P(e.authz.authenticatedUserRoleCode,"/config/authz/authenticatedUserRoleCode"),n=new Map(e.authz.scopeDimensions.map(c=>[String(c.code),{valueType:c.valueType==="uuid"?"uuid":"string",...c.valueSource?.resourceCode?{valueSourceResourceCode:String(c.valueSource.resourceCode)}:{}}])),i=new Set(n.keys()),r=new Map(e.data.resources.map((c,f)=>{let u=Ye(c,`/config/data/resources/${f}`,e.appCode);return[u.code,new Map(u.schema.fields.map(p=>[String(p.code),p]))]}));for(let[c,f]of e.authz.scopeDimensions.entries()){let u=`/config/authz/scopeDimensions/${c}`,p=N(f,u);if(C(p,["code","name","resourceCode","valueType","hierarchyMode","valueSource"],u,!0),p.valueSource===void 0)continue;let _=N(p.valueSource,`${u}/valueSource`);C(_,["kind","resourceCode","labelField","enabledField"],`${u}/valueSource`,!0),_.kind!=="native_resource"&&m("NATIVE_SCOPE_VALUE_SOURCE_KIND_INVALID",`${u}/valueSource/kind`),p.valueType!=="uuid"&&m("NATIVE_SCOPE_VALUE_SOURCE_TYPE_INVALID",`${u}/valueType`);let E=H(_.resourceCode,`${u}/valueSource/resourceCode`),A=r.get(E);A||m("NATIVE_SCOPE_VALUE_SOURCE_RESOURCE_MISSING",`${u}/valueSource/resourceCode`);let O=G(_.labelField,`${u}/valueSource/labelField`);if(["text.short","text.long"].includes(String(A.get(O)?.type||""))||m("NATIVE_SCOPE_VALUE_SOURCE_LABEL_FIELD_INVALID",`${u}/valueSource/labelField`),_.enabledField!==void 0){let b=G(_.enabledField,`${u}/valueSource/enabledField`);A.get(b)?.type!=="boolean"&&m("NATIVE_SCOPE_VALUE_SOURCE_ENABLED_FIELD_INVALID",`${u}/valueSource/enabledField`)}}let d=new Set,s=new Set;for(let[c,f]of e.authz.scopeSources.entries()){let u=`/config/authz/scopeSources/${c}`,p=N(f,u);C(p,["code","name","resourceCode","subject","grants","operationField","enabledField","effectiveFromField","effectiveToField","failureMode"],u,!0);let _=P(p.code,`${u}/code`);d.has(_)&&m("NATIVE_SCOPE_SOURCE_DUPLICATE",`${u}/code`),d.add(_),w(p.name,`${u}/name`,255);let E=H(p.resourceCode,`${u}/resourceCode`),A=r.get(E);A||m("NATIVE_SCOPE_SOURCE_RESOURCE_MISSING",`${u}/resourceCode`);let O=N(p.subject,`${u}/subject`),b=w(O.type,`${u}/subject/type`,32);C(O,b==="role_membership"?["type","userIdField","roleCode"]:["type","userIdField"],`${u}/subject`),["user","role_membership"].includes(b)||m("NATIVE_SCOPE_SOURCE_SUBJECT_INVALID",`${u}/subject/type`);let g=at(O.userIdField,A);bn(g)||m("NATIVE_SCOPE_SOURCE_SUBJECT_PATH_INVALID",`${u}/subject/userIdField`),b==="role_membership"&&!t.has(String(O.roleCode))&&m("NATIVE_ROLE_REFERENCE_MISSING",`${u}/subject/roleCode`);let I=new Set;for(let[T,l]of S(p.grants,`${u}/grants`,100).entries()){let y=`${u}/grants/${T}`,R=N(l,y);C(R,["dimensionCode","valueField","parentValueField"],y,!0);let h=P(R.dimensionCode,`${y}/dimensionCode`);(!i.has(h)||I.has(h))&&m("NATIVE_SCOPE_SOURCE_DIMENSION_INVALID",`${y}/dimensionCode`),I.add(h),p.failureMode==="last_known_good"&&s.add(h);for(let $ of["valueField","parentValueField"]){if(R[$]===void 0)continue;let k=at(R[$],A);wo(k,n.get(h),r)||m("NATIVE_SCOPE_SOURCE_GRANT_PATH_INVALID",`${y}/${$}`)}}I.size===0&&m("NATIVE_SCOPE_SOURCE_GRANT_REQUIRED",`${u}/grants`),["strict","last_known_good"].includes(p.failureMode)||m("NATIVE_SCOPE_SOURCE_FAILURE_MODE_INVALID",`${u}/failureMode`);for(let T of["operationField","enabledField","effectiveFromField","effectiveToField"]){if(p[T]===void 0)continue;let l=G(p[T],`${u}/${T}`);A.has(l)||m("NATIVE_SCOPE_SOURCE_FIELD_MISSING",`${u}/${T}`)}}ll(e,t,r,o);let a=new Set;for(let[c,f]of e.authz.dataPolicies.entries()){let u=`/config/authz/dataPolicies/${c}`,p=N(f,u);C(p,["code","name","resourceCode","unrestrictedRoleCodes","publicRead","operations","matchMode","rules","readExpression","writeBoundary"],u,!0);let _=P(p.code,`${u}/code`);a.has(_)&&m("NATIVE_DATA_POLICY_DUPLICATE",`${u}/code`),a.add(_);let E=p.readExpression!==void 0,A=L(p.operations||[],`${u}/operations`,4);p.operations!==void 0&&(A.length===0||A.some(l=>!["read","create","update","delete"].includes(l)))&&m("NATIVE_DATA_POLICY_OPERATIONS_INVALID",`${u}/operations`),["AND","OR"].includes(p.matchMode)||m("NATIVE_DATA_POLICY_MATCH_MODE_INVALID",`${u}/matchMode`),E&&p.operations!==void 0&&m("NATIVE_DATA_POLICY_READ_EXPRESSION_OPERATIONS_FORBIDDEN",`${u}/operations`);let O=e.data.resources.find(l=>l.dataPolicyCode===_),b=p.resourceCode||O?.code,g=b?r.get(H(b,`${u}/resourceCode`)):void 0;if(E&&!g&&m("NATIVE_DATA_POLICY_RESOURCE_MISSING",`${u}/resourceCode`),p.publicRead!==void 0){try{let l=e.authz.roles.find(y=>y.code===o);ko({policy:p,resource:e.data.resources.find(y=>y.code===b),baselineRoleCode:o,baselineCapabilities:l?.capabilities||[],baselineDeniedCapabilities:l?.deniedCapabilities||[],pointer:u})}catch(l){if(!(l instanceof dt))throw l;m(l.code,l.pointer)}(p.unrestrictedRoleCodes||[]).includes(o)||m("AUTHENTICATED_PUBLIC_READ_CANONICAL_BASELINE_MISSING",`${u}/unrestrictedRoleCodes`)}else o&&(p.unrestrictedRoleCodes||[]).includes(o)&&m("NATIVE_DATA_POLICY_BASELINE_UNRESTRICTED",`${u}/unrestrictedRoleCodes`);let I=L(p.unrestrictedRoleCodes||[],`${u}/unrestrictedRoleCodes`,100);p.unrestrictedRoleCodes!==void 0&&I.length===0&&m("NATIVE_DATA_POLICY_UNRESTRICTED_ROLES_INVALID",`${u}/unrestrictedRoleCodes`);for(let l of I)t.has(l)||m("NATIVE_ROLE_REFERENCE_MISSING",`${u}/unrestrictedRoleCodes`);let T;try{let l=S(p.rules,`${u}/rules`,100).map((y,R)=>({rule:N(y,`${u}/rules/${R}`),pointer:`${u}/rules/${R}`}));l.length===0?(!E||p.matchMode!=="AND"||p.writeBoundary!=="capability_only")&&m("NATIVE_DATA_POLICY_WRITE_BOUNDARY_REQUIRED",u):p.writeBoundary!==void 0&&m("NATIVE_DATA_POLICY_WRITE_BOUNDARY_INVALID",`${u}/writeBoundary`),T=[...l],E&&(T.push(...Gt(p.readExpression,`${u}/readExpression`)),Ai(p.readExpression,`${u}/readExpression`))}catch(l){throw l instanceof _t&&m(l.code,l.pointer),l}for(let{rule:l,pointer:y}of T){C(l,["subject","dimensionCode","relationCode","resourceCode","field","roleCodes","operation","valuePath","emptyMatchesAll","operator","value","operand"],y,!0);let R=G(l.field,`${y}/field`),h=g?.get(R);E&&!h&&m("NATIVE_DATA_POLICY_FIELD_MISSING",`${y}/field`);for(let X of L(l.roleCodes||[],`${y}/roleCodes`,100))t.has(X)||m("NATIVE_ROLE_REFERENCE_MISSING",`${y}/roleCodes`);let $=String(l.operator||""),k=l.operand==="db_now",M=["is_null","is_not_null"].includes($),V=["eq","not_eq","in","not_in"].includes($),Y=!k&&(l.operator!==void 0||l.value!==void 0);if([l.subject==="current_user"?"current_user":"",typeof l.dimensionCode=="string"?"dimension":"",typeof l.relationCode=="string"?"relationship":"",Y?"constant":"",k?"db_now":""].filter(Boolean).length!==1&&m("NATIVE_DATA_POLICY_RULE_SOURCE_INVALID",y),l.subject!==void 0&&l.subject!=="current_user"&&m("NATIVE_DATA_POLICY_SUBJECT_INVALID",`${y}/subject`),Y){if(!V&&!M&&m("NATIVE_DATA_POLICY_OPERATOR_INVALID",`${y}/operator`),["in","not_in"].includes($)){let X=S(l.value,`${y}/value`,100).map((ce,le)=>w(ce,`${y}/value/${le}`,2048));(X.length===0||new Set(X).size!==X.length)&&m("NATIVE_DATA_POLICY_VALUE_INVALID",`${y}/value`)}else["eq","not_eq"].includes($)?w(l.value,`${y}/value`,2048):(l.value!==void 0||l.operand!==void 0)&&m("NATIVE_DATA_POLICY_VALUE_INVALID",`${y}/value`);for(let X of["operation","valuePath","emptyMatchesAll","resourceCode","operand"])l[X]!==void 0&&m("NATIVE_DATA_POLICY_CONSTANT_RULE_INVALID",`${y}/${X}`)}if(k){(!["lt","lte","gt","gte"].includes($)||l.value!==void 0||h?.type!=="datetime")&&m("NATIVE_DATA_POLICY_DB_NOW_INVALID",y);for(let X of["operation","valuePath","emptyMatchesAll","resourceCode","value"])l[X]!==void 0&&m("NATIVE_DATA_POLICY_DB_NOW_INVALID",`${y}/${X}`)}l.dimensionCode&&!i.has(l.dimensionCode)&&m("NATIVE_SCOPE_DIMENSION_MISSING",`${y}/dimensionCode`),s.has(String(l.dimensionCode||""))&&l.operation!=="read"&&m("NATIVE_SCOPE_SOURCE_LAST_KNOWN_GOOD_UNSAFE",`${y}/operation`)}}for(let[c,f]of e.data.resources.entries()){let u=N(f,`/config/data/resources/${c}`);u.dataPolicyCode&&!a.has(u.dataPolicyCode)&&m("NATIVE_DATA_POLICY_REFERENCE_MISSING",`/config/data/resources/${c}/dataPolicyCode`)}}function cl(e){try{co(e.data.resources,"/config/data/resources"),e.data.resources.forEach((t,o)=>oo(t.schema.fields,new Set(e.authz.roles.map(n=>n.code)),new Set(e.authz.scopeDimensions.map(n=>n.code)),`/config/data/resources/${o}/schema/fields`))}catch(t){throw(t instanceof ye||t instanceof Le)&&m(t.code,t.pointer),t}}function ll(e,t,o,n){let i=new Set;for(let[r,d]of e.authz.roleMembershipSources.entries()){let s=`/config/authz/roleMembershipSources/${r}`,a=N(d,s);C(a,["code","name","resourceCode","userIdField","roleCode","enabledField","effectiveFromField","effectiveToField","failureMode"],s,!0);let c=P(a.code,`${s}/code`);c.length>100&&m("NATIVE_AUTHORIZATION_PROJECTION_SOURCE_CODE_INVALID",`${s}/code`),i.has(c)&&m("NATIVE_AUTHORIZATION_PROJECTION_SOURCE_DUPLICATE",`${s}/code`),i.add(c),w(a.name,`${s}/name`,255);let f=ls(a.resourceCode,`${s}/resourceCode`,o);us(a.userIdField,`${s}/userIdField`,f),t.has(String(a.roleCode||""))||m("NATIVE_ROLE_REFERENCE_MISSING",`${s}/roleCode`),n&&a.roleCode===n&&m("NATIVE_AUTHENTICATED_USER_ROLE_SOURCE_CONFLICT",`${s}/roleCode`),fs(a,s,f)}for(let[r,d]of e.authz.relationshipGrantSources.entries()){let s=`/config/authz/relationshipGrantSources/${r}`,a=N(d,s);C(a,["code","name","resourceCode","subject","relationCode","targetResourceCode","resourceIdField","operations","enabledField","effectiveFromField","effectiveToField","failureMode"],s,!0);let c=P(a.code,`${s}/code`);c.length>100&&m("NATIVE_AUTHORIZATION_PROJECTION_SOURCE_CODE_INVALID",`${s}/code`),i.has(c)&&m("NATIVE_AUTHORIZATION_PROJECTION_SOURCE_DUPLICATE",`${s}/code`),i.add(c),w(a.name,`${s}/name`,255);let f=ls(a.resourceCode,`${s}/resourceCode`,o),u=N(a.subject,`${s}/subject`),p=w(u.type,`${s}/subject/type`,32);C(u,p==="role_membership"?["type","userIdField","roleCode"]:["type","userIdField"],`${s}/subject`),["user","role_membership"].includes(p)||m("NATIVE_AUTHORIZATION_PROJECTION_SUBJECT_INVALID",`${s}/subject/type`),us(u.userIdField,`${s}/subject/userIdField`,f),p==="role_membership"&&!t.has(String(u.roleCode||""))&&m("NATIVE_ROLE_REFERENCE_MISSING",`${s}/subject/roleCode`),P(a.relationCode,`${s}/relationCode`);let _=H(a.targetResourceCode,`${s}/targetResourceCode`);o.has(_)||m("NATIVE_AUTHORIZATION_PROJECTION_TARGET_RESOURCE_MISSING",`${s}/targetResourceCode`);let E=at(a.resourceIdField,f),A=E?.field.type==="resource-ref.single"&&E.valuePath==="value"&&E.field.source?.resourceCode===_;(a.resourceIdField==="id"?_!==String(a.resourceCode):!A)&&m("NATIVE_AUTHORIZATION_PROJECTION_RESOURCE_ID_FIELD_INVALID",`${s}/resourceIdField`);let O=L(a.operations,`${s}/operations`,20);(O.length===0||O.some(b=>b.length>64||!/^[A-Za-z0-9][A-Za-z0-9:._*-]{0,63}$/.test(b)))&&m("NATIVE_AUTHORIZATION_PROJECTION_OPERATIONS_INVALID",`${s}/operations`),fs(a,s,f)}}function ls(e,t,o){let n=H(e,t),i=o.get(n);return i||m("NATIVE_AUTHORIZATION_PROJECTION_RESOURCE_MISSING",t),i}function us(e,t,o){let n=at(e,o);bn(n)||m("NATIVE_AUTHORIZATION_PROJECTION_USER_FIELD_INVALID",t)}function fs(e,t,o){if(e.failureMode!=="strict"&&m("NATIVE_AUTHORIZATION_PROJECTION_FAILURE_MODE_INVALID",`${t}/failureMode`),e.enabledField!==void 0){let n=G(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=G(e[n],`${t}/${n}`);["date","datetime"].includes(String(o.get(i)?.type))||m("NATIVE_AUTHORIZATION_PROJECTION_EFFECTIVE_FIELD_INVALID",`${t}/${n}`)}}function ul(e){let t=new Set,o=new Set;e.forEach((n,i)=>{let r=`/config/backend/secrets/${i}`,d=N(n,r);C(d,["name","env","description","required","exposure"],r,!0);let s=w(d.name,`${r}/name`,128),a=w(d.env,`${r}/env`,128);fc.test(s)||m("NATIVE_SECRET_NAME_INVALID",`${r}/name`),(!pc.test(a)||a.startsWith("OPENXIANGDA_")||["NODE_ENV","PORT"].includes(a))&&m("NATIVE_SECRET_ENV_INVALID",`${r}/env`),t.has(s)&&m("NATIVE_SECRET_NAME_DUPLICATE",`${r}/name`),o.has(a)&&m("NATIVE_SECRET_ENV_DUPLICATE",`${r}/env`),t.add(s),o.add(a),F(d.exposure,"active_only",`${r}/exposure`),d.required!==void 0&&Et(d.required,`${r}/required`),d.description!==void 0&&hi(d.description,`${r}/description`,2e3)})}function fl(e){let t=new Set,o=new Map,n=new Map(e.data.resources.map(_=>[String(_.code),_])),i=new Map(e.frontend.routes.map((_,E)=>{let A=N(_,`/config/frontend/routes/${E}`);return[P(A.code,`/config/frontend/routes/${E}/code`),A]}));for(let[_,E]of e.workflows.definitions.entries()){let A=`/config/workflows/definitions/${_}`,O=N(E,A);if(C(O,["version","definition","launch"],A,["detailRouteCode"]),Ds(O.launch,`${A}/launch`),O.detailRouteCode!==void 0){let h=ks(O.detailRouteCode,`${A}/detailRouteCode`);for(let[$,k,M]of[["desktop",h.desktop,["admin","user"]],["mobile",h.mobile,["user"]]]){let V=`${A}/detailRouteCode/${$}`,Y=i.get(k);Y||m("NATIVE_WORKFLOW_DETAIL_ROUTE_MISSING",V),M.some(ce=>ce===Y.surface)||m("NATIVE_WORKFLOW_DETAIL_ROUTE_SURFACE_INVALID",V);let ne=Ne(Y.path,V),X=[...ne.matchAll(/:([A-Za-z][A-Za-z0-9_]*)/g)].map(ce=>ce[1]);(ne.includes("*")||X.length!==1||X[0]!=="instanceId")&&m("NATIVE_WORKFLOW_DETAIL_ROUTE_PATH_INVALID",V)}}let b=N(O.definition,`${A}/definition`),g=`${b.code}:${At(O.version,`${A}/version`)}`;t.has(g)&&m("NATIVE_WORKFLOW_DEFINITION_DUPLICATE",A),t.add(g),ml(b,`${A}/definition`);let I=Pn(b);I.length&&m(I[0],`${A}/definition/launchPreflight`);let T=ii(b);T.length&&m(T[0],`${A}/definition/approvedDelegation`);let l=ni(b,e.backend.operations);l.length&&m(l[0],`${A}/definition/commandHandlers`),pl(b.subject,n,`${A}/definition/subject`);let y=jt(b,new Map((n.get(b.subject.resourceCode)?.schema.fields||[]).map(h=>[h.code,{...n.get(b.subject.resourceCode)?.surface?.fields?.[h.code],...h,system:["id","revision","createdAt","updatedAt","createdBy","updatedBy"].includes(h.code)}])),new Map([...n].map(([h,$])=>[h,new Map($.schema.fields.map(k=>[k.code,{...$.surface?.fields?.[k.code],...k,system:["id","revision","createdAt","updatedAt","createdBy","updatedBy"].includes(k.code)}]))])),bt(n.get(b.subject.resourceCode)?.schema||{}));y.length&&m(y[0],`${A}/definition/taskPages`);let R=xo(b,{appCode:e.appCode,capabilities:e.authz.capabilities.map(h=>h.code),fields:new Map((n.get(b.subject.resourceCode)?.schema.fields||[]).map(h=>[h.code,h]))});R.length&&m("NATIVE_WORKFLOW_INSTANCE_COMMAND_POLICY_INVALID",`${A}/definition/instanceCommands`,{errors:R}),b.title===b.code&&m("NATIVE_WORKFLOW_USER_TITLE_REQUIRED",`${A}/definition/title`),o.set(g,b)}let r=new Set,d=new Map;for(let[_,E]of e.workflows.bindings.entries()){let A=N(E,`/config/workflows/bindings/${_}`),O=N(A.binding,`/config/workflows/bindings/${_}/binding`),b=`${O.workflowCode}:${At(A.version,`/config/workflows/bindings/${_}/version`)}`;r.has(b)&&m("NATIVE_WORKFLOW_BINDING_DUPLICATE",`/config/workflows/bindings/${_}`),r.add(b),_l(O,`/config/workflows/bindings/${_}/binding`),d.set(b,O)}let s=new Set,a=new Map;for(let[_,E]of e.workflows.activations.entries()){let A=`/config/workflows/activations/${_}`,O=N(E,A);C(O,["workflowCode","definitionVersion","bindingVersion","acceptedCommandDeactivationPolicy"],A,["environmentKey"]);let b=P(O.workflowCode,`${A}/workflowCode`);s.has(b)&&m("NATIVE_WORKFLOW_ACTIVATION_DUPLICATE",A),s.add(b);let g=`${b}:${At(O.definitionVersion,`${A}/definitionVersion`)}`,I=`${b}:${At(O.bindingVersion,`${A}/bindingVersion`)}`;t.has(g)||m("NATIVE_WORKFLOW_DEFINITION_REFERENCE_MISSING",`${A}/definitionVersion`),r.has(I)||m("NATIVE_WORKFLOW_BINDING_REFERENCE_MISSING",`${A}/bindingVersion`);let T=o.get(g),l=d.get(I),y=Pn(T,l);y.length&&m(y[0],A);let R=kn(T,l);R.length&&m(R[0],A),(!["finish-pinned","cancel-on-deactivate"].includes(O.acceptedCommandDeactivationPolicy)||O.acceptedCommandDeactivationPolicy!==T.acceptedCommandDeactivationPolicy)&&m("NATIVE_WORKFLOW_COMMAND_DEACTIVATION_POLICY_MISMATCH",`${A}/acceptedCommandDeactivationPolicy`),gl(T,l,`/config/workflows/activations/${_}`);try{let h=n.get(T.subject.resourceCode)?.schema.fields||[];io(T,l,new Map(h.map($=>[$.code,$])),`${A}/bindings`,new Map([...n].map(([$,k])=>[$,new Map(k.schema.fields.map(M=>[M.code,M]))])))}catch(h){throw h instanceof Le&&m(h.code,h.pointer),h}a.set(b,l)}let c=fi([...a.values()]);c.length&&m(c[0],"/config/workflows/activations");let f=new Set;e.workflows.providers.forEach((_,E)=>{let A=`/config/workflows/providers/${E}`,O=N(_,A);C(O,["code","endpointPath","timeoutMs"],A,!0);let b=P(O.code,`${A}/code`);f.has(b)&&m("NATIVE_WORKFLOW_PROVIDER_DUPLICATE",`${A}/code`),f.add(b),Ne(O.endpointPath,`${A}/endpointPath`),O.timeoutMs!==void 0&&ie(O.timeoutMs,`${A}/timeoutMs`,100,1e4)});for(let[_,E]of a.entries())for(let[A,O]of Object.entries(N(E.bindings,"/config/workflows/bindings/*/binding/bindings"))){let b=N(O,`/config/workflows/${_}/bindings/${A}`);b.provider==="application_provider"&&!f.has(b.providerCode)&&m("NATIVE_WORKFLOW_PROVIDER_REFERENCE_MISSING",`/config/workflows/${_}/bindings/${A}/providerCode`)}let u=new Set(e.authz.roles.map(_=>_.code)),p=new Set;e.workflows.editableParameters.forEach((_,E)=>{let A=`/config/workflows/editableParameters/${E}`,O=N(_,A);C(O,["code","workflowCode","bindingKey","label","valueType","required","allowedRoleCodes","allowedProviderCodes","maxItems"],A,!0);let b=P(O.code,`${A}/code`);p.has(b)&&m("NATIVE_WORKFLOW_EDITABLE_PARAMETER_DUPLICATE",`${A}/code`),p.add(b);let g=zn(O.workflowCode,`${A}/workflowCode`),I=Bn(O.bindingKey,`${A}/bindingKey`),T=a.get(g);(!T||!N(T.bindings,`${A}/bindingKey`)[I])&&m("NATIVE_WORKFLOW_EDITABLE_BINDING_MISSING",`${A}/bindingKey`),w(O.label,`${A}/label`,255),["role_code","user_ids","provider_code"].includes(O.valueType)||m("NATIVE_WORKFLOW_EDITABLE_VALUE_TYPE_INVALID",`${A}/valueType`);for(let l of L(O.allowedRoleCodes||[],`${A}/allowedRoleCodes`,100))u.has(l)||m("NATIVE_ROLE_REFERENCE_MISSING",`${A}/allowedRoleCodes`);for(let l of L(O.allowedProviderCodes||[],`${A}/allowedProviderCodes`,100))f.has(l)||m("NATIVE_WORKFLOW_PROVIDER_REFERENCE_MISSING",`${A}/allowedProviderCodes`);O.required!==void 0&&Et(O.required,`${A}/required`),O.maxItems!==void 0&&ie(O.maxItems,`${A}/maxItems`,1,200)})}function pl(e,t,o){let n=N(e,o);C(n,["resourceCode","factProjection"],o,["summaryFields"]);let i=H(n.resourceCode,`${o}/resourceCode`),r=t.get(i);r||m("NATIVE_WORKFLOW_SUBJECT_RESOURCE_MISSING",`${o}/resourceCode`);let d=new Set(S(N(r.schema,`${o}/resourceCode`).fields,`${o}/resourceCode`,500).map((c,f)=>G(N(c,`${o}/resourceCode/${f}`).code,`${o}/resourceCode/${f}`))),s=N(n.factProjection,`${o}/factProjection`),a=Object.entries(s);(a.length<1||a.length>64)&&m("NATIVE_WORKFLOW_SUBJECT_FACT_PROJECTION_INVALID",`${o}/factProjection`);for(let[c,f]of a){gc.test(c)||m("NATIVE_WORKFLOW_SUBJECT_FACT_KEY_INVALID",`${o}/factProjection/${c}`);let u=G(f,`${o}/factProjection/${c}`);d.has(u)||m("NATIVE_WORKFLOW_SUBJECT_FIELD_MISSING",`${o}/factProjection/${c}`)}if(n.summaryFields!==void 0){let c=L(n.summaryFields,`${o}/summaryFields`,Ac).map((E,A)=>G(E,`${o}/summaryFields/${A}`)),f=t.get(i),u=f.surface&&typeof f.surface=="object"&&!Array.isArray(f.surface)?f.surface:{},p=u.fields&&typeof u.fields=="object"&&!Array.isArray(u.fields)?u.fields:{},_=new Map(S(N(f.schema,`${o}/resourceCode`).fields,`${o}/resourceCode`,500).map((E,A)=>{let O=N(E,`${o}/resourceCode/${A}`);return[String(O.code),O]}));for(let[E,A]of c.entries()){let O=_.get(A),b=p[A],g=String(O?.type||""),I=O?.maxLength;(!O||O.system===!0||b&&typeof b=="object"&&!Array.isArray(b)&&b.system===!0||["id","revision","created_by","updated_by","created_at","updated_at"].includes(A)||!Ic.has(g)||g==="text.long"&&typeof I=="number"&&Number.isFinite(I)&&I>Ec)&&m("NATIVE_WORKFLOW_SUBJECT_SUMMARY_FIELDS_INVALID",`${o}/summaryFields/${E}`)}}}function ml(e,t){C(e,["schemaVersion","code","title","subject","acceptedCommandDeactivationPolicy","startAt","inputSchema","nodes"],t,["organizationContext","instanceCommands","readability","taskPages","rejectionNotification","commandHandlers","launchPreflight","approvedDelegation"]),F(e.schemaVersion,"openxiangda.workflow-definition/v2",`${t}/schemaVersion`),zn(e.code,`${t}/code`),w(e.title,`${t}/title`,255),["finish-pinned","cancel-on-deactivate"].includes(e.acceptedCommandDeactivationPolicy)||m("NATIVE_WORKFLOW_COMMAND_DEACTIVATION_POLICY_REQUIRED",`${t}/acceptedCommandDeactivationPolicy`);let o=N(e.nodes,`${t}/nodes`),n=Object.keys(o);(n.length===0||n.length>200)&&m("NATIVE_WORKFLOW_NODE_COUNT_INVALID",`${t}/nodes`);let i=w(e.startAt,`${t}/startAt`,128),r=qo(e);r.length&&m(r[0],`${t}/readability`);let d=kn(e);d.length&&m(d[0],`${t}/nodes`);let s=vn(e);s.length&&m(s[0],`${t}/nodes`);let a=ft(e);a.length&&m(a[0],`${t}/nodes`);let c=Qo(e);c.length&&m(c[0],`${t}/nodes`);let f=ti(e);f.length&&m(f[0],`${t}/rejectionNotification`);let u=$n(e);u.length&&m(u[0],`${t}/nodes`);let p=jt(e);p.length&&m(p[0],`${t}/taskPages`);let _=$t(e);_.length&&m(_[0],`${t}/nodes`),o[i]||m("NATIVE_WORKFLOW_START_NODE_MISSING",`${t}/startAt`);let E=new Map;for(let[g,I]of Object.entries(o)){let T=`${t}/nodes/${g}`,l=N(I,T);F(l.id,g,`${T}/id`),["approval","condition","end","cc","action","correction"].includes(l.kind)||m("NATIVE_WORKFLOW_NODE_KIND_INVALID",`${T}/kind`);let y=[];if(l.kind==="approval"){w(l.title,`${T}/title`,255),Bn(l.binding,`${T}/binding`),["single","any","all","sequence"].includes(l.mode)||m("NATIVE_WORKFLOW_APPROVAL_MODE_INVALID",`${T}/mode`),y.push(w(l.onApprove,`${T}/onApprove`,128),w(l.onReject,`${T}/onReject`,128));for(let R of L(l.returnTargets||[],`${T}/returnTargets`,200))o[R]||m("NATIVE_WORKFLOW_TARGET_MISSING",`${T}/returnTargets`);for(let R of L(l.allowedOperations||[],`${T}/allowedOperations`,20))bc.has(R)||m("NATIVE_WORKFLOW_OPERATION_INVALID",`${T}/allowedOperations`)}else if(l.kind==="correction"){let R=ri(e);R.length&&m(R[0],T)}else if(l.kind==="action")y.push(w(l.next,`${T}/next`,128));else if(l.kind==="cc")w(l.title,`${T}/title`,255),Bn(l.binding,`${T}/binding`),y.push(w(l.next,`${T}/next`,128));else if(l.kind==="condition"){let R=S(l.branches,`${T}/branches`,100);R.length===0&&m("NATIVE_WORKFLOW_BRANCH_REQUIRED",`${T}/branches`),R.forEach((h,$)=>{let k=N(h,`${T}/branches/${$}`);zt(k.when,`${T}/branches/${$}/when`,0),y.push(w(k.target,`${T}/branches/${$}/target`,128))}),y.push(w(l.otherwise,`${T}/otherwise`,128))}else w(l.title,`${T}/title`,255),w(l.outcome,`${T}/outcome`,128);for(let R of y)o[R]||m("NATIVE_WORKFLOW_TARGET_MISSING",T);E.set(g,y)}let A=new Set,O=new Set,b=g=>{if(O.has(g)&&m("NATIVE_WORKFLOW_CYCLE_FORBIDDEN",`${t}/nodes/${g}`),!A.has(g)){A.add(g),O.add(g);for(let I of E.get(g)||[])b(I);O.delete(g)}};b(i);for(let g of[...A]){let I=o[g];if(I?.kind==="approval")for(let T of I.returnTargets||[])o[T]?.kind==="correction"&&A.add(T)}A.size!==n.length&&m("NATIVE_WORKFLOW_NODE_UNREACHABLE",`${t}/nodes`)}function zt(e,t,o){o>20&&m("NATIVE_WORKFLOW_EXPRESSION_DEPTH_EXCEEDED",t);let n=N(e,t),i=w(n.op,`${t}/op`,16);if(i!=="literal"){if(i==="path"){let r=w(n.path,`${t}/path`,255);(!/^[A-Za-z][A-Za-z0-9_.-]{0,254}$/.test(r)||r.split(".").some(d=>["__proto__","constructor","prototype"].includes(d)))&&m("NATIVE_WORKFLOW_EXPRESSION_PATH_INVALID",`${t}/path`);return}if(["eq","neq","gt","gte","lt","lte","in","contains"].includes(i)){zt(n.left,`${t}/left`,o+1),zt(n.right,`${t}/right`,o+1);return}if(["and","or"].includes(i)){let r=S(n.values,`${t}/values`,100);r.length===0&&m("NATIVE_WORKFLOW_EXPRESSION_EMPTY",`${t}/values`),r.forEach((d,s)=>zt(d,`${t}/values/${s}`,o+1));return}if(["not","exists"].includes(i)){zt(n.value,`${t}/value`,o+1);return}m("NATIVE_WORKFLOW_EXPRESSION_OPERATOR_INVALID",`${t}/op`)}}function _l(e,t){F(e.schemaVersion,"openxiangda.workflow-binding/v2",`${t}/schemaVersion`),zn(e.workflowCode,`${t}/workflowCode`);let o=N(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)){Bn(n,`${t}/bindings/${n}`);let r=N(i,`${t}/bindings/${n}`),d=Jo(r);d.length&&m(d[0],`${t}/bindings/${n}/selectedInputPath`);let s=Pt(r);s.length&&m(s[0],`${t}/bindings/${n}/roleCodes`);let a=w(r.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"&&(Array.isArray(r.users)||m("NATIVE_WORKFLOW_BINDING_USERS_REQUIRED",`${t}/bindings/${n}/users`),S(r.users,`${t}/bindings/${n}/users`,200)),["input_users","form_field_users"].includes(a)&&w(r.inputPath,`${t}/bindings/${n}/inputPath`,255),["app_role","app_role_in_scope","initiator_select"].includes(a)&&r.roleCodes===void 0&&P(r.roleCode,`${t}/bindings/${n}/roleCode`),a==="department_supervisor"&&w(r.departmentIdFrom,`${t}/bindings/${n}/departmentIdFrom`,255),a==="application_provider"&&P(r.providerCode,`${t}/bindings/${n}/providerCode`),r.routing!==void 0){let c=Mt(r.routing);c.length&&m(c[0],`${t}/bindings/${n}/routing`)}}}function gl(e,t,o){F(t.workflowCode,e.code,`${o}/workflowCode`);let n=N(t.bindings,`${o}/bindings`);for(let[s,a]of Object.entries(n))a.provider==="fixed_users"&&!a.users.length&&!Zo(e,s)&&m("NATIVE_WORKFLOW_BINDING_USERS_REQUIRED",`${o}/bindings/${s}/users`);let i=vn(e,t);i.length&&m(i[0],o);let r=$n(e,t);r.length&&m(r[0],o);let d=$t(e,t);d.length&&m(d[0],o);for(let[s,a]of Object.entries(N(e.nodes,`${o}/nodes`))){let c=N(a,`${o}/nodes/${s}`);["approval","cc"].includes(c.kind)&&!n[c.binding]&&m("NATIVE_WORKFLOW_BINDING_REFERENCE_MISSING",`${o}/nodes/${s}/binding`)}}function Al(e,t,o){let n=N(t.routeManifest,"/contracts/routeManifest"),i=N(e.routeManifest,"/contracts/routeManifest"),r=new Map;for(let f of S(o.data?.resources,"/config/data/resources",B.resources)){let u=N(f,"/config/data/resources");r.set(String(u.code||""),u)}let d=new Set(S(i.routes,"/contracts/routeManifest/routes",B.routes).map(f=>String(N(f,"/contracts/routeManifest/routes").code||""))),s=[];for(let f of S(n.routes,"/contracts/routeManifest/routes",B.routes)){let u=N(f,"/contracts/routeManifest/routes"),p=String(u.kind||"");if(p!=="resource-records"&&p!=="resource-submit")continue;let _=String(u.resourceCode||""),E=r.get(_);E||m("NATIVE_ROUTE_MANIFEST_RESOURCE_UNKNOWN","/contracts/routeManifest/routes");let O=`user.${_}.${p==="resource-records"?"records":"submit"}`;F(String(u.code||""),O,"/contracts/routeManifest/routes/code");let b=p==="resource-records"?"read":"create",g=String(N(E.capabilities,"/config/data/resources/capabilities")[b]||"");for(let I of["desktop","mobile"]){let T=N(u[I],`/contracts/routeManifest/routes/${I}`),l=I==="mobile"?"/m/my/":"/my/",y=p==="resource-records"?`${l}${_}`:`${l}${_}/submit`;F(String(T.path||""),y,`/contracts/routeManifest/routes/${I}/path`),F(String(T.capability||""),g,`/contracts/routeManifest/routes/${I}/capability`),F(String(T.routeCode||""),`${O}.${I}`,`/contracts/routeManifest/routes/${I}/routeCode`)}(d.has(O)||s.some(I=>String(I.code)===O))&&m("NATIVE_ROUTE_MANIFEST_DUPLICATE","/contracts/routeManifest/routes/code"),s.push(u)}if(!s.length)return;i.routes=S([...i.routes,...s],"/contracts/routeManifest/routes",1e3).sort((f,u)=>Ee(String(N(f,"x").code||""),String(N(u,"x").code||"")));let a=String(N(n.rootEntry,"x").code||"");if(s.find(f=>String(f.code)===a&&f.kind==="resource-records")){let f=N(n.rootEntry,"x");i.rootEntry={code:a,desktop:String(f.desktop||""),mobile:String(f.mobile||"")}}i.digest=Z({schemaVersion:i.schemaVersion,appCode:i.appCode,devicePolicy:i.devicePolicy,rootEntry:i.rootEntry,authentication:i.authentication,routes:i.routes})}function Ye(e,t,o){let n=N(e,t);C(n,["schemaVersion","appCode","code","name","schema","surface","invariants","decimalReservationLifecycle","uniqueKeys","workflowHistory","recordPrint","recordComments","recordDeletion","capabilities","dataPolicyCode","fieldPolicies"],t,!0),F(n.schemaVersion,"openxiangda.data-resource/v2",`${t}/schemaVersion`),F(n.appCode,o,`${t}/appCode`);let i=H(n.code,`${t}/code`),r=w(n.name,`${t}/name`,255),d=N(n.schema,`${t}/schema`);C(d,["fields","ownedRowLimit"],`${t}/schema`,!0),d.ownedRowLimit!==void 0&&!tt(d.ownedRowLimit)&&m("NATIVE_DATA_OWNED_ROW_LIMIT_INVALID",`${t}/schema/ownedRowLimit`);let s,a,c,f;try{c=An(n.decimalReservationLifecycle,`${t}/decimalReservationLifecycle`),s=dn(d.fields,`${t}/schema/fields`),f=Po(n.uniqueKeys,s,`${t}/uniqueKeys`),a=lo(n.invariants,s,`${t}/invariants`),pn(n.surface,s,`${t}/surface`)}catch(E){throw(E instanceof ye||E instanceof Le||E instanceof Ke||E instanceof ct)&&m(E.code,E.pointer),E}if(n.recordComments!==void 0){let E=N(n.recordComments,`${t}/recordComments`);C(E,["read","create"],`${t}/recordComments`);for(let A of["read","create"]){let O=E[A];(!Array.isArray(O)||O.length>20||O.some(b=>typeof b!="string"||!b.trim())||new Set(O).size!==O.length)&&m("NATIVE_RECORD_COMMENTS_POLICY_INVALID",`${t}/recordComments/${A}`)}}if(n.recordDeletion!==void 0){let E=N(n.recordDeletion,`${t}/recordDeletion`);C(E,["delete"],`${t}/recordDeletion`);let A=E.delete;(!Array.isArray(A)||A.length>20||A.some(O=>typeof O!="string"||!O.trim())||new Set(A).size!==A.length)&&m("NATIVE_RECORD_DELETION_DELETE_INVALID",`${t}/recordDeletion/delete`)}if(n.recordPrint!==void 0){let E=N(n.recordPrint,`${t}/recordPrint`);C(E,["read"],`${t}/recordPrint`);let A=E.read;(!Array.isArray(A)||A.length>20||A.some(O=>typeof O!="string"||!O.trim())||new Set(A).size!==A.length)&&m("NATIVE_RECORD_PRINT_READ_INVALID",`${t}/recordPrint/read`)}if(n.workflowHistory!==void 0){let E=N(n.workflowHistory,`${t}/workflowHistory`);C(E,["read"],`${t}/workflowHistory`);let A=E.read;(!Array.isArray(A)||A.length>20||A.some(O=>typeof O!="string"||!O.trim())||new Set(A).size!==A.length)&&m("NATIVE_WORKFLOW_HISTORY_READ_INVALID",`${t}/workflowHistory/read`)}let u=new Set(s.map(E=>E.code)),p=N(n.capabilities,`${t}/capabilities`);C(p,["read","create","update","delete"],`${t}/capabilities`);let _=N(n.fieldPolicies,`${t}/fieldPolicies`);for(let[E,A]of Object.entries(_)){!u.has(E)&&!nt(E)&&m("NATIVE_DATA_FIELD_POLICY_FIELD_MISSING",`${t}/fieldPolicies/${E}`);let O=`${t}/fieldPolicies/${E}`,b=N(A,O);nt(E)&&(C(b,["read"],O,!0),(!Array.isArray(b.read)||b.read.length>20||b.read.some(g=>typeof g!="string"||!g.trim())||new Set(b.read).size!==b.read.length)&&m("NATIVE_DATA_AUDIT_READ_POLICY_INVALID",`${O}/read`)),C(b,["read","create","update","mask"],O,!0),b.mask!==void 0&&!["omit","null"].includes(b.mask)&&m("NATIVE_DATA_FIELD_POLICY_MASK_INVALID",`${O}/mask`)}return{...n,code:i,name:r,schema:{fields:s,...d.ownedRowLimit!==void 0?{ownedRowLimit:d.ownedRowLimit}:{}},...n.invariants===void 0?{}:{invariants:a},...c?{decimalReservationLifecycle:c}:{},...f!==void 0?{uniqueKeys:f}:{},capabilities:p,fieldPolicies:_}}function $s(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 ps(e,t,o,n){let i=e.toString("utf8"),r;try{r=JSON.parse(i)}catch{m(o,t)}let d=N(r,t);return Q(d)!==i&&m(n,t),d}function Ii(e,t,o){let n=0,i=(r,d,s)=>{if(n+=1,n>o&&m("NATIVE_ARTIFACT_NODE_LIMIT_EXCEEDED",d),s>Tc&&m("NATIVE_ARTIFACT_DEPTH_LIMIT_EXCEEDED",d),typeof r=="string"){Buffer.byteLength(r)>bi&&m("NATIVE_ARTIFACT_STRING_LIMIT_EXCEEDED",d);return}if(Array.isArray(r)){r.forEach((a,c)=>i(a,`${d}/${c}`,s+1));return}if(!(!r||typeof r!="object"))for(let[a,c]of Object.entries(r))["__proto__","prototype","constructor"].includes(a)&&m("NATIVE_ARTIFACT_DANGEROUS_KEY",`${d}/${a}`),El(a)&&m("NATIVE_ARTIFACT_RUNTIME_FIELD_FORBIDDEN",`${d}/${a}`),i(c,`${d}/${a}`,s+1)};i(e,t,0)}function El(e){return["environmentKey","environmentId","secretValue","ciphertext","oauthClient","oauthClientId","oauthClientSecret","signingSecret","kubernetesNamespace","nodePort","productionUrl"].includes(e)}function gt(e){return{value:e,digest:Z(e)}}function ms(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 _s(e,t,o,n){let i=Kn.createHash("sha256").update(e).digest("hex");Kn.timingSafeEqual(Buffer.from(i),Buffer.from(t))||m(n,o)}function N(e,t){return(!e||typeof e!="object"||Array.isArray(e))&&m("NATIVE_OBJECT_REQUIRED",t),e}function S(e,t,o){return Array.isArray(e)||m("NATIVE_ARRAY_REQUIRED",t),e.length>o&&m("NATIVE_ARRAY_LIMIT_EXCEEDED",t),e}function L(e,t,o){let n=S(e,t,o).map((i,r)=>w(i,`${t}/${r}`,255));return new Set(n).size!==n.length&&m("NATIVE_ARRAY_DUPLICATE",t),n}function w(e,t,o){return(typeof e!="string"||e.length===0||e.length>o)&&m("NATIVE_STRING_INVALID",t),e}function hi(e,t,o){return(typeof e!="string"||e.length>o)&&m("NATIVE_STRING_INVALID",t),e}function P(e,t){let o=w(e,t,128);return dc.test(o)||m("NATIVE_CODE_INVALID",t),o}function H(e,t){let o=w(e,t,64);return lc.test(o)||m("NATIVE_RESOURCE_CODE_INVALID",t),o}function G(e,t){let o=w(e,t,63);return uc.test(o)||m("NATIVE_FIELD_CODE_INVALID",t),o}function zn(e,t){let o=w(e,t,128);return mc.test(o)||m("NATIVE_WORKFLOW_CODE_INVALID",t),o}function Bn(e,t){let o=w(e,t,128);return _c.test(o)||m("NATIVE_WORKFLOW_BINDING_CODE_INVALID",t),o}function pe(e,t,o){let n=w(e,t,255);return ac.test(n)||m("NATIVE_CAPABILITY_CODE_INVALID",t),!n.startsWith(`app:${o}:`)&&!$s(o).some(i=>i.code===n)&&m("NATIVE_CAPABILITY_APP_MISMATCH",t),n}function Ne(e,t){let o=w(e,t,2048);return(!o.startsWith("/")||o.startsWith("//")||o.includes("..")||o.includes("?")||o.includes("#"))&&m("NATIVE_ABSOLUTE_PATH_INVALID",t),o}function At(e,t){return(!Number.isInteger(e)||Number(e)<1)&&m("NATIVE_POSITIVE_INTEGER_REQUIRED",t),Number(e)}function ie(e,t,o,n){return(!Number.isInteger(e)||Number(e)<o||Number(e)>n)&&m("NATIVE_INTEGER_OUT_OF_RANGE",t),Number(e)}function Et(e,t){return typeof e!="boolean"&&m("NATIVE_BOOLEAN_REQUIRED",t),e}function Ni(e,t){let o=w(e,t,64).toLowerCase();return rc.test(o)||m("NATIVE_DIGEST_INVALID",t),o}function F(e,t,o){e!==t&&m("NATIVE_VALUE_MISMATCH",o)}function C(e,t,o,n=!1){let i=new Set([...t,...Array.isArray(n)?n:[]]);for(let r of Object.keys(e))i.has(r)||m("NATIVE_PROPERTY_UNKNOWN",`${o}/${r}`);if(n!==!0)for(let r of t)Object.prototype.hasOwnProperty.call(e,r)||m("NATIVE_PROPERTY_REQUIRED",`${o}/${r}`)}function ee(e,t){return[...e].sort((o,n)=>Ee(t(o),t(n)))}function U(e){return[...new Set(e)].sort(Ee)}function gs(e){return[...new Set(e)].sort((t,o)=>t-o)}function Ee(e,t){return e===t?0:e<t?-1:1}function vs(e){return!e||typeof e!="object"||Object.isFrozen(e)||(Object.freeze(e),Object.values(e).forEach(t=>vs(t))),e}function Ti(e,t,o){if(yi(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(!yi(e[i],t[i]))return Ti(e[i],t[i],`${o}/${i}`)}if(e&&t&&typeof e=="object"&&typeof t=="object"&&!Array.isArray(e)&&!Array.isArray(t)){let n=U([...Object.keys(e),...Object.keys(t)]);for(let i of n){let r=e[i],d=t[i];if(!yi(r,d))return Ti(r,d,`${o}/${i}`)}}return o}function yi(e,t){return e===void 0||t===void 0?e===t:Q(e)===Q(t)}function m(e,t,o={}){throw new Wn(e,t,o)}var Il="openxiangda.workflow-step-data-command/v1",Ps="openxiangda.workflow-step-data-resolution/v1";function yl(e,t,o=!1){let n=s=>!!s&&typeof s=="object"&&!Array.isArray(s),i=s=>typeof s=="string"&&/^[a-f0-9]{8}(-[a-f0-9]{4}){3}-[a-f0-9]{12}$/i.test(s),r=()=>{throw new Error("WORKFLOW_STEP_DATA_RESPONSE_INVALID")};if(!n(e)||e.schemaVersion!==Ps||e.executionId!==t||Object.keys(e).some(s=>!["schemaVersion","executionId","outcome","transaction"].includes(s)))return r();if(e.outcome==="not_observed"&&!Object.hasOwn(e,"transaction")&&!o)return e;let d=e.transaction;if(e.outcome!=="committed"||!n(d)||d.schemaVersion!=="openxiangda.data-transaction-result/v2"||d.idempotencyKey!==`workflow-step:${t}`||typeof d.replayed!="boolean"||!Array.isArray(d.items)||d.items.length<1||d.items.length>2016||d.evaluatedAt!==void 0&&(typeof d.evaluatedAt!="string"||!Number.isFinite(Date.parse(d.evaluatedAt))))return r();for(let[s,a]of d.items.entries()){if(!n(a)||a.index!==s)return r();if(a.operation==="emitEvent"){if(typeof a.eventType!="string"||!a.eventType||!i(a.eventId))return r()}else if(!["create","update","delete","increment"].includes(a.operation)||typeof a.resourceCode!="string"||!a.resourceCode||!i(a.id)||!Number.isSafeInteger(a.revision)||a.revision<1)return r()}return e}var gp=50,Ap=131072,Jn=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 bl(e){let t=u=>{throw new Jn(u)},o=(u,p)=>((!u||typeof u!="object"||Array.isArray(u))&&t(p),u),n=(u,p,_)=>{for(let E of Object.keys(u))p.includes(E)||t(`${_}/${E}`)},i=(u,p,_)=>((typeof u!="string"||!u.trim()||u.length>p)&&t(_),u),r=(u,p)=>{let _=i(u,36,p);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(_)||t(p),_.toLowerCase()},d=o(e,""),s;try{s=new TextEncoder().encode(JSON.stringify(d)).byteLength}catch{t("")}s>131072&&t(""),n(d,["schemaVersion","environmentKey","items"],""),d.schemaVersion!=="openxiangda.native-role-membership-batch-request/v2"&&t("/schemaVersion"),d.environmentKey!==void 0&&!["preproduction","production"].includes(String(d.environmentKey))&&t("/environmentKey"),(!Array.isArray(d.items)||d.items.length<1||d.items.length>50)&&t("/items");let a=new Set,c=new Set,f;for(let[u,p]of d.items.entries()){let _=`/items/${u}`,E=o(p,_);["create","update","revoke"].includes(String(E.operation))||t(`${_}/operation`),f??=E.operation,f!==E.operation&&t(`${_}/operation`),n(E,["operation","operationId","reason",...f==="create"?["userId","roleCode"]:["membershipId","expectedRevision"],...f!=="revoke"?["scopeGrants","validFrom","validTo"]:[]],_);let A=r(E.operationId,`${_}/operationId`);a.has(A)&&t(`${_}/operationId`),a.add(A),i(E.reason,1e3,`${_}/reason`);let O;if(f==="create"){let b=i(E.userId,255,`${_}/userId`),g=i(E.roleCode,128,`${_}/roleCode`);/^[a-z][a-z0-9]*(?:[._-][a-z0-9]+)*$/.test(g)||t(`${_}/roleCode`),O=JSON.stringify([b,g])}else O=r(E.membershipId,`${_}/membershipId`),(!Number.isSafeInteger(E.expectedRevision)||Number(E.expectedRevision)<1)&&t(`${_}/expectedRevision`);c.has(O)&&t(_),c.add(O),E.scopeGrants!==void 0&&(!Array.isArray(E.scopeGrants)||E.scopeGrants.length>100)&&t(`${_}/scopeGrants`);for(let b of["validFrom","validTo"])E[b]!==void 0&&E[b]!==null&&i(E[b],64,`${_}/${b}`)}}var xs="openxiangda.workflow-delegation-administration/v2",js="openxiangda.workflow-delegation-mutation/v2",Ls="openxiangda.workflow-delegation-preview/v2";var Ht={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}$"},me={type:"string",minLength:1,maxLength:255},Xe={type:"string",format:"date-time"},It={type:"integer",minimum:1},Ol={anyOf:[Xe,{type:"null"}]},wi={anyOf:[me,{type:"null"}]},Ws={anyOf:[{type:"string",pattern:"^[A-Za-z0-9._:-]{1,128}$"},{type:"null"}]},Hn={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}$"},Us={const:"future-assignments-only"},Si={schemaVersion:{const:xs},id:Ht,appCode:me,environmentKey:me,workflowCode:wi,nodeId:Ws,delegatorUserId:me,delegateUserId:me,delegatorRoleSubjectKey:Hn,delegateRoleSubjectKey:Hn,validFrom:Xe,validTo:Xe,status:{enum:["active","revoked","expired"]},reason:{type:"string",minLength:1,maxLength:4e3},createdBy:me,createdAt:Xe,revokedAt:Ol,revision:It,roleCode:me,roleName:me,delegatorDisplayName:me,delegateDisplayName:me,delegatorRoleSubjectRevision:It,delegateRoleSubjectRevision:It,effectiveState:{enum:["active","scheduled","expired","revoked","ineligible"]},evaluatedAt:Xe,issues:{type:"array",maxItems:20,uniqueItems:!0,items:me},canRevoke:{type:"boolean"},revokedBy:wi,revokeReason:{type:["string","null"],maxLength:4e3},taskPolicy:Us},Di={type:"object",additionalProperties:!1,required:Object.keys(Si).filter(e=>e!=="nodeId"),properties:Si},Ip={$id:xs,...Di},Ms={schemaVersion:{const:js},operationId:Ht,environmentKey:{enum:["preproduction","production"]},reason:{type:"string",minLength:1,maxLength:2e3,pattern:"\\S"}},Vs={...Ms,operation:{const:"create"},workflowCode:wi,nodeId:Ws,delegatorRoleSubjectKey:Hn,expectedDelegatorRevision:It,delegateUserId:me,delegateRoleSubjectKey:Hn,expectedDelegateRevision:It,validFrom:Xe,validTo:Xe},Fs={...Ms,operation:{const:"revoke"},delegationId:Ht,expectedRevision:It},Bs={$id:js,type:"object",oneOf:[{type:"object",additionalProperties:!1,required:Object.keys(Vs).filter(e=>e!=="nodeId"),properties:Vs,if:{required:["nodeId"],properties:{nodeId:{type:"string"}}},then:{properties:{workflowCode:me}}},{type:"object",additionalProperties:!1,required:Object.keys(Fs),properties:Fs}]},Nl={type:"string",pattern:"^[0-9a-f]{64}$"},yp={$id:Ls,type:"object",additionalProperties:!1,required:["schemaVersion","operationId","operation","requestDigest","before","after","taskPolicy"],properties:{schemaVersion:{const:Ls},operationId:Ht,operation:{enum:["create","revoke"]},requestDigest:Nl,before:{anyOf:[Di,{type:"null"}]},after:{...Di,properties:{...Si,id:{anyOf:[Ht,{type:"null"}]}}},taskPolicy:Us}};function Tl(e){return e===void 0?"":`
9
+ ${Z(e)}`}function Rl(e,t){let o=e.handlers.find(n=>n.code===t);return Z(o?.workflowStep?o:e)}var Cl="openxiangda.data-business-command/v1",Ks="openxiangda.data-business-command-resolution/v1",Tp=65536;function hl(e){let t=0,o=0,n=new Set,i=new TextEncoder,r=()=>{throw new Error("OPENXIANGDA_DATA_COMMAND_INTENT_INVALID")},d=a=>(o+=i.encode(a).byteLength,o>65536&&r(),a),s=(a,c)=>{if(++t>1e4||c>32)return r();if(a===null||typeof a=="string"||typeof a=="boolean")return d(JSON.stringify(a));if(typeof a=="number")return Number.isFinite(a)?d(JSON.stringify(a)):r();if(!a||typeof a!="object"||n.has(a)||Object.getOwnPropertySymbols(a).length)return r();n.add(a);let f;if(Array.isArray(a))return Object.keys(a).length!==a.length?r():(f=d("[")+a.map((p,_)=>(_?d(","):"")+s(p,c+1)).join("")+d("]"),n.delete(a),f);let u=Object.getPrototypeOf(a);return u!==Object.prototype&&u!==null?r():(f=d("{")+Object.keys(a).sort().map((p,_)=>(_?d(","):"")+d(JSON.stringify(p))+d(":")+s(a[p],c+1)).join("")+d("}"),n.delete(a),f)};return!e||typeof e!="object"||Array.isArray(e)?r():s(e,0)}function wl(e,t,o=!1){let n=e,i=()=>{throw new Error("OPENXIANGDA_DATA_COMMAND_RESPONSE_INVALID")};if(!n||typeof n!="object"||n.schemaVersion!==Ks)return i();for(let a of["appCode","environmentKey","operationCode","idempotencyKey","intentDigest"])if(n[a]!==t[a])return i();if(typeof n.observedAt!="string"||!Number.isFinite(Date.parse(n.observedAt)))return i();if(n.outcome==="not_observed"&&n.receipt===null&&!o)return n;if(n.outcome!=="committed"||!n.receipt)return i();let r=n.receipt,d=a=>typeof a=="string"&&/^[a-f0-9]{8}(-[a-f0-9]{4}){3}-[a-f0-9]{12}$/i.test(a);if(!d(r.id)||!d(r.appVersionId)||!Number.isSafeInteger(r.environmentHeadRevision)||r.environmentHeadRevision<1||typeof r.completedAt!="string"||!Number.isFinite(Date.parse(r.completedAt)))return i();let s=r.transaction;if(!s||s.schemaVersion!=="openxiangda.data-transaction-result/v2"||s.idempotencyKey!==t.idempotencyKey||typeof s.replayed!="boolean"||!Array.isArray(s.items)||!s.items.length||s.items.length>1e3)return i();for(let[a,c]of s.items.entries()){if(!c||c.index!==a)return i();if(c.operation==="emitEvent"){if(!d(c.eventId)||typeof c.eventType!="string"||!c.eventType)return i()}else if(!["create","update","delete","increment"].includes(c.operation)||!d(c.id)||typeof c.resourceCode!="string"||!c.resourceCode||!Number.isSafeInteger(c.revision)||c.revision<1)return i()}return n}var Gs=/^[a-z][a-z0-9]*(?:[-_.][a-z0-9]+)*$/,Yn=e=>!!e&&typeof e=="object"&&!Array.isArray(e),Yt=(e,t)=>typeof e=="string"&&e.length<=t&&e.trim().length>0&&e===e.trim(),ki=(e,t,o=[])=>t.every(n=>Object.hasOwn(e,n))&&Object.keys(e).every(n=>[...t,...o].includes(n));function Sl(e){if(!Yn(e)||!ki(e,["kind","errorCode","anyOf"],["allowAppSuperAdmin"])||e.kind!=="actor-authority"||!Yt(e.errorCode,110)||!/^OPENXIANGDA_[A-Z0-9_]{1,96}$/.test(e.errorCode)||Object.hasOwn(e,"allowAppSuperAdmin")&&typeof e.allowAppSuperAdmin!="boolean"||!Array.isArray(e.anyOf)||e.anyOf.length<1||e.anyOf.length>20)return!1;let t=new Set;return e.anyOf.every(o=>{if(!Yn(o)||!ki(o,["roleCode"],["scope"])||!Yt(o.roleCode,100)||!Gs.test(o.roleCode))return!1;if(Object.hasOwn(o,"scope")){let r=o.scope;if(!Yn(r)||!ki(r,["dimensionCode","value","operation"])||!Yt(r.dimensionCode,100)||!Gs.test(r.dimensionCode)||!Yt(r.value,255)||!Yt(r.operation,64)||!/^[A-Za-z0-9*][A-Za-z0-9*._:-]*$/.test(r.operation))return!1}let n=o.scope,i=JSON.stringify([o.roleCode,n?.dimensionCode,n?.value,n?.operation]);return t.has(i)?!1:(t.add(i),!0)})}function Dl(e,t,o){if(t.roleSource!=="package"||t.roleCode!==e.roleCode||!o||!t.capabilityCodes.includes(o))return!1;if(!e.scope)return!0;let n;try{n=JSON.parse(t.scopeGrantsJson)}catch{return!1}if(!Array.isArray(n))return!1;let i=e.scope;return n.some(r=>Yn(r)&&r.dimensionCode===i.dimensionCode&&Array.isArray(r.values)&&r.values.includes(i.value)&&(r.operations===void 0||r.operations===null||Array.isArray(r.operations)&&(!r.operations.length||r.operations.includes("*")||r.operations.includes(i.operation))))}var hp=500,kl=/^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i,$i=e=>!!e&&typeof e=="object"&&!Array.isArray(e);function $l(e){if(!$i(e)||e.kind!=="record-set-match"||Object.keys(e).some(o=>!["kind","resourceCode","errorCode","records","where"].includes(o))||typeof e.resourceCode!="string"||e.resourceCode.length>64||!/^[a-z][a-z0-9]*(?:[-_.][a-z0-9]+)*$/.test(e.resourceCode)||typeof e.errorCode!="string"||!/^OPENXIANGDA_[A-Z0-9_]{1,96}$/.test(e.errorCode)||!Array.isArray(e.records)||!e.records.length||e.records.length>500||Object.hasOwn(e,"where")&&!$i(e.where))return!1;let t=new Set;return e.records.every(o=>{if(!$i(o)||Object.keys(o).length!==2||typeof o.id!="string"||!kl.test(o.id)||!Number.isSafeInteger(o.expectedRevision)||Number(o.expectedRevision)<1)return!1;let n=o.id.toLowerCase();return t.has(n)?!1:(t.add(n),!0)})}function qs(e,t){if(t===void 0)return e;let o=e.views?.find(d=>d.code===t);if(!o)throw new Error(`DATA_RESOURCE_VIEW_NOT_FOUND: ${t}`);let n=new Map(o.sections?.flatMap(d=>d.fields.map(s=>[s,d.title]))),{views:i,...r}=e;return{...r,generated:o.generated,list:o.list,form:o.form,detail:o.detail,mobile:o.mobile,fields:Object.fromEntries(Object.entries(e.fields).map(([d,s])=>{let{section:a,...c}=s,f=n.get(d);return[d,{...c,...f?{section:f}:{},list:o.list.fieldOrder?.includes(d)??!1}]}))}}var zs="openxiangda.development-configuration/v1",vi="openxiangda.development-configuration-manifest/v1",vl="application.development-configuration",Pl="/openxiangda-api/v2/applications/{appCode}/dev-sessions/configuration",Xn=class extends Error{constructor(o,n){super(o);this.code=o;this.pointer=n;this.data={pointer:n}}code;pointer;status=400;data};function je(e){throw new Xn("OPENXIANGDA_CONNECTED_DEV_CONFIGURATION_INVALID",e)}function Js(e){(!e||typeof e!="object"||Array.isArray(e))&&je("/packageManifest");let t=e,o=["schemaVersion","appCode","version","configDigest","contractDigest","source","toolchain","artifacts"];(Object.keys(t).some(i=>!o.includes(i))||t.schemaVersion!==vi||typeof t.appCode!="string"||!/^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/.test(t.appCode)||!/^[a-f0-9]{64}$/.test(t.configDigest)||!/^[a-f0-9]{64}$/.test(t.contractDigest)||t.version!==`development-${t.configDigest}`)&&je("/packageManifest"),(!t.source||typeof t.source!="object"||Array.isArray(t.source)||Object.keys(t.source).some(i=>!["repository","commit","dirty"].includes(i))||![null,"string"].includes(t.source.repository===null?null:typeof t.source.repository)||t.source.repository!==null&&(t.source.repository.length>1024||/[\r\n\0]/.test(t.source.repository))||t.source.commit!==null&&(typeof t.source.commit!="string"||!/^(?:[a-f0-9]{40}|[a-f0-9]{64})$/.test(t.source.commit))||typeof t.source.dirty!="boolean")&&je("/packageManifest/source"),(!t.toolchain||Object.keys(t.toolchain).some(i=>!["version","contractVersion"].includes(i))||typeof t.toolchain.version!="string"||!/^[A-Za-z0-9][A-Za-z0-9.+_-]{0,127}$/.test(t.toolchain.version)||t.toolchain.contractVersion!==_i)&&je("/packageManifest/toolchain");let n=[{kind:"config",digest:t.configDigest,mediaType:"application/json"},{kind:"contracts",digest:t.contractDigest,mediaType:"application/json"}];return Q(t.artifacts)!==Q(n)&&je("/packageManifest/artifacts"),t}function Ll(e,t){return Js({schemaVersion:vi,appCode:e,version:`development-${t.configDigest}`,configDigest:t.configDigest,contractDigest:t.contractDigest,source:{...t.source},toolchain:{version:t.toolchainVersion,contractVersion:_i},artifacts:[{kind:"config",digest:t.configDigest,mediaType:"application/json"},{kind:"contracts",digest:t.contractDigest,mediaType:"application/json"}]})}function Vl(e,t){return(!Number.isSafeInteger(t)||t<1)&&je("/expectedHeadRevision"),`development:${Z({manifest:e,expectedHeadRevision:t})}`}function Fl(e,t,o){(!e||typeof e!="object"||Array.isArray(e))&&je("/result");let n=e,i=["schemaVersion","appCode","environmentKey","environmentId","appVersionId","configurationRunId","headRevision","configDigest","contractDigest","reused","runtimeArtifactsDeployed","backendEventsAvailable"],r=/^[a-f0-9]{8}-[a-f0-9]{4}-[1-5][a-f0-9]{3}-[89ab][a-f0-9]{3}-[a-f0-9]{12}$/i;return(Object.keys(n).some(d=>!i.includes(d))||n.schemaVersion!==zs||n.appCode!==t||n.environmentKey!=="preproduction"||n.configDigest!==o.configDigest||n.contractDigest!==o.contractDigest||!r.test(n.environmentId)||!r.test(n.appVersionId)||!r.test(n.configurationRunId)||typeof n.reused!="boolean"||!Number.isSafeInteger(n.headRevision)||n.headRevision<1||!n.reused&&n.headRevision!==o.expectedHeadRevision+1||n.runtimeArtifactsDeployed!==!1||n.backendEventsAvailable!==!1)&&je("/result"),n}var xl="application.development-backend-events",jl="openxiangda.development-backend/v1",Wl="application.development-backend-invocations",Hs="openxiangda.development-backend-invocation/v1",vp=262144,Pp=1048576,Lp=131072,Vp=131072,Fp=8,xp=45,Ul=/^\/__platform\/events\/[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/;function Ml(e){return(e.backend?.operations?.length||0)>0||(e.workflows?.providers?.length||0)>0||(e.events?.subscriptions||[]).some(t=>t.execution?.kind!=="native-data")}function Bl(e){return`connected-development:${e}`}function Ys(e){if(typeof e!="string"||e.length%4!==0||!/^[A-Za-z0-9+/]*={0,2}$/.test(e))return null;let t="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",o=e.endsWith("==")?2:e.endsWith("=")?1:0;return o&&t.indexOf(e[e.length-o-1])%(o===2?16:4)!==0?null:e.length/4*3-o}function Xs(e,t,o){if(!["GET","POST","PUT","PATCH","DELETE","HEAD","OPTIONS"].includes(e)||o.method!==e||typeof t!="string"||t.length>2048||!t.startsWith("/")||t.startsWith("//")||t.startsWith("/__platform")||/[\\?#\s\u0000-\u001f\u007f]/.test(t))return!1;let n=t.split("/"),i=String(o.path||"").split("/");return n.length!==i.length?!1:n.every((r,d)=>{if(d===0)return i[d]==="";let s;try{s=decodeURIComponent(r)}catch{return!1}return!s||[".",".."].includes(s)||/[\/\\\s\u0000-\u001f\u007f]/.test(s)?!1:/^:[A-Za-z][A-Za-z0-9_]*$/.test(i[d]||"")||r===i[d]})}var Kl=/^(?:authorization|content-type|content-length|accept|if-match|idempotency-key|x-request-id|x-openxiangda-(?:gateway-assertion|forwarded-by|perspective|csrf-token|mcp-bus-token))$/i,Gl=/^(?:content-type|content-disposition|cache-control|etag|last-modified|retry-after)$/i;function Zs(e,t=!1){if(!e||typeof e!="object"||Array.isArray(e))return!1;let o=Object.entries(e),n=o.map(([i])=>i.toLowerCase());return o.length<=24&&new Set(n).size===n.length&&o.every(([i,r])=>(t?Gl:Kl).test(i)&&typeof r=="string"&&r.length<=8192&&!/[\r\n\u0000]/.test(r))}function ql(e){let t=Ys(e.body);return e.schemaVersion===Hs&&!!e.operation&&typeof e.operation.code=="string"&&e.operation.code.length<=128&&e.operation.code.length>0&&Xs(e.method,e.endpointPath,e.operation)&&typeof e.canonicalQuery=="string"&&e.canonicalQuery.length<=8192&&!/[\s#\u0000-\u001f\u007f]/.test(e.canonicalQuery)&&t!==null&&t<=262144&&Zs(e.headers)&&Object.entries(e.headers).some(([o,n])=>o.toLowerCase()==="authorization"&&/^Bearer \S+$/.test(n))&&Object.entries(e.headers).some(([o,n])=>o.toLowerCase()==="x-openxiangda-gateway-assertion"&&!!n)}var zl="4479089b607e094e71bea2ab23778da2d25b00f674bb976ed1963b8f0ec05c5a";0&&(module.exports={AuthenticatedPublicReadContractError,DATA_AUDIT_METADATA_FIELDS,DATA_BUSINESS_COMMAND_INTENT_MAX_BYTES,DATA_BUSINESS_COMMAND_RESOLUTION_SCHEMA,DATA_BUSINESS_COMMAND_SCHEMA,DATA_EVENT_TYPES_V2,DATA_FORM_DRAFT_MAX_BYTES,DATA_SUBTABLE_DEFAULT_TOTAL_ROWS,DATA_SUBTABLE_MAX_ROWS,DATA_SUBTABLE_MAX_TOTAL_ROWS,DATA_SYSTEM_SORT_FIELD_CODES,DATA_TRANSACTION_MAX_BYTES,DATA_TRANSACTION_MAX_OPERATIONS,DATA_TRANSACTION_RECORD_SET_MAX_RECORDS,DATE_EVENT_RESERVED_DATA_FIELDS_V2,DEVELOPMENT_BACKEND_CONNECTION_TTL_SECONDS,DEVELOPMENT_BACKEND_ENDPOINT_PATTERN,DEVELOPMENT_BACKEND_FEATURE,DEVELOPMENT_BACKEND_INVOCATION_FEATURE,DEVELOPMENT_BACKEND_INVOCATION_MAX_REQUEST_BYTES,DEVELOPMENT_BACKEND_INVOCATION_MAX_RESPONSE_BYTES,DEVELOPMENT_BACKEND_INVOCATION_SCHEMA,DEVELOPMENT_BACKEND_MAX_INFLIGHT,DEVELOPMENT_BACKEND_MAX_REQUEST_BYTES,DEVELOPMENT_BACKEND_MAX_RESPONSE_BYTES,DEVELOPMENT_BACKEND_SCHEMA,DEVELOPMENT_CONFIGURATION_ENDPOINT,DEVELOPMENT_CONFIGURATION_FEATURE,DEVELOPMENT_CONFIGURATION_MANIFEST_SCHEMA,DEVELOPMENT_CONFIGURATION_SCHEMA,DateEventProjectionV2Error,DevelopmentConfigurationContractError,ManagedConcurrencyContractError,NATIVE_ARTIFACT_CAPACITY_V2,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,USER_CANDIDATE_MAX_SELECTIONS,USER_CANDIDATE_SCOPE_FIELD_TYPES,UserCandidateContractError,WORKFLOW_APPROVAL_EMPTY_PROVIDERS,WORKFLOW_APPROVED_DELEGATION_MAX_BYTES,WORKFLOW_APPROVED_DELEGATION_MAX_REQUESTS,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_LAUNCH_PREFLIGHT_PROVIDERS,WORKFLOW_REJECTION_NOTIFICATION_MAX_BYTES,WORKFLOW_REJECTION_NOTIFICATION_SCHEMA,WORKFLOW_ROLE_UNION_MAX_ROLES,WORKFLOW_ROUTING_MAX_BYTES,WORKFLOW_ROUTING_MAX_MATCHED_RULES,WORKFLOW_ROUTING_MAX_RULES,WORKFLOW_STEP_DATA_COMMAND_SCHEMA,WORKFLOW_STEP_DATA_RESOLUTION_SCHEMA,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,assertDevelopmentConfigurationManifest,assertDevelopmentConfigurationResult,assertNativeRoleMembershipBatchInput,assertWorkflowNativeStageGuard,assertWorkflowNativeStagePolicy,assertWorkflowNativeStageSourceGuard,assertWorkflowOwnedSubjectCreate,assertWorkflowOwnedSubjectCreateResources,canonicalDataBusinessIntent,compileNativeApplicationConfiguration,compileNativeEventAction,compileNativeEventCapturePlansV2,compileRequiredPlatformCapabilitiesV3,compileWorkflowBusinessStepHandlers,createDevelopmentConfigurationManifest,dataOwnedRowLimit,dateEventProjectionEnvelopeSchemaV2,dateEventProjectionFieldsV2,developmentBackendBase64Bytes,developmentBackendInvocationHeadersValid,developmentBackendInvocationRequestValid,developmentBackendInvocationRevision,developmentBackendOperationMatches,developmentConfigurationKey,evaluateWorkflowTaskPageExpression,formatWorkflowCompletionDeadline,formatWorkflowExpression,generatedCrudCapabilityOperations,hasDataAuditReadPolicy,isDataAuditMetadataField,isDataOwnedRowLimit,isDataSystemSortField,isDataTransactionActorAuthorityGuard,isDataTransactionRecordSetMatchGuard,isNativeDataQueryOperatorV2,isNativeMultiValueFieldV2,isWorkflowRejectionNotificationSnapshot,matchesDataActorAuthorityMembership,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,nativeUniqueKeysContractVersion,nativeUniqueKeysJsonSchema,normalizeWorkflowOwnedSubjectCreate,parseDataBusinessCommandResolution,parseDataFieldUserCandidates,parseDecimalReservationLifecycle,parseNativeDataFieldsV2,parseNativeDataResourceInvariantsV2,parseNativeUniqueKeys,parseWorkflowStepDataResolution,projectDataResourceView,projectNativeDataResourceViewV2,projectWorkflowGraph,projectWorkflowNodePolicy,quoteNativeIdentifierV2,refreshWorkflowTaskPageFacts,requiresAggregateOwnedSubtableCapacity,requiresDateTimeMinutePrecision,requiresDevelopmentBackendCredential,requiresExtendedArtifactCapacity,requiresExtendedDeclarationCapacity,requiresExtendedOwnedSubtableCapacity,requiresOwnedSubtableMinimumRows,requiresUserCandidateLaunchScope,requiresWorkflowRoleInputSelection,requiresWorkflowRoleUnion,resolveNativeScopeSourceFieldPathV2,resolveWorkflowUserCandidates,selectWorkflowAssignmentRoutingRules,serializedDataBytes,userCandidateScopeValue,validateAuthenticatedPublicRead,validateDecimalReservationLifecycles,validateManagedConcurrency,validateNativeDataDraftStateV2,validateNativeDataResourceReferencesV2,validateNativeDataResourceSurfaceV2,validateUserCandidateReferences,validateWorkflowAdministration,validateWorkflowApprovalEmptyPolicy,validateWorkflowApprovedDelegation,validateWorkflowAssignmentRoutingBindings,validateWorkflowAssignmentRoutingPolicy,validateWorkflowAssignmentRoutingRules,validateWorkflowAutomaticCc,validateWorkflowBusinessStepHandlerContract,validateWorkflowBusinessStepRequest,validateWorkflowBusinessStepResult,validateWorkflowBusinessStepSchema,validateWorkflowBusinessStepSubscriptions,validateWorkflowBusinessSteps,validateWorkflowCommandHandlers,validateWorkflowCompletionDeadlines,validateWorkflowCorrections,validateWorkflowInitiatorApprovalPolicy,validateWorkflowInstanceCommandPolicies,validateWorkflowLaunchPreflight,validateWorkflowNodeConfigurationPatch,validateWorkflowReadability,validateWorkflowRejectionNotification,validateWorkflowRoleInputSelection,validateWorkflowRoleUnion,validateWorkflowTaskPages,validateWorkflowUserCandidateBindings,workflowApprovalCanSkip,workflowApprovedDelegationRequests,workflowAssignmentRoutingFacts,workflowAssignmentRoutingPolicySchema,workflowAssignmentRoutingSemantic,workflowBindingAllowsEmptyUsers,workflowBindingRoleCodes,workflowBusinessCommandInvocationSchema,workflowBusinessStepFactSchema,workflowBusinessStepHandlerDigest,workflowBusinessStepInput,workflowBusinessStepPath,workflowBusinessStepReceiptSignatureSuffix,workflowBusinessStepValueMatches,workflowDelegationMutationRequestSchema,workflowExpressionPaths,workflowInitiatorApprovalCanComplete,workflowInstanceCommandDeadlineError,workflowInstanceTerminateCapabilityAllowed,workflowInstanceWithdrawalReasonRequired,workflowNativeStagePolicySchema,workflowNodeAllowedOperations,workflowOperationCommentRequired,workflowOperationReasonRequired,workflowOwnedSubjectCreateSchema,workflowPolicyTimestamp,workflowRoleCodesSchema,workflowTaskPageFieldState,workflowTaskPageReplayCoversInvalidation,workflowTaskSubtableRows,workflowVariableLabel});