@nimiplatform/app-tools 0.16.0-rc.10 → 0.16.0-rc.12

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
@@ -239,6 +239,49 @@ Keep repository setup, architecture, build/release commands and engineering acce
239
239
 
240
240
  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
241
 
242
+ ### Storefront Presentation (`metadata.storefront`)
243
+
244
+ 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`.
245
+
246
+ 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.
247
+
248
+ ```yaml
249
+ metadata:
250
+ summary: 中文简介(默认语种来自顶层字段与 NIMI_APP.md)
251
+ icon: assets/app-artwork.png
252
+ storefront:
253
+ category: lifestyle
254
+ default_locale: zh
255
+ locales:
256
+ zh:
257
+ tags: [节律观察, 本地隐私]
258
+ highlights:
259
+ - title: 确定性排盘
260
+ description: 本地先算准客观盘面,再结合模型解读。
261
+ en:
262
+ display_name: ShiJing
263
+ summary: Deterministic personal rhythm companion.
264
+ introduction: NIMI_APP.en.md
265
+ tags: [Rhythm, Local-First]
266
+ highlights:
267
+ - title: Deterministic Engine
268
+ description: Computes local charts before layering AI reflection.
269
+ media:
270
+ cover:
271
+ path: assets/storefront/cover-zh.webp
272
+ locales:
273
+ en: assets/storefront/cover-en.webp
274
+ gallery:
275
+ - id: overview
276
+ kind: image
277
+ path: assets/storefront/overview-zh.webp
278
+ caption:
279
+ zh: 主视图总览
280
+ en: "Main workspace overview"
281
+ ```
282
+
283
+ 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.
284
+
242
285
  ### Package v2 Output & Sidecar Verification
243
286
  `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
287
 
@@ -256,7 +299,7 @@ Licensed under [Apache-2.0](../licenses/Apache-2.0.txt).
256
299
 
257
300
  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
301
 
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).
302
+ 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
303
 
261
304
  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
305
 
@@ -2,7 +2,7 @@ import { isAppId } from './app-identifiers.mjs';
2
2
  import { readWebDevelopment } from './web-development.mjs';
3
3
  import { readMobileDevelopment } from './mobile-development.mjs';
4
4
  import { APP_AUTHOR_DECLARATION_FIELDS, hashScaffoldManagedContent } from './app-scaffold.mjs';
5
- import { readAppIntroduction } from './app-info.mjs';
5
+ import { readAppIntroduction, readAppStorefront } from './app-info.mjs';
6
6
  import { existsSync, readdirSync, readFileSync, realpathSync, statSync } from 'node:fs';
7
7
  import path from 'node:path';
8
8
  import { minVersion } from 'semver';
@@ -500,6 +500,7 @@ function assertProjectConfiguration(targetDir, parsedManifest = null, managed =
500
500
  }
501
501
  }
502
502
  readAppIntroduction(targetDir, document);
503
+ readAppStorefront(targetDir, document);
503
504
  assertCarrierDevelopmentInputs(targetDir, document, readJsonFile(path.join(targetDir, 'package.json')), managed);
504
505
  }
505
506
 
