openxiangda-contracts 2.4.0 → 2.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/native-compiler/index.cjs +1 -1
- package/dist/native-compiler/index.js +1 -1
- package/dist/native-version.d.ts +1 -1
- package/dist/native-version.js +1 -1
- package/dist/schemas.d.ts +52 -0
- package/dist/schemas.d.ts.map +1 -1
- package/dist/schemas.js +12 -0
- package/dist/schemas.js.map +1 -1
- package/dist/types.d.ts +15 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +1 -0
- package/dist/types.js.map +1 -1
- package/package.json +1 -1
|
@@ -5,4 +5,4 @@ import{createHash as Fn}from"node:crypto";function Ln(e){if(!e||typeof e!="objec
|
|
|
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 ue(e,...t){return`${e}_${uo("sha256").update(t.join(":")).digest("hex").slice(0,32)}`}function H(e){if(!/^[A-Za-z_][A-Za-z0-9_]{0,62}$/.test(e))throw new Error("OPENXIANGDA_NATIVE_IDENTIFIER_INVALID");return`"${e}"`}function Io(e,t){return e.type==="subtable"?"none":t?"gin-trigram":e.indexed?["date-range","datetime-range"].includes(e.type)?"gist-range":ut.has(e.type)?"btree-snapshot-expressions":fo.has(e.type)?"gin-jsonb-path":"btree":"none"}function mo(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 Eo.has(e.type),"jsonb"}}function Bt(e,t){if(ke(t.type)&&t.type!=="subtable")return"'[]'::jsonb";if(t.type!=="serial-number")return"";let n=jt(t.serial?.prefix||""),o=t.serial?.digits??6;return`(${n} || lpad(nextval(${jt(je(e,t.code))})::text, ${o}, '0'))`}function No(e,t){return Wt.has(t.type)?` CHECK (${e} IS NULL OR jsonb_typeof(${e}) = 'array')`:_o.has(t.type)?` CHECK (${e} IS NULL OR jsonb_typeof(${e}) = 'object')`:""}function xe(e){return`"app_data".${H(e)}`}function je(e,t){let n=ue("seq",e,t);return`"app_data".${H(n)}`}function jt(e){return`'${e.replace(/'/g,"''")}'`}var Jt=new Set(["option.single","option.multiple","user.single","user.multiple","department.single","department.multiple","resource-ref.single","resource-ref.multiple"]),To=new Set([...Jt,"cascade.single","cascade.multiple","file","image","signature","address","location","json"]),Gt=/^[A-Za-z][A-Za-z0-9_]{0,62}$/,go=new Set(["__proto__","prototype","constructor"]),ft=class extends Error{constructor(n){super("OPENXIANGDA_SCOPE_PROJECTION_FIELD_PATH_INVALID");this.path=n;this.name="NativeScopeSourceFieldPathV2Error"}path;code="OPENXIANGDA_SCOPE_PROJECTION_FIELD_PATH_INVALID"};function he(e,t){let n=Yt(e);if(!n)return null;let o=t.get(n[0]);if(!o)return null;let i=n.slice(1).join(".")||void 0;return{field:o,...i?{valuePath:i}:{}}}function _t(e){return!!(e&&e.field.type==="user.single"&&e.valuePath==="value")}function zt(e,t,n){if(!e||!t||!Co(e))return!1;let{field:o,valuePath:i}=e;if(!i)return t.valueType==="uuid"?o.type==="uuid":["text.short","text.long","serial-number"].includes(o.type);if(i==="value")return!(t.valueSourceResourceCode&&o.type.startsWith("resource-ref.")&&o.source?.resourceCode!==t.valueSourceResourceCode);let s=i.slice(9),r=n.get(o.source?.resourceCode||"")?.get(s)?.type;return t.valueType==="uuid"?r==="uuid":["text.short","text.long","serial-number"].includes(r||"")}function Ts(e,t){let n=Yt(t);if(!n)throw new ft(String(t||""));let o=e;for(let i of n){if(!o||typeof o!="object"||!Object.prototype.hasOwnProperty.call(o,i))return;o=o[i]}return o}function Co(e){let{field:t,valuePath:n}=e;if(!n)return!To.has(t.type);if(n==="value")return Jt.has(t.type);if(!n.startsWith("snapshot."))return!1;let o=n.slice(9);return Gt.test(o)&&t.type.startsWith("resource-ref.")&&!!t.source?.snapshotFields?.includes(o)}function Yt(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(n=>!Gt.test(n)||go.has(n))||t.length===2&&t[1]!=="value"||t.length===3&&t[1]!=="snapshot"?null:t}var Oo=new Set(["option.single","user.single","department.single","resource-ref.single"]),bo=new Set(["text.short","text.long","text.rich","number.integer","number.decimal","boolean","date","time","datetime","uuid","serial-number"]),$o=new Set(["value","label","description","color"]),ho=new Set(["avatarUrl","employeeNo","title","mobile","email"]),Ro=new Set(["fullPath","parent.value","parent.label"]),Do=new Set(["country.value","country.label","province.value","province.label","city.value","city.label","district.value","district.label","street.value","street.label","detail","fullAddress"]),So=new Set(["longitude","latitude","accuracy"]),Vo=new Set(["address","name","province","city","district","source"]);function Cs(e){let t=new Map(e.map(n=>[n.code,new Map(n.schema.fields.map(o=>[o.code,o]))]));return e.map(n=>({...n,schema:{...n.schema,fields:n.schema.fields.map(o=>{let i=yo(o,t);if(!Object.keys(i).length)return o;let s={...o};return Object.defineProperty(s,"queryPathTypes",{configurable:!1,enumerable:!1,writable:!1,value:Object.freeze(i)}),s})}}))}function Os(e,t){if(Oo.has(e.type)&&$o.has(t)||e.type==="user.single"&&ho.has(t)||e.type==="department.single"&&Ro.has(t))return Re(t);if(e.type==="resource-ref.single"){let n=e.queryPathTypes?.[t];return n?{parts:t.split("."),type:n}:null}if(e.type==="address"&&Do.has(t))return Re(t);if(e.type==="location"){if(So.has(t))return{parts:[t],type:"number.decimal"};if(Vo.has(t))return Re(t);if(t==="capturedAt")return{parts:[t],type:"datetime"}}return null}function yo(e,t){if(e.type!=="resource-ref.single"||!e.source)return{};let n=t.get(e.source.resourceCode);return n?Object.fromEntries((e.source.snapshotFields||[]).flatMap(o=>{let i=n.get(o);return i?[[`snapshot.${o}`,bo.has(i.type)?i.type:"json"]]:[]})):{}}function Re(e){return{parts:e.split("."),type:"text.short"}}function fe(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)?e:void 0}function Kt(e,t){if(e?.instanceCommands===void 0)return[];let n=fe(e.instanceCommands);if(!n||!Object.keys(n).length||Object.keys(n).some(i=>!["withdraw","terminate"].includes(i)))return["WORKFLOW_INSTANCE_COMMAND_POLICIES_INVALID"];let o=[];for(let[i,s]of Object.entries(n)){let a=fe(s),r=i==="withdraw"?["beforeFact"]:["beforeFact","capability"];if(!a||Object.keys(a).some(d=>!r.includes(d))){o.push(`WORKFLOW_INSTANCE_COMMAND_POLICY_INVALID:${i}`);continue}if(i==="terminate"){let d=a.capability;(typeof d!="string"||d.length>255||!/^app:[a-z][a-z0-9]*(?:-[a-z0-9]+)*:[A-Za-z0-9:._-]+$/.test(d)||t&&(!d.startsWith(`app:${t.appCode}:`)||!t.capabilities.includes(d)))&&o.push("WORKFLOW_INSTANCE_TERMINATE_CAPABILITY_INVALID")}if(i==="withdraw"||a.beforeFact!==void 0){let d=a.beforeFact,_=fe(e.inputSchema),E=fe(fe(_?.properties)?.[d]),u=fe(fe(e.subject)?.factProjection)?.[d],c=t?.fields.get(u);(typeof d!="string"||!/^[A-Za-z][A-Za-z0-9_]{0,62}$/.test(d)||!Array.isArray(_?.required)||!_.required.includes(d)||E?.type!=="string"||E?.format!=="date-time"||typeof u!="string"||t&&(c?.type!=="datetime"||c.nullable===!0))&&o.push(`WORKFLOW_INSTANCE_COMMAND_DEADLINE_FACT_INVALID:${i}`)}}return o}function $s(e,t){let n=e?.terminate?.capability;return typeof n=="string"&&/^app:[a-z][a-z0-9]*(?:-[a-z0-9]+)*:[A-Za-z0-9:._-]+$/.test(n)&&t.includes(n)}function Ht(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[,n,o,i,s,a,r]=t,d=t[8],_=new Date(Date.UTC(Number(n),Number(o),0)).getUTCDate();if(Number(o)<1||Number(o)>12||Number(i)<1||Number(i)>_||Number(s)>23||Number(a)>59||Number(r)>59||d!=="Z"&&(Number(d.slice(1,3))>23||Number(d.slice(4))>59))return null;let E=Date.parse(e);return Number.isFinite(E)?E:null}function hs(e,t,n,o){let i=e?.[t];if(!i||t==="terminate"&&i.beforeFact===void 0)return null;let s=i.beforeFact,a=fe(n),r=s&&a&&Object.hasOwn(a,s)?Ht(a[s]):null,d=o instanceof Date?o.getTime():Ht(o);return r===null||d===null||!Number.isFinite(d)?"WORKFLOW_V2_CANCELLATION_DEADLINE_INVALID":d<r?null:"WORKFLOW_V2_CANCELLATION_DEADLINE_PASSED"}import*as Ge from"crypto";var qt="native-4",Xt={"application-native-2":"1.0.0","authz.native-batch-explain":"1.0.0","authz.native-management":"1.0.0","deployment.durable-runs":"1.0.0","deployment.platform-executor":"1.0.0","environment.on-demand-production":"1.0.0","environment.runtime-lifecycle":"1.0.0","data-api-v2":"1.1.0","data.native-golden-crud":"1.0.0","data.managed-files":"1.1.0","workflow.named-input-sources":"1.0.0","directory-v2":"1.0.0","events-v2":"1.0.0","events.durable-receipts":"1.0.0","workflow-kernel-v2":"1.0.0","workflow.instance-cancellation-policy":"1.0.0","business-process.durable-command":"1.0.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 Ss=5,Vs=20,ys=50,ws=50,Ps=100,Se=class extends Error{constructor(n,o){super(n);this.code=n;this.pointer=o;this.name="NativeDataPolicyExpressionV2Error"}code;pointer};function We(e,t){let n=[],o=(i,s,a)=>{a>5&&De("NATIVE_DATA_POLICY_EXPRESSION_DEPTH_EXCEEDED",s);let r=Zt(i,s),d=["allOf","anyOf"].filter(u=>u in r);if(d.length===0){n.push({rule:r,pointer:s}),n.length>50&&De("NATIVE_DATA_POLICY_EXPRESSION_LEAVES_EXCEEDED",s);return}let _=d[0],E=r[_];(d.length!==1||Object.keys(r).length!==1||!Array.isArray(E)||E.length<1||E.length>20)&&De("NATIVE_DATA_POLICY_EXPRESSION_GROUP_INVALID",s),E.forEach((u,c)=>o(u,`${s}/${_}/${c}`,a+1))};return o(e,t,1),n}function Qt(e,t){We(e,t);let n=(o,i)=>{let s=Zt(o,i);if(Array.isArray(s.allOf))return Et(s.allOf.flatMap((a,r)=>n(a,`${i}/allOf/${r}`)),i);if(Array.isArray(s.anyOf)){let a=[[]];return s.anyOf.forEach((r,d)=>{let _=n(r,`${i}/anyOf/${d}`);a=Et(a.flatMap(E=>_.map(u=>[...E,...u])),i)}),a}return[[s]]};return Et(n(e,t),t)}function Et(e,t){let n=e.reduce((o,i)=>o+i.length,0);return(e.length>50||n>100)&&De("NATIVE_DATA_POLICY_EXPRESSION_EXPANSION_EXCEEDED",t),e}function Zt(e,t){return(!e||typeof e!="object"||Array.isArray(e))&&De("NATIVE_DATA_POLICY_EXPRESSION_NODE_INVALID",t),e}function De(e,t){throw new Se(e,t)}var wo="openxiangda.config-bundle/v3",Nn="openxiangda.contract-bundle/v3",en="openxiangda.native-configuration-projection/v1",ye=qt,Po=/^[a-f0-9]{64}$/,Fo=/^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/,Lo=/^app:[a-z][a-z0-9]*(?:-[a-z0-9]+)*:[A-Za-z0-9:._*-]+$/,vo=/^[a-z][a-z0-9]*(?:[-_.][a-z0-9]+)*$/,ko=/^[a-z][a-z0-9]*(?:[-.][a-z0-9]+)*$/,Mo=/^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/,Uo=/^[A-Za-z][A-Za-z0-9_]{0,62}$/,tn=/^[A-Za-z][A-Za-z0-9_]{0,127}$/,xo=/^[a-z][a-z0-9]*(?:[-_][a-z0-9]+)*$/,jo=/^[A-Z][A-Z0-9_]*$/,Wo=/^[A-Za-z][A-Za-z0-9_-]{0,127}$/,Bo=/^[A-Za-z][A-Za-z0-9_-]{0,127}$/,Jo=/^[A-Za-z][A-Za-z0-9_.]{0,127}$/,Go=16,zo=2*1024,Yo=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"]),Ho=new Set(["overview","database","operations","workflow","members","calendar","document","folder","settings"]),Ko=new Set(["approve","reject","return","transfer","delegate","add_assignee","resubmit","withdraw","terminate","admin_reassign","admin_override","retry_resolution"]),qo=4*1024*1024,Xo=8*1024*1024,Qo=40,Zo=1e5,At=1024*1024,ei="openxiangda.event-handler-manifest/v2",Tn="openxiangda.application-route-manifest/v3",nn=64,ti=new Set(["id","revision","created_by","updated_by","created_at","updated_at"]),B=Object.freeze({perspectives:100,resources:100,capabilities:2e3,operations:500,eventConsumers:100,eventProducers:1e3,eventSchemas:100,eventTypes:500,workflows:100,routes:500,adminPages:500,adminNavigationGroups:100,adminNavigationItems:500}),on=["openxiangda.data.record.created.v2","openxiangda.data.record.updated.v2","openxiangda.data.record.deleted.v2"],It=["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"],ni=new Set(It),mt=class extends Error{code;pointer;identifiers;constructor(t,n,o={}){super(t),this.name="NativeConfigurationCompilerError",this.code=t,this.pointer=n,this.identifiers=Object.fromEntries(Object.entries(o).slice(0,8).map(([i,s])=>[i,String(s).slice(0,128)]))}};function Gs(e){let t=b(e.appCode,"/appCode",128);Fo.test(t)||l("NATIVE_CONFIG_APP_CODE_INVALID","/appCode");let n=Tt(e.expectedConfigDigest,"/expectedConfigDigest"),o=Tt(e.expectedContractDigest,"/expectedContractDigest"),i=An(e.configBytes,qo,"/configBytes","NATIVE_CONFIG_ARTIFACT_TOO_LARGE"),s=An(e.contractBytes,Xo,"/contractBytes","NATIVE_CONTRACT_ARTIFACT_TOO_LARGE");In(i,n,"/configBytes","NATIVE_CONFIG_DIGEST_MISMATCH"),In(s,o,"/contractBytes","NATIVE_CONTRACT_DIGEST_MISMATCH");let a=En(i,"/configBytes","NATIVE_CONFIG_JSON_INVALID","NATIVE_CONFIG_NOT_CANONICAL"),r=En(s,"/contractBytes","NATIVE_CONTRACT_JSON_INVALID","NATIVE_CONTRACT_NOT_CANONICAL");pn(a,"/config"),pn(r,"/contracts");let d=a,_=r;ri(d,t),ai(_,t,n);let E=ci(d,n,_.generatorVersion);W(E)!==W(_)&&l("NATIVE_CONTRACT_CLOSURE_MISMATCH",gt(E,_,"/contracts"));let u={authz:{appCode:t,...d.authz,perspectives:d.perspectives,capabilityCatalog:E.capabilities},data:{appCode:t,resources:d.data.resources,resourceContracts:E.resources},events:{appCode:t,...d.events,consumers:E.eventConsumers,producers:E.eventProducers,handlerManifest:E.eventHandlerManifest,eventTypes:E.eventTypes,capturePlans:ii({resources:d.data.resources,dataPolicies:d.authz.dataPolicies,subscriptions:E.eventConsumers})},workflows:{appCode:t,...d.workflows,contracts:E.workflows},runtime:{appCode:t,requirements:d.runtime,backend:d.backend,frontend:d.frontend},contracts:E},c={authz:Ce(u.authz),data:Ce(u.data),events:Ce(u.events),workflows:Ce(u.workflows),runtime:Ce(u.runtime),contracts:Ce(u.contracts)},p={configDigest:n,contractDigest:o,generatorVersion:_.generatorVersion},f=oi(d),A={schemaVersion:en,compilerContractVersion:ye,appCode:t,source:p,projections:c,requiredPlatformCapabilities:f,aggregateDigest:Z({schemaVersion:en,compilerContractVersion:ye,appCode:t,source:p,requiredPlatformCapabilities:f,projectionDigests:Object.fromEntries(Object.entries(c).map(([m,N])=>[m,N.digest]))})};return wn(A)}function oi(e){let t=e.authz.roles,n=e.data.resources,o=e.backend.operations,i=t.some(f=>f.capabilities.some(A=>A.endsWith(":directory:read")))||n.some(f=>f.schema.fields.some(A=>["user.single","user.multiple","department.single","department.multiple"].includes(A.type)))||o.some(f=>f.platformAccess?.directory),s=!!(e.events.subscriptions.length||e.events.timers.length||e.events.dateTriggers.length||e.events.schemas.length),a=o.some(f=>f.platformAccess?.managedFiles||f.platformAccess?.managedFileCopies)||e.events.subscriptions.some(f=>f.platformAccess?.managedFileCopies),r=o.some(f=>f.platformAccess?.notification)||e.events.subscriptions.some(f=>f.platformAccess?.notification),d=e.workflows.definitions.filter(f=>f.launch.mode==="standalone"||f.launch.mode==="hidden-handoff"),_=o.some(f=>f.platformAccess?.workflow)||d.length>0,E={resources:n},u={perspectives:e.perspectives,authz:e.authz},c={schemaVersion:e.schemaVersion,appCode:e.appCode,frontend:{routes:e.frontend.routes,user:e.frontend.user,admin:e.frontend.admin,devicePolicy:e.frontend.devicePolicy},backend:{operations:o.map(f=>({code:f.code,method:f.method,path:f.path,capability:f.capability,platformAccess:f.platformAccess||null,ai:f.ai||null}))}};return[{code:"application-native-2",declaration:c},{code:"authz.native-batch-explain",declaration:u},{code:"authz.native-management",declaration:u},{code:"deployment.durable-runs",declaration:c.backend},{code:"deployment.platform-executor",declaration:c.backend},{code:"environment.on-demand-production",declaration:{environments:["preproduction","production"]}},{code:"environment.runtime-lifecycle",declaration:{environments:["preproduction","production"]}},...n.length?[{code:"data-api-v2",declaration:E},{code:"data.native-golden-crud",declaration:E}]:[],...i?[{code:"directory-v2",declaration:{roles:t.map(f=>({code:f.code,capabilities:f.capabilities.filter(A=>A.endsWith(":directory:read"))})),resources:n.map(f=>({code:f.code,fields:f.schema.fields.filter(A=>["user.single","user.multiple","department.single","department.multiple"].includes(A.type))})),operations:o.filter(f=>f.platformAccess?.directory).map(f=>({code:f.code,directory:f.platformAccess.directory}))}}]:[],...a?[{code:"data.managed-files",declaration:{operations:o.filter(f=>f.platformAccess?.managedFiles||f.platformAccess?.managedFileCopies).map(f=>({code:f.code,...f.platformAccess?.managedFiles?{managedFiles:f.platformAccess.managedFiles}:{},...f.platformAccess?.managedFileCopies?{managedFileCopies:f.platformAccess.managedFileCopies}:{}})),subscriptions:e.events.subscriptions.filter(f=>f.platformAccess?.managedFileCopies).map(f=>({code:f.code,managedFileCopies:f.platformAccess.managedFileCopies}))}}]:[],...s?[{code:"events-v2",declaration:e.events},{code:"events.durable-receipts",declaration:e.events}]:[],...e.workflows.activations.length?[{code:"workflow-kernel-v2",declaration:e.workflows},{code:"workflow.fresh-command-token",declaration:e.workflows}]:[],...e.workflows.definitions.some(f=>f.definition.instanceCommands!==void 0)?[{code:"workflow.instance-cancellation-policy",declaration:e.workflows.definitions.filter(f=>f.definition.instanceCommands!==void 0)}]:[],..._?[{code:"business-process.durable-command",declaration:{operations:o.filter(f=>f.platformAccess?.workflow).map(f=>({code:f.code,workflow:f.platformAccess.workflow})),definitions:d,activations:e.workflows.activations.filter(f=>d.some(A=>A.definition.code===f.workflowCode))}}]:[],...r?[{code:"notification-hub-v2",declaration:{operations:o.filter(f=>f.platformAccess?.notification).map(f=>({code:f.code,notification:f.platformAccess.notification})),subscriptions:e.events.subscriptions.filter(f=>f.platformAccess?.notification).map(f=>({code:f.code,notification:f.platformAccess.notification}))}}]:[],...e.frontend.authentication?[{code:"authentication.application-login-surface",declaration:e.frontend.authentication}]:[],...e.frontend.publicAccess?[{code:"public-access.anonymous-owner-records",declaration:e.frontend.publicAccess}]:[]].map(({code:f,declaration:A})=>({code:f,contractVersion:Xt[f],usageDigest:`sha256:${Z(A)}`})).sort((f,A)=>f.code===A.code?0:f.code<A.code?-1:1)}function ii(e){let t=new Map(e.dataPolicies.map((o,i)=>{let s=I(o,`/capturePlan/dataPolicies/${i}`);return[String(s.code),s]})),n=e.subscriptions.map((o,i)=>I(o,`/capturePlan/subscriptions/${i}`));return e.resources.map((o,i)=>{let s=`/capturePlan/resources/${i}`,a=I(o,s),r=x(a.code,`${s}/code`),d=a.schema?I(a.schema,`${s}/schema`):a,_=new Set($(d.fields||[],`${s}/schema/fields`,500).map((g,D)=>J(I(g,`${s}/schema/fields/${D}`).code,`${s}/schema/fields/${D}/code`))),E=a.dataPolicyCode?S(a.dataPolicyCode,`${s}/dataPolicyCode`):null,u=E?t.get(E):void 0;E&&!u&&l("NATIVE_EVENT_CAPTURE_AUTHZ_POLICY_NOT_FOUND",s,{resourceCode:r,dataPolicyCode:E});let c=new Set;for(let g of u?.rules||[])c.add(String(g.field));if(u?.readExpression)for(let g of We(u.readExpression,`${s}/readExpression`))c.add(String(g.rule.field));let p=new Set,f=new Set;for(let[g,D]of n.entries()){if(!$(D.eventTypes,`/capturePlan/subscriptions/${g}/eventTypes`,20).map(String).some(L=>L.startsWith("openxiangda.data.")))continue;let R=I(D.filter||{},`/capturePlan/subscriptions/${g}/filter`),v=Array.isArray(R.resourceCodes)?R.resourceCodes.map(String):[];if(v.length&&!v.includes(r))continue;for(let L of si(R,`/capturePlan/subscriptions/${g}/filter`))p.add(L);let V=I(D.payload||{},`/capturePlan/subscriptions/${g}/payload`);for(let L of $(V.fields||[],`/capturePlan/subscriptions/${g}/payload/fields`,32))f.add(J(L,`/capturePlan/subscriptions/${g}/payload/fields`))}let A=new Set([...p,...f]),m=new Set([...A,...c]);m.size>nn&&l("NATIVE_EVENT_CAPTURE_FIELDS_LIMIT",s,{resourceCode:r,maximum:nn});for(let g of m)!_.has(g)&&!(c.has(g)&&ti.has(g))&&l("NATIVE_EVENT_CAPTURE_FIELD_NOT_FOUND",s,{resourceCode:r,field:g});let N=I(a.fieldPolicies||{},`${s}/fieldPolicies`);for(let g of A)N[g]?.mask==="omit"&&l("NATIVE_EVENT_CAPTURE_FIELD_SENSITIVE",s,{resourceCode:r,field:g});let C={resourceCode:r,filterFields:[...p].sort(),projectionFields:[...f].sort(),authorizationFields:[...c].sort(),captureFields:[...m].sort()};return{...C,digest:Z(C)}}).sort((o,i)=>o.resourceCode.localeCompare(i.resourceCode))}function si(e,t){let n=new Set;for(let[a,r]of $(e.changes||[],`${t}/changes`,16).entries()){let d=I(r,`${t}/changes/${a}`);n.add(J(d.field,`${t}/changes/${a}/field`))}let o=I(e.changedFields||{},`${t}/changedFields`);for(let a of["anyOf","allOf","noneOf"])for(let[r,d]of $(o[a]||[],`${t}/changedFields/${a}`,32).entries())n.add(J(d,`${t}/changedFields/${a}/${r}`));let i=0,s=(a,r,d)=>{d>3&&l("NATIVE_EVENT_FILTER_DEPTH_LIMIT",r);let _=I(a,r);if(_.change){let u=I(_.change,`${r}/change`);n.add(J(u.field,`${r}/change/field`)),i+=1;return}if(_.not){s(_.not,`${r}/not`,d+1);return}let E=_.all?"all":_.any?"any":null;E||l("NATIVE_EVENT_FILTER_CONDITION_INVALID",r);for(let[u,c]of $(_[E],`${r}/${E}`,16).entries())s(c,`${r}/${E}/${u}`,d+1)};return e.where&&s(e.where,`${t}/where`,1),i+=Array.isArray(e.changes)?e.changes.length:0,i>16&&l("NATIVE_EVENT_FILTER_ATOM_LIMIT",t),[...n].sort()}function ri(e,t){T(e,["schemaVersion","compilerContractVersion","appCode","perspectives","authz","backend","data","events","workflows","frontend","runtime"],"/config"),F(e.schemaVersion,wo,"/config/schemaVersion"),F(e.compilerContractVersion,ye,"/config/compilerContractVersion"),F(e.appCode,t,"/config/appCode"),$(e.perspectives,"/config/perspectives",100);let n=I(e.authz,"/config/authz");T(n,["capabilities","roles","scopeDimensions","scopeSources","roleMembershipSources","relationshipGrantSources","dataPolicies","authorizationTransitions"],"/config/authz",["authenticatedUserRoleCode"]),$(n.capabilities,"/config/authz/capabilities",2e3),$(n.roles,"/config/authz/roles",100),$(n.scopeDimensions,"/config/authz/scopeDimensions",100),$(n.scopeSources,"/config/authz/scopeSources",100),$(n.roleMembershipSources,"/config/authz/roleMembershipSources",100),$(n.relationshipGrantSources,"/config/authz/relationshipGrantSources",100),$(n.dataPolicies,"/config/authz/dataPolicies",100),$(n.authorizationTransitions,"/config/authz/authorizationTransitions",100);let o=I(e.backend,"/config/backend");T(o,["secrets","operations"],"/config/backend"),$(o.secrets,"/config/backend/secrets",100),$(o.operations,"/config/backend/operations",500),Ui(o.secrets);let i=I(e.data,"/config/data");T(i,["resources"],"/config/data",["resourceDetailRoutes"]),$(i.resources,"/config/data/resources",100),i.resourceDetailRoutes!==void 0&&$(i.resourceDetailRoutes,"/config/data/resourceDetailRoutes",100);let s=I(e.events,"/config/events");T(s,["schemas","subscriptions","timers","dateTriggers"],"/config/events"),$(s.schemas,"/config/events/schemas",100),$(s.subscriptions,"/config/events/subscriptions",100),$(s.timers,"/config/events/timers",100),$(s.dateTriggers,"/config/events/dateTriggers",100);let a=I(e.workflows,"/config/workflows");T(a,["definitions","bindings","activations","providers","editableParameters"],"/config/workflows"),$(a.definitions,"/config/workflows/definitions",100),$(a.bindings,"/config/workflows/bindings",100),$(a.activations,"/config/workflows/activations",100),$(a.providers,"/config/workflows/providers",100),$(a.editableParameters,"/config/workflows/editableParameters",100);let r=I(e.frontend,"/config/frontend");T(r,["routes","user","admin","devicePolicy"],"/config/frontend",["authentication","publicAccess"]),$(r.routes,"/config/frontend/routes",500);let d=I(r.user,"/config/frontend/user");T(d,["applicationTodoCenter"],"/config/frontend/user"),be(d.applicationTodoCenter,"/config/frontend/user/applicationTodoCenter"),Ct(r.devicePolicy,"/config/frontend/devicePolicy"),Object.prototype.hasOwnProperty.call(r,"authentication")&&Cn(r.authentication,r.routes,e,"/config/frontend/authentication"),Object.prototype.hasOwnProperty.call(r,"publicAccess")&&Ti(r.publicAccess,e,"/config/frontend/publicAccess");let _=I(r.admin,"/config/frontend/admin");T(_,["navigation"],"/config/frontend/admin",["access"]),_.access!==void 0&&Ye(_.access,"/config/frontend/admin/access",e.appCode),bi(_.navigation,"/config/frontend/admin/navigation");let E=I(e.runtime,"/config/runtime");T(E,["protocolCapabilities","health"],"/config/runtime"),w(E.protocolCapabilities,"/config/runtime/protocolCapabilities",100),T(I(E.health,"/config/runtime/health"),["livePath","readyPath","versionPath"],"/config/runtime/health"),F(E.health.livePath,"/__platform/health","/config/runtime/health/livePath"),F(E.health.readyPath,"/__platform/ready","/config/runtime/health/readyPath"),F(E.health.versionPath,"/__platform/version","/config/runtime/health/versionPath")}function ai(e,t,n){T(e,["schemaVersion","compilerContractVersion","generatorVersion","appCode","configDigest","perspectives","resources","capabilities","operations","eventConsumers","eventProducers","eventSchemas","eventHandlerManifest","eventTypes","workflows","routes","routeManifest","adminPages","adminNavigation"],"/contracts",["authentication","publicAccess","adminAccess"]),F(e.schemaVersion,Nn,"/contracts/schemaVersion"),F(e.compilerContractVersion,ye,"/contracts/compilerContractVersion"),b(e.generatorVersion,"/contracts/generatorVersion",128),F(e.appCode,t,"/contracts/appCode"),F(e.configDigest,n,"/contracts/configDigest"),$(e.perspectives,"/contracts/perspectives",B.perspectives),$(e.resources,"/contracts/resources",B.resources),$(e.capabilities,"/contracts/capabilities",B.capabilities),$(e.operations,"/contracts/operations",B.operations),$(e.eventConsumers,"/contracts/eventConsumers",B.eventConsumers),$(e.eventProducers,"/contracts/eventProducers",B.eventProducers),$(e.eventSchemas,"/contracts/eventSchemas",B.eventSchemas),I(e.eventHandlerManifest,"/contracts/eventHandlerManifest"),w(e.eventTypes,"/contracts/eventTypes",B.eventTypes),$(e.workflows,"/contracts/workflows",B.workflows),$(e.routes,"/contracts/routes",B.routes),Object.prototype.hasOwnProperty.call(e,"authentication")&&Ii(e.authentication,"/contracts/authentication"),Object.prototype.hasOwnProperty.call(e,"publicAccess")&&gi(e.publicAccess,"/contracts/publicAccess"),Object.prototype.hasOwnProperty.call(e,"adminAccess")&&Ye(e.adminAccess,"/contracts/adminAccess",t),Vi(e.routeManifest,"/contracts/routeManifest",t),Ri(e.adminPages,"/contracts/adminPages"),Di(e.adminNavigation,"/contracts/adminNavigation")}function ci(e,t,n){let o=ui(e);Li(e,o),ki(e),vi(e),xi(e);let i=e.events.schemas.map((c,p)=>{let f=`/config/events/schemas/${p}`,A=I(c,f),m=b(A.eventType,`${f}/eventType`,255);return m.startsWith("openxiangda.")&&l("NATIVE_EVENT_SCHEMA_RESERVED",`${f}/eventType`,{eventType:m}),F(A.schemaDigest,Z(I(A.jsonSchema,`${f}/jsonSchema`)),`${f}/schemaDigest`),A}),s=new Set([...on,...It,...i.map(c=>String(c.eventType))]),a=new Map(e.data.resources.map(c=>[String(c.code),new Map(c.schema.fields.map(p=>[String(p.code),String(p.type)]))])),r=q(e.events.subscriptions.map((c,p)=>{let f=`/config/events/subscriptions/${p}`,A=I(c,f),m=w(A.eventTypes,`${f}/eventTypes`,20);m.forEach((g,D)=>{s.has(g)||l("NATIVE_EVENT_TYPE_NOT_REGISTERED",`${f}/eventTypes/${D}`,{eventType:g})});let N=li(A.delivery,m,`${f}/delivery`),C=di(A.platformAccess,`${f}/platformAccess`,a);return{code:S(A.code,`${f}/code`),endpointPath:ee(A.endpointPath,`${f}/endpointPath`),eventTypes:m,filter:I(A.filter,`${f}/filter`),payload:I(A.payload,`${f}/payload`),...C?{platformAccess:C}:{},delivery:N}}),c=>c.code),d=new Map(i.map(c=>[String(c.eventType),String(c.dataSchemaVersion)])),_=q([...e.data.resources.flatMap(c=>on.map(p=>({code:`data:${c.code}:${p}`,source:"data",eventType:p,dataSchemaVersion:"2.0.0",resourceCode:c.code}))),...i.map(c=>({code:`app:${c.eventType}`,source:"app",eventType:c.eventType,dataSchemaVersion:c.dataSchemaVersion})),...e.events.timers.map(c=>({code:c.code,source:"timer",eventType:c.eventType,dataSchemaVersion:d.get(String(c.eventType))||"2.0.0"})),...e.events.dateTriggers.map(c=>({code:c.code,source:"date",eventType:c.eventType,dataSchemaVersion:d.get(String(c.eventType))||"2.0.0",resourceCode:c.resourceCode,field:c.field})),...e.workflows.activations.length?It.map(c=>({code:`workflow:${c}`,source:"workflow",eventType:c,dataSchemaVersion:"2.0.0"})):[]],c=>`${c.source}:${c.code}:${c.eventType}`),E=k([...r.flatMap(c=>c.eventTypes),..._.map(c=>String(c.eventType))]);hi(e);let u=$n(e);return{schemaVersion:Nn,compilerContractVersion:ye,generatorVersion:n,appCode:e.appCode,configDigest:t,perspectives:e.perspectives,resources:fi(e),capabilities:q(o,c=>c.code),operations:gn(e),eventConsumers:r,eventProducers:_,eventSchemas:i,eventHandlerManifest:{schemaVersion:ei,appCode:e.appCode,handlers:r.map(c=>({code:c.code,endpointPath:c.endpointPath,eventTypes:c.eventTypes,dataSchemaVersions:k(c.eventTypes.map(p=>p.startsWith("openxiangda.")?"2.0.0":d.get(p)||"2.0.0")),maxBodyBytes:65536,receiptProtocolVersion:2}))},eventTypes:E,workflows:Dn(e),routes:ze(e),...Object.prototype.hasOwnProperty.call(e.frontend,"authentication")?{authentication:mi(e)}:{},...Object.prototype.hasOwnProperty.call(e.frontend,"publicAccess")?{publicAccess:Ci(e)}:{},...e.frontend.admin.access?{adminAccess:e.frontend.admin.access}:{},routeManifest:Pi(e),adminPages:u,adminNavigation:Oi(e)}}function di(e,t,n){if(e===void 0)return;let o=I(e,t);T(o,["notification","managedFileCopies"],t,!0);let i={};if(o.notification!==void 0){let s=I(o.notification,`${t}/notification`);T(s,["mode"],`${t}/notification`),F(s.mode,"business-standard",`${t}/notification/mode`),i.notification={mode:"business-standard"}}if(o.managedFileCopies!==void 0){let s=$(o.managedFileCopies,`${t}/managedFileCopies`,16);s.length||l("NATIVE_EVENT_MANAGED_FILE_COPIES_REQUIRED",`${t}/managedFileCopies`);let a=new Set;i.managedFileCopies=q(s.map((r,d)=>{let _=`${t}/managedFileCopies/${d}`,E=I(r,_);T(E,["mode","sourceResourceCode","sourceFieldCodes","targetResourceCode","targetFieldCodes"],_),F(E.mode,"copy",`${_}/mode`);let u=x(E.sourceResourceCode,`${_}/sourceResourceCode`),c=x(E.targetResourceCode,`${_}/targetResourceCode`),p=n.get(u),f=n.get(c);(!p||!f)&&l("NATIVE_EVENT_MANAGED_FILE_COPY_RESOURCE_INVALID",_);let A=w(E.sourceFieldCodes,`${_}/sourceFieldCodes`,16),m=w(E.targetFieldCodes,`${_}/targetFieldCodes`,16);(!A.length||A.length!==m.length)&&l("NATIVE_EVENT_MANAGED_FILE_COPY_FIELDS_INVALID",_),A.forEach((C,g)=>{let D=p.get(C),h=f.get(m[g]);(!["file","image"].includes(String(D))||D!==h)&&l("NATIVE_EVENT_MANAGED_FILE_COPY_FIELD_INVALID",`${_}/sourceFieldCodes/${g}`)});let N=`${u}:${A.join(",")}=>${c}:${m.join(",")}`;return a.has(N)&&l("NATIVE_EVENT_MANAGED_FILE_COPY_DUPLICATE",_),a.add(N),{mode:"copy",sourceResourceCode:u,sourceFieldCodes:k(A),targetResourceCode:c,targetFieldCodes:k(m)}}),r=>`${r.sourceResourceCode}:${r.sourceFieldCodes.join(",")}=>${r.targetResourceCode}:${r.targetFieldCodes.join(",")}`)}return Object.keys(i).length||l("NATIVE_EVENT_PLATFORM_ACCESS_EMPTY",t),i}function li(e,t,n){let o=I(e,n);T(o,["timeoutMs","maxAttempts","initialBackoffMs","maxBackoffMs","ordering","concurrency"],n),z(o.timeoutMs,`${n}/timeoutMs`,1e3,3e4),z(o.maxAttempts,`${n}/maxAttempts`,1,12);let i=z(o.initialBackoffMs,`${n}/initialBackoffMs`,1e3,3e5);z(o.maxBackoffMs,`${n}/maxBackoffMs`,i,18e5),z(o.concurrency,`${n}/concurrency`,1,50);let s=b(o.ordering,`${n}/ordering`,32);return["none","record","workflow-instance"].includes(s)||l("NATIVE_EVENT_DELIVERY_ORDERING_INVALID",`${n}/ordering`),s==="workflow-instance"&&t.some(a=>!ni.has(a))&&l("NATIVE_EVENT_WORKFLOW_ORDERING_REQUIRES_WORKFLOW_FACTS",`${n}/ordering`),o}function ui(e){let t=new Map;for(let n of yn(e.appCode))t.set(n.code,n);for(let[n,o]of e.authz.capabilities.entries()){let i=`/config/authz/capabilities/${n}`,s=I(o,i);T(s,["code","kind","name","description"],i,!0);let a=_e(s.code,`${i}/code`,e.appCode);t.has(a)&&l("NATIVE_CAPABILITY_DUPLICATE",`${i}/code`),["backend","ui"].includes(s.kind)||l("NATIVE_CAPABILITY_KIND_INVALID",`${i}/kind`);let r={code:a,kind:s.kind,name:b(s.name,`${i}/name`,255),source:"explicit",...s.description===void 0?{}:{description:bt(s.description,`${i}/description`,2e3)}};t.set(a,r)}for(let[n,o]of e.data.resources.entries()){let i=`/config/data/resources/${n}`,s=we(o,i,e.appCode),a={read:`\u8BFB\u53D6${s.name}`,create:`\u65B0\u5EFA${s.name}`,update:`\u66F4\u65B0${s.name}`,delete:`\u5220\u9664${s.name}`};for(let r of["read","create","update","delete"]){let d=_e(s.capabilities[r],`${i}/capabilities/${r}`,e.appCode);t.has(d)&&l("NATIVE_CAPABILITY_DUPLICATE",`${i}/capabilities/${r}`),t.set(d,{code:d,kind:"data",name:a[r],source:"data"})}for(let[r,d]of Object.entries(s.fieldPolicies)){let _=I(d,`${i}/fieldPolicies/${r}`);for(let E of["read","create","update"])if(Array.isArray(_[E]))for(let u of w(_[E],`${i}/fieldPolicies/${r}/${E}`,2e3))_e(u,`${i}/fieldPolicies/${r}/${E}`,e.appCode),!t.has(u)&&t.set(u,{code:u,kind:"data",name:`${s.name}.${r}.${E}`,source:"data"})}}return[...t.values()]}function fi(e){let t=_i(e);return q(e.data.resources.map((n,o)=>{let i=we(n,`/config/data/resources/${o}`,e.appCode),s=t.get(i.code);return{code:i.code,schemaDigest:Z(i.schema),fields:q(i.schema.fields.map(a=>({code:a.code,type:a.type})),a=>a.code),...s?{detailRouteCode:s}:{}}}),n=>n.code)}function _i(e){let t=e.data.resourceDetailRoutes===void 0?[]:$(e.data.resourceDetailRoutes,"/config/data/resourceDetailRoutes",100),n=new Map(e.data.resources.map((s,a)=>{let r=`/config/data/resources/${a}`,d=we(s,r,e.appCode);return[d.code,d]})),o=new Map(ze(e).map(s=>[String(s.code),s])),i=new Map;for(let[s,a]of t.entries()){let r=`/config/data/resourceDetailRoutes/${s}`,d=I(a,r);T(d,["resourceCode","desktop","mobile"],r);let _=x(d.resourceCode,`${r}/resourceCode`);i.has(_)&&l("NATIVE_DATA_RESOURCE_DETAIL_ROUTE_DUPLICATE",`${r}/resourceCode`);let E=n.get(_);E||l("NATIVE_DATA_RESOURCE_DETAIL_ROUTE_RESOURCE_MISSING",`${r}/resourceCode`);let u=S(d.desktop,`${r}/desktop`),c=S(d.mobile,`${r}/mobile`);u===c&&l("NATIVE_DATA_RESOURCE_DETAIL_ROUTE_INVALID",r);let p=String(E.capabilities.read);for(let[f,A]of[["desktop",u],["mobile",c]]){let m=`${r}/${f}`,N=o.get(A);N||l("NATIVE_DATA_RESOURCE_DETAIL_ROUTE_REFERENCE_MISSING",m),N.surface!=="user"&&l("NATIVE_DATA_RESOURCE_DETAIL_ROUTE_SURFACE_INVALID",m);let C=ee(N.path,`${m}/path`),g=[...C.matchAll(/:([A-Za-z][A-Za-z0-9_]*)/g)],D=f==="mobile"?!C.startsWith("/m/"):C==="/m"||C.startsWith("/m/");(C.includes("*")||C.includes("?")||C.includes("#")||C.split("/").includes("..")||g.length!==1||D)&&l("NATIVE_DATA_RESOURCE_DETAIL_ROUTE_PATH_INVALID",m);let h=Array.isArray(N.access?.allOf)?N.access.allOf:[];N.capability!==p&&!h.includes(p)&&l("NATIVE_DATA_RESOURCE_DETAIL_ROUTE_CAPABILITY_INVALID",m)}i.set(_,{desktop:u,mobile:c})}return i}function gn(e){let t=new Map(e.data.resources.map((i,s)=>{let a=`/config/data/resources/${s}`,r=we(i,a,e.appCode);return[r.code,new Map(r.schema.fields.map(d=>[String(d.code),String(d.type)]))]})),n=new Set(t.keys()),o=new Set(e.workflows.activations.map((i,s)=>He(I(i,`/config/workflows/activations/${s}`).workflowCode,`/config/workflows/activations/${s}/workflowCode`)));return q(e.backend.operations.map((i,s)=>{let a=`/config/backend/operations/${s}`,r=I(i,a);T(r,["code","method","path","capability","requestSchema","responseSchema","description","platformAccess","ai"],a,!0);let d=b(r.method,`${a}/method`,16);["GET","POST","PUT","PATCH","DELETE"].includes(d)||l("NATIVE_OPERATION_METHOD_INVALID",`${a}/method`);let _=S(r.code,`${a}/code`);pi(r.ai,a,_,d,n);let E=Ei(r.platformAccess,`${a}/platformAccess`,t,o,new Set(e.authz.roles.map(u=>String(u.code))));return{code:_,method:d,path:ee(r.path,`${a}/path`),requiredCapability:_e(r.capability,`${a}/capability`,e.appCode),requestSchemaDigest:Z(I(r.requestSchema,`${a}/requestSchema`)),responseSchemaDigest:Z(I(r.responseSchema,`${a}/responseSchema`)),...r.description===void 0?{}:{description:bt(r.description,`${a}/description`,2e3)},...E?{platformAccess:E}:{}}}),i=>i.code)}function Ei(e,t,n,o,i){if(e===void 0)return null;let s=I(e,t);T(s,["directory","managedFiles","managedFileCopies","notification","workflow","roleAssertions"],t,!0),Object.keys(s).length===0&&l("NATIVE_OPERATION_PLATFORM_ACCESS_EMPTY",t);let a={};if(s.roleAssertions!==void 0){let r=I(s.roleAssertions,`${t}/roleAssertions`);T(r,["roleCodes"],`${t}/roleAssertions`);let d=w(r.roleCodes,`${t}/roleAssertions/roleCodes`,20);d.length||l("NATIVE_OPERATION_ROLE_ASSERTIONS_REQUIRED",`${t}/roleAssertions/roleCodes`),d.forEach((_,E)=>{i.has(_)||l("NATIVE_ROLE_REFERENCE_MISSING",`${t}/roleAssertions/roleCodes/${E}`)}),a.roleAssertions={roleCodes:k(d)}}if(s.directory!==void 0){let r=I(s.directory,`${t}/directory`);T(r,["mode","fields"],`${t}/directory`),r.mode!=="current-initiator"&&l("NATIVE_OPERATION_DIRECTORY_MODE_INVALID",`${t}/directory/mode`);let d=new Set(["displayName","employeeNumber","primaryDepartment","departments"]),_=w(r.fields,`${t}/directory/fields`,4);(!_.length||_.some(E=>!d.has(E)))&&l("NATIVE_OPERATION_DIRECTORY_FIELDS_INVALID",`${t}/directory/fields`),a.directory={mode:"current-initiator",fields:k(_)}}if(s.managedFiles!==void 0){let r=$(s.managedFiles,`${t}/managedFiles`,16);r.length||l("NATIVE_OPERATION_MANAGED_FILES_REQUIRED",`${t}/managedFiles`);let d=new Set;a.managedFiles=q(r.map((_,E)=>{let u=`${t}/managedFiles/${E}`,c=I(_,u);T(c,["resourceCode","fieldCodes","intents"],u);let p=x(c.resourceCode,`${u}/resourceCode`);(d.has(p)||!n.has(p))&&l("NATIVE_OPERATION_MANAGED_FILE_RESOURCE_INVALID",`${u}/resourceCode`),d.add(p);let f=w(c.fieldCodes,`${u}/fieldCodes`,16);(!f.length||f.some(m=>!["file","image","signature"].includes(String(n.get(p)?.get(m)||""))))&&l("NATIVE_OPERATION_MANAGED_FILE_FIELD_INVALID",`${u}/fieldCodes`);let A=w(c.intents,`${u}/intents`,2);return(!A.length||A.some(m=>!["create","update"].includes(m)))&&l("NATIVE_OPERATION_MANAGED_FILE_INTENT_INVALID",`${u}/intents`),{resourceCode:p,fieldCodes:k(f),intents:k(A)}}),_=>_.resourceCode)}if(s.managedFileCopies!==void 0){let r=$(s.managedFileCopies,`${t}/managedFileCopies`,16);r.length||l("NATIVE_OPERATION_MANAGED_FILE_COPIES_REQUIRED",`${t}/managedFileCopies`);let d=new Set;a.managedFileCopies=q(r.map((_,E)=>{let u=`${t}/managedFileCopies/${E}`,c=I(_,u);T(c,["mode","sourceResourceCode","sourceFieldCodes","targetResourceCode","targetFieldCodes"],u),F(c.mode,"copy",`${u}/mode`);let p=x(c.sourceResourceCode,`${u}/sourceResourceCode`),f=x(c.targetResourceCode,`${u}/targetResourceCode`),A=n.get(p),m=n.get(f);(!A||!m)&&l("NATIVE_OPERATION_MANAGED_FILE_COPY_RESOURCE_INVALID",u);let N=w(c.sourceFieldCodes,`${u}/sourceFieldCodes`,16),C=w(c.targetFieldCodes,`${u}/targetFieldCodes`,16);(!N.length||N.length!==C.length)&&l("NATIVE_OPERATION_MANAGED_FILE_COPY_FIELDS_INVALID",u),N.forEach((D,h)=>{let R=A.get(D),v=m.get(C[h]);(!["file","image"].includes(String(R))||R!==v)&&l("NATIVE_OPERATION_MANAGED_FILE_COPY_FIELD_INVALID",`${u}/sourceFieldCodes/${h}`)});let g=`${p}:${N.join(",")}=>${f}:${C.join(",")}`;return d.has(g)&&l("NATIVE_OPERATION_MANAGED_FILE_COPY_DUPLICATE",u),d.add(g),{mode:"copy",sourceResourceCode:p,sourceFieldCodes:k(N),targetResourceCode:f,targetFieldCodes:k(C)}}),_=>`${_.sourceResourceCode}:${_.sourceFieldCodes.join(",")}=>${_.targetResourceCode}:${_.targetFieldCodes.join(",")}`)}if(s.notification!==void 0){let r=I(s.notification,`${t}/notification`);T(r,["mode"],`${t}/notification`),r.mode!=="business-standard"&&l("NATIVE_OPERATION_NOTIFICATION_MODE_INVALID",`${t}/notification/mode`),a.notification={mode:"business-standard"}}if(s.workflow!==void 0){let r=I(s.workflow,`${t}/workflow`);T(r,["codes"],`${t}/workflow`);let d=w(r.codes,`${t}/workflow/codes`,16);(!d.length||d.some(_=>!o.has(_)))&&l("NATIVE_OPERATION_WORKFLOW_CODE_INVALID",`${t}/workflow/codes`),a.workflow={codes:k(d)}}return a}function pi(e,t,n,o,i){if(e===void 0)return;let s=`${t}/ai`,a=I(e,s);ko.test(n)||l("NATIVE_OPERATION_AI_CODE_INVALID",`${t}/code`),T(a,["name","description","risk","resources","sideEffects","concurrency","timeoutMs"],s,!0),b(a.name,`${s}/name`,At),b(a.description,`${s}/description`,At);let r=b(a.risk,`${s}/risk`,16);["read","write","destructive","external"].includes(r)||l("NATIVE_OPERATION_AI_RISK_INVALID",`${s}/risk`),r==="read"!=(o==="GET")&&l("NATIVE_OPERATION_AI_METHOD_RISK_MISMATCH",`${s}/risk`),o==="DELETE"&&!["destructive","external"].includes(r)&&l("NATIVE_OPERATION_AI_METHOD_RISK_MISMATCH",`${s}/risk`);let d=w(a.resources,`${s}/resources`,16);d.length===0&&l("NATIVE_OPERATION_AI_RESOURCE_REQUIRED",`${s}/resources`),d.forEach((E,u)=>{let c=x(E,`${s}/resources/${u}`);i.has(c)||l("NATIVE_OPERATION_AI_RESOURCE_MISSING",`${s}/resources/${u}`)});let _=w(a.sideEffects,`${s}/sideEffects`,20);(r==="read"&&_.length!==0||r!=="read"&&_.length===0)&&l("NATIVE_OPERATION_AI_SIDE_EFFECT_INVALID",`${s}/sideEffects`),a.concurrency!==void 0&&!["none","revision"].includes(b(a.concurrency,`${s}/concurrency`,16))&&l("NATIVE_OPERATION_AI_CONCURRENCY_INVALID",`${s}/concurrency`),a.timeoutMs!==void 0&&z(a.timeoutMs,`${s}/timeoutMs`,100,3e4)}function Be(e){return(e.replace(/\/{2,}/g,"/").replace(/\/$/,"")||"/").split("/").map(n=>n.startsWith(":")?":":n.includes("*")?"*":n).join("/")}function Ai(e,t){let n=I(e,t),o=b(n.type,`${t}/type`,32),i=["code","type","label","presentation","required"],s=o==="sso"?[...i,"provider"]:o==="dingtalk"?[...i,"flow"]:i;T(n,s,t);let a=S(n.code,`${t}/code`),r=b(n.label,`${t}/label`,255),d=b(n.presentation,`${t}/presentation`,16);["primary","secondary"].includes(d)||l("NATIVE_APPLICATION_AUTH_METHOD_PRESENTATION_INVALID",`${t}/presentation`);let _=be(n.required,`${t}/required`);return["sso","password","dingtalk"].includes(o)||l("NATIVE_APPLICATION_AUTH_METHOD_TYPE_INVALID",`${t}/type`),o==="sso"&&n.provider!=="tenant-default"&&l("NATIVE_APPLICATION_AUTH_SSO_PROVIDER_INVALID",`${t}/provider`),o==="dingtalk"&&!["auto","jsapi","oauth"].includes(b(n.flow,`${t}/flow`,16))&&l("NATIVE_APPLICATION_AUTH_DINGTALK_FLOW_INVALID",`${t}/flow`),{code:a,type:o,label:r,presentation:d,required:_,...o==="sso"?{provider:"tenant-default"}:{},...o==="dingtalk"?{flow:n.flow}:{}}}function sn(e,t,n){let o=I(e,n);T(o,["routeCode","path","defaultRouteCode"],n);let i=S(o.routeCode,`${n}/routeCode`),s=ee(o.path,`${n}/path`),a=t==="desktop"?"/login":"/m/login";return(s!==a||/[:*?#\\]/.test(s))&&l("NATIVE_APPLICATION_AUTH_SURFACE_PATH_INVALID",`${n}/path`,{device:t,expectedPath:a}),{routeCode:i,path:s,defaultRouteCode:S(o.defaultRouteCode,`${n}/defaultRouteCode`)}}function Cn(e,t,n,o){if(e===null)return;let i=I(e,o);T(i,["accountMode","registration","methods","surfaces"],o),F(i.accountMode,"existing-platform-users-only",`${o}/accountMode`);let s=I(i.registration,`${o}/registration`);T(s,["mode"],`${o}/registration`),F(s.mode,"reject",`${o}/registration/mode`);let a=$(i.methods,`${o}/methods`,8);a.length===0&&l("NATIVE_APPLICATION_AUTH_METHOD_REQUIRED",`${o}/methods`);let r=a.map((m,N)=>Ai(m,`${o}/methods/${N}`)),d=new Set,_=new Set;for(let[m,N]of r.entries())d.has(N.code)&&l("NATIVE_APPLICATION_AUTH_METHOD_CODE_DUPLICATE",`${o}/methods/${m}/code`),_.has(N.type)&&l("NATIVE_APPLICATION_AUTH_METHOD_TYPE_DUPLICATE",`${o}/methods/${m}/type`),d.add(N.code),_.add(N.type);r.filter(m=>m.presentation==="primary").length!==1&&l("NATIVE_APPLICATION_AUTH_PRIMARY_METHOD_INVALID",`${o}/methods`);let E=I(i.surfaces,`${o}/surfaces`);T(E,["desktop","mobile"],`${o}/surfaces`);let u=sn(E.desktop,"desktop",`${o}/surfaces/desktop`),c=sn(E.mobile,"mobile",`${o}/surfaces/mobile`);u.routeCode===c.routeCode&&l("NATIVE_APPLICATION_AUTH_SURFACE_CODE_DUPLICATE",`${o}/surfaces/mobile/routeCode`);let p=$(t,"/config/frontend/routes",500),f=new Map;for(let[m,N]of p.entries()){let C=I(N,`/config/frontend/routes/${m}`);f.set(String(C.code||""),C)}for(let[m,N]of[["desktop",u],["mobile",c]]){f.has(N.routeCode)&&l("NATIVE_APPLICATION_AUTH_SURFACE_CODE_CONFLICT",`${o}/surfaces/${m}/routeCode`);let C=f.get(N.defaultRouteCode),g=String(C?.path||""),D=m==="desktop"?g==="/m"||g.startsWith("/m/"):!(g==="/m"||g.startsWith("/m/"));(!C||C.surface!=="user"||/[:*]/.test(g)||D)&&l("NATIVE_APPLICATION_AUTH_DEFAULT_ROUTE_INVALID",`${o}/surfaces/${m}/defaultRouteCode`)}let A=On(n).filter(m=>!m.owner.startsWith("authentication:"));for(let[m,N]of[["desktop",u],["mobile",c]]){let C=A.find(g=>Be(g.path)===Be(N.path));C&&l("NATIVE_APPLICATION_AUTH_SURFACE_PATH_CONFLICT",`${o}/surfaces/${m}/path`,{owner:C.owner})}}function Ii(e,t){if(e===null)return;let n={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}},o=I(e,t),i=I(o.surfaces,`${t}/surfaces`),s={...o,surfaces:{...i,desktop:{...I(i.desktop,`${t}/surfaces/desktop`),defaultRouteCode:"auth-desktop-default"},mobile:{...I(i.mobile,`${t}/surfaces/mobile`),defaultRouteCode:"auth-mobile-default"}}};Cn(s,n.frontend.routes,{...n,frontend:{...n.frontend,authentication:s}},t)}function mi(e){let t=e.frontend.authentication;return t===null?null:{accountMode:t.accountMode,registration:{mode:t.registration.mode},methods:t.methods.map(n=>({...n})),surfaces:{desktop:{...t.surfaces.desktop},mobile:{...t.surfaces.mobile}}}}var Ni=new Set(["draft.read","draft.update","validate","create","own.list","own.read"]);function Ti(e,t,n){let o=I(e,n);T(o,["policies"],n);let i=$(o.policies,`${n}/policies`,16);i.length<1&&l("NATIVE_PUBLIC_POLICY_REQUIRED",n);let s=new Map(t.frontend.routes.map(_=>[_.code,_])),a=new Map(t.data.resources.map(_=>[_.code,_])),r=new Set,d=new Set;i.forEach((_,E)=>{let u=`${n}/policies/${E}`,c=I(_,u);T(c,["code","routeCode","mode","resourceCode","operations","fields"],u,["requiredFields","ownRecordFields","draft","validations"]);let p=S(c.code,`${u}/code`);r.has(p)&&l("NATIVE_PUBLIC_POLICY_DUPLICATE",`${u}/code`);let f=S(c.routeCode,`${u}/routeCode`);d.has(f)&&l("NATIVE_PUBLIC_ROUTE_DUPLICATE",`${u}/routeCode`);let A=s.get(f);(!A||A.surface!=="user"||A.capability!==void 0||A.access!==void 0||/[:*]/.test(String(A.path)))&&l("NATIVE_PUBLIC_ROUTE_INVALID",`${u}/routeCode`),F(c.mode,"anonymous",`${u}/mode`);let m=x(c.resourceCode,`${u}/resourceCode`),N=a.get(m);N||l("NATIVE_PUBLIC_RESOURCE_MISSING",`${u}/resourceCode`);let C=new Map(N.schema.fields.map(P=>[String(P.code),String(P.type)])),g=w(c.operations,`${u}/operations`,6);(g.length<1||g.some(P=>!Ni.has(P)))&&l("NATIVE_PUBLIC_OPERATION_INVALID",`${u}/operations`),g.includes("draft.read")!==g.includes("draft.update")&&l("NATIVE_PUBLIC_DRAFT_OPERATION_INCOMPLETE",`${u}/operations`);let D=w(c.fields,`${u}/fields`,64);(D.length<1||D.some(P=>!C.has(P)))&&l("NATIVE_PUBLIC_FIELD_INVALID",`${u}/fields`);for(let P of["requiredFields","ownRecordFields"]){if(!Object.prototype.hasOwnProperty.call(c,P))continue;w(c[P],`${u}/${P}`,64).some(G=>!D.includes(G))&&l("NATIVE_PUBLIC_FIELD_SCOPE_INVALID",`${u}/${P}`)}let h=Object.prototype.hasOwnProperty.call(c,"requiredFields")?w(c.requiredFields,`${u}/requiredFields`,64):[],R=N.surface||{},v=R.fields||{},V=String(R.mutationOwner||"native")==="native"&&R.generated?.create!==!1,L=N.schema.fields.filter(P=>Me(P,v[P.code])).map(P=>String(P.code));if(g.includes("create")&&!V&&l("NATIVE_PUBLIC_CREATE_FIELDS_INCOMPLETE",`${u}/fields`),g.includes("create"))for(let P of L){let Q=D.includes(P)?h.includes(P)?null:"requiredFields":"fields";Q&&l("NATIVE_PUBLIC_CREATE_FIELDS_INCOMPLETE",`${u}/${Q}`,{resourceCode:x,fieldCode:P})}if(Object.prototype.hasOwnProperty.call(c,"draft")){let P=I(c.draft,`${u}/draft`);T(P,["enabled","inactivityTtlSeconds","maxBytes"],`${u}/draft`),F(P.enabled,!0,`${u}/draft/enabled`),z(P.inactivityTtlSeconds,`${u}/draft/inactivityTtlSeconds`,3600,7776e3),z(P.maxBytes,`${u}/draft/maxBytes`,4096,262144)}else g.includes("draft.read")&&l("NATIVE_PUBLIC_DRAFT_REQUIRED",`${u}/draft`);let M=Object.prototype.hasOwnProperty.call(c,"validations")?$(c.validations,`${u}/validations`,16):[],K=new Set;M.forEach((P,Q)=>{let G=`${u}/validations/${Q}`,U=I(P,G);T(U,["code","kind","fields","result"],G);let Ee=S(U.code,`${G}/code`);K.has(Ee)&&l("NATIVE_PUBLIC_VALIDATION_DUPLICATE",`${G}/code`),F(U.kind,"duplicate",`${G}/kind`),F(U.result,"availability",`${G}/result`);let re=w(U.fields,`${G}/fields`,8);(re.length<1||re.some(ae=>!D.includes(ae))||re.some(ae=>["file","subtable"].includes(C.get(ae)||"")))&&l("NATIVE_PUBLIC_VALIDATION_FIELD_INVALID",`${G}/fields`),K.add(Ee)}),r.add(p),d.add(f)})}function gi(e,t){let n=I(e,t);T(n,["policies"],t),$(n.policies,`${t}/policies`,16).length<1&&l("NATIVE_PUBLIC_POLICY_REQUIRED",t)}function Ci(e){return{policies:q(e.frontend.publicAccess.policies.map(t=>({code:t.code,routeCode:t.routeCode,mode:t.mode,resourceCode:t.resourceCode,operations:k(t.operations),fields:k(t.fields),...t.requiredFields?{requiredFields:k(t.requiredFields)}:{},...t.ownRecordFields?{ownRecordFields:k(t.ownRecordFields)}:{},...t.draft?{draft:{...t.draft}}:{},...t.validations?{validations:q(t.validations.map(n=>({code:n.code,kind:n.kind,fields:k(n.fields),result:n.result})),n=>n.code)}:{}})),t=>t.code)}}function On(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 n of e.data.resources){let o=bn(n),i=`/admin/resources/${n.code}`,s=[["list",i],["detail",`${i}/:id`],["create",`${i}/new`],["update",`${i}/:id/edit`]];for(let[a,r]of s)o[a]&&t.push({owner:`resource:${n.code}:${a}`,path:r},{owner:`resource:${n.code}:${a}:mobile`,path:`/m${r}`})}if(e.frontend.user.applicationTodoCenter===!0&&t.push({owner:"application:todo-center",path:"/todos"},{owner:"application:todo-center:mobile",path:"/m/todos"}),e.workflows.definitions.length>0){t.push({owner:"workflow:work-center",path:"/work-center"},{owner:"workflow:work-center:mobile",path:"/m/work-center"},{owner:"workflow:task",path:"/tasks/:taskId"},{owner:"workflow:task:mobile",path:"/m/tasks/:taskId"},{owner:"workflow:instance",path:"/workflows/:instanceId"},{owner:"workflow:instance:mobile",path:"/m/workflows/:instanceId"});let n=!1;for(let o of e.workflows.definitions)["standalone","hidden-handoff"].includes(o.launch.mode)&&(n=!0);n&&t.push({owner:"workflow:launch",path:"/workflows/:workflowCode/start"},{owner:"workflow:launch:mobile",path:"/m/workflows/:workflowCode/start"})}return t}function ze(e){let t=new Map(On(e).map(n=>[Be(n.path),n]));return q(e.frontend.routes.map((n,o)=>{let i=`/config/frontend/routes/${o}`,s=I(n,i);T(s,["code","path","label","surface","parentCode","capability","access","pinned","tabPersistence","keepAlive"],i,!0),["admin","user"].includes(s.surface)||l("NATIVE_ROUTE_SURFACE_INVALID",`${i}/surface`);let a=ee(s.path,`${i}/path`);s.surface==="admin"&&a!=="/admin"&&!a.startsWith("/admin/")&&l("NATIVE_ADMIN_ROUTE_PATH_INVALID",`${i}/path`),s.surface==="user"&&(a==="/admin"||a.startsWith("/admin/"))&&l("NATIVE_USER_ROUTE_PATH_RESERVED",`${i}/path`);let r=Be(a),d=t.get(r);d&&l("NATIVE_ROUTE_PATH_CONFLICT",`${i}/path`,{path:a,owner:d.owner}),t.set(r,{owner:`frontend:${String(s.code||o)}`,path:a});let _=/[:*]/.test(a),E=Ot(s,i,e.appCode),u=s.pinned===void 0?void 0:be(s.pinned,`${i}/pinned`),c=s.tabPersistence===void 0?_?"none":"session":b(s.tabPersistence,`${i}/tabPersistence`,16),p=s.keepAlive===void 0?"none":b(s.keepAlive,`${i}/keepAlive`,16);return["session","none"].includes(c)||l("NATIVE_ROUTE_TAB_PERSISTENCE_INVALID",`${i}/tabPersistence`),["none","memory"].includes(p)||l("NATIVE_ROUTE_KEEP_ALIVE_INVALID",`${i}/keepAlive`),_&&u===!0&&l("NATIVE_DYNAMIC_ROUTE_PINNED_FORBIDDEN",`${i}/pinned`),_&&c==="session"&&l("NATIVE_DYNAMIC_ROUTE_TAB_PERSISTENCE_FORBIDDEN",`${i}/tabPersistence`),_&&p==="memory"&&l("NATIVE_DYNAMIC_ROUTE_KEEP_ALIVE_FORBIDDEN",`${i}/keepAlive`),{code:S(s.code,`${i}/code`),path:a,label:b(s.label,`${i}/label`,255),surface:s.surface,...s.parentCode===void 0?{}:{parentCode:S(s.parentCode,`${i}/parentCode`)},...E,...u===void 0?{}:{pinned:u},tabPersistence:c,keepAlive:p}}),n=>n.code)}function bn(e){let t=e.surface===void 0?{}:I(e.surface,"/surface"),n=t.mutationOwner||"native",o=t.generated===void 0?{}:I(t.generated,"/surface/generated"),i=n==="native";return{list:o.list??!0,detail:o.detail??!0,create:o.create??i,update:o.update??i,delete:o.delete??i}}function $n(e){let t=[];for(let n of q(e.data.resources,o=>o.code).flatMap(o=>[{resource:o,viewCode:void 0},...(o.surface?.views||[]).map(i=>({viewCode:i.code,resource:{...o,name:i.name,surface:lt(o.surface,i.code)}}))])){let{resource:o,viewCode:i}=n,s=`/admin/resources/${o.code}${i?`/views/${i}`:""}`,a=bn(o),r=[{operation:"list",kind:"resource-list",path:`${s}`,label:o.name,capability:o.capabilities.read,navigationEligible:!0},{operation:"detail",kind:"resource-detail",path:`${s}/:id`,label:`${o.name}\u8BE6\u60C5`,capability:o.capabilities.read,navigationEligible:!1},{operation:"create",kind:"resource-create",path:`${s}/new`,label:`\u65B0\u589E${o.name}`,capability:o.capabilities.create,navigationEligible:!1},{operation:"update",kind:"resource-update",path:`${s}/:id/edit`,label:`\u7F16\u8F91${o.name}`,capability:o.capabilities.update,navigationEligible:!1}];for(let d of r)a[d.operation]&&t.push({code:`resource:${o.code}${i?`:view:${i}`:""}:${d.operation}`,kind:d.kind,path:d.path,label:d.label,navigationEligible:d.navigationEligible,capability:d.capability,resourceCode:o.code,...i?{viewCode:i}:{}})}for(let n of ze(e))n.surface==="admin"&&t.push({code:`operation:${n.code}`,kind:"operation",path:n.path,label:n.label,navigationEligible:!/[:*]/.test(n.path),routeCode:n.code});return t.sort((n,o)=>se(n.code,o.code))}function hn(e){return e.kind==="resource"?`resource:${e.resourceCode}${e.viewCode?`:view:${e.viewCode}`:""}:list`:`operation:${e.routeCode}`}function Oi(e){return e.frontend.admin.navigation.map((t,n)=>({code:t.code,label:t.label,...t.icon===void 0?{}:{icon:t.icon},order:t.order??n,items:t.items.map((o,i)=>({pageCode:hn(o.page),...o.label===void 0?{}:{label:o.label},...o.icon===void 0?{}:{icon:o.icon},order:o.order??i})).sort((o,i)=>o.order-i.order||se(o.pageCode,i.pageCode))})).sort((t,n)=>t.order-n.order||se(t.code,n.code))}function bi(e,t){let n=$(e,t,B.adminNavigationGroups),o=0;n.forEach((i,s)=>{let a=`${t}/${s}`,r=I(i,a);T(r,["code","label","icon","order","items"],a,!0),S(r.code,`${a}/code`),b(r.label,`${a}/label`,255),Je(r.icon,`${a}/icon`),ln(r.order,`${a}/order`);let d=$(r.items,`${a}/items`,500);d.length===0&&l("NATIVE_ADMIN_GROUP_ORPHANED",`${a}/items`),o+=d.length,o>B.adminNavigationItems&&l("NATIVE_ARRAY_LIMIT_EXCEEDED",t),d.forEach((_,E)=>{let u=`${a}/items/${E}`,c=I(_,u);T(c,["page","label","icon","order"],u,!0),$i(c.page,`${u}/page`),c.label!==void 0&&b(c.label,`${u}/label`,255),Je(c.icon,`${u}/icon`),ln(c.order,`${u}/order`)})})}function $i(e,t){let n=I(e,t),o=b(n.kind,`${t}/kind`,64);if(o==="resource"){T(n,["kind","resourceCode"],t,["viewCode"]),n.viewCode!==void 0&&S(n.viewCode,`${t}/viewCode`),x(n.resourceCode,`${t}/resourceCode`);return}if(o==="operation"){T(n,["kind","routeCode"],t),S(n.routeCode,`${t}/routeCode`);return}l("NATIVE_ADMIN_PAGE_REFERENCE_KIND_INVALID",`${t}/kind`)}function hi(e){let t=new Map($n(e).map(i=>[String(i.code),i])),n=new Set,o=new Set;e.frontend.admin.navigation.forEach((i,s)=>{let a=`/config/frontend/admin/navigation/${s}`;n.has(i.code)&&l("NATIVE_ADMIN_GROUP_DUPLICATE",`${a}/code`),n.add(i.code),i.label===i.code&&l("NATIVE_ADMIN_USER_LABEL_REQUIRED",`${a}/label`),i.items.forEach((r,d)=>{let _=`${a}/items/${d}`,E=hn(r.page),u=t.get(E);(!u||u.navigationEligible!==!0)&&l("NATIVE_ADMIN_PAGE_NOT_FOUND",`${_}/page`),o.has(E)&&l("NATIVE_ADMIN_PAGE_DUPLICATE",`${_}/page`),o.add(E);let c=r.page.resourceCode||r.page.routeCode||r.page.workflowCode||E,p=r.label||u.label;(!p||p===c||p===E)&&l("NATIVE_ADMIN_USER_LABEL_REQUIRED",`${_}/label`)})})}function Ri(e,t){let n=$(e,t,B.adminPages),o=new Set;n.forEach((i,s)=>{let a=`${t}/${s}`,r=I(i,a);T(r,["code","kind","path","label","navigationEligible","capability","access","resourceCode","viewCode","routeCode"],a,!0);let d=b(r.code,`${a}/code`,255);o.has(d)&&l("NATIVE_ADMIN_PAGE_DUPLICATE",`${a}/code`),o.add(d);let _=b(r.kind,`${a}/kind`,64);if(["resource-list","resource-detail","resource-create","resource-update","operation"].includes(_)||l("NATIVE_ADMIN_PAGE_KIND_INVALID",`${a}/kind`),ee(r.path,`${a}/path`),b(r.label,`${a}/label`,255),be(r.navigationEligible,`${a}/navigationEligible`),r.capability!==void 0&&r.access!==void 0&&l("NATIVE_ROUTE_ACCESS_CONFLICT",`${a}/access`),r.capability!==void 0&&b(r.capability,`${a}/capability`,255),r.access!==void 0){let E=I(r.access,`${a}/access`);T(E,["allOf","anyOf"],`${a}/access`,!0);for(let u of["allOf","anyOf"])E[u]!==void 0&&w(E[u],`${a}/access/${u}`,50)}for(let E of["resourceCode","viewCode","routeCode"])r[E]!==void 0&&S(r[E],`${a}/${E}`)})}function Di(e,t){let n=$(e,t,B.adminNavigationGroups),o=0;n.forEach((i,s)=>{let a=`${t}/${s}`,r=I(i,a);T(r,["code","label","icon","order","items"],a,!0),S(r.code,`${a}/code`),b(r.label,`${a}/label`,255),Je(r.icon,`${a}/icon`),z(r.order,`${a}/order`,-1e4,1e4);let d=$(r.items,`${a}/items`,500);d.length===0&&l("NATIVE_ADMIN_GROUP_ORPHANED",`${a}/items`),o+=d.length,o>B.adminNavigationItems&&l("NATIVE_ARRAY_LIMIT_EXCEEDED",t),d.forEach((_,E)=>{let u=`${a}/items/${E}`,c=I(_,u);T(c,["pageCode","label","icon","order"],u,!0),b(c.pageCode,`${u}/pageCode`,255),c.label!==void 0&&b(c.label,`${u}/label`,255),Je(c.icon,`${u}/icon`),z(c.order,`${u}/order`,-1e4,1e4)})})}var Si=new Set(["application-todo-center","workflow-work-center","workflow-launch","workflow-task","workflow-instance"]);function Vi(e,t,n){let o=I(e,t);T(o,["schemaVersion","appCode","devicePolicy","rootEntry","authentication","routes","digest"],t),F(o.schemaVersion,Tn,`${t}/schemaVersion`),F(o.appCode,n,`${t}/appCode`),Ct(o.devicePolicy,`${t}/devicePolicy`),yi(o.rootEntry,`${t}/rootEntry`),wi(o.authentication,`${t}/authentication`),Tt(o.digest,`${t}/digest`);let i=$(o.routes,`${t}/routes`,B.routes),s=new Set;i.forEach((a,r)=>{let d=`${t}/routes/${r}`,_=I(a,d);T(_,["code","kind","desktop","mobile"],d,["workflowCode"]);let E=b(_.code,`${d}/code`,255);s.has(E)&&l("NATIVE_ROUTE_MANIFEST_DUPLICATE",`${d}/code`),s.add(E);let u=b(_.kind,`${d}/kind`,64);Si.has(u)||l("NATIVE_ROUTE_MANIFEST_KIND_INVALID",`${d}/kind`),_.workflowCode!==void 0&&S(_.workflowCode,`${d}/workflowCode`);let c=an(_.desktop,`${d}/desktop`,n),p=an(_.mobile,`${d}/mobile`,n);c.surface!=="user"&&l("NATIVE_ROUTE_MANIFEST_DESKTOP_SURFACE_INVALID",`${d}/desktop/surface`),p.surface!=="user"&&l("NATIVE_ROUTE_MANIFEST_MOBILE_SURFACE_INVALID",`${d}/mobile/surface`),c.routeCode===p.routeCode&&l("NATIVE_ROUTE_MANIFEST_PAIR_DUPLICATE",d)}),F(o.digest,Z({schemaVersion:o.schemaVersion,appCode:o.appCode,devicePolicy:o.devicePolicy,rootEntry:o.rootEntry,authentication:o.authentication,routes:o.routes}),`${t}/digest`)}function Ct(e,t){let n=I(e,t);T(n,["kind","mobileMaxWidthPx","desktopMinWidthPx"],t),F(n.kind,"viewport-family",`${t}/kind`);let o=z(n.mobileMaxWidthPx,`${t}/mobileMaxWidthPx`,320,1600),i=z(n.desktopMinWidthPx,`${t}/desktopMinWidthPx`,320,1600);return i!==o+1&&l("NATIVE_FRONTEND_DEVICE_POLICY_INVALID",t),{kind:"viewport-family",mobileMaxWidthPx:o,desktopMinWidthPx:i}}function yi(e,t){let n=I(e,t);T(n,["code","desktop","mobile"],t);let o=S(n.code,`${t}/code`),i=Nt(n.desktop,`${t}/desktop`),s=Nt(n.mobile,`${t}/mobile`);return(i===s||s==="/"||!s.startsWith("/m/"))&&l("NATIVE_ROUTE_MANIFEST_ROOT_ENTRY_INVALID",t),i.startsWith("/m/")&&l("NATIVE_ROUTE_MANIFEST_ROOT_ENTRY_INVALID",`${t}/desktop`),{code:o,desktop:i,mobile:s}}function wi(e,t){let n=I(e,t);T(n,["desktop","mobile"],t);let o=rn(n.desktop,`${t}/desktop`,!1),i=rn(n.mobile,`${t}/mobile`,!0);return(o.routeCode===i.routeCode||o.path===i.path)&&l("NATIVE_ROUTE_MANIFEST_AUTHENTICATION_DUPLICATE",t),{desktop:o,mobile:i}}function rn(e,t,n){let o=I(e,t);T(o,["routeCode","path"],t);let i=S(o.routeCode,`${t}/routeCode`),s=Nt(o.path,`${t}/path`);return(n?!s.startsWith("/m/"):s.startsWith("/m/"))&&l("NATIVE_ROUTE_MANIFEST_AUTHENTICATION_PATH_INVALID",`${t}/path`),{routeCode:i,path:s}}function Nt(e,t){let n=ee(e,t);return/[:*?#\\\\]/.test(n)&&l("NATIVE_ROUTE_MANIFEST_STATIC_PATH_INVALID",t),n}function an(e,t,n){let o=I(e,t);T(o,["routeCode","path","surface","pathParams","requiresAuthentication"],t,["capability","access"]),S(o.routeCode,`${t}/routeCode`);let i=ee(o.path,`${t}/path`),s=b(o.surface,`${t}/surface`,16);["admin","user"].includes(s)||l("NATIVE_ROUTE_SURFACE_INVALID",`${t}/surface`);let a=w(o.pathParams,`${t}/pathParams`,8);return a.forEach((r,d)=>{(!/^[A-Za-z][A-Za-z0-9_]*$/.test(r)||r.length>64)&&l("NATIVE_ROUTE_PATH_PARAM_INVALID",`${t}/pathParams/${d}`)}),W(a)!==W(Rn(i))&&l("NATIVE_ROUTE_PATH_PARAMS_MISMATCH",`${t}/pathParams`),Ot(o,t,n),o.requiresAuthentication!==!0&&l("NATIVE_ROUTE_AUTHENTICATION_REQUIRED",`${t}/requiresAuthentication`),o}function Rn(e){return k([...e.matchAll(/:([A-Za-z][A-Za-z0-9_]*)/g)].map(t=>t[1]))}function cn(e,t,n,o){return{routeCode:e,path:t,surface:n,pathParams:Rn(t),...o?.capability?{capability:o.capability}:{},...o?.access?{access:o.access}:{},requiresAuthentication:!0}}function dn(e,t,n){return e==="workflow-launch"?`workflow.${n}.launch.${t}`:e==="application-todo-center"?`application.todo-center.${t}`:`${e.replace(/-/g,".")}.${t}`}function Pi(e){let t=e.appCode,n=[],o=(p,f,A,m,N,C)=>{n.push({code:p,kind:f,...N?{workflowCode:N}:{},desktop:cn(dn(f,"desktop",N),A,"user",C),mobile:cn(dn(f,"mobile",N),m,"user",C)})};e.frontend.user.applicationTodoCenter===!0&&o("application:todo-center","application-todo-center","/todos","/m/todos");let i=Dn(e);i.length>0&&(o("workflow:work-center","workflow-work-center","/work-center","/m/work-center"),o("workflow:task","workflow-task","/tasks/:taskId","/m/tasks/:taskId"),o("workflow:instance","workflow-instance","/workflows/:instanceId","/m/workflows/:instanceId"));for(let p of i){if(!["standalone","hidden-handoff"].includes(p.launch.mode))continue;let f=k([p.launch.submission?.create?.requiredCapability,p.launch.submission?.existing?.requiredCapability].filter(A=>!!A));o(`workflow:${p.code}:launch`,"workflow-launch","/workflows/:workflowCode/start","/m/workflows/:workflowCode/start",p.code,f.length===1?{capability:f[0]}:f.length>1?{access:{anyOf:f}}:void 0)}let s=n.sort((p,f)=>se(String(p.code),String(f.code))),a=ze(e),r=p=>{let f=p==="mobile"?"/m/":"/",A=a.filter(N=>N.surface==="user"&&!/[:*?#\\\\]/.test(N.path)&&N.path===f).sort((N,C)=>se(N.code,C.code))[0];if(A)return{code:A.code,path:A.path};let m=a.filter(N=>N.surface==="user"&&!/[:*?#\\\\]/.test(N.path)&&(p==="mobile"?N.path.startsWith("/m/"):!N.path.startsWith("/m/"))).sort((N,C)=>se(N.code,C.code))[0];return m?{code:m.code,path:m.path}:{code:p==="mobile"?"application-root-mobile":"application-root",path:f}},d=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"}},_=Ct(e.frontend.devicePolicy,"/config/frontend/devicePolicy"),E=r("desktop"),u=r("mobile"),c={schemaVersion:Tn,appCode:t,devicePolicy:_,rootEntry:{code:E.code,desktop:E.path,mobile:u.path},authentication:d,routes:s};return{...c,digest:Z(c)}}function Je(e,t){if(e===void 0)return;let n=b(e,t,32);Ho.has(n)||l("NATIVE_ADMIN_ICON_INVALID",t)}function ln(e,t){e!==void 0&&z(e,t,-1e4,1e4)}function Ot(e,t,n){return e.capability!==void 0&&e.access!==void 0&&l("NATIVE_ROUTE_ACCESS_CONFLICT",`${t}/access`),e.capability!==void 0?{capability:_e(e.capability,`${t}/capability`,n)}:e.access===void 0?{}:{access:Ye(e.access,`${t}/access`,n)}}function Ye(e,t,n){let o=I(e,t);T(o,["allOf","anyOf"],t,!0);let i=o.allOf===void 0?void 0:k(w(o.allOf,`${t}/allOf`,50).map((a,r)=>_e(a,`${t}/allOf/${r}`,n))),s=o.anyOf===void 0?void 0:k(w(o.anyOf,`${t}/anyOf`,50).map((a,r)=>_e(a,`${t}/anyOf/${r}`,n)));return(i?.length||0)+(s?.length||0)===0&&l("NATIVE_ROUTE_ACCESS_EMPTY",t),{...i===void 0?{}:{allOf:i},...s===void 0?{}:{anyOf:s}}}function Dn(e){let t=new Map(gn(e).map(i=>[String(i.code),i])),n=e.workflows.definitions.map((i,s)=>{let a=`/config/workflows/definitions/${s}`,r=I(i,a);T(r,["version","definition","launch"],a,["detailRouteCode"]);let d=I(r.definition,`${a}/definition`),_=r.detailRouteCode===void 0?void 0:Vn(r.detailRouteCode,`${a}/detailRouteCode`);return{code:S(d.code,`${a}/definition/code`),title:b(d.title,`${a}/definition/title`,255),version:Oe(r.version,`${a}/version`),launch:Fi(e,d,r.launch,`${a}/launch`,t),..._?{detailRouteCode:_}:{},definition:d}});return k(n.map(i=>i.code)).map(i=>{let s=n.filter(_=>_.code===i),a=e.workflows.activations.find(_=>_.workflowCode===i)?.definitionVersion,r=s.find(_=>_.version===a)||[...s].sort((_,E)=>E.version-_.version)[0],d=new Set;for(let _ of s){let E=I(_.definition.nodes,"/config/workflows/definitions/nodes");for(let u of Object.values(E)){let c=I(u,"/config/workflows/definitions/nodes/*");if(c.kind==="approval")for(let p of w(c.allowedOperations||[],"/config/workflows/definitions/nodes/*/allowedOperations",20))d.add(p)}}return{code:i,title:r.title,acceptedCommandDeactivationPolicy:r.definition.acceptedCommandDeactivationPolicy,subject:r.definition.subject,launch:r.launch,...["standalone","hidden-handoff"].includes(r.launch.mode)&&!r.launch.submission?{processOperationCode:`openxiangda.workflow.${i}.submit`}:{},...r.detailRouteCode?{detailRouteCode:r.detailRouteCode}:{},definitionVersions:mn(s.map(_=>_.version)),bindingVersions:mn(e.workflows.bindings.map((_,E)=>{let u=`/config/workflows/bindings/${E}`,c=I(_,u),p=I(c.binding,`${u}/binding`);return{code:S(p.workflowCode,`${u}/binding/workflowCode`),version:Oe(c.version,`${u}/version`)}}).filter(_=>_.code===i).map(_=>_.version)),providerCodes:k(e.workflows.providers.map((_,E)=>S(I(_,`/config/workflows/providers/${E}`).code,`/config/workflows/providers/${E}/code`))),allowedOperations:[...d].sort(se),editableParameterCodes:k(e.workflows.editableParameters.map((_,E)=>{let u=`/config/workflows/editableParameters/${E}`,c=I(_,u);return{code:S(c.code,`${u}/code`),workflowCode:S(c.workflowCode,`${u}/workflowCode`)}}).filter(_=>_.workflowCode===i).map(_=>_.code))}})}function Sn(e,t){let n=I(e,t);T(n,["mode"],t,["submission"]);let o=b(n.mode,`${t}/mode`,32);return["standalone","custom-page","hidden-handoff","work-center-only"].includes(o)||l("NATIVE_WORKFLOW_LAUNCH_MODE_INVALID",`${t}/mode`),{mode:o,...n.submission===void 0?{}:{submission:I(n.submission,`${t}/submission`)}}}function Fi(e,t,n,o,i){let s=Sn(n,o);if(!s.submission)return{mode:s.mode};["standalone","hidden-handoff"].includes(s.mode)||l("NATIVE_WORKFLOW_NAMED_OPERATION_SUBMISSION_INVALID",`${o}/submission`);let a=I(s.submission,`${o}/submission`);T(a,["kind"],`${o}/submission`,["create","existing","context"]),F(a.kind,"named-operation",`${o}/submission/kind`);let r=o.endsWith("/launch")?o.slice(0,-7):o,d=I(t.subject,`${r}/definition/subject`),_=x(d.resourceCode,`${r}/definition/subject/resourceCode`),E=e.data.resources.findIndex(R=>R.code===_),u=e.data.resources[E];(E<0||!u)&&l("NATIVE_WORKFLOW_SUBJECT_RESOURCE_MISSING",`${r}/definition/subject/resourceCode`);let c=new Set(I(u.schema,`/config/data/resources/${E}/schema`).fields.map(R=>String(R.code))),p=new Map(e.backend.operations.map(R=>[String(R.code),R])),f=(R,v)=>{let V=`${o}/submission/${v}`,L=I(R,V);T(L,["operationCode","inputs","output"],V);let M=S(L.operationCode,`${V}/operationCode`),K=p.get(M),P=i.get(M),Q=P?.platformAccess?.workflow?.codes;(!K||!P||P.method!=="POST"||!Array.isArray(Q)||!Q.includes(t.code))&&l("NATIVE_WORKFLOW_NAMED_OPERATION_INVALID",V);let G=I(K.requestSchema,`${V}/operation/requestSchema`),U=I(G.properties,`${V}/operation/requestSchema/properties`),Ee=new Set(G.required===void 0?[]:w(G.required,`${V}/operation/requestSchema/required`,64)),re=I(L.inputs,`${V}/inputs`),ae=Object.entries(re);(!ae.length||ae.length>64)&&l("NATIVE_WORKFLOW_NAMED_OPERATION_INPUT_INVALID",`${V}/inputs`);let Ke=new Set,pe=new Map,qe={};for(let[j,Ie]of ae){(!tn.test(j)||!Object.prototype.hasOwnProperty.call(U,j))&&l("NATIVE_WORKFLOW_NAMED_OPERATION_INPUT_INVALID",`${V}/inputs/${j}`);let me=`${V}/inputs/${j}`,Xe=I(Ie,me),Ae=b(Xe.source,`${me}/source`,32);if(["field","idempotency-key","current-user-reference","subject-id","subject-revision","requested-at"].includes(Ae)||l("NATIVE_WORKFLOW_NAMED_OPERATION_INPUT_INVALID",me),T(Xe,["source"],me,Ae==="field"?["fieldCode"]:!1),pe.set(Ae,(pe.get(Ae)||0)+1),Ae==="field"){let Fe=J(Xe.fieldCode,`${me}/fieldCode`);(Ke.has(Fe)||!c.has(Fe))&&l("NATIVE_WORKFLOW_NAMED_OPERATION_INPUT_INVALID",`${me}/fieldCode`),Ke.add(Fe),qe[j]={source:Ae,fieldCode:Fe}}else qe[j]={source:Ae}}([...Ee].some(j=>!(j in re))||(pe.get("idempotency-key")||0)!==1||!ae.some(([j,Ie])=>I(Ie,`${V}/inputs/${j}`).source==="idempotency-key"&&Ee.has(j))||v==="create"&&((pe.get("subject-id")||0)>0||(pe.get("subject-revision")||0)>0)||v==="existing"&&((pe.get("subject-id")||0)!==1||(pe.get("subject-revision")||0)!==1))&&l("NATIVE_WORKFLOW_NAMED_OPERATION_INPUT_INVALID",`${V}/inputs`);let Pe=I(L.output,`${V}/output`);T(Pe,["subjectId"],`${V}/output`,["subjectRevision","processCommand"]);let Pn=I(I(K.responseSchema,`${V}/operation/responseSchema`).properties,`${V}/operation/responseSchema/properties`);for(let j of["subjectId","subjectRevision","processCommand"]){if(Pe[j]===void 0)continue;let Ie=b(Pe[j],`${V}/output/${j}`,128);(!tn.test(Ie)||!Object.prototype.hasOwnProperty.call(Pn,Ie))&&l("NATIVE_WORKFLOW_NAMED_OPERATION_OUTPUT_INVALID",`${V}/output/${j}`)}return{operationCode:M,method:"POST",path:P.path,requiredCapability:P.requiredCapability,requestSchemaDigest:P.requestSchemaDigest,responseSchemaDigest:P.responseSchemaDigest,inputs:qe,output:{...Pe},fieldCodes:Ke}},A=a.create===void 0?void 0:f(a.create,"create"),m=a.existing===void 0?void 0:f(a.existing,"existing");!A&&!m&&l("NATIVE_WORKFLOW_NAMED_OPERATION_SUBMISSION_INVALID",`${o}/submission`);let N=new Set([...A?.fieldCodes||[],...m?.fieldCodes||[]]),C=a.context===void 0?[]:$(a.context,`${o}/submission/context`,16),g=new Set,D=C.map((R,v)=>{let V=`${o}/submission/context/${v}`,L=I(R,V);T(L,["queryParameter","fieldCode"],V);let M=b(L.queryParameter,`${V}/queryParameter`,64),K=J(L.fieldCode,`${V}/fieldCode`);return(!/^[A-Za-z][A-Za-z0-9]{0,63}$/.test(M)||g.has(M)||!N.has(K))&&l("NATIVE_WORKFLOW_LAUNCH_CONTEXT_INVALID",V),g.add(M),{queryParameter:M,fieldCode:K}}),h=R=>{let{fieldCodes:v,...V}=R;return V};return{mode:s.mode,submission:{kind:"named-operation",...A?{create:h(A)}:{},...m?{existing:h(m)}:{},context:D}}}function Vn(e,t){let n=I(e,t);T(n,["desktop","mobile"],t);let o=S(n.desktop,`${t}/desktop`),i=S(n.mobile,`${t}/mobile`);return o===i&&l("NATIVE_WORKFLOW_DETAIL_ROUTE_DUPLICATE",t),{desktop:o,mobile:i}}function Li(e,t){let n=new Set(t.map(E=>E.code)),o=new Map;e.data.resources.forEach((E,u)=>{let c=`/config/data/resources/${u}`,p=I(E,c);if(((p.surface===void 0?{}:I(p.surface,`${c}/surface`)).mutationOwner||"native")==="native")return;let A=I(p.capabilities,`${c}/capabilities`);for(let m of["create","update","delete"])o.set(String(A[m]),m)});let i=new Set;for(let[E,u]of e.authz.roles.entries()){let c=`/config/authz/roles/${E}`,p=I(u,c);T(p,["code","name","description","capabilities"],c,!0);let f=S(p.code,`${c}/code`);i.has(f)&&l("NATIVE_ROLE_DUPLICATE",`${c}/code`),i.add(f),b(p.name,`${c}/name`,255);let A=w(p.capabilities,`${c}/capabilities`,2e3);for(let[m,N]of A.entries())o.has(N)&&l("NATIVE_DATA_SURFACE_MUTATION_GRANT_FORBIDDEN",`${c}/capabilities/${m}`,{operation:o.get(N)}),n.has(N)||l("NATIVE_CAPABILITY_REFERENCE_MISSING",`${c}/capabilities`)}let s=e.authz.authenticatedUserRoleCode===void 0?"":S(e.authz.authenticatedUserRoleCode,"/config/authz/authenticatedUserRoleCode");s&&!i.has(s)&&l("NATIVE_AUTHENTICATED_USER_ROLE_REFERENCE_MISSING","/config/authz/authenticatedUserRoleCode");let a=new Set,r=0;for(let[E,u]of e.perspectives.entries()){let c=`/config/perspectives/${E}`,p=I(u,c);T(p,["code","name","description","roleCodes","capabilityCodes","default"],c,!0);let f=S(p.code,`${c}/code`);a.has(f)&&l("NATIVE_PERSPECTIVE_DUPLICATE",`${c}/code`),a.add(f),b(p.name,`${c}/name`,255);let A=w(p.roleCodes,`${c}/roleCodes`,20);A.length<1&&l("NATIVE_PERSPECTIVE_ROLE_REQUIRED",`${c}/roleCodes`),A.forEach((C,g)=>{i.has(C)||l("NATIVE_PERSPECTIVE_ROLE_MISSING",`${c}/roleCodes/${g}`)});let m=k(e.authz.roles.filter(C=>A.includes(C.code)).flatMap(C=>C.capabilities)),N=w(p.capabilityCodes,`${c}/capabilityCodes`,2e3);W(m)!==W(N)&&l("NATIVE_PERSPECTIVE_CAPABILITY_PROJECTION_MISMATCH",`${c}/capabilityCodes`),p.default===!0?r+=1:p.default!==void 0&&l("NATIVE_PERSPECTIVE_DEFAULT_INVALID",`${c}/default`)}r>1&&l("NATIVE_PERSPECTIVE_DEFAULT_DUPLICATE","/config/perspectives");for(let[E,u]of e.backend.operations.entries()){let c=I(u,`/config/backend/operations/${E}`);n.has(c.capability)||l("NATIVE_CAPABILITY_REFERENCE_MISSING",`/config/backend/operations/${E}/capability`)}let d=new Set,_=new Set;for(let[E,u]of e.frontend.routes.entries()){let c=`/config/frontend/routes/${E}`,p=I(u,c),f=S(p.code,`${c}/code`);d.has(f)&&l("NATIVE_ROUTE_DUPLICATE",`${c}/code`),d.add(f);let A=ee(p.path,`${c}/path`);_.has(A)&&l("NATIVE_ROUTE_PATH_DUPLICATE",`${c}/path`),_.add(A);let m=Ot(p,c,e.appCode);m.capability&&!n.has(m.capability)&&l("NATIVE_CAPABILITY_REFERENCE_MISSING",`${c}/capability`);let N=p.access===void 0?void 0:I(p.access,`${c}/access`);for(let C of["allOf","anyOf"]){let g=N?.[C]===void 0?[]:$(N[C],`${c}/access/${C}`,50);for(let[D,h]of g.entries()){let R=_e(h,`${c}/access/${C}/${D}`,e.appCode);n.has(R)||l("NATIVE_CAPABILITY_REFERENCE_MISSING",`${c}/access/${C}/${D}`)}}}if(e.frontend.admin.access!==void 0){let E=Ye(e.frontend.admin.access,"/config/frontend/admin/access",e.appCode);for(let u of["allOf","anyOf"])for(let[c,p]of(E[u]||[]).entries())n.has(p)||l("NATIVE_CAPABILITY_REFERENCE_MISSING",`/config/frontend/admin/access/${u}/${c}`)}for(let[E,u]of e.frontend.routes.entries()){let c=I(u,`/config/frontend/routes/${E}`);c.parentCode&&!d.has(c.parentCode)&&l("NATIVE_ROUTE_PARENT_MISSING",`/config/frontend/routes/${E}/parentCode`)}}function vi(e){let t=new Set(e.authz.roles.map(_=>String(_.code))),n=e.authz.authenticatedUserRoleCode===void 0?"":S(e.authz.authenticatedUserRoleCode,"/config/authz/authenticatedUserRoleCode"),o=new Map(e.authz.scopeDimensions.map(_=>[String(_.code),{valueType:_.valueType==="uuid"?"uuid":"string",..._.valueSource?.resourceCode?{valueSourceResourceCode:String(_.valueSource.resourceCode)}:{}}])),i=new Set(o.keys()),s=new Map(e.data.resources.map((_,E)=>{let u=we(_,`/config/data/resources/${E}`,e.appCode);return[u.code,new Map(u.schema.fields.map(c=>[String(c.code),c]))]}));for(let[_,E]of e.authz.scopeDimensions.entries()){let u=`/config/authz/scopeDimensions/${_}`,c=I(E,u);if(T(c,["code","name","resourceCode","valueType","hierarchyMode","valueSource"],u,!0),c.valueSource===void 0)continue;let p=I(c.valueSource,`${u}/valueSource`);T(p,["kind","resourceCode","labelField","enabledField"],`${u}/valueSource`,!0),p.kind!=="native_resource"&&l("NATIVE_SCOPE_VALUE_SOURCE_KIND_INVALID",`${u}/valueSource/kind`),c.valueType!=="uuid"&&l("NATIVE_SCOPE_VALUE_SOURCE_TYPE_INVALID",`${u}/valueType`);let f=x(p.resourceCode,`${u}/valueSource/resourceCode`),A=s.get(f);A||l("NATIVE_SCOPE_VALUE_SOURCE_RESOURCE_MISSING",`${u}/valueSource/resourceCode`);let m=J(p.labelField,`${u}/valueSource/labelField`);if(["text.short","text.long"].includes(String(A.get(m)?.type||""))||l("NATIVE_SCOPE_VALUE_SOURCE_LABEL_FIELD_INVALID",`${u}/valueSource/labelField`),p.enabledField!==void 0){let N=J(p.enabledField,`${u}/valueSource/enabledField`);A.get(N)?.type!=="boolean"&&l("NATIVE_SCOPE_VALUE_SOURCE_ENABLED_FIELD_INVALID",`${u}/valueSource/enabledField`)}}let a=new Set,r=new Set;for(let[_,E]of e.authz.scopeSources.entries()){let u=`/config/authz/scopeSources/${_}`,c=I(E,u);T(c,["code","name","resourceCode","subject","grants","operationField","enabledField","effectiveFromField","effectiveToField","failureMode"],u,!0);let p=S(c.code,`${u}/code`);a.has(p)&&l("NATIVE_SCOPE_SOURCE_DUPLICATE",`${u}/code`),a.add(p),b(c.name,`${u}/name`,255);let f=x(c.resourceCode,`${u}/resourceCode`),A=s.get(f);A||l("NATIVE_SCOPE_SOURCE_RESOURCE_MISSING",`${u}/resourceCode`);let m=I(c.subject,`${u}/subject`),N=b(m.type,`${u}/subject/type`,32);T(m,N==="role_membership"?["type","userIdField","roleCode"]:["type","userIdField"],`${u}/subject`),["user","role_membership"].includes(N)||l("NATIVE_SCOPE_SOURCE_SUBJECT_INVALID",`${u}/subject/type`);let C=he(m.userIdField,A);_t(C)||l("NATIVE_SCOPE_SOURCE_SUBJECT_PATH_INVALID",`${u}/subject/userIdField`),N==="role_membership"&&!t.has(String(m.roleCode))&&l("NATIVE_ROLE_REFERENCE_MISSING",`${u}/subject/roleCode`);let g=new Set;for(let[D,h]of $(c.grants,`${u}/grants`,100).entries()){let R=`${u}/grants/${D}`,v=I(h,R);T(v,["dimensionCode","valueField","parentValueField"],R,!0);let V=S(v.dimensionCode,`${R}/dimensionCode`);(!i.has(V)||g.has(V))&&l("NATIVE_SCOPE_SOURCE_DIMENSION_INVALID",`${R}/dimensionCode`),g.add(V),c.failureMode==="last_known_good"&&r.add(V);for(let L of["valueField","parentValueField"]){if(v[L]===void 0)continue;let M=he(v[L],A);zt(M,o.get(V),s)||l("NATIVE_SCOPE_SOURCE_GRANT_PATH_INVALID",`${R}/${L}`)}}g.size===0&&l("NATIVE_SCOPE_SOURCE_GRANT_REQUIRED",`${u}/grants`),["strict","last_known_good"].includes(c.failureMode)||l("NATIVE_SCOPE_SOURCE_FAILURE_MODE_INVALID",`${u}/failureMode`);for(let D of["operationField","enabledField","effectiveFromField","effectiveToField"]){if(c[D]===void 0)continue;let h=J(c[D],`${u}/${D}`);A.has(h)||l("NATIVE_SCOPE_SOURCE_FIELD_MISSING",`${u}/${D}`)}}Mi(e,t,s,n);let d=new Set;for(let[_,E]of e.authz.dataPolicies.entries()){let u=`/config/authz/dataPolicies/${_}`,c=I(E,u);T(c,["code","name","resourceCode","unrestrictedRoleCodes","operations","matchMode","rules","readExpression","writeBoundary"],u,!0);let p=S(c.code,`${u}/code`);d.has(p)&&l("NATIVE_DATA_POLICY_DUPLICATE",`${u}/code`),d.add(p);let f=c.readExpression!==void 0,A=w(c.operations||[],`${u}/operations`,4);c.operations!==void 0&&(A.length===0||A.some(h=>!["read","create","update","delete"].includes(h)))&&l("NATIVE_DATA_POLICY_OPERATIONS_INVALID",`${u}/operations`),["AND","OR"].includes(c.matchMode)||l("NATIVE_DATA_POLICY_MATCH_MODE_INVALID",`${u}/matchMode`),f&&c.operations!==void 0&&l("NATIVE_DATA_POLICY_READ_EXPRESSION_OPERATIONS_FORBIDDEN",`${u}/operations`);let m=e.data.resources.find(h=>h.dataPolicyCode===p),N=c.resourceCode||m?.code,C=N?s.get(x(N,`${u}/resourceCode`)):void 0;f&&!C&&l("NATIVE_DATA_POLICY_RESOURCE_MISSING",`${u}/resourceCode`);let g=w(c.unrestrictedRoleCodes||[],`${u}/unrestrictedRoleCodes`,100);c.unrestrictedRoleCodes!==void 0&&g.length===0&&l("NATIVE_DATA_POLICY_UNRESTRICTED_ROLES_INVALID",`${u}/unrestrictedRoleCodes`);for(let h of g)t.has(h)||l("NATIVE_ROLE_REFERENCE_MISSING",`${u}/unrestrictedRoleCodes`);let D;try{let h=$(c.rules,`${u}/rules`,100).map((R,v)=>({rule:I(R,`${u}/rules/${v}`),pointer:`${u}/rules/${v}`}));h.length===0?(!f||c.matchMode!=="AND"||c.writeBoundary!=="capability_only")&&l("NATIVE_DATA_POLICY_WRITE_BOUNDARY_REQUIRED",u):c.writeBoundary!==void 0&&l("NATIVE_DATA_POLICY_WRITE_BOUNDARY_INVALID",`${u}/writeBoundary`),D=[...h],f&&(D.push(...We(c.readExpression,`${u}/readExpression`)),Qt(c.readExpression,`${u}/readExpression`))}catch(h){throw h instanceof Se&&l(h.code,h.pointer),h}for(let{rule:h,pointer:R}of D){T(h,["subject","dimensionCode","relationCode","resourceCode","field","roleCodes","operation","valuePath","emptyMatchesAll","operator","value","operand"],R,!0);let v=J(h.field,`${R}/field`),V=C?.get(v);f&&!V&&l("NATIVE_DATA_POLICY_FIELD_MISSING",`${R}/field`);for(let U of w(h.roleCodes||[],`${R}/roleCodes`,100))t.has(U)||l("NATIVE_ROLE_REFERENCE_MISSING",`${R}/roleCodes`);let L=String(h.operator||""),M=h.operand==="db_now",K=["is_null","is_not_null"].includes(L),P=["eq","not_eq","in","not_in"].includes(L),Q=!M&&(h.operator!==void 0||h.value!==void 0);if([h.subject==="current_user"?"current_user":"",typeof h.dimensionCode=="string"?"dimension":"",typeof h.relationCode=="string"?"relationship":"",Q?"constant":"",M?"db_now":""].filter(Boolean).length!==1&&l("NATIVE_DATA_POLICY_RULE_SOURCE_INVALID",R),h.subject!==void 0&&h.subject!=="current_user"&&l("NATIVE_DATA_POLICY_SUBJECT_INVALID",`${R}/subject`),Q){if(!P&&!K&&l("NATIVE_DATA_POLICY_OPERATOR_INVALID",`${R}/operator`),["in","not_in"].includes(L)){let U=$(h.value,`${R}/value`,100).map((Ee,re)=>b(Ee,`${R}/value/${re}`,2048));(U.length===0||new Set(U).size!==U.length)&&l("NATIVE_DATA_POLICY_VALUE_INVALID",`${R}/value`)}else["eq","not_eq"].includes(L)?b(h.value,`${R}/value`,2048):(h.value!==void 0||h.operand!==void 0)&&l("NATIVE_DATA_POLICY_VALUE_INVALID",`${R}/value`);for(let U of["operation","valuePath","emptyMatchesAll","resourceCode","operand"])h[U]!==void 0&&l("NATIVE_DATA_POLICY_CONSTANT_RULE_INVALID",`${R}/${U}`)}if(M){(!["lt","lte","gt","gte"].includes(L)||h.value!==void 0||V?.type!=="datetime")&&l("NATIVE_DATA_POLICY_DB_NOW_INVALID",R);for(let U of["operation","valuePath","emptyMatchesAll","resourceCode","value"])h[U]!==void 0&&l("NATIVE_DATA_POLICY_DB_NOW_INVALID",`${R}/${U}`)}h.dimensionCode&&!i.has(h.dimensionCode)&&l("NATIVE_SCOPE_DIMENSION_MISSING",`${R}/dimensionCode`),r.has(String(h.dimensionCode||""))&&h.operation!=="read"&&l("NATIVE_SCOPE_SOURCE_LAST_KNOWN_GOOD_UNSAFE",`${R}/operation`)}}for(let[_,E]of e.data.resources.entries()){let u=I(E,`/config/data/resources/${_}`);u.dataPolicyCode&&!d.has(u.dataPolicyCode)&&l("NATIVE_DATA_POLICY_REFERENCE_MISSING",`/config/data/resources/${_}/dataPolicyCode`)}}function ki(e){try{wt(e.data.resources,"/config/data/resources")}catch(t){throw t instanceof ce&&l(t.code,t.pointer),t}}function Mi(e,t,n,o){let i=new Set;for(let[s,a]of e.authz.roleMembershipSources.entries()){let r=`/config/authz/roleMembershipSources/${s}`,d=I(a,r);T(d,["code","name","resourceCode","userIdField","roleCode","enabledField","effectiveFromField","effectiveToField","failureMode"],r,!0);let _=S(d.code,`${r}/code`);_.length>100&&l("NATIVE_AUTHORIZATION_PROJECTION_SOURCE_CODE_INVALID",`${r}/code`),i.has(_)&&l("NATIVE_AUTHORIZATION_PROJECTION_SOURCE_DUPLICATE",`${r}/code`),i.add(_),b(d.name,`${r}/name`,255);let E=un(d.resourceCode,`${r}/resourceCode`,n);fn(d.userIdField,`${r}/userIdField`,E),t.has(String(d.roleCode||""))||l("NATIVE_ROLE_REFERENCE_MISSING",`${r}/roleCode`),o&&d.roleCode===o&&l("NATIVE_AUTHENTICATED_USER_ROLE_SOURCE_CONFLICT",`${r}/roleCode`),_n(d,r,E)}for(let[s,a]of e.authz.relationshipGrantSources.entries()){let r=`/config/authz/relationshipGrantSources/${s}`,d=I(a,r);T(d,["code","name","resourceCode","subject","relationCode","targetResourceCode","resourceIdField","operations","enabledField","effectiveFromField","effectiveToField","failureMode"],r,!0);let _=S(d.code,`${r}/code`);_.length>100&&l("NATIVE_AUTHORIZATION_PROJECTION_SOURCE_CODE_INVALID",`${r}/code`),i.has(_)&&l("NATIVE_AUTHORIZATION_PROJECTION_SOURCE_DUPLICATE",`${r}/code`),i.add(_),b(d.name,`${r}/name`,255);let E=un(d.resourceCode,`${r}/resourceCode`,n),u=I(d.subject,`${r}/subject`),c=b(u.type,`${r}/subject/type`,32);T(u,c==="role_membership"?["type","userIdField","roleCode"]:["type","userIdField"],`${r}/subject`),["user","role_membership"].includes(c)||l("NATIVE_AUTHORIZATION_PROJECTION_SUBJECT_INVALID",`${r}/subject/type`),fn(u.userIdField,`${r}/subject/userIdField`,E),c==="role_membership"&&!t.has(String(u.roleCode||""))&&l("NATIVE_ROLE_REFERENCE_MISSING",`${r}/subject/roleCode`),S(d.relationCode,`${r}/relationCode`);let p=x(d.targetResourceCode,`${r}/targetResourceCode`);n.has(p)||l("NATIVE_AUTHORIZATION_PROJECTION_TARGET_RESOURCE_MISSING",`${r}/targetResourceCode`);let f=he(d.resourceIdField,E),A=f?.field.type==="resource-ref.single"&&f.valuePath==="value"&&f.field.source?.resourceCode===p;(d.resourceIdField==="id"?p!==String(d.resourceCode):!A)&&l("NATIVE_AUTHORIZATION_PROJECTION_RESOURCE_ID_FIELD_INVALID",`${r}/resourceIdField`);let m=w(d.operations,`${r}/operations`,20);(m.length===0||m.some(N=>N.length>64||!/^[A-Za-z0-9][A-Za-z0-9:._*-]{0,63}$/.test(N)))&&l("NATIVE_AUTHORIZATION_PROJECTION_OPERATIONS_INVALID",`${r}/operations`),_n(d,r,E)}}function un(e,t,n){let o=x(e,t),i=n.get(o);return i||l("NATIVE_AUTHORIZATION_PROJECTION_RESOURCE_MISSING",t),i}function fn(e,t,n){let o=he(e,n);_t(o)||l("NATIVE_AUTHORIZATION_PROJECTION_USER_FIELD_INVALID",t)}function _n(e,t,n){if(e.failureMode!=="strict"&&l("NATIVE_AUTHORIZATION_PROJECTION_FAILURE_MODE_INVALID",`${t}/failureMode`),e.enabledField!==void 0){let o=J(e.enabledField,`${t}/enabledField`);n.get(o)?.type!=="boolean"&&l("NATIVE_AUTHORIZATION_PROJECTION_ENABLED_FIELD_INVALID",`${t}/enabledField`)}for(let o of["effectiveFromField","effectiveToField"]){if(e[o]===void 0)continue;let i=J(e[o],`${t}/${o}`);["date","datetime"].includes(String(n.get(i)?.type))||l("NATIVE_AUTHORIZATION_PROJECTION_EFFECTIVE_FIELD_INVALID",`${t}/${o}`)}}function Ui(e){let t=new Set,n=new Set;e.forEach((o,i)=>{let s=`/config/backend/secrets/${i}`,a=I(o,s);T(a,["name","env","description","required","exposure"],s,!0);let r=b(a.name,`${s}/name`,128),d=b(a.env,`${s}/env`,128);xo.test(r)||l("NATIVE_SECRET_NAME_INVALID",`${s}/name`),(!jo.test(d)||d.startsWith("OPENXIANGDA_")||["NODE_ENV","PORT"].includes(d))&&l("NATIVE_SECRET_ENV_INVALID",`${s}/env`),t.has(r)&&l("NATIVE_SECRET_NAME_DUPLICATE",`${s}/name`),n.has(d)&&l("NATIVE_SECRET_ENV_DUPLICATE",`${s}/env`),t.add(r),n.add(d),F(a.exposure,"active_only",`${s}/exposure`),a.required!==void 0&&be(a.required,`${s}/required`),a.description!==void 0&&bt(a.description,`${s}/description`,2e3)})}function xi(e){let t=new Set,n=new Map,o=new Map(e.data.resources.map(c=>[String(c.code),c])),i=new Map(e.frontend.routes.map((c,p)=>{let f=I(c,`/config/frontend/routes/${p}`);return[S(f.code,`/config/frontend/routes/${p}/code`),f]}));for(let[c,p]of e.workflows.definitions.entries()){let f=`/config/workflows/definitions/${c}`,A=I(p,f);if(T(A,["version","definition","launch"],f,["detailRouteCode"]),Sn(A.launch,`${f}/launch`),A.detailRouteCode!==void 0){let g=Vn(A.detailRouteCode,`${f}/detailRouteCode`);for(let[D,h,R]of[["desktop",g.desktop,"admin"],["mobile",g.mobile,"user"]]){let v=`${f}/detailRouteCode/${D}`,V=i.get(h);V||l("NATIVE_WORKFLOW_DETAIL_ROUTE_MISSING",v),V.surface!==R&&l("NATIVE_WORKFLOW_DETAIL_ROUTE_SURFACE_INVALID",v);let L=ee(V.path,v),M=[...L.matchAll(/:([A-Za-z][A-Za-z0-9_]*)/g)].map(K=>K[1]);(L.includes("*")||M.length!==1||M[0]!=="instanceId")&&l("NATIVE_WORKFLOW_DETAIL_ROUTE_PATH_INVALID",v)}}let m=I(A.definition,`${f}/definition`),N=`${m.code}:${Oe(A.version,`${f}/version`)}`;t.has(N)&&l("NATIVE_WORKFLOW_DEFINITION_DUPLICATE",f),t.add(N),Wi(m,`${f}/definition`),ji(m.subject,o,`${f}/definition/subject`);let C=Kt(m,{appCode:e.appCode,capabilities:e.authz.capabilities.map(g=>g.code),fields:new Map((o.get(m.subject.resourceCode)?.schema.fields||[]).map(g=>[g.code,g]))});C.length&&l("NATIVE_WORKFLOW_INSTANCE_COMMAND_POLICY_INVALID",`${f}/definition/instanceCommands`,{errors:C}),m.title===m.code&&l("NATIVE_WORKFLOW_USER_TITLE_REQUIRED",`${f}/definition/title`),n.set(N,m)}let s=new Set,a=new Map;for(let[c,p]of e.workflows.bindings.entries()){let f=I(p,`/config/workflows/bindings/${c}`),A=I(f.binding,`/config/workflows/bindings/${c}/binding`),m=`${A.workflowCode}:${Oe(f.version,`/config/workflows/bindings/${c}/version`)}`;s.has(m)&&l("NATIVE_WORKFLOW_BINDING_DUPLICATE",`/config/workflows/bindings/${c}`),s.add(m),Bi(A,`/config/workflows/bindings/${c}/binding`),a.set(m,A)}let r=new Set,d=new Map;for(let[c,p]of e.workflows.activations.entries()){let f=`/config/workflows/activations/${c}`,A=I(p,f);T(A,["workflowCode","definitionVersion","bindingVersion","acceptedCommandDeactivationPolicy"],f,["environmentKey"]);let m=S(A.workflowCode,`${f}/workflowCode`);r.has(m)&&l("NATIVE_WORKFLOW_ACTIVATION_DUPLICATE",f),r.add(m);let N=`${m}:${Oe(A.definitionVersion,`${f}/definitionVersion`)}`,C=`${m}:${Oe(A.bindingVersion,`${f}/bindingVersion`)}`;t.has(N)||l("NATIVE_WORKFLOW_DEFINITION_REFERENCE_MISSING",`${f}/definitionVersion`),s.has(C)||l("NATIVE_WORKFLOW_BINDING_REFERENCE_MISSING",`${f}/bindingVersion`);let g=n.get(N),D=a.get(C);(!["finish-pinned","cancel-on-deactivate"].includes(A.acceptedCommandDeactivationPolicy)||A.acceptedCommandDeactivationPolicy!==g.acceptedCommandDeactivationPolicy)&&l("NATIVE_WORKFLOW_COMMAND_DEACTIVATION_POLICY_MISMATCH",`${f}/acceptedCommandDeactivationPolicy`),Ji(g,D,`/config/workflows/activations/${c}`),d.set(m,D)}let _=new Set;e.workflows.providers.forEach((c,p)=>{let f=`/config/workflows/providers/${p}`,A=I(c,f);T(A,["code","endpointPath","timeoutMs"],f,!0);let m=S(A.code,`${f}/code`);_.has(m)&&l("NATIVE_WORKFLOW_PROVIDER_DUPLICATE",`${f}/code`),_.add(m),ee(A.endpointPath,`${f}/endpointPath`),A.timeoutMs!==void 0&&z(A.timeoutMs,`${f}/timeoutMs`,100,1e4)});for(let[c,p]of d.entries())for(let[f,A]of Object.entries(I(p.bindings,"/config/workflows/bindings/*/binding/bindings"))){let m=I(A,`/config/workflows/${c}/bindings/${f}`);m.provider==="application_provider"&&!_.has(m.providerCode)&&l("NATIVE_WORKFLOW_PROVIDER_REFERENCE_MISSING",`/config/workflows/${c}/bindings/${f}/providerCode`)}let E=new Set(e.authz.roles.map(c=>c.code)),u=new Set;e.workflows.editableParameters.forEach((c,p)=>{let f=`/config/workflows/editableParameters/${p}`,A=I(c,f);T(A,["code","workflowCode","bindingKey","label","valueType","required","allowedRoleCodes","allowedProviderCodes","maxItems"],f,!0);let m=S(A.code,`${f}/code`);u.has(m)&&l("NATIVE_WORKFLOW_EDITABLE_PARAMETER_DUPLICATE",`${f}/code`),u.add(m);let N=He(A.workflowCode,`${f}/workflowCode`),C=$t(A.bindingKey,`${f}/bindingKey`),g=d.get(N);(!g||!I(g.bindings,`${f}/bindingKey`)[C])&&l("NATIVE_WORKFLOW_EDITABLE_BINDING_MISSING",`${f}/bindingKey`),b(A.label,`${f}/label`,255),["role_code","user_ids","provider_code"].includes(A.valueType)||l("NATIVE_WORKFLOW_EDITABLE_VALUE_TYPE_INVALID",`${f}/valueType`);for(let D of w(A.allowedRoleCodes||[],`${f}/allowedRoleCodes`,100))E.has(D)||l("NATIVE_ROLE_REFERENCE_MISSING",`${f}/allowedRoleCodes`);for(let D of w(A.allowedProviderCodes||[],`${f}/allowedProviderCodes`,100))_.has(D)||l("NATIVE_WORKFLOW_PROVIDER_REFERENCE_MISSING",`${f}/allowedProviderCodes`);A.required!==void 0&&be(A.required,`${f}/required`),A.maxItems!==void 0&&z(A.maxItems,`${f}/maxItems`,1,200)})}function ji(e,t,n){let o=I(e,n);T(o,["resourceCode","factProjection"],n,["summaryFields"]);let i=x(o.resourceCode,`${n}/resourceCode`),s=t.get(i);s||l("NATIVE_WORKFLOW_SUBJECT_RESOURCE_MISSING",`${n}/resourceCode`);let a=new Set($(I(s.schema,`${n}/resourceCode`).fields,`${n}/resourceCode`,500).map((_,E)=>J(I(_,`${n}/resourceCode/${E}`).code,`${n}/resourceCode/${E}`))),r=I(o.factProjection,`${n}/factProjection`),d=Object.entries(r);(d.length<1||d.length>64)&&l("NATIVE_WORKFLOW_SUBJECT_FACT_PROJECTION_INVALID",`${n}/factProjection`);for(let[_,E]of d){Jo.test(_)||l("NATIVE_WORKFLOW_SUBJECT_FACT_KEY_INVALID",`${n}/factProjection/${_}`);let u=J(E,`${n}/factProjection/${_}`);a.has(u)||l("NATIVE_WORKFLOW_SUBJECT_FIELD_MISSING",`${n}/factProjection/${_}`)}if(o.summaryFields!==void 0){let _=w(o.summaryFields,`${n}/summaryFields`,Go).map((f,A)=>J(f,`${n}/summaryFields/${A}`)),E=t.get(i),u=E.surface&&typeof E.surface=="object"&&!Array.isArray(E.surface)?E.surface:{},c=u.fields&&typeof u.fields=="object"&&!Array.isArray(u.fields)?u.fields:{},p=new Map($(I(E.schema,`${n}/resourceCode`).fields,`${n}/resourceCode`,500).map((f,A)=>{let m=I(f,`${n}/resourceCode/${A}`);return[String(m.code),m]}));for(let[f,A]of _.entries()){let m=p.get(A),N=c[A],C=String(m?.type||""),g=m?.maxLength;(!m||m.system===!0||N&&typeof N=="object"&&!Array.isArray(N)&&N.system===!0||["id","revision","created_by","updated_by","created_at","updated_at"].includes(A)||!Yo.has(C)||C==="text.long"&&typeof g=="number"&&Number.isFinite(g)&&g>zo)&&l("NATIVE_WORKFLOW_SUBJECT_SUMMARY_FIELDS_INVALID",`${n}/summaryFields/${f}`)}}}function Wi(e,t){T(e,["schemaVersion","code","title","subject","acceptedCommandDeactivationPolicy","startAt","inputSchema","nodes"],t,["organizationContext","instanceCommands"]),F(e.schemaVersion,"openxiangda.workflow-definition/v2",`${t}/schemaVersion`),He(e.code,`${t}/code`),b(e.title,`${t}/title`,255),["finish-pinned","cancel-on-deactivate"].includes(e.acceptedCommandDeactivationPolicy)||l("NATIVE_WORKFLOW_COMMAND_DEACTIVATION_POLICY_REQUIRED",`${t}/acceptedCommandDeactivationPolicy`);let n=I(e.nodes,`${t}/nodes`),o=Object.keys(n);(o.length===0||o.length>200)&&l("NATIVE_WORKFLOW_NODE_COUNT_INVALID",`${t}/nodes`);let i=b(e.startAt,`${t}/startAt`,128);n[i]||l("NATIVE_WORKFLOW_START_NODE_MISSING",`${t}/startAt`);let s=new Map;for(let[_,E]of Object.entries(n)){let u=`${t}/nodes/${_}`,c=I(E,u);F(c.id,_,`${u}/id`),["approval","condition","end"].includes(c.kind)||l("NATIVE_WORKFLOW_NODE_KIND_INVALID",`${u}/kind`);let p=[];if(c.kind==="approval"){$t(c.binding,`${u}/binding`),["single","any","all","sequence"].includes(c.mode)||l("NATIVE_WORKFLOW_APPROVAL_MODE_INVALID",`${u}/mode`),p.push(b(c.onApprove,`${u}/onApprove`,128),b(c.onReject,`${u}/onReject`,128));for(let f of w(c.returnTargets||[],`${u}/returnTargets`,200))n[f]||l("NATIVE_WORKFLOW_TARGET_MISSING",`${u}/returnTargets`);for(let f of w(c.allowedOperations||[],`${u}/allowedOperations`,20))Ko.has(f)||l("NATIVE_WORKFLOW_OPERATION_INVALID",`${u}/allowedOperations`)}else if(c.kind==="condition"){let f=$(c.branches,`${u}/branches`,100);f.length===0&&l("NATIVE_WORKFLOW_BRANCH_REQUIRED",`${u}/branches`),f.forEach((A,m)=>{let N=I(A,`${u}/branches/${m}`);Ve(N.when,`${u}/branches/${m}/when`,0),p.push(b(N.target,`${u}/branches/${m}/target`,128))}),p.push(b(c.otherwise,`${u}/otherwise`,128))}else b(c.outcome,`${u}/outcome`,128);for(let f of p)n[f]||l("NATIVE_WORKFLOW_TARGET_MISSING",u);s.set(_,p)}let a=new Set,r=new Set,d=_=>{if(r.has(_)&&l("NATIVE_WORKFLOW_CYCLE_FORBIDDEN",`${t}/nodes/${_}`),!a.has(_)){a.add(_),r.add(_);for(let E of s.get(_)||[])d(E);r.delete(_)}};d(i),a.size!==o.length&&l("NATIVE_WORKFLOW_NODE_UNREACHABLE",`${t}/nodes`)}function Ve(e,t,n){n>20&&l("NATIVE_WORKFLOW_EXPRESSION_DEPTH_EXCEEDED",t);let o=I(e,t),i=b(o.op,`${t}/op`,16);if(i!=="literal"){if(i==="path"){let s=b(o.path,`${t}/path`,255);/^[A-Za-z][A-Za-z0-9_.]{0,254}$/.test(s)||l("NATIVE_WORKFLOW_EXPRESSION_PATH_INVALID",`${t}/path`);return}if(["eq","neq","gt","gte","lt","lte","in","contains"].includes(i)){Ve(o.left,`${t}/left`,n+1),Ve(o.right,`${t}/right`,n+1);return}if(["and","or"].includes(i)){let s=$(o.values,`${t}/values`,100);s.length===0&&l("NATIVE_WORKFLOW_EXPRESSION_EMPTY",`${t}/values`),s.forEach((a,r)=>Ve(a,`${t}/values/${r}`,n+1));return}if(["not","exists"].includes(i)){Ve(o.value,`${t}/value`,n+1);return}l("NATIVE_WORKFLOW_EXPRESSION_OPERATOR_INVALID",`${t}/op`)}}function Bi(e,t){F(e.schemaVersion,"openxiangda.workflow-binding/v2",`${t}/schemaVersion`),He(e.workflowCode,`${t}/workflowCode`);let n=I(e.bindings,`${t}/bindings`);Object.keys(n).length>200&&l("NATIVE_WORKFLOW_BINDING_LIMIT_EXCEEDED",`${t}/bindings`);for(let[o,i]of Object.entries(n)){$t(o,`${t}/bindings/${o}`);let s=I(i,`${t}/bindings/${o}`),a=b(s.provider,`${t}/bindings/${o}/provider`,64);["fixed_users","initiator","input_users","form_field_users","department_supervisor","app_role","app_role_in_scope","business_relation","previous_node_actor","initiator_select","application_provider"].includes(a)||l("NATIVE_WORKFLOW_BINDING_PROVIDER_INVALID",`${t}/bindings/${o}/provider`),a==="fixed_users"&&$(s.users,`${t}/bindings/${o}/users`,200).length===0&&l("NATIVE_WORKFLOW_BINDING_USERS_REQUIRED",`${t}/bindings/${o}/users`),["input_users","form_field_users"].includes(a)&&b(s.inputPath,`${t}/bindings/${o}/inputPath`,255),["app_role","app_role_in_scope","initiator_select"].includes(a)&&S(s.roleCode,`${t}/bindings/${o}/roleCode`),a==="department_supervisor"&&b(s.departmentIdFrom,`${t}/bindings/${o}/departmentIdFrom`,255),a==="application_provider"&&S(s.providerCode,`${t}/bindings/${o}/providerCode`)}}function Ji(e,t,n){F(t.workflowCode,e.code,`${n}/workflowCode`);let o=I(t.bindings,`${n}/bindings`);for(let[i,s]of Object.entries(I(e.nodes,`${n}/nodes`))){let a=I(s,`${n}/nodes/${i}`);a.kind==="approval"&&!o[a.binding]&&l("NATIVE_WORKFLOW_BINDING_REFERENCE_MISSING",`${n}/nodes/${i}/binding`)}}function we(e,t,n){let o=I(e,t);T(o,["schemaVersion","appCode","code","name","schema","surface","invariants","capabilities","dataPolicyCode","fieldPolicies"],t,!0),F(o.schemaVersion,"openxiangda.data-resource/v2",`${t}/schemaVersion`),F(o.appCode,n,`${t}/appCode`);let i=x(o.code,`${t}/code`),s=b(o.name,`${t}/name`,255),a=I(o.schema,`${t}/schema`);T(a,["fields"],`${t}/schema`);let r,d;try{r=tt(a.fields,`${t}/schema/fields`),d=Pt(o.invariants,r,`${t}/invariants`),dt(o.surface,r,`${t}/surface`)}catch(c){throw c instanceof ce&&l(c.code,c.pointer),c}let _=new Set(r.map(c=>c.code)),E=I(o.capabilities,`${t}/capabilities`);T(E,["read","create","update","delete"],`${t}/capabilities`);let u=I(o.fieldPolicies,`${t}/fieldPolicies`);for(let[c,p]of Object.entries(u)){_.has(c)||l("NATIVE_DATA_FIELD_POLICY_FIELD_MISSING",`${t}/fieldPolicies/${c}`);let f=`${t}/fieldPolicies/${c}`,A=I(p,f);T(A,["read","create","update","mask"],f,!0),A.mask!==void 0&&!["omit","null"].includes(A.mask)&&l("NATIVE_DATA_FIELD_POLICY_MASK_INVALID",`${f}/mask`)}return{...o,code:i,name:s,schema:{fields:r},...o.invariants===void 0?{}:{invariants:d},capabilities:E,fieldPolicies:u}}function yn(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,n])=>({code:t,kind:"platform",name:n,source:"platform"}))]}function En(e,t,n,o){let i=e.toString("utf8"),s;try{s=JSON.parse(i)}catch{l(n,t)}let a=I(s,t);return W(a)!==i&&l(o,t),a}function pn(e,t){let n=0,o=(i,s,a)=>{if(n+=1,n>Zo&&l("NATIVE_ARTIFACT_NODE_LIMIT_EXCEEDED",s),a>Qo&&l("NATIVE_ARTIFACT_DEPTH_LIMIT_EXCEEDED",s),typeof i=="string"){Buffer.byteLength(i)>At&&l("NATIVE_ARTIFACT_STRING_LIMIT_EXCEEDED",s);return}if(Array.isArray(i)){i.forEach((r,d)=>o(r,`${s}/${d}`,a+1));return}if(!(!i||typeof i!="object"))for(let[r,d]of Object.entries(i))["__proto__","prototype","constructor"].includes(r)&&l("NATIVE_ARTIFACT_DANGEROUS_KEY",`${s}/${r}`),Gi(r)&&l("NATIVE_ARTIFACT_RUNTIME_FIELD_FORBIDDEN",`${s}/${r}`),o(d,`${s}/${r}`,a+1)};o(e,t,0)}function Gi(e){return["environmentKey","environmentId","secretValue","ciphertext","oauthClient","oauthClientId","oauthClientSecret","signingSecret","kubernetesNamespace","nodePort","productionUrl"].includes(e)}function Ce(e){return{value:e,digest:Z(e)}}function An(e,t,n,o){typeof e!="string"&&!Buffer.isBuffer(e)&&!(e instanceof Uint8Array)&&l("NATIVE_ARTIFACT_BYTES_REQUIRED",n);let i=Buffer.isBuffer(e)?e:Buffer.from(e);return i.byteLength===0&&l("NATIVE_ARTIFACT_EMPTY",n),i.byteLength>t&&l(o,n),i}function In(e,t,n,o){let i=Ge.createHash("sha256").update(e).digest("hex");Ge.timingSafeEqual(Buffer.from(i),Buffer.from(t))||l(o,n)}function I(e,t){return(!e||typeof e!="object"||Array.isArray(e))&&l("NATIVE_OBJECT_REQUIRED",t),e}function $(e,t,n){return Array.isArray(e)||l("NATIVE_ARRAY_REQUIRED",t),e.length>n&&l("NATIVE_ARRAY_LIMIT_EXCEEDED",t),e}function w(e,t,n){let o=$(e,t,n).map((i,s)=>b(i,`${t}/${s}`,255));return new Set(o).size!==o.length&&l("NATIVE_ARRAY_DUPLICATE",t),o}function b(e,t,n){return(typeof e!="string"||e.length===0||e.length>n)&&l("NATIVE_STRING_INVALID",t),e}function bt(e,t,n){return(typeof e!="string"||e.length>n)&&l("NATIVE_STRING_INVALID",t),e}function S(e,t){let n=b(e,t,128);return vo.test(n)||l("NATIVE_CODE_INVALID",t),n}function x(e,t){let n=b(e,t,64);return Mo.test(n)||l("NATIVE_RESOURCE_CODE_INVALID",t),n}function J(e,t){let n=b(e,t,63);return Uo.test(n)||l("NATIVE_FIELD_CODE_INVALID",t),n}function He(e,t){let n=b(e,t,128);return Wo.test(n)||l("NATIVE_WORKFLOW_CODE_INVALID",t),n}function $t(e,t){let n=b(e,t,128);return Bo.test(n)||l("NATIVE_WORKFLOW_BINDING_CODE_INVALID",t),n}function _e(e,t,n){let o=b(e,t,255);return Lo.test(o)||l("NATIVE_CAPABILITY_CODE_INVALID",t),!o.startsWith(`app:${n}:`)&&!yn(n).some(i=>i.code===o)&&l("NATIVE_CAPABILITY_APP_MISMATCH",t),o}function ee(e,t){let n=b(e,t,2048);return(!n.startsWith("/")||n.startsWith("//")||n.includes("..")||n.includes("?")||n.includes("#"))&&l("NATIVE_ABSOLUTE_PATH_INVALID",t),n}function Oe(e,t){return(!Number.isInteger(e)||Number(e)<1)&&l("NATIVE_POSITIVE_INTEGER_REQUIRED",t),Number(e)}function z(e,t,n,o){return(!Number.isInteger(e)||Number(e)<n||Number(e)>o)&&l("NATIVE_INTEGER_OUT_OF_RANGE",t),Number(e)}function be(e,t){return typeof e!="boolean"&&l("NATIVE_BOOLEAN_REQUIRED",t),e}function Tt(e,t){let n=b(e,t,64).toLowerCase();return Po.test(n)||l("NATIVE_DIGEST_INVALID",t),n}function F(e,t,n){e!==t&&l("NATIVE_VALUE_MISMATCH",n)}function T(e,t,n,o=!1){let i=new Set([...t,...Array.isArray(o)?o:[]]);for(let s of Object.keys(e))i.has(s)||l("NATIVE_PROPERTY_UNKNOWN",`${n}/${s}`);if(o!==!0)for(let s of t)Object.prototype.hasOwnProperty.call(e,s)||l("NATIVE_PROPERTY_REQUIRED",`${n}/${s}`)}function q(e,t){return[...e].sort((n,o)=>se(t(n),t(o)))}function k(e){return[...new Set(e)].sort(se)}function mn(e){return[...new Set(e)].sort((t,n)=>t-n)}function se(e,t){return e===t?0:e<t?-1:1}function wn(e){return!e||typeof e!="object"||Object.isFrozen(e)||(Object.freeze(e),Object.values(e).forEach(t=>wn(t))),e}function gt(e,t,n){if(pt(e,t))return n;if(Array.isArray(e)&&Array.isArray(t)){let o=Math.max(e.length,t.length);for(let i=0;i<o;i+=1)if(!pt(e[i],t[i]))return gt(e[i],t[i],`${n}/${i}`)}if(e&&t&&typeof e=="object"&&typeof t=="object"&&!Array.isArray(e)&&!Array.isArray(t)){let o=k([...Object.keys(e),...Object.keys(t)]);for(let i of o){let s=e[i],a=t[i];if(!pt(s,a))return gt(s,a,`${n}/${i}`)}}return n}function pt(e,t){return e===void 0||t===void 0?e===t:W(e)===W(t)}function l(e,t,n={}){throw new mt(e,t,n)}var Ys="20cb48cbb9514c3b67ceca47ff2bc1c50fd554104ee380ea60e5a8b5395673ae";export{on as DATA_EVENT_TYPES_V2,Ys as NATIVE_CONFIGURATION_VALIDATOR_DIGEST,B as NATIVE_CONTRACT_CAPACITY_V2,ws as NATIVE_DATA_POLICY_EXPRESSION_MAX_CLAUSES,Ss as NATIVE_DATA_POLICY_EXPRESSION_MAX_DEPTH,Vs as NATIVE_DATA_POLICY_EXPRESSION_MAX_GROUP_ITEMS,ys as NATIVE_DATA_POLICY_EXPRESSION_MAX_LEAVES,Ps as NATIVE_DATA_POLICY_EXPRESSION_MAX_OCCURRENCES,Hn as NATIVE_DATA_QUERY_OPERATORS_V2,mt as NativeConfigurationCompilerError,ce as NativeDataFieldContractV2Error,Se as NativeDataPolicyExpressionV2Error,ft as NativeScopeSourceFieldPathV2Error,vn as OPENXIANGDA_NATIVE_DATA_FIELD_TYPES_V2,le as OPENXIANGDA_NATIVE_DATA_SURFACE_KEYS_V2,Mn as OPENXIANGDA_NATIVE_SYSTEM_FIELDS_V2,Hi as OPENXIANGDA_NATIVE_SYSTEM_FIELD_MAP_V2,It as WORKFLOW_EVENT_TYPES_V2,Gs as compileNativeApplicationConfiguration,ii as compileNativeEventCapturePlansV2,oi as compileRequiredPlatformCapabilitiesV3,qi as isNativeDataQueryOperatorV2,ke as isNativeMultiValueFieldV2,Cs as materializeNativeDataQueryPathTypesV2,We as nativeDataPolicyExpressionLeavesV2,Qt as nativeDataPolicyExpressionToCnfV2,Os as nativeDataQueryPathPlanV2,Qi as nativeFieldAggregatePlanV2,us as nativeFieldColumnDefinitionV2,fs as nativeFieldDefaultSqlV2,_s as nativeFieldHasDefaultV2,Is as nativeFieldIndexStatementsV2,Me as nativeFieldRequiresCreateInputV2,As as nativeFieldSequenceGrantStatementsV2,ps as nativeFieldSequenceOwnershipStatementsV2,Es as nativeFieldSequenceStatementsV2,kt as nativeFieldSupportsFilterV2,Xi as nativeFieldSupportsOperatorV2,st as nativeFieldSupportsSearchV2,rt as nativeFieldSupportsSortV2,vt as nativeOperatorsForFieldV2,po as nativePhysicalFieldV2,ls as nativePhysicalFieldsV2,ue as nativePhysicalObjectNameV2,Ts as nativeScopeSourceFieldValueV2,zt as nativeScopeSourceGrantPathSupportedV2,_t as nativeScopeSourceSubjectPathSupportedV2,ms as nativeSubtableConstraintStatementsV2,tt as parseNativeDataFieldsV2,Pt as parseNativeDataResourceInvariantsV2,lt as projectNativeDataResourceViewV2,H as quoteNativeIdentifierV2,he as resolveNativeScopeSourceFieldPathV2,wt as validateNativeDataResourceReferencesV2,dt as validateNativeDataResourceSurfaceV2,Kt as validateWorkflowInstanceCommandPolicies,hs as workflowInstanceCommandDeadlineError,$s as workflowInstanceTerminateCapabilityAllowed,Ht as workflowPolicyTimestamp};
|
|
8
|
+
END $native_subtable$`]}function ue(e,...t){return`${e}_${uo("sha256").update(t.join(":")).digest("hex").slice(0,32)}`}function H(e){if(!/^[A-Za-z_][A-Za-z0-9_]{0,62}$/.test(e))throw new Error("OPENXIANGDA_NATIVE_IDENTIFIER_INVALID");return`"${e}"`}function Io(e,t){return e.type==="subtable"?"none":t?"gin-trigram":e.indexed?["date-range","datetime-range"].includes(e.type)?"gist-range":ut.has(e.type)?"btree-snapshot-expressions":fo.has(e.type)?"gin-jsonb-path":"btree":"none"}function mo(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 Eo.has(e.type),"jsonb"}}function Bt(e,t){if(ke(t.type)&&t.type!=="subtable")return"'[]'::jsonb";if(t.type!=="serial-number")return"";let n=jt(t.serial?.prefix||""),o=t.serial?.digits??6;return`(${n} || lpad(nextval(${jt(je(e,t.code))})::text, ${o}, '0'))`}function No(e,t){return Wt.has(t.type)?` CHECK (${e} IS NULL OR jsonb_typeof(${e}) = 'array')`:_o.has(t.type)?` CHECK (${e} IS NULL OR jsonb_typeof(${e}) = 'object')`:""}function xe(e){return`"app_data".${H(e)}`}function je(e,t){let n=ue("seq",e,t);return`"app_data".${H(n)}`}function jt(e){return`'${e.replace(/'/g,"''")}'`}var Jt=new Set(["option.single","option.multiple","user.single","user.multiple","department.single","department.multiple","resource-ref.single","resource-ref.multiple"]),To=new Set([...Jt,"cascade.single","cascade.multiple","file","image","signature","address","location","json"]),Gt=/^[A-Za-z][A-Za-z0-9_]{0,62}$/,go=new Set(["__proto__","prototype","constructor"]),ft=class extends Error{constructor(n){super("OPENXIANGDA_SCOPE_PROJECTION_FIELD_PATH_INVALID");this.path=n;this.name="NativeScopeSourceFieldPathV2Error"}path;code="OPENXIANGDA_SCOPE_PROJECTION_FIELD_PATH_INVALID"};function he(e,t){let n=Yt(e);if(!n)return null;let o=t.get(n[0]);if(!o)return null;let i=n.slice(1).join(".")||void 0;return{field:o,...i?{valuePath:i}:{}}}function _t(e){return!!(e&&e.field.type==="user.single"&&e.valuePath==="value")}function zt(e,t,n){if(!e||!t||!Co(e))return!1;let{field:o,valuePath:i}=e;if(!i)return t.valueType==="uuid"?o.type==="uuid":["text.short","text.long","serial-number"].includes(o.type);if(i==="value")return!(t.valueSourceResourceCode&&o.type.startsWith("resource-ref.")&&o.source?.resourceCode!==t.valueSourceResourceCode);let s=i.slice(9),r=n.get(o.source?.resourceCode||"")?.get(s)?.type;return t.valueType==="uuid"?r==="uuid":["text.short","text.long","serial-number"].includes(r||"")}function Ts(e,t){let n=Yt(t);if(!n)throw new ft(String(t||""));let o=e;for(let i of n){if(!o||typeof o!="object"||!Object.prototype.hasOwnProperty.call(o,i))return;o=o[i]}return o}function Co(e){let{field:t,valuePath:n}=e;if(!n)return!To.has(t.type);if(n==="value")return Jt.has(t.type);if(!n.startsWith("snapshot."))return!1;let o=n.slice(9);return Gt.test(o)&&t.type.startsWith("resource-ref.")&&!!t.source?.snapshotFields?.includes(o)}function Yt(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(n=>!Gt.test(n)||go.has(n))||t.length===2&&t[1]!=="value"||t.length===3&&t[1]!=="snapshot"?null:t}var Oo=new Set(["option.single","user.single","department.single","resource-ref.single"]),bo=new Set(["text.short","text.long","text.rich","number.integer","number.decimal","boolean","date","time","datetime","uuid","serial-number"]),$o=new Set(["value","label","description","color"]),ho=new Set(["avatarUrl","employeeNo","title","mobile","email"]),Ro=new Set(["fullPath","parent.value","parent.label"]),Do=new Set(["country.value","country.label","province.value","province.label","city.value","city.label","district.value","district.label","street.value","street.label","detail","fullAddress"]),So=new Set(["longitude","latitude","accuracy"]),Vo=new Set(["address","name","province","city","district","source"]);function Cs(e){let t=new Map(e.map(n=>[n.code,new Map(n.schema.fields.map(o=>[o.code,o]))]));return e.map(n=>({...n,schema:{...n.schema,fields:n.schema.fields.map(o=>{let i=yo(o,t);if(!Object.keys(i).length)return o;let s={...o};return Object.defineProperty(s,"queryPathTypes",{configurable:!1,enumerable:!1,writable:!1,value:Object.freeze(i)}),s})}}))}function Os(e,t){if(Oo.has(e.type)&&$o.has(t)||e.type==="user.single"&&ho.has(t)||e.type==="department.single"&&Ro.has(t))return Re(t);if(e.type==="resource-ref.single"){let n=e.queryPathTypes?.[t];return n?{parts:t.split("."),type:n}:null}if(e.type==="address"&&Do.has(t))return Re(t);if(e.type==="location"){if(So.has(t))return{parts:[t],type:"number.decimal"};if(Vo.has(t))return Re(t);if(t==="capturedAt")return{parts:[t],type:"datetime"}}return null}function yo(e,t){if(e.type!=="resource-ref.single"||!e.source)return{};let n=t.get(e.source.resourceCode);return n?Object.fromEntries((e.source.snapshotFields||[]).flatMap(o=>{let i=n.get(o);return i?[[`snapshot.${o}`,bo.has(i.type)?i.type:"json"]]:[]})):{}}function Re(e){return{parts:e.split("."),type:"text.short"}}function fe(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)?e:void 0}function Kt(e,t){if(e?.instanceCommands===void 0)return[];let n=fe(e.instanceCommands);if(!n||!Object.keys(n).length||Object.keys(n).some(i=>!["withdraw","terminate"].includes(i)))return["WORKFLOW_INSTANCE_COMMAND_POLICIES_INVALID"];let o=[];for(let[i,s]of Object.entries(n)){let a=fe(s),r=i==="withdraw"?["beforeFact"]:["beforeFact","capability"];if(!a||Object.keys(a).some(d=>!r.includes(d))){o.push(`WORKFLOW_INSTANCE_COMMAND_POLICY_INVALID:${i}`);continue}if(i==="terminate"){let d=a.capability;(typeof d!="string"||d.length>255||!/^app:[a-z][a-z0-9]*(?:-[a-z0-9]+)*:[A-Za-z0-9:._-]+$/.test(d)||t&&(!d.startsWith(`app:${t.appCode}:`)||!t.capabilities.includes(d)))&&o.push("WORKFLOW_INSTANCE_TERMINATE_CAPABILITY_INVALID")}if(i==="withdraw"||a.beforeFact!==void 0){let d=a.beforeFact,_=fe(e.inputSchema),E=fe(fe(_?.properties)?.[d]),u=fe(fe(e.subject)?.factProjection)?.[d],c=t?.fields.get(u);(typeof d!="string"||!/^[A-Za-z][A-Za-z0-9_]{0,62}$/.test(d)||!Array.isArray(_?.required)||!_.required.includes(d)||E?.type!=="string"||E?.format!=="date-time"||typeof u!="string"||t&&(c?.type!=="datetime"||c.nullable===!0))&&o.push(`WORKFLOW_INSTANCE_COMMAND_DEADLINE_FACT_INVALID:${i}`)}}return o}function $s(e,t){let n=e?.terminate?.capability;return typeof n=="string"&&/^app:[a-z][a-z0-9]*(?:-[a-z0-9]+)*:[A-Za-z0-9:._-]+$/.test(n)&&t.includes(n)}function Ht(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[,n,o,i,s,a,r]=t,d=t[8],_=new Date(Date.UTC(Number(n),Number(o),0)).getUTCDate();if(Number(o)<1||Number(o)>12||Number(i)<1||Number(i)>_||Number(s)>23||Number(a)>59||Number(r)>59||d!=="Z"&&(Number(d.slice(1,3))>23||Number(d.slice(4))>59))return null;let E=Date.parse(e);return Number.isFinite(E)?E:null}function hs(e,t,n,o){let i=e?.[t];if(!i||t==="terminate"&&i.beforeFact===void 0)return null;let s=i.beforeFact,a=fe(n),r=s&&a&&Object.hasOwn(a,s)?Ht(a[s]):null,d=o instanceof Date?o.getTime():Ht(o);return r===null||d===null||!Number.isFinite(d)?"WORKFLOW_V2_CANCELLATION_DEADLINE_INVALID":d<r?null:"WORKFLOW_V2_CANCELLATION_DEADLINE_PASSED"}import*as Ge from"crypto";var qt="native-4",Xt={"application-native-2":"1.0.0","authz.native-batch-explain":"1.0.0","authz.native-management":"1.0.0","deployment.durable-runs":"1.0.0","deployment.platform-executor":"1.0.0","environment.on-demand-production":"1.0.0","environment.runtime-lifecycle":"1.0.0","data-api-v2":"1.1.0","data.native-golden-crud":"1.0.0","data.managed-files":"1.1.0","workflow.named-input-sources":"1.0.0","directory-v2":"1.0.0","events-v2":"1.0.0","events.durable-receipts":"1.0.0","workflow-kernel-v2":"1.0.0","workflow.instance-cancellation-policy":"1.0.0","business-process.durable-command":"1.1.0","workflow.fresh-command-token":"1.0.0","notification-hub-v2":"1.0.0","authentication.application-login-surface":"1.0.0","public-access.anonymous-owner-records":"1.0.0"};var Ss=5,Vs=20,ys=50,ws=50,Ps=100,Se=class extends Error{constructor(n,o){super(n);this.code=n;this.pointer=o;this.name="NativeDataPolicyExpressionV2Error"}code;pointer};function We(e,t){let n=[],o=(i,s,a)=>{a>5&&De("NATIVE_DATA_POLICY_EXPRESSION_DEPTH_EXCEEDED",s);let r=Zt(i,s),d=["allOf","anyOf"].filter(u=>u in r);if(d.length===0){n.push({rule:r,pointer:s}),n.length>50&&De("NATIVE_DATA_POLICY_EXPRESSION_LEAVES_EXCEEDED",s);return}let _=d[0],E=r[_];(d.length!==1||Object.keys(r).length!==1||!Array.isArray(E)||E.length<1||E.length>20)&&De("NATIVE_DATA_POLICY_EXPRESSION_GROUP_INVALID",s),E.forEach((u,c)=>o(u,`${s}/${_}/${c}`,a+1))};return o(e,t,1),n}function Qt(e,t){We(e,t);let n=(o,i)=>{let s=Zt(o,i);if(Array.isArray(s.allOf))return Et(s.allOf.flatMap((a,r)=>n(a,`${i}/allOf/${r}`)),i);if(Array.isArray(s.anyOf)){let a=[[]];return s.anyOf.forEach((r,d)=>{let _=n(r,`${i}/anyOf/${d}`);a=Et(a.flatMap(E=>_.map(u=>[...E,...u])),i)}),a}return[[s]]};return Et(n(e,t),t)}function Et(e,t){let n=e.reduce((o,i)=>o+i.length,0);return(e.length>50||n>100)&&De("NATIVE_DATA_POLICY_EXPRESSION_EXPANSION_EXCEEDED",t),e}function Zt(e,t){return(!e||typeof e!="object"||Array.isArray(e))&&De("NATIVE_DATA_POLICY_EXPRESSION_NODE_INVALID",t),e}function De(e,t){throw new Se(e,t)}var wo="openxiangda.config-bundle/v3",Nn="openxiangda.contract-bundle/v3",en="openxiangda.native-configuration-projection/v1",ye=qt,Po=/^[a-f0-9]{64}$/,Fo=/^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/,Lo=/^app:[a-z][a-z0-9]*(?:-[a-z0-9]+)*:[A-Za-z0-9:._*-]+$/,vo=/^[a-z][a-z0-9]*(?:[-_.][a-z0-9]+)*$/,ko=/^[a-z][a-z0-9]*(?:[-.][a-z0-9]+)*$/,Mo=/^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/,Uo=/^[A-Za-z][A-Za-z0-9_]{0,62}$/,tn=/^[A-Za-z][A-Za-z0-9_]{0,127}$/,xo=/^[a-z][a-z0-9]*(?:[-_][a-z0-9]+)*$/,jo=/^[A-Z][A-Z0-9_]*$/,Wo=/^[A-Za-z][A-Za-z0-9_-]{0,127}$/,Bo=/^[A-Za-z][A-Za-z0-9_-]{0,127}$/,Jo=/^[A-Za-z][A-Za-z0-9_.]{0,127}$/,Go=16,zo=2*1024,Yo=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"]),Ho=new Set(["overview","database","operations","workflow","members","calendar","document","folder","settings"]),Ko=new Set(["approve","reject","return","transfer","delegate","add_assignee","resubmit","withdraw","terminate","admin_reassign","admin_override","retry_resolution"]),qo=4*1024*1024,Xo=8*1024*1024,Qo=40,Zo=1e5,At=1024*1024,ei="openxiangda.event-handler-manifest/v2",Tn="openxiangda.application-route-manifest/v3",nn=64,ti=new Set(["id","revision","created_by","updated_by","created_at","updated_at"]),B=Object.freeze({perspectives:100,resources:100,capabilities:2e3,operations:500,eventConsumers:100,eventProducers:1e3,eventSchemas:100,eventTypes:500,workflows:100,routes:500,adminPages:500,adminNavigationGroups:100,adminNavigationItems:500}),on=["openxiangda.data.record.created.v2","openxiangda.data.record.updated.v2","openxiangda.data.record.deleted.v2"],It=["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"],ni=new Set(It),mt=class extends Error{code;pointer;identifiers;constructor(t,n,o={}){super(t),this.name="NativeConfigurationCompilerError",this.code=t,this.pointer=n,this.identifiers=Object.fromEntries(Object.entries(o).slice(0,8).map(([i,s])=>[i,String(s).slice(0,128)]))}};function Gs(e){let t=b(e.appCode,"/appCode",128);Fo.test(t)||l("NATIVE_CONFIG_APP_CODE_INVALID","/appCode");let n=Tt(e.expectedConfigDigest,"/expectedConfigDigest"),o=Tt(e.expectedContractDigest,"/expectedContractDigest"),i=An(e.configBytes,qo,"/configBytes","NATIVE_CONFIG_ARTIFACT_TOO_LARGE"),s=An(e.contractBytes,Xo,"/contractBytes","NATIVE_CONTRACT_ARTIFACT_TOO_LARGE");In(i,n,"/configBytes","NATIVE_CONFIG_DIGEST_MISMATCH"),In(s,o,"/contractBytes","NATIVE_CONTRACT_DIGEST_MISMATCH");let a=En(i,"/configBytes","NATIVE_CONFIG_JSON_INVALID","NATIVE_CONFIG_NOT_CANONICAL"),r=En(s,"/contractBytes","NATIVE_CONTRACT_JSON_INVALID","NATIVE_CONTRACT_NOT_CANONICAL");pn(a,"/config"),pn(r,"/contracts");let d=a,_=r;ri(d,t),ai(_,t,n);let E=ci(d,n,_.generatorVersion);W(E)!==W(_)&&l("NATIVE_CONTRACT_CLOSURE_MISMATCH",gt(E,_,"/contracts"));let u={authz:{appCode:t,...d.authz,perspectives:d.perspectives,capabilityCatalog:E.capabilities},data:{appCode:t,resources:d.data.resources,resourceContracts:E.resources},events:{appCode:t,...d.events,consumers:E.eventConsumers,producers:E.eventProducers,handlerManifest:E.eventHandlerManifest,eventTypes:E.eventTypes,capturePlans:ii({resources:d.data.resources,dataPolicies:d.authz.dataPolicies,subscriptions:E.eventConsumers})},workflows:{appCode:t,...d.workflows,contracts:E.workflows},runtime:{appCode:t,requirements:d.runtime,backend:d.backend,frontend:d.frontend},contracts:E},c={authz:Ce(u.authz),data:Ce(u.data),events:Ce(u.events),workflows:Ce(u.workflows),runtime:Ce(u.runtime),contracts:Ce(u.contracts)},p={configDigest:n,contractDigest:o,generatorVersion:_.generatorVersion},f=oi(d),A={schemaVersion:en,compilerContractVersion:ye,appCode:t,source:p,projections:c,requiredPlatformCapabilities:f,aggregateDigest:Z({schemaVersion:en,compilerContractVersion:ye,appCode:t,source:p,requiredPlatformCapabilities:f,projectionDigests:Object.fromEntries(Object.entries(c).map(([m,N])=>[m,N.digest]))})};return wn(A)}function oi(e){let t=e.authz.roles,n=e.data.resources,o=e.backend.operations,i=t.some(f=>f.capabilities.some(A=>A.endsWith(":directory:read")))||n.some(f=>f.schema.fields.some(A=>["user.single","user.multiple","department.single","department.multiple"].includes(A.type)))||o.some(f=>f.platformAccess?.directory),s=!!(e.events.subscriptions.length||e.events.timers.length||e.events.dateTriggers.length||e.events.schemas.length),a=o.some(f=>f.platformAccess?.managedFiles||f.platformAccess?.managedFileCopies)||e.events.subscriptions.some(f=>f.platformAccess?.managedFileCopies),r=o.some(f=>f.platformAccess?.notification)||e.events.subscriptions.some(f=>f.platformAccess?.notification),d=e.workflows.definitions.filter(f=>f.launch.mode==="standalone"||f.launch.mode==="hidden-handoff"),_=o.some(f=>f.platformAccess?.workflow)||d.length>0,E={resources:n},u={perspectives:e.perspectives,authz:e.authz},c={schemaVersion:e.schemaVersion,appCode:e.appCode,frontend:{routes:e.frontend.routes,user:e.frontend.user,admin:e.frontend.admin,devicePolicy:e.frontend.devicePolicy},backend:{operations:o.map(f=>({code:f.code,method:f.method,path:f.path,capability:f.capability,platformAccess:f.platformAccess||null,ai:f.ai||null}))}};return[{code:"application-native-2",declaration:c},{code:"authz.native-batch-explain",declaration:u},{code:"authz.native-management",declaration:u},{code:"deployment.durable-runs",declaration:c.backend},{code:"deployment.platform-executor",declaration:c.backend},{code:"environment.on-demand-production",declaration:{environments:["preproduction","production"]}},{code:"environment.runtime-lifecycle",declaration:{environments:["preproduction","production"]}},...n.length?[{code:"data-api-v2",declaration:E},{code:"data.native-golden-crud",declaration:E}]:[],...i?[{code:"directory-v2",declaration:{roles:t.map(f=>({code:f.code,capabilities:f.capabilities.filter(A=>A.endsWith(":directory:read"))})),resources:n.map(f=>({code:f.code,fields:f.schema.fields.filter(A=>["user.single","user.multiple","department.single","department.multiple"].includes(A.type))})),operations:o.filter(f=>f.platformAccess?.directory).map(f=>({code:f.code,directory:f.platformAccess.directory}))}}]:[],...a?[{code:"data.managed-files",declaration:{operations:o.filter(f=>f.platformAccess?.managedFiles||f.platformAccess?.managedFileCopies).map(f=>({code:f.code,...f.platformAccess?.managedFiles?{managedFiles:f.platformAccess.managedFiles}:{},...f.platformAccess?.managedFileCopies?{managedFileCopies:f.platformAccess.managedFileCopies}:{}})),subscriptions:e.events.subscriptions.filter(f=>f.platformAccess?.managedFileCopies).map(f=>({code:f.code,managedFileCopies:f.platformAccess.managedFileCopies}))}}]:[],...s?[{code:"events-v2",declaration:e.events},{code:"events.durable-receipts",declaration:e.events}]:[],...e.workflows.activations.length?[{code:"workflow-kernel-v2",declaration:e.workflows},{code:"workflow.fresh-command-token",declaration:e.workflows}]:[],...e.workflows.definitions.some(f=>f.definition.instanceCommands!==void 0)?[{code:"workflow.instance-cancellation-policy",declaration:e.workflows.definitions.filter(f=>f.definition.instanceCommands!==void 0)}]:[],..._?[{code:"business-process.durable-command",declaration:{operations:o.filter(f=>f.platformAccess?.workflow).map(f=>({code:f.code,workflow:f.platformAccess.workflow})),definitions:d,activations:e.workflows.activations.filter(f=>d.some(A=>A.definition.code===f.workflowCode))}}]:[],...r?[{code:"notification-hub-v2",declaration:{operations:o.filter(f=>f.platformAccess?.notification).map(f=>({code:f.code,notification:f.platformAccess.notification})),subscriptions:e.events.subscriptions.filter(f=>f.platformAccess?.notification).map(f=>({code:f.code,notification:f.platformAccess.notification}))}}]:[],...e.frontend.authentication?[{code:"authentication.application-login-surface",declaration:e.frontend.authentication}]:[],...e.frontend.publicAccess?[{code:"public-access.anonymous-owner-records",declaration:e.frontend.publicAccess}]:[]].map(({code:f,declaration:A})=>({code:f,contractVersion:Xt[f],usageDigest:`sha256:${Z(A)}`})).sort((f,A)=>f.code===A.code?0:f.code<A.code?-1:1)}function ii(e){let t=new Map(e.dataPolicies.map((o,i)=>{let s=I(o,`/capturePlan/dataPolicies/${i}`);return[String(s.code),s]})),n=e.subscriptions.map((o,i)=>I(o,`/capturePlan/subscriptions/${i}`));return e.resources.map((o,i)=>{let s=`/capturePlan/resources/${i}`,a=I(o,s),r=x(a.code,`${s}/code`),d=a.schema?I(a.schema,`${s}/schema`):a,_=new Set($(d.fields||[],`${s}/schema/fields`,500).map((g,D)=>J(I(g,`${s}/schema/fields/${D}`).code,`${s}/schema/fields/${D}/code`))),E=a.dataPolicyCode?S(a.dataPolicyCode,`${s}/dataPolicyCode`):null,u=E?t.get(E):void 0;E&&!u&&l("NATIVE_EVENT_CAPTURE_AUTHZ_POLICY_NOT_FOUND",s,{resourceCode:r,dataPolicyCode:E});let c=new Set;for(let g of u?.rules||[])c.add(String(g.field));if(u?.readExpression)for(let g of We(u.readExpression,`${s}/readExpression`))c.add(String(g.rule.field));let p=new Set,f=new Set;for(let[g,D]of n.entries()){if(!$(D.eventTypes,`/capturePlan/subscriptions/${g}/eventTypes`,20).map(String).some(L=>L.startsWith("openxiangda.data.")))continue;let R=I(D.filter||{},`/capturePlan/subscriptions/${g}/filter`),v=Array.isArray(R.resourceCodes)?R.resourceCodes.map(String):[];if(v.length&&!v.includes(r))continue;for(let L of si(R,`/capturePlan/subscriptions/${g}/filter`))p.add(L);let V=I(D.payload||{},`/capturePlan/subscriptions/${g}/payload`);for(let L of $(V.fields||[],`/capturePlan/subscriptions/${g}/payload/fields`,32))f.add(J(L,`/capturePlan/subscriptions/${g}/payload/fields`))}let A=new Set([...p,...f]),m=new Set([...A,...c]);m.size>nn&&l("NATIVE_EVENT_CAPTURE_FIELDS_LIMIT",s,{resourceCode:r,maximum:nn});for(let g of m)!_.has(g)&&!(c.has(g)&&ti.has(g))&&l("NATIVE_EVENT_CAPTURE_FIELD_NOT_FOUND",s,{resourceCode:r,field:g});let N=I(a.fieldPolicies||{},`${s}/fieldPolicies`);for(let g of A)N[g]?.mask==="omit"&&l("NATIVE_EVENT_CAPTURE_FIELD_SENSITIVE",s,{resourceCode:r,field:g});let C={resourceCode:r,filterFields:[...p].sort(),projectionFields:[...f].sort(),authorizationFields:[...c].sort(),captureFields:[...m].sort()};return{...C,digest:Z(C)}}).sort((o,i)=>o.resourceCode.localeCompare(i.resourceCode))}function si(e,t){let n=new Set;for(let[a,r]of $(e.changes||[],`${t}/changes`,16).entries()){let d=I(r,`${t}/changes/${a}`);n.add(J(d.field,`${t}/changes/${a}/field`))}let o=I(e.changedFields||{},`${t}/changedFields`);for(let a of["anyOf","allOf","noneOf"])for(let[r,d]of $(o[a]||[],`${t}/changedFields/${a}`,32).entries())n.add(J(d,`${t}/changedFields/${a}/${r}`));let i=0,s=(a,r,d)=>{d>3&&l("NATIVE_EVENT_FILTER_DEPTH_LIMIT",r);let _=I(a,r);if(_.change){let u=I(_.change,`${r}/change`);n.add(J(u.field,`${r}/change/field`)),i+=1;return}if(_.not){s(_.not,`${r}/not`,d+1);return}let E=_.all?"all":_.any?"any":null;E||l("NATIVE_EVENT_FILTER_CONDITION_INVALID",r);for(let[u,c]of $(_[E],`${r}/${E}`,16).entries())s(c,`${r}/${E}/${u}`,d+1)};return e.where&&s(e.where,`${t}/where`,1),i+=Array.isArray(e.changes)?e.changes.length:0,i>16&&l("NATIVE_EVENT_FILTER_ATOM_LIMIT",t),[...n].sort()}function ri(e,t){T(e,["schemaVersion","compilerContractVersion","appCode","perspectives","authz","backend","data","events","workflows","frontend","runtime"],"/config"),F(e.schemaVersion,wo,"/config/schemaVersion"),F(e.compilerContractVersion,ye,"/config/compilerContractVersion"),F(e.appCode,t,"/config/appCode"),$(e.perspectives,"/config/perspectives",100);let n=I(e.authz,"/config/authz");T(n,["capabilities","roles","scopeDimensions","scopeSources","roleMembershipSources","relationshipGrantSources","dataPolicies","authorizationTransitions"],"/config/authz",["authenticatedUserRoleCode"]),$(n.capabilities,"/config/authz/capabilities",2e3),$(n.roles,"/config/authz/roles",100),$(n.scopeDimensions,"/config/authz/scopeDimensions",100),$(n.scopeSources,"/config/authz/scopeSources",100),$(n.roleMembershipSources,"/config/authz/roleMembershipSources",100),$(n.relationshipGrantSources,"/config/authz/relationshipGrantSources",100),$(n.dataPolicies,"/config/authz/dataPolicies",100),$(n.authorizationTransitions,"/config/authz/authorizationTransitions",100);let o=I(e.backend,"/config/backend");T(o,["secrets","operations"],"/config/backend"),$(o.secrets,"/config/backend/secrets",100),$(o.operations,"/config/backend/operations",500),Ui(o.secrets);let i=I(e.data,"/config/data");T(i,["resources"],"/config/data",["resourceDetailRoutes"]),$(i.resources,"/config/data/resources",100),i.resourceDetailRoutes!==void 0&&$(i.resourceDetailRoutes,"/config/data/resourceDetailRoutes",100);let s=I(e.events,"/config/events");T(s,["schemas","subscriptions","timers","dateTriggers"],"/config/events"),$(s.schemas,"/config/events/schemas",100),$(s.subscriptions,"/config/events/subscriptions",100),$(s.timers,"/config/events/timers",100),$(s.dateTriggers,"/config/events/dateTriggers",100);let a=I(e.workflows,"/config/workflows");T(a,["definitions","bindings","activations","providers","editableParameters"],"/config/workflows"),$(a.definitions,"/config/workflows/definitions",100),$(a.bindings,"/config/workflows/bindings",100),$(a.activations,"/config/workflows/activations",100),$(a.providers,"/config/workflows/providers",100),$(a.editableParameters,"/config/workflows/editableParameters",100);let r=I(e.frontend,"/config/frontend");T(r,["routes","user","admin","devicePolicy"],"/config/frontend",["authentication","publicAccess"]),$(r.routes,"/config/frontend/routes",500);let d=I(r.user,"/config/frontend/user");T(d,["applicationTodoCenter"],"/config/frontend/user"),be(d.applicationTodoCenter,"/config/frontend/user/applicationTodoCenter"),Ct(r.devicePolicy,"/config/frontend/devicePolicy"),Object.prototype.hasOwnProperty.call(r,"authentication")&&Cn(r.authentication,r.routes,e,"/config/frontend/authentication"),Object.prototype.hasOwnProperty.call(r,"publicAccess")&&Ti(r.publicAccess,e,"/config/frontend/publicAccess");let _=I(r.admin,"/config/frontend/admin");T(_,["navigation"],"/config/frontend/admin",["access"]),_.access!==void 0&&Ye(_.access,"/config/frontend/admin/access",e.appCode),bi(_.navigation,"/config/frontend/admin/navigation");let E=I(e.runtime,"/config/runtime");T(E,["protocolCapabilities","health"],"/config/runtime"),w(E.protocolCapabilities,"/config/runtime/protocolCapabilities",100),T(I(E.health,"/config/runtime/health"),["livePath","readyPath","versionPath"],"/config/runtime/health"),F(E.health.livePath,"/__platform/health","/config/runtime/health/livePath"),F(E.health.readyPath,"/__platform/ready","/config/runtime/health/readyPath"),F(E.health.versionPath,"/__platform/version","/config/runtime/health/versionPath")}function ai(e,t,n){T(e,["schemaVersion","compilerContractVersion","generatorVersion","appCode","configDigest","perspectives","resources","capabilities","operations","eventConsumers","eventProducers","eventSchemas","eventHandlerManifest","eventTypes","workflows","routes","routeManifest","adminPages","adminNavigation"],"/contracts",["authentication","publicAccess","adminAccess"]),F(e.schemaVersion,Nn,"/contracts/schemaVersion"),F(e.compilerContractVersion,ye,"/contracts/compilerContractVersion"),b(e.generatorVersion,"/contracts/generatorVersion",128),F(e.appCode,t,"/contracts/appCode"),F(e.configDigest,n,"/contracts/configDigest"),$(e.perspectives,"/contracts/perspectives",B.perspectives),$(e.resources,"/contracts/resources",B.resources),$(e.capabilities,"/contracts/capabilities",B.capabilities),$(e.operations,"/contracts/operations",B.operations),$(e.eventConsumers,"/contracts/eventConsumers",B.eventConsumers),$(e.eventProducers,"/contracts/eventProducers",B.eventProducers),$(e.eventSchemas,"/contracts/eventSchemas",B.eventSchemas),I(e.eventHandlerManifest,"/contracts/eventHandlerManifest"),w(e.eventTypes,"/contracts/eventTypes",B.eventTypes),$(e.workflows,"/contracts/workflows",B.workflows),$(e.routes,"/contracts/routes",B.routes),Object.prototype.hasOwnProperty.call(e,"authentication")&&Ii(e.authentication,"/contracts/authentication"),Object.prototype.hasOwnProperty.call(e,"publicAccess")&&gi(e.publicAccess,"/contracts/publicAccess"),Object.prototype.hasOwnProperty.call(e,"adminAccess")&&Ye(e.adminAccess,"/contracts/adminAccess",t),Vi(e.routeManifest,"/contracts/routeManifest",t),Ri(e.adminPages,"/contracts/adminPages"),Di(e.adminNavigation,"/contracts/adminNavigation")}function ci(e,t,n){let o=ui(e);Li(e,o),ki(e),vi(e),xi(e);let i=e.events.schemas.map((c,p)=>{let f=`/config/events/schemas/${p}`,A=I(c,f),m=b(A.eventType,`${f}/eventType`,255);return m.startsWith("openxiangda.")&&l("NATIVE_EVENT_SCHEMA_RESERVED",`${f}/eventType`,{eventType:m}),F(A.schemaDigest,Z(I(A.jsonSchema,`${f}/jsonSchema`)),`${f}/schemaDigest`),A}),s=new Set([...on,...It,...i.map(c=>String(c.eventType))]),a=new Map(e.data.resources.map(c=>[String(c.code),new Map(c.schema.fields.map(p=>[String(p.code),String(p.type)]))])),r=q(e.events.subscriptions.map((c,p)=>{let f=`/config/events/subscriptions/${p}`,A=I(c,f),m=w(A.eventTypes,`${f}/eventTypes`,20);m.forEach((g,D)=>{s.has(g)||l("NATIVE_EVENT_TYPE_NOT_REGISTERED",`${f}/eventTypes/${D}`,{eventType:g})});let N=li(A.delivery,m,`${f}/delivery`),C=di(A.platformAccess,`${f}/platformAccess`,a);return{code:S(A.code,`${f}/code`),endpointPath:ee(A.endpointPath,`${f}/endpointPath`),eventTypes:m,filter:I(A.filter,`${f}/filter`),payload:I(A.payload,`${f}/payload`),...C?{platformAccess:C}:{},delivery:N}}),c=>c.code),d=new Map(i.map(c=>[String(c.eventType),String(c.dataSchemaVersion)])),_=q([...e.data.resources.flatMap(c=>on.map(p=>({code:`data:${c.code}:${p}`,source:"data",eventType:p,dataSchemaVersion:"2.0.0",resourceCode:c.code}))),...i.map(c=>({code:`app:${c.eventType}`,source:"app",eventType:c.eventType,dataSchemaVersion:c.dataSchemaVersion})),...e.events.timers.map(c=>({code:c.code,source:"timer",eventType:c.eventType,dataSchemaVersion:d.get(String(c.eventType))||"2.0.0"})),...e.events.dateTriggers.map(c=>({code:c.code,source:"date",eventType:c.eventType,dataSchemaVersion:d.get(String(c.eventType))||"2.0.0",resourceCode:c.resourceCode,field:c.field})),...e.workflows.activations.length?It.map(c=>({code:`workflow:${c}`,source:"workflow",eventType:c,dataSchemaVersion:"2.0.0"})):[]],c=>`${c.source}:${c.code}:${c.eventType}`),E=k([...r.flatMap(c=>c.eventTypes),..._.map(c=>String(c.eventType))]);hi(e);let u=$n(e);return{schemaVersion:Nn,compilerContractVersion:ye,generatorVersion:n,appCode:e.appCode,configDigest:t,perspectives:e.perspectives,resources:fi(e),capabilities:q(o,c=>c.code),operations:gn(e),eventConsumers:r,eventProducers:_,eventSchemas:i,eventHandlerManifest:{schemaVersion:ei,appCode:e.appCode,handlers:r.map(c=>({code:c.code,endpointPath:c.endpointPath,eventTypes:c.eventTypes,dataSchemaVersions:k(c.eventTypes.map(p=>p.startsWith("openxiangda.")?"2.0.0":d.get(p)||"2.0.0")),maxBodyBytes:65536,receiptProtocolVersion:2}))},eventTypes:E,workflows:Dn(e),routes:ze(e),...Object.prototype.hasOwnProperty.call(e.frontend,"authentication")?{authentication:mi(e)}:{},...Object.prototype.hasOwnProperty.call(e.frontend,"publicAccess")?{publicAccess:Ci(e)}:{},...e.frontend.admin.access?{adminAccess:e.frontend.admin.access}:{},routeManifest:Pi(e),adminPages:u,adminNavigation:Oi(e)}}function di(e,t,n){if(e===void 0)return;let o=I(e,t);T(o,["notification","managedFileCopies"],t,!0);let i={};if(o.notification!==void 0){let s=I(o.notification,`${t}/notification`);T(s,["mode"],`${t}/notification`),F(s.mode,"business-standard",`${t}/notification/mode`),i.notification={mode:"business-standard"}}if(o.managedFileCopies!==void 0){let s=$(o.managedFileCopies,`${t}/managedFileCopies`,16);s.length||l("NATIVE_EVENT_MANAGED_FILE_COPIES_REQUIRED",`${t}/managedFileCopies`);let a=new Set;i.managedFileCopies=q(s.map((r,d)=>{let _=`${t}/managedFileCopies/${d}`,E=I(r,_);T(E,["mode","sourceResourceCode","sourceFieldCodes","targetResourceCode","targetFieldCodes"],_),F(E.mode,"copy",`${_}/mode`);let u=x(E.sourceResourceCode,`${_}/sourceResourceCode`),c=x(E.targetResourceCode,`${_}/targetResourceCode`),p=n.get(u),f=n.get(c);(!p||!f)&&l("NATIVE_EVENT_MANAGED_FILE_COPY_RESOURCE_INVALID",_);let A=w(E.sourceFieldCodes,`${_}/sourceFieldCodes`,16),m=w(E.targetFieldCodes,`${_}/targetFieldCodes`,16);(!A.length||A.length!==m.length)&&l("NATIVE_EVENT_MANAGED_FILE_COPY_FIELDS_INVALID",_),A.forEach((C,g)=>{let D=p.get(C),h=f.get(m[g]);(!["file","image"].includes(String(D))||D!==h)&&l("NATIVE_EVENT_MANAGED_FILE_COPY_FIELD_INVALID",`${_}/sourceFieldCodes/${g}`)});let N=`${u}:${A.join(",")}=>${c}:${m.join(",")}`;return a.has(N)&&l("NATIVE_EVENT_MANAGED_FILE_COPY_DUPLICATE",_),a.add(N),{mode:"copy",sourceResourceCode:u,sourceFieldCodes:k(A),targetResourceCode:c,targetFieldCodes:k(m)}}),r=>`${r.sourceResourceCode}:${r.sourceFieldCodes.join(",")}=>${r.targetResourceCode}:${r.targetFieldCodes.join(",")}`)}return Object.keys(i).length||l("NATIVE_EVENT_PLATFORM_ACCESS_EMPTY",t),i}function li(e,t,n){let o=I(e,n);T(o,["timeoutMs","maxAttempts","initialBackoffMs","maxBackoffMs","ordering","concurrency"],n),z(o.timeoutMs,`${n}/timeoutMs`,1e3,3e4),z(o.maxAttempts,`${n}/maxAttempts`,1,12);let i=z(o.initialBackoffMs,`${n}/initialBackoffMs`,1e3,3e5);z(o.maxBackoffMs,`${n}/maxBackoffMs`,i,18e5),z(o.concurrency,`${n}/concurrency`,1,50);let s=b(o.ordering,`${n}/ordering`,32);return["none","record","workflow-instance"].includes(s)||l("NATIVE_EVENT_DELIVERY_ORDERING_INVALID",`${n}/ordering`),s==="workflow-instance"&&t.some(a=>!ni.has(a))&&l("NATIVE_EVENT_WORKFLOW_ORDERING_REQUIRES_WORKFLOW_FACTS",`${n}/ordering`),o}function ui(e){let t=new Map;for(let n of yn(e.appCode))t.set(n.code,n);for(let[n,o]of e.authz.capabilities.entries()){let i=`/config/authz/capabilities/${n}`,s=I(o,i);T(s,["code","kind","name","description"],i,!0);let a=_e(s.code,`${i}/code`,e.appCode);t.has(a)&&l("NATIVE_CAPABILITY_DUPLICATE",`${i}/code`),["backend","ui"].includes(s.kind)||l("NATIVE_CAPABILITY_KIND_INVALID",`${i}/kind`);let r={code:a,kind:s.kind,name:b(s.name,`${i}/name`,255),source:"explicit",...s.description===void 0?{}:{description:bt(s.description,`${i}/description`,2e3)}};t.set(a,r)}for(let[n,o]of e.data.resources.entries()){let i=`/config/data/resources/${n}`,s=we(o,i,e.appCode),a={read:`\u8BFB\u53D6${s.name}`,create:`\u65B0\u5EFA${s.name}`,update:`\u66F4\u65B0${s.name}`,delete:`\u5220\u9664${s.name}`};for(let r of["read","create","update","delete"]){let d=_e(s.capabilities[r],`${i}/capabilities/${r}`,e.appCode);t.has(d)&&l("NATIVE_CAPABILITY_DUPLICATE",`${i}/capabilities/${r}`),t.set(d,{code:d,kind:"data",name:a[r],source:"data"})}for(let[r,d]of Object.entries(s.fieldPolicies)){let _=I(d,`${i}/fieldPolicies/${r}`);for(let E of["read","create","update"])if(Array.isArray(_[E]))for(let u of w(_[E],`${i}/fieldPolicies/${r}/${E}`,2e3))_e(u,`${i}/fieldPolicies/${r}/${E}`,e.appCode),!t.has(u)&&t.set(u,{code:u,kind:"data",name:`${s.name}.${r}.${E}`,source:"data"})}}return[...t.values()]}function fi(e){let t=_i(e);return q(e.data.resources.map((n,o)=>{let i=we(n,`/config/data/resources/${o}`,e.appCode),s=t.get(i.code);return{code:i.code,schemaDigest:Z(i.schema),fields:q(i.schema.fields.map(a=>({code:a.code,type:a.type})),a=>a.code),...s?{detailRouteCode:s}:{}}}),n=>n.code)}function _i(e){let t=e.data.resourceDetailRoutes===void 0?[]:$(e.data.resourceDetailRoutes,"/config/data/resourceDetailRoutes",100),n=new Map(e.data.resources.map((s,a)=>{let r=`/config/data/resources/${a}`,d=we(s,r,e.appCode);return[d.code,d]})),o=new Map(ze(e).map(s=>[String(s.code),s])),i=new Map;for(let[s,a]of t.entries()){let r=`/config/data/resourceDetailRoutes/${s}`,d=I(a,r);T(d,["resourceCode","desktop","mobile"],r);let _=x(d.resourceCode,`${r}/resourceCode`);i.has(_)&&l("NATIVE_DATA_RESOURCE_DETAIL_ROUTE_DUPLICATE",`${r}/resourceCode`);let E=n.get(_);E||l("NATIVE_DATA_RESOURCE_DETAIL_ROUTE_RESOURCE_MISSING",`${r}/resourceCode`);let u=S(d.desktop,`${r}/desktop`),c=S(d.mobile,`${r}/mobile`);u===c&&l("NATIVE_DATA_RESOURCE_DETAIL_ROUTE_INVALID",r);let p=String(E.capabilities.read);for(let[f,A]of[["desktop",u],["mobile",c]]){let m=`${r}/${f}`,N=o.get(A);N||l("NATIVE_DATA_RESOURCE_DETAIL_ROUTE_REFERENCE_MISSING",m),N.surface!=="user"&&l("NATIVE_DATA_RESOURCE_DETAIL_ROUTE_SURFACE_INVALID",m);let C=ee(N.path,`${m}/path`),g=[...C.matchAll(/:([A-Za-z][A-Za-z0-9_]*)/g)],D=f==="mobile"?!C.startsWith("/m/"):C==="/m"||C.startsWith("/m/");(C.includes("*")||C.includes("?")||C.includes("#")||C.split("/").includes("..")||g.length!==1||D)&&l("NATIVE_DATA_RESOURCE_DETAIL_ROUTE_PATH_INVALID",m);let h=Array.isArray(N.access?.allOf)?N.access.allOf:[];N.capability!==p&&!h.includes(p)&&l("NATIVE_DATA_RESOURCE_DETAIL_ROUTE_CAPABILITY_INVALID",m)}i.set(_,{desktop:u,mobile:c})}return i}function gn(e){let t=new Map(e.data.resources.map((i,s)=>{let a=`/config/data/resources/${s}`,r=we(i,a,e.appCode);return[r.code,new Map(r.schema.fields.map(d=>[String(d.code),String(d.type)]))]})),n=new Set(t.keys()),o=new Set(e.workflows.activations.map((i,s)=>He(I(i,`/config/workflows/activations/${s}`).workflowCode,`/config/workflows/activations/${s}/workflowCode`)));return q(e.backend.operations.map((i,s)=>{let a=`/config/backend/operations/${s}`,r=I(i,a);T(r,["code","method","path","capability","requestSchema","responseSchema","description","platformAccess","ai"],a,!0);let d=b(r.method,`${a}/method`,16);["GET","POST","PUT","PATCH","DELETE"].includes(d)||l("NATIVE_OPERATION_METHOD_INVALID",`${a}/method`);let _=S(r.code,`${a}/code`);pi(r.ai,a,_,d,n);let E=Ei(r.platformAccess,`${a}/platformAccess`,t,o,new Set(e.authz.roles.map(u=>String(u.code))));return{code:_,method:d,path:ee(r.path,`${a}/path`),requiredCapability:_e(r.capability,`${a}/capability`,e.appCode),requestSchemaDigest:Z(I(r.requestSchema,`${a}/requestSchema`)),responseSchemaDigest:Z(I(r.responseSchema,`${a}/responseSchema`)),...r.description===void 0?{}:{description:bt(r.description,`${a}/description`,2e3)},...E?{platformAccess:E}:{}}}),i=>i.code)}function Ei(e,t,n,o,i){if(e===void 0)return null;let s=I(e,t);T(s,["directory","managedFiles","managedFileCopies","notification","workflow","roleAssertions"],t,!0),Object.keys(s).length===0&&l("NATIVE_OPERATION_PLATFORM_ACCESS_EMPTY",t);let a={};if(s.roleAssertions!==void 0){let r=I(s.roleAssertions,`${t}/roleAssertions`);T(r,["roleCodes"],`${t}/roleAssertions`);let d=w(r.roleCodes,`${t}/roleAssertions/roleCodes`,20);d.length||l("NATIVE_OPERATION_ROLE_ASSERTIONS_REQUIRED",`${t}/roleAssertions/roleCodes`),d.forEach((_,E)=>{i.has(_)||l("NATIVE_ROLE_REFERENCE_MISSING",`${t}/roleAssertions/roleCodes/${E}`)}),a.roleAssertions={roleCodes:k(d)}}if(s.directory!==void 0){let r=I(s.directory,`${t}/directory`);T(r,["mode","fields"],`${t}/directory`),r.mode!=="current-initiator"&&l("NATIVE_OPERATION_DIRECTORY_MODE_INVALID",`${t}/directory/mode`);let d=new Set(["displayName","employeeNumber","primaryDepartment","departments"]),_=w(r.fields,`${t}/directory/fields`,4);(!_.length||_.some(E=>!d.has(E)))&&l("NATIVE_OPERATION_DIRECTORY_FIELDS_INVALID",`${t}/directory/fields`),a.directory={mode:"current-initiator",fields:k(_)}}if(s.managedFiles!==void 0){let r=$(s.managedFiles,`${t}/managedFiles`,16);r.length||l("NATIVE_OPERATION_MANAGED_FILES_REQUIRED",`${t}/managedFiles`);let d=new Set;a.managedFiles=q(r.map((_,E)=>{let u=`${t}/managedFiles/${E}`,c=I(_,u);T(c,["resourceCode","fieldCodes","intents"],u);let p=x(c.resourceCode,`${u}/resourceCode`);(d.has(p)||!n.has(p))&&l("NATIVE_OPERATION_MANAGED_FILE_RESOURCE_INVALID",`${u}/resourceCode`),d.add(p);let f=w(c.fieldCodes,`${u}/fieldCodes`,16);(!f.length||f.some(m=>!["file","image","signature"].includes(String(n.get(p)?.get(m)||""))))&&l("NATIVE_OPERATION_MANAGED_FILE_FIELD_INVALID",`${u}/fieldCodes`);let A=w(c.intents,`${u}/intents`,2);return(!A.length||A.some(m=>!["create","update"].includes(m)))&&l("NATIVE_OPERATION_MANAGED_FILE_INTENT_INVALID",`${u}/intents`),{resourceCode:p,fieldCodes:k(f),intents:k(A)}}),_=>_.resourceCode)}if(s.managedFileCopies!==void 0){let r=$(s.managedFileCopies,`${t}/managedFileCopies`,16);r.length||l("NATIVE_OPERATION_MANAGED_FILE_COPIES_REQUIRED",`${t}/managedFileCopies`);let d=new Set;a.managedFileCopies=q(r.map((_,E)=>{let u=`${t}/managedFileCopies/${E}`,c=I(_,u);T(c,["mode","sourceResourceCode","sourceFieldCodes","targetResourceCode","targetFieldCodes"],u),F(c.mode,"copy",`${u}/mode`);let p=x(c.sourceResourceCode,`${u}/sourceResourceCode`),f=x(c.targetResourceCode,`${u}/targetResourceCode`),A=n.get(p),m=n.get(f);(!A||!m)&&l("NATIVE_OPERATION_MANAGED_FILE_COPY_RESOURCE_INVALID",u);let N=w(c.sourceFieldCodes,`${u}/sourceFieldCodes`,16),C=w(c.targetFieldCodes,`${u}/targetFieldCodes`,16);(!N.length||N.length!==C.length)&&l("NATIVE_OPERATION_MANAGED_FILE_COPY_FIELDS_INVALID",u),N.forEach((D,h)=>{let R=A.get(D),v=m.get(C[h]);(!["file","image"].includes(String(R))||R!==v)&&l("NATIVE_OPERATION_MANAGED_FILE_COPY_FIELD_INVALID",`${u}/sourceFieldCodes/${h}`)});let g=`${p}:${N.join(",")}=>${f}:${C.join(",")}`;return d.has(g)&&l("NATIVE_OPERATION_MANAGED_FILE_COPY_DUPLICATE",u),d.add(g),{mode:"copy",sourceResourceCode:p,sourceFieldCodes:k(N),targetResourceCode:f,targetFieldCodes:k(C)}}),_=>`${_.sourceResourceCode}:${_.sourceFieldCodes.join(",")}=>${_.targetResourceCode}:${_.targetFieldCodes.join(",")}`)}if(s.notification!==void 0){let r=I(s.notification,`${t}/notification`);T(r,["mode"],`${t}/notification`),r.mode!=="business-standard"&&l("NATIVE_OPERATION_NOTIFICATION_MODE_INVALID",`${t}/notification/mode`),a.notification={mode:"business-standard"}}if(s.workflow!==void 0){let r=I(s.workflow,`${t}/workflow`);T(r,["codes"],`${t}/workflow`);let d=w(r.codes,`${t}/workflow/codes`,16);(!d.length||d.some(_=>!o.has(_)))&&l("NATIVE_OPERATION_WORKFLOW_CODE_INVALID",`${t}/workflow/codes`),a.workflow={codes:k(d)}}return a}function pi(e,t,n,o,i){if(e===void 0)return;let s=`${t}/ai`,a=I(e,s);ko.test(n)||l("NATIVE_OPERATION_AI_CODE_INVALID",`${t}/code`),T(a,["name","description","risk","resources","sideEffects","concurrency","timeoutMs"],s,!0),b(a.name,`${s}/name`,At),b(a.description,`${s}/description`,At);let r=b(a.risk,`${s}/risk`,16);["read","write","destructive","external"].includes(r)||l("NATIVE_OPERATION_AI_RISK_INVALID",`${s}/risk`),r==="read"!=(o==="GET")&&l("NATIVE_OPERATION_AI_METHOD_RISK_MISMATCH",`${s}/risk`),o==="DELETE"&&!["destructive","external"].includes(r)&&l("NATIVE_OPERATION_AI_METHOD_RISK_MISMATCH",`${s}/risk`);let d=w(a.resources,`${s}/resources`,16);d.length===0&&l("NATIVE_OPERATION_AI_RESOURCE_REQUIRED",`${s}/resources`),d.forEach((E,u)=>{let c=x(E,`${s}/resources/${u}`);i.has(c)||l("NATIVE_OPERATION_AI_RESOURCE_MISSING",`${s}/resources/${u}`)});let _=w(a.sideEffects,`${s}/sideEffects`,20);(r==="read"&&_.length!==0||r!=="read"&&_.length===0)&&l("NATIVE_OPERATION_AI_SIDE_EFFECT_INVALID",`${s}/sideEffects`),a.concurrency!==void 0&&!["none","revision"].includes(b(a.concurrency,`${s}/concurrency`,16))&&l("NATIVE_OPERATION_AI_CONCURRENCY_INVALID",`${s}/concurrency`),a.timeoutMs!==void 0&&z(a.timeoutMs,`${s}/timeoutMs`,100,3e4)}function Be(e){return(e.replace(/\/{2,}/g,"/").replace(/\/$/,"")||"/").split("/").map(n=>n.startsWith(":")?":":n.includes("*")?"*":n).join("/")}function Ai(e,t){let n=I(e,t),o=b(n.type,`${t}/type`,32),i=["code","type","label","presentation","required"],s=o==="sso"?[...i,"provider"]:o==="dingtalk"?[...i,"flow"]:i;T(n,s,t);let a=S(n.code,`${t}/code`),r=b(n.label,`${t}/label`,255),d=b(n.presentation,`${t}/presentation`,16);["primary","secondary"].includes(d)||l("NATIVE_APPLICATION_AUTH_METHOD_PRESENTATION_INVALID",`${t}/presentation`);let _=be(n.required,`${t}/required`);return["sso","password","dingtalk"].includes(o)||l("NATIVE_APPLICATION_AUTH_METHOD_TYPE_INVALID",`${t}/type`),o==="sso"&&n.provider!=="tenant-default"&&l("NATIVE_APPLICATION_AUTH_SSO_PROVIDER_INVALID",`${t}/provider`),o==="dingtalk"&&!["auto","jsapi","oauth"].includes(b(n.flow,`${t}/flow`,16))&&l("NATIVE_APPLICATION_AUTH_DINGTALK_FLOW_INVALID",`${t}/flow`),{code:a,type:o,label:r,presentation:d,required:_,...o==="sso"?{provider:"tenant-default"}:{},...o==="dingtalk"?{flow:n.flow}:{}}}function sn(e,t,n){let o=I(e,n);T(o,["routeCode","path","defaultRouteCode"],n);let i=S(o.routeCode,`${n}/routeCode`),s=ee(o.path,`${n}/path`),a=t==="desktop"?"/login":"/m/login";return(s!==a||/[:*?#\\]/.test(s))&&l("NATIVE_APPLICATION_AUTH_SURFACE_PATH_INVALID",`${n}/path`,{device:t,expectedPath:a}),{routeCode:i,path:s,defaultRouteCode:S(o.defaultRouteCode,`${n}/defaultRouteCode`)}}function Cn(e,t,n,o){if(e===null)return;let i=I(e,o);T(i,["accountMode","registration","methods","surfaces"],o),F(i.accountMode,"existing-platform-users-only",`${o}/accountMode`);let s=I(i.registration,`${o}/registration`);T(s,["mode"],`${o}/registration`),F(s.mode,"reject",`${o}/registration/mode`);let a=$(i.methods,`${o}/methods`,8);a.length===0&&l("NATIVE_APPLICATION_AUTH_METHOD_REQUIRED",`${o}/methods`);let r=a.map((m,N)=>Ai(m,`${o}/methods/${N}`)),d=new Set,_=new Set;for(let[m,N]of r.entries())d.has(N.code)&&l("NATIVE_APPLICATION_AUTH_METHOD_CODE_DUPLICATE",`${o}/methods/${m}/code`),_.has(N.type)&&l("NATIVE_APPLICATION_AUTH_METHOD_TYPE_DUPLICATE",`${o}/methods/${m}/type`),d.add(N.code),_.add(N.type);r.filter(m=>m.presentation==="primary").length!==1&&l("NATIVE_APPLICATION_AUTH_PRIMARY_METHOD_INVALID",`${o}/methods`);let E=I(i.surfaces,`${o}/surfaces`);T(E,["desktop","mobile"],`${o}/surfaces`);let u=sn(E.desktop,"desktop",`${o}/surfaces/desktop`),c=sn(E.mobile,"mobile",`${o}/surfaces/mobile`);u.routeCode===c.routeCode&&l("NATIVE_APPLICATION_AUTH_SURFACE_CODE_DUPLICATE",`${o}/surfaces/mobile/routeCode`);let p=$(t,"/config/frontend/routes",500),f=new Map;for(let[m,N]of p.entries()){let C=I(N,`/config/frontend/routes/${m}`);f.set(String(C.code||""),C)}for(let[m,N]of[["desktop",u],["mobile",c]]){f.has(N.routeCode)&&l("NATIVE_APPLICATION_AUTH_SURFACE_CODE_CONFLICT",`${o}/surfaces/${m}/routeCode`);let C=f.get(N.defaultRouteCode),g=String(C?.path||""),D=m==="desktop"?g==="/m"||g.startsWith("/m/"):!(g==="/m"||g.startsWith("/m/"));(!C||C.surface!=="user"||/[:*]/.test(g)||D)&&l("NATIVE_APPLICATION_AUTH_DEFAULT_ROUTE_INVALID",`${o}/surfaces/${m}/defaultRouteCode`)}let A=On(n).filter(m=>!m.owner.startsWith("authentication:"));for(let[m,N]of[["desktop",u],["mobile",c]]){let C=A.find(g=>Be(g.path)===Be(N.path));C&&l("NATIVE_APPLICATION_AUTH_SURFACE_PATH_CONFLICT",`${o}/surfaces/${m}/path`,{owner:C.owner})}}function Ii(e,t){if(e===null)return;let n={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}},o=I(e,t),i=I(o.surfaces,`${t}/surfaces`),s={...o,surfaces:{...i,desktop:{...I(i.desktop,`${t}/surfaces/desktop`),defaultRouteCode:"auth-desktop-default"},mobile:{...I(i.mobile,`${t}/surfaces/mobile`),defaultRouteCode:"auth-mobile-default"}}};Cn(s,n.frontend.routes,{...n,frontend:{...n.frontend,authentication:s}},t)}function mi(e){let t=e.frontend.authentication;return t===null?null:{accountMode:t.accountMode,registration:{mode:t.registration.mode},methods:t.methods.map(n=>({...n})),surfaces:{desktop:{...t.surfaces.desktop},mobile:{...t.surfaces.mobile}}}}var Ni=new Set(["draft.read","draft.update","validate","create","own.list","own.read"]);function Ti(e,t,n){let o=I(e,n);T(o,["policies"],n);let i=$(o.policies,`${n}/policies`,16);i.length<1&&l("NATIVE_PUBLIC_POLICY_REQUIRED",n);let s=new Map(t.frontend.routes.map(_=>[_.code,_])),a=new Map(t.data.resources.map(_=>[_.code,_])),r=new Set,d=new Set;i.forEach((_,E)=>{let u=`${n}/policies/${E}`,c=I(_,u);T(c,["code","routeCode","mode","resourceCode","operations","fields"],u,["requiredFields","ownRecordFields","draft","validations"]);let p=S(c.code,`${u}/code`);r.has(p)&&l("NATIVE_PUBLIC_POLICY_DUPLICATE",`${u}/code`);let f=S(c.routeCode,`${u}/routeCode`);d.has(f)&&l("NATIVE_PUBLIC_ROUTE_DUPLICATE",`${u}/routeCode`);let A=s.get(f);(!A||A.surface!=="user"||A.capability!==void 0||A.access!==void 0||/[:*]/.test(String(A.path)))&&l("NATIVE_PUBLIC_ROUTE_INVALID",`${u}/routeCode`),F(c.mode,"anonymous",`${u}/mode`);let m=x(c.resourceCode,`${u}/resourceCode`),N=a.get(m);N||l("NATIVE_PUBLIC_RESOURCE_MISSING",`${u}/resourceCode`);let C=new Map(N.schema.fields.map(P=>[String(P.code),String(P.type)])),g=w(c.operations,`${u}/operations`,6);(g.length<1||g.some(P=>!Ni.has(P)))&&l("NATIVE_PUBLIC_OPERATION_INVALID",`${u}/operations`),g.includes("draft.read")!==g.includes("draft.update")&&l("NATIVE_PUBLIC_DRAFT_OPERATION_INCOMPLETE",`${u}/operations`);let D=w(c.fields,`${u}/fields`,64);(D.length<1||D.some(P=>!C.has(P)))&&l("NATIVE_PUBLIC_FIELD_INVALID",`${u}/fields`);for(let P of["requiredFields","ownRecordFields"]){if(!Object.prototype.hasOwnProperty.call(c,P))continue;w(c[P],`${u}/${P}`,64).some(G=>!D.includes(G))&&l("NATIVE_PUBLIC_FIELD_SCOPE_INVALID",`${u}/${P}`)}let h=Object.prototype.hasOwnProperty.call(c,"requiredFields")?w(c.requiredFields,`${u}/requiredFields`,64):[],R=N.surface||{},v=R.fields||{},V=String(R.mutationOwner||"native")==="native"&&R.generated?.create!==!1,L=N.schema.fields.filter(P=>Me(P,v[P.code])).map(P=>String(P.code));if(g.includes("create")&&!V&&l("NATIVE_PUBLIC_CREATE_FIELDS_INCOMPLETE",`${u}/fields`),g.includes("create"))for(let P of L){let Q=D.includes(P)?h.includes(P)?null:"requiredFields":"fields";Q&&l("NATIVE_PUBLIC_CREATE_FIELDS_INCOMPLETE",`${u}/${Q}`,{resourceCode:x,fieldCode:P})}if(Object.prototype.hasOwnProperty.call(c,"draft")){let P=I(c.draft,`${u}/draft`);T(P,["enabled","inactivityTtlSeconds","maxBytes"],`${u}/draft`),F(P.enabled,!0,`${u}/draft/enabled`),z(P.inactivityTtlSeconds,`${u}/draft/inactivityTtlSeconds`,3600,7776e3),z(P.maxBytes,`${u}/draft/maxBytes`,4096,262144)}else g.includes("draft.read")&&l("NATIVE_PUBLIC_DRAFT_REQUIRED",`${u}/draft`);let M=Object.prototype.hasOwnProperty.call(c,"validations")?$(c.validations,`${u}/validations`,16):[],K=new Set;M.forEach((P,Q)=>{let G=`${u}/validations/${Q}`,U=I(P,G);T(U,["code","kind","fields","result"],G);let Ee=S(U.code,`${G}/code`);K.has(Ee)&&l("NATIVE_PUBLIC_VALIDATION_DUPLICATE",`${G}/code`),F(U.kind,"duplicate",`${G}/kind`),F(U.result,"availability",`${G}/result`);let re=w(U.fields,`${G}/fields`,8);(re.length<1||re.some(ae=>!D.includes(ae))||re.some(ae=>["file","subtable"].includes(C.get(ae)||"")))&&l("NATIVE_PUBLIC_VALIDATION_FIELD_INVALID",`${G}/fields`),K.add(Ee)}),r.add(p),d.add(f)})}function gi(e,t){let n=I(e,t);T(n,["policies"],t),$(n.policies,`${t}/policies`,16).length<1&&l("NATIVE_PUBLIC_POLICY_REQUIRED",t)}function Ci(e){return{policies:q(e.frontend.publicAccess.policies.map(t=>({code:t.code,routeCode:t.routeCode,mode:t.mode,resourceCode:t.resourceCode,operations:k(t.operations),fields:k(t.fields),...t.requiredFields?{requiredFields:k(t.requiredFields)}:{},...t.ownRecordFields?{ownRecordFields:k(t.ownRecordFields)}:{},...t.draft?{draft:{...t.draft}}:{},...t.validations?{validations:q(t.validations.map(n=>({code:n.code,kind:n.kind,fields:k(n.fields),result:n.result})),n=>n.code)}:{}})),t=>t.code)}}function On(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 n of e.data.resources){let o=bn(n),i=`/admin/resources/${n.code}`,s=[["list",i],["detail",`${i}/:id`],["create",`${i}/new`],["update",`${i}/:id/edit`]];for(let[a,r]of s)o[a]&&t.push({owner:`resource:${n.code}:${a}`,path:r},{owner:`resource:${n.code}:${a}:mobile`,path:`/m${r}`})}if(e.frontend.user.applicationTodoCenter===!0&&t.push({owner:"application:todo-center",path:"/todos"},{owner:"application:todo-center:mobile",path:"/m/todos"}),e.workflows.definitions.length>0){t.push({owner:"workflow:work-center",path:"/work-center"},{owner:"workflow:work-center:mobile",path:"/m/work-center"},{owner:"workflow:task",path:"/tasks/:taskId"},{owner:"workflow:task:mobile",path:"/m/tasks/:taskId"},{owner:"workflow:instance",path:"/workflows/:instanceId"},{owner:"workflow:instance:mobile",path:"/m/workflows/:instanceId"});let n=!1;for(let o of e.workflows.definitions)["standalone","hidden-handoff"].includes(o.launch.mode)&&(n=!0);n&&t.push({owner:"workflow:launch",path:"/workflows/:workflowCode/start"},{owner:"workflow:launch:mobile",path:"/m/workflows/:workflowCode/start"})}return t}function ze(e){let t=new Map(On(e).map(n=>[Be(n.path),n]));return q(e.frontend.routes.map((n,o)=>{let i=`/config/frontend/routes/${o}`,s=I(n,i);T(s,["code","path","label","surface","parentCode","capability","access","pinned","tabPersistence","keepAlive"],i,!0),["admin","user"].includes(s.surface)||l("NATIVE_ROUTE_SURFACE_INVALID",`${i}/surface`);let a=ee(s.path,`${i}/path`);s.surface==="admin"&&a!=="/admin"&&!a.startsWith("/admin/")&&l("NATIVE_ADMIN_ROUTE_PATH_INVALID",`${i}/path`),s.surface==="user"&&(a==="/admin"||a.startsWith("/admin/"))&&l("NATIVE_USER_ROUTE_PATH_RESERVED",`${i}/path`);let r=Be(a),d=t.get(r);d&&l("NATIVE_ROUTE_PATH_CONFLICT",`${i}/path`,{path:a,owner:d.owner}),t.set(r,{owner:`frontend:${String(s.code||o)}`,path:a});let _=/[:*]/.test(a),E=Ot(s,i,e.appCode),u=s.pinned===void 0?void 0:be(s.pinned,`${i}/pinned`),c=s.tabPersistence===void 0?_?"none":"session":b(s.tabPersistence,`${i}/tabPersistence`,16),p=s.keepAlive===void 0?"none":b(s.keepAlive,`${i}/keepAlive`,16);return["session","none"].includes(c)||l("NATIVE_ROUTE_TAB_PERSISTENCE_INVALID",`${i}/tabPersistence`),["none","memory"].includes(p)||l("NATIVE_ROUTE_KEEP_ALIVE_INVALID",`${i}/keepAlive`),_&&u===!0&&l("NATIVE_DYNAMIC_ROUTE_PINNED_FORBIDDEN",`${i}/pinned`),_&&c==="session"&&l("NATIVE_DYNAMIC_ROUTE_TAB_PERSISTENCE_FORBIDDEN",`${i}/tabPersistence`),_&&p==="memory"&&l("NATIVE_DYNAMIC_ROUTE_KEEP_ALIVE_FORBIDDEN",`${i}/keepAlive`),{code:S(s.code,`${i}/code`),path:a,label:b(s.label,`${i}/label`,255),surface:s.surface,...s.parentCode===void 0?{}:{parentCode:S(s.parentCode,`${i}/parentCode`)},...E,...u===void 0?{}:{pinned:u},tabPersistence:c,keepAlive:p}}),n=>n.code)}function bn(e){let t=e.surface===void 0?{}:I(e.surface,"/surface"),n=t.mutationOwner||"native",o=t.generated===void 0?{}:I(t.generated,"/surface/generated"),i=n==="native";return{list:o.list??!0,detail:o.detail??!0,create:o.create??i,update:o.update??i,delete:o.delete??i}}function $n(e){let t=[];for(let n of q(e.data.resources,o=>o.code).flatMap(o=>[{resource:o,viewCode:void 0},...(o.surface?.views||[]).map(i=>({viewCode:i.code,resource:{...o,name:i.name,surface:lt(o.surface,i.code)}}))])){let{resource:o,viewCode:i}=n,s=`/admin/resources/${o.code}${i?`/views/${i}`:""}`,a=bn(o),r=[{operation:"list",kind:"resource-list",path:`${s}`,label:o.name,capability:o.capabilities.read,navigationEligible:!0},{operation:"detail",kind:"resource-detail",path:`${s}/:id`,label:`${o.name}\u8BE6\u60C5`,capability:o.capabilities.read,navigationEligible:!1},{operation:"create",kind:"resource-create",path:`${s}/new`,label:`\u65B0\u589E${o.name}`,capability:o.capabilities.create,navigationEligible:!1},{operation:"update",kind:"resource-update",path:`${s}/:id/edit`,label:`\u7F16\u8F91${o.name}`,capability:o.capabilities.update,navigationEligible:!1}];for(let d of r)a[d.operation]&&t.push({code:`resource:${o.code}${i?`:view:${i}`:""}:${d.operation}`,kind:d.kind,path:d.path,label:d.label,navigationEligible:d.navigationEligible,capability:d.capability,resourceCode:o.code,...i?{viewCode:i}:{}})}for(let n of ze(e))n.surface==="admin"&&t.push({code:`operation:${n.code}`,kind:"operation",path:n.path,label:n.label,navigationEligible:!/[:*]/.test(n.path),routeCode:n.code});return t.sort((n,o)=>se(n.code,o.code))}function hn(e){return e.kind==="resource"?`resource:${e.resourceCode}${e.viewCode?`:view:${e.viewCode}`:""}:list`:`operation:${e.routeCode}`}function Oi(e){return e.frontend.admin.navigation.map((t,n)=>({code:t.code,label:t.label,...t.icon===void 0?{}:{icon:t.icon},order:t.order??n,items:t.items.map((o,i)=>({pageCode:hn(o.page),...o.label===void 0?{}:{label:o.label},...o.icon===void 0?{}:{icon:o.icon},order:o.order??i})).sort((o,i)=>o.order-i.order||se(o.pageCode,i.pageCode))})).sort((t,n)=>t.order-n.order||se(t.code,n.code))}function bi(e,t){let n=$(e,t,B.adminNavigationGroups),o=0;n.forEach((i,s)=>{let a=`${t}/${s}`,r=I(i,a);T(r,["code","label","icon","order","items"],a,!0),S(r.code,`${a}/code`),b(r.label,`${a}/label`,255),Je(r.icon,`${a}/icon`),ln(r.order,`${a}/order`);let d=$(r.items,`${a}/items`,500);d.length===0&&l("NATIVE_ADMIN_GROUP_ORPHANED",`${a}/items`),o+=d.length,o>B.adminNavigationItems&&l("NATIVE_ARRAY_LIMIT_EXCEEDED",t),d.forEach((_,E)=>{let u=`${a}/items/${E}`,c=I(_,u);T(c,["page","label","icon","order"],u,!0),$i(c.page,`${u}/page`),c.label!==void 0&&b(c.label,`${u}/label`,255),Je(c.icon,`${u}/icon`),ln(c.order,`${u}/order`)})})}function $i(e,t){let n=I(e,t),o=b(n.kind,`${t}/kind`,64);if(o==="resource"){T(n,["kind","resourceCode"],t,["viewCode"]),n.viewCode!==void 0&&S(n.viewCode,`${t}/viewCode`),x(n.resourceCode,`${t}/resourceCode`);return}if(o==="operation"){T(n,["kind","routeCode"],t),S(n.routeCode,`${t}/routeCode`);return}l("NATIVE_ADMIN_PAGE_REFERENCE_KIND_INVALID",`${t}/kind`)}function hi(e){let t=new Map($n(e).map(i=>[String(i.code),i])),n=new Set,o=new Set;e.frontend.admin.navigation.forEach((i,s)=>{let a=`/config/frontend/admin/navigation/${s}`;n.has(i.code)&&l("NATIVE_ADMIN_GROUP_DUPLICATE",`${a}/code`),n.add(i.code),i.label===i.code&&l("NATIVE_ADMIN_USER_LABEL_REQUIRED",`${a}/label`),i.items.forEach((r,d)=>{let _=`${a}/items/${d}`,E=hn(r.page),u=t.get(E);(!u||u.navigationEligible!==!0)&&l("NATIVE_ADMIN_PAGE_NOT_FOUND",`${_}/page`),o.has(E)&&l("NATIVE_ADMIN_PAGE_DUPLICATE",`${_}/page`),o.add(E);let c=r.page.resourceCode||r.page.routeCode||r.page.workflowCode||E,p=r.label||u.label;(!p||p===c||p===E)&&l("NATIVE_ADMIN_USER_LABEL_REQUIRED",`${_}/label`)})})}function Ri(e,t){let n=$(e,t,B.adminPages),o=new Set;n.forEach((i,s)=>{let a=`${t}/${s}`,r=I(i,a);T(r,["code","kind","path","label","navigationEligible","capability","access","resourceCode","viewCode","routeCode"],a,!0);let d=b(r.code,`${a}/code`,255);o.has(d)&&l("NATIVE_ADMIN_PAGE_DUPLICATE",`${a}/code`),o.add(d);let _=b(r.kind,`${a}/kind`,64);if(["resource-list","resource-detail","resource-create","resource-update","operation"].includes(_)||l("NATIVE_ADMIN_PAGE_KIND_INVALID",`${a}/kind`),ee(r.path,`${a}/path`),b(r.label,`${a}/label`,255),be(r.navigationEligible,`${a}/navigationEligible`),r.capability!==void 0&&r.access!==void 0&&l("NATIVE_ROUTE_ACCESS_CONFLICT",`${a}/access`),r.capability!==void 0&&b(r.capability,`${a}/capability`,255),r.access!==void 0){let E=I(r.access,`${a}/access`);T(E,["allOf","anyOf"],`${a}/access`,!0);for(let u of["allOf","anyOf"])E[u]!==void 0&&w(E[u],`${a}/access/${u}`,50)}for(let E of["resourceCode","viewCode","routeCode"])r[E]!==void 0&&S(r[E],`${a}/${E}`)})}function Di(e,t){let n=$(e,t,B.adminNavigationGroups),o=0;n.forEach((i,s)=>{let a=`${t}/${s}`,r=I(i,a);T(r,["code","label","icon","order","items"],a,!0),S(r.code,`${a}/code`),b(r.label,`${a}/label`,255),Je(r.icon,`${a}/icon`),z(r.order,`${a}/order`,-1e4,1e4);let d=$(r.items,`${a}/items`,500);d.length===0&&l("NATIVE_ADMIN_GROUP_ORPHANED",`${a}/items`),o+=d.length,o>B.adminNavigationItems&&l("NATIVE_ARRAY_LIMIT_EXCEEDED",t),d.forEach((_,E)=>{let u=`${a}/items/${E}`,c=I(_,u);T(c,["pageCode","label","icon","order"],u,!0),b(c.pageCode,`${u}/pageCode`,255),c.label!==void 0&&b(c.label,`${u}/label`,255),Je(c.icon,`${u}/icon`),z(c.order,`${u}/order`,-1e4,1e4)})})}var Si=new Set(["application-todo-center","workflow-work-center","workflow-launch","workflow-task","workflow-instance"]);function Vi(e,t,n){let o=I(e,t);T(o,["schemaVersion","appCode","devicePolicy","rootEntry","authentication","routes","digest"],t),F(o.schemaVersion,Tn,`${t}/schemaVersion`),F(o.appCode,n,`${t}/appCode`),Ct(o.devicePolicy,`${t}/devicePolicy`),yi(o.rootEntry,`${t}/rootEntry`),wi(o.authentication,`${t}/authentication`),Tt(o.digest,`${t}/digest`);let i=$(o.routes,`${t}/routes`,B.routes),s=new Set;i.forEach((a,r)=>{let d=`${t}/routes/${r}`,_=I(a,d);T(_,["code","kind","desktop","mobile"],d,["workflowCode"]);let E=b(_.code,`${d}/code`,255);s.has(E)&&l("NATIVE_ROUTE_MANIFEST_DUPLICATE",`${d}/code`),s.add(E);let u=b(_.kind,`${d}/kind`,64);Si.has(u)||l("NATIVE_ROUTE_MANIFEST_KIND_INVALID",`${d}/kind`),_.workflowCode!==void 0&&S(_.workflowCode,`${d}/workflowCode`);let c=an(_.desktop,`${d}/desktop`,n),p=an(_.mobile,`${d}/mobile`,n);c.surface!=="user"&&l("NATIVE_ROUTE_MANIFEST_DESKTOP_SURFACE_INVALID",`${d}/desktop/surface`),p.surface!=="user"&&l("NATIVE_ROUTE_MANIFEST_MOBILE_SURFACE_INVALID",`${d}/mobile/surface`),c.routeCode===p.routeCode&&l("NATIVE_ROUTE_MANIFEST_PAIR_DUPLICATE",d)}),F(o.digest,Z({schemaVersion:o.schemaVersion,appCode:o.appCode,devicePolicy:o.devicePolicy,rootEntry:o.rootEntry,authentication:o.authentication,routes:o.routes}),`${t}/digest`)}function Ct(e,t){let n=I(e,t);T(n,["kind","mobileMaxWidthPx","desktopMinWidthPx"],t),F(n.kind,"viewport-family",`${t}/kind`);let o=z(n.mobileMaxWidthPx,`${t}/mobileMaxWidthPx`,320,1600),i=z(n.desktopMinWidthPx,`${t}/desktopMinWidthPx`,320,1600);return i!==o+1&&l("NATIVE_FRONTEND_DEVICE_POLICY_INVALID",t),{kind:"viewport-family",mobileMaxWidthPx:o,desktopMinWidthPx:i}}function yi(e,t){let n=I(e,t);T(n,["code","desktop","mobile"],t);let o=S(n.code,`${t}/code`),i=Nt(n.desktop,`${t}/desktop`),s=Nt(n.mobile,`${t}/mobile`);return(i===s||s==="/"||!s.startsWith("/m/"))&&l("NATIVE_ROUTE_MANIFEST_ROOT_ENTRY_INVALID",t),i.startsWith("/m/")&&l("NATIVE_ROUTE_MANIFEST_ROOT_ENTRY_INVALID",`${t}/desktop`),{code:o,desktop:i,mobile:s}}function wi(e,t){let n=I(e,t);T(n,["desktop","mobile"],t);let o=rn(n.desktop,`${t}/desktop`,!1),i=rn(n.mobile,`${t}/mobile`,!0);return(o.routeCode===i.routeCode||o.path===i.path)&&l("NATIVE_ROUTE_MANIFEST_AUTHENTICATION_DUPLICATE",t),{desktop:o,mobile:i}}function rn(e,t,n){let o=I(e,t);T(o,["routeCode","path"],t);let i=S(o.routeCode,`${t}/routeCode`),s=Nt(o.path,`${t}/path`);return(n?!s.startsWith("/m/"):s.startsWith("/m/"))&&l("NATIVE_ROUTE_MANIFEST_AUTHENTICATION_PATH_INVALID",`${t}/path`),{routeCode:i,path:s}}function Nt(e,t){let n=ee(e,t);return/[:*?#\\\\]/.test(n)&&l("NATIVE_ROUTE_MANIFEST_STATIC_PATH_INVALID",t),n}function an(e,t,n){let o=I(e,t);T(o,["routeCode","path","surface","pathParams","requiresAuthentication"],t,["capability","access"]),S(o.routeCode,`${t}/routeCode`);let i=ee(o.path,`${t}/path`),s=b(o.surface,`${t}/surface`,16);["admin","user"].includes(s)||l("NATIVE_ROUTE_SURFACE_INVALID",`${t}/surface`);let a=w(o.pathParams,`${t}/pathParams`,8);return a.forEach((r,d)=>{(!/^[A-Za-z][A-Za-z0-9_]*$/.test(r)||r.length>64)&&l("NATIVE_ROUTE_PATH_PARAM_INVALID",`${t}/pathParams/${d}`)}),W(a)!==W(Rn(i))&&l("NATIVE_ROUTE_PATH_PARAMS_MISMATCH",`${t}/pathParams`),Ot(o,t,n),o.requiresAuthentication!==!0&&l("NATIVE_ROUTE_AUTHENTICATION_REQUIRED",`${t}/requiresAuthentication`),o}function Rn(e){return k([...e.matchAll(/:([A-Za-z][A-Za-z0-9_]*)/g)].map(t=>t[1]))}function cn(e,t,n,o){return{routeCode:e,path:t,surface:n,pathParams:Rn(t),...o?.capability?{capability:o.capability}:{},...o?.access?{access:o.access}:{},requiresAuthentication:!0}}function dn(e,t,n){return e==="workflow-launch"?`workflow.${n}.launch.${t}`:e==="application-todo-center"?`application.todo-center.${t}`:`${e.replace(/-/g,".")}.${t}`}function Pi(e){let t=e.appCode,n=[],o=(p,f,A,m,N,C)=>{n.push({code:p,kind:f,...N?{workflowCode:N}:{},desktop:cn(dn(f,"desktop",N),A,"user",C),mobile:cn(dn(f,"mobile",N),m,"user",C)})};e.frontend.user.applicationTodoCenter===!0&&o("application:todo-center","application-todo-center","/todos","/m/todos");let i=Dn(e);i.length>0&&(o("workflow:work-center","workflow-work-center","/work-center","/m/work-center"),o("workflow:task","workflow-task","/tasks/:taskId","/m/tasks/:taskId"),o("workflow:instance","workflow-instance","/workflows/:instanceId","/m/workflows/:instanceId"));for(let p of i){if(!["standalone","hidden-handoff"].includes(p.launch.mode))continue;let f=k([p.launch.submission?.create?.requiredCapability,p.launch.submission?.existing?.requiredCapability].filter(A=>!!A));o(`workflow:${p.code}:launch`,"workflow-launch","/workflows/:workflowCode/start","/m/workflows/:workflowCode/start",p.code,f.length===1?{capability:f[0]}:f.length>1?{access:{anyOf:f}}:void 0)}let s=n.sort((p,f)=>se(String(p.code),String(f.code))),a=ze(e),r=p=>{let f=p==="mobile"?"/m/":"/",A=a.filter(N=>N.surface==="user"&&!/[:*?#\\\\]/.test(N.path)&&N.path===f).sort((N,C)=>se(N.code,C.code))[0];if(A)return{code:A.code,path:A.path};let m=a.filter(N=>N.surface==="user"&&!/[:*?#\\\\]/.test(N.path)&&(p==="mobile"?N.path.startsWith("/m/"):!N.path.startsWith("/m/"))).sort((N,C)=>se(N.code,C.code))[0];return m?{code:m.code,path:m.path}:{code:p==="mobile"?"application-root-mobile":"application-root",path:f}},d=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"}},_=Ct(e.frontend.devicePolicy,"/config/frontend/devicePolicy"),E=r("desktop"),u=r("mobile"),c={schemaVersion:Tn,appCode:t,devicePolicy:_,rootEntry:{code:E.code,desktop:E.path,mobile:u.path},authentication:d,routes:s};return{...c,digest:Z(c)}}function Je(e,t){if(e===void 0)return;let n=b(e,t,32);Ho.has(n)||l("NATIVE_ADMIN_ICON_INVALID",t)}function ln(e,t){e!==void 0&&z(e,t,-1e4,1e4)}function Ot(e,t,n){return e.capability!==void 0&&e.access!==void 0&&l("NATIVE_ROUTE_ACCESS_CONFLICT",`${t}/access`),e.capability!==void 0?{capability:_e(e.capability,`${t}/capability`,n)}:e.access===void 0?{}:{access:Ye(e.access,`${t}/access`,n)}}function Ye(e,t,n){let o=I(e,t);T(o,["allOf","anyOf"],t,!0);let i=o.allOf===void 0?void 0:k(w(o.allOf,`${t}/allOf`,50).map((a,r)=>_e(a,`${t}/allOf/${r}`,n))),s=o.anyOf===void 0?void 0:k(w(o.anyOf,`${t}/anyOf`,50).map((a,r)=>_e(a,`${t}/anyOf/${r}`,n)));return(i?.length||0)+(s?.length||0)===0&&l("NATIVE_ROUTE_ACCESS_EMPTY",t),{...i===void 0?{}:{allOf:i},...s===void 0?{}:{anyOf:s}}}function Dn(e){let t=new Map(gn(e).map(i=>[String(i.code),i])),n=e.workflows.definitions.map((i,s)=>{let a=`/config/workflows/definitions/${s}`,r=I(i,a);T(r,["version","definition","launch"],a,["detailRouteCode"]);let d=I(r.definition,`${a}/definition`),_=r.detailRouteCode===void 0?void 0:Vn(r.detailRouteCode,`${a}/detailRouteCode`);return{code:S(d.code,`${a}/definition/code`),title:b(d.title,`${a}/definition/title`,255),version:Oe(r.version,`${a}/version`),launch:Fi(e,d,r.launch,`${a}/launch`,t),..._?{detailRouteCode:_}:{},definition:d}});return k(n.map(i=>i.code)).map(i=>{let s=n.filter(_=>_.code===i),a=e.workflows.activations.find(_=>_.workflowCode===i)?.definitionVersion,r=s.find(_=>_.version===a)||[...s].sort((_,E)=>E.version-_.version)[0],d=new Set;for(let _ of s){let E=I(_.definition.nodes,"/config/workflows/definitions/nodes");for(let u of Object.values(E)){let c=I(u,"/config/workflows/definitions/nodes/*");if(c.kind==="approval")for(let p of w(c.allowedOperations||[],"/config/workflows/definitions/nodes/*/allowedOperations",20))d.add(p)}}return{code:i,title:r.title,acceptedCommandDeactivationPolicy:r.definition.acceptedCommandDeactivationPolicy,subject:r.definition.subject,launch:r.launch,...["standalone","hidden-handoff"].includes(r.launch.mode)&&!r.launch.submission?{processOperationCode:`openxiangda.workflow.${i}.submit`}:{},...r.detailRouteCode?{detailRouteCode:r.detailRouteCode}:{},definitionVersions:mn(s.map(_=>_.version)),bindingVersions:mn(e.workflows.bindings.map((_,E)=>{let u=`/config/workflows/bindings/${E}`,c=I(_,u),p=I(c.binding,`${u}/binding`);return{code:S(p.workflowCode,`${u}/binding/workflowCode`),version:Oe(c.version,`${u}/version`)}}).filter(_=>_.code===i).map(_=>_.version)),providerCodes:k(e.workflows.providers.map((_,E)=>S(I(_,`/config/workflows/providers/${E}`).code,`/config/workflows/providers/${E}/code`))),allowedOperations:[...d].sort(se),editableParameterCodes:k(e.workflows.editableParameters.map((_,E)=>{let u=`/config/workflows/editableParameters/${E}`,c=I(_,u);return{code:S(c.code,`${u}/code`),workflowCode:S(c.workflowCode,`${u}/workflowCode`)}}).filter(_=>_.workflowCode===i).map(_=>_.code))}})}function Sn(e,t){let n=I(e,t);T(n,["mode"],t,["submission"]);let o=b(n.mode,`${t}/mode`,32);return["standalone","custom-page","hidden-handoff","work-center-only"].includes(o)||l("NATIVE_WORKFLOW_LAUNCH_MODE_INVALID",`${t}/mode`),{mode:o,...n.submission===void 0?{}:{submission:I(n.submission,`${t}/submission`)}}}function Fi(e,t,n,o,i){let s=Sn(n,o);if(!s.submission)return{mode:s.mode};["standalone","hidden-handoff"].includes(s.mode)||l("NATIVE_WORKFLOW_NAMED_OPERATION_SUBMISSION_INVALID",`${o}/submission`);let a=I(s.submission,`${o}/submission`);T(a,["kind"],`${o}/submission`,["create","existing","context"]),F(a.kind,"named-operation",`${o}/submission/kind`);let r=o.endsWith("/launch")?o.slice(0,-7):o,d=I(t.subject,`${r}/definition/subject`),_=x(d.resourceCode,`${r}/definition/subject/resourceCode`),E=e.data.resources.findIndex(R=>R.code===_),u=e.data.resources[E];(E<0||!u)&&l("NATIVE_WORKFLOW_SUBJECT_RESOURCE_MISSING",`${r}/definition/subject/resourceCode`);let c=new Set(I(u.schema,`/config/data/resources/${E}/schema`).fields.map(R=>String(R.code))),p=new Map(e.backend.operations.map(R=>[String(R.code),R])),f=(R,v)=>{let V=`${o}/submission/${v}`,L=I(R,V);T(L,["operationCode","inputs","output"],V);let M=S(L.operationCode,`${V}/operationCode`),K=p.get(M),P=i.get(M),Q=P?.platformAccess?.workflow?.codes;(!K||!P||P.method!=="POST"||!Array.isArray(Q)||!Q.includes(t.code))&&l("NATIVE_WORKFLOW_NAMED_OPERATION_INVALID",V);let G=I(K.requestSchema,`${V}/operation/requestSchema`),U=I(G.properties,`${V}/operation/requestSchema/properties`),Ee=new Set(G.required===void 0?[]:w(G.required,`${V}/operation/requestSchema/required`,64)),re=I(L.inputs,`${V}/inputs`),ae=Object.entries(re);(!ae.length||ae.length>64)&&l("NATIVE_WORKFLOW_NAMED_OPERATION_INPUT_INVALID",`${V}/inputs`);let Ke=new Set,pe=new Map,qe={};for(let[j,Ie]of ae){(!tn.test(j)||!Object.prototype.hasOwnProperty.call(U,j))&&l("NATIVE_WORKFLOW_NAMED_OPERATION_INPUT_INVALID",`${V}/inputs/${j}`);let me=`${V}/inputs/${j}`,Xe=I(Ie,me),Ae=b(Xe.source,`${me}/source`,32);if(["field","idempotency-key","current-user-reference","subject-id","subject-revision","requested-at"].includes(Ae)||l("NATIVE_WORKFLOW_NAMED_OPERATION_INPUT_INVALID",me),T(Xe,["source"],me,Ae==="field"?["fieldCode"]:!1),pe.set(Ae,(pe.get(Ae)||0)+1),Ae==="field"){let Fe=J(Xe.fieldCode,`${me}/fieldCode`);(Ke.has(Fe)||!c.has(Fe))&&l("NATIVE_WORKFLOW_NAMED_OPERATION_INPUT_INVALID",`${me}/fieldCode`),Ke.add(Fe),qe[j]={source:Ae,fieldCode:Fe}}else qe[j]={source:Ae}}([...Ee].some(j=>!(j in re))||(pe.get("idempotency-key")||0)!==1||!ae.some(([j,Ie])=>I(Ie,`${V}/inputs/${j}`).source==="idempotency-key"&&Ee.has(j))||v==="create"&&((pe.get("subject-id")||0)>0||(pe.get("subject-revision")||0)>0)||v==="existing"&&((pe.get("subject-id")||0)!==1||(pe.get("subject-revision")||0)!==1))&&l("NATIVE_WORKFLOW_NAMED_OPERATION_INPUT_INVALID",`${V}/inputs`);let Pe=I(L.output,`${V}/output`);T(Pe,["subjectId"],`${V}/output`,["subjectRevision","processCommand"]);let Pn=I(I(K.responseSchema,`${V}/operation/responseSchema`).properties,`${V}/operation/responseSchema/properties`);for(let j of["subjectId","subjectRevision","processCommand"]){if(Pe[j]===void 0)continue;let Ie=b(Pe[j],`${V}/output/${j}`,128);(!tn.test(Ie)||!Object.prototype.hasOwnProperty.call(Pn,Ie))&&l("NATIVE_WORKFLOW_NAMED_OPERATION_OUTPUT_INVALID",`${V}/output/${j}`)}return{operationCode:M,method:"POST",path:P.path,requiredCapability:P.requiredCapability,requestSchemaDigest:P.requestSchemaDigest,responseSchemaDigest:P.responseSchemaDigest,inputs:qe,output:{...Pe},fieldCodes:Ke}},A=a.create===void 0?void 0:f(a.create,"create"),m=a.existing===void 0?void 0:f(a.existing,"existing");!A&&!m&&l("NATIVE_WORKFLOW_NAMED_OPERATION_SUBMISSION_INVALID",`${o}/submission`);let N=new Set([...A?.fieldCodes||[],...m?.fieldCodes||[]]),C=a.context===void 0?[]:$(a.context,`${o}/submission/context`,16),g=new Set,D=C.map((R,v)=>{let V=`${o}/submission/context/${v}`,L=I(R,V);T(L,["queryParameter","fieldCode"],V);let M=b(L.queryParameter,`${V}/queryParameter`,64),K=J(L.fieldCode,`${V}/fieldCode`);return(!/^[A-Za-z][A-Za-z0-9]{0,63}$/.test(M)||g.has(M)||!N.has(K))&&l("NATIVE_WORKFLOW_LAUNCH_CONTEXT_INVALID",V),g.add(M),{queryParameter:M,fieldCode:K}}),h=R=>{let{fieldCodes:v,...V}=R;return V};return{mode:s.mode,submission:{kind:"named-operation",...A?{create:h(A)}:{},...m?{existing:h(m)}:{},context:D}}}function Vn(e,t){let n=I(e,t);T(n,["desktop","mobile"],t);let o=S(n.desktop,`${t}/desktop`),i=S(n.mobile,`${t}/mobile`);return o===i&&l("NATIVE_WORKFLOW_DETAIL_ROUTE_DUPLICATE",t),{desktop:o,mobile:i}}function Li(e,t){let n=new Set(t.map(E=>E.code)),o=new Map;e.data.resources.forEach((E,u)=>{let c=`/config/data/resources/${u}`,p=I(E,c);if(((p.surface===void 0?{}:I(p.surface,`${c}/surface`)).mutationOwner||"native")==="native")return;let A=I(p.capabilities,`${c}/capabilities`);for(let m of["create","update","delete"])o.set(String(A[m]),m)});let i=new Set;for(let[E,u]of e.authz.roles.entries()){let c=`/config/authz/roles/${E}`,p=I(u,c);T(p,["code","name","description","capabilities"],c,!0);let f=S(p.code,`${c}/code`);i.has(f)&&l("NATIVE_ROLE_DUPLICATE",`${c}/code`),i.add(f),b(p.name,`${c}/name`,255);let A=w(p.capabilities,`${c}/capabilities`,2e3);for(let[m,N]of A.entries())o.has(N)&&l("NATIVE_DATA_SURFACE_MUTATION_GRANT_FORBIDDEN",`${c}/capabilities/${m}`,{operation:o.get(N)}),n.has(N)||l("NATIVE_CAPABILITY_REFERENCE_MISSING",`${c}/capabilities`)}let s=e.authz.authenticatedUserRoleCode===void 0?"":S(e.authz.authenticatedUserRoleCode,"/config/authz/authenticatedUserRoleCode");s&&!i.has(s)&&l("NATIVE_AUTHENTICATED_USER_ROLE_REFERENCE_MISSING","/config/authz/authenticatedUserRoleCode");let a=new Set,r=0;for(let[E,u]of e.perspectives.entries()){let c=`/config/perspectives/${E}`,p=I(u,c);T(p,["code","name","description","roleCodes","capabilityCodes","default"],c,!0);let f=S(p.code,`${c}/code`);a.has(f)&&l("NATIVE_PERSPECTIVE_DUPLICATE",`${c}/code`),a.add(f),b(p.name,`${c}/name`,255);let A=w(p.roleCodes,`${c}/roleCodes`,20);A.length<1&&l("NATIVE_PERSPECTIVE_ROLE_REQUIRED",`${c}/roleCodes`),A.forEach((C,g)=>{i.has(C)||l("NATIVE_PERSPECTIVE_ROLE_MISSING",`${c}/roleCodes/${g}`)});let m=k(e.authz.roles.filter(C=>A.includes(C.code)).flatMap(C=>C.capabilities)),N=w(p.capabilityCodes,`${c}/capabilityCodes`,2e3);W(m)!==W(N)&&l("NATIVE_PERSPECTIVE_CAPABILITY_PROJECTION_MISMATCH",`${c}/capabilityCodes`),p.default===!0?r+=1:p.default!==void 0&&l("NATIVE_PERSPECTIVE_DEFAULT_INVALID",`${c}/default`)}r>1&&l("NATIVE_PERSPECTIVE_DEFAULT_DUPLICATE","/config/perspectives");for(let[E,u]of e.backend.operations.entries()){let c=I(u,`/config/backend/operations/${E}`);n.has(c.capability)||l("NATIVE_CAPABILITY_REFERENCE_MISSING",`/config/backend/operations/${E}/capability`)}let d=new Set,_=new Set;for(let[E,u]of e.frontend.routes.entries()){let c=`/config/frontend/routes/${E}`,p=I(u,c),f=S(p.code,`${c}/code`);d.has(f)&&l("NATIVE_ROUTE_DUPLICATE",`${c}/code`),d.add(f);let A=ee(p.path,`${c}/path`);_.has(A)&&l("NATIVE_ROUTE_PATH_DUPLICATE",`${c}/path`),_.add(A);let m=Ot(p,c,e.appCode);m.capability&&!n.has(m.capability)&&l("NATIVE_CAPABILITY_REFERENCE_MISSING",`${c}/capability`);let N=p.access===void 0?void 0:I(p.access,`${c}/access`);for(let C of["allOf","anyOf"]){let g=N?.[C]===void 0?[]:$(N[C],`${c}/access/${C}`,50);for(let[D,h]of g.entries()){let R=_e(h,`${c}/access/${C}/${D}`,e.appCode);n.has(R)||l("NATIVE_CAPABILITY_REFERENCE_MISSING",`${c}/access/${C}/${D}`)}}}if(e.frontend.admin.access!==void 0){let E=Ye(e.frontend.admin.access,"/config/frontend/admin/access",e.appCode);for(let u of["allOf","anyOf"])for(let[c,p]of(E[u]||[]).entries())n.has(p)||l("NATIVE_CAPABILITY_REFERENCE_MISSING",`/config/frontend/admin/access/${u}/${c}`)}for(let[E,u]of e.frontend.routes.entries()){let c=I(u,`/config/frontend/routes/${E}`);c.parentCode&&!d.has(c.parentCode)&&l("NATIVE_ROUTE_PARENT_MISSING",`/config/frontend/routes/${E}/parentCode`)}}function vi(e){let t=new Set(e.authz.roles.map(_=>String(_.code))),n=e.authz.authenticatedUserRoleCode===void 0?"":S(e.authz.authenticatedUserRoleCode,"/config/authz/authenticatedUserRoleCode"),o=new Map(e.authz.scopeDimensions.map(_=>[String(_.code),{valueType:_.valueType==="uuid"?"uuid":"string",..._.valueSource?.resourceCode?{valueSourceResourceCode:String(_.valueSource.resourceCode)}:{}}])),i=new Set(o.keys()),s=new Map(e.data.resources.map((_,E)=>{let u=we(_,`/config/data/resources/${E}`,e.appCode);return[u.code,new Map(u.schema.fields.map(c=>[String(c.code),c]))]}));for(let[_,E]of e.authz.scopeDimensions.entries()){let u=`/config/authz/scopeDimensions/${_}`,c=I(E,u);if(T(c,["code","name","resourceCode","valueType","hierarchyMode","valueSource"],u,!0),c.valueSource===void 0)continue;let p=I(c.valueSource,`${u}/valueSource`);T(p,["kind","resourceCode","labelField","enabledField"],`${u}/valueSource`,!0),p.kind!=="native_resource"&&l("NATIVE_SCOPE_VALUE_SOURCE_KIND_INVALID",`${u}/valueSource/kind`),c.valueType!=="uuid"&&l("NATIVE_SCOPE_VALUE_SOURCE_TYPE_INVALID",`${u}/valueType`);let f=x(p.resourceCode,`${u}/valueSource/resourceCode`),A=s.get(f);A||l("NATIVE_SCOPE_VALUE_SOURCE_RESOURCE_MISSING",`${u}/valueSource/resourceCode`);let m=J(p.labelField,`${u}/valueSource/labelField`);if(["text.short","text.long"].includes(String(A.get(m)?.type||""))||l("NATIVE_SCOPE_VALUE_SOURCE_LABEL_FIELD_INVALID",`${u}/valueSource/labelField`),p.enabledField!==void 0){let N=J(p.enabledField,`${u}/valueSource/enabledField`);A.get(N)?.type!=="boolean"&&l("NATIVE_SCOPE_VALUE_SOURCE_ENABLED_FIELD_INVALID",`${u}/valueSource/enabledField`)}}let a=new Set,r=new Set;for(let[_,E]of e.authz.scopeSources.entries()){let u=`/config/authz/scopeSources/${_}`,c=I(E,u);T(c,["code","name","resourceCode","subject","grants","operationField","enabledField","effectiveFromField","effectiveToField","failureMode"],u,!0);let p=S(c.code,`${u}/code`);a.has(p)&&l("NATIVE_SCOPE_SOURCE_DUPLICATE",`${u}/code`),a.add(p),b(c.name,`${u}/name`,255);let f=x(c.resourceCode,`${u}/resourceCode`),A=s.get(f);A||l("NATIVE_SCOPE_SOURCE_RESOURCE_MISSING",`${u}/resourceCode`);let m=I(c.subject,`${u}/subject`),N=b(m.type,`${u}/subject/type`,32);T(m,N==="role_membership"?["type","userIdField","roleCode"]:["type","userIdField"],`${u}/subject`),["user","role_membership"].includes(N)||l("NATIVE_SCOPE_SOURCE_SUBJECT_INVALID",`${u}/subject/type`);let C=he(m.userIdField,A);_t(C)||l("NATIVE_SCOPE_SOURCE_SUBJECT_PATH_INVALID",`${u}/subject/userIdField`),N==="role_membership"&&!t.has(String(m.roleCode))&&l("NATIVE_ROLE_REFERENCE_MISSING",`${u}/subject/roleCode`);let g=new Set;for(let[D,h]of $(c.grants,`${u}/grants`,100).entries()){let R=`${u}/grants/${D}`,v=I(h,R);T(v,["dimensionCode","valueField","parentValueField"],R,!0);let V=S(v.dimensionCode,`${R}/dimensionCode`);(!i.has(V)||g.has(V))&&l("NATIVE_SCOPE_SOURCE_DIMENSION_INVALID",`${R}/dimensionCode`),g.add(V),c.failureMode==="last_known_good"&&r.add(V);for(let L of["valueField","parentValueField"]){if(v[L]===void 0)continue;let M=he(v[L],A);zt(M,o.get(V),s)||l("NATIVE_SCOPE_SOURCE_GRANT_PATH_INVALID",`${R}/${L}`)}}g.size===0&&l("NATIVE_SCOPE_SOURCE_GRANT_REQUIRED",`${u}/grants`),["strict","last_known_good"].includes(c.failureMode)||l("NATIVE_SCOPE_SOURCE_FAILURE_MODE_INVALID",`${u}/failureMode`);for(let D of["operationField","enabledField","effectiveFromField","effectiveToField"]){if(c[D]===void 0)continue;let h=J(c[D],`${u}/${D}`);A.has(h)||l("NATIVE_SCOPE_SOURCE_FIELD_MISSING",`${u}/${D}`)}}Mi(e,t,s,n);let d=new Set;for(let[_,E]of e.authz.dataPolicies.entries()){let u=`/config/authz/dataPolicies/${_}`,c=I(E,u);T(c,["code","name","resourceCode","unrestrictedRoleCodes","operations","matchMode","rules","readExpression","writeBoundary"],u,!0);let p=S(c.code,`${u}/code`);d.has(p)&&l("NATIVE_DATA_POLICY_DUPLICATE",`${u}/code`),d.add(p);let f=c.readExpression!==void 0,A=w(c.operations||[],`${u}/operations`,4);c.operations!==void 0&&(A.length===0||A.some(h=>!["read","create","update","delete"].includes(h)))&&l("NATIVE_DATA_POLICY_OPERATIONS_INVALID",`${u}/operations`),["AND","OR"].includes(c.matchMode)||l("NATIVE_DATA_POLICY_MATCH_MODE_INVALID",`${u}/matchMode`),f&&c.operations!==void 0&&l("NATIVE_DATA_POLICY_READ_EXPRESSION_OPERATIONS_FORBIDDEN",`${u}/operations`);let m=e.data.resources.find(h=>h.dataPolicyCode===p),N=c.resourceCode||m?.code,C=N?s.get(x(N,`${u}/resourceCode`)):void 0;f&&!C&&l("NATIVE_DATA_POLICY_RESOURCE_MISSING",`${u}/resourceCode`);let g=w(c.unrestrictedRoleCodes||[],`${u}/unrestrictedRoleCodes`,100);c.unrestrictedRoleCodes!==void 0&&g.length===0&&l("NATIVE_DATA_POLICY_UNRESTRICTED_ROLES_INVALID",`${u}/unrestrictedRoleCodes`);for(let h of g)t.has(h)||l("NATIVE_ROLE_REFERENCE_MISSING",`${u}/unrestrictedRoleCodes`);let D;try{let h=$(c.rules,`${u}/rules`,100).map((R,v)=>({rule:I(R,`${u}/rules/${v}`),pointer:`${u}/rules/${v}`}));h.length===0?(!f||c.matchMode!=="AND"||c.writeBoundary!=="capability_only")&&l("NATIVE_DATA_POLICY_WRITE_BOUNDARY_REQUIRED",u):c.writeBoundary!==void 0&&l("NATIVE_DATA_POLICY_WRITE_BOUNDARY_INVALID",`${u}/writeBoundary`),D=[...h],f&&(D.push(...We(c.readExpression,`${u}/readExpression`)),Qt(c.readExpression,`${u}/readExpression`))}catch(h){throw h instanceof Se&&l(h.code,h.pointer),h}for(let{rule:h,pointer:R}of D){T(h,["subject","dimensionCode","relationCode","resourceCode","field","roleCodes","operation","valuePath","emptyMatchesAll","operator","value","operand"],R,!0);let v=J(h.field,`${R}/field`),V=C?.get(v);f&&!V&&l("NATIVE_DATA_POLICY_FIELD_MISSING",`${R}/field`);for(let U of w(h.roleCodes||[],`${R}/roleCodes`,100))t.has(U)||l("NATIVE_ROLE_REFERENCE_MISSING",`${R}/roleCodes`);let L=String(h.operator||""),M=h.operand==="db_now",K=["is_null","is_not_null"].includes(L),P=["eq","not_eq","in","not_in"].includes(L),Q=!M&&(h.operator!==void 0||h.value!==void 0);if([h.subject==="current_user"?"current_user":"",typeof h.dimensionCode=="string"?"dimension":"",typeof h.relationCode=="string"?"relationship":"",Q?"constant":"",M?"db_now":""].filter(Boolean).length!==1&&l("NATIVE_DATA_POLICY_RULE_SOURCE_INVALID",R),h.subject!==void 0&&h.subject!=="current_user"&&l("NATIVE_DATA_POLICY_SUBJECT_INVALID",`${R}/subject`),Q){if(!P&&!K&&l("NATIVE_DATA_POLICY_OPERATOR_INVALID",`${R}/operator`),["in","not_in"].includes(L)){let U=$(h.value,`${R}/value`,100).map((Ee,re)=>b(Ee,`${R}/value/${re}`,2048));(U.length===0||new Set(U).size!==U.length)&&l("NATIVE_DATA_POLICY_VALUE_INVALID",`${R}/value`)}else["eq","not_eq"].includes(L)?b(h.value,`${R}/value`,2048):(h.value!==void 0||h.operand!==void 0)&&l("NATIVE_DATA_POLICY_VALUE_INVALID",`${R}/value`);for(let U of["operation","valuePath","emptyMatchesAll","resourceCode","operand"])h[U]!==void 0&&l("NATIVE_DATA_POLICY_CONSTANT_RULE_INVALID",`${R}/${U}`)}if(M){(!["lt","lte","gt","gte"].includes(L)||h.value!==void 0||V?.type!=="datetime")&&l("NATIVE_DATA_POLICY_DB_NOW_INVALID",R);for(let U of["operation","valuePath","emptyMatchesAll","resourceCode","value"])h[U]!==void 0&&l("NATIVE_DATA_POLICY_DB_NOW_INVALID",`${R}/${U}`)}h.dimensionCode&&!i.has(h.dimensionCode)&&l("NATIVE_SCOPE_DIMENSION_MISSING",`${R}/dimensionCode`),r.has(String(h.dimensionCode||""))&&h.operation!=="read"&&l("NATIVE_SCOPE_SOURCE_LAST_KNOWN_GOOD_UNSAFE",`${R}/operation`)}}for(let[_,E]of e.data.resources.entries()){let u=I(E,`/config/data/resources/${_}`);u.dataPolicyCode&&!d.has(u.dataPolicyCode)&&l("NATIVE_DATA_POLICY_REFERENCE_MISSING",`/config/data/resources/${_}/dataPolicyCode`)}}function ki(e){try{wt(e.data.resources,"/config/data/resources")}catch(t){throw t instanceof ce&&l(t.code,t.pointer),t}}function Mi(e,t,n,o){let i=new Set;for(let[s,a]of e.authz.roleMembershipSources.entries()){let r=`/config/authz/roleMembershipSources/${s}`,d=I(a,r);T(d,["code","name","resourceCode","userIdField","roleCode","enabledField","effectiveFromField","effectiveToField","failureMode"],r,!0);let _=S(d.code,`${r}/code`);_.length>100&&l("NATIVE_AUTHORIZATION_PROJECTION_SOURCE_CODE_INVALID",`${r}/code`),i.has(_)&&l("NATIVE_AUTHORIZATION_PROJECTION_SOURCE_DUPLICATE",`${r}/code`),i.add(_),b(d.name,`${r}/name`,255);let E=un(d.resourceCode,`${r}/resourceCode`,n);fn(d.userIdField,`${r}/userIdField`,E),t.has(String(d.roleCode||""))||l("NATIVE_ROLE_REFERENCE_MISSING",`${r}/roleCode`),o&&d.roleCode===o&&l("NATIVE_AUTHENTICATED_USER_ROLE_SOURCE_CONFLICT",`${r}/roleCode`),_n(d,r,E)}for(let[s,a]of e.authz.relationshipGrantSources.entries()){let r=`/config/authz/relationshipGrantSources/${s}`,d=I(a,r);T(d,["code","name","resourceCode","subject","relationCode","targetResourceCode","resourceIdField","operations","enabledField","effectiveFromField","effectiveToField","failureMode"],r,!0);let _=S(d.code,`${r}/code`);_.length>100&&l("NATIVE_AUTHORIZATION_PROJECTION_SOURCE_CODE_INVALID",`${r}/code`),i.has(_)&&l("NATIVE_AUTHORIZATION_PROJECTION_SOURCE_DUPLICATE",`${r}/code`),i.add(_),b(d.name,`${r}/name`,255);let E=un(d.resourceCode,`${r}/resourceCode`,n),u=I(d.subject,`${r}/subject`),c=b(u.type,`${r}/subject/type`,32);T(u,c==="role_membership"?["type","userIdField","roleCode"]:["type","userIdField"],`${r}/subject`),["user","role_membership"].includes(c)||l("NATIVE_AUTHORIZATION_PROJECTION_SUBJECT_INVALID",`${r}/subject/type`),fn(u.userIdField,`${r}/subject/userIdField`,E),c==="role_membership"&&!t.has(String(u.roleCode||""))&&l("NATIVE_ROLE_REFERENCE_MISSING",`${r}/subject/roleCode`),S(d.relationCode,`${r}/relationCode`);let p=x(d.targetResourceCode,`${r}/targetResourceCode`);n.has(p)||l("NATIVE_AUTHORIZATION_PROJECTION_TARGET_RESOURCE_MISSING",`${r}/targetResourceCode`);let f=he(d.resourceIdField,E),A=f?.field.type==="resource-ref.single"&&f.valuePath==="value"&&f.field.source?.resourceCode===p;(d.resourceIdField==="id"?p!==String(d.resourceCode):!A)&&l("NATIVE_AUTHORIZATION_PROJECTION_RESOURCE_ID_FIELD_INVALID",`${r}/resourceIdField`);let m=w(d.operations,`${r}/operations`,20);(m.length===0||m.some(N=>N.length>64||!/^[A-Za-z0-9][A-Za-z0-9:._*-]{0,63}$/.test(N)))&&l("NATIVE_AUTHORIZATION_PROJECTION_OPERATIONS_INVALID",`${r}/operations`),_n(d,r,E)}}function un(e,t,n){let o=x(e,t),i=n.get(o);return i||l("NATIVE_AUTHORIZATION_PROJECTION_RESOURCE_MISSING",t),i}function fn(e,t,n){let o=he(e,n);_t(o)||l("NATIVE_AUTHORIZATION_PROJECTION_USER_FIELD_INVALID",t)}function _n(e,t,n){if(e.failureMode!=="strict"&&l("NATIVE_AUTHORIZATION_PROJECTION_FAILURE_MODE_INVALID",`${t}/failureMode`),e.enabledField!==void 0){let o=J(e.enabledField,`${t}/enabledField`);n.get(o)?.type!=="boolean"&&l("NATIVE_AUTHORIZATION_PROJECTION_ENABLED_FIELD_INVALID",`${t}/enabledField`)}for(let o of["effectiveFromField","effectiveToField"]){if(e[o]===void 0)continue;let i=J(e[o],`${t}/${o}`);["date","datetime"].includes(String(n.get(i)?.type))||l("NATIVE_AUTHORIZATION_PROJECTION_EFFECTIVE_FIELD_INVALID",`${t}/${o}`)}}function Ui(e){let t=new Set,n=new Set;e.forEach((o,i)=>{let s=`/config/backend/secrets/${i}`,a=I(o,s);T(a,["name","env","description","required","exposure"],s,!0);let r=b(a.name,`${s}/name`,128),d=b(a.env,`${s}/env`,128);xo.test(r)||l("NATIVE_SECRET_NAME_INVALID",`${s}/name`),(!jo.test(d)||d.startsWith("OPENXIANGDA_")||["NODE_ENV","PORT"].includes(d))&&l("NATIVE_SECRET_ENV_INVALID",`${s}/env`),t.has(r)&&l("NATIVE_SECRET_NAME_DUPLICATE",`${s}/name`),n.has(d)&&l("NATIVE_SECRET_ENV_DUPLICATE",`${s}/env`),t.add(r),n.add(d),F(a.exposure,"active_only",`${s}/exposure`),a.required!==void 0&&be(a.required,`${s}/required`),a.description!==void 0&&bt(a.description,`${s}/description`,2e3)})}function xi(e){let t=new Set,n=new Map,o=new Map(e.data.resources.map(c=>[String(c.code),c])),i=new Map(e.frontend.routes.map((c,p)=>{let f=I(c,`/config/frontend/routes/${p}`);return[S(f.code,`/config/frontend/routes/${p}/code`),f]}));for(let[c,p]of e.workflows.definitions.entries()){let f=`/config/workflows/definitions/${c}`,A=I(p,f);if(T(A,["version","definition","launch"],f,["detailRouteCode"]),Sn(A.launch,`${f}/launch`),A.detailRouteCode!==void 0){let g=Vn(A.detailRouteCode,`${f}/detailRouteCode`);for(let[D,h,R]of[["desktop",g.desktop,"admin"],["mobile",g.mobile,"user"]]){let v=`${f}/detailRouteCode/${D}`,V=i.get(h);V||l("NATIVE_WORKFLOW_DETAIL_ROUTE_MISSING",v),V.surface!==R&&l("NATIVE_WORKFLOW_DETAIL_ROUTE_SURFACE_INVALID",v);let L=ee(V.path,v),M=[...L.matchAll(/:([A-Za-z][A-Za-z0-9_]*)/g)].map(K=>K[1]);(L.includes("*")||M.length!==1||M[0]!=="instanceId")&&l("NATIVE_WORKFLOW_DETAIL_ROUTE_PATH_INVALID",v)}}let m=I(A.definition,`${f}/definition`),N=`${m.code}:${Oe(A.version,`${f}/version`)}`;t.has(N)&&l("NATIVE_WORKFLOW_DEFINITION_DUPLICATE",f),t.add(N),Wi(m,`${f}/definition`),ji(m.subject,o,`${f}/definition/subject`);let C=Kt(m,{appCode:e.appCode,capabilities:e.authz.capabilities.map(g=>g.code),fields:new Map((o.get(m.subject.resourceCode)?.schema.fields||[]).map(g=>[g.code,g]))});C.length&&l("NATIVE_WORKFLOW_INSTANCE_COMMAND_POLICY_INVALID",`${f}/definition/instanceCommands`,{errors:C}),m.title===m.code&&l("NATIVE_WORKFLOW_USER_TITLE_REQUIRED",`${f}/definition/title`),n.set(N,m)}let s=new Set,a=new Map;for(let[c,p]of e.workflows.bindings.entries()){let f=I(p,`/config/workflows/bindings/${c}`),A=I(f.binding,`/config/workflows/bindings/${c}/binding`),m=`${A.workflowCode}:${Oe(f.version,`/config/workflows/bindings/${c}/version`)}`;s.has(m)&&l("NATIVE_WORKFLOW_BINDING_DUPLICATE",`/config/workflows/bindings/${c}`),s.add(m),Bi(A,`/config/workflows/bindings/${c}/binding`),a.set(m,A)}let r=new Set,d=new Map;for(let[c,p]of e.workflows.activations.entries()){let f=`/config/workflows/activations/${c}`,A=I(p,f);T(A,["workflowCode","definitionVersion","bindingVersion","acceptedCommandDeactivationPolicy"],f,["environmentKey"]);let m=S(A.workflowCode,`${f}/workflowCode`);r.has(m)&&l("NATIVE_WORKFLOW_ACTIVATION_DUPLICATE",f),r.add(m);let N=`${m}:${Oe(A.definitionVersion,`${f}/definitionVersion`)}`,C=`${m}:${Oe(A.bindingVersion,`${f}/bindingVersion`)}`;t.has(N)||l("NATIVE_WORKFLOW_DEFINITION_REFERENCE_MISSING",`${f}/definitionVersion`),s.has(C)||l("NATIVE_WORKFLOW_BINDING_REFERENCE_MISSING",`${f}/bindingVersion`);let g=n.get(N),D=a.get(C);(!["finish-pinned","cancel-on-deactivate"].includes(A.acceptedCommandDeactivationPolicy)||A.acceptedCommandDeactivationPolicy!==g.acceptedCommandDeactivationPolicy)&&l("NATIVE_WORKFLOW_COMMAND_DEACTIVATION_POLICY_MISMATCH",`${f}/acceptedCommandDeactivationPolicy`),Ji(g,D,`/config/workflows/activations/${c}`),d.set(m,D)}let _=new Set;e.workflows.providers.forEach((c,p)=>{let f=`/config/workflows/providers/${p}`,A=I(c,f);T(A,["code","endpointPath","timeoutMs"],f,!0);let m=S(A.code,`${f}/code`);_.has(m)&&l("NATIVE_WORKFLOW_PROVIDER_DUPLICATE",`${f}/code`),_.add(m),ee(A.endpointPath,`${f}/endpointPath`),A.timeoutMs!==void 0&&z(A.timeoutMs,`${f}/timeoutMs`,100,1e4)});for(let[c,p]of d.entries())for(let[f,A]of Object.entries(I(p.bindings,"/config/workflows/bindings/*/binding/bindings"))){let m=I(A,`/config/workflows/${c}/bindings/${f}`);m.provider==="application_provider"&&!_.has(m.providerCode)&&l("NATIVE_WORKFLOW_PROVIDER_REFERENCE_MISSING",`/config/workflows/${c}/bindings/${f}/providerCode`)}let E=new Set(e.authz.roles.map(c=>c.code)),u=new Set;e.workflows.editableParameters.forEach((c,p)=>{let f=`/config/workflows/editableParameters/${p}`,A=I(c,f);T(A,["code","workflowCode","bindingKey","label","valueType","required","allowedRoleCodes","allowedProviderCodes","maxItems"],f,!0);let m=S(A.code,`${f}/code`);u.has(m)&&l("NATIVE_WORKFLOW_EDITABLE_PARAMETER_DUPLICATE",`${f}/code`),u.add(m);let N=He(A.workflowCode,`${f}/workflowCode`),C=$t(A.bindingKey,`${f}/bindingKey`),g=d.get(N);(!g||!I(g.bindings,`${f}/bindingKey`)[C])&&l("NATIVE_WORKFLOW_EDITABLE_BINDING_MISSING",`${f}/bindingKey`),b(A.label,`${f}/label`,255),["role_code","user_ids","provider_code"].includes(A.valueType)||l("NATIVE_WORKFLOW_EDITABLE_VALUE_TYPE_INVALID",`${f}/valueType`);for(let D of w(A.allowedRoleCodes||[],`${f}/allowedRoleCodes`,100))E.has(D)||l("NATIVE_ROLE_REFERENCE_MISSING",`${f}/allowedRoleCodes`);for(let D of w(A.allowedProviderCodes||[],`${f}/allowedProviderCodes`,100))_.has(D)||l("NATIVE_WORKFLOW_PROVIDER_REFERENCE_MISSING",`${f}/allowedProviderCodes`);A.required!==void 0&&be(A.required,`${f}/required`),A.maxItems!==void 0&&z(A.maxItems,`${f}/maxItems`,1,200)})}function ji(e,t,n){let o=I(e,n);T(o,["resourceCode","factProjection"],n,["summaryFields"]);let i=x(o.resourceCode,`${n}/resourceCode`),s=t.get(i);s||l("NATIVE_WORKFLOW_SUBJECT_RESOURCE_MISSING",`${n}/resourceCode`);let a=new Set($(I(s.schema,`${n}/resourceCode`).fields,`${n}/resourceCode`,500).map((_,E)=>J(I(_,`${n}/resourceCode/${E}`).code,`${n}/resourceCode/${E}`))),r=I(o.factProjection,`${n}/factProjection`),d=Object.entries(r);(d.length<1||d.length>64)&&l("NATIVE_WORKFLOW_SUBJECT_FACT_PROJECTION_INVALID",`${n}/factProjection`);for(let[_,E]of d){Jo.test(_)||l("NATIVE_WORKFLOW_SUBJECT_FACT_KEY_INVALID",`${n}/factProjection/${_}`);let u=J(E,`${n}/factProjection/${_}`);a.has(u)||l("NATIVE_WORKFLOW_SUBJECT_FIELD_MISSING",`${n}/factProjection/${_}`)}if(o.summaryFields!==void 0){let _=w(o.summaryFields,`${n}/summaryFields`,Go).map((f,A)=>J(f,`${n}/summaryFields/${A}`)),E=t.get(i),u=E.surface&&typeof E.surface=="object"&&!Array.isArray(E.surface)?E.surface:{},c=u.fields&&typeof u.fields=="object"&&!Array.isArray(u.fields)?u.fields:{},p=new Map($(I(E.schema,`${n}/resourceCode`).fields,`${n}/resourceCode`,500).map((f,A)=>{let m=I(f,`${n}/resourceCode/${A}`);return[String(m.code),m]}));for(let[f,A]of _.entries()){let m=p.get(A),N=c[A],C=String(m?.type||""),g=m?.maxLength;(!m||m.system===!0||N&&typeof N=="object"&&!Array.isArray(N)&&N.system===!0||["id","revision","created_by","updated_by","created_at","updated_at"].includes(A)||!Yo.has(C)||C==="text.long"&&typeof g=="number"&&Number.isFinite(g)&&g>zo)&&l("NATIVE_WORKFLOW_SUBJECT_SUMMARY_FIELDS_INVALID",`${n}/summaryFields/${f}`)}}}function Wi(e,t){T(e,["schemaVersion","code","title","subject","acceptedCommandDeactivationPolicy","startAt","inputSchema","nodes"],t,["organizationContext","instanceCommands"]),F(e.schemaVersion,"openxiangda.workflow-definition/v2",`${t}/schemaVersion`),He(e.code,`${t}/code`),b(e.title,`${t}/title`,255),["finish-pinned","cancel-on-deactivate"].includes(e.acceptedCommandDeactivationPolicy)||l("NATIVE_WORKFLOW_COMMAND_DEACTIVATION_POLICY_REQUIRED",`${t}/acceptedCommandDeactivationPolicy`);let n=I(e.nodes,`${t}/nodes`),o=Object.keys(n);(o.length===0||o.length>200)&&l("NATIVE_WORKFLOW_NODE_COUNT_INVALID",`${t}/nodes`);let i=b(e.startAt,`${t}/startAt`,128);n[i]||l("NATIVE_WORKFLOW_START_NODE_MISSING",`${t}/startAt`);let s=new Map;for(let[_,E]of Object.entries(n)){let u=`${t}/nodes/${_}`,c=I(E,u);F(c.id,_,`${u}/id`),["approval","condition","end"].includes(c.kind)||l("NATIVE_WORKFLOW_NODE_KIND_INVALID",`${u}/kind`);let p=[];if(c.kind==="approval"){$t(c.binding,`${u}/binding`),["single","any","all","sequence"].includes(c.mode)||l("NATIVE_WORKFLOW_APPROVAL_MODE_INVALID",`${u}/mode`),p.push(b(c.onApprove,`${u}/onApprove`,128),b(c.onReject,`${u}/onReject`,128));for(let f of w(c.returnTargets||[],`${u}/returnTargets`,200))n[f]||l("NATIVE_WORKFLOW_TARGET_MISSING",`${u}/returnTargets`);for(let f of w(c.allowedOperations||[],`${u}/allowedOperations`,20))Ko.has(f)||l("NATIVE_WORKFLOW_OPERATION_INVALID",`${u}/allowedOperations`)}else if(c.kind==="condition"){let f=$(c.branches,`${u}/branches`,100);f.length===0&&l("NATIVE_WORKFLOW_BRANCH_REQUIRED",`${u}/branches`),f.forEach((A,m)=>{let N=I(A,`${u}/branches/${m}`);Ve(N.when,`${u}/branches/${m}/when`,0),p.push(b(N.target,`${u}/branches/${m}/target`,128))}),p.push(b(c.otherwise,`${u}/otherwise`,128))}else b(c.outcome,`${u}/outcome`,128);for(let f of p)n[f]||l("NATIVE_WORKFLOW_TARGET_MISSING",u);s.set(_,p)}let a=new Set,r=new Set,d=_=>{if(r.has(_)&&l("NATIVE_WORKFLOW_CYCLE_FORBIDDEN",`${t}/nodes/${_}`),!a.has(_)){a.add(_),r.add(_);for(let E of s.get(_)||[])d(E);r.delete(_)}};d(i),a.size!==o.length&&l("NATIVE_WORKFLOW_NODE_UNREACHABLE",`${t}/nodes`)}function Ve(e,t,n){n>20&&l("NATIVE_WORKFLOW_EXPRESSION_DEPTH_EXCEEDED",t);let o=I(e,t),i=b(o.op,`${t}/op`,16);if(i!=="literal"){if(i==="path"){let s=b(o.path,`${t}/path`,255);/^[A-Za-z][A-Za-z0-9_.]{0,254}$/.test(s)||l("NATIVE_WORKFLOW_EXPRESSION_PATH_INVALID",`${t}/path`);return}if(["eq","neq","gt","gte","lt","lte","in","contains"].includes(i)){Ve(o.left,`${t}/left`,n+1),Ve(o.right,`${t}/right`,n+1);return}if(["and","or"].includes(i)){let s=$(o.values,`${t}/values`,100);s.length===0&&l("NATIVE_WORKFLOW_EXPRESSION_EMPTY",`${t}/values`),s.forEach((a,r)=>Ve(a,`${t}/values/${r}`,n+1));return}if(["not","exists"].includes(i)){Ve(o.value,`${t}/value`,n+1);return}l("NATIVE_WORKFLOW_EXPRESSION_OPERATOR_INVALID",`${t}/op`)}}function Bi(e,t){F(e.schemaVersion,"openxiangda.workflow-binding/v2",`${t}/schemaVersion`),He(e.workflowCode,`${t}/workflowCode`);let n=I(e.bindings,`${t}/bindings`);Object.keys(n).length>200&&l("NATIVE_WORKFLOW_BINDING_LIMIT_EXCEEDED",`${t}/bindings`);for(let[o,i]of Object.entries(n)){$t(o,`${t}/bindings/${o}`);let s=I(i,`${t}/bindings/${o}`),a=b(s.provider,`${t}/bindings/${o}/provider`,64);["fixed_users","initiator","input_users","form_field_users","department_supervisor","app_role","app_role_in_scope","business_relation","previous_node_actor","initiator_select","application_provider"].includes(a)||l("NATIVE_WORKFLOW_BINDING_PROVIDER_INVALID",`${t}/bindings/${o}/provider`),a==="fixed_users"&&$(s.users,`${t}/bindings/${o}/users`,200).length===0&&l("NATIVE_WORKFLOW_BINDING_USERS_REQUIRED",`${t}/bindings/${o}/users`),["input_users","form_field_users"].includes(a)&&b(s.inputPath,`${t}/bindings/${o}/inputPath`,255),["app_role","app_role_in_scope","initiator_select"].includes(a)&&S(s.roleCode,`${t}/bindings/${o}/roleCode`),a==="department_supervisor"&&b(s.departmentIdFrom,`${t}/bindings/${o}/departmentIdFrom`,255),a==="application_provider"&&S(s.providerCode,`${t}/bindings/${o}/providerCode`)}}function Ji(e,t,n){F(t.workflowCode,e.code,`${n}/workflowCode`);let o=I(t.bindings,`${n}/bindings`);for(let[i,s]of Object.entries(I(e.nodes,`${n}/nodes`))){let a=I(s,`${n}/nodes/${i}`);a.kind==="approval"&&!o[a.binding]&&l("NATIVE_WORKFLOW_BINDING_REFERENCE_MISSING",`${n}/nodes/${i}/binding`)}}function we(e,t,n){let o=I(e,t);T(o,["schemaVersion","appCode","code","name","schema","surface","invariants","capabilities","dataPolicyCode","fieldPolicies"],t,!0),F(o.schemaVersion,"openxiangda.data-resource/v2",`${t}/schemaVersion`),F(o.appCode,n,`${t}/appCode`);let i=x(o.code,`${t}/code`),s=b(o.name,`${t}/name`,255),a=I(o.schema,`${t}/schema`);T(a,["fields"],`${t}/schema`);let r,d;try{r=tt(a.fields,`${t}/schema/fields`),d=Pt(o.invariants,r,`${t}/invariants`),dt(o.surface,r,`${t}/surface`)}catch(c){throw c instanceof ce&&l(c.code,c.pointer),c}let _=new Set(r.map(c=>c.code)),E=I(o.capabilities,`${t}/capabilities`);T(E,["read","create","update","delete"],`${t}/capabilities`);let u=I(o.fieldPolicies,`${t}/fieldPolicies`);for(let[c,p]of Object.entries(u)){_.has(c)||l("NATIVE_DATA_FIELD_POLICY_FIELD_MISSING",`${t}/fieldPolicies/${c}`);let f=`${t}/fieldPolicies/${c}`,A=I(p,f);T(A,["read","create","update","mask"],f,!0),A.mask!==void 0&&!["omit","null"].includes(A.mask)&&l("NATIVE_DATA_FIELD_POLICY_MASK_INVALID",`${f}/mask`)}return{...o,code:i,name:s,schema:{fields:r},...o.invariants===void 0?{}:{invariants:d},capabilities:E,fieldPolicies:u}}function yn(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,n])=>({code:t,kind:"platform",name:n,source:"platform"}))]}function En(e,t,n,o){let i=e.toString("utf8"),s;try{s=JSON.parse(i)}catch{l(n,t)}let a=I(s,t);return W(a)!==i&&l(o,t),a}function pn(e,t){let n=0,o=(i,s,a)=>{if(n+=1,n>Zo&&l("NATIVE_ARTIFACT_NODE_LIMIT_EXCEEDED",s),a>Qo&&l("NATIVE_ARTIFACT_DEPTH_LIMIT_EXCEEDED",s),typeof i=="string"){Buffer.byteLength(i)>At&&l("NATIVE_ARTIFACT_STRING_LIMIT_EXCEEDED",s);return}if(Array.isArray(i)){i.forEach((r,d)=>o(r,`${s}/${d}`,a+1));return}if(!(!i||typeof i!="object"))for(let[r,d]of Object.entries(i))["__proto__","prototype","constructor"].includes(r)&&l("NATIVE_ARTIFACT_DANGEROUS_KEY",`${s}/${r}`),Gi(r)&&l("NATIVE_ARTIFACT_RUNTIME_FIELD_FORBIDDEN",`${s}/${r}`),o(d,`${s}/${r}`,a+1)};o(e,t,0)}function Gi(e){return["environmentKey","environmentId","secretValue","ciphertext","oauthClient","oauthClientId","oauthClientSecret","signingSecret","kubernetesNamespace","nodePort","productionUrl"].includes(e)}function Ce(e){return{value:e,digest:Z(e)}}function An(e,t,n,o){typeof e!="string"&&!Buffer.isBuffer(e)&&!(e instanceof Uint8Array)&&l("NATIVE_ARTIFACT_BYTES_REQUIRED",n);let i=Buffer.isBuffer(e)?e:Buffer.from(e);return i.byteLength===0&&l("NATIVE_ARTIFACT_EMPTY",n),i.byteLength>t&&l(o,n),i}function In(e,t,n,o){let i=Ge.createHash("sha256").update(e).digest("hex");Ge.timingSafeEqual(Buffer.from(i),Buffer.from(t))||l(o,n)}function I(e,t){return(!e||typeof e!="object"||Array.isArray(e))&&l("NATIVE_OBJECT_REQUIRED",t),e}function $(e,t,n){return Array.isArray(e)||l("NATIVE_ARRAY_REQUIRED",t),e.length>n&&l("NATIVE_ARRAY_LIMIT_EXCEEDED",t),e}function w(e,t,n){let o=$(e,t,n).map((i,s)=>b(i,`${t}/${s}`,255));return new Set(o).size!==o.length&&l("NATIVE_ARRAY_DUPLICATE",t),o}function b(e,t,n){return(typeof e!="string"||e.length===0||e.length>n)&&l("NATIVE_STRING_INVALID",t),e}function bt(e,t,n){return(typeof e!="string"||e.length>n)&&l("NATIVE_STRING_INVALID",t),e}function S(e,t){let n=b(e,t,128);return vo.test(n)||l("NATIVE_CODE_INVALID",t),n}function x(e,t){let n=b(e,t,64);return Mo.test(n)||l("NATIVE_RESOURCE_CODE_INVALID",t),n}function J(e,t){let n=b(e,t,63);return Uo.test(n)||l("NATIVE_FIELD_CODE_INVALID",t),n}function He(e,t){let n=b(e,t,128);return Wo.test(n)||l("NATIVE_WORKFLOW_CODE_INVALID",t),n}function $t(e,t){let n=b(e,t,128);return Bo.test(n)||l("NATIVE_WORKFLOW_BINDING_CODE_INVALID",t),n}function _e(e,t,n){let o=b(e,t,255);return Lo.test(o)||l("NATIVE_CAPABILITY_CODE_INVALID",t),!o.startsWith(`app:${n}:`)&&!yn(n).some(i=>i.code===o)&&l("NATIVE_CAPABILITY_APP_MISMATCH",t),o}function ee(e,t){let n=b(e,t,2048);return(!n.startsWith("/")||n.startsWith("//")||n.includes("..")||n.includes("?")||n.includes("#"))&&l("NATIVE_ABSOLUTE_PATH_INVALID",t),n}function Oe(e,t){return(!Number.isInteger(e)||Number(e)<1)&&l("NATIVE_POSITIVE_INTEGER_REQUIRED",t),Number(e)}function z(e,t,n,o){return(!Number.isInteger(e)||Number(e)<n||Number(e)>o)&&l("NATIVE_INTEGER_OUT_OF_RANGE",t),Number(e)}function be(e,t){return typeof e!="boolean"&&l("NATIVE_BOOLEAN_REQUIRED",t),e}function Tt(e,t){let n=b(e,t,64).toLowerCase();return Po.test(n)||l("NATIVE_DIGEST_INVALID",t),n}function F(e,t,n){e!==t&&l("NATIVE_VALUE_MISMATCH",n)}function T(e,t,n,o=!1){let i=new Set([...t,...Array.isArray(o)?o:[]]);for(let s of Object.keys(e))i.has(s)||l("NATIVE_PROPERTY_UNKNOWN",`${n}/${s}`);if(o!==!0)for(let s of t)Object.prototype.hasOwnProperty.call(e,s)||l("NATIVE_PROPERTY_REQUIRED",`${n}/${s}`)}function q(e,t){return[...e].sort((n,o)=>se(t(n),t(o)))}function k(e){return[...new Set(e)].sort(se)}function mn(e){return[...new Set(e)].sort((t,n)=>t-n)}function se(e,t){return e===t?0:e<t?-1:1}function wn(e){return!e||typeof e!="object"||Object.isFrozen(e)||(Object.freeze(e),Object.values(e).forEach(t=>wn(t))),e}function gt(e,t,n){if(pt(e,t))return n;if(Array.isArray(e)&&Array.isArray(t)){let o=Math.max(e.length,t.length);for(let i=0;i<o;i+=1)if(!pt(e[i],t[i]))return gt(e[i],t[i],`${n}/${i}`)}if(e&&t&&typeof e=="object"&&typeof t=="object"&&!Array.isArray(e)&&!Array.isArray(t)){let o=k([...Object.keys(e),...Object.keys(t)]);for(let i of o){let s=e[i],a=t[i];if(!pt(s,a))return gt(s,a,`${n}/${i}`)}}return n}function pt(e,t){return e===void 0||t===void 0?e===t:W(e)===W(t)}function l(e,t,n={}){throw new mt(e,t,n)}var Ys="4682a2cae5f284b4581f26b5ff2d4a3b34cdc4e1cd11f723ac56fcd9d720a44d";export{on as DATA_EVENT_TYPES_V2,Ys as NATIVE_CONFIGURATION_VALIDATOR_DIGEST,B as NATIVE_CONTRACT_CAPACITY_V2,ws as NATIVE_DATA_POLICY_EXPRESSION_MAX_CLAUSES,Ss as NATIVE_DATA_POLICY_EXPRESSION_MAX_DEPTH,Vs as NATIVE_DATA_POLICY_EXPRESSION_MAX_GROUP_ITEMS,ys as NATIVE_DATA_POLICY_EXPRESSION_MAX_LEAVES,Ps as NATIVE_DATA_POLICY_EXPRESSION_MAX_OCCURRENCES,Hn as NATIVE_DATA_QUERY_OPERATORS_V2,mt as NativeConfigurationCompilerError,ce as NativeDataFieldContractV2Error,Se as NativeDataPolicyExpressionV2Error,ft as NativeScopeSourceFieldPathV2Error,vn as OPENXIANGDA_NATIVE_DATA_FIELD_TYPES_V2,le as OPENXIANGDA_NATIVE_DATA_SURFACE_KEYS_V2,Mn as OPENXIANGDA_NATIVE_SYSTEM_FIELDS_V2,Hi as OPENXIANGDA_NATIVE_SYSTEM_FIELD_MAP_V2,It as WORKFLOW_EVENT_TYPES_V2,Gs as compileNativeApplicationConfiguration,ii as compileNativeEventCapturePlansV2,oi as compileRequiredPlatformCapabilitiesV3,qi as isNativeDataQueryOperatorV2,ke as isNativeMultiValueFieldV2,Cs as materializeNativeDataQueryPathTypesV2,We as nativeDataPolicyExpressionLeavesV2,Qt as nativeDataPolicyExpressionToCnfV2,Os as nativeDataQueryPathPlanV2,Qi as nativeFieldAggregatePlanV2,us as nativeFieldColumnDefinitionV2,fs as nativeFieldDefaultSqlV2,_s as nativeFieldHasDefaultV2,Is as nativeFieldIndexStatementsV2,Me as nativeFieldRequiresCreateInputV2,As as nativeFieldSequenceGrantStatementsV2,ps as nativeFieldSequenceOwnershipStatementsV2,Es as nativeFieldSequenceStatementsV2,kt as nativeFieldSupportsFilterV2,Xi as nativeFieldSupportsOperatorV2,st as nativeFieldSupportsSearchV2,rt as nativeFieldSupportsSortV2,vt as nativeOperatorsForFieldV2,po as nativePhysicalFieldV2,ls as nativePhysicalFieldsV2,ue as nativePhysicalObjectNameV2,Ts as nativeScopeSourceFieldValueV2,zt as nativeScopeSourceGrantPathSupportedV2,_t as nativeScopeSourceSubjectPathSupportedV2,ms as nativeSubtableConstraintStatementsV2,tt as parseNativeDataFieldsV2,Pt as parseNativeDataResourceInvariantsV2,lt as projectNativeDataResourceViewV2,H as quoteNativeIdentifierV2,he as resolveNativeScopeSourceFieldPathV2,wt as validateNativeDataResourceReferencesV2,dt as validateNativeDataResourceSurfaceV2,Kt as validateWorkflowInstanceCommandPolicies,hs as workflowInstanceCommandDeadlineError,$s as workflowInstanceTerminateCapabilityAllowed,Ht as workflowPolicyTimestamp};
|