@nimiplatform/app-tools 0.16.0-rc.10 → 0.16.0-rc.13
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 +59 -4
- package/bin/nimi-app.mjs +11 -4
- package/lib/app-doctor-update.mjs +22 -7
- package/lib/app-info.mjs +292 -1
- package/lib/app-pack.mjs +260 -15
- package/lib/app-project-lifecycle.mjs +41 -5
- package/lib/app-scaffold-capabilities.mjs +28 -0
- package/lib/app-scaffold-profiles.mjs +50 -0
- package/lib/app-scaffold.mjs +291 -16
- package/lib/desktop-window.mjs +106 -0
- package/lib/index.mjs +1 -0
- package/lib/storefront-media.mjs +154 -0
- package/package.json +4 -3
- package/scripts/dev-shell.mjs +13 -1
- package/templates/default-starter/README.md +14 -6
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
// @nimi-authority: rule.nimi.platform.app-ecosystem.p-napp-042a
|
|
2
|
+
// @nimi-authority: rule.nimi.platform.app-ecosystem.p-napp-042b
|
|
3
|
+
import { createHash } from 'node:crypto';
|
|
4
|
+
import { createRequire } from 'node:module';
|
|
5
|
+
import { PNG } from 'pngjs';
|
|
6
|
+
|
|
7
|
+
const require = createRequire(import.meta.url);
|
|
8
|
+
|
|
9
|
+
export const STOREFRONT_CATEGORIES = Object.freeze([
|
|
10
|
+
'companions-worlds',
|
|
11
|
+
'lifestyle',
|
|
12
|
+
'writing-notes',
|
|
13
|
+
'design-diagrams',
|
|
14
|
+
'audio-music',
|
|
15
|
+
'video-media',
|
|
16
|
+
'research-learning',
|
|
17
|
+
'productivity-automation',
|
|
18
|
+
'developer-tools',
|
|
19
|
+
]);
|
|
20
|
+
|
|
21
|
+
export const STOREFRONT_IMAGE_MAX_BYTES = 512 * 1024;
|
|
22
|
+
export const STOREFRONT_ARCHIVE_MAX_BYTES = 8 * 1024 * 1024;
|
|
23
|
+
export const STOREFRONT_COVER_BOUNDS = Object.freeze({ minW: 800, maxW: 2560, minH: 450, maxH: 1600 });
|
|
24
|
+
export const STOREFRONT_GALLERY_BOUNDS = Object.freeze({ minW: 640, maxW: 2560, minH: 360, maxH: 1600 });
|
|
25
|
+
|
|
26
|
+
export const STOREFRONT_LOCALE_PATTERN = /^[a-z]{2,3}(?:-[A-Za-z0-9]{2,8})*$/u;
|
|
27
|
+
export const STOREFRONT_GALLERY_ID_PATTERN = /^[a-z0-9](?:[a-z0-9-]{0,62}[a-z0-9])?$/u;
|
|
28
|
+
export const STOREFRONT_SHA256_PATTERN = /^[0-9a-f]{64}$/u;
|
|
29
|
+
|
|
30
|
+
const PNG_SIGNATURE = Buffer.from('89504e470d0a1a0a', 'hex');
|
|
31
|
+
|
|
32
|
+
export function storefrontMediaExtension(mediaType) {
|
|
33
|
+
if (mediaType === 'image/webp') return 'webp';
|
|
34
|
+
if (mediaType === 'image/png') return 'png';
|
|
35
|
+
throw new Error(`Unsupported storefront image media type: ${mediaType}`);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export function inspectStaticStorefrontImage(bytes, bounds, label = 'storefront image') {
|
|
39
|
+
if (!Buffer.isBuffer(bytes) || bytes.length === 0 || bytes.length > STOREFRONT_IMAGE_MAX_BYTES) {
|
|
40
|
+
throw new Error(`${label} must be a nonempty static WebP or PNG of at most ${STOREFRONT_IMAGE_MAX_BYTES} bytes`);
|
|
41
|
+
}
|
|
42
|
+
const sha256 = createHash('sha256').update(bytes).digest('hex');
|
|
43
|
+
|
|
44
|
+
if (bytes.length >= 8 && bytes.subarray(0, 8).equals(PNG_SIGNATURE)) {
|
|
45
|
+
let offset = 8;
|
|
46
|
+
let width = 0;
|
|
47
|
+
let height = 0;
|
|
48
|
+
let ended = false;
|
|
49
|
+
while (offset + 12 <= bytes.length) {
|
|
50
|
+
const length = bytes.readUInt32BE(offset);
|
|
51
|
+
const type = bytes.toString('ascii', offset + 4, offset + 8);
|
|
52
|
+
if (offset + length + 12 > bytes.length) throw new Error(`${label} PNG chunk is truncated`);
|
|
53
|
+
if (type === 'acTL') throw new Error(`${label} animated PNG (APNG) is not allowed`);
|
|
54
|
+
if (offset === 8 && (type !== 'IHDR' || length !== 13)) throw new Error(`${label} PNG header is invalid`);
|
|
55
|
+
if (type === 'IHDR') {
|
|
56
|
+
if (offset !== 8) throw new Error(`${label} PNG has more than one header`);
|
|
57
|
+
width = bytes.readUInt32BE(offset + 8);
|
|
58
|
+
height = bytes.readUInt32BE(offset + 12);
|
|
59
|
+
}
|
|
60
|
+
offset += length + 12;
|
|
61
|
+
if (type === 'IEND') {
|
|
62
|
+
ended = length === 0 && offset === bytes.length;
|
|
63
|
+
break;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
if (!ended) throw new Error(`${label} PNG is truncated or has trailing bytes`);
|
|
67
|
+
assertImageBounds(width, height, bounds, label);
|
|
68
|
+
const decoded = PNG.sync.read(bytes, { checkCRC: true });
|
|
69
|
+
if (decoded.width !== width || decoded.height !== height) throw new Error(`${label} PNG dimensions are inconsistent`);
|
|
70
|
+
return { media_type: 'image/png', width, height, size: bytes.length, sha256 };
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
if (bytes.length >= 16 && bytes.toString('ascii', 0, 4) === 'RIFF' && bytes.toString('ascii', 8, 12) === 'WEBP') {
|
|
74
|
+
const riffSize = bytes.readUInt32LE(4);
|
|
75
|
+
if (riffSize + 8 !== bytes.length) throw new Error(`${label} WebP RIFF size does not match file length`);
|
|
76
|
+
let offset = 12;
|
|
77
|
+
let width = 0;
|
|
78
|
+
let height = 0;
|
|
79
|
+
let hasBitstream = false;
|
|
80
|
+
while (offset < bytes.length) {
|
|
81
|
+
if (offset + 8 > bytes.length) throw new Error(`${label} WebP chunk header is truncated`);
|
|
82
|
+
const type = bytes.toString('ascii', offset, offset + 4);
|
|
83
|
+
const chunkSize = bytes.readUInt32LE(offset + 4);
|
|
84
|
+
const dataStart = offset + 8;
|
|
85
|
+
const dataEnd = dataStart + chunkSize;
|
|
86
|
+
const paddedEnd = dataEnd + (chunkSize & 1);
|
|
87
|
+
if (paddedEnd > bytes.length) throw new Error(`${label} WebP chunk ${type} is truncated`);
|
|
88
|
+
if (type === 'ANIM' || type === 'ANMF') throw new Error(`${label} animated WebP is not allowed`);
|
|
89
|
+
if (type === 'VP8X') {
|
|
90
|
+
if (offset !== 12 || chunkSize !== 10) throw new Error(`${label} WebP VP8X chunk is invalid`);
|
|
91
|
+
const flags = bytes[dataStart];
|
|
92
|
+
if ((flags & 0x02) !== 0) throw new Error(`${label} animated WebP (VP8X animation flag) is not allowed`);
|
|
93
|
+
width = 1 + (bytes[dataStart + 4] | (bytes[dataStart + 5] << 8) | (bytes[dataStart + 6] << 16));
|
|
94
|
+
height = 1 + (bytes[dataStart + 7] | (bytes[dataStart + 8] << 8) | (bytes[dataStart + 9] << 16));
|
|
95
|
+
} else if (type === 'VP8 ' || type === 'VP8L') {
|
|
96
|
+
const frame = bytes.subarray(dataStart, dataEnd);
|
|
97
|
+
const dimensions = webpFrameDimensions(type, frame, label);
|
|
98
|
+
if (hasBitstream || (width !== 0 && (width !== dimensions.width || height !== dimensions.height))) {
|
|
99
|
+
throw new Error(`${label} WebP dimensions are inconsistent`);
|
|
100
|
+
}
|
|
101
|
+
width = dimensions.width;
|
|
102
|
+
height = dimensions.height;
|
|
103
|
+
hasBitstream = true;
|
|
104
|
+
}
|
|
105
|
+
offset = paddedEnd;
|
|
106
|
+
}
|
|
107
|
+
if (!hasBitstream || width <= 0 || height <= 0) throw new Error(`${label} WebP is missing image bitstream or dimensions`);
|
|
108
|
+
assertImageBounds(width, height, bounds, label);
|
|
109
|
+
const { Transformer } = require('@napi-rs/image');
|
|
110
|
+
try {
|
|
111
|
+
const image = new Transformer(bytes);
|
|
112
|
+
const pixels = image.rawPixelsSync();
|
|
113
|
+
const decoded = image.metadataSync();
|
|
114
|
+
if (decoded.width !== width || decoded.height !== height || !pixels.length) throw new Error('invalid decoded image');
|
|
115
|
+
} catch (cause) {
|
|
116
|
+
throw new Error(`${label} WebP pixels could not be decoded`, { cause });
|
|
117
|
+
}
|
|
118
|
+
return { media_type: 'image/webp', width, height, size: bytes.length, sha256 };
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
throw new Error(`${label} must be a static WebP or PNG image`);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
function webpFrameDimensions(type, frame, label) {
|
|
125
|
+
if (type === 'VP8L') {
|
|
126
|
+
if (frame.length < 5 || frame[0] !== 0x2f) throw new Error(`${label} WebP VP8L header is invalid`);
|
|
127
|
+
const bits = frame.readUInt32LE(1);
|
|
128
|
+
return { width: (bits & 0x3fff) + 1, height: ((bits >>> 14) & 0x3fff) + 1 };
|
|
129
|
+
}
|
|
130
|
+
if (frame.length < 10 || (frame[0] & 1) !== 0 || frame[3] !== 0x9d || frame[4] !== 1 || frame[5] !== 0x2a) {
|
|
131
|
+
throw new Error(`${label} WebP VP8 keyframe header is invalid`);
|
|
132
|
+
}
|
|
133
|
+
return { width: frame.readUInt16LE(6) & 0x3fff, height: frame.readUInt16LE(8) & 0x3fff };
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
function assertImageBounds(width, height, bounds, label) {
|
|
137
|
+
if (width < bounds.minW || width > bounds.maxW || height < bounds.minH || height > bounds.maxH) {
|
|
138
|
+
throw new Error(`${label} dimensions ${width}x${height} are outside allowed bounds (${bounds.minW}-${bounds.maxW} x ${bounds.minH}-${bounds.maxH})`);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
export function collectStorefrontImageRefs(media) {
|
|
143
|
+
const refs = [];
|
|
144
|
+
if (!media) return refs;
|
|
145
|
+
if (media.cover) {
|
|
146
|
+
refs.push(media.cover.default);
|
|
147
|
+
for (const ref of Object.values(media.cover.locales || {})) refs.push(ref);
|
|
148
|
+
}
|
|
149
|
+
for (const item of media.gallery || []) {
|
|
150
|
+
refs.push(item.default);
|
|
151
|
+
for (const ref of Object.values(item.locales || {})) refs.push(ref);
|
|
152
|
+
}
|
|
153
|
+
return refs;
|
|
154
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nimiplatform/app-tools",
|
|
3
|
-
"version": "0.16.0-rc.
|
|
3
|
+
"version": "0.16.0-rc.13",
|
|
4
4
|
"description": "Public app-authoring CLI for Nimi App projects.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"type": "module",
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
},
|
|
20
20
|
"nimiScaffoldVersions": {
|
|
21
21
|
"sdkVersion": "^0.24.0-rc.10",
|
|
22
|
-
"appToolsVersion": "^0.16.0-rc.
|
|
22
|
+
"appToolsVersion": "^0.16.0-rc.13",
|
|
23
23
|
"nimicodingVersion": "0.7.0",
|
|
24
24
|
"aiSdkVersion": "^7.0.171",
|
|
25
25
|
"kitVersion": "^0.24.0-rc.16",
|
|
@@ -68,7 +68,7 @@
|
|
|
68
68
|
"prepublishOnly": "pnpm run build",
|
|
69
69
|
"test": "node ../scripts/with-workspace-surfaces.mjs -- pnpm run test:prepared",
|
|
70
70
|
"test:large-archive": "node --test test/app-pack-large.test.mjs",
|
|
71
|
-
"test:prepared": "node scripts/sync-scaffold-versions.mjs --check && node --test test/dev-shell.test.mjs && node --test test/app-icons.test.mjs test/app-dependency-combinations.test.mjs test/app-safety-profile.test.mjs test/app-project-lifecycle.test.mjs test/app-pack.test.mjs test/app-pack-large.test.mjs test/app-scaffold.test.mjs test/web-carrier.test.mjs test/hosted-web-release.test.mjs test/mobile-development.test.mjs"
|
|
71
|
+
"test:prepared": "node scripts/sync-scaffold-versions.mjs --check && node --test test/dev-shell.test.mjs && node --test test/app-icons.test.mjs test/app-storefront.test.mjs test/app-dependency-combinations.test.mjs test/app-safety-profile.test.mjs test/app-project-lifecycle.test.mjs test/app-pack.test.mjs test/app-pack-large.test.mjs test/app-scaffold.test.mjs test/managed-web-carrier.test.mjs test/web-carrier.test.mjs test/hosted-web-release.test.mjs test/mobile-development.test.mjs"
|
|
72
72
|
},
|
|
73
73
|
"files": [
|
|
74
74
|
"bin",
|
|
@@ -79,6 +79,7 @@
|
|
|
79
79
|
"README.md"
|
|
80
80
|
],
|
|
81
81
|
"dependencies": {
|
|
82
|
+
"@napi-rs/image": "1.16.0",
|
|
82
83
|
"pngjs": "7.0.0",
|
|
83
84
|
"semver": "^7.8.6",
|
|
84
85
|
"typescript": "6.0.3",
|
package/scripts/dev-shell.mjs
CHANGED
|
@@ -46,7 +46,9 @@ export async function runDevShell(cwd, options = {}) {
|
|
|
46
46
|
if (typeof fetchImpl !== 'function') {
|
|
47
47
|
throw new DevShellError('local-development-launcher-unavailable', 'This Node.js runtime does not provide fetch.');
|
|
48
48
|
}
|
|
49
|
-
if (!options.listRegistrations
|
|
49
|
+
if (!options.listRegistrations && !(await isManagedWebProject(projectRoot))) {
|
|
50
|
+
await assertProjectElectronRuntime(projectRoot);
|
|
51
|
+
}
|
|
50
52
|
let registrationSelector = options.resume;
|
|
51
53
|
if (options.listRegistrations || (!options.resume && !options.newRegistration)) {
|
|
52
54
|
const listed = await postJson(fetchImpl, descriptor, '/v1/registrations', {
|
|
@@ -207,6 +209,16 @@ export async function assertProjectElectronRuntime(projectRoot, platform = proce
|
|
|
207
209
|
}
|
|
208
210
|
}
|
|
209
211
|
|
|
212
|
+
export async function isManagedWebProject(projectRoot) {
|
|
213
|
+
try {
|
|
214
|
+
const raw = await readFile(path.join(projectRoot, '.nimi', 'config', 'build-profile.yaml'), 'utf8');
|
|
215
|
+
const parsed = parseYaml(raw);
|
|
216
|
+
return parsed?.build_profile_ref === 'managed-web-pnpm-vite';
|
|
217
|
+
} catch {
|
|
218
|
+
return false;
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
|
|
210
222
|
export class DevShellError extends Error {
|
|
211
223
|
constructor(reasonCode, message) {
|
|
212
224
|
super(message);
|
|
@@ -24,18 +24,23 @@ pnpm install
|
|
|
24
24
|
pnpm run init
|
|
25
25
|
pnpm run sync
|
|
26
26
|
pnpm run check
|
|
27
|
-
pnpm run
|
|
28
|
-
pnpm run app:build -- --target windows-x86_64
|
|
27
|
+
pnpm run app:build
|
|
29
28
|
pnpm dev
|
|
30
29
|
```
|
|
31
30
|
|
|
32
31
|
### Local Development
|
|
33
32
|
|
|
34
|
-
|
|
33
|
+
Open Nimi Home, sign in and enable Developer Mode before running `pnpm dev`. Add an App test under `test/*.test.mjs` and run it with `pnpm test`.
|
|
35
34
|
|
|
36
35
|
### Building & Carrier Layout
|
|
37
36
|
|
|
38
|
-
|
|
37
|
+
<!-- carrier: managed-web -->
|
|
38
|
+
This App builds static frontend files into `dist/renderer/`. Nimi Home runs them in its managed desktop carrier on Windows x64 and macOS arm64. Both platforms use the same package.
|
|
39
|
+
|
|
40
|
+
Set the summary, PNG icon and release notes in `nimi.app.yaml` and the license identifier in `package.json`. Run `pnpm exec nimi-app pack --target desktop-universal` after building. The resulting `.nimiapp` is in `dist/nimi-app/`.
|
|
41
|
+
<!-- end carrier -->
|
|
42
|
+
<!-- carrier: native -->
|
|
43
|
+
The `windows-x86_64` build outputs a fresh non-installer Electron directory at `dist-electron-package/acme-widget-shell-win32-x64/`, containing:
|
|
39
44
|
|
|
40
45
|
- The App-specific executable `acme-widget-shell.exe`
|
|
41
46
|
- ASAR-packaged JavaScript and renderer assets
|
|
@@ -45,11 +50,14 @@ The production bundle rejects `--nimi-dev-renderer-url`. The protected native bi
|
|
|
45
50
|
|
|
46
51
|
Electron packages target Windows x64 and macOS arm64. Standard builds use Node, pnpm and the prebuilt native Kit package for the target.
|
|
47
52
|
|
|
53
|
+
Run `pnpm exec nimi-app pack --target windows-x86_64` on Windows or `pnpm exec nimi-app pack --target macos-aarch64` on macOS after building. Publishers may sign the Windows executable before packing. Production packing records the observed Authenticode signature or an explicit unsigned posture.
|
|
54
|
+
<!-- end carrier -->
|
|
55
|
+
|
|
48
56
|
### Packaging & Release Boundaries
|
|
49
57
|
|
|
50
|
-
|
|
58
|
+
Pushing a protected version tag triggers the managed GitHub Release workflow. Submit the resulting immutable Release through the Registry pull-request and human-review flow.
|
|
51
59
|
|
|
52
|
-
Before cutting a production release,
|
|
60
|
+
Before cutting a production release, enable a protected `v*` tag ruleset and immutable releases in the public GitHub repository, and provide a read-only repository-admin token to verify those settings. Manual workflow dispatch runs a development build.
|
|
53
61
|
|
|
54
62
|
A GitHub Release remains independent from registry admission, Runtime installation, Desktop launch, and Nimi Access. Runtime, Realm, registry admission, installed state, and process truth remain with their canonical owners. This repository stores no Runtime credentials or protected session material.
|
|
55
63
|
|