@@ -623,6 +624,7 @@ function assertCarrierDevelopmentInputs(targetDir, manifest, packageJson, manage
623
624
  export function validateAppProjectInputs(targetDir, manifest, packageJson, managed = false, plannedSources) {
624
625
  assertManifestAppAccessDeclaration(stringifyYaml(manifest), 'nimi.app.yaml');
625
626
  readAppIntroduction(targetDir, manifest);
627
+ readAppStorefront(targetDir, manifest);
626
628
  assertCarrierDevelopmentInputs(targetDir, manifest, packageJson, managed, plannedSources);
627
629
  const findings = scanForbiddenPatterns(targetDir, manifest.profile, managed ? null : LOCAL_DEVELOPMENT_BYPASS_LABELS, plannedSources);
628
630
  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)) {
package/lib/app-pack.mjs CHANGED
@@ -25,7 +25,8 @@ import {
25
25
  } from 'node:fs';
26
26
  import path from 'node:path';
27
27
  import { parse as parseYaml, stringify as stringifyYaml } from 'yaml';
28
- import { APP_INFO_DECLARATION_FIELDS, APP_INFO_MAX_BYTES, readAppInfo, validateAppInfo } from './app-info.mjs';
28
+ import { APP_INFO_DECLARATION_FIELDS, APP_INFO_MAX_BYTES, readAppInfo, readAppStorefront, validateAppInfo } from './app-info.mjs';
29
+ import { STOREFRONT_ARCHIVE_MAX_BYTES } from './storefront-media.mjs';
29
30
  import { observeWindowsExecutableFacts } from './windows-powershell.mjs';
30
31
  import { SYMBOLIC_LINK_MODE, validatePayloadLinks } from './payload-links.mjs';
31
32
  import { observeMacOSExecutableFacts } from './macos-native.mjs';
@@ -536,6 +537,7 @@ export function aggregateAppTargetCandidates(cwd, options = {}) {
536
537
  const appId = targets[0].app_id;
537
538
  const version = targets[0].version;
538
539
  const seen = new Set();
540
+ const parsedInfos = [];
539
541
  for (const target of targets) {
540
542
  const metadataLabel = `${target.target_id || 'unknown'} target metadata`;
541
543
  if (target.format !== TARGET_METADATA_FORMAT || target.app_id !== appId || target.version !== version) throw new Error('Target metadata cannot be aggregated across App releases');
@@ -566,6 +568,7 @@ export function aggregateAppTargetCandidates(cwd, options = {}) {
566
568
  if (infoBytes.length !== infoAsset.size || createHash('sha256').update(infoBytes).digest('hex') !== infoAsset.sha256 || !entries.get('app-info.json')?.bytes.equals(infoBytes)) throw new Error(`Target App info changed or differs from archive: ${target.target_id}`);
567
569
  const info = validateAppInfo(JSON.parse(infoBytes));
568
570
  if (info.app_id !== appId || info.version !== version || info.target_id !== target.target_id) throw new Error(`Target App info identity differs: ${target.target_id}`);
571
+ parsedInfos.push({ targetId: target.target_id, info });
569
572
  validatePayloadLinks(entries, target.os);
570
573
  const manifest = readPackageManifestFromArchive(entries, metadataLabel);
571
574
  if (manifest.format !== PACKAGE_FORMAT) throw new Error(`Target archive manifest format is invalid: ${target.asset_name}`);
@@ -580,8 +583,53 @@ export function aggregateAppTargetCandidates(cwd, options = {}) {
580
583
  throw new Error(`Target archive runtime_entry is missing or non-executable: ${runtimeEntry}`);
581
584
  }
582
585
  }
583
- const candidate = { format: AGGREGATE_FORMAT, app_id: appId, version, targets: targets.sort((left, right) => compareText(left.target_id, right.target_id)) };
586
+ const firstInfo = parsedInfos[0].info;
587
+ for (const entry of parsedInfos.slice(1)) {
588
+ for (const field of ['display_name', 'summary', 'icon', 'readme_markdown', 'release_notes_markdown', 'safety_profile', 'storefront']) {
589
+ if (!sameCanonicalValue(entry.info[field], firstInfo[field])) {
590
+ throw new Error(`Target App info ${field} differs between ${parsedInfos[0].targetId} and ${entry.targetId}; one release shares one presentation`);
591
+ }
592
+ }
593
+ }
594
+ let storefrontMedia;
595
+ if (firstInfo.storefront?.media !== undefined) {
596
+ const repoManifest = readYaml(path.join(targetDir, 'nimi.app.yaml'), 'nimi.app.yaml');
597
+ const { storefront: repoStorefront, mediaEntries } = readAppStorefront(targetDir, repoManifest);
598
+ if (!sameCanonicalValue(repoStorefront?.media, firstInfo.storefront.media)) {
599
+ throw new Error('Repository storefront media changed after target packing; rebuild targets and aggregate from the same commit');
600
+ }
601
+ const archiveEntries = [...mediaEntries.entries()]
602
+ .sort(([left], [right]) => compareText(left, right))
603
+ .map(([name, bytes]) => ({ name, bytes, mode: 0o644 }));
604
+ const mediaArchive = writeNimiAppArchive(archiveEntries);
605
+ if (mediaArchive.length > STOREFRONT_ARCHIVE_MAX_BYTES) {
606
+ throw new Error(`Storefront media archive exceeds ${STOREFRONT_ARCHIVE_MAX_BYTES} bytes`);
607
+ }
608
+ const mediaAssetName = `${appId}-${version}-storefront-media.zip`;
609
+ const mediaArchivePath = path.join(outputDir, mediaAssetName);
610
+ writeAppArchiveFile(mediaArchivePath, mediaArchive);
611
+ storefrontMedia = {
612
+ asset_name: mediaAssetName,
613
+ size: mediaArchive.length,
614
+ sha256: hashAppArchive(mediaArchive),
615
+ };
616
+ }
617
+ const candidate = {
618
+ format: AGGREGATE_FORMAT,
619
+ app_id: appId,
620
+ version,
621
+ ...(storefrontMedia ? { storefront_media: storefrontMedia } : {}),
622
+ targets: targets.sort((left, right) => compareText(left.target_id, right.target_id)),
623
+ };
584
624
  const candidatePath = path.join(outputDir, `${appId}-${version}.candidate.json`);
585
625
  writeFileSync(candidatePath, canonicalJson(candidate));
586
- return { ok: true, command: 'pack', aggregate: true, dir: targetDir, candidatePath, ...candidate };
626
+ return {
627
+ ok: true,
628
+ command: 'pack',
629
+ aggregate: true,
630
+ dir: targetDir,
631
+ candidatePath,
632
+ ...(storefrontMedia ? { storefrontMediaPath: path.join(outputDir, storefrontMedia.asset_name) } : {}),
633
+ ...candidate,
634
+ };
587
635
  }
@@ -278,6 +278,7 @@ const APP_RELEASE_WORKFLOW = [
278
278
  ' dist/nimi-app/*.target.json',
279
279
  ' dist/nimi-app/*.app-info.json',
280
280
  ' dist/nimi-app/*.candidate.json',
281
+ ' dist/nimi-app/*-storefront-media.zip',
281
282
  ' if-no-files-found: error',
282
283
  ' release:',
283
284
  " if: github.event_name == 'push' && github.ref_type == 'tag'",
@@ -316,7 +317,7 @@ const APP_RELEASE_WORKFLOW = [
316
317
  " sleep 10",
317
318
  " done",
318
319
  " }",
319
- ' assets=(release-assets/*.nimiapp release-assets/*.app-info.json release-assets/*.candidate.json)',
320
+ ' assets=(release-assets/*.nimiapp release-assets/*.app-info.json release-assets/*.candidate.json release-assets/*-storefront-media.zip)',
320
321
  ' test "${#assets[@]}" -gt 0',
321
322
  " expected=$(printf '%s\\n' \"${assets[@]##*/}\" | jq -R -s -c 'split(\"\\n\")[:-1] | sort')",
322
323
  ' if release_id=$(gh release view "$GITHUB_REF_NAME" --repo "$GITHUB_REPOSITORY" --json databaseId --jq .databaseId 2>/dev/null); then',
@@ -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.10",
3
+ "version": "0.16.0-rc.12",
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.10",
22
+ "appToolsVersion": "^0.16.0-rc.12",
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/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",