@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 CHANGED
@@ -50,6 +50,8 @@ pnpm dev
50
50
 
51
51
  Set `--author` to the person or team responsible for the App and its license.
52
52
 
53
+ Desktop projects default to a static frontend that Home opens in Nimi’s managed carrier on Windows x64 and macOS arm64. Choose `--carrier native` at creation if the App needs its own Electron main process.
54
+
53
55
  ### Feature Profiles
54
56
  - `--features studio-create`: Injects creative text and multimodal generation capabilities along with `runtime.consume` permissions.
55
57
  - `--features studio-media`: Includes music, audio separation, and speech transcription capabilities.
@@ -96,6 +98,16 @@ pnpm dev -- --resume <selector>
96
98
  ## 4. Production Packaging & Distribution
97
99
 
98
100
  ### Building for Targets
101
+
102
+ For the default managed desktop App, build one package for both supported platforms:
103
+
104
+ ```bash
105
+ pnpm exec nimi-app build --target desktop-universal --production
106
+ pnpm exec nimi-app pack --target desktop-universal --production
107
+ ```
108
+
109
+ For an App created with `--carrier native`, build on the matching host:
110
+
99
111
  ```bash
100
112
  # macOS (Apple Silicon)
101
113
  pnpm exec nimi-app build --target macos-aarch64 --production
@@ -162,14 +174,14 @@ Save it as a **secret** (not an Actions variable) and confirm the exact name app
162
174
  Electron packages must keep native add-ons and their companion libraries outside the ASAR archive with their relative directory layout intact. The scaffold configures `asar: { unpack: '**/*.{node,dylib,dll}' }` on macOS and Windows. Apply the equivalent rule to any custom App-owned packager configuration and verify native module loading from the packaged layout—unpacking only `.node` files can leave companion libraries such as Sharp's `libvips` unavailable to the OS dynamic loader.
163
175
 
164
176
  #### Local Pre-Release Check & Tagging
165
- Run the production verification path locally from the App repository:
177
+ Run the production verification path locally from the App repository. For a native App, substitute the matching host target shown above.
166
178
 
167
179
  ```bash
168
180
  pnpm run sync
169
181
  pnpm exec nimi-app check --production
170
182
  pnpm exec nimi-app test
