@nextclaw/app-runtime 0.5.0 → 0.7.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/README.md +39 -5
- package/dist/bundle/app-bundle.service.d.ts +7 -2
- package/dist/bundle/app-bundle.service.js +77 -16
- package/dist/bundle/app-bundle.types.d.ts +5 -1
- package/dist/cli/app-runtime-cli.service.d.ts +1 -0
- package/dist/cli/app-runtime-cli.service.js +23 -5
- package/dist/cli/app-runtime-options.service.d.ts +4 -0
- package/dist/cli/app-runtime-options.service.js +22 -4
- package/dist/commands/pack.controller.d.ts +1 -0
- package/dist/commands/pack.controller.js +4 -3
- package/dist/commands/publish.controller.d.ts +1 -0
- package/dist/commands/publish.controller.js +4 -3
- package/dist/commands/validate-publish.controller.d.ts +16 -0
- package/dist/commands/validate-publish.controller.js +33 -0
- package/dist/index.d.ts +7 -4
- package/dist/index.js +6 -3
- package/dist/install/app-installation.service.d.ts +4 -1
- package/dist/install/app-installation.service.js +21 -3
- package/dist/install/app-installation.types.d.ts +4 -0
- package/dist/package.js +1 -1
- package/dist/publish/app-publish-validation.service.d.ts +40 -0
- package/dist/publish/app-publish-validation.service.js +80 -0
- package/dist/publish/app-publish.service.d.ts +2 -0
- package/dist/publish/app-publish.service.js +9 -3
- package/dist/publish/app-publish.types.d.ts +4 -1
- package/dist/registry/app-registry.service.d.ts +1 -0
- package/dist/registry/app-registry.service.js +2 -1
- package/dist/registry/app-registry.types.d.ts +2 -0
- package/dist/registry/app-remote-registry-client.service.js +5 -1
- package/dist/registry/app-remote-registry.types.d.ts +5 -0
- package/dist/scaffold/app-scaffold.service.d.ts +4 -2
- package/dist/scaffold/app-scaffold.service.js +14 -1
- package/dist/scaffold/app-ts-http-lite-scaffold-template.service.d.ts +18 -0
- package/dist/scaffold/app-ts-http-lite-scaffold-template.service.js +267 -0
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -2,6 +2,7 @@ import { AppManifestService } from "./manifest/app-manifest.service.js";
|
|
|
2
2
|
import { AppBundleService } from "./bundle/app-bundle.service.js";
|
|
3
3
|
import { HostBridgeServer } from "./bridge/host-bridge.service.js";
|
|
4
4
|
import { AppTsHttpScaffoldTemplateService } from "./scaffold/app-ts-http-scaffold-template.service.js";
|
|
5
|
+
import { AppTsHttpLiteScaffoldTemplateService } from "./scaffold/app-ts-http-lite-scaffold-template.service.js";
|
|
5
6
|
import { AppScaffoldService } from "./scaffold/app-scaffold.service.js";
|
|
6
7
|
import { CreateCommand } from "./commands/create.controller.js";
|
|
7
8
|
import { UiServerService } from "./ui/ui-server.service.js";
|
|
@@ -12,6 +13,8 @@ import { WasmSidecarClientService } from "./sidecar/wasm-sidecar-client.service.
|
|
|
12
13
|
import { WasmMainRunnerService } from "./runtime/wasm-main-runner.service.js";
|
|
13
14
|
import { AppInstanceService } from "./host/app-instance.service.js";
|
|
14
15
|
import { AppHomeService } from "./paths/app-home.service.js";
|
|
16
|
+
import { AppRuntimeToolchainService } from "./runtime/app-runtime-toolchain.service.js";
|
|
17
|
+
import { AppBuildService } from "./runtime/app-build.service.js";
|
|
15
18
|
import { DEFAULT_APP_REGISTRY_URL } from "./registry/app-remote-registry.types.js";
|
|
16
19
|
import { AppRegistryConfigService } from "./registry/app-registry-config.service.js";
|
|
17
20
|
import { AppRemoteRegistryClientService } from "./registry/app-remote-registry-client.service.js";
|
|
@@ -35,8 +38,8 @@ import { RegistryCommand } from "./commands/registry.controller.js";
|
|
|
35
38
|
import { RevokeCommand } from "./commands/revoke.controller.js";
|
|
36
39
|
import { UninstallCommand } from "./commands/uninstall.controller.js";
|
|
37
40
|
import { UpdateCommand } from "./commands/update.controller.js";
|
|
38
|
-
import {
|
|
39
|
-
import {
|
|
41
|
+
import { AppPublishValidationService } from "./publish/app-publish-validation.service.js";
|
|
42
|
+
import { ValidatePublishCommand } from "./commands/validate-publish.controller.js";
|
|
40
43
|
import { AppRuntimeOptionsService } from "./cli/app-runtime-options.service.js";
|
|
41
44
|
import { AppRuntimeCliService } from "./cli/app-runtime-cli.service.js";
|
|
42
|
-
export { AppBuildService, AppBundleService, AppGrantService, AppHomeService, AppHostService, AppInstallationService, AppInstanceService, AppManifestService, AppMarketplaceClientService, AppMarketplaceMetadataService, AppPermissionsService, AppPublishService, AppRegistryConfigService, AppRegistryService, AppRemoteRegistryClientService, AppRuntimeCliService, AppRuntimeOptionsService, AppRuntimeToolchainService, AppScaffoldService, AppTsHttpScaffoldTemplateService, CreateCommand, DEFAULT_APP_MARKETPLACE_API_BASE, DEFAULT_APP_REGISTRY_URL, GrantCommand, HostBridgeServer, InfoCommand, InstallCommand, ListCommand, MainRunnerService, PackCommand, PermissionsCommand, PlatformAuthStateService, PublishCommand, RegistryCommand, RevokeCommand, UiServerService, UninstallCommand, UpdateCommand, WasmMainRunnerService, WasmSidecarClientService, WasmtimeWasiHttpComponentService };
|
|
45
|
+
export { AppBuildService, AppBundleService, AppGrantService, AppHomeService, AppHostService, AppInstallationService, AppInstanceService, AppManifestService, AppMarketplaceClientService, AppMarketplaceMetadataService, AppPermissionsService, AppPublishService, AppPublishValidationService, AppRegistryConfigService, AppRegistryService, AppRemoteRegistryClientService, AppRuntimeCliService, AppRuntimeOptionsService, AppRuntimeToolchainService, AppScaffoldService, AppTsHttpLiteScaffoldTemplateService, AppTsHttpScaffoldTemplateService, CreateCommand, DEFAULT_APP_MARKETPLACE_API_BASE, DEFAULT_APP_REGISTRY_URL, GrantCommand, HostBridgeServer, InfoCommand, InstallCommand, ListCommand, MainRunnerService, PackCommand, PermissionsCommand, PlatformAuthStateService, PublishCommand, RegistryCommand, RevokeCommand, UiServerService, UninstallCommand, UpdateCommand, ValidatePublishCommand, WasmMainRunnerService, WasmSidecarClientService, WasmtimeWasiHttpComponentService };
|
|
@@ -3,6 +3,7 @@ import { AppBundleService } from "../bundle/app-bundle.service.js";
|
|
|
3
3
|
import { AppDocumentGrantMap } from "../permissions/app-permissions.types.js";
|
|
4
4
|
import { AppHomeService } from "../paths/app-home.service.js";
|
|
5
5
|
import { AppRegistryService } from "../registry/app-registry.service.js";
|
|
6
|
+
import { AppBuildService } from "../runtime/app-build.service.js";
|
|
6
7
|
import { AppRegistryConfigService } from "../registry/app-registry-config.service.js";
|
|
7
8
|
import { AppRemoteRegistryClientService } from "../registry/app-remote-registry-client.service.js";
|
|
8
9
|
import { AppInfoResult, AppInstallResult, AppLaunchResolution, AppUninstallResult, AppUpdateResult, InstalledAppListItem } from "./app-installation.types.js";
|
|
@@ -12,10 +13,11 @@ declare class AppInstallationService {
|
|
|
12
13
|
private readonly appHomeService;
|
|
13
14
|
private readonly bundleService;
|
|
14
15
|
private readonly manifestService;
|
|
16
|
+
private readonly buildService;
|
|
15
17
|
private readonly registryService;
|
|
16
18
|
private readonly registryConfigService;
|
|
17
19
|
private readonly remoteRegistryClient;
|
|
18
|
-
constructor(appHomeService?: AppHomeService, bundleService?: AppBundleService, manifestService?: AppManifestService, registryService?: AppRegistryService, registryConfigService?: AppRegistryConfigService, remoteRegistryClient?: AppRemoteRegistryClientService);
|
|
20
|
+
constructor(appHomeService?: AppHomeService, bundleService?: AppBundleService, manifestService?: AppManifestService, buildService?: AppBuildService, registryService?: AppRegistryService, registryConfigService?: AppRegistryConfigService, remoteRegistryClient?: AppRemoteRegistryClientService);
|
|
19
21
|
install: (appSource: string, options?: {
|
|
20
22
|
registryUrl?: string;
|
|
21
23
|
}) => Promise<AppInstallResult>;
|
|
@@ -32,6 +34,7 @@ declare class AppInstallationService {
|
|
|
32
34
|
private detectLocalSourceType;
|
|
33
35
|
private parseRegistrySpec;
|
|
34
36
|
private looksLikePath;
|
|
37
|
+
private materializeDistribution;
|
|
35
38
|
}
|
|
36
39
|
//#endregion
|
|
37
40
|
export { AppInstallationService };
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { AppManifestService } from "../manifest/app-manifest.service.js";
|
|
2
2
|
import { AppBundleService } from "../bundle/app-bundle.service.js";
|
|
3
3
|
import { AppHomeService } from "../paths/app-home.service.js";
|
|
4
|
+
import { AppBuildService } from "../runtime/app-build.service.js";
|
|
4
5
|
import { AppRegistryConfigService } from "../registry/app-registry-config.service.js";
|
|
5
6
|
import { AppRemoteRegistryClientService } from "../registry/app-remote-registry-client.service.js";
|
|
6
7
|
import { AppRegistryService } from "../registry/app-registry.service.js";
|
|
@@ -8,10 +9,11 @@ import { access, cp, mkdir, rm } from "node:fs/promises";
|
|
|
8
9
|
import path from "node:path";
|
|
9
10
|
//#region src/install/app-installation.service.ts
|
|
10
11
|
var AppInstallationService = class {
|
|
11
|
-
constructor(appHomeService = new AppHomeService(), bundleService = new AppBundleService(), manifestService = new AppManifestService(), registryService = new AppRegistryService(appHomeService), registryConfigService = new AppRegistryConfigService(appHomeService), remoteRegistryClient = new AppRemoteRegistryClientService(new AppRegistryConfigService(appHomeService))) {
|
|
12
|
+
constructor(appHomeService = new AppHomeService(), bundleService = new AppBundleService(), manifestService = new AppManifestService(), buildService = new AppBuildService(), registryService = new AppRegistryService(appHomeService), registryConfigService = new AppRegistryConfigService(appHomeService), remoteRegistryClient = new AppRemoteRegistryClientService(new AppRegistryConfigService(appHomeService))) {
|
|
12
13
|
this.appHomeService = appHomeService;
|
|
13
14
|
this.bundleService = bundleService;
|
|
14
15
|
this.manifestService = manifestService;
|
|
16
|
+
this.buildService = buildService;
|
|
15
17
|
this.registryService = registryService;
|
|
16
18
|
this.registryConfigService = registryConfigService;
|
|
17
19
|
this.remoteRegistryClient = remoteRegistryClient;
|
|
@@ -28,10 +30,14 @@ var AppInstallationService = class {
|
|
|
28
30
|
targetDirectory: tempDirectory
|
|
29
31
|
})).bundlePath;
|
|
30
32
|
const extractedDirectory = path.join(tempDirectory, "bundle");
|
|
31
|
-
await this.bundleService.extractBundle({
|
|
33
|
+
const extractedMetadata = await this.bundleService.extractBundle({
|
|
32
34
|
bundlePath,
|
|
33
35
|
targetDirectory: extractedDirectory
|
|
34
36
|
});
|
|
37
|
+
await this.materializeDistribution({
|
|
38
|
+
appDirectory: extractedDirectory,
|
|
39
|
+
distributionMode: extractedMetadata.metadata.distributionMode
|
|
40
|
+
});
|
|
35
41
|
const manifestBundle = await this.manifestService.load(extractedDirectory);
|
|
36
42
|
const installDirectory = this.appHomeService.getInstallDirectory(manifestBundle.manifest.id, manifestBundle.manifest.version);
|
|
37
43
|
if (source.kind === "registry" && manifestBundle.manifest.id !== source.registryResolution.appId) throw new Error(`bundle manifest.appId 与 registry 请求不一致:期望 ${source.registryResolution.appId},实际 ${manifestBundle.manifest.id}`);
|
|
@@ -51,6 +57,7 @@ var AppInstallationService = class {
|
|
|
51
57
|
installDirectory,
|
|
52
58
|
dataDirectory,
|
|
53
59
|
sourceKind: source.kind,
|
|
60
|
+
distributionMode: source.kind === "registry" ? source.registryResolution.distributionMode : extractedMetadata.metadata.distributionMode,
|
|
54
61
|
sourceRef: source.sourceRef,
|
|
55
62
|
installedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
56
63
|
permissions: manifestBundle.manifest.permissions ?? {},
|
|
@@ -67,6 +74,7 @@ var AppInstallationService = class {
|
|
|
67
74
|
dataDirectory,
|
|
68
75
|
sourceKind: source.kind,
|
|
69
76
|
sourceRef: source.sourceRef,
|
|
77
|
+
distributionMode: registryRecord.installedVersions[registryRecord.activeVersion]?.distributionMode,
|
|
70
78
|
permissions: registryRecord.installedVersions[registryRecord.activeVersion]?.permissions ?? {},
|
|
71
79
|
registryUrl: registryRecord.installedVersions[registryRecord.activeVersion]?.registryUrl,
|
|
72
80
|
bundleUrl: registryRecord.installedVersions[registryRecord.activeVersion]?.bundleUrl,
|
|
@@ -138,7 +146,8 @@ var AppInstallationService = class {
|
|
|
138
146
|
appId: appRecord.appId,
|
|
139
147
|
name: appRecord.name,
|
|
140
148
|
activeVersion: appRecord.activeVersion,
|
|
141
|
-
sourceKind: appRecord.installedVersions[appRecord.activeVersion]?.sourceKind ?? "directory"
|
|
149
|
+
sourceKind: appRecord.installedVersions[appRecord.activeVersion]?.sourceKind ?? "directory",
|
|
150
|
+
distributionMode: appRecord.installedVersions[appRecord.activeVersion]?.distributionMode
|
|
142
151
|
}));
|
|
143
152
|
};
|
|
144
153
|
info = async (appId) => {
|
|
@@ -155,6 +164,7 @@ var AppInstallationService = class {
|
|
|
155
164
|
version: versionRecord.version,
|
|
156
165
|
installDirectory: versionRecord.installDirectory,
|
|
157
166
|
sourceKind: versionRecord.sourceKind,
|
|
167
|
+
distributionMode: versionRecord.distributionMode,
|
|
158
168
|
sourceRef: versionRecord.sourceRef,
|
|
159
169
|
installedAt: versionRecord.installedAt,
|
|
160
170
|
permissions: versionRecord.permissions,
|
|
@@ -251,6 +261,14 @@ var AppInstallationService = class {
|
|
|
251
261
|
looksLikePath = (appSource) => {
|
|
252
262
|
return appSource.startsWith(".") || appSource.startsWith("/") || appSource.includes(path.sep);
|
|
253
263
|
};
|
|
264
|
+
materializeDistribution = async (params) => {
|
|
265
|
+
if (params.distributionMode !== "source") return;
|
|
266
|
+
if ((await this.manifestService.load(params.appDirectory)).manifest.main.kind !== "wasi-http-component") return;
|
|
267
|
+
await this.buildService.build({
|
|
268
|
+
appDirectory: params.appDirectory,
|
|
269
|
+
install: true
|
|
270
|
+
});
|
|
271
|
+
};
|
|
254
272
|
};
|
|
255
273
|
//#endregion
|
|
256
274
|
export { AppInstallationService };
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { AppPermissions } from "../manifest/app-manifest.types.js";
|
|
2
|
+
import { AppDistributionMode } from "../bundle/app-bundle.types.js";
|
|
2
3
|
import { AppDocumentGrantMap } from "../permissions/app-permissions.types.js";
|
|
3
4
|
import { AppPublisher } from "../registry/app-remote-registry.types.js";
|
|
4
5
|
import { AppInstallSourceKind } from "../registry/app-registry.types.js";
|
|
@@ -11,6 +12,7 @@ type AppInstallResult = {
|
|
|
11
12
|
installDirectory: string;
|
|
12
13
|
dataDirectory: string;
|
|
13
14
|
sourceKind: AppInstallSourceKind;
|
|
15
|
+
distributionMode?: AppDistributionMode;
|
|
14
16
|
sourceRef: string;
|
|
15
17
|
permissions: AppPermissions;
|
|
16
18
|
registryUrl?: string;
|
|
@@ -28,6 +30,7 @@ type AppInfoResult = {
|
|
|
28
30
|
version: string;
|
|
29
31
|
installDirectory: string;
|
|
30
32
|
sourceKind: AppInstallSourceKind;
|
|
33
|
+
distributionMode?: AppDistributionMode;
|
|
31
34
|
sourceRef: string;
|
|
32
35
|
installedAt: string;
|
|
33
36
|
permissions: AppPermissions;
|
|
@@ -43,6 +46,7 @@ type InstalledAppListItem = {
|
|
|
43
46
|
name: string;
|
|
44
47
|
activeVersion: string;
|
|
45
48
|
sourceKind: AppInstallSourceKind;
|
|
49
|
+
distributionMode?: AppDistributionMode;
|
|
46
50
|
};
|
|
47
51
|
type AppUninstallResult = {
|
|
48
52
|
appId: string;
|
package/dist/package.js
CHANGED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { AppManifestService } from "../manifest/app-manifest.service.js";
|
|
2
|
+
import { AppDistributionMode } from "../bundle/app-bundle.types.js";
|
|
3
|
+
import { AppBundleService } from "../bundle/app-bundle.service.js";
|
|
4
|
+
import { AppMarketplaceMetadataService } from "./app-marketplace-metadata.service.js";
|
|
5
|
+
|
|
6
|
+
//#region src/publish/app-publish-validation.service.d.ts
|
|
7
|
+
type AppPublishValidationWarningCode = "main-entry-large" | "bundle-large";
|
|
8
|
+
type AppPublishValidationWarning = {
|
|
9
|
+
code: AppPublishValidationWarningCode;
|
|
10
|
+
message: string;
|
|
11
|
+
};
|
|
12
|
+
type AppPublishValidationResult = {
|
|
13
|
+
ok: boolean;
|
|
14
|
+
appDirectory: string;
|
|
15
|
+
metadataPath: string;
|
|
16
|
+
appId: string;
|
|
17
|
+
version: string;
|
|
18
|
+
distributionMode: AppDistributionMode;
|
|
19
|
+
mainKind: string;
|
|
20
|
+
mainEntryPath: string;
|
|
21
|
+
mainEntrySizeBytes: number;
|
|
22
|
+
bundleSizeBytes: number;
|
|
23
|
+
bundleFilePaths: string[];
|
|
24
|
+
warnings: AppPublishValidationWarning[];
|
|
25
|
+
};
|
|
26
|
+
declare class AppPublishValidationService {
|
|
27
|
+
private readonly manifestService;
|
|
28
|
+
private readonly metadataService;
|
|
29
|
+
private readonly bundleService;
|
|
30
|
+
constructor(manifestService?: AppManifestService, metadataService?: AppMarketplaceMetadataService, bundleService?: AppBundleService);
|
|
31
|
+
validate: (params: {
|
|
32
|
+
appDirectory: string;
|
|
33
|
+
metadataPath?: string;
|
|
34
|
+
mode?: AppDistributionMode;
|
|
35
|
+
}) => Promise<AppPublishValidationResult>;
|
|
36
|
+
private buildWarnings;
|
|
37
|
+
private formatBytes;
|
|
38
|
+
}
|
|
39
|
+
//#endregion
|
|
40
|
+
export { AppPublishValidationResult, AppPublishValidationService, AppPublishValidationWarning, AppPublishValidationWarningCode };
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { AppManifestService } from "../manifest/app-manifest.service.js";
|
|
2
|
+
import { AppBundleService } from "../bundle/app-bundle.service.js";
|
|
3
|
+
import { AppMarketplaceMetadataService } from "./app-marketplace-metadata.service.js";
|
|
4
|
+
import { mkdtemp, rm, stat } from "node:fs/promises";
|
|
5
|
+
import path from "node:path";
|
|
6
|
+
import { tmpdir } from "node:os";
|
|
7
|
+
//#region src/publish/app-publish-validation.service.ts
|
|
8
|
+
const MAIN_ENTRY_WARN_BYTES = 10 * 1024 * 1024;
|
|
9
|
+
const BUNDLE_WARN_BYTES = 5 * 1024 * 1024;
|
|
10
|
+
var AppPublishValidationService = class {
|
|
11
|
+
constructor(manifestService = new AppManifestService(), metadataService = new AppMarketplaceMetadataService(), bundleService = new AppBundleService()) {
|
|
12
|
+
this.manifestService = manifestService;
|
|
13
|
+
this.metadataService = metadataService;
|
|
14
|
+
this.bundleService = bundleService;
|
|
15
|
+
}
|
|
16
|
+
validate = async (params) => {
|
|
17
|
+
const { appDirectory: inputAppDirectory, metadataPath: inputMetadataPath, mode } = params;
|
|
18
|
+
const appDirectory = path.resolve(inputAppDirectory);
|
|
19
|
+
const distributionMode = mode ?? "source";
|
|
20
|
+
const bundle = await this.manifestService.load(appDirectory);
|
|
21
|
+
const metadataPath = inputMetadataPath ? path.resolve(inputMetadataPath) : path.join(appDirectory, "marketplace.json");
|
|
22
|
+
await this.metadataService.load({
|
|
23
|
+
appDirectory,
|
|
24
|
+
manifest: bundle.manifest,
|
|
25
|
+
metadataPath
|
|
26
|
+
});
|
|
27
|
+
const tempDirectory = await mkdtemp(path.join(tmpdir(), "napp-validate-publish-"));
|
|
28
|
+
try {
|
|
29
|
+
const packResult = await this.bundleService.packAppDirectory({
|
|
30
|
+
appDirectory,
|
|
31
|
+
outputPath: path.join(tempDirectory, `${bundle.manifest.id}-${bundle.manifest.version}.napp`),
|
|
32
|
+
mode: distributionMode
|
|
33
|
+
});
|
|
34
|
+
const mainEntryStats = await stat(bundle.mainEntryPath);
|
|
35
|
+
const warnings = this.buildWarnings({
|
|
36
|
+
mainEntrySizeBytes: mainEntryStats.size,
|
|
37
|
+
bundleSizeBytes: packResult.sizeBytes
|
|
38
|
+
});
|
|
39
|
+
return {
|
|
40
|
+
ok: true,
|
|
41
|
+
appDirectory,
|
|
42
|
+
metadataPath,
|
|
43
|
+
appId: bundle.manifest.id,
|
|
44
|
+
version: bundle.manifest.version,
|
|
45
|
+
distributionMode,
|
|
46
|
+
mainKind: bundle.manifest.main.kind,
|
|
47
|
+
mainEntryPath: bundle.mainEntryPath,
|
|
48
|
+
mainEntrySizeBytes: mainEntryStats.size,
|
|
49
|
+
bundleSizeBytes: packResult.sizeBytes,
|
|
50
|
+
bundleFilePaths: packResult.filePaths,
|
|
51
|
+
warnings
|
|
52
|
+
};
|
|
53
|
+
} finally {
|
|
54
|
+
await rm(tempDirectory, {
|
|
55
|
+
recursive: true,
|
|
56
|
+
force: true
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
buildWarnings = (params) => {
|
|
61
|
+
const { bundleSizeBytes, mainEntrySizeBytes } = params;
|
|
62
|
+
const warnings = [];
|
|
63
|
+
if (mainEntrySizeBytes > MAIN_ENTRY_WARN_BYTES) warnings.push({
|
|
64
|
+
code: "main-entry-large",
|
|
65
|
+
message: `main entry is ${this.formatBytes(mainEntrySizeBytes)}, which is larger than the ${this.formatBytes(MAIN_ENTRY_WARN_BYTES)} warning threshold.`
|
|
66
|
+
});
|
|
67
|
+
if (bundleSizeBytes > BUNDLE_WARN_BYTES) warnings.push({
|
|
68
|
+
code: "bundle-large",
|
|
69
|
+
message: `packed .napp is ${this.formatBytes(bundleSizeBytes)}, which is larger than the ${this.formatBytes(BUNDLE_WARN_BYTES)} warning threshold.`
|
|
70
|
+
});
|
|
71
|
+
return warnings;
|
|
72
|
+
};
|
|
73
|
+
formatBytes = (value) => {
|
|
74
|
+
if (value < 1024) return `${value} B`;
|
|
75
|
+
if (value < 1024 * 1024) return `${(value / 1024).toFixed(1)} KB`;
|
|
76
|
+
return `${(value / (1024 * 1024)).toFixed(1)} MB`;
|
|
77
|
+
};
|
|
78
|
+
};
|
|
79
|
+
//#endregion
|
|
80
|
+
export { AppPublishValidationService };
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { AppManifestService } from "../manifest/app-manifest.service.js";
|
|
2
|
+
import { AppDistributionMode } from "../bundle/app-bundle.types.js";
|
|
2
3
|
import { AppBundleService } from "../bundle/app-bundle.service.js";
|
|
3
4
|
import { AppPublishResult } from "./app-publish.types.js";
|
|
4
5
|
import { AppMarketplaceClientService } from "./app-marketplace-client.service.js";
|
|
@@ -18,6 +19,7 @@ declare class AppPublishService {
|
|
|
18
19
|
metadataPath?: string;
|
|
19
20
|
apiBaseUrl?: string;
|
|
20
21
|
token?: string;
|
|
22
|
+
mode?: AppDistributionMode;
|
|
21
23
|
}) => Promise<AppPublishResult>;
|
|
22
24
|
private resolvePublishActor;
|
|
23
25
|
private fetchCurrentPlatformUser;
|
|
@@ -18,6 +18,7 @@ var AppPublishService = class {
|
|
|
18
18
|
}
|
|
19
19
|
publish = async (params) => {
|
|
20
20
|
const { appDirectory: inputAppDirectory, metadataPath, apiBaseUrl, token } = params;
|
|
21
|
+
const distributionMode = params.mode ?? "source";
|
|
21
22
|
const appDirectory = path.resolve(inputAppDirectory);
|
|
22
23
|
const manifestBundle = await this.manifestService.load(appDirectory);
|
|
23
24
|
const metadata = await this.metadataService.load({
|
|
@@ -30,7 +31,10 @@ var AppPublishService = class {
|
|
|
30
31
|
explicitToken: token,
|
|
31
32
|
appId: manifestBundle.manifest.id
|
|
32
33
|
});
|
|
33
|
-
const bundle = await this.bundleService.packAppDirectory({
|
|
34
|
+
const bundle = await this.bundleService.packAppDirectory({
|
|
35
|
+
appDirectory,
|
|
36
|
+
mode: distributionMode
|
|
37
|
+
});
|
|
34
38
|
const bundleBytes = Buffer.from(await readFile(bundle.bundlePath));
|
|
35
39
|
const bundleSha256 = createHash("sha256").update(bundleBytes).digest("hex");
|
|
36
40
|
const publishFiles = await this.metadataService.collectPublishFiles({
|
|
@@ -52,6 +56,7 @@ var AppPublishService = class {
|
|
|
52
56
|
homepage: metadata.homepage,
|
|
53
57
|
featured: metadata.featured ?? false,
|
|
54
58
|
publisher: actor.publisher,
|
|
59
|
+
distributionMode,
|
|
55
60
|
manifest: manifestBundle.manifest,
|
|
56
61
|
permissions: manifestBundle.manifest.permissions ?? {},
|
|
57
62
|
bundleBase64: bundleBytes.toString("base64"),
|
|
@@ -67,9 +72,10 @@ var AppPublishService = class {
|
|
|
67
72
|
apiBaseUrl,
|
|
68
73
|
token: actor.token
|
|
69
74
|
}),
|
|
70
|
-
|
|
75
|
+
distribution: {
|
|
71
76
|
path: bundle.bundlePath,
|
|
72
|
-
sha256: bundleSha256
|
|
77
|
+
sha256: bundleSha256,
|
|
78
|
+
mode: distributionMode
|
|
73
79
|
}
|
|
74
80
|
};
|
|
75
81
|
};
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { AppManifest, AppPermissions } from "../manifest/app-manifest.types.js";
|
|
2
|
+
import { AppDistributionMode } from "../bundle/app-bundle.types.js";
|
|
2
3
|
import { AppPublisher } from "../registry/app-remote-registry.types.js";
|
|
3
4
|
|
|
4
5
|
//#region src/publish/app-publish.types.d.ts
|
|
@@ -35,6 +36,7 @@ type AppPublishPayload = {
|
|
|
35
36
|
homepage?: string;
|
|
36
37
|
featured: boolean;
|
|
37
38
|
publisher: AppPublisher;
|
|
39
|
+
distributionMode: AppDistributionMode;
|
|
38
40
|
manifest: AppManifest;
|
|
39
41
|
permissions: AppPermissions;
|
|
40
42
|
bundleBase64: string;
|
|
@@ -56,9 +58,10 @@ type AppPublishResult = {
|
|
|
56
58
|
registry: string;
|
|
57
59
|
};
|
|
58
60
|
};
|
|
59
|
-
|
|
61
|
+
distribution: {
|
|
60
62
|
path: string;
|
|
61
63
|
sha256: string;
|
|
64
|
+
mode: AppDistributionMode;
|
|
62
65
|
};
|
|
63
66
|
fileCount: number;
|
|
64
67
|
};
|
|
@@ -22,6 +22,7 @@ declare class AppRegistryService {
|
|
|
22
22
|
sourceKind: AppInstallSourceKind;
|
|
23
23
|
sourceRef: string;
|
|
24
24
|
installedAt: string;
|
|
25
|
+
distributionMode?: AppRegistryInstalledVersion["distributionMode"];
|
|
25
26
|
permissions: AppPermissions;
|
|
26
27
|
registryUrl?: string;
|
|
27
28
|
bundleUrl?: string;
|
|
@@ -36,7 +36,7 @@ var AppRegistryService = class {
|
|
|
36
36
|
return appRecord.installedVersions[appRecord.activeVersion];
|
|
37
37
|
};
|
|
38
38
|
upsertInstallation = async (params) => {
|
|
39
|
-
const { appId, name, description, version, installDirectory, dataDirectory, sourceKind, sourceRef, installedAt, permissions, registryUrl, bundleUrl, sha256, publisher } = params;
|
|
39
|
+
const { appId, name, description, version, installDirectory, dataDirectory, sourceKind, sourceRef, installedAt, distributionMode, permissions, registryUrl, bundleUrl, sha256, publisher } = params;
|
|
40
40
|
const registry = await this.load();
|
|
41
41
|
const currentRecord = registry.apps[appId];
|
|
42
42
|
const nextRecord = {
|
|
@@ -53,6 +53,7 @@ var AppRegistryService = class {
|
|
|
53
53
|
sourceKind,
|
|
54
54
|
sourceRef,
|
|
55
55
|
installedAt,
|
|
56
|
+
distributionMode,
|
|
56
57
|
permissions,
|
|
57
58
|
registryUrl,
|
|
58
59
|
bundleUrl,
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { AppPermissions } from "../manifest/app-manifest.types.js";
|
|
2
|
+
import { AppDistributionMode } from "../bundle/app-bundle.types.js";
|
|
2
3
|
import { AppDocumentGrantMap } from "../permissions/app-permissions.types.js";
|
|
3
4
|
import { AppPublisher } from "./app-remote-registry.types.js";
|
|
4
5
|
|
|
@@ -10,6 +11,7 @@ type AppRegistryInstalledVersion = {
|
|
|
10
11
|
sourceKind: AppInstallSourceKind;
|
|
11
12
|
sourceRef: string;
|
|
12
13
|
installedAt: string;
|
|
14
|
+
distributionMode?: AppDistributionMode;
|
|
13
15
|
permissions: AppPermissions;
|
|
14
16
|
registryUrl?: string;
|
|
15
17
|
bundleUrl?: string;
|
|
@@ -25,7 +25,8 @@ var AppRemoteRegistryClientService = class {
|
|
|
25
25
|
description: versionRecord.description ?? document.description,
|
|
26
26
|
publisher: versionRecord.publisher,
|
|
27
27
|
permissions: versionRecord.permissions,
|
|
28
|
-
|
|
28
|
+
distributionMode: versionRecord.dist.kind === "source" ? "source" : "bundle",
|
|
29
|
+
bundleUrl: new URL(versionRecord.dist.artifact ?? versionRecord.dist.source ?? versionRecord.dist.bundle, metadataUrl).toString(),
|
|
29
30
|
sha256: versionRecord.dist.sha256
|
|
30
31
|
};
|
|
31
32
|
};
|
|
@@ -72,7 +73,10 @@ var AppRemoteRegistryClientService = class {
|
|
|
72
73
|
publisher: this.parsePublisher(candidate.publisher, version),
|
|
73
74
|
permissions: candidate.permissions,
|
|
74
75
|
dist: {
|
|
76
|
+
kind: distCandidate.kind === "source" || distCandidate.kind === "bundle" ? distCandidate.kind : void 0,
|
|
77
|
+
artifact: this.readOptionalString(distCandidate.artifact, `versions.${version}.dist.artifact`),
|
|
75
78
|
bundle: this.readRequiredString(distCandidate.bundle, `versions.${version}.dist.bundle`),
|
|
79
|
+
source: this.readOptionalString(distCandidate.source, `versions.${version}.dist.source`),
|
|
76
80
|
sha256: this.readRequiredString(distCandidate.sha256, `versions.${version}.dist.sha256`)
|
|
77
81
|
}
|
|
78
82
|
};
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { AppPermissions } from "../manifest/app-manifest.types.js";
|
|
2
|
+
import { AppDistributionMode } from "../bundle/app-bundle.types.js";
|
|
2
3
|
|
|
3
4
|
//#region src/registry/app-remote-registry.types.d.ts
|
|
4
5
|
declare const DEFAULT_APP_REGISTRY_URL = "https://apps-registry.nextclaw.io/api/v1/apps/registry/";
|
|
@@ -25,7 +26,10 @@ type AppRemoteRegistryVersion = {
|
|
|
25
26
|
publisher?: AppPublisher;
|
|
26
27
|
permissions?: AppPermissions;
|
|
27
28
|
dist: {
|
|
29
|
+
kind?: AppDistributionMode;
|
|
30
|
+
artifact?: string;
|
|
28
31
|
bundle: string;
|
|
32
|
+
source?: string;
|
|
29
33
|
sha256: string;
|
|
30
34
|
};
|
|
31
35
|
};
|
|
@@ -45,6 +49,7 @@ type AppRemoteRegistryResolution = {
|
|
|
45
49
|
description?: string;
|
|
46
50
|
publisher?: AppPublisher;
|
|
47
51
|
permissions?: AppPermissions;
|
|
52
|
+
distributionMode: AppDistributionMode;
|
|
48
53
|
bundleUrl: string;
|
|
49
54
|
sha256: string;
|
|
50
55
|
};
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { AppTsHttpScaffoldTemplateService } from "./app-ts-http-scaffold-template.service.js";
|
|
2
|
+
import { AppTsHttpLiteScaffoldTemplateService } from "./app-ts-http-lite-scaffold-template.service.js";
|
|
2
3
|
|
|
3
4
|
//#region src/scaffold/app-scaffold.service.d.ts
|
|
4
|
-
type AppScaffoldTemplate = "starter" | "ts-http";
|
|
5
|
+
type AppScaffoldTemplate = "starter" | "ts-http" | "ts-http-lite";
|
|
5
6
|
type AppScaffoldResult = {
|
|
6
7
|
appDirectory: string;
|
|
7
8
|
manifestPath: string;
|
|
@@ -9,7 +10,8 @@ type AppScaffoldResult = {
|
|
|
9
10
|
};
|
|
10
11
|
declare class AppScaffoldService {
|
|
11
12
|
private readonly tsHttpTemplateService;
|
|
12
|
-
|
|
13
|
+
private readonly tsHttpLiteTemplateService;
|
|
14
|
+
constructor(tsHttpTemplateService?: AppTsHttpScaffoldTemplateService, tsHttpLiteTemplateService?: AppTsHttpLiteScaffoldTemplateService);
|
|
13
15
|
scaffold: (targetDirectory: string, options?: {
|
|
14
16
|
template?: AppScaffoldTemplate;
|
|
15
17
|
}) => Promise<AppScaffoldResult>;
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import { AppTsHttpScaffoldTemplateService } from "./app-ts-http-scaffold-template.service.js";
|
|
2
|
+
import { AppTsHttpLiteScaffoldTemplateService } from "./app-ts-http-lite-scaffold-template.service.js";
|
|
2
3
|
import { access, mkdir, writeFile } from "node:fs/promises";
|
|
3
4
|
import path from "node:path";
|
|
4
5
|
//#region src/scaffold/app-scaffold.service.ts
|
|
5
6
|
var AppScaffoldService = class {
|
|
6
|
-
constructor(tsHttpTemplateService = new AppTsHttpScaffoldTemplateService()) {
|
|
7
|
+
constructor(tsHttpTemplateService = new AppTsHttpScaffoldTemplateService(), tsHttpLiteTemplateService = new AppTsHttpLiteScaffoldTemplateService()) {
|
|
7
8
|
this.tsHttpTemplateService = tsHttpTemplateService;
|
|
9
|
+
this.tsHttpLiteTemplateService = tsHttpLiteTemplateService;
|
|
8
10
|
}
|
|
9
11
|
scaffold = async (targetDirectory, options) => {
|
|
10
12
|
const appDirectory = path.resolve(targetDirectory);
|
|
@@ -27,6 +29,17 @@ var AppScaffoldService = class {
|
|
|
27
29
|
template
|
|
28
30
|
};
|
|
29
31
|
}
|
|
32
|
+
if (template === "ts-http-lite") {
|
|
33
|
+
await this.writeTemplateFiles(appDirectory, this.tsHttpLiteTemplateService.buildFiles({
|
|
34
|
+
appId,
|
|
35
|
+
appName
|
|
36
|
+
}));
|
|
37
|
+
return {
|
|
38
|
+
appDirectory,
|
|
39
|
+
manifestPath,
|
|
40
|
+
template
|
|
41
|
+
};
|
|
42
|
+
}
|
|
30
43
|
await Promise.all([
|
|
31
44
|
writeFile(manifestPath, `${JSON.stringify(this.buildManifest(appId, appName), null, 2)}\n`, "utf-8"),
|
|
32
45
|
writeFile(path.join(appDirectory, "marketplace.json"), `${JSON.stringify(this.buildMarketplaceMetadata(appName), null, 2)}\n`, "utf-8"),
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { AppScaffoldFile, AppTsHttpScaffoldTemplateService } from "./app-ts-http-scaffold-template.service.js";
|
|
2
|
+
|
|
3
|
+
//#region src/scaffold/app-ts-http-lite-scaffold-template.service.d.ts
|
|
4
|
+
declare class AppTsHttpLiteScaffoldTemplateService {
|
|
5
|
+
private readonly standardTemplateService;
|
|
6
|
+
constructor(standardTemplateService?: AppTsHttpScaffoldTemplateService);
|
|
7
|
+
buildFiles: (params: {
|
|
8
|
+
appId: string;
|
|
9
|
+
appName: string;
|
|
10
|
+
}) => AppScaffoldFile[];
|
|
11
|
+
private buildMainPackageJson;
|
|
12
|
+
private buildMarketplaceMetadata;
|
|
13
|
+
private buildReadme;
|
|
14
|
+
private buildComponentSource;
|
|
15
|
+
private normalizeSlug;
|
|
16
|
+
}
|
|
17
|
+
//#endregion
|
|
18
|
+
export { AppTsHttpLiteScaffoldTemplateService };
|