@nextclaw/app-runtime 0.15.0 → 0.16.1-beta.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/index.d.ts +4 -4
- package/dist/package.js +1 -1
- package/dist/services/app-grant.service.d.ts +2 -0
- package/dist/services/app-grant.service.d.ts.map +1 -1
- package/dist/services/app-grant.service.js +40 -16
- package/dist/services/app-grant.service.js.map +1 -1
- package/dist/services/app-installation-lifecycle.service.js +29 -2
- package/dist/services/app-installation-lifecycle.service.js.map +1 -1
- package/dist/services/app-installation.service.d.ts.map +1 -1
- package/dist/services/app-installation.service.js +1 -1
- package/dist/services/app-installation.service.js.map +1 -1
- package/dist/services/app-manifest.service.d.ts +1 -0
- package/dist/services/app-manifest.service.d.ts.map +1 -1
- package/dist/services/app-manifest.service.js +27 -0
- package/dist/services/app-manifest.service.js.map +1 -1
- package/dist/services/app-permissions.service.d.ts.map +1 -1
- package/dist/services/app-permissions.service.js +0 -3
- package/dist/services/app-permissions.service.js.map +1 -1
- package/dist/services/app-registry-parser.service.js +228 -0
- package/dist/services/app-registry-parser.service.js.map +1 -0
- package/dist/services/app-registry.service.d.ts +7 -11
- package/dist/services/app-registry.service.d.ts.map +1 -1
- package/dist/services/app-registry.service.js +91 -173
- package/dist/services/app-registry.service.js.map +1 -1
- package/dist/services/app-rust-wasi-scaffold-template.service.d.ts.map +1 -1
- package/dist/services/app-rust-wasi-scaffold-template.service.js +37 -0
- package/dist/services/app-rust-wasi-scaffold-template.service.js.map +1 -1
- package/dist/types/app-installation.types.d.ts +2 -2
- package/dist/types/app-installation.types.d.ts.map +1 -1
- package/dist/types/app-manifest.types.d.ts +8 -1
- package/dist/types/app-manifest.types.d.ts.map +1 -1
- package/dist/types/app-manifest.types.js.map +1 -1
- package/dist/types/app-permissions.types.d.ts +12 -1
- package/dist/types/app-permissions.types.d.ts.map +1 -1
- package/dist/types/app-registry.types.d.ts +10 -3
- package/dist/types/app-registry.types.d.ts.map +1 -1
- package/package.json +2 -2
- package/resources/wit/deps/clocks@0.2.6/monotonic-clock.wit +50 -0
- package/resources/wit/deps/clocks@0.2.6/timezone.wit +55 -0
- package/resources/wit/deps/clocks@0.2.6/wall-clock.wit +46 -0
- package/resources/wit/deps/clocks@0.2.6/world.wit +11 -0
- package/resources/wit/deps/config@0.2.0-draft-2024-09-27/package.wit +1 -0
- package/resources/wit/deps/config@0.2.0-draft-2024-09-27/store.wit +9 -0
- package/resources/wit/deps/http@0.2.6/handler.wit +49 -0
- package/resources/wit/deps/http@0.2.6/package.wit +1 -0
- package/resources/wit/deps/http@0.2.6/types.wit +688 -0
- package/resources/wit/deps/io@0.2.6/error.wit +34 -0
- package/resources/wit/deps/io@0.2.6/poll.wit +47 -0
- package/resources/wit/deps/io@0.2.6/streams.wit +290 -0
- package/resources/wit/deps/io@0.2.6/world.wit +10 -0
- package/resources/wit/deps/spin@2.0.0/package.wit +1 -0
- package/resources/wit/deps/spin@2.0.0/sqlite.wit +50 -0
- package/resources/wit/portable-service.wit +73 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"app-manifest.service.js","names":[],"sources":["../../src/services/app-manifest.service.ts"],"sourcesContent":["import { access, lstat, readFile } from \"node:fs/promises\";\nimport path from \"node:path\";\nimport { AppPlatformTargetService } from \"#app-runtime/services/app-platform-target.service.js\";\nimport type {\n AppComponentManifest,\n AppComponentManifestBundle,\n AppComponentReference,\n AppDocumentAccessScope,\n AppManifest,\n AppManifestBundle,\n AppManifestSummary,\n AppPermissions,\n AppPlatformSecuritySummary,\n AppResolvedComponent,\n AppStandaloneManifest,\n AppStandaloneManifestBundle,\n} from \"#app-runtime/types/app-manifest.types.js\";\n\nconst PACKAGE_ID_PATTERN = /^[a-z0-9]+(?:[.-][a-z0-9]+)*$/;\nconst COMPONENT_ID_PATTERN = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;\n\nexport class AppManifestService {\n constructor(\n private readonly platformTargetService = new AppPlatformTargetService(),\n ) {}\n\n load = async (appDirectory: string): Promise<AppManifestBundle> => {\n const normalizedDirectory = path.resolve(appDirectory);\n const manifestPath = path.join(normalizedDirectory, \"manifest.json\");\n const rawManifest = JSON.parse(await readFile(manifestPath, \"utf-8\")) as unknown;\n const manifest = this.parseManifest(rawManifest);\n return manifest.schemaVersion === 1\n ? await this.loadStandaloneBundle(normalizedDirectory, manifestPath, manifest)\n : await this.loadComponentBundle(normalizedDirectory, manifestPath, manifest);\n };\n\n summarize = (bundle: AppManifestBundle): AppManifestSummary => {\n if (bundle.manifest.schemaVersion === 2) {\n const componentBundle = bundle as AppComponentManifestBundle;\n return {\n schemaVersion: 2,\n id: componentBundle.manifest.id,\n name: componentBundle.manifest.name,\n version: componentBundle.manifest.version,\n description: componentBundle.manifest.description,\n manifestPath: componentBundle.manifestPath,\n iconPath: componentBundle.iconPath,\n primaryPanelId: componentBundle.primaryPanelId,\n components: componentBundle.components,\n distribution: this.platformTargetService.resolveDistribution(\n componentBundle.manifest.distribution,\n ),\n security: this.resolvePlatformSecurity(componentBundle.manifest),\n };\n }\n const standaloneBundle = bundle as AppStandaloneManifestBundle;\n const permissions = standaloneBundle.manifest.permissions ?? {};\n return {\n schemaVersion: 1,\n id: standaloneBundle.manifest.id,\n name: standaloneBundle.manifest.name,\n version: standaloneBundle.manifest.version,\n description: standaloneBundle.manifest.description,\n mainKind: standaloneBundle.manifest.main.kind,\n action:\n standaloneBundle.manifest.main.kind === \"wasm\"\n ? standaloneBundle.manifest.main.action\n : undefined,\n manifestPath: standaloneBundle.manifestPath,\n mainEntryPath: standaloneBundle.mainEntryPath,\n uiEntryPath: standaloneBundle.uiEntryPath,\n iconPath: standaloneBundle.iconPath,\n permissions,\n };\n };\n\n private loadStandaloneBundle = async (\n appDirectory: string,\n manifestPath: string,\n manifest: AppStandaloneManifest,\n ): Promise<AppStandaloneManifestBundle> => {\n const mainEntryPath = await this.assertResolvedFile(\n appDirectory,\n manifest.main.entry,\n \"main.entry\",\n );\n const uiEntryPath = await this.assertResolvedFile(\n appDirectory,\n manifest.ui.entry,\n \"ui.entry\",\n );\n const iconPath = manifest.icon\n ? await this.assertResolvedFile(appDirectory, manifest.icon, \"icon\")\n : undefined;\n return {\n appDirectory,\n manifestPath,\n manifest,\n mainEntryPath,\n uiEntryPath,\n uiDirectoryPath: path.dirname(uiEntryPath),\n assetsDirectoryPath: path.join(appDirectory, \"assets\"),\n iconPath,\n };\n };\n\n private loadComponentBundle = async (\n appDirectory: string,\n manifestPath: string,\n manifest: AppComponentManifest,\n ): Promise<AppComponentManifestBundle> => {\n const components: AppResolvedComponent[] = [];\n for (const [index, component] of manifest.components.entries()) {\n const componentDirectory = await this.assertResolvedDirectory(\n appDirectory,\n component.path,\n `components[${index}].path`,\n );\n const componentId = await this.readComponentId(component, componentDirectory);\n const expectedPrefix = `${manifest.id.replace(/[^a-z0-9]+/g, \"-\")}-`;\n if (!componentId.startsWith(expectedPrefix)) {\n throw new Error(\n `组件 ${componentId} 必须使用包前缀 ${expectedPrefix}。`,\n );\n }\n components.push({\n ...component,\n id: componentId,\n componentDirectory,\n manifestPath: path.join(\n componentDirectory,\n component.kind === \"panel\" ? \"panel-app.json\" : \"service-app.json\",\n ),\n });\n }\n const duplicateId = components.find(\n (component, index) => components.findIndex((entry) => entry.id === component.id) !== index,\n );\n if (duplicateId) {\n throw new Error(`components 包含重复组件 id:${duplicateId.id}`);\n }\n const panelIds = components\n .filter((component) => component.kind === \"panel\")\n .map((component) => component.id);\n const declaredPrimaryPanel = manifest.presentation?.primaryPanel;\n if (declaredPrimaryPanel && !panelIds.includes(declaredPrimaryPanel)) {\n throw new Error(\"presentation.primaryPanel 必须引用真实 Panel component id。\");\n }\n if (panelIds.length > 1 && !declaredPrimaryPanel) {\n throw new Error(\"包含多个 Panel 时必须声明 presentation.primaryPanel。\");\n }\n if (panelIds.length === 0 && declaredPrimaryPanel) {\n throw new Error(\"不含 Panel 的包不能声明 presentation.primaryPanel。\");\n }\n const iconPath = manifest.icon\n ? await this.assertResolvedFile(appDirectory, manifest.icon, \"icon\")\n : undefined;\n return {\n appDirectory,\n manifestPath,\n manifest,\n components,\n assetsDirectoryPath: path.join(appDirectory, \"assets\"),\n iconPath,\n primaryPanelId: declaredPrimaryPanel ?? panelIds[0],\n };\n };\n\n private parseManifest = (rawManifest: unknown): AppManifest => {\n const candidate = this.assertObject(rawManifest, \"manifest.json\");\n const schemaVersion = this.readNumber(candidate.schemaVersion, \"schemaVersion\");\n if (schemaVersion !== 1 && schemaVersion !== 2) {\n throw new Error(\"当前只支持 schemaVersion = 1 或 2。\");\n }\n const common = this.parseCommonManifest(candidate);\n if (schemaVersion === 1) {\n return {\n schemaVersion: 1,\n ...common,\n main: this.parseMain(candidate.main),\n ui: this.parseUi(candidate.ui),\n permissions: this.parsePermissions(candidate.permissions),\n };\n }\n const components = this.parseComponents(candidate.components);\n const runtime = this.parseRuntime(candidate.runtime);\n this.assertRuntimeMatchesComponents(runtime, components);\n return {\n schemaVersion: 2,\n ...common,\n engines: this.parseEngines(candidate.engines),\n presentation: this.parsePresentation(candidate.presentation),\n runtime,\n distribution: this.platformTargetService.parseDistribution(candidate.distribution),\n storage: this.parseAppStorage(candidate.storage),\n permissions: this.parsePermissions(candidate.permissions),\n components,\n };\n };\n\n resolvePlatformSecurity = (\n manifest: AppComponentManifest,\n ): AppPlatformSecuritySummary => {\n const hasServiceComponents = manifest.components.some(\n (component) => component.kind === \"service\",\n );\n const runtimeProfile = manifest.runtime?.profile ?? (\n hasServiceComponents ? \"native-process\" : \"panel-only\"\n );\n const isolation = runtimeProfile === \"panel-only\"\n ? \"sandboxed\"\n : runtimeProfile === \"wasi\"\n ? \"host-mediated\"\n : \"full-user\";\n const declaredPermissions = manifest.permissions ?? {};\n const permissions: AppPermissions = runtimeProfile === \"native-process\"\n ? {\n ...declaredPermissions,\n storage: declaredPermissions.storage ?? true,\n capabilities: {\n ...declaredPermissions.capabilities,\n nativeProcess: true,\n },\n }\n : declaredPermissions;\n return {\n runtimeProfile,\n isolation,\n hasServiceComponents,\n inferred: manifest.runtime === undefined,\n permissions,\n };\n };\n\n private parseCommonManifest = (candidate: Record<string, unknown>) => {\n const id = this.readRequiredString(candidate.id, \"id\");\n if (!PACKAGE_ID_PATTERN.test(id)) {\n throw new Error(\"id 必须由小写字母、数字、点或连字符组成。\");\n }\n return {\n id,\n name: this.readRequiredString(candidate.name, \"name\"),\n version: this.readRequiredString(candidate.version, \"version\"),\n description: this.readOptionalString(candidate.description, \"description\"),\n icon: this.readOptionalString(candidate.icon, \"icon\"),\n };\n };\n\n private parseMain = (rawMain: unknown): AppStandaloneManifest[\"main\"] => {\n const candidate = this.assertObject(rawMain, \"main\");\n const kind = this.readRequiredString(candidate.kind, \"main.kind\");\n if (kind === \"wasm\") {\n return {\n kind,\n entry: this.readRequiredString(candidate.entry, \"main.entry\"),\n export: this.readRequiredString(candidate.export, \"main.export\"),\n action: this.readRequiredString(candidate.action, \"main.action\"),\n };\n }\n if (kind === \"wasi-http-component\") {\n return {\n kind,\n entry: this.readRequiredString(candidate.entry, \"main.entry\"),\n };\n }\n throw new Error(\"当前 main.kind 只支持 wasm 或 wasi-http-component。\");\n };\n\n private parseUi = (rawUi: unknown): AppStandaloneManifest[\"ui\"] => {\n const candidate = this.assertObject(rawUi, \"ui\");\n return { entry: this.readRequiredString(candidate.entry, \"ui.entry\") };\n };\n\n private parseComponents = (rawComponents: unknown): AppComponentReference[] => {\n if (!Array.isArray(rawComponents) || rawComponents.length === 0) {\n throw new Error(\"components 必须是非空数组。\");\n }\n const components = rawComponents.map((rawComponent, index) => {\n const candidate = this.assertObject(rawComponent, `components[${index}]`);\n const kind = this.readRequiredString(candidate.kind, `components[${index}].kind`);\n if (kind !== \"panel\" && kind !== \"service\") {\n throw new Error(`components[${index}].kind 只支持 panel 或 service。`);\n }\n const normalizedKind: AppComponentReference[\"kind\"] = kind;\n return {\n kind: normalizedKind,\n path: this.normalizeRelativePath(\n this.readRequiredString(candidate.path, `components[${index}].path`),\n `components[${index}].path`,\n ),\n };\n });\n for (let leftIndex = 0; leftIndex < components.length; leftIndex += 1) {\n for (let rightIndex = leftIndex + 1; rightIndex < components.length; rightIndex += 1) {\n const left = components[leftIndex]?.path;\n const right = components[rightIndex]?.path;\n if (left && right && (left === right || left.startsWith(`${right}/`) || right.startsWith(`${left}/`))) {\n throw new Error(`components path 不能重复或重叠:${left} / ${right}`);\n }\n }\n }\n return components;\n };\n\n private parseEngines = (\n rawEngines: unknown,\n ): AppComponentManifest[\"engines\"] => {\n if (rawEngines === undefined) {\n return undefined;\n }\n const candidate = this.assertObject(rawEngines, \"engines\");\n return { nextclaw: this.readOptionalString(candidate.nextclaw, \"engines.nextclaw\") };\n };\n\n private parsePresentation = (\n rawPresentation: unknown,\n ): AppComponentManifest[\"presentation\"] => {\n if (rawPresentation === undefined) {\n return undefined;\n }\n const candidate = this.assertObject(rawPresentation, \"presentation\");\n return {\n primaryPanel: this.readOptionalString(\n candidate.primaryPanel,\n \"presentation.primaryPanel\",\n ),\n };\n };\n\n private parseRuntime = (\n rawRuntime: unknown,\n ): AppComponentManifest[\"runtime\"] => {\n if (rawRuntime === undefined) {\n return undefined;\n }\n const candidate = this.assertObject(rawRuntime, \"runtime\");\n const profile = this.readRequiredString(candidate.profile, \"runtime.profile\");\n if (profile !== \"panel-only\" && profile !== \"wasi\" && profile !== \"native-process\") {\n throw new Error(\"runtime.profile 只支持 panel-only、wasi 或 native-process。\");\n }\n return { profile };\n };\n\n private parseAppStorage = (\n rawStorage: unknown,\n ): AppComponentManifest[\"storage\"] => {\n if (rawStorage === undefined) {\n return undefined;\n }\n const candidate = this.assertObject(rawStorage, \"storage\");\n const scope = this.readRequiredString(candidate.scope, \"storage.scope\");\n if (scope !== \"global\") {\n throw new Error(\"当前 storage.scope 只支持 global。\");\n }\n const schemaVersion = this.readNumber(candidate.schemaVersion, \"storage.schemaVersion\");\n if (!Number.isSafeInteger(schemaVersion) || schemaVersion < 1) {\n throw new Error(\"storage.schemaVersion 必须是正整数。\");\n }\n return { scope, schemaVersion };\n };\n\n private assertRuntimeMatchesComponents = (\n runtime: AppComponentManifest[\"runtime\"],\n components: AppComponentReference[],\n ): void => {\n if (!runtime) {\n return;\n }\n const hasService = components.some((component) => component.kind === \"service\");\n if (runtime.profile === \"panel-only\" && hasService) {\n throw new Error(\"runtime.profile=panel-only 不能包含 Service component。\");\n }\n if (runtime.profile === \"wasi\") {\n if (!hasService) {\n throw new Error(\"wasi runtime 必须包含 Service component。\");\n }\n return;\n }\n if (runtime.profile !== \"panel-only\" && !hasService) {\n throw new Error(`${runtime.profile} runtime 必须包含 Service component。`);\n }\n };\n\n private readComponentId = async (\n component: AppComponentReference,\n componentDirectory: string,\n ): Promise<string> => {\n const manifestFile = component.kind === \"panel\" ? \"panel-app.json\" : \"service-app.json\";\n const raw = JSON.parse(\n await readFile(path.join(componentDirectory, manifestFile), \"utf-8\"),\n ) as unknown;\n const manifest = this.assertObject(raw, `${component.path}/${manifestFile}`);\n const id = this.readRequiredString(manifest.id, `${component.path}/${manifestFile}.id`);\n if (!COMPONENT_ID_PATTERN.test(id)) {\n throw new Error(`组件 id 必须是 kebab-case:${id}`);\n }\n const directoryName = path.basename(componentDirectory);\n const expectedId = component.kind === \"panel\"\n ? directoryName.replace(/\\.panel$/, \"\")\n : directoryName;\n if (component.kind === \"panel\" && !directoryName.endsWith(\".panel\")) {\n throw new Error(`Panel component 目录必须以 .panel 结尾:${component.path}`);\n }\n if (id !== expectedId) {\n throw new Error(`组件 id 必须与目录名一致:期望 ${expectedId},实际 ${id}`);\n }\n return id;\n };\n\n private parsePermissions = (rawPermissions: unknown): AppPermissions | undefined => {\n if (rawPermissions === undefined) {\n return undefined;\n }\n const candidate = this.assertObject(rawPermissions, \"permissions\");\n return {\n documentAccess: this.parseDocumentAccess(candidate.documentAccess),\n allowedDomains: this.parseStringArray(candidate.allowedDomains, \"permissions.allowedDomains\"),\n storage: this.parseStorage(candidate.storage),\n capabilities: this.parseCapabilities(candidate.capabilities),\n };\n };\n\n private parseDocumentAccess = (rawDocumentAccess: unknown): AppDocumentAccessScope[] | undefined => {\n if (rawDocumentAccess === undefined) {\n return undefined;\n }\n if (!Array.isArray(rawDocumentAccess)) {\n throw new Error(\"permissions.documentAccess 必须是数组。\");\n }\n return rawDocumentAccess.map((scope, index) => {\n const candidate = this.assertObject(scope, `permissions.documentAccess[${index}]`);\n const mode = this.readRequiredString(candidate.mode, `permissions.documentAccess[${index}].mode`);\n if (mode !== \"read\" && mode !== \"read-write\") {\n throw new Error(`permissions.documentAccess[${index}].mode 只支持 read 或 read-write。`);\n }\n return {\n id: this.readRequiredString(candidate.id, `permissions.documentAccess[${index}].id`),\n mode,\n description: this.readOptionalString(\n candidate.description,\n `permissions.documentAccess[${index}].description`,\n ),\n };\n });\n };\n\n private parseStringArray = (rawValue: unknown, fieldName: string): string[] | undefined => {\n if (rawValue === undefined) {\n return undefined;\n }\n if (!Array.isArray(rawValue)) {\n throw new Error(`${fieldName} 必须是字符串数组。`);\n }\n return rawValue.map((item, index) => this.readRequiredString(item, `${fieldName}[${index}]`));\n };\n\n private parseStorage = (rawStorage: unknown): AppPermissions[\"storage\"] | undefined => {\n if (rawStorage === undefined || typeof rawStorage === \"boolean\") {\n return rawStorage;\n }\n const candidate = this.assertObject(rawStorage, \"permissions.storage\");\n return { namespace: this.readOptionalString(candidate.namespace, \"permissions.storage.namespace\") };\n };\n\n private parseCapabilities = (rawCapabilities: unknown): AppPermissions[\"capabilities\"] | undefined => {\n if (rawCapabilities === undefined) {\n return undefined;\n }\n const candidate = this.assertObject(rawCapabilities, \"permissions.capabilities\");\n return {\n hostBridge: candidate.hostBridge === undefined\n ? undefined\n : this.readBoolean(candidate.hostBridge, \"permissions.capabilities.hostBridge\"),\n nativeProcess: candidate.nativeProcess === undefined\n ? undefined\n : this.readBoolean(candidate.nativeProcess, \"permissions.capabilities.nativeProcess\"),\n };\n };\n\n private assertResolvedFile = async (\n appDirectory: string,\n relativePath: string,\n fieldName: string,\n ): Promise<string> => {\n const resolvedPath = this.resolveInside(appDirectory, relativePath, fieldName);\n const stats = await lstat(resolvedPath);\n if (!stats.isFile() || stats.isSymbolicLink()) {\n throw new Error(`${fieldName} 必须指向包内普通文件。`);\n }\n return resolvedPath;\n };\n\n private assertResolvedDirectory = async (\n appDirectory: string,\n relativePath: string,\n fieldName: string,\n ): Promise<string> => {\n const resolvedPath = this.resolveInside(appDirectory, relativePath, fieldName);\n const stats = await lstat(resolvedPath);\n if (!stats.isDirectory() || stats.isSymbolicLink()) {\n throw new Error(`${fieldName} 必须指向包内普通目录。`);\n }\n await access(resolvedPath);\n return resolvedPath;\n };\n\n private resolveInside = (appDirectory: string, relativePath: string, fieldName: string): string => {\n const normalizedPath = this.normalizeRelativePath(relativePath, fieldName);\n const resolvedPath = path.resolve(appDirectory, normalizedPath);\n const relative = path.relative(appDirectory, resolvedPath);\n if (relative.startsWith(\"..\") || path.isAbsolute(relative)) {\n throw new Error(`${fieldName} 不能指向应用目录之外。`);\n }\n return resolvedPath;\n };\n\n private normalizeRelativePath = (relativePath: string, fieldName: string): string => {\n if (path.isAbsolute(relativePath) || relativePath.includes(\"\\0\")) {\n throw new Error(`${fieldName} 必须使用包内相对路径。`);\n }\n const segments = relativePath.replace(/\\\\/g, \"/\").split(\"/\");\n if (segments.some((segment) => !segment || segment === \".\" || segment === \"..\")) {\n throw new Error(`${fieldName} 包含非法路径片段。`);\n }\n return segments.join(\"/\");\n };\n\n private assertObject = (value: unknown, fieldName: string): Record<string, unknown> => {\n if (!value || typeof value !== \"object\" || Array.isArray(value)) {\n throw new Error(`${fieldName} 必须是对象。`);\n }\n return value as Record<string, unknown>;\n };\n\n private readRequiredString = (value: unknown, fieldName: string): string => {\n if (typeof value !== \"string\" || !value.trim()) {\n throw new Error(`${fieldName} 必须是非空字符串。`);\n }\n return value.trim();\n };\n\n private readOptionalString = (value: unknown, fieldName: string): string | undefined => {\n return value === undefined ? undefined : this.readRequiredString(value, fieldName);\n };\n\n private readNumber = (value: unknown, fieldName: string): number => {\n if (typeof value !== \"number\" || Number.isNaN(value)) {\n throw new Error(`${fieldName} 必须是数字。`);\n }\n return value;\n };\n\n private readBoolean = (value: unknown, fieldName: string): boolean => {\n if (typeof value !== \"boolean\") {\n throw new Error(`${fieldName} 必须是布尔值。`);\n }\n return value;\n };\n}\n"],"mappings":";;;;AAkBA,MAAM,qBAAqB;AAC3B,MAAM,uBAAuB;AAE7B,IAAa,qBAAb,MAAgC;CAC9B,YACE,wBAAyC,IAAI,0BAA0B,EACvE;AADiB,OAAA,wBAAA;;CAGnB,OAAO,OAAO,iBAAqD;EACjE,MAAM,sBAAsB,KAAK,QAAQ,aAAa;EACtD,MAAM,eAAe,KAAK,KAAK,qBAAqB,gBAAgB;EACpE,MAAM,cAAc,KAAK,MAAM,MAAM,SAAS,cAAc,QAAQ,CAAC;EACrE,MAAM,WAAW,KAAK,cAAc,YAAY;AAChD,SAAO,SAAS,kBAAkB,IAC9B,MAAM,KAAK,qBAAqB,qBAAqB,cAAc,SAAS,GAC5E,MAAM,KAAK,oBAAoB,qBAAqB,cAAc,SAAS;;CAGjF,aAAa,WAAkD;AAC7D,MAAI,OAAO,SAAS,kBAAkB,GAAG;GACvC,MAAM,kBAAkB;AACxB,UAAO;IACL,eAAe;IACf,IAAI,gBAAgB,SAAS;IAC7B,MAAM,gBAAgB,SAAS;IAC/B,SAAS,gBAAgB,SAAS;IAClC,aAAa,gBAAgB,SAAS;IACtC,cAAc,gBAAgB;IAC9B,UAAU,gBAAgB;IAC1B,gBAAgB,gBAAgB;IAChC,YAAY,gBAAgB;IAC5B,cAAc,KAAK,sBAAsB,oBACvC,gBAAgB,SAAS,aAC1B;IACD,UAAU,KAAK,wBAAwB,gBAAgB,SAAS;IACjE;;EAEH,MAAM,mBAAmB;EACzB,MAAM,cAAc,iBAAiB,SAAS,eAAe,EAAE;AAC/D,SAAO;GACL,eAAe;GACf,IAAI,iBAAiB,SAAS;GAC9B,MAAM,iBAAiB,SAAS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,SAAS;AAExC,SAAO;;CAGT,eAAuB,OAAgB,cAA+B;AACpE,MAAI,OAAO,UAAU,UACnB,OAAM,IAAI,MAAM,GAAG,UAAU,UAAU;AAEzC,SAAO"}
|
|
1
|
+
{"version":3,"file":"app-manifest.service.js","names":[],"sources":["../../src/services/app-manifest.service.ts"],"sourcesContent":["import { access, lstat, readFile } from \"node:fs/promises\";\nimport path from \"node:path\";\nimport { AppPlatformTargetService } from \"#app-runtime/services/app-platform-target.service.js\";\nimport type {\n AppComponentManifest,\n AppComponentManifestBundle,\n AppComponentReference,\n AppDocumentAccessScope,\n AppManifest,\n AppManifestBundle,\n AppManifestSummary,\n AppPermissions,\n AppPlatformSecuritySummary,\n AppResolvedComponent,\n AppSecretSlot,\n AppStandaloneManifest,\n AppStandaloneManifestBundle,\n} from \"#app-runtime/types/app-manifest.types.js\";\n\nconst PACKAGE_ID_PATTERN = /^[a-z0-9]+(?:[.-][a-z0-9]+)*$/;\nconst COMPONENT_ID_PATTERN = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;\nconst SECRET_SLOT_ID_PATTERN = /^[a-z][a-z0-9]*(?:[._-][a-z0-9]+)*$/;\n\nexport class AppManifestService {\n constructor(\n private readonly platformTargetService = new AppPlatformTargetService(),\n ) {}\n\n load = async (appDirectory: string): Promise<AppManifestBundle> => {\n const normalizedDirectory = path.resolve(appDirectory);\n const manifestPath = path.join(normalizedDirectory, \"manifest.json\");\n const rawManifest = JSON.parse(await readFile(manifestPath, \"utf-8\")) as unknown;\n const manifest = this.parseManifest(rawManifest);\n return manifest.schemaVersion === 1\n ? await this.loadStandaloneBundle(normalizedDirectory, manifestPath, manifest)\n : await this.loadComponentBundle(normalizedDirectory, manifestPath, manifest);\n };\n\n summarize = (bundle: AppManifestBundle): AppManifestSummary => {\n if (bundle.manifest.schemaVersion === 2) {\n const componentBundle = bundle as AppComponentManifestBundle;\n return {\n schemaVersion: 2,\n id: componentBundle.manifest.id,\n name: componentBundle.manifest.name,\n version: componentBundle.manifest.version,\n description: componentBundle.manifest.description,\n manifestPath: componentBundle.manifestPath,\n iconPath: componentBundle.iconPath,\n primaryPanelId: componentBundle.primaryPanelId,\n components: componentBundle.components,\n distribution: this.platformTargetService.resolveDistribution(\n componentBundle.manifest.distribution,\n ),\n security: this.resolvePlatformSecurity(componentBundle.manifest),\n };\n }\n const standaloneBundle = bundle as AppStandaloneManifestBundle;\n const permissions = standaloneBundle.manifest.permissions ?? {};\n return {\n schemaVersion: 1,\n id: standaloneBundle.manifest.id,\n name: standaloneBundle.manifest.name,\n version: standaloneBundle.manifest.version,\n description: standaloneBundle.manifest.description,\n mainKind: standaloneBundle.manifest.main.kind,\n action:\n standaloneBundle.manifest.main.kind === \"wasm\"\n ? standaloneBundle.manifest.main.action\n : undefined,\n manifestPath: standaloneBundle.manifestPath,\n mainEntryPath: standaloneBundle.mainEntryPath,\n uiEntryPath: standaloneBundle.uiEntryPath,\n iconPath: standaloneBundle.iconPath,\n permissions,\n };\n };\n\n private loadStandaloneBundle = async (\n appDirectory: string,\n manifestPath: string,\n manifest: AppStandaloneManifest,\n ): Promise<AppStandaloneManifestBundle> => {\n const mainEntryPath = await this.assertResolvedFile(\n appDirectory,\n manifest.main.entry,\n \"main.entry\",\n );\n const uiEntryPath = await this.assertResolvedFile(\n appDirectory,\n manifest.ui.entry,\n \"ui.entry\",\n );\n const iconPath = manifest.icon\n ? await this.assertResolvedFile(appDirectory, manifest.icon, \"icon\")\n : undefined;\n return {\n appDirectory,\n manifestPath,\n manifest,\n mainEntryPath,\n uiEntryPath,\n uiDirectoryPath: path.dirname(uiEntryPath),\n assetsDirectoryPath: path.join(appDirectory, \"assets\"),\n iconPath,\n };\n };\n\n private loadComponentBundle = async (\n appDirectory: string,\n manifestPath: string,\n manifest: AppComponentManifest,\n ): Promise<AppComponentManifestBundle> => {\n const components: AppResolvedComponent[] = [];\n for (const [index, component] of manifest.components.entries()) {\n const componentDirectory = await this.assertResolvedDirectory(\n appDirectory,\n component.path,\n `components[${index}].path`,\n );\n const componentId = await this.readComponentId(component, componentDirectory);\n const expectedPrefix = `${manifest.id.replace(/[^a-z0-9]+/g, \"-\")}-`;\n if (!componentId.startsWith(expectedPrefix)) {\n throw new Error(\n `组件 ${componentId} 必须使用包前缀 ${expectedPrefix}。`,\n );\n }\n components.push({\n ...component,\n id: componentId,\n componentDirectory,\n manifestPath: path.join(\n componentDirectory,\n component.kind === \"panel\" ? \"panel-app.json\" : \"service-app.json\",\n ),\n });\n }\n const duplicateId = components.find(\n (component, index) => components.findIndex((entry) => entry.id === component.id) !== index,\n );\n if (duplicateId) {\n throw new Error(`components 包含重复组件 id:${duplicateId.id}`);\n }\n const panelIds = components\n .filter((component) => component.kind === \"panel\")\n .map((component) => component.id);\n const declaredPrimaryPanel = manifest.presentation?.primaryPanel;\n if (declaredPrimaryPanel && !panelIds.includes(declaredPrimaryPanel)) {\n throw new Error(\"presentation.primaryPanel 必须引用真实 Panel component id。\");\n }\n if (panelIds.length > 1 && !declaredPrimaryPanel) {\n throw new Error(\"包含多个 Panel 时必须声明 presentation.primaryPanel。\");\n }\n if (panelIds.length === 0 && declaredPrimaryPanel) {\n throw new Error(\"不含 Panel 的包不能声明 presentation.primaryPanel。\");\n }\n const iconPath = manifest.icon\n ? await this.assertResolvedFile(appDirectory, manifest.icon, \"icon\")\n : undefined;\n return {\n appDirectory,\n manifestPath,\n manifest,\n components,\n assetsDirectoryPath: path.join(appDirectory, \"assets\"),\n iconPath,\n primaryPanelId: declaredPrimaryPanel ?? panelIds[0],\n };\n };\n\n private parseManifest = (rawManifest: unknown): AppManifest => {\n const candidate = this.assertObject(rawManifest, \"manifest.json\");\n const schemaVersion = this.readNumber(candidate.schemaVersion, \"schemaVersion\");\n if (schemaVersion !== 1 && schemaVersion !== 2) {\n throw new Error(\"当前只支持 schemaVersion = 1 或 2。\");\n }\n const common = this.parseCommonManifest(candidate);\n if (schemaVersion === 1) {\n return {\n schemaVersion: 1,\n ...common,\n main: this.parseMain(candidate.main),\n ui: this.parseUi(candidate.ui),\n permissions: this.parsePermissions(candidate.permissions),\n };\n }\n const components = this.parseComponents(candidate.components);\n const runtime = this.parseRuntime(candidate.runtime);\n this.assertRuntimeMatchesComponents(runtime, components);\n return {\n schemaVersion: 2,\n ...common,\n engines: this.parseEngines(candidate.engines),\n presentation: this.parsePresentation(candidate.presentation),\n runtime,\n distribution: this.platformTargetService.parseDistribution(candidate.distribution),\n storage: this.parseAppStorage(candidate.storage),\n permissions: this.parsePermissions(candidate.permissions),\n components,\n };\n };\n\n resolvePlatformSecurity = (\n manifest: AppComponentManifest,\n ): AppPlatformSecuritySummary => {\n const hasServiceComponents = manifest.components.some(\n (component) => component.kind === \"service\",\n );\n const runtimeProfile = manifest.runtime?.profile ?? (\n hasServiceComponents ? \"native-process\" : \"panel-only\"\n );\n const isolation = runtimeProfile === \"panel-only\"\n ? \"sandboxed\"\n : runtimeProfile === \"wasi\"\n ? \"host-mediated\"\n : \"full-user\";\n const declaredPermissions = manifest.permissions ?? {};\n const permissions: AppPermissions = runtimeProfile === \"native-process\"\n ? {\n ...declaredPermissions,\n storage: declaredPermissions.storage ?? true,\n capabilities: {\n ...declaredPermissions.capabilities,\n nativeProcess: true,\n },\n }\n : declaredPermissions;\n return {\n runtimeProfile,\n isolation,\n hasServiceComponents,\n inferred: manifest.runtime === undefined,\n permissions,\n };\n };\n\n private parseCommonManifest = (candidate: Record<string, unknown>) => {\n const id = this.readRequiredString(candidate.id, \"id\");\n if (!PACKAGE_ID_PATTERN.test(id)) {\n throw new Error(\"id 必须由小写字母、数字、点或连字符组成。\");\n }\n return {\n id,\n name: this.readRequiredString(candidate.name, \"name\"),\n version: this.readRequiredString(candidate.version, \"version\"),\n description: this.readOptionalString(candidate.description, \"description\"),\n icon: this.readOptionalString(candidate.icon, \"icon\"),\n };\n };\n\n private parseMain = (rawMain: unknown): AppStandaloneManifest[\"main\"] => {\n const candidate = this.assertObject(rawMain, \"main\");\n const kind = this.readRequiredString(candidate.kind, \"main.kind\");\n if (kind === \"wasm\") {\n return {\n kind,\n entry: this.readRequiredString(candidate.entry, \"main.entry\"),\n export: this.readRequiredString(candidate.export, \"main.export\"),\n action: this.readRequiredString(candidate.action, \"main.action\"),\n };\n }\n if (kind === \"wasi-http-component\") {\n return {\n kind,\n entry: this.readRequiredString(candidate.entry, \"main.entry\"),\n };\n }\n throw new Error(\"当前 main.kind 只支持 wasm 或 wasi-http-component。\");\n };\n\n private parseUi = (rawUi: unknown): AppStandaloneManifest[\"ui\"] => {\n const candidate = this.assertObject(rawUi, \"ui\");\n return { entry: this.readRequiredString(candidate.entry, \"ui.entry\") };\n };\n\n private parseComponents = (rawComponents: unknown): AppComponentReference[] => {\n if (!Array.isArray(rawComponents) || rawComponents.length === 0) {\n throw new Error(\"components 必须是非空数组。\");\n }\n const components = rawComponents.map((rawComponent, index) => {\n const candidate = this.assertObject(rawComponent, `components[${index}]`);\n const kind = this.readRequiredString(candidate.kind, `components[${index}].kind`);\n if (kind !== \"panel\" && kind !== \"service\") {\n throw new Error(`components[${index}].kind 只支持 panel 或 service。`);\n }\n const normalizedKind: AppComponentReference[\"kind\"] = kind;\n return {\n kind: normalizedKind,\n path: this.normalizeRelativePath(\n this.readRequiredString(candidate.path, `components[${index}].path`),\n `components[${index}].path`,\n ),\n };\n });\n for (let leftIndex = 0; leftIndex < components.length; leftIndex += 1) {\n for (let rightIndex = leftIndex + 1; rightIndex < components.length; rightIndex += 1) {\n const left = components[leftIndex]?.path;\n const right = components[rightIndex]?.path;\n if (left && right && (left === right || left.startsWith(`${right}/`) || right.startsWith(`${left}/`))) {\n throw new Error(`components path 不能重复或重叠:${left} / ${right}`);\n }\n }\n }\n return components;\n };\n\n private parseEngines = (\n rawEngines: unknown,\n ): AppComponentManifest[\"engines\"] => {\n if (rawEngines === undefined) {\n return undefined;\n }\n const candidate = this.assertObject(rawEngines, \"engines\");\n return { nextclaw: this.readOptionalString(candidate.nextclaw, \"engines.nextclaw\") };\n };\n\n private parsePresentation = (\n rawPresentation: unknown,\n ): AppComponentManifest[\"presentation\"] => {\n if (rawPresentation === undefined) {\n return undefined;\n }\n const candidate = this.assertObject(rawPresentation, \"presentation\");\n return {\n primaryPanel: this.readOptionalString(\n candidate.primaryPanel,\n \"presentation.primaryPanel\",\n ),\n };\n };\n\n private parseRuntime = (\n rawRuntime: unknown,\n ): AppComponentManifest[\"runtime\"] => {\n if (rawRuntime === undefined) {\n return undefined;\n }\n const candidate = this.assertObject(rawRuntime, \"runtime\");\n const profile = this.readRequiredString(candidate.profile, \"runtime.profile\");\n if (profile !== \"panel-only\" && profile !== \"wasi\" && profile !== \"native-process\") {\n throw new Error(\"runtime.profile 只支持 panel-only、wasi 或 native-process。\");\n }\n return { profile };\n };\n\n private parseAppStorage = (\n rawStorage: unknown,\n ): AppComponentManifest[\"storage\"] => {\n if (rawStorage === undefined) {\n return undefined;\n }\n const candidate = this.assertObject(rawStorage, \"storage\");\n const scope = this.readRequiredString(candidate.scope, \"storage.scope\");\n if (scope !== \"global\") {\n throw new Error(\"当前 storage.scope 只支持 global。\");\n }\n const schemaVersion = this.readNumber(candidate.schemaVersion, \"storage.schemaVersion\");\n if (!Number.isSafeInteger(schemaVersion) || schemaVersion < 1) {\n throw new Error(\"storage.schemaVersion 必须是正整数。\");\n }\n return { scope, schemaVersion };\n };\n\n private assertRuntimeMatchesComponents = (\n runtime: AppComponentManifest[\"runtime\"],\n components: AppComponentReference[],\n ): void => {\n if (!runtime) {\n return;\n }\n const hasService = components.some((component) => component.kind === \"service\");\n if (runtime.profile === \"panel-only\" && hasService) {\n throw new Error(\"runtime.profile=panel-only 不能包含 Service component。\");\n }\n if (runtime.profile === \"wasi\") {\n if (!hasService) {\n throw new Error(\"wasi runtime 必须包含 Service component。\");\n }\n return;\n }\n if (runtime.profile !== \"panel-only\" && !hasService) {\n throw new Error(`${runtime.profile} runtime 必须包含 Service component。`);\n }\n };\n\n private readComponentId = async (\n component: AppComponentReference,\n componentDirectory: string,\n ): Promise<string> => {\n const manifestFile = component.kind === \"panel\" ? \"panel-app.json\" : \"service-app.json\";\n const raw = JSON.parse(\n await readFile(path.join(componentDirectory, manifestFile), \"utf-8\"),\n ) as unknown;\n const manifest = this.assertObject(raw, `${component.path}/${manifestFile}`);\n const id = this.readRequiredString(manifest.id, `${component.path}/${manifestFile}.id`);\n if (!COMPONENT_ID_PATTERN.test(id)) {\n throw new Error(`组件 id 必须是 kebab-case:${id}`);\n }\n const directoryName = path.basename(componentDirectory);\n const expectedId = component.kind === \"panel\"\n ? directoryName.replace(/\\.panel$/, \"\")\n : directoryName;\n if (component.kind === \"panel\" && !directoryName.endsWith(\".panel\")) {\n throw new Error(`Panel component 目录必须以 .panel 结尾:${component.path}`);\n }\n if (id !== expectedId) {\n throw new Error(`组件 id 必须与目录名一致:期望 ${expectedId},实际 ${id}`);\n }\n return id;\n };\n\n private parsePermissions = (rawPermissions: unknown): AppPermissions | undefined => {\n if (rawPermissions === undefined) {\n return undefined;\n }\n const candidate = this.assertObject(rawPermissions, \"permissions\");\n return {\n documentAccess: this.parseDocumentAccess(candidate.documentAccess),\n secrets: this.parseSecretSlots(candidate.secrets),\n allowedDomains: this.parseStringArray(candidate.allowedDomains, \"permissions.allowedDomains\"),\n storage: this.parseStorage(candidate.storage),\n capabilities: this.parseCapabilities(candidate.capabilities),\n };\n };\n\n private parseDocumentAccess = (rawDocumentAccess: unknown): AppDocumentAccessScope[] | undefined => {\n if (rawDocumentAccess === undefined) {\n return undefined;\n }\n if (!Array.isArray(rawDocumentAccess)) {\n throw new Error(\"permissions.documentAccess 必须是数组。\");\n }\n return rawDocumentAccess.map((scope, index) => {\n const candidate = this.assertObject(scope, `permissions.documentAccess[${index}]`);\n const mode = this.readRequiredString(candidate.mode, `permissions.documentAccess[${index}].mode`);\n if (mode !== \"read\" && mode !== \"read-write\") {\n throw new Error(`permissions.documentAccess[${index}].mode 只支持 read 或 read-write。`);\n }\n return {\n id: this.readRequiredString(candidate.id, `permissions.documentAccess[${index}].id`),\n mode,\n description: this.readOptionalString(\n candidate.description,\n `permissions.documentAccess[${index}].description`,\n ),\n };\n });\n };\n\n private parseSecretSlots = (rawSecrets: unknown): AppSecretSlot[] | undefined => {\n if (rawSecrets === undefined) {\n return undefined;\n }\n if (!Array.isArray(rawSecrets)) {\n throw new Error(\"permissions.secrets 必须是数组。\");\n }\n const slots = rawSecrets.map((rawSlot, index) => {\n const field = `permissions.secrets[${index}]`;\n const candidate = this.assertObject(rawSlot, field);\n const unsupportedField = Object.keys(candidate).find(\n (key) => ![\"id\", \"title\", \"description\", \"required\"].includes(key),\n );\n if (unsupportedField) {\n throw new Error(`${field} 只能声明 id、title、description 和 required。`);\n }\n const id = this.readRequiredString(candidate.id, `${field}.id`);\n if (!SECRET_SLOT_ID_PATTERN.test(id)) {\n throw new Error(`${field}.id 必须是稳定的 lowercase slot id。`);\n }\n return {\n id,\n title: this.readRequiredString(candidate.title, `${field}.title`),\n description: this.readRequiredString(candidate.description, `${field}.description`),\n required: this.readBoolean(candidate.required, `${field}.required`),\n };\n });\n const duplicate = slots.find(\n (slot, index) => slots.findIndex((entry) => entry.id === slot.id) !== index,\n );\n if (duplicate) {\n throw new Error(`permissions.secrets 包含重复 slot id:${duplicate.id}`);\n }\n return slots;\n };\n\n private parseStringArray = (rawValue: unknown, fieldName: string): string[] | undefined => {\n if (rawValue === undefined) {\n return undefined;\n }\n if (!Array.isArray(rawValue)) {\n throw new Error(`${fieldName} 必须是字符串数组。`);\n }\n return rawValue.map((item, index) => this.readRequiredString(item, `${fieldName}[${index}]`));\n };\n\n private parseStorage = (rawStorage: unknown): AppPermissions[\"storage\"] | undefined => {\n if (rawStorage === undefined || typeof rawStorage === \"boolean\") {\n return rawStorage;\n }\n const candidate = this.assertObject(rawStorage, \"permissions.storage\");\n return { namespace: this.readOptionalString(candidate.namespace, \"permissions.storage.namespace\") };\n };\n\n private parseCapabilities = (rawCapabilities: unknown): AppPermissions[\"capabilities\"] | undefined => {\n if (rawCapabilities === undefined) {\n return undefined;\n }\n const candidate = this.assertObject(rawCapabilities, \"permissions.capabilities\");\n return {\n hostBridge: candidate.hostBridge === undefined\n ? undefined\n : this.readBoolean(candidate.hostBridge, \"permissions.capabilities.hostBridge\"),\n nativeProcess: candidate.nativeProcess === undefined\n ? undefined\n : this.readBoolean(candidate.nativeProcess, \"permissions.capabilities.nativeProcess\"),\n };\n };\n\n private assertResolvedFile = async (\n appDirectory: string,\n relativePath: string,\n fieldName: string,\n ): Promise<string> => {\n const resolvedPath = this.resolveInside(appDirectory, relativePath, fieldName);\n const stats = await lstat(resolvedPath);\n if (!stats.isFile() || stats.isSymbolicLink()) {\n throw new Error(`${fieldName} 必须指向包内普通文件。`);\n }\n return resolvedPath;\n };\n\n private assertResolvedDirectory = async (\n appDirectory: string,\n relativePath: string,\n fieldName: string,\n ): Promise<string> => {\n const resolvedPath = this.resolveInside(appDirectory, relativePath, fieldName);\n const stats = await lstat(resolvedPath);\n if (!stats.isDirectory() || stats.isSymbolicLink()) {\n throw new Error(`${fieldName} 必须指向包内普通目录。`);\n }\n await access(resolvedPath);\n return resolvedPath;\n };\n\n private resolveInside = (appDirectory: string, relativePath: string, fieldName: string): string => {\n const normalizedPath = this.normalizeRelativePath(relativePath, fieldName);\n const resolvedPath = path.resolve(appDirectory, normalizedPath);\n const relative = path.relative(appDirectory, resolvedPath);\n if (relative.startsWith(\"..\") || path.isAbsolute(relative)) {\n throw new Error(`${fieldName} 不能指向应用目录之外。`);\n }\n return resolvedPath;\n };\n\n private normalizeRelativePath = (relativePath: string, fieldName: string): string => {\n if (path.isAbsolute(relativePath) || relativePath.includes(\"\\0\")) {\n throw new Error(`${fieldName} 必须使用包内相对路径。`);\n }\n const segments = relativePath.replace(/\\\\/g, \"/\").split(\"/\");\n if (segments.some((segment) => !segment || segment === \".\" || segment === \"..\")) {\n throw new Error(`${fieldName} 包含非法路径片段。`);\n }\n return segments.join(\"/\");\n };\n\n private assertObject = (value: unknown, fieldName: string): Record<string, unknown> => {\n if (!value || typeof value !== \"object\" || Array.isArray(value)) {\n throw new Error(`${fieldName} 必须是对象。`);\n }\n return value as Record<string, unknown>;\n };\n\n private readRequiredString = (value: unknown, fieldName: string): string => {\n if (typeof value !== \"string\" || !value.trim()) {\n throw new Error(`${fieldName} 必须是非空字符串。`);\n }\n return value.trim();\n };\n\n private readOptionalString = (value: unknown, fieldName: string): string | undefined => {\n return value === undefined ? undefined : this.readRequiredString(value, fieldName);\n };\n\n private readNumber = (value: unknown, fieldName: string): number => {\n if (typeof value !== \"number\" || Number.isNaN(value)) {\n throw new Error(`${fieldName} 必须是数字。`);\n }\n return value;\n };\n\n private readBoolean = (value: unknown, fieldName: string): boolean => {\n if (typeof value !== \"boolean\") {\n throw new Error(`${fieldName} 必须是布尔值。`);\n }\n return value;\n };\n}\n"],"mappings":";;;;AAmBA,MAAM,qBAAqB;AAC3B,MAAM,uBAAuB;AAC7B,MAAM,yBAAyB;AAE/B,IAAa,qBAAb,MAAgC;CAC9B,YACE,wBAAyC,IAAI,0BAA0B,EACvE;AADiB,OAAA,wBAAA;;CAGnB,OAAO,OAAO,iBAAqD;EACjE,MAAM,sBAAsB,KAAK,QAAQ,aAAa;EACtD,MAAM,eAAe,KAAK,KAAK,qBAAqB,gBAAgB;EACpE,MAAM,cAAc,KAAK,MAAM,MAAM,SAAS,cAAc,QAAQ,CAAC;EACrE,MAAM,WAAW,KAAK,cAAc,YAAY;AAChD,SAAO,SAAS,kBAAkB,IAC9B,MAAM,KAAK,qBAAqB,qBAAqB,cAAc,SAAS,GAC5E,MAAM,KAAK,oBAAoB,qBAAqB,cAAc,SAAS;;CAGjF,aAAa,WAAkD;AAC7D,MAAI,OAAO,SAAS,kBAAkB,GAAG;GACvC,MAAM,kBAAkB;AACxB,UAAO;IACL,eAAe;IACf,IAAI,gBAAgB,SAAS;IAC7B,MAAM,gBAAgB,SAAS;IAC/B,SAAS,gBAAgB,SAAS;IAClC,aAAa,gBAAgB,SAAS;IACtC,cAAc,gBAAgB;IAC9B,UAAU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AAM,GAAG,UAAU,SAAS;AAExC,SAAO;;CAGT,eAAuB,OAAgB,cAA+B;AACpE,MAAI,OAAO,UAAU,UACnB,OAAM,IAAI,MAAM,GAAG,UAAU,UAAU;AAEzC,SAAO"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"app-permissions.service.d.ts","names":[],"sources":["../../src/services/app-permissions.service.ts"],"mappings":";;;;
|
|
1
|
+
{"version":3,"file":"app-permissions.service.d.ts","names":[],"sources":["../../src/services/app-permissions.service.ts"],"mappings":";;;;cAaa,qBAAA;EACX,OAAA,GACE,MAAA,EAAQ,iBAAA,EACR,gBAAA,EAAkB,mBAAA,EAClB,OAAA;IACE,KAAA;EAAA,MAED,OAAA,CAAQ,mBAAA;EAiCX,SAAA,GACE,MAAA,EAAQ,iBAAA,EACR,WAAA,EAAa,mBAAA,KACZ,oBAAA;EAAA,QAUK,oBAAA;AAAA"}
|
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
import { isAppStandaloneManifestBundle } from "../types/app-manifest.types.js";
|
|
2
1
|
import { access } from "node:fs/promises";
|
|
3
2
|
import path from "node:path";
|
|
4
3
|
//#region src/services/app-permissions.service.ts
|
|
5
4
|
var AppPermissionsService = class {
|
|
6
5
|
resolve = async (bundle, documentGrantMap, context) => {
|
|
7
|
-
if (!isAppStandaloneManifestBundle(bundle)) throw new Error("schema v2 组合包权限由 Panel/Service runtime grant 管理。");
|
|
8
6
|
const requestedPermissions = bundle.manifest.permissions ?? {};
|
|
9
7
|
return {
|
|
10
8
|
documentAccess: requestedPermissions.documentAccess === void 0 ? [] : await Promise.all(requestedPermissions.documentAccess.map((scope) => this.resolveDocumentGrant(scope, documentGrantMap, context?.appId))),
|
|
@@ -17,7 +15,6 @@ var AppPermissionsService = class {
|
|
|
17
15
|
};
|
|
18
16
|
};
|
|
19
17
|
summarize = (bundle, permissions) => {
|
|
20
|
-
if (!isAppStandaloneManifestBundle(bundle)) throw new Error("schema v2 组合包权限由 Panel/Service runtime grant 管理。");
|
|
21
18
|
return {
|
|
22
19
|
requested: bundle.manifest.permissions ?? {},
|
|
23
20
|
documentAccess: permissions.documentAccess,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"app-permissions.service.js","names":[],"sources":["../../src/services/app-permissions.service.ts"],"sourcesContent":["import { access } from \"node:fs/promises\";\nimport path from \"node:path\";\nimport type {\n AppDocumentAccessScope,\n AppManifestBundle,\n} from \"#app-runtime/types/app-manifest.types.js\";\nimport
|
|
1
|
+
{"version":3,"file":"app-permissions.service.js","names":[],"sources":["../../src/services/app-permissions.service.ts"],"sourcesContent":["import { access } from \"node:fs/promises\";\nimport path from \"node:path\";\nimport type {\n AppDocumentAccessScope,\n AppManifestBundle,\n} from \"#app-runtime/types/app-manifest.types.js\";\nimport type {\n AppDocumentGrantMap,\n AppPermissionSummary,\n ResolvedDocumentGrant,\n ResolvedPermissions,\n} from \"#app-runtime/types/app-permissions.types.js\";\n\nexport class AppPermissionsService {\n resolve = async (\n bundle: AppManifestBundle,\n documentGrantMap: AppDocumentGrantMap,\n context?: {\n appId?: string;\n },\n ): Promise<ResolvedPermissions> => {\n const requestedPermissions = bundle.manifest.permissions ?? {};\n const documentAccess =\n requestedPermissions.documentAccess === undefined\n ? []\n : await Promise.all(\n requestedPermissions.documentAccess.map((scope) =>\n this.resolveDocumentGrant(\n scope,\n documentGrantMap,\n context?.appId,\n ),\n ),\n );\n\n return {\n documentAccess,\n allowedDomains: requestedPermissions.allowedDomains ?? [],\n storage: {\n enabled:\n requestedPermissions.storage !== undefined &&\n requestedPermissions.storage !== false,\n namespace:\n typeof requestedPermissions.storage === \"object\"\n ? requestedPermissions.storage.namespace\n : undefined,\n },\n capabilities: {\n hostBridge: requestedPermissions.capabilities?.hostBridge !== false,\n },\n };\n };\n\n summarize = (\n bundle: AppManifestBundle,\n permissions: ResolvedPermissions,\n ): AppPermissionSummary => {\n return {\n requested: bundle.manifest.permissions ?? {},\n documentAccess: permissions.documentAccess,\n allowedDomains: permissions.allowedDomains,\n storage: permissions.storage,\n capabilities: permissions.capabilities,\n };\n };\n\n private resolveDocumentGrant = async (\n scope: AppDocumentAccessScope,\n documentGrantMap: AppDocumentGrantMap,\n appId?: string,\n ): Promise<ResolvedDocumentGrant> => {\n const grantedPath = documentGrantMap[scope.id];\n if (!grantedPath) {\n if (appId) {\n throw new Error(\n `缺少 documentAccess 授权:${scope.id}。请先执行 napp grant ${appId} --document ${scope.id}=/absolute/path`,\n );\n }\n throw new Error(\n `缺少 documentAccess 授权:${scope.id}。请通过 --document ${scope.id}=/absolute/path 提供授权。`,\n );\n }\n const normalizedPath = path.resolve(grantedPath);\n try {\n await access(normalizedPath);\n } catch {\n throw new Error(\n `documentAccess 授权路径不存在:${scope.id} -> ${normalizedPath}`,\n );\n }\n return {\n id: scope.id,\n mode: scope.mode,\n description: scope.description,\n path: normalizedPath,\n };\n };\n}\n"],"mappings":";;;AAaA,IAAa,wBAAb,MAAmC;CACjC,UAAU,OACR,QACA,kBACA,YAGiC;EACjC,MAAM,uBAAuB,OAAO,SAAS,eAAe,EAAE;AAc9D,SAAO;GACL,gBAbA,qBAAqB,mBAAmB,KAAA,IACpC,EAAE,GACF,MAAM,QAAQ,IACZ,qBAAqB,eAAe,KAAK,UACvC,KAAK,qBACH,OACA,kBACA,SAAS,MACV,CACF,CACF;GAIL,gBAAgB,qBAAqB,kBAAkB,EAAE;GACzD,SAAS;IACP,SACE,qBAAqB,YAAY,KAAA,KACjC,qBAAqB,YAAY;IACnC,WACE,OAAO,qBAAqB,YAAY,WACpC,qBAAqB,QAAQ,YAC7B,KAAA;IACP;GACD,cAAc,EACZ,YAAY,qBAAqB,cAAc,eAAe,OAC/D;GACF;;CAGH,aACE,QACA,gBACyB;AACzB,SAAO;GACL,WAAW,OAAO,SAAS,eAAe,EAAE;GAC5C,gBAAgB,YAAY;GAC5B,gBAAgB,YAAY;GAC5B,SAAS,YAAY;GACrB,cAAc,YAAY;GAC3B;;CAGH,uBAA+B,OAC7B,OACA,kBACA,UACmC;EACnC,MAAM,cAAc,iBAAiB,MAAM;AAC3C,MAAI,CAAC,aAAa;AAChB,OAAI,MACF,OAAM,IAAI,MACR,wBAAwB,MAAM,GAAG,mBAAmB,MAAM,cAAc,MAAM,GAAG,iBAClF;AAEH,SAAM,IAAI,MACR,wBAAwB,MAAM,GAAG,kBAAkB,MAAM,GAAG,uBAC7D;;EAEH,MAAM,iBAAiB,KAAK,QAAQ,YAAY;AAChD,MAAI;AACF,SAAM,OAAO,eAAe;UACtB;AACN,SAAM,IAAI,MACR,0BAA0B,MAAM,GAAG,MAAM,iBAC1C;;AAEH,SAAO;GACL,IAAI,MAAM;GACV,MAAM,MAAM;GACZ,aAAa,MAAM;GACnB,MAAM;GACP"}
|
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
import { AppPlatformTargetService } from "./app-platform-target.service.js";
|
|
2
|
+
import { AppInstanceStorageService } from "./app-instance-storage.service.js";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
//#region src/services/app-registry-parser.service.ts
|
|
5
|
+
const SAFE_APP_ID_PATTERN = /^[a-z0-9]+(?:[.-][a-z0-9]+)*$/;
|
|
6
|
+
const SAFE_VERSION_PATTERN = /^[0-9A-Za-z]+(?:[._+-][0-9A-Za-z]+)*$/;
|
|
7
|
+
const SAFE_COMPONENT_ID_PATTERN = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;
|
|
8
|
+
const SAFE_SECRET_SLOT_ID_PATTERN = /^[a-z][a-z0-9]*(?:[._-][a-z0-9]+)*$/;
|
|
9
|
+
var AppRegistryParserService = class {
|
|
10
|
+
instanceStorageService;
|
|
11
|
+
platformTargetService = new AppPlatformTargetService();
|
|
12
|
+
constructor(appHomeService) {
|
|
13
|
+
this.appHomeService = appHomeService;
|
|
14
|
+
this.instanceStorageService = new AppInstanceStorageService(appHomeService);
|
|
15
|
+
}
|
|
16
|
+
parse = (rawRegistry) => {
|
|
17
|
+
const candidate = this.assertRecord(rawRegistry, "registry.json");
|
|
18
|
+
if (candidate.schemaVersion !== 1) throw new Error("当前只支持 registry schemaVersion = 1。");
|
|
19
|
+
const rawApps = this.assertRecord(candidate.apps, "registry.apps");
|
|
20
|
+
const apps = {};
|
|
21
|
+
for (const [appId, rawApp] of Object.entries(rawApps)) {
|
|
22
|
+
if (!SAFE_APP_ID_PATTERN.test(appId)) throw new Error(`registry.apps 包含不安全的 appId:${appId}`);
|
|
23
|
+
const app = this.assertRecord(rawApp, `registry.apps.${appId}`);
|
|
24
|
+
const installedVersions = this.parseInstalledVersions(appId, app.installedVersions);
|
|
25
|
+
const activeVersion = this.requireString(app.activeVersion, `registry.apps.${appId}.activeVersion`);
|
|
26
|
+
if (!installedVersions[activeVersion]) throw new Error(`registry.apps.${appId} 缺少 activeVersion ${activeVersion}。`);
|
|
27
|
+
const dataDirectory = this.requireString(app.dataDirectory, `registry.apps.${appId}.dataDirectory`);
|
|
28
|
+
const firstInstalledAt = Object.values(installedVersions).map((version) => version.installedAt).filter((value) => typeof value === "string").sort()[0] ?? (/* @__PURE__ */ new Date(0)).toISOString();
|
|
29
|
+
const defaultInstance = this.parseDefaultInstance(app.defaultInstance, appId, dataDirectory, firstInstalledAt);
|
|
30
|
+
apps[appId] = {
|
|
31
|
+
...app,
|
|
32
|
+
appId,
|
|
33
|
+
publisher: app.publisher ?? installedVersions[activeVersion]?.publisher,
|
|
34
|
+
enabled: typeof app.enabled === "boolean" ? app.enabled : true,
|
|
35
|
+
activeVersion,
|
|
36
|
+
dataDirectory: defaultInstance.storage.dataDirectory,
|
|
37
|
+
defaultInstance,
|
|
38
|
+
installedVersions,
|
|
39
|
+
grants: this.parseDocumentGrants(app.grants, installedVersions[activeVersion]?.permissions ?? {}, `registry.apps.${appId}.grants`),
|
|
40
|
+
secretBindings: this.parseSecretBindings(app.secretBindings, `registry.apps.${appId}.secretBindings`)
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
return {
|
|
44
|
+
schemaVersion: 1,
|
|
45
|
+
apps,
|
|
46
|
+
suppressedBuiltIns: candidate.suppressedBuiltIns && typeof candidate.suppressedBuiltIns === "object" && !Array.isArray(candidate.suppressedBuiltIns) ? Object.fromEntries(Object.entries(candidate.suppressedBuiltIns).flatMap(([appId, raw]) => {
|
|
47
|
+
if (!raw || typeof raw !== "object" || Array.isArray(raw)) return [];
|
|
48
|
+
const suppressedAt = raw.suppressedAt;
|
|
49
|
+
return typeof suppressedAt === "string" ? [[appId, { suppressedAt }]] : [];
|
|
50
|
+
})) : {}
|
|
51
|
+
};
|
|
52
|
+
};
|
|
53
|
+
parseSecretSlotId = (slotId, field) => {
|
|
54
|
+
if (!SAFE_SECRET_SLOT_ID_PATTERN.test(slotId)) throw new Error(`${field} 必须是稳定的 lowercase slot id。`);
|
|
55
|
+
return slotId;
|
|
56
|
+
};
|
|
57
|
+
parseSecretBinding = (rawBinding, field) => {
|
|
58
|
+
const binding = this.assertRecord(rawBinding, field);
|
|
59
|
+
if (Object.prototype.hasOwnProperty.call(binding, "value")) throw new Error(`${field} 不能保存 Secret 明文。`);
|
|
60
|
+
if (Object.keys(binding).find((key) => ![
|
|
61
|
+
"source",
|
|
62
|
+
"provider",
|
|
63
|
+
"id"
|
|
64
|
+
].includes(key))) throw new Error(`${field} 只允许保存 source、provider 和 id。`);
|
|
65
|
+
const source = this.requireString(binding.source, `${field}.source`);
|
|
66
|
+
if (source !== "env" && source !== "file" && source !== "exec") throw new Error(`${field}.source 只支持 env、file 或 exec。`);
|
|
67
|
+
return {
|
|
68
|
+
source,
|
|
69
|
+
provider: binding.provider === void 0 ? void 0 : this.requireString(binding.provider, `${field}.provider`),
|
|
70
|
+
id: this.requireString(binding.id, `${field}.id`)
|
|
71
|
+
};
|
|
72
|
+
};
|
|
73
|
+
retainDeclaredSecretBindings = (bindings, permissions) => {
|
|
74
|
+
const declared = new Set((permissions.secrets ?? []).map((slot) => slot.id));
|
|
75
|
+
return Object.fromEntries(Object.entries(bindings).filter(([slotId]) => declared.has(slotId)));
|
|
76
|
+
};
|
|
77
|
+
retainCompatibleDocumentGrants = (grants, permissions) => {
|
|
78
|
+
const declared = new Map((permissions.documentAccess ?? []).map((scope) => [scope.id, scope]));
|
|
79
|
+
return Object.fromEntries(Object.entries(grants).filter(([scopeId, grant]) => {
|
|
80
|
+
const scope = declared.get(scopeId);
|
|
81
|
+
return scope && (scope.mode === "read-write" || grant.mode === "read");
|
|
82
|
+
}));
|
|
83
|
+
};
|
|
84
|
+
parseDocumentGrants = (raw, permissions, field) => {
|
|
85
|
+
if (raw === void 0) return {};
|
|
86
|
+
const declared = new Map((permissions.documentAccess ?? []).map((scope) => [scope.id, scope]));
|
|
87
|
+
return Object.fromEntries(Object.entries(this.assertRecord(raw, field)).flatMap(([scopeId, value]) => {
|
|
88
|
+
const scope = declared.get(scopeId);
|
|
89
|
+
if (!scope) return [];
|
|
90
|
+
if (typeof value === "string") return [[scopeId, {
|
|
91
|
+
path: value,
|
|
92
|
+
mode: scope.mode,
|
|
93
|
+
grantedAt: (/* @__PURE__ */ new Date(0)).toISOString()
|
|
94
|
+
}]];
|
|
95
|
+
const grant = this.assertRecord(value, `${field}.${scopeId}`);
|
|
96
|
+
const mode = grant.mode === "read-write" ? "read-write" : grant.mode === "read" ? "read" : void 0;
|
|
97
|
+
if (!mode || mode === "read-write" && scope.mode !== "read-write") return [];
|
|
98
|
+
return [[scopeId, {
|
|
99
|
+
path: this.requireString(grant.path, `${field}.${scopeId}.path`),
|
|
100
|
+
mode,
|
|
101
|
+
grantedAt: typeof grant.grantedAt === "string" ? grant.grantedAt : (/* @__PURE__ */ new Date(0)).toISOString()
|
|
102
|
+
}]];
|
|
103
|
+
}));
|
|
104
|
+
};
|
|
105
|
+
parseInstalledVersions = (appId, raw) => {
|
|
106
|
+
const installedVersions = {};
|
|
107
|
+
const rawVersions = this.assertRecord(raw, `registry.apps.${appId}.installedVersions`);
|
|
108
|
+
for (const [version, rawVersion] of Object.entries(rawVersions)) {
|
|
109
|
+
if (!SAFE_VERSION_PATTERN.test(version)) throw new Error(`registry.apps.${appId} 包含不安全的版本:${version}`);
|
|
110
|
+
const field = `registry.apps.${appId}.installedVersions.${version}`;
|
|
111
|
+
const versionRecord = this.assertRecord(rawVersion, field);
|
|
112
|
+
const installDirectory = this.requireString(versionRecord.installDirectory, `${field}.installDirectory`);
|
|
113
|
+
this.assertExactPath(installDirectory, this.appHomeService.getInstallDirectory(appId, version), `${field}.installDirectory`);
|
|
114
|
+
installedVersions[version] = {
|
|
115
|
+
...versionRecord,
|
|
116
|
+
version,
|
|
117
|
+
installDirectory: path.resolve(installDirectory),
|
|
118
|
+
manifestSchemaVersion: versionRecord.manifestSchemaVersion === 2 ? 2 : 1,
|
|
119
|
+
target: versionRecord.target === void 0 ? void 0 : this.platformTargetService.parseArtifactTarget(versionRecord.target, `${field}.target`),
|
|
120
|
+
components: this.parseComponents(versionRecord.components, installDirectory, `${field}.components`),
|
|
121
|
+
dataSchemaVersion: typeof versionRecord.dataSchemaVersion === "number" && Number.isSafeInteger(versionRecord.dataSchemaVersion) && versionRecord.dataSchemaVersion > 0 ? versionRecord.dataSchemaVersion : 1
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
return installedVersions;
|
|
125
|
+
};
|
|
126
|
+
parseDefaultInstance = (raw, appId, dataDirectory, createdAt) => {
|
|
127
|
+
if (!raw || typeof raw !== "object" || Array.isArray(raw)) {
|
|
128
|
+
this.assertExactPath(dataDirectory, this.appHomeService.getAppDataDirectory(appId), `registry.apps.${appId}.dataDirectory`);
|
|
129
|
+
return this.instanceStorageService.buildLegacyDefaultInstance({
|
|
130
|
+
appId,
|
|
131
|
+
dataDirectory,
|
|
132
|
+
createdAt
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
const instance = raw;
|
|
136
|
+
if (instance.id !== "default" || !instance.storage || typeof instance.storage !== "object" || instance.storage.layout !== "legacy" && instance.storage.layout !== "instance-v1") throw new Error(`registry.apps.${appId}.defaultInstance 无效。`);
|
|
137
|
+
if (instance.publisherId !== void 0 && typeof instance.publisherId !== "string") throw new Error(`registry.apps.${appId}.defaultInstance.publisherId 无效。`);
|
|
138
|
+
const dataSchemaVersion = typeof instance.dataSchemaVersion === "number" && Number.isSafeInteger(instance.dataSchemaVersion) && instance.dataSchemaVersion > 0 ? instance.dataSchemaVersion : 1;
|
|
139
|
+
const instanceCreatedAt = typeof instance.createdAt === "string" ? instance.createdAt : createdAt;
|
|
140
|
+
const instanceDirectory = path.resolve(this.appHomeService.getAppInstanceDirectory(appId, "default"));
|
|
141
|
+
const expectedStorage = {
|
|
142
|
+
layout: "instance-v1",
|
|
143
|
+
layoutVersion: 1,
|
|
144
|
+
instanceId: "default",
|
|
145
|
+
instanceDirectory,
|
|
146
|
+
dataDirectory: path.join(instanceDirectory, "data"),
|
|
147
|
+
configDirectory: path.join(instanceDirectory, "config"),
|
|
148
|
+
stateDirectory: path.join(instanceDirectory, "state"),
|
|
149
|
+
cacheDirectory: path.join(instanceDirectory, "cache"),
|
|
150
|
+
temporaryDirectory: path.join(instanceDirectory, "tmp"),
|
|
151
|
+
logsDirectory: path.join(instanceDirectory, "logs")
|
|
152
|
+
};
|
|
153
|
+
if (instance.storage.layout === "legacy") {
|
|
154
|
+
const legacy = this.appHomeService.getAppDataDirectory(appId);
|
|
155
|
+
this.assertExactPath(dataDirectory, legacy, `registry.apps.${appId}.dataDirectory`);
|
|
156
|
+
return {
|
|
157
|
+
id: "default",
|
|
158
|
+
publisherId: instance.publisherId,
|
|
159
|
+
storage: {
|
|
160
|
+
...expectedStorage,
|
|
161
|
+
layout: "legacy",
|
|
162
|
+
dataDirectory: path.resolve(legacy)
|
|
163
|
+
},
|
|
164
|
+
dataSchemaVersion,
|
|
165
|
+
createdAt: instanceCreatedAt,
|
|
166
|
+
migratedAt: instance.migratedAt,
|
|
167
|
+
legacyDataDirectory: path.resolve(legacy)
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
for (const [field, expectedPath] of Object.entries(expectedStorage).filter(([key]) => key.endsWith("Directory"))) this.assertExactPath(instance.storage[field], expectedPath, `registry.apps.${appId}.defaultInstance.storage.${field}`);
|
|
171
|
+
this.assertExactPath(dataDirectory, expectedStorage.dataDirectory, `registry.apps.${appId}.dataDirectory`);
|
|
172
|
+
return {
|
|
173
|
+
id: "default",
|
|
174
|
+
publisherId: instance.publisherId,
|
|
175
|
+
storage: expectedStorage,
|
|
176
|
+
dataSchemaVersion,
|
|
177
|
+
createdAt: instanceCreatedAt,
|
|
178
|
+
migratedAt: instance.migratedAt,
|
|
179
|
+
legacyDataDirectory: instance.legacyDataDirectory
|
|
180
|
+
};
|
|
181
|
+
};
|
|
182
|
+
parseSecretBindings = (raw, field) => {
|
|
183
|
+
if (raw === void 0) return {};
|
|
184
|
+
return Object.fromEntries(Object.entries(this.assertRecord(raw, field)).map(([slotId, binding]) => {
|
|
185
|
+
const normalized = this.parseSecretSlotId(slotId, `${field} slot id`);
|
|
186
|
+
return [normalized, this.parseSecretBinding(binding, `${field}.${normalized}`)];
|
|
187
|
+
}));
|
|
188
|
+
};
|
|
189
|
+
parseComponents = (raw, installDirectory, field) => {
|
|
190
|
+
if (raw === void 0) return void 0;
|
|
191
|
+
if (!Array.isArray(raw)) throw new Error(`${field} 必须是数组。`);
|
|
192
|
+
return raw.map((item, index) => {
|
|
193
|
+
const component = this.assertRecord(item, `${field}[${index}]`);
|
|
194
|
+
if (component.kind !== "panel" && component.kind !== "service") throw new Error(`${field}[${index}].kind 无效。`);
|
|
195
|
+
const id = this.requireString(component.id, `${field}[${index}].id`);
|
|
196
|
+
if (!SAFE_COMPONENT_ID_PATTERN.test(id)) throw new Error(`${field}[${index}].id 不安全。`);
|
|
197
|
+
const relativePath = this.requireString(component.path, `${field}[${index}].path`);
|
|
198
|
+
const directory = path.resolve(installDirectory, relativePath);
|
|
199
|
+
const relative = path.relative(path.resolve(installDirectory), directory);
|
|
200
|
+
if (!relative || relative.startsWith("..") || path.isAbsolute(relative)) throw new Error(`${field}[${index}].path 必须位于版本目录内。`);
|
|
201
|
+
const manifestPath = path.join(directory, component.kind === "panel" ? "panel-app.json" : "service-app.json");
|
|
202
|
+
this.assertExactPath(component.componentDirectory, directory, `${field}[${index}].componentDirectory`);
|
|
203
|
+
this.assertExactPath(component.manifestPath, manifestPath, `${field}[${index}].manifestPath`);
|
|
204
|
+
return {
|
|
205
|
+
kind: component.kind,
|
|
206
|
+
id,
|
|
207
|
+
path: relativePath,
|
|
208
|
+
componentDirectory: directory,
|
|
209
|
+
manifestPath
|
|
210
|
+
};
|
|
211
|
+
});
|
|
212
|
+
};
|
|
213
|
+
assertExactPath = (actual, expected, field) => {
|
|
214
|
+
if (typeof actual !== "string" || path.resolve(actual) !== path.resolve(expected)) throw new Error(`${field} 必须位于受管路径 ${path.resolve(expected)}。`);
|
|
215
|
+
};
|
|
216
|
+
assertRecord = (value, field) => {
|
|
217
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) throw new Error(`${field} 必须是对象。`);
|
|
218
|
+
return value;
|
|
219
|
+
};
|
|
220
|
+
requireString = (value, field) => {
|
|
221
|
+
if (typeof value !== "string" || !value.trim()) throw new Error(`${field} 必须是非空字符串。`);
|
|
222
|
+
return value;
|
|
223
|
+
};
|
|
224
|
+
};
|
|
225
|
+
//#endregion
|
|
226
|
+
export { AppRegistryParserService };
|
|
227
|
+
|
|
228
|
+
//# sourceMappingURL=app-registry-parser.service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"app-registry-parser.service.js","names":[],"sources":["../../src/services/app-registry-parser.service.ts"],"sourcesContent":["import path from \"node:path\";\nimport type {\n AppPermissions,\n AppResolvedComponent,\n} from \"#app-runtime/types/app-manifest.types.js\";\nimport type { AppStoredDocumentGrantMap } from \"#app-runtime/types/app-permissions.types.js\";\nimport type { AppHomeService } from \"#app-runtime/services/app-home.service.js\";\nimport { AppInstanceStorageService } from \"#app-runtime/services/app-instance-storage.service.js\";\nimport { AppPlatformTargetService } from \"#app-runtime/services/app-platform-target.service.js\";\nimport type { AppInstanceRecord } from \"#app-runtime/types/app-storage.types.js\";\nimport type {\n AppRegistry,\n AppRegistryAppRecord,\n AppRegistryInstalledVersion,\n AppSecretBinding,\n AppSecretBindingMap,\n} from \"#app-runtime/types/app-registry.types.js\";\n\nconst SAFE_APP_ID_PATTERN = /^[a-z0-9]+(?:[.-][a-z0-9]+)*$/;\nconst SAFE_VERSION_PATTERN = /^[0-9A-Za-z]+(?:[._+-][0-9A-Za-z]+)*$/;\nconst SAFE_COMPONENT_ID_PATTERN = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;\nconst SAFE_SECRET_SLOT_ID_PATTERN = /^[a-z][a-z0-9]*(?:[._-][a-z0-9]+)*$/;\n\nexport class AppRegistryParserService {\n private readonly instanceStorageService: AppInstanceStorageService;\n private readonly platformTargetService = new AppPlatformTargetService();\n\n constructor(private readonly appHomeService: AppHomeService) {\n this.instanceStorageService = new AppInstanceStorageService(appHomeService);\n }\n\n parse = (rawRegistry: unknown): AppRegistry => {\n const candidate = this.assertRecord(rawRegistry, \"registry.json\");\n if (candidate.schemaVersion !== 1)\n throw new Error(\"当前只支持 registry schemaVersion = 1。\");\n const rawApps = this.assertRecord(candidate.apps, \"registry.apps\");\n const apps: Record<string, AppRegistryAppRecord> = {};\n for (const [appId, rawApp] of Object.entries(rawApps)) {\n if (!SAFE_APP_ID_PATTERN.test(appId))\n throw new Error(`registry.apps 包含不安全的 appId:${appId}`);\n const app = this.assertRecord(\n rawApp,\n `registry.apps.${appId}`,\n ) as Partial<AppRegistryAppRecord>;\n const installedVersions = this.parseInstalledVersions(\n appId,\n app.installedVersions,\n );\n const activeVersion = this.requireString(\n app.activeVersion,\n `registry.apps.${appId}.activeVersion`,\n );\n if (!installedVersions[activeVersion])\n throw new Error(\n `registry.apps.${appId} 缺少 activeVersion ${activeVersion}。`,\n );\n const dataDirectory = this.requireString(\n app.dataDirectory,\n `registry.apps.${appId}.dataDirectory`,\n );\n const firstInstalledAt =\n Object.values(installedVersions)\n .map((version) => version.installedAt)\n .filter((value): value is string => typeof value === \"string\")\n .sort()[0] ?? new Date(0).toISOString();\n const defaultInstance = this.parseDefaultInstance(\n app.defaultInstance,\n appId,\n dataDirectory,\n firstInstalledAt,\n );\n apps[appId] = {\n ...(app as AppRegistryAppRecord),\n appId,\n publisher: app.publisher ?? installedVersions[activeVersion]?.publisher,\n enabled: typeof app.enabled === \"boolean\" ? app.enabled : true,\n activeVersion,\n dataDirectory: defaultInstance.storage.dataDirectory,\n defaultInstance,\n installedVersions,\n grants: this.parseDocumentGrants(\n app.grants,\n installedVersions[activeVersion]?.permissions ?? {},\n `registry.apps.${appId}.grants`,\n ),\n secretBindings: this.parseSecretBindings(\n app.secretBindings,\n `registry.apps.${appId}.secretBindings`,\n ),\n };\n }\n const suppressedBuiltIns =\n candidate.suppressedBuiltIns &&\n typeof candidate.suppressedBuiltIns === \"object\" &&\n !Array.isArray(candidate.suppressedBuiltIns)\n ? Object.fromEntries(\n Object.entries(candidate.suppressedBuiltIns).flatMap(\n ([appId, raw]) => {\n if (!raw || typeof raw !== \"object\" || Array.isArray(raw))\n return [];\n const suppressedAt = (raw as { suppressedAt?: unknown })\n .suppressedAt;\n return typeof suppressedAt === \"string\"\n ? [[appId, { suppressedAt }]]\n : [];\n },\n ),\n )\n : {};\n return { schemaVersion: 1, apps, suppressedBuiltIns };\n };\n\n parseSecretSlotId = (slotId: string, field: string): string => {\n if (!SAFE_SECRET_SLOT_ID_PATTERN.test(slotId))\n throw new Error(`${field} 必须是稳定的 lowercase slot id。`);\n return slotId;\n };\n\n parseSecretBinding = (\n rawBinding: unknown,\n field: string,\n ): AppSecretBinding => {\n const binding = this.assertRecord(rawBinding, field);\n if (Object.prototype.hasOwnProperty.call(binding, \"value\"))\n throw new Error(`${field} 不能保存 Secret 明文。`);\n const unsupportedField = Object.keys(binding).find(\n (key) => ![\"source\", \"provider\", \"id\"].includes(key),\n );\n if (unsupportedField)\n throw new Error(`${field} 只允许保存 source、provider 和 id。`);\n const source = this.requireString(binding.source, `${field}.source`);\n if (source !== \"env\" && source !== \"file\" && source !== \"exec\") {\n throw new Error(`${field}.source 只支持 env、file 或 exec。`);\n }\n return {\n source,\n provider:\n binding.provider === undefined\n ? undefined\n : this.requireString(binding.provider, `${field}.provider`),\n id: this.requireString(binding.id, `${field}.id`),\n };\n };\n\n retainDeclaredSecretBindings = (\n bindings: AppSecretBindingMap,\n permissions: AppPermissions,\n ): AppSecretBindingMap => {\n const declared = new Set(\n (permissions.secrets ?? []).map((slot) => slot.id),\n );\n return Object.fromEntries(\n Object.entries(bindings).filter(([slotId]) => declared.has(slotId)),\n );\n };\n\n retainCompatibleDocumentGrants = (\n grants: AppStoredDocumentGrantMap,\n permissions: AppPermissions,\n ): AppStoredDocumentGrantMap => {\n const declared = new Map(\n (permissions.documentAccess ?? []).map((scope) => [scope.id, scope]),\n );\n return Object.fromEntries(\n Object.entries(grants).filter(([scopeId, grant]) => {\n const scope = declared.get(scopeId);\n return scope && (scope.mode === \"read-write\" || grant.mode === \"read\");\n }),\n );\n };\n\n private parseDocumentGrants = (\n raw: unknown,\n permissions: AppPermissions,\n field: string,\n ): AppStoredDocumentGrantMap => {\n if (raw === undefined) return {};\n const declared = new Map(\n (permissions.documentAccess ?? []).map((scope) => [scope.id, scope]),\n );\n return Object.fromEntries(\n Object.entries(this.assertRecord(raw, field)).flatMap(\n ([scopeId, value]) => {\n const scope = declared.get(scopeId);\n if (!scope) return [];\n if (typeof value === \"string\") {\n return [\n [\n scopeId,\n {\n path: value,\n mode: scope.mode,\n grantedAt: new Date(0).toISOString(),\n },\n ],\n ];\n }\n const grant = this.assertRecord(value, `${field}.${scopeId}`);\n const mode =\n grant.mode === \"read-write\"\n ? \"read-write\"\n : grant.mode === \"read\"\n ? \"read\"\n : undefined;\n if (!mode || (mode === \"read-write\" && scope.mode !== \"read-write\"))\n return [];\n return [\n [\n scopeId,\n {\n path: this.requireString(\n grant.path,\n `${field}.${scopeId}.path`,\n ),\n mode,\n grantedAt:\n typeof grant.grantedAt === \"string\"\n ? grant.grantedAt\n : new Date(0).toISOString(),\n },\n ],\n ];\n },\n ),\n );\n };\n\n private parseInstalledVersions = (\n appId: string,\n raw: unknown,\n ): Record<string, AppRegistryInstalledVersion> => {\n const installedVersions: Record<string, AppRegistryInstalledVersion> = {};\n const rawVersions = this.assertRecord(\n raw,\n `registry.apps.${appId}.installedVersions`,\n );\n for (const [version, rawVersion] of Object.entries(rawVersions)) {\n if (!SAFE_VERSION_PATTERN.test(version))\n throw new Error(`registry.apps.${appId} 包含不安全的版本:${version}`);\n const field = `registry.apps.${appId}.installedVersions.${version}`;\n const versionRecord = this.assertRecord(\n rawVersion,\n field,\n ) as Partial<AppRegistryInstalledVersion>;\n const installDirectory = this.requireString(\n versionRecord.installDirectory,\n `${field}.installDirectory`,\n );\n this.assertExactPath(\n installDirectory,\n this.appHomeService.getInstallDirectory(appId, version),\n `${field}.installDirectory`,\n );\n installedVersions[version] = {\n ...(versionRecord as AppRegistryInstalledVersion),\n version,\n installDirectory: path.resolve(installDirectory),\n manifestSchemaVersion:\n versionRecord.manifestSchemaVersion === 2 ? 2 : 1,\n target:\n versionRecord.target === undefined\n ? undefined\n : this.platformTargetService.parseArtifactTarget(\n versionRecord.target,\n `${field}.target`,\n ),\n components: this.parseComponents(\n versionRecord.components,\n installDirectory,\n `${field}.components`,\n ),\n dataSchemaVersion:\n typeof versionRecord.dataSchemaVersion === \"number\" &&\n Number.isSafeInteger(versionRecord.dataSchemaVersion) &&\n versionRecord.dataSchemaVersion > 0\n ? versionRecord.dataSchemaVersion\n : 1,\n };\n }\n return installedVersions;\n };\n\n private parseDefaultInstance = (\n raw: unknown,\n appId: string,\n dataDirectory: string,\n createdAt: string,\n ): AppInstanceRecord => {\n if (!raw || typeof raw !== \"object\" || Array.isArray(raw)) {\n this.assertExactPath(\n dataDirectory,\n this.appHomeService.getAppDataDirectory(appId),\n `registry.apps.${appId}.dataDirectory`,\n );\n return this.instanceStorageService.buildLegacyDefaultInstance({\n appId,\n dataDirectory,\n createdAt,\n });\n }\n const instance = raw as Partial<AppInstanceRecord>;\n if (\n instance.id !== \"default\" ||\n !instance.storage ||\n typeof instance.storage !== \"object\" ||\n (instance.storage.layout !== \"legacy\" &&\n instance.storage.layout !== \"instance-v1\")\n ) {\n throw new Error(`registry.apps.${appId}.defaultInstance 无效。`);\n }\n if (\n instance.publisherId !== undefined &&\n typeof instance.publisherId !== \"string\"\n ) {\n throw new Error(\n `registry.apps.${appId}.defaultInstance.publisherId 无效。`,\n );\n }\n const dataSchemaVersion =\n typeof instance.dataSchemaVersion === \"number\" &&\n Number.isSafeInteger(instance.dataSchemaVersion) &&\n instance.dataSchemaVersion > 0\n ? instance.dataSchemaVersion\n : 1;\n const instanceCreatedAt =\n typeof instance.createdAt === \"string\" ? instance.createdAt : createdAt;\n const instanceDirectory = path.resolve(\n this.appHomeService.getAppInstanceDirectory(appId, \"default\"),\n );\n const expectedStorage = {\n layout: \"instance-v1\" as const,\n layoutVersion: 1 as const,\n instanceId: \"default\",\n instanceDirectory,\n dataDirectory: path.join(instanceDirectory, \"data\"),\n configDirectory: path.join(instanceDirectory, \"config\"),\n stateDirectory: path.join(instanceDirectory, \"state\"),\n cacheDirectory: path.join(instanceDirectory, \"cache\"),\n temporaryDirectory: path.join(instanceDirectory, \"tmp\"),\n logsDirectory: path.join(instanceDirectory, \"logs\"),\n };\n if (instance.storage.layout === \"legacy\") {\n const legacy = this.appHomeService.getAppDataDirectory(appId);\n this.assertExactPath(\n dataDirectory,\n legacy,\n `registry.apps.${appId}.dataDirectory`,\n );\n return {\n id: \"default\",\n publisherId: instance.publisherId,\n storage: {\n ...expectedStorage,\n layout: \"legacy\",\n dataDirectory: path.resolve(legacy),\n },\n dataSchemaVersion,\n createdAt: instanceCreatedAt,\n migratedAt: instance.migratedAt,\n legacyDataDirectory: path.resolve(legacy),\n };\n }\n for (const [field, expectedPath] of Object.entries(expectedStorage).filter(\n ([key]) => key.endsWith(\"Directory\"),\n )) {\n this.assertExactPath(\n instance.storage[field as keyof typeof instance.storage],\n expectedPath as string,\n `registry.apps.${appId}.defaultInstance.storage.${field}`,\n );\n }\n this.assertExactPath(\n dataDirectory,\n expectedStorage.dataDirectory,\n `registry.apps.${appId}.dataDirectory`,\n );\n return {\n id: \"default\",\n publisherId: instance.publisherId,\n storage: expectedStorage,\n dataSchemaVersion,\n createdAt: instanceCreatedAt,\n migratedAt: instance.migratedAt,\n legacyDataDirectory: instance.legacyDataDirectory,\n };\n };\n\n private parseSecretBindings = (\n raw: unknown,\n field: string,\n ): AppSecretBindingMap => {\n if (raw === undefined) return {};\n return Object.fromEntries(\n Object.entries(this.assertRecord(raw, field)).map(([slotId, binding]) => {\n const normalized = this.parseSecretSlotId(slotId, `${field} slot id`);\n return [\n normalized,\n this.parseSecretBinding(binding, `${field}.${normalized}`),\n ];\n }),\n );\n };\n\n private parseComponents = (\n raw: unknown,\n installDirectory: string,\n field: string,\n ): AppResolvedComponent[] | undefined => {\n if (raw === undefined) return undefined;\n if (!Array.isArray(raw)) throw new Error(`${field} 必须是数组。`);\n return raw.map((item, index) => {\n const component = this.assertRecord(item, `${field}[${index}]`);\n if (component.kind !== \"panel\" && component.kind !== \"service\")\n throw new Error(`${field}[${index}].kind 无效。`);\n const id = this.requireString(component.id, `${field}[${index}].id`);\n if (!SAFE_COMPONENT_ID_PATTERN.test(id))\n throw new Error(`${field}[${index}].id 不安全。`);\n const relativePath = this.requireString(\n component.path,\n `${field}[${index}].path`,\n );\n const directory = path.resolve(installDirectory, relativePath);\n const relative = path.relative(path.resolve(installDirectory), directory);\n if (!relative || relative.startsWith(\"..\") || path.isAbsolute(relative))\n throw new Error(`${field}[${index}].path 必须位于版本目录内。`);\n const manifestPath = path.join(\n directory,\n component.kind === \"panel\" ? \"panel-app.json\" : \"service-app.json\",\n );\n this.assertExactPath(\n component.componentDirectory,\n directory,\n `${field}[${index}].componentDirectory`,\n );\n this.assertExactPath(\n component.manifestPath,\n manifestPath,\n `${field}[${index}].manifestPath`,\n );\n return {\n kind: component.kind,\n id,\n path: relativePath,\n componentDirectory: directory,\n manifestPath,\n };\n });\n };\n\n private assertExactPath = (\n actual: unknown,\n expected: string,\n field: string,\n ): void => {\n if (\n typeof actual !== \"string\" ||\n path.resolve(actual) !== path.resolve(expected)\n )\n throw new Error(`${field} 必须位于受管路径 ${path.resolve(expected)}。`);\n };\n\n private assertRecord = (\n value: unknown,\n field: string,\n ): Record<string, unknown> => {\n if (!value || typeof value !== \"object\" || Array.isArray(value))\n throw new Error(`${field} 必须是对象。`);\n return value as Record<string, unknown>;\n };\n\n private requireString = (value: unknown, field: string): string => {\n if (typeof value !== \"string\" || !value.trim())\n throw new Error(`${field} 必须是非空字符串。`);\n return value;\n };\n}\n"],"mappings":";;;;AAkBA,MAAM,sBAAsB;AAC5B,MAAM,uBAAuB;AAC7B,MAAM,4BAA4B;AAClC,MAAM,8BAA8B;AAEpC,IAAa,2BAAb,MAAsC;CACpC;CACA,wBAAyC,IAAI,0BAA0B;CAEvE,YAAY,gBAAiD;AAAhC,OAAA,iBAAA;AAC3B,OAAK,yBAAyB,IAAI,0BAA0B,eAAe;;CAG7E,SAAS,gBAAsC;EAC7C,MAAM,YAAY,KAAK,aAAa,aAAa,gBAAgB;AACjE,MAAI,UAAU,kBAAkB,EAC9B,OAAM,IAAI,MAAM,oCAAoC;EACtD,MAAM,UAAU,KAAK,aAAa,UAAU,MAAM,gBAAgB;EAClE,MAAM,OAA6C,EAAE;AACrD,OAAK,MAAM,CAAC,OAAO,WAAW,OAAO,QAAQ,QAAQ,EAAE;AACrD,OAAI,CAAC,oBAAoB,KAAK,MAAM,CAClC,OAAM,IAAI,MAAM,8BAA8B,QAAQ;GACxD,MAAM,MAAM,KAAK,aACf,QACA,iBAAiB,QAClB;GACD,MAAM,oBAAoB,KAAK,uBAC7B,OACA,IAAI,kBACL;GACD,MAAM,gBAAgB,KAAK,cACzB,IAAI,eACJ,iBAAiB,MAAM,gBACxB;AACD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SAAS,CAE/C,OAAM,IAAI,MAAM,GAAG,MAAM,YAAY,KAAK,QAAQ,SAAS,CAAC,GAAG;;CAGnE,gBACE,OACA,UAC4B;AAC5B,MAAI,CAAC,SAAS,OAAO,UAAU,YAAY,MAAM,QAAQ,MAAM,CAC7D,OAAM,IAAI,MAAM,GAAG,MAAM,SAAS;AACpC,SAAO;;CAGT,iBAAyB,OAAgB,UAA0B;AACjE,MAAI,OAAO,UAAU,YAAY,CAAC,MAAM,MAAM,CAC5C,OAAM,IAAI,MAAM,GAAG,MAAM,YAAY;AACvC,SAAO"}
|
|
@@ -1,15 +1,14 @@
|
|
|
1
1
|
import { AppPermissions, AppPlatformSecuritySummary, AppResolvedComponent } from "../types/app-manifest.types.js";
|
|
2
|
-
import { AppDocumentGrantMap } from "../types/app-permissions.types.js";
|
|
2
|
+
import { AppDocumentGrantMap, AppStoredDocumentGrant } from "../types/app-permissions.types.js";
|
|
3
3
|
import { AppHomeService } from "./app-home.service.js";
|
|
4
4
|
import { AppInstanceRecord } from "../types/app-storage.types.js";
|
|
5
|
-
import { AppInstallSourceKind, AppRegistry, AppRegistryAppRecord, AppRegistryInstalledVersion } from "../types/app-registry.types.js";
|
|
5
|
+
import { AppInstallSourceKind, AppRegistry, AppRegistryAppRecord, AppRegistryInstalledVersion, AppSecretBinding } from "../types/app-registry.types.js";
|
|
6
6
|
|
|
7
7
|
//#region src/services/app-registry.service.d.ts
|
|
8
8
|
declare class AppRegistryService {
|
|
9
9
|
private readonly appHomeService;
|
|
10
|
-
private readonly instanceStorageService;
|
|
11
10
|
private readonly fileLockService;
|
|
12
|
-
private readonly
|
|
11
|
+
private readonly parser;
|
|
13
12
|
constructor(appHomeService?: AppHomeService);
|
|
14
13
|
load: () => Promise<AppRegistry>;
|
|
15
14
|
save: (registry: AppRegistry) => Promise<void>;
|
|
@@ -47,19 +46,16 @@ declare class AppRegistryService {
|
|
|
47
46
|
activateVersion: (appId: string, version: string) => Promise<AppRegistryAppRecord>;
|
|
48
47
|
setVersionContentDigest: (appId: string, version: string, contentSha256: string) => Promise<AppRegistryAppRecord>;
|
|
49
48
|
updateGrants: (appId: string, grants: AppDocumentGrantMap) => Promise<AppRegistryAppRecord>;
|
|
50
|
-
setDocumentGrant: (appId: string, scopeId: string, directoryPath: string) => Promise<AppRegistryAppRecord>;
|
|
49
|
+
setDocumentGrant: (appId: string, scopeId: string, directoryPath: string, mode?: "read" | "read-write") => Promise<AppRegistryAppRecord>;
|
|
50
|
+
restoreDocumentGrant: (appId: string, scopeId: string, grant: AppStoredDocumentGrant | undefined) => Promise<void>;
|
|
51
51
|
removeDocumentGrant: (appId: string, scopeId: string) => Promise<boolean>;
|
|
52
|
+
bindSecret: (appId: string, slotId: string, binding: AppSecretBinding) => Promise<AppRegistryAppRecord>;
|
|
53
|
+
unbindSecret: (appId: string, slotId: string) => Promise<boolean>;
|
|
52
54
|
removeApp: (appId: string) => Promise<AppRegistryAppRecord | undefined>;
|
|
53
55
|
isBuiltInSuppressed: (appId: string) => Promise<boolean>;
|
|
54
56
|
setBuiltInSuppressed: (appId: string, suppressed: boolean) => Promise<void>;
|
|
55
57
|
private updateApp;
|
|
56
58
|
private withMutation;
|
|
57
|
-
private parseRegistry;
|
|
58
|
-
private parseDefaultInstance;
|
|
59
|
-
private assertExactPath;
|
|
60
|
-
private parseComponents;
|
|
61
|
-
private assertRecord;
|
|
62
|
-
private requireString;
|
|
63
59
|
private isMissingFileError;
|
|
64
60
|
}
|
|
65
61
|
//#endregion
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"app-registry.service.d.ts","names":[],"sources":["../../src/services/app-registry.service.ts"],"mappings":";;;;;;;
|
|
1
|
+
{"version":3,"file":"app-registry.service.d.ts","names":[],"sources":["../../src/services/app-registry.service.ts"],"mappings":";;;;;;;cAuBa,kBAAA;EAAA,iBAKQ,cAAA;EAAA,iBAJF,eAAA;EAAA,iBACA,MAAA;cAGE,cAAA,GAAgB,cAAA;EAKnC,IAAA,QAAiB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