171
- pnpm exec nimi-app build --target windows-x86_64 --production
172
- pnpm exec nimi-app pack --target windows-x86_64 --production
183
+ pnpm exec nimi-app build --target desktop-universal --production
184
+ pnpm exec nimi-app pack --target desktop-universal --production
173
185
  ```
174
186
 
175
187
  Ensure `package.json` and `nimi.app.yaml` declare the exact same version, commit all release changes, and land that exact commit on the repository's canonical default branch. Then create and push an annotated tag matching that version (`0.1.0` shown as an example):
@@ -239,6 +251,49 @@ Keep repository setup, architecture, build/release commands and engineering acce
239
251
 
240
252
  Packaging copies its exact text into the existing `app-info.json` `readme_markdown` field. Installed and Catalog entries display their exact release snapshot; changing source documentation does not rewrite an immutable release.
241
253
 
254
+ ### Storefront Presentation (`metadata.storefront`)
255
+
256
+ Apps may declare optional `metadata.storefront` in `nimi.app.yaml` to provide localized store copy, highlights, tags, a 16:9 cover image, and up to 6 static screenshots (WebP or PNG, static only, `<= 512 KiB` each; cover `800–2560 × 450–1600`, gallery `640–2560 × 360–1600`). Supported `category` values: `companions-worlds`, `lifestyle`, `writing-notes`, `design-diagrams`, `audio-music`, `video-media`, `research-learning`, `productivity-automation`, `developer-tools`.
257
+
258
+ Non-default locales may override `display_name`, `summary`, and `introduction` (pointing to a repo-relative UTF-8 Markdown file up to `96 KiB`); the `default_locale` reuses top-level `display_name`, `metadata.summary`, and root `NIMI_APP.md` without duplicating them.
259
+
260
+ ```yaml
261
+ metadata:
262
+ summary: 中文简介(默认语种来自顶层字段与 NIMI_APP.md)
263
+ icon: assets/app-artwork.png
264
+ storefront:
265
+ category: lifestyle
266
+ default_locale: zh
267
+ locales:
268
+ zh:
269
+ tags: [节律观察, 本地隐私]
270
+ highlights:
271
+ - title: 确定性排盘
272
+ description: 本地先算准客观盘面,再结合模型解读。
273
+ en:
274
+ display_name: ShiJing
275
+ summary: Deterministic personal rhythm companion.
276
+ introduction: NIMI_APP.en.md
277
+ tags: [Rhythm, Local-First]
278
+ highlights:
279
+ - title: Deterministic Engine
280
+ description: Computes local charts before layering AI reflection.
281
+ media:
282
+ cover:
283
+ path: assets/storefront/cover-zh.webp
284
+ locales:
285
+ en: assets/storefront/cover-en.webp
286
+ gallery:
287
+ - id: overview
288
+ kind: image
289
+ path: assets/storefront/overview-zh.webp
290
+ caption:
291
+ zh: 主视图总览
292
+ en: "Main workspace overview"
293
+ ```
294
+
295
+ During `nimi-app pack --target`, App Tools validates every declared image and writes only image digests and dimensions into `app-info.json` (never embedding screenshots inside `.nimiapp`). During `nimi-app pack --aggregate`, App Tools checks cross-target display parity and packages all referenced images once into a deduplicated `<app_id>-<version>-storefront-media.zip` (`<= 8 MiB`) uploaded alongside the immutable GitHub Release.
296
+
242
297
  ### Package v2 Output & Sidecar Verification
243
298
  `pack` writes the `nimi.app-package/v2` format and emits the exact embedded `app-info.json` bytes as a sidecar file named `<app_id>-<version>-<target_id>.app-info.json` alongside the `.nimiapp` bundle and `.target.json`. Aggregate verification checks both files and confirms they match the embedded document byte-for-byte.
244
299
 
@@ -256,7 +311,7 @@ Licensed under [Apache-2.0](../licenses/Apache-2.0.txt).
256
311
 
257
312
  The same CLI supports `create --platform web`, Web `init/sync/check/test/build`, existing-site `init --adopt`, and `dev --platform web`. `standalone` is still the repository topology. Web `--features all` currently resolves to `studio-create` (text, streaming chat and embeddings); other feature selections fail explicitly until their Web carrier is admitted. Mobile generation remains outside this command. For managed Web hosting, build a static release with the App's public slug and prepare it for separate human Registry admission.
258
313
 
259
- Use a compatible host and matching prerelease packages for Web development. App Tools `0.16.0-rc.10` scaffolds the project with SDK `0.24.0-rc.10` and Kit `0.24.0-rc.16`. For unpublished changes, use a matching set of complete source archives. See [Environment Setup](../docs/start/install.md).
314
+ Use a compatible host and matching prerelease packages for Web development. App Tools `0.16.0-rc.12` scaffolds the project with SDK `0.24.0-rc.10` and Kit `0.24.0-rc.16`. For unpublished changes, use a matching set of complete source archives. See [Environment Setup](../docs/start/install.md).
260
315
 
261
316
  The current workbench uses account-owned prompt drafts with an asynchronous `promptDraft` projection and independent history record documents. For existing unreleased generated prototypes, update the App-owned AI Studio capability source together with the generated host adapters. `sync` intentionally preserves `src/capabilities` and does not migrate or overwrite that business source; running `check` alone is not a substitute for the project's typecheck/build after this source update.
262
317
 
package/bin/nimi-app.mjs CHANGED
@@ -14,14 +14,14 @@ import {
14
14
  syncApp,
15
15
  testApp,
16
16
  } from '../lib/index.mjs';
17
- import { APP_SCAFFOLD_MODULE_REGISTRY } from '../lib/app-scaffold-capabilities.mjs';
17
+ import { APP_SCAFFOLD_MANAGED_WEB_FEATURE_IDS, APP_SCAFFOLD_MODULE_REGISTRY } from '../lib/app-scaffold-capabilities.mjs';
18
18
  import { LIFECYCLE_SKILL_PATH } from '../lib/app-lifecycle-guidance.mjs';
19
19
  import { createInterface } from 'node:readline/promises';
20
20
 
21
21
  function parseArgs(argv) {
22
22
  const [command = '', ...rest] = argv;
23
23
  const values = {
24
- dir: '', profile: '', platform: '', appId: '', version: '', title: '', packageName: '', author: '',
24
+ dir: '', profile: '', platform: '', carrier: '', appId: '', version: '', title: '', packageName: '', author: '',
25
25
  features: undefined, shell: '', cdpPort: undefined, noCdp: false, listRegistrations: false, resume: '', newRegistration: false, target: '', aggregate: false, production: false, json: false,
26
26
  adopt: false, dryRun: false, input: '', realm: '',
27
27
  };
@@ -90,6 +90,10 @@ function parseArgs(argv) {
90
90
  index = readValue(index, '--platform', 'platform');
91
91
  continue;
92
92
  }
93
+ if (rest[index] === '--carrier') {
94
+ index = readValue(index, '--carrier', 'carrier');
95
+ continue;
96
+ }
93
97
  if (rest[index] === '--features') {
94
98
  index = readValue(index, '--features', 'features');
95
99
  continue;
@@ -157,7 +161,7 @@ function parseArgs(argv) {
157
161
 
158
162
  function assertCommandOptions(command, providedOptions) {
159
163
  const allowed = {
160
- create: new Set(['dir', 'profile', 'platform', 'appId', 'version', 'title', 'packageName', 'author', 'features', 'json']),
164
+ create: new Set(['dir', 'profile', 'platform', 'carrier', 'appId', 'version', 'title', 'packageName', 'author', 'features', 'json']),
161
165
  init: new Set(['dir', 'json', 'adopt', 'input', 'dryRun']),
162
166
  sync: new Set(['dir', 'json', 'dryRun']),
163
167
  check: new Set(['dir', 'json', 'production']),
@@ -188,7 +192,7 @@ function printUsage() {
188
192
  'Nimi App developer tools',
189
193
  '',
190
194
  'Usage:',
191
- ' nimi-app create [--dir path] [--profile standalone] [--platform desktop|web] [--features admitted-ids|all] [--app-id dotted.id] [--version semver] [--title title] [--package-name name] [--author person-or-team] [--json]',
195
+ ' nimi-app create [--dir path] [--profile standalone] [--platform desktop|web] [--carrier managed-web|native] [--features admitted-ids|all] [--app-id dotted.id] [--version semver] [--title title] [--package-name name] [--author person-or-team] [--json]',
192
196
  ' nimi-app init [--adopt [--input json-path]] [--dry-run] [--dir path] [--json]',
193
197
  ' nimi-app sync [--dry-run] [--dir path] [--json]',
194
198
  ' nimi-app check [--dir path] [--production] [--json]',
@@ -207,6 +211,7 @@ function printUsage() {
207
211
  '',
208
212
  'Current module registry:',
209
213
  ` Admitted features: ${featureList(admitted)}`,
214
+ ` Managed desktop features (--carrier managed-web, default): ${APP_SCAFFOLD_MANAGED_WEB_FEATURE_IDS.join(', ') || '(none)'}`,
210
215
  ` Web features: ${featureList(admitted.filter(entry => entry.carriers.includes('web')))}`,
211
216
  ` Candidate features (not public-selectable): ${featureList(candidates)}`,
212
217
  ` Internal modules (dependency-only): ${internalList}`,
@@ -324,6 +329,7 @@ try {
324
329
  dir,
325
330
  profile,
326
331
  platform,
332
+ carrier,
327
333
  appId,
328
334
  version,
329
335
  title,
@@ -366,6 +372,7 @@ try {
366
372
  dir,
367
373
  profile,
368
374
  platform,
375
+ carrier,
369
376
  appId,
370
377
  version,
371
378
  title,
@@ -1,8 +1,9 @@
1
1
  import { isAppId } from './app-identifiers.mjs';
2
+ import { validateManifestDesktop } from './desktop-window.mjs';
2
3
  import { readWebDevelopment } from './web-development.mjs';
3
4
  import { readMobileDevelopment } from './mobile-development.mjs';
4
5
  import { APP_AUTHOR_DECLARATION_FIELDS, hashScaffoldManagedContent } from './app-scaffold.mjs';
5
- import { readAppIntroduction } from './app-info.mjs';
6
+ import { readAppIntroduction, readAppStorefront } from './app-info.mjs';
6
7
  import { existsSync, readdirSync, readFileSync, realpathSync, statSync } from 'node:fs';
7
8
  import path from 'node:path';
8
9
  import { minVersion } from 'semver';
@@ -186,6 +187,7 @@ function expectedSnapshotFromLock(lock, versions, intent, targetDir, options = {
186
187
  }
187
188
  for (const [intentField, lockField, label] of [
188
189
  ['profile', 'profile', 'profile'],
190
+ ['carrier', 'carrier', 'carrier'],
189
191
  ['appId', 'appId', 'App ID'],
190
192
  ['appTitle', 'appTitle', 'display name'],
191
193
  ['packageName', 'packageName', 'package name'],
@@ -479,12 +481,20 @@ function assertRequiredSupportFiles(targetDir, snapshot) {
479
481
  }
480
482
  }
481
483
 
482
- function usesAppOwnedRenderer(targetDir, plannedSources) {
484
+ function readBuildProfileRef(targetDir, plannedSources) {
483
485
  const relativePath = '.nimi/config/build-profile.yaml';
484
486
  const filePath = path.join(targetDir, relativePath);
485
487
  const source = plannedSources?.get(relativePath)
486
488
  ?? (existsSync(filePath) ? readFileSync(filePath, 'utf8') : undefined);
487
- return source !== undefined && parseYaml(source)?.build_profile_ref === 'electron-pnpm';
489
+ return source !== undefined ? parseYaml(source)?.build_profile_ref : undefined;
490
+ }
491
+
492
+ function usesAppOwnedRenderer(targetDir, plannedSources) {
493
+ return readBuildProfileRef(targetDir, plannedSources) === 'electron-pnpm';
494
+ }
495
+
496
+ function usesManagedWebCarrier(targetDir, plannedSources) {
497
+ return readBuildProfileRef(targetDir, plannedSources) === 'managed-web-pnpm-vite';
488
498
  }
489
499
 
490
500
  function assertProjectConfiguration(targetDir, parsedManifest = null, managed = true) {
@@ -499,7 +509,9 @@ function assertProjectConfiguration(targetDir, parsedManifest = null, managed =
499
509
  throw new Error(`Submitted manifest YAML cannot be parsed: ${error instanceof Error ? error.message : String(error)}`);
500
510
  }
501
511
  }
512
+ validateManifestDesktop(document?.desktop, 'nimi.app.yaml desktop', manifest);
502
513
  readAppIntroduction(targetDir, document);
514
+ readAppStorefront(targetDir, document);
503
515
  assertCarrierDevelopmentInputs(targetDir, document, readJsonFile(path.join(targetDir, 'package.json')), managed);
504
516
  }
505
517
 
@@ -550,7 +562,7 @@ function assertDeclaredHostSourceDirectory(targetDir, document) {
550
562
  }
551
563
  }
552
564
 
553
- function assertOfficialDevelopmentEntrypoints(targetDir, rendererOrigin, packageJson = readJsonFile(path.join(targetDir, 'package.json'), 'package.json'), managed = true) {
565
+ function assertOfficialDevelopmentEntrypoints(targetDir, rendererOrigin, packageJson = readJsonFile(path.join(targetDir, 'package.json'), 'package.json'), managed = true, managedWeb = false) {
554
566
  const scripts = packageJson?.scripts;
555
567
  if (!scripts || typeof scripts !== 'object' || Array.isArray(scripts)) {
556
568
  throw new Error('package.json scripts are required');
@@ -572,11 +584,11 @@ function assertOfficialDevelopmentEntrypoints(targetDir, rendererOrigin, package
572
584
  || /\b(?:nimi-app\s+dev|(?:pnpm|npm)\s+(?:run\s+)?(?:dev|dev:renderer))(?=\s|$)/u.test(rendererCommand)) {
573
585
  throw new Error('package.json dev:renderer must be a non-recursive App-owned renderer command for the declared loopback origin');
574
586
  }
575
- if (
587
+ if (!managedWeb && (
576
588
  typeof scripts['build:electron'] !== 'string'
577
589
  || scripts['build:electron'].trim() !== scripts['build:electron']
578
590
  || scripts['build:electron'].length === 0
579
- ) {
591
+ )) {
580
592
  throw new Error('package.json build:electron must build the Desktop-supervised Electron host');
581
593
  }
582
594
  for (const [name, value] of Object.entries(scripts)) {
@@ -614,15 +626,18 @@ function assertCarrierDevelopmentInputs(targetDir, manifest, packageJson, manage
614
626
  }
615
627
  if (manifest.platform !== 'web') {
616
628
  if (manifest.platform !== undefined && manifest.platform !== 'desktop') throw new Error('Unsupported App platform.');
629
+ const managedWeb = usesManagedWebCarrier(targetDir, plannedSources);
617
630
  const rendererOrigin = assertElectronLocalDevelopmentManifest(manifest);
618
631
  assertDeclaredHostSourceDirectory(targetDir, manifest);
619
- assertOfficialDevelopmentEntrypoints(targetDir, rendererOrigin, packageJson, managed || !usesAppOwnedRenderer(targetDir, plannedSources));
632
+ assertOfficialDevelopmentEntrypoints(targetDir, rendererOrigin, packageJson, managed || !usesAppOwnedRenderer(targetDir, plannedSources), managedWeb);
620
633
  }
621
634
  }
622
635
 
623
636
  export function validateAppProjectInputs(targetDir, manifest, packageJson, managed = false, plannedSources) {
624
637
  assertManifestAppAccessDeclaration(stringifyYaml(manifest), 'nimi.app.yaml');
638
+ validateManifestDesktop(manifest?.desktop, 'nimi.app.yaml desktop');
625
639
  readAppIntroduction(targetDir, manifest);
640
+ readAppStorefront(targetDir, manifest);
626
641
  assertCarrierDevelopmentInputs(targetDir, manifest, packageJson, managed, plannedSources);
627
642
  const findings = scanForbiddenPatterns(targetDir, manifest.profile, managed ? null : LOCAL_DEVELOPMENT_BYPASS_LABELS, plannedSources);
628
643
  if (findings.length) throw new Error(`Forbidden App source patterns: ${findings.join('; ')}`);
package/lib/app-info.mjs CHANGED
@@ -9,13 +9,24 @@ import { parse as parseYaml } from 'yaml';
9
9
  import { normalizeAppAccessItems } from './app-access-declaration.mjs';
10
10
  import { CANONICAL_CAPABILITY_IDS } from './canonical-capability-ids.generated.mjs';
11
11
  import { SAFETY_PROFILE_FIELD, normalizeSafetyProfile } from './app-safety-profile.mjs';
12
+ import {
13
+ STOREFRONT_CATEGORIES,
14
+ STOREFRONT_COVER_BOUNDS,
15
+ STOREFRONT_GALLERY_BOUNDS,
16
+ STOREFRONT_GALLERY_ID_PATTERN,
17
+ STOREFRONT_IMAGE_MAX_BYTES,
18
+ STOREFRONT_LOCALE_PATTERN,
19
+ STOREFRONT_SHA256_PATTERN,
20
+ inspectStaticStorefrontImage,
21
+ storefrontMediaExtension,
22
+ } from './storefront-media.mjs';
12
23
 
13
24
  export const APP_INFO_MAX_BYTES = 1024 * 1024;
14
25
  export const APP_INTRODUCTION_FILE = 'NIMI_APP.md';
15
26
  export const APP_INFO_FIELDS = Object.freeze([
16
27
  'format', 'app_id', 'version', 'target_id', 'display_name', 'summary', 'icon', 'readme_markdown', 'release_notes_markdown',
17
28
  'license', 'app_access', 'capability_contract_refs', 'required_standardized_feature_refs', 'storage_policy', 'author',
18
- 'homepage_url', 'support_url', SAFETY_PROFILE_FIELD,
29
+ 'homepage_url', 'support_url', SAFETY_PROFILE_FIELD, 'storefront',
19
30
  ]);
20
31
  // Declaration fields that App Tools projects from nimi.app.yaml into the
21
32
  // archive declaration and that Registry compares against the candidate.
@@ -102,10 +113,288 @@ export function validateAppInfo(info) {
102
113
  https(info.homepage_url, 'homepage_url');
103
114
  https(info.support_url, 'support_url');
104
115
  safetyProfile(info[SAFETY_PROFILE_FIELD], 'App info');
116
+ if (info.storefront !== undefined) validateAppInfoStorefront(info.storefront);
105
117
  if (Buffer.byteLength(JSON.stringify(info)) > APP_INFO_MAX_BYTES) throw new Error('App info exceeds 1 MiB');
106
118
  return info;
107
119
  }
108
120
 
121
+ function validLocale(value, label) {
122
+ if (typeof value !== 'string' || value.length > 16 || !STOREFRONT_LOCALE_PATTERN.test(value)) {
123
+ throw new Error(`${label} must be a valid locale tag (e.g. en, zh)`);
124
+ }
125
+ return value;
126
+ }
127
+
128
+ function validateImageRef(ref, bounds, label) {
129
+ if (!ref || typeof ref !== 'object' || Array.isArray(ref)) throw new Error(`${label} must be an image reference object`);
130
+ for (const key of Object.keys(ref)) {
131
+ if (!['media_type', 'width', 'height', 'size', 'sha256'].includes(key)) throw new Error(`${label} contains unsupported field: ${key}`);
132
+ }
133
+ if (!['image/webp', 'image/png'].includes(ref.media_type)) throw new Error(`${label} media_type must be image/webp or image/png`);
134
+ if (!Number.isInteger(ref.width) || !Number.isInteger(ref.height)
135
+ || ref.width < bounds.minW || ref.width > bounds.maxW || ref.height < bounds.minH || ref.height > bounds.maxH) {
136
+ throw new Error(`${label} dimensions are outside allowed bounds`);
137
+ }
138
+ if (!Number.isInteger(ref.size) || ref.size <= 0 || ref.size > STOREFRONT_IMAGE_MAX_BYTES || !STOREFRONT_SHA256_PATTERN.test(ref.sha256)) {
139
+ throw new Error(`${label} size or sha256 is invalid`);
140
+ }
141
+ return ref;
142
+ }
143
+
144
+ export function validateAppInfoStorefront(storefront) {
145
+ if (!storefront || typeof storefront !== 'object' || Array.isArray(storefront)) throw new Error('App info storefront must be an object');
146
+ for (const key of Object.keys(storefront)) {
147
+ if (!['category', 'default_locale', 'locales', 'media'].includes(key)) throw new Error(`App info storefront contains unsupported field: ${key}`);
148
+ }
149
+ if (!STOREFRONT_CATEGORIES.includes(storefront.category)) throw new Error(`App info storefront category is unsupported: ${storefront.category}`);
150
+ const defaultLocale = validLocale(storefront.default_locale, 'storefront.default_locale');
151
+ if (storefront.locales !== undefined) {
152
+ if (!storefront.locales || typeof storefront.locales !== 'object' || Array.isArray(storefront.locales)) throw new Error('App info storefront.locales must be an object');
153
+ const entries = Object.entries(storefront.locales);
154
+ if (entries.length > 16) throw new Error('App info storefront.locales exceeds 16 locales');
155
+ for (const [locale, entry] of entries) {
156
+ validLocale(locale, 'storefront.locales key');
157
+ if (!entry || typeof entry !== 'object' || Array.isArray(entry)) throw new Error(`storefront.locales.${locale} must be an object`);
158
+ for (const key of Object.keys(entry)) {
159
+ if (!['display_name', 'summary', 'tags', 'highlights', 'introduction_markdown'].includes(key)) {
160
+ throw new Error(`storefront.locales.${locale} contains unsupported field: ${key}`);
161
+ }
162
+ }
163
+ if (locale === defaultLocale) {
164
+ if (entry.display_name !== undefined || entry.summary !== undefined || entry.introduction_markdown !== undefined) {
165
+ throw new Error(`storefront.locales.${locale} must not duplicate top-level display_name, summary or NIMI_APP.md`);
166
+ }
167
+ } else {
168
+ if (entry.display_name !== undefined) text(entry.display_name, `storefront.locales.${locale}.display_name`, 120);
169
+ if (entry.summary !== undefined) text(entry.summary, `storefront.locales.${locale}.summary`, 280);
170
+ if (entry.introduction_markdown !== undefined) text(entry.introduction_markdown, `storefront.locales.${locale}.introduction_markdown`, 96 * 1024, true);
171
+ }
172
+ if (entry.tags !== undefined) {
173
+ if (!Array.isArray(entry.tags) || entry.tags.length > 5 || new Set(entry.tags).size !== entry.tags.length) {
174
+ throw new Error(`storefront.locales.${locale}.tags must contain at most 5 unique tags`);
175
+ }
176
+ for (const tag of entry.tags) text(tag, `storefront.locales.${locale}.tags`, 32);
177
+ }
178
+ if (entry.highlights !== undefined) {
179
+ if (!Array.isArray(entry.highlights) || entry.highlights.length > 4) {
180
+ throw new Error(`storefront.locales.${locale}.highlights must contain at most 4 items`);
181
+ }
182
+ for (const item of entry.highlights) {
183
+ if (!item || typeof item !== 'object' || Array.isArray(item)) throw new Error(`storefront.locales.${locale}.highlights item must be an object`);
184
+ for (const key of Object.keys(item)) {
185
+ if (!['title', 'description'].includes(key)) throw new Error(`storefront highlight contains unsupported field: ${key}`);
186
+ }
187
+ text(item.title, `storefront.locales.${locale}.highlights.title`, 60);
188
+ text(item.description, `storefront.locales.${locale}.highlights.description`, 200);
189
+ }
190
+ }
191
+ }
192
+ }
193
+ if (storefront.media !== undefined) {
194
+ const media = storefront.media;
195
+ if (!media || typeof media !== 'object' || Array.isArray(media)) throw new Error('App info storefront.media must be an object');
196
+ for (const key of Object.keys(media)) {
197
+ if (!['cover', 'gallery'].includes(key)) throw new Error(`App info storefront.media contains unsupported field: ${key}`);
198
+ }
199
+ if (media.cover === undefined && (!Array.isArray(media.gallery) || media.gallery.length === 0)) {
200
+ throw new Error('App info storefront.media must declare cover or gallery');
201
+ }
202
+ if (media.cover !== undefined) {
203
+ if (!media.cover || typeof media.cover !== 'object' || Array.isArray(media.cover)) throw new Error('storefront.media.cover must be an object');
204
+ for (const key of Object.keys(media.cover)) {
205
+ if (!['default', 'locales'].includes(key)) throw new Error(`storefront.media.cover contains unsupported field: ${key}`);
206
+ }
207
+ validateImageRef(media.cover.default, STOREFRONT_COVER_BOUNDS, 'storefront.media.cover.default');
208
+ if (media.cover.locales !== undefined) {
209
+ if (!media.cover.locales || typeof media.cover.locales !== 'object' || Array.isArray(media.cover.locales)) {
210
+ throw new Error('storefront.media.cover.locales must be an object');
211
+ }
212
+ const entries = Object.entries(media.cover.locales);
213
+ if (entries.length > 15) throw new Error('storefront.media.cover.locales exceeds 15 locales');
214
+ for (const [locale, ref] of entries) {
215
+ validLocale(locale, 'storefront.media.cover.locales key');
216
+ if (locale === defaultLocale) throw new Error('storefront.media.cover.locales must not duplicate default_locale');
217
+ validateImageRef(ref, STOREFRONT_COVER_BOUNDS, `storefront.media.cover.locales.${locale}`);
218
+ }
219
+ }
220
+ }
221
+ if (media.gallery !== undefined) {
222
+ if (!Array.isArray(media.gallery) || media.gallery.length > 6) throw new Error('storefront.media.gallery must contain at most 6 items');
223
+ const seenIds = new Set();
224
+ for (const item of media.gallery) {
225
+ if (!item || typeof item !== 'object' || Array.isArray(item)) throw new Error('storefront.media.gallery item must be an object');
226
+ for (const key of Object.keys(item)) {
227
+ if (!['id', 'kind', 'default', 'locales', 'caption'].includes(key)) throw new Error(`storefront gallery item contains unsupported field: ${key}`);
228
+ }
229
+ if (typeof item.id !== 'string' || !STOREFRONT_GALLERY_ID_PATTERN.test(item.id) || seenIds.has(item.id)) {
230
+ throw new Error(`storefront gallery id is invalid or duplicated: ${item.id}`);
231
+ }
232
+ seenIds.add(item.id);
233
+ if (item.kind !== 'image') throw new Error(`storefront gallery item ${item.id} kind must be image`);
234
+ validateImageRef(item.default, STOREFRONT_GALLERY_BOUNDS, `storefront.media.gallery.${item.id}.default`);
235
+ if (item.locales !== undefined) {
236
+ if (!item.locales || typeof item.locales !== 'object' || Array.isArray(item.locales)) {
237
+ throw new Error(`storefront.media.gallery.${item.id}.locales must be an object`);
238
+ }
239
+ const entries = Object.entries(item.locales);
240
+ if (entries.length > 15) throw new Error(`storefront.media.gallery.${item.id}.locales exceeds 15 locales`);
241
+ for (const [locale, ref] of entries) {
242
+ validLocale(locale, `storefront.media.gallery.${item.id}.locales key`);
243
+ if (locale === defaultLocale) throw new Error(`storefront.media.gallery.${item.id}.locales must not duplicate default_locale`);
244
+ validateImageRef(ref, STOREFRONT_GALLERY_BOUNDS, `storefront.media.gallery.${item.id}.locales.${locale}`);
245
+ }
246
+ }
247
+ if (item.caption !== undefined) {
248
+ if (!item.caption || typeof item.caption !== 'object' || Array.isArray(item.caption)) {
249
+ throw new Error(`storefront.media.gallery.${item.id}.caption must be an object`);
250
+ }
251
+ const entries = Object.entries(item.caption);
252
+ if (entries.length > 16) throw new Error(`storefront.media.gallery.${item.id}.caption exceeds 16 locales`);
253
+ for (const [locale, captionText] of entries) {
254
+ validLocale(locale, `storefront.media.gallery.${item.id}.caption key`);
255
+ text(captionText, `storefront.media.gallery.${item.id}.caption.${locale}`, 200);
256
+ }
257
+ }
258
+ }
259
+ }
260
+ }
261
+ return storefront;
262
+ }
263
+
264
+ export function readAppStorefront(root, manifest) {
265
+ const raw = manifest?.metadata?.storefront;
266
+ if (raw === undefined) return { storefront: undefined, mediaEntries: new Map() };
267
+ if (!raw || typeof raw !== 'object' || Array.isArray(raw)) throw new Error('metadata.storefront must be an object');
268
+ for (const key of Object.keys(raw)) {
269
+ if (!['category', 'default_locale', 'locales', 'media'].includes(key)) {
270
+ throw new Error(`metadata.storefront contains unsupported field: ${key}`);
271
+ }
272
+ }
273
+ const category = raw.category;
274
+ const defaultLocale = validLocale(raw.default_locale, 'metadata.storefront.default_locale');
275
+ const storefront = { category, default_locale: defaultLocale };
276
+ const readUtf8 = (relative, label, max) => new TextDecoder('utf-8', { fatal: true, ignoreBOM: true }).decode(resource(root, relative, label, max));
277
+
278
+ if (raw.locales !== undefined) {
279
+ if (!raw.locales || typeof raw.locales !== 'object' || Array.isArray(raw.locales)) throw new Error('metadata.storefront.locales must be an object');
280
+ const localesOut = {};
281
+ for (const locale of Object.keys(raw.locales).sort()) {
282
+ validLocale(locale, 'metadata.storefront.locales key');
283
+ const entry = raw.locales[locale];
284
+ if (!entry || typeof entry !== 'object' || Array.isArray(entry)) throw new Error(`metadata.storefront.locales.${locale} must be an object`);
285
+ for (const key of Object.keys(entry)) {
286
+ if (!['display_name', 'summary', 'tags', 'highlights', 'introduction'].includes(key)) {
287
+ throw new Error(`metadata.storefront.locales.${locale} contains unsupported field: ${key}`);
288
+ }
289
+ }
290
+ const next = {};
291
+ if (locale === defaultLocale) {
292
+ if (entry.display_name !== undefined || entry.summary !== undefined || entry.introduction !== undefined) {
293
+ throw new Error(`metadata.storefront.locales.${locale} must not specify display_name, summary or introduction (use top-level metadata and NIMI_APP.md)`);
294
+ }
295
+ } else {
296
+ if (entry.display_name !== undefined) next.display_name = entry.display_name;
297
+ if (entry.summary !== undefined) next.summary = entry.summary;
298
+ if (entry.introduction !== undefined) {
299
+ next.introduction_markdown = readUtf8(entry.introduction, `storefront.locales.${locale}.introduction`, 96 * 1024);
300
+ }
301
+ }
302
+ if (entry.tags !== undefined) next.tags = entry.tags;
303
+ if (entry.highlights !== undefined) {
304
+ if (!Array.isArray(entry.highlights)) throw new Error(`metadata.storefront.locales.${locale}.highlights must be a list`);
305
+ next.highlights = entry.highlights.map((item) => {
306
+ if (!item || typeof item !== 'object' || Array.isArray(item)) throw new Error(`metadata.storefront.locales.${locale}.highlights item must be an object`);
307
+ for (const key of Object.keys(item)) {
308
+ if (!['title', 'description'].includes(key)) throw new Error(`metadata.storefront highlight contains unsupported field: ${key}`);
309
+ }
310
+ return { title: item.title, description: item.description };
311
+ });
312
+ }
313
+ localesOut[locale] = next;
314
+ }
315
+ if (Object.keys(localesOut).length > 0) storefront.locales = localesOut;
316
+ }
317
+
318
+ const mediaEntries = new Map();
319
+ const readImage = (relative, bounds, label) => {
320
+ const bytes = resource(root, relative, label, STOREFRONT_IMAGE_MAX_BYTES);
321
+ const ref = inspectStaticStorefrontImage(bytes, bounds, label);
322
+ const archiveName = `${ref.sha256}.${storefrontMediaExtension(ref.media_type)}`;
323
+ if (!mediaEntries.has(archiveName)) mediaEntries.set(archiveName, bytes);
324
+ return ref;
325
+ };
326
+
327
+ if (raw.media !== undefined) {
328
+ const rawMedia = raw.media;
329
+ if (!rawMedia || typeof rawMedia !== 'object' || Array.isArray(rawMedia)) throw new Error('metadata.storefront.media must be an object');
330
+ for (const key of Object.keys(rawMedia)) {
331
+ if (!['cover', 'gallery'].includes(key)) throw new Error(`metadata.storefront.media contains unsupported field: ${key}`);
332
+ }
333
+ const mediaOut = {};
334
+ if (rawMedia.cover !== undefined) {
335
+ const rawCover = rawMedia.cover;
336
+ if (!rawCover || typeof rawCover !== 'object' || Array.isArray(rawCover)) throw new Error('metadata.storefront.media.cover must be an object');
337
+ for (const key of Object.keys(rawCover)) {
338
+ if (!['path', 'locales'].includes(key)) throw new Error(`metadata.storefront.media.cover contains unsupported field: ${key}`);
339
+ }
340
+ const coverOut = { default: readImage(rawCover.path, STOREFRONT_COVER_BOUNDS, 'storefront.media.cover.path') };
341
+ if (rawCover.locales !== undefined) {
342
+ if (!rawCover.locales || typeof rawCover.locales !== 'object' || Array.isArray(rawCover.locales)) {
343
+ throw new Error('metadata.storefront.media.cover.locales must be an object');
344
+ }
345
+ const coverLocales = {};
346
+ for (const locale of Object.keys(rawCover.locales).sort()) {
347
+ validLocale(locale, 'metadata.storefront.media.cover.locales key');
348
+ if (locale === defaultLocale) throw new Error('metadata.storefront.media.cover.locales must not duplicate default_locale');
349
+ coverLocales[locale] = readImage(rawCover.locales[locale], STOREFRONT_COVER_BOUNDS, `storefront.media.cover.locales.${locale}`);
350
+ }
351
+ if (Object.keys(coverLocales).length > 0) coverOut.locales = coverLocales;
352
+ }
353
+ mediaOut.cover = coverOut;
354
+ }
355
+ if (rawMedia.gallery !== undefined) {
356
+ if (!Array.isArray(rawMedia.gallery)) throw new Error('metadata.storefront.media.gallery must be a list');
357
+ mediaOut.gallery = rawMedia.gallery.map((item) => {
358
+ if (!item || typeof item !== 'object' || Array.isArray(item)) throw new Error('metadata.storefront.media.gallery item must be an object');
359
+ for (const key of Object.keys(item)) {
360
+ if (!['id', 'kind', 'path', 'locales', 'caption'].includes(key)) throw new Error(`metadata.storefront gallery item contains unsupported field: ${key}`);
361
+ }
362
+ if (item.kind !== 'image') throw new Error(`metadata.storefront gallery item ${item.id} kind must be image`);
363
+ const galleryItem = {
364
+ id: item.id,
365
+ kind: 'image',
366
+ default: readImage(item.path, STOREFRONT_GALLERY_BOUNDS, `storefront.media.gallery.${item.id}.path`),
367
+ };
368
+ if (item.locales !== undefined) {
369
+ if (!item.locales || typeof item.locales !== 'object' || Array.isArray(item.locales)) {
370
+ throw new Error(`metadata.storefront.media.gallery.${item.id}.locales must be an object`);
371
+ }
372
+ const itemLocales = {};
373
+ for (const locale of Object.keys(item.locales).sort()) {
374
+ validLocale(locale, `metadata.storefront.media.gallery.${item.id}.locales key`);
375
+ if (locale === defaultLocale) throw new Error(`metadata.storefront.media.gallery.${item.id}.locales must not duplicate default_locale`);
376
+ itemLocales[locale] = readImage(item.locales[locale], STOREFRONT_GALLERY_BOUNDS, `storefront.media.gallery.${item.id}.locales.${locale}`);
377
+ }
378
+ if (Object.keys(itemLocales).length > 0) galleryItem.locales = itemLocales;
379
+ }
380
+ if (item.caption !== undefined) {
381
+ if (!item.caption || typeof item.caption !== 'object' || Array.isArray(item.caption)) {
382
+ throw new Error(`metadata.storefront.media.gallery.${item.id}.caption must be an object`);
383
+ }
384
+ const captions = {};
385
+ for (const locale of Object.keys(item.caption).sort()) captions[locale] = item.caption[locale];
386
+ if (Object.keys(captions).length > 0) galleryItem.caption = captions;
387
+ }
388
+ return galleryItem;
389
+ });
390
+ }
391
+ storefront.media = mediaOut;
392
+ }
393
+
394
+ validateAppInfoStorefront(storefront);
395
+ return { storefront, mediaEntries };
396
+ }
397
+
109
398
  function resource(root, relative, label, maxBytes) {
110
399
  if (typeof relative !== 'string' || path.isAbsolute(relative) || relative.includes('\\')
111
400
  || relative.split('/').some((part) => !part || part === '.' || part === '..')) throw new Error(`metadata.${label} must name an App-relative resource`);
@@ -141,6 +430,7 @@ export function readAppInfo(root, targetId) {
141
430
  const metadata = manifest.metadata;
142
431
  if (!metadata || typeof metadata !== 'object') throw new Error('nimi.app.yaml metadata is required for distribution (summary, icon)');
143
432
  const readText = (relative, label, max) => new TextDecoder('utf-8', { fatal: true, ignoreBOM: true }).decode(resource(root, relative, label, max));
433
+ const { storefront } = readAppStorefront(root, manifest);
144
434
  const info = validateAppInfo({
145
435
  format: 'nimi.app-info/v1', app_id: manifest.app_id, version: manifest.version, target_id: targetId,
146
436
  display_name: manifest.display_name, summary: metadata.summary,
@@ -154,6 +444,7 @@ export function readAppInfo(root, targetId) {
154
444
  storage_policy: storage(manifest.storage_policy),
155
445
  author: metadata.author || '', homepage_url: https(metadata.homepage_url, 'homepage_url'), support_url: https(metadata.support_url, 'support_url'),
156
446
  ...(manifest[SAFETY_PROFILE_FIELD] === undefined ? {} : { [SAFETY_PROFILE_FIELD]: normalizeSafetyProfile(manifest[SAFETY_PROFILE_FIELD]) }),
447
+ ...(storefront === undefined ? {} : { storefront }),
157
448
  });
158
449
  const submissionPath = path.join(root, '.nimi/admission/submission.yaml');
159
450
  if (existsSync(submissionPath)) {