@vectoriox/iox-ui 5.97.0 → 5.98.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/fesm2022/vectoriox-iox-ui-generation-core.mjs +1114 -223
- package/fesm2022/vectoriox-iox-ui-generation-core.mjs.map +1 -1
- package/fesm2022/vectoriox-iox-ui-harness-core.mjs +115 -42
- package/fesm2022/vectoriox-iox-ui-harness-core.mjs.map +1 -1
- package/generation-core/index.d.ts +515 -17
- package/harness-core/index.d.ts +66 -6
- package/package.json +1 -1
- package/src/generation-core/audit-site.ts +8 -0
- package/src/generation-core/compose-site.ts +130 -4
- package/src/generation-core/nav-shape.ts +4 -2
- package/src/generation-core/patterns.ts +25 -1
- package/src/generation-core/pictures.ts +1 -1
- package/src/generation-core/plan-derived.ts +10 -5
- package/src/generation-core/plan-edits.ts +8 -7
- package/src/generation-core/plan-wire.ts +59 -10
- package/src/generation-core/plan-words.ts +18 -1
- package/src/generation-core/public-api.ts +1 -0
- package/src/generation-core/shop-plan.ts +165 -0
- package/src/generation-core/showcase.ts +29 -4
- package/src/generation-core/site-build-run.ts +25 -0
- package/src/generation-core/site-plan.model.ts +49 -1
- package/src/generation-core/site-spec.generated.ts +330 -2
- package/src/generation-core/stock-photos.ts +19 -2
- package/src/generation-core/validate-site-plan.ts +146 -8
- package/src/harness-core/business-types.ts +13 -0
- package/src/harness-core/harness-spec.generated.ts +69 -39
- package/src/harness-core/needs.ts +30 -1
- package/src/harness-core/site-reading.ts +8 -2
|
@@ -7,9 +7,11 @@ import {
|
|
|
7
7
|
BindScope, patternById, patternHasForm, patternLinkSlots, patternNeedsBinding, patternOptionalParts, patternRoleNeeds, patternTakesBinding, patternScopes,
|
|
8
8
|
patternSlots, PatternGlobalPosition, slotBudget, SCENE_LEVEL, SCENE_OTHER_PAGES } from './patterns';
|
|
9
9
|
import { ContentFieldControl, FIELD_TYPE_OF_CONTROL,
|
|
10
|
-
FACT_KEYS, GlobalSlot, PAGE_ARCHETYPES, SITE_NEED_IDS, PlanDataSourceMode, PlanDataSourceType, RelativeOp, REQUIRED_CONTENT_ROLES,
|
|
11
|
-
SITE_LOCALES, SITE_PLAN_VERSION,
|
|
10
|
+
FACT_KEYS, GlobalSlot, PAGE_ARCHETYPES, SITE_NEED_IDS, PlanDataSourceMode, PlanDataSourceType, RelativeOp, REQUIRED_CONTENT_ROLES, ShopResource, SitePlan,
|
|
11
|
+
SitePlanSourceKind, SITE_LOCALES, SITE_PLAN_VERSION,
|
|
12
12
|
} from './site-plan.model';
|
|
13
|
+
import { pricesIn } from './plan-words';
|
|
14
|
+
import { isShopResource, planSells, SHOP_PRODUCTS_MAX, SHOP_SLUG_FIELD, shopContentType } from './shop-plan';
|
|
13
15
|
import { artDirectionIssues } from './art-direction';
|
|
14
16
|
import { patternListGap } from './recipe-fields';
|
|
15
17
|
import { SPEC_SITE_LAYOUT, SPEC_SITE_PLAN_SHAPE } from './site-spec.generated';
|
|
@@ -85,6 +87,20 @@ export enum SitePlanIssueCode {
|
|
|
85
87
|
Compose = 'compose',
|
|
86
88
|
/** M8 gate 2: a composed page's layout (`checkLayout`'s issues, each at its path under `layout`). */
|
|
87
89
|
Layout = 'layout',
|
|
90
|
+
/** Commerce C-D21: what the business sells — a selling business without its products, one that sells nothing with a
|
|
91
|
+
* shop, a product past the sixth, a shop source with no shop, or a content type named after a shop list. */
|
|
92
|
+
Shop = 'shop',
|
|
93
|
+
/** Commerce C-D21: a selling site has a product page — a page at a `:slug` route reading the shop's one product. */
|
|
94
|
+
ProductPage = 'product-page',
|
|
95
|
+
/** Commerce C-D21: a price, a stock count or a fee written into what the business sells — the owner sets those. */
|
|
96
|
+
Price = 'price',
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/** What the validator is told about the business (iox-cms's reading), beyond the plan itself. */
|
|
100
|
+
export interface SitePlanContext {
|
|
101
|
+
/** True: the business sells (the reading's need `products`) — the plan must name what. False: it sells nothing — the
|
|
102
|
+
* plan holds no shop. Absent: the plan is judged as written (a template, a stored plan). */
|
|
103
|
+
readonly sells?: boolean;
|
|
88
104
|
}
|
|
89
105
|
|
|
90
106
|
export type SitePlanIssue = PathIssue<SitePlanIssueCode>;
|
|
@@ -122,6 +138,10 @@ const SLUG_FIELD = 'slug';
|
|
|
122
138
|
const SEED_FIXED_KEYS = shapeKeys(SHAPE['seed']);
|
|
123
139
|
const CMS_SOURCE_KEYS = shapeKeys(SHAPE['cmsDataSource']);
|
|
124
140
|
const RELATIVE_SOURCE_KEYS = shapeKeys(SHAPE['relativeDataSource']);
|
|
141
|
+
const SHOP_SOURCE_KEYS = shapeKeys(SHAPE['shopDataSource']);
|
|
142
|
+
const SHOP_KEYS = shapeKeys(SHAPE['shop']);
|
|
143
|
+
const SHOP_PRODUCT_KEYS = shapeKeys(SHAPE['shopProduct']);
|
|
144
|
+
const SHOP_OPTION_KEYS = shapeKeys(SHAPE['shopOption']);
|
|
125
145
|
const PAGE_KEYS = shapeKeys(SHAPE['page']);
|
|
126
146
|
const FILM_KEYS = shapeKeys(SHAPE['film']);
|
|
127
147
|
const ART_DIRECTION_KEYS = shapeKeys(SHAPE['artDirection']);
|
|
@@ -288,6 +308,10 @@ function validateRoles(c: Collector, roles: unknown, path: string, typeName: str
|
|
|
288
308
|
|
|
289
309
|
interface SourceInfo { type: string; mode?: string; contentType?: string; routeParam?: string; of?: string; op?: string; }
|
|
290
310
|
|
|
311
|
+
/** A source a page may read ONE item from by its route (`routeSource`), or bind a list to — a cms one or the shop's. */
|
|
312
|
+
const isItemSource = (s: SourceInfo | undefined) => !!s && (s.type === PlanDataSourceType.Cms || s.type === PlanDataSourceType.Shop) && s.mode === PlanDataSourceMode.Single;
|
|
313
|
+
const isListSource = (s: SourceInfo | undefined) => !!s && (s.type === PlanDataSourceType.Cms || s.type === PlanDataSourceType.Shop) && s.mode === PlanDataSourceMode.Query;
|
|
314
|
+
|
|
291
315
|
function validateDataSources(c: Collector, list: unknown[], types: Map<string, ContentTypeInfo>): Map<string, SourceInfo> {
|
|
292
316
|
const sources = new Map<string, SourceInfo>();
|
|
293
317
|
list.forEach((raw, i) => {
|
|
@@ -324,8 +348,11 @@ function validateDataSources(c: Collector, list: unknown[], types: Map<string, C
|
|
|
324
348
|
c.string(raw, 'within', path);
|
|
325
349
|
if (!(Object.values(RelativeOp) as unknown[]).includes(raw['op'])) c.add(SitePlanIssueCode.InvalidDataSource, `${path}.op`, `must be one of ${Object.values(RelativeOp).join(', ')}`);
|
|
326
350
|
if (alias && !sources.has(alias)) sources.set(alias, { type: PlanDataSourceType.Relative, of: raw['of'] as string, op: raw['op'] as string });
|
|
351
|
+
} else if (raw['type'] === PlanDataSourceType.Shop) {
|
|
352
|
+
const routeParam = validateShopSource(c, raw, path);
|
|
353
|
+
if (alias && !sources.has(alias)) sources.set(alias, { type: PlanDataSourceType.Shop, mode: raw['mode'] as string, contentType: raw['resource'] as string, routeParam });
|
|
327
354
|
} else {
|
|
328
|
-
c.add(SitePlanIssueCode.InvalidDataSource, `${path}.type`, `must be
|
|
355
|
+
c.add(SitePlanIssueCode.InvalidDataSource, `${path}.type`, `must be one of ${Object.values(PlanDataSourceType).map(t => `"${t}"`).join(', ')}`);
|
|
329
356
|
}
|
|
330
357
|
});
|
|
331
358
|
c.unique(list.map(r => (isObject(r) && isNonEmptyString(r['alias']) ? r['alias'] : null)), i => `dataSources[${i}].alias`, 'alias');
|
|
@@ -341,6 +368,95 @@ function validateDataSources(c: Collector, list: unknown[], types: Map<string, C
|
|
|
341
368
|
return sources;
|
|
342
369
|
}
|
|
343
370
|
|
|
371
|
+
/** A shop source (derived — `derivedShopSources` — so a bad one is the plan's own writing): a list of the shop or one row of
|
|
372
|
+
* it by its slug. Returns the route param it is looked up by. */
|
|
373
|
+
function validateShopSource(c: Collector, raw: Obj, path: string): string | undefined {
|
|
374
|
+
c.keys(raw, SHOP_SOURCE_KEYS, path);
|
|
375
|
+
const mode = raw['mode'];
|
|
376
|
+
if (mode !== PlanDataSourceMode.Query && mode !== PlanDataSourceMode.Single) c.add(SitePlanIssueCode.InvalidDataSource, `${path}.mode`, `must be "${PlanDataSourceMode.Query}" or "${PlanDataSourceMode.Single}"`);
|
|
377
|
+
if (!isShopResource(raw['resource'])) c.add(SitePlanIssueCode.InvalidDataSource, `${path}.resource`, `must be one of ${Object.values(ShopResource).join(', ')}`);
|
|
378
|
+
if (raw['limit'] !== undefined && (!Number.isInteger(raw['limit']) || (raw['limit'] as number) < 1)) c.add(SitePlanIssueCode.InvalidDataSource, `${path}.limit`, 'must be a positive whole number');
|
|
379
|
+
const byRoute = raw['filterByRouteParam'];
|
|
380
|
+
if (byRoute === undefined) return undefined;
|
|
381
|
+
if (!isObject(byRoute)) { c.add(SitePlanIssueCode.Shape, `${path}.filterByRouteParam`, 'must be an object'); return undefined; }
|
|
382
|
+
c.keys(byRoute, ['field', 'routeParam'], `${path}.filterByRouteParam`);
|
|
383
|
+
const field = c.string(byRoute, 'field', `${path}.filterByRouteParam`);
|
|
384
|
+
const routeParam = c.string(byRoute, 'routeParam', `${path}.filterByRouteParam`) ?? undefined;
|
|
385
|
+
if (field && field !== SHOP_SLUG_FIELD) c.add(SitePlanIssueCode.InvalidDataSource, `${path}.filterByRouteParam.field`, `a shop row is looked up by its ${SHOP_SLUG_FIELD}`);
|
|
386
|
+
if (mode !== PlanDataSourceMode.Single) c.add(SitePlanIssueCode.InvalidDataSource, `${path}.filterByRouteParam`, 'only a single source is looked up by a route param');
|
|
387
|
+
return routeParam;
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
/**
|
|
391
|
+
* Commerce C-D21: what the business sells — up to six products by name, each in one of the categories, how each varies;
|
|
392
|
+
* never a price, a stock count or a fee (the owner sets those, shop-aware §3i). A selling business must say what it
|
|
393
|
+
* sells, one that sells nothing holds no shop, and a shop list is never a content type's name (its collection is the
|
|
394
|
+
* shop's). Returns whether the plan sells.
|
|
395
|
+
*/
|
|
396
|
+
function validateShop(c: Collector, plan: Obj, ctx: SitePlanContext): boolean {
|
|
397
|
+
c.array(plan, 'contentTypes', '').forEach((t, i) => {
|
|
398
|
+
if (isObject(t) && isShopResource(t['name'])) c.add(SitePlanIssueCode.Shop, `contentTypes[${i}].name`, `"${t['name']}" is the shop's own list — what the business sells goes in shop, never a content type`);
|
|
399
|
+
});
|
|
400
|
+
const shop = plan['shop'];
|
|
401
|
+
const sells = planSells(plan);
|
|
402
|
+
if (ctx.sells === true && !sells) c.add(SitePlanIssueCode.Shop, 'shop', `this business sells — name what (1–${SHOP_PRODUCTS_MAX} products, each in a category)`);
|
|
403
|
+
if (ctx.sells === false && shop !== undefined) c.add(SitePlanIssueCode.Shop, 'shop', 'this business sells nothing online — no shop');
|
|
404
|
+
if (!sells) {
|
|
405
|
+
c.array(plan, 'dataSources', '').forEach((d, i) => {
|
|
406
|
+
if (isObject(d) && d['type'] === PlanDataSourceType.Shop) c.add(SitePlanIssueCode.Shop, `dataSources[${i}]`, 'a shop source on a plan that sells nothing');
|
|
407
|
+
});
|
|
408
|
+
}
|
|
409
|
+
if (shop === undefined) return sells;
|
|
410
|
+
if (!isObject(shop)) { c.add(SitePlanIssueCode.Shape, 'shop', 'must be an object'); return false; }
|
|
411
|
+
c.keys(shop, SHOP_KEYS, 'shop');
|
|
412
|
+
const categories = c.array(shop, 'categories', 'shop');
|
|
413
|
+
categories.forEach((name, i) => { if (!isNonEmptyString(name)) c.add(SitePlanIssueCode.Shape, `shop.categories[${i}]`, 'must be a name'); });
|
|
414
|
+
c.unique(categories.map(n => (isNonEmptyString(n) ? n : null)), i => `shop.categories[${i}]`, 'category');
|
|
415
|
+
const products = c.array(shop, 'products', 'shop');
|
|
416
|
+
if (!products.length) c.add(SitePlanIssueCode.Shop, 'shop.products', 'name what the business sells, or hold no shop');
|
|
417
|
+
if (products.length > SHOP_PRODUCTS_MAX) c.add(SitePlanIssueCode.Shop, 'shop.products', `${products.length} products — at most ${SHOP_PRODUCTS_MAX} samples`);
|
|
418
|
+
const price = (path: string, text: unknown) => {
|
|
419
|
+
if (typeof text === 'string' && pricesIn(text).length) c.add(SitePlanIssueCode.Price, path, `"${pricesIn(text)[0]}" — never a price, stock or fee: the owner sets those`);
|
|
420
|
+
};
|
|
421
|
+
products.forEach((raw, i) => {
|
|
422
|
+
const path = `shop.products[${i}]`;
|
|
423
|
+
if (!isObject(raw)) return c.add(SitePlanIssueCode.Shape, path, 'must be an object');
|
|
424
|
+
c.keys(raw, SHOP_PRODUCT_KEYS, path);
|
|
425
|
+
price(`${path}.name`, c.string(raw, 'name', path));
|
|
426
|
+
const category = c.string(raw, 'category', path);
|
|
427
|
+
if (category && !categories.includes(category)) c.add(SitePlanIssueCode.Shop, `${path}.category`, `"${category}" is not one of the shop's categories`);
|
|
428
|
+
const description = raw['description'];
|
|
429
|
+
if (typeof description !== 'string') c.add(SitePlanIssueCode.Shape, `${path}.description`, 'must be a string (one line)');
|
|
430
|
+
else price(`${path}.description`, description);
|
|
431
|
+
const options = c.array(raw, 'options', path);
|
|
432
|
+
options.forEach((o, j) => {
|
|
433
|
+
const op = `${path}.options[${j}]`;
|
|
434
|
+
if (!isObject(o)) return c.add(SitePlanIssueCode.Shape, op, 'must be an object');
|
|
435
|
+
c.keys(o, SHOP_OPTION_KEYS, op);
|
|
436
|
+
c.string(o, 'name', op);
|
|
437
|
+
const values = c.array(o, 'values', op);
|
|
438
|
+
if (!values.length) c.add(SitePlanIssueCode.Shop, `${op}.values`, 'an option names its values (sizes, colours…)');
|
|
439
|
+
values.forEach((v, k) => { if (!isNonEmptyString(v)) c.add(SitePlanIssueCode.Shape, `${op}.values[${k}]`, 'must be a name'); else price(`${op}.values[${k}]`, v); });
|
|
440
|
+
c.unique(values.map(v => (isNonEmptyString(v) ? v : null)), k => `${op}.values[${k}]`, 'value');
|
|
441
|
+
});
|
|
442
|
+
c.unique(options.map(o => (isObject(o) && isNonEmptyString(o['name']) ? o['name'] : null)), j => `${path}.options[${j}].name`, 'option');
|
|
443
|
+
});
|
|
444
|
+
c.unique(products.map(p => (isObject(p) && isNonEmptyString(p['name']) ? p['name'] : null)), i => `shop.products[${i}].name`, 'product');
|
|
445
|
+
return sells;
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
/** A selling site has a product page: a page whose route item is the shop's one product (`/shop/:slug`). */
|
|
449
|
+
function validateProductPage(c: Collector, pages: unknown[], sources: Map<string, SourceInfo>): void {
|
|
450
|
+
const hasProductPage = pages.some(p => {
|
|
451
|
+
const source = isObject(p) && typeof p['routeSource'] === 'string' ? sources.get(p['routeSource']) : undefined;
|
|
452
|
+
return source?.type === PlanDataSourceType.Shop && source.mode === PlanDataSourceMode.Single && source.contentType === ShopResource.Products;
|
|
453
|
+
});
|
|
454
|
+
if (!hasProductPage) {
|
|
455
|
+
const item = [...sources].find(([, s]) => s.type === PlanDataSourceType.Shop && s.mode === PlanDataSourceMode.Single)?.[0] ?? 'product';
|
|
456
|
+
c.add(SitePlanIssueCode.ProductPage, 'pages', `this site sells — it needs a product page: a page at /shop/:slug whose routeSource is "${item}" and template "${ShopResource.Products}"`);
|
|
457
|
+
}
|
|
458
|
+
}
|
|
459
|
+
|
|
344
460
|
function validatePages(c: Collector, list: unknown[], types: Map<string, ContentTypeInfo>, sources: Map<string, SourceInfo>, density: string | null): void {
|
|
345
461
|
const homes: number[] = [];
|
|
346
462
|
const routes = new Set(list.map(p => (isObject(p) && typeof p['route'] === 'string' ? p['route'] : null)).filter((r): r is string => !!r));
|
|
@@ -365,13 +481,13 @@ function validatePages(c: Collector, list: unknown[], types: Map<string, Content
|
|
|
365
481
|
const template = c.string(raw, 'template', path, false);
|
|
366
482
|
const routeSourceAlias = c.string(raw, 'routeSource', path, false);
|
|
367
483
|
const routeSource = routeSourceAlias ? sources.get(routeSourceAlias) : undefined;
|
|
368
|
-
const routeSourceOk =
|
|
484
|
+
const routeSourceOk = isItemSource(routeSource);
|
|
369
485
|
if (template && !types.has(template)) c.add(SitePlanIssueCode.UnknownContentType, `${path}.template`, `no content type "${template}" in the plan`);
|
|
370
486
|
if (params.length > 1) c.add(SitePlanIssueCode.InvalidRoute, `${path}.route`, 'a template page has one route param');
|
|
371
487
|
if (params.length && !routeSourceAlias) c.add(SitePlanIssueCode.RouteSource, `${path}.routeSource`, `a route with :${params[0]} names the source that reads it`);
|
|
372
488
|
if (routeSourceAlias) {
|
|
373
489
|
if (!routeSourceOk) {
|
|
374
|
-
c.add(SitePlanIssueCode.RouteSource, `${path}.routeSource`, `"${routeSourceAlias}" must be a single
|
|
490
|
+
c.add(SitePlanIssueCode.RouteSource, `${path}.routeSource`, `"${routeSourceAlias}" must be a single source of the plan`);
|
|
375
491
|
} else {
|
|
376
492
|
if (!params.length || routeSource!.routeParam !== params[0]) c.add(SitePlanIssueCode.RouteSource, `${path}.routeSource`, `"${routeSourceAlias}" is not looked up by this route's param`);
|
|
377
493
|
if (template && routeSource!.contentType !== template) c.add(SitePlanIssueCode.RouteSource, `${path}.template`, `"${routeSourceAlias}" reads ${routeSource!.contentType}, not ${template}`);
|
|
@@ -439,7 +555,7 @@ function validatePages(c: Collector, list: unknown[], types: Map<string, Content
|
|
|
439
555
|
} else {
|
|
440
556
|
const src = sources.get(binding);
|
|
441
557
|
if (!src) c.add(SitePlanIssueCode.UnknownDataSource, `${sp}.binding`, `no data source "${binding}"`);
|
|
442
|
-
else if (src
|
|
558
|
+
else if (!isListSource(src)) c.add(SitePlanIssueCode.Binding, `${sp}.binding`, `"${binding}" is not a list source`);
|
|
443
559
|
else {
|
|
444
560
|
const listed = src.contentType ? types.get(src.contentType) : undefined;
|
|
445
561
|
const gap = listed ? patternListGap(pattern, listed.described) : null;
|
|
@@ -448,6 +564,15 @@ function validatePages(c: Collector, list: unknown[], types: Map<string, Content
|
|
|
448
564
|
}
|
|
449
565
|
} else if (binding) c.add(SitePlanIssueCode.Binding, `${sp}.binding`, `"${patternId}" repeats nothing — it takes no binding`);
|
|
450
566
|
|
|
567
|
+
// Commerce G1: a store section reads the shop — its list from a shop source, its product from the page's.
|
|
568
|
+
if (pattern.shop) {
|
|
569
|
+
const listed = binding ? sources.get(binding) : undefined;
|
|
570
|
+
if (listed && listed.type !== PlanDataSourceType.Shop) c.add(SitePlanIssueCode.Binding, `${sp}.binding`, `"${patternId}" shows the shop's products — bind a shop source, not "${binding}"`);
|
|
571
|
+
if (patternScopes(pattern).has(BindScope.Route) && routeSourceOk && routeSource!.type !== PlanDataSourceType.Shop) {
|
|
572
|
+
c.add(SitePlanIssueCode.RouteSource, `${sp}.pattern`, `"${patternId}" shows one product — its page reads a shop source, not "${routeSourceAlias}"`);
|
|
573
|
+
}
|
|
574
|
+
}
|
|
575
|
+
|
|
451
576
|
// A pattern reading the route item needs a routeSource (an INVALID one is reported above, once).
|
|
452
577
|
const scopes = patternScopes(pattern);
|
|
453
578
|
const readsRoute = scopes.has(BindScope.Route) || scopes.has(BindScope.Next);
|
|
@@ -561,7 +686,7 @@ function validateGlobals(c: Collector, globals: unknown): void {
|
|
|
561
686
|
}
|
|
562
687
|
|
|
563
688
|
/** Check a Site Plan against the plan shape and the pattern library. Never throws, never repairs. */
|
|
564
|
-
export function validateSitePlan(plan: unknown): SitePlanValidation {
|
|
689
|
+
export function validateSitePlan(plan: unknown, ctx: SitePlanContext = {}): SitePlanValidation {
|
|
565
690
|
const c = new Collector();
|
|
566
691
|
if (!isObject(plan)) {
|
|
567
692
|
c.add(SitePlanIssueCode.Shape, '', 'a site plan is an object');
|
|
@@ -575,8 +700,10 @@ export function validateSitePlan(plan: unknown): SitePlanValidation {
|
|
|
575
700
|
validateDesign(c, plan['design']);
|
|
576
701
|
const types = validateContentTypes(c, c.array(plan, 'contentTypes', ''));
|
|
577
702
|
const sources = validateDataSources(c, c.array(plan, 'dataSources', ''), types);
|
|
703
|
+
const sells = validateShop(c, plan, ctx);
|
|
578
704
|
const design = isObject(plan['design']) ? plan['design'] : {};
|
|
579
|
-
validatePages(c, c.array(plan, 'pages', ''), types, sources, typeof design['density'] === 'string' ? design['density'] : null);
|
|
705
|
+
validatePages(c, c.array(plan, 'pages', ''), withShopTypes(types, sources), sources, typeof design['density'] === 'string' ? design['density'] : null);
|
|
706
|
+
if (sells) validateProductPage(c, c.array(plan, 'pages', ''), sources);
|
|
580
707
|
validateGlobals(c, plan['globals']);
|
|
581
708
|
validateScenes(c, c.array(plan, 'pages', ''), typeof design['animate'] === 'string' ? design['animate'] : null);
|
|
582
709
|
validateFilm(c, plan['film'], c.array(plan, 'pages', ''));
|
|
@@ -627,6 +754,17 @@ function validateComposed(c: Collector, pages: unknown[]): void {
|
|
|
627
754
|
if (composed > COMPOSED_PAGES_MAX) c.add(SitePlanIssueCode.Compose, 'pages', `${composed} composed pages — the home page and at most ${COMPOSED_PAGES_MAX - 1} other`);
|
|
628
755
|
}
|
|
629
756
|
|
|
757
|
+
/** The plan's content types and, for each shop list a source reads, the shop's own (fixed fields and roles). */
|
|
758
|
+
function withShopTypes(types: Map<string, ContentTypeInfo>, sources: Map<string, SourceInfo>): Map<string, ContentTypeInfo> {
|
|
759
|
+
const out = new Map(types);
|
|
760
|
+
for (const s of sources.values()) {
|
|
761
|
+
if (s.type !== PlanDataSourceType.Shop || !isShopResource(s.contentType) || out.has(s.contentType)) continue;
|
|
762
|
+
const shop = shopContentType(s.contentType);
|
|
763
|
+
out.set(s.contentType, { fields: new Set(shop.fields.map(f => f.name)), described: shop.fields.map(f => ({ ...f })), roles: { ...shop.roles } as Record<string, string> });
|
|
764
|
+
}
|
|
765
|
+
return out;
|
|
766
|
+
}
|
|
767
|
+
|
|
630
768
|
/** Throw a `SitePlanError` carrying every issue unless the plan is valid. */
|
|
631
769
|
export function assertValidSitePlan(plan: unknown): void {
|
|
632
770
|
const result = validateSitePlan(plan);
|
|
@@ -39,6 +39,18 @@ export enum BookingNeed {
|
|
|
39
39
|
None = 'none',
|
|
40
40
|
}
|
|
41
41
|
|
|
42
|
+
/** Commerce C-D21: whether a kind of business sells online — the need `products` (its site is a whole store). */
|
|
43
|
+
export enum SellingNeed {
|
|
44
|
+
/** It sells: the reading names `products` (from: type) — the owner may switch it off. */
|
|
45
|
+
Inferred = 'inferred',
|
|
46
|
+
/** It may sell (a café's beans, an artist's prints): offered on Analysis, switched off until the owner says so. */
|
|
47
|
+
Offered = 'offered',
|
|
48
|
+
/** Care and trust work: never a shop, whatever a reading said. */
|
|
49
|
+
Never = 'never',
|
|
50
|
+
/** Not on the lists: as the owner said. */
|
|
51
|
+
None = 'none',
|
|
52
|
+
}
|
|
53
|
+
|
|
42
54
|
/** The content checks of the avoid grammar (a look rule is the other kind). */
|
|
43
55
|
export enum AvoidCheck {
|
|
44
56
|
NeedsFamily = 'needs-family',
|
|
@@ -131,6 +143,7 @@ export interface BusinessType {
|
|
|
131
143
|
/** Stock photos may fill its pictures (never the work itself). */
|
|
132
144
|
readonly stock: boolean;
|
|
133
145
|
readonly booking: `${BookingNeed}`;
|
|
146
|
+
readonly sells: `${SellingNeed}`;
|
|
134
147
|
}
|
|
135
148
|
|
|
136
149
|
/** The 30, in the board's order. Assignment here proves the generated data fits the type. */
|
|
@@ -15,6 +15,10 @@ export const SPEC_NEEDS = {
|
|
|
15
15
|
"label": "Your work or products",
|
|
16
16
|
"archetype": "collection"
|
|
17
17
|
},
|
|
18
|
+
"products": {
|
|
19
|
+
"label": "Products you sell",
|
|
20
|
+
"archetype": "collection"
|
|
21
|
+
},
|
|
18
22
|
"detail": {
|
|
19
23
|
"label": "A page for each item",
|
|
20
24
|
"archetype": "detail"
|
|
@@ -260,7 +264,8 @@ export const SPEC_BUSINESS_TYPES = [
|
|
|
260
264
|
"structure": "studio",
|
|
261
265
|
"slice": true,
|
|
262
266
|
"stock": false,
|
|
263
|
-
"booking": "sometimes"
|
|
267
|
+
"booking": "sometimes",
|
|
268
|
+
"sells": "offered"
|
|
264
269
|
},
|
|
265
270
|
{
|
|
266
271
|
"id": "interior-design",
|
|
@@ -372,7 +377,8 @@ export const SPEC_BUSINESS_TYPES = [
|
|
|
372
377
|
"structure": "studio",
|
|
373
378
|
"slice": true,
|
|
374
379
|
"stock": false,
|
|
375
|
-
"booking": "none"
|
|
380
|
+
"booking": "none",
|
|
381
|
+
"sells": "none"
|
|
376
382
|
},
|
|
377
383
|
{
|
|
378
384
|
"id": "architecture",
|
|
@@ -479,7 +485,8 @@ export const SPEC_BUSINESS_TYPES = [
|
|
|
479
485
|
"structure": "studio",
|
|
480
486
|
"slice": false,
|
|
481
487
|
"stock": false,
|
|
482
|
-
"booking": "none"
|
|
488
|
+
"booking": "none",
|
|
489
|
+
"sells": "none"
|
|
483
490
|
},
|
|
484
491
|
{
|
|
485
492
|
"id": "creative-studio",
|
|
@@ -578,7 +585,8 @@ export const SPEC_BUSINESS_TYPES = [
|
|
|
578
585
|
"structure": "studio",
|
|
579
586
|
"slice": false,
|
|
580
587
|
"stock": false,
|
|
581
|
-
"booking": "none"
|
|
588
|
+
"booking": "none",
|
|
589
|
+
"sells": "none"
|
|
582
590
|
},
|
|
583
591
|
{
|
|
584
592
|
"id": "artist",
|
|
@@ -679,7 +687,8 @@ export const SPEC_BUSINESS_TYPES = [
|
|
|
679
687
|
"structure": "studio",
|
|
680
688
|
"slice": false,
|
|
681
689
|
"stock": false,
|
|
682
|
-
"booking": "none"
|
|
690
|
+
"booking": "none",
|
|
691
|
+
"sells": "offered"
|
|
683
692
|
},
|
|
684
693
|
{
|
|
685
694
|
"id": "makers",
|
|
@@ -751,8 +760,7 @@ export const SPEC_BUSINESS_TYPES = [
|
|
|
751
760
|
"contact"
|
|
752
761
|
],
|
|
753
762
|
"needs": [
|
|
754
|
-
"
|
|
755
|
-
"detail",
|
|
763
|
+
"products",
|
|
756
764
|
"about",
|
|
757
765
|
"contact"
|
|
758
766
|
],
|
|
@@ -785,7 +793,8 @@ export const SPEC_BUSINESS_TYPES = [
|
|
|
785
793
|
"structure": "studio",
|
|
786
794
|
"slice": true,
|
|
787
795
|
"stock": false,
|
|
788
|
-
"booking": "sometimes"
|
|
796
|
+
"booking": "sometimes",
|
|
797
|
+
"sells": "inferred"
|
|
789
798
|
},
|
|
790
799
|
{
|
|
791
800
|
"id": "jewellery",
|
|
@@ -849,8 +858,7 @@ export const SPEC_BUSINESS_TYPES = [
|
|
|
849
858
|
"contact"
|
|
850
859
|
],
|
|
851
860
|
"needs": [
|
|
852
|
-
"
|
|
853
|
-
"detail",
|
|
861
|
+
"products",
|
|
854
862
|
"about",
|
|
855
863
|
"contact"
|
|
856
864
|
],
|
|
@@ -887,7 +895,8 @@ export const SPEC_BUSINESS_TYPES = [
|
|
|
887
895
|
"structure": "studio",
|
|
888
896
|
"slice": false,
|
|
889
897
|
"stock": false,
|
|
890
|
-
"booking": "none"
|
|
898
|
+
"booking": "none",
|
|
899
|
+
"sells": "inferred"
|
|
891
900
|
},
|
|
892
901
|
{
|
|
893
902
|
"id": "tattoo",
|
|
@@ -984,7 +993,8 @@ export const SPEC_BUSINESS_TYPES = [
|
|
|
984
993
|
"structure": "studio",
|
|
985
994
|
"slice": false,
|
|
986
995
|
"stock": false,
|
|
987
|
-
"booking": "must"
|
|
996
|
+
"booking": "must",
|
|
997
|
+
"sells": "none"
|
|
988
998
|
},
|
|
989
999
|
{
|
|
990
1000
|
"id": "spa",
|
|
@@ -1101,7 +1111,8 @@ export const SPEC_BUSINESS_TYPES = [
|
|
|
1101
1111
|
"structure": "practice",
|
|
1102
1112
|
"slice": true,
|
|
1103
1113
|
"stock": true,
|
|
1104
|
-
"booking": "must"
|
|
1114
|
+
"booking": "must",
|
|
1115
|
+
"sells": "none"
|
|
1105
1116
|
},
|
|
1106
1117
|
{
|
|
1107
1118
|
"id": "salon",
|
|
@@ -1207,7 +1218,8 @@ export const SPEC_BUSINESS_TYPES = [
|
|
|
1207
1218
|
"structure": "practice",
|
|
1208
1219
|
"slice": true,
|
|
1209
1220
|
"stock": true,
|
|
1210
|
-
"booking": "must"
|
|
1221
|
+
"booking": "must",
|
|
1222
|
+
"sells": "none"
|
|
1211
1223
|
},
|
|
1212
1224
|
{
|
|
1213
1225
|
"id": "yoga",
|
|
@@ -1309,7 +1321,8 @@ export const SPEC_BUSINESS_TYPES = [
|
|
|
1309
1321
|
"structure": "practice",
|
|
1310
1322
|
"slice": false,
|
|
1311
1323
|
"stock": true,
|
|
1312
|
-
"booking": "must"
|
|
1324
|
+
"booking": "must",
|
|
1325
|
+
"sells": "none"
|
|
1313
1326
|
},
|
|
1314
1327
|
{
|
|
1315
1328
|
"id": "fitness",
|
|
@@ -1419,7 +1432,8 @@ export const SPEC_BUSINESS_TYPES = [
|
|
|
1419
1432
|
"structure": "practice",
|
|
1420
1433
|
"slice": false,
|
|
1421
1434
|
"stock": true,
|
|
1422
|
-
"booking": "must"
|
|
1435
|
+
"booking": "must",
|
|
1436
|
+
"sells": "none"
|
|
1423
1437
|
},
|
|
1424
1438
|
{
|
|
1425
1439
|
"id": "therapist",
|
|
@@ -1530,7 +1544,8 @@ export const SPEC_BUSINESS_TYPES = [
|
|
|
1530
1544
|
"structure": "practice",
|
|
1531
1545
|
"slice": false,
|
|
1532
1546
|
"stock": true,
|
|
1533
|
-
"booking": "must"
|
|
1547
|
+
"booking": "must",
|
|
1548
|
+
"sells": "never"
|
|
1534
1549
|
},
|
|
1535
1550
|
{
|
|
1536
1551
|
"id": "clinic",
|
|
@@ -1644,7 +1659,8 @@ export const SPEC_BUSINESS_TYPES = [
|
|
|
1644
1659
|
"structure": "practice",
|
|
1645
1660
|
"slice": true,
|
|
1646
1661
|
"stock": true,
|
|
1647
|
-
"booking": "must"
|
|
1662
|
+
"booking": "must",
|
|
1663
|
+
"sells": "never"
|
|
1648
1664
|
},
|
|
1649
1665
|
{
|
|
1650
1666
|
"id": "dental",
|
|
@@ -1743,7 +1759,8 @@ export const SPEC_BUSINESS_TYPES = [
|
|
|
1743
1759
|
"structure": "practice",
|
|
1744
1760
|
"slice": false,
|
|
1745
1761
|
"stock": true,
|
|
1746
|
-
"booking": "must"
|
|
1762
|
+
"booking": "must",
|
|
1763
|
+
"sells": "never"
|
|
1747
1764
|
},
|
|
1748
1765
|
{
|
|
1749
1766
|
"id": "vet",
|
|
@@ -1843,7 +1860,8 @@ export const SPEC_BUSINESS_TYPES = [
|
|
|
1843
1860
|
"structure": "practice",
|
|
1844
1861
|
"slice": false,
|
|
1845
1862
|
"stock": true,
|
|
1846
|
-
"booking": "must"
|
|
1863
|
+
"booking": "must",
|
|
1864
|
+
"sells": "none"
|
|
1847
1865
|
},
|
|
1848
1866
|
{
|
|
1849
1867
|
"id": "restaurant",
|
|
@@ -1951,7 +1969,8 @@ export const SPEC_BUSINESS_TYPES = [
|
|
|
1951
1969
|
"structure": "place",
|
|
1952
1970
|
"slice": false,
|
|
1953
1971
|
"stock": true,
|
|
1954
|
-
"booking": "tables"
|
|
1972
|
+
"booking": "tables",
|
|
1973
|
+
"sells": "none"
|
|
1955
1974
|
},
|
|
1956
1975
|
{
|
|
1957
1976
|
"id": "cafe-bakery",
|
|
@@ -2055,7 +2074,8 @@ export const SPEC_BUSINESS_TYPES = [
|
|
|
2055
2074
|
"structure": "place",
|
|
2056
2075
|
"slice": true,
|
|
2057
2076
|
"stock": true,
|
|
2058
|
-
"booking": "none"
|
|
2077
|
+
"booking": "none",
|
|
2078
|
+
"sells": "offered"
|
|
2059
2079
|
},
|
|
2060
2080
|
{
|
|
2061
2081
|
"id": "bar-winery",
|
|
@@ -2160,7 +2180,8 @@ export const SPEC_BUSINESS_TYPES = [
|
|
|
2160
2180
|
"structure": "place",
|
|
2161
2181
|
"slice": false,
|
|
2162
2182
|
"stock": true,
|
|
2163
|
-
"booking": "none"
|
|
2183
|
+
"booking": "none",
|
|
2184
|
+
"sells": "offered"
|
|
2164
2185
|
},
|
|
2165
2186
|
{
|
|
2166
2187
|
"id": "boutique",
|
|
@@ -2227,8 +2248,7 @@ export const SPEC_BUSINESS_TYPES = [
|
|
|
2227
2248
|
"contact"
|
|
2228
2249
|
],
|
|
2229
2250
|
"needs": [
|
|
2230
|
-
"
|
|
2231
|
-
"detail",
|
|
2251
|
+
"products",
|
|
2232
2252
|
"about",
|
|
2233
2253
|
"contact"
|
|
2234
2254
|
],
|
|
@@ -2257,7 +2277,8 @@ export const SPEC_BUSINESS_TYPES = [
|
|
|
2257
2277
|
"structure": "studio",
|
|
2258
2278
|
"slice": false,
|
|
2259
2279
|
"stock": true,
|
|
2260
|
-
"booking": "none"
|
|
2280
|
+
"booking": "none",
|
|
2281
|
+
"sells": "inferred"
|
|
2261
2282
|
},
|
|
2262
2283
|
{
|
|
2263
2284
|
"id": "florist",
|
|
@@ -2323,7 +2344,7 @@ export const SPEC_BUSINESS_TYPES = [
|
|
|
2323
2344
|
"contact"
|
|
2324
2345
|
],
|
|
2325
2346
|
"needs": [
|
|
2326
|
-
"
|
|
2347
|
+
"products",
|
|
2327
2348
|
"about",
|
|
2328
2349
|
"contact"
|
|
2329
2350
|
],
|
|
@@ -2355,7 +2376,8 @@ export const SPEC_BUSINESS_TYPES = [
|
|
|
2355
2376
|
"structure": "studio",
|
|
2356
2377
|
"slice": false,
|
|
2357
2378
|
"stock": true,
|
|
2358
|
-
"booking": "none"
|
|
2379
|
+
"booking": "none",
|
|
2380
|
+
"sells": "inferred"
|
|
2359
2381
|
},
|
|
2360
2382
|
{
|
|
2361
2383
|
"id": "home-goods",
|
|
@@ -2420,8 +2442,7 @@ export const SPEC_BUSINESS_TYPES = [
|
|
|
2420
2442
|
"contact"
|
|
2421
2443
|
],
|
|
2422
2444
|
"needs": [
|
|
2423
|
-
"
|
|
2424
|
-
"detail",
|
|
2445
|
+
"products",
|
|
2425
2446
|
"about",
|
|
2426
2447
|
"contact"
|
|
2427
2448
|
],
|
|
@@ -2453,7 +2474,8 @@ export const SPEC_BUSINESS_TYPES = [
|
|
|
2453
2474
|
"structure": "studio",
|
|
2454
2475
|
"slice": false,
|
|
2455
2476
|
"stock": true,
|
|
2456
|
-
"booking": "none"
|
|
2477
|
+
"booking": "none",
|
|
2478
|
+
"sells": "inferred"
|
|
2457
2479
|
},
|
|
2458
2480
|
{
|
|
2459
2481
|
"id": "consultant",
|
|
@@ -2554,7 +2576,8 @@ export const SPEC_BUSINESS_TYPES = [
|
|
|
2554
2576
|
"structure": "practice",
|
|
2555
2577
|
"slice": true,
|
|
2556
2578
|
"stock": true,
|
|
2557
|
-
"booking": "sometimes"
|
|
2579
|
+
"booking": "sometimes",
|
|
2580
|
+
"sells": "none"
|
|
2558
2581
|
},
|
|
2559
2582
|
{
|
|
2560
2583
|
"id": "coach",
|
|
@@ -2648,7 +2671,8 @@ export const SPEC_BUSINESS_TYPES = [
|
|
|
2648
2671
|
"structure": "practice",
|
|
2649
2672
|
"slice": false,
|
|
2650
2673
|
"stock": true,
|
|
2651
|
-
"booking": "must"
|
|
2674
|
+
"booking": "must",
|
|
2675
|
+
"sells": "none"
|
|
2652
2676
|
},
|
|
2653
2677
|
{
|
|
2654
2678
|
"id": "law-accounting",
|
|
@@ -2762,7 +2786,8 @@ export const SPEC_BUSINESS_TYPES = [
|
|
|
2762
2786
|
"structure": "practice",
|
|
2763
2787
|
"slice": false,
|
|
2764
2788
|
"stock": true,
|
|
2765
|
-
"booking": "sometimes"
|
|
2789
|
+
"booking": "sometimes",
|
|
2790
|
+
"sells": "never"
|
|
2766
2791
|
},
|
|
2767
2792
|
{
|
|
2768
2793
|
"id": "real-estate",
|
|
@@ -2866,7 +2891,8 @@ export const SPEC_BUSINESS_TYPES = [
|
|
|
2866
2891
|
"structure": "studio",
|
|
2867
2892
|
"slice": false,
|
|
2868
2893
|
"stock": false,
|
|
2869
|
-
"booking": "sometimes"
|
|
2894
|
+
"booking": "sometimes",
|
|
2895
|
+
"sells": "none"
|
|
2870
2896
|
},
|
|
2871
2897
|
{
|
|
2872
2898
|
"id": "nonprofit",
|
|
@@ -2959,7 +2985,8 @@ export const SPEC_BUSINESS_TYPES = [
|
|
|
2959
2985
|
"structure": "practice",
|
|
2960
2986
|
"slice": false,
|
|
2961
2987
|
"stock": true,
|
|
2962
|
-
"booking": "none"
|
|
2988
|
+
"booking": "none",
|
|
2989
|
+
"sells": "none"
|
|
2963
2990
|
},
|
|
2964
2991
|
{
|
|
2965
2992
|
"id": "venue-events",
|
|
@@ -3064,7 +3091,8 @@ export const SPEC_BUSINESS_TYPES = [
|
|
|
3064
3091
|
"structure": "place",
|
|
3065
3092
|
"slice": false,
|
|
3066
3093
|
"stock": true,
|
|
3067
|
-
"booking": "tables"
|
|
3094
|
+
"booking": "tables",
|
|
3095
|
+
"sells": "none"
|
|
3068
3096
|
},
|
|
3069
3097
|
{
|
|
3070
3098
|
"id": "hotel-bnb",
|
|
@@ -3169,7 +3197,8 @@ export const SPEC_BUSINESS_TYPES = [
|
|
|
3169
3197
|
"structure": "place",
|
|
3170
3198
|
"slice": false,
|
|
3171
3199
|
"stock": true,
|
|
3172
|
-
"booking": "tables"
|
|
3200
|
+
"booking": "tables",
|
|
3201
|
+
"sells": "none"
|
|
3173
3202
|
},
|
|
3174
3203
|
{
|
|
3175
3204
|
"id": "classes",
|
|
@@ -3276,7 +3305,8 @@ export const SPEC_BUSINESS_TYPES = [
|
|
|
3276
3305
|
"structure": "practice",
|
|
3277
3306
|
"slice": false,
|
|
3278
3307
|
"stock": true,
|
|
3279
|
-
"booking": "must"
|
|
3308
|
+
"booking": "must",
|
|
3309
|
+
"sells": "offered"
|
|
3280
3310
|
}
|
|
3281
3311
|
] as const;
|
|
3282
3312
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { BookingNeed, BUSINESS_TYPES, BusinessType, NeedId } from './business-types';
|
|
1
|
+
import { BookingNeed, BUSINESS_TYPES, BusinessType, NeedId, SellingNeed } from './business-types';
|
|
2
2
|
|
|
3
3
|
/** Who asked for a need: the owner named it, or the kind of business needs it ("we added"). */
|
|
4
4
|
export enum NeedSource {
|
|
@@ -40,3 +40,32 @@ export function inferNeeds(
|
|
|
40
40
|
}
|
|
41
41
|
return out;
|
|
42
42
|
}
|
|
43
|
+
|
|
44
|
+
/** The need a business that sells names (generation-core `SHOP_NEED`): its site is a whole store. */
|
|
45
|
+
export const PRODUCTS_NEED: NeedId = 'products';
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Commerce C-D21 (R-H1): whether a reading's business sells — settled by its kind, never left to a model's guess. A kind
|
|
49
|
+
* that sells (`inferred`) has `products` (from: type, unless the owner named it); a kind that never sells (care, trust)
|
|
50
|
+
* has none, whatever was said; the rest keep what the reading said — on Analysis, an `offered` kind shows `products`
|
|
51
|
+
* switched off (`offeredNeeds`). Pure; the same list when nothing changes.
|
|
52
|
+
*/
|
|
53
|
+
export function withSellingNeed(typeId: string | null | undefined, needs: ReadonlyArray<SiteNeed>, types: ReadonlyArray<BusinessType> = BUSINESS_TYPES): SiteNeed[] {
|
|
54
|
+
const sells = types.find(t => t.id === typeId)?.sells;
|
|
55
|
+
const has = needs.some(n => n.id === PRODUCTS_NEED);
|
|
56
|
+
if (sells === SellingNeed.Never && has) return needs.filter(n => n.id !== PRODUCTS_NEED);
|
|
57
|
+
if (sells === SellingNeed.Inferred && !has) return [...needs, { id: PRODUCTS_NEED, from: NeedSource.Type }];
|
|
58
|
+
return [...needs];
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/** The needs Analysis offers switched off for this kind of business (a café's beans): `products` for an `offered` one
|
|
62
|
+
* whose reading lacks it. */
|
|
63
|
+
export function offeredNeeds(typeId: string | null | undefined, needs: ReadonlyArray<Pick<SiteNeed, 'id'>>, types: ReadonlyArray<BusinessType> = BUSINESS_TYPES): NeedId[] {
|
|
64
|
+
const sells = types.find(t => t.id === typeId)?.sells;
|
|
65
|
+
return sells === SellingNeed.Offered && !needs.some(n => n.id === PRODUCTS_NEED) ? [PRODUCTS_NEED] : [];
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/** True when the needs say the business sells (the plan must name what — generation-core `validateSitePlan`'s `sells`). */
|
|
69
|
+
export function needsSell(needs: ReadonlyArray<Pick<SiteNeed, 'id'>>): boolean {
|
|
70
|
+
return needs.some(n => n.id === PRODUCTS_NEED);
|
|
71
|
+
}
|