@websolutespa/bom-core 3.0.3 → 4.0.0-next.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/CHANGELOG.md CHANGED
@@ -1,5 +1,23 @@
1
1
  # @websolutespa/bom-core
2
2
 
3
+ ## 4.0.0-next.0
4
+
5
+ ### Major Changes
6
+
7
+ - Next: support of the bom-next app package
8
+
9
+ ## 3.0.5
10
+
11
+ ### Patch Changes
12
+
13
+ - added: IRoute isProtected
14
+
15
+ ## 3.0.4
16
+
17
+ ### Patch Changes
18
+
19
+ - Fixing: qsDeserializeKeys
20
+
3
21
  ## 3.0.3
4
22
 
5
23
  ### Patch Changes
package/dist/index.d.ts CHANGED
@@ -270,92 +270,6 @@ type IMeta = {
270
270
  image?: IMedia;
271
271
  };
272
272
 
273
- type ICategory = IEntity & {
274
- category?: IEquatable | ICategory;
275
- id: IEquatable;
276
- media?: IMedia;
277
- order?: number;
278
- slug: ILocalizable;
279
- title: ILocalizable;
280
- isHidden?: boolean;
281
- };
282
- type ICategoryItem = ICategory & {
283
- items: ICategory[];
284
- };
285
- type ICategorized = IEntity & {
286
- title: ILocalizable;
287
- abstract?: string;
288
- description?: string;
289
- media?: IMedia;
290
- meta?: IMeta;
291
- components?: IComponent[];
292
- category: IEquatable | ICategory;
293
- slug: ILocalizable;
294
- template?: string;
295
- isDefault?: boolean;
296
- useSplat?: boolean;
297
- order?: number;
298
- markets?: string[];
299
- createdAt?: Date;
300
- updatedAt?: Date;
301
- _status?: string;
302
- };
303
-
304
- type IClassNameValue = string | boolean | number | null | undefined;
305
- type IClassNameCollection = Record<string, IClassNameValue>;
306
- type IClassName = IClassNameCollection | IClassNameValue;
307
-
308
- type IEmailConfig = IEntity & {
309
- id: string;
310
- subject: string;
311
- fromAddress: string;
312
- to: [{
313
- address: string;
314
- }];
315
- cc: [{
316
- address: string;
317
- }];
318
- bcc: [{
319
- address: string;
320
- }];
321
- };
322
-
323
- type FetchRequestOptions = {
324
- method?: string;
325
- headers?: {
326
- [key: string]: string;
327
- };
328
- body?: Blob | BufferSource | FormData | URLSearchParams | string | ReadableStream;
329
- mode?: 'cors' | 'no-cors' | 'same-origin';
330
- credentials?: 'omit' | 'same-origin' | 'include';
331
- cache?: 'default' | 'no-store' | 'reload' | 'no-cache' | 'force-cache' | 'only-if-cached';
332
- redirect?: 'follow' | 'error' | 'manual';
333
- referrer?: string;
334
- referrerPolicy?: 'no-referrer, no-referrer-when-downgrade, same-origin, origin, strict-origin, origin-when-cross-origin, strict-origin-when-cross-origin, or unsafe-url';
335
- integrity?: string;
336
- keepalive?: boolean;
337
- signal?: AbortSignal;
338
- };
339
- type FetchService<T = unknown> = (url: string, options?: FetchRequestOptions, serviceOptions?: any) => Promise<T>;
340
- type FetchError = any;
341
-
342
- declare enum ImageStrategy {
343
- None = "none",
344
- Next = "next",
345
- Mixer = "mixer",
346
- Oven = "oven",
347
- Token = "token",
348
- Custom = "custom"
349
- }
350
- type IImageResize = {
351
- q: number;
352
- w: number;
353
- h?: number;
354
- x?: number;
355
- y?: number;
356
- src: string;
357
- };
358
-
359
273
  type ILabel = IEntity & {
360
274
  id: IEquatable;
361
275
  text?: ILocalizable;
@@ -380,6 +294,113 @@ type IMarket = IEntity & {
380
294
  isHidden?: boolean;
381
295
  };
382
296
 
297
+ declare enum MenuCategoryStrategy {
298
+ Default = "default",// show hidden categories recursively,
299
+ ExcludeHidden = "exclude-hidden",
300
+ ExcludeRoute = "exclude-route",
301
+ ExcludeHiddenAndRoute = "exclude-hidden-and-route"
302
+ }
303
+ type IMenuBase = {
304
+ abstract?: ILocalizable;
305
+ extra?: ILocalizable;
306
+ customClass?: string;
307
+ id: IEquatable;
308
+ items?: IMenuItem[];
309
+ media?: IMedia;
310
+ title: ILocalizable;
311
+ };
312
+ type IMenuCategory = IMenuBase & {
313
+ type: 'category';
314
+ href: string;
315
+ category: IEquatable;
316
+ customTitle?: ILocalizable;
317
+ };
318
+ type IMenuGroup = IMenuBase & {
319
+ type: 'group';
320
+ };
321
+ type IMenuLink = IMenuBase & {
322
+ type: 'link';
323
+ href: string;
324
+ target: string;
325
+ };
326
+ type IMenuRoute = IMenuBase & {
327
+ type: 'route';
328
+ href: string;
329
+ page: IEquatable;
330
+ schema: string;
331
+ };
332
+ type IMenuPage = IMenuBase & {
333
+ type: 'page';
334
+ href: string;
335
+ page: IEquatable;
336
+ schema: string;
337
+ customTitle?: ILocalizable;
338
+ };
339
+ type IMenuCustom = Record<string, unknown> & {
340
+ id: IEquatable;
341
+ type: string;
342
+ };
343
+ type IMenuItem = IMenuCategory | IMenuGroup | IMenuLink | IMenuPage | IMenuRoute;
344
+ type IMenuHref = IMenuCategory | IMenuLink | IMenuPage | IMenuRoute;
345
+ declare function isMenuHref(item: IMenuItem): item is IMenuHref;
346
+ declare function isMenuCategory(item: IMenuItem): item is IMenuCategory;
347
+ declare function isMenuGroup(item: IMenuItem): item is IMenuGroup;
348
+ declare function isMenuLink(item: IMenuItem): item is IMenuLink;
349
+ declare function isMenuPage(item: IMenuItem): item is IMenuPage;
350
+ declare function isMenuRoute(item: IMenuItem): item is IMenuRoute;
351
+ type IMenu = {
352
+ id: string;
353
+ items: IMenuItem[];
354
+ };
355
+ type ILocalizedMenu = {
356
+ id: string;
357
+ items: ILocalized<IMenuItem>[];
358
+ };
359
+ /**
360
+ * this is the original menu model from cms
361
+ */
362
+ type IUndecoratedMenuBase = {
363
+ abstract?: ILocalizable;
364
+ extra?: ILocalizable;
365
+ customClass?: string;
366
+ id?: string;
367
+ items: IUndecoratedMenuItem[];
368
+ markets?: string[];
369
+ media?: IMedia;
370
+ type: string;
371
+ };
372
+ type IUndecoratedMenuCategory = Omit<IUndecoratedMenuBase, 'type'> & {
373
+ type: 'category';
374
+ category: string;
375
+ maxDepth?: number;
376
+ strategy?: MenuCategoryStrategy;
377
+ title?: ILocalizable;
378
+ };
379
+ type IUndecoratedMenuGroup = Omit<IUndecoratedMenuBase, 'type'> & {
380
+ type: 'group';
381
+ title: ILocalizable;
382
+ };
383
+ type IUndecoratedMenuLink = Omit<IUndecoratedMenuBase, 'type'> & {
384
+ type: 'link';
385
+ title: ILocalizable;
386
+ href: string;
387
+ target?: string;
388
+ };
389
+ type IUndecoratedMenuPage = Omit<IUndecoratedMenuBase, 'type'> & {
390
+ type: 'page';
391
+ page: IPageRelation;
392
+ title?: ILocalizable;
393
+ };
394
+ type IUndecoratedMenuCustom = Omit<IUndecoratedMenuBase, 'type'> & {
395
+ type: 'custom';
396
+ blockType: string;
397
+ };
398
+ type IUndecoratedMenuItem = IUndecoratedMenuCategory | IUndecoratedMenuGroup | IUndecoratedMenuLink | IUndecoratedMenuPage | IUndecoratedMenuCustom;
399
+ type IUndecoratedMenu = IEntity & {
400
+ id: string;
401
+ items: IUndecoratedMenuItem[];
402
+ };
403
+
383
404
  type IRoute = {
384
405
  category: IEquatable;
385
406
  id: string;
@@ -391,6 +412,7 @@ type IRoute = {
391
412
  title: string;
392
413
  _status?: 'published' | 'draft';
393
414
  isDefault?: boolean;
415
+ isProtected?: boolean;
394
416
  isRoot?: boolean;
395
417
  media?: {
396
418
  url: string;
@@ -400,6 +422,7 @@ type IRoute = {
400
422
  };
401
423
  noindex?: boolean;
402
424
  order?: number;
425
+ publicRedirect?: string;
403
426
  template?: string;
404
427
  updatedAt?: Date | string;
405
428
  useSplat?: boolean;
@@ -422,6 +445,19 @@ type IRouteParams = Record<string, any> & {
422
445
  market: string;
423
446
  };
424
447
 
448
+ type ILayout<T extends IAppExtended = IAppExtended> = {
449
+ labels: ILabel[];
450
+ locale: string;
451
+ locales: ILocale[];
452
+ market: string;
453
+ markets: IMarket[];
454
+ app: IPrettify<IApp<T>>;
455
+ menu: Record<string, ILocalizedMenu>;
456
+ topLevelHrefs: Record<string, string>;
457
+ topLevelRoutes: Record<string, IRouteLink>;
458
+ tree?: IRouteLink;
459
+ };
460
+
425
461
  /**
426
462
  * Represents a listing item returned from the findMany method of a page collection.
427
463
  * @template T - The type of the categorized item.
@@ -488,124 +524,92 @@ type IPageUnresolvedRelation = {
488
524
  value: IEquatable | IEquatable[];
489
525
  };
490
526
 
491
- declare enum MenuCategoryStrategy {
492
- Default = "default",// show hidden categories recursively,
493
- ExcludeHidden = "exclude-hidden",
494
- ExcludeRoute = "exclude-route",
495
- ExcludeHiddenAndRoute = "exclude-hidden-and-route"
496
- }
497
- type IMenuBase = {
498
- abstract?: ILocalizable;
499
- extra?: ILocalizable;
500
- customClass?: string;
527
+ type ICategory = IEntity & {
528
+ category?: IEquatable | ICategory;
501
529
  id: IEquatable;
502
- items?: IMenuItem[];
503
530
  media?: IMedia;
531
+ order?: number;
532
+ slug: ILocalizable;
504
533
  title: ILocalizable;
534
+ isHidden?: boolean;
505
535
  };
506
- type IMenuCategory = IMenuBase & {
507
- type: 'category';
508
- href: string;
509
- category: IEquatable;
510
- customTitle?: ILocalizable;
511
- };
512
- type IMenuGroup = IMenuBase & {
513
- type: 'group';
514
- };
515
- type IMenuLink = IMenuBase & {
516
- type: 'link';
517
- href: string;
518
- target: string;
519
- };
520
- type IMenuRoute = IMenuBase & {
521
- type: 'route';
522
- href: string;
523
- page: IEquatable;
524
- schema: string;
525
- };
526
- type IMenuPage = IMenuBase & {
527
- type: 'page';
528
- href: string;
529
- page: IEquatable;
530
- schema: string;
531
- customTitle?: ILocalizable;
532
- };
533
- type IMenuCustom = Record<string, unknown> & {
534
- id: IEquatable;
535
- type: string;
536
- };
537
- type IMenuItem = IMenuCategory | IMenuGroup | IMenuLink | IMenuPage | IMenuRoute;
538
- type IMenuHref = IMenuCategory | IMenuLink | IMenuPage | IMenuRoute;
539
- declare function isMenuHref(item: IMenuItem): item is IMenuHref;
540
- declare function isMenuCategory(item: IMenuItem): item is IMenuCategory;
541
- declare function isMenuGroup(item: IMenuItem): item is IMenuGroup;
542
- declare function isMenuLink(item: IMenuItem): item is IMenuLink;
543
- declare function isMenuPage(item: IMenuItem): item is IMenuPage;
544
- declare function isMenuRoute(item: IMenuItem): item is IMenuRoute;
545
- type IMenu = {
546
- id: string;
547
- items: IMenuItem[];
548
- };
549
- type ILocalizedMenu = {
550
- id: string;
551
- items: ILocalized<IMenuItem>[];
536
+ type ICategoryItem = ICategory & {
537
+ items: ICategory[];
552
538
  };
553
- /**
554
- * this is the original menu model from cms
555
- */
556
- type IUndecoratedMenuBase = {
557
- abstract?: ILocalizable;
558
- extra?: ILocalizable;
559
- customClass?: string;
560
- id?: string;
561
- items: IUndecoratedMenuItem[];
539
+ type ICategorized = IEntity & {
540
+ category: IEquatable | ICategory;
541
+ slug: ILocalizable;
542
+ title: ILocalizable;
543
+ _status?: string;
544
+ abstract?: string;
545
+ components?: IComponent[];
546
+ createdAt?: Date;
547
+ description?: string;
548
+ isDefault?: boolean;
549
+ isProtected?: boolean;
562
550
  markets?: string[];
563
551
  media?: IMedia;
564
- type: string;
565
- };
566
- type IUndecoratedMenuCategory = Omit<IUndecoratedMenuBase, 'type'> & {
567
- type: 'category';
568
- category: string;
569
- maxDepth?: number;
570
- strategy?: MenuCategoryStrategy;
571
- title?: ILocalizable;
572
- };
573
- type IUndecoratedMenuGroup = Omit<IUndecoratedMenuBase, 'type'> & {
574
- type: 'group';
575
- title: ILocalizable;
576
- };
577
- type IUndecoratedMenuLink = Omit<IUndecoratedMenuBase, 'type'> & {
578
- type: 'link';
579
- title: ILocalizable;
580
- href: string;
581
- target?: string;
582
- };
583
- type IUndecoratedMenuPage = Omit<IUndecoratedMenuBase, 'type'> & {
584
- type: 'page';
585
- page: IPageRelation;
586
- title?: ILocalizable;
587
- };
588
- type IUndecoratedMenuCustom = Omit<IUndecoratedMenuBase, 'type'> & {
589
- type: 'custom';
590
- blockType: string;
552
+ meta?: IMeta;
553
+ order?: number;
554
+ publicRedirect?: IEquatable | IEntity | IPageUnresolvedRelation;
555
+ template?: string;
556
+ updatedAt?: Date;
557
+ useSplat?: boolean;
591
558
  };
592
- type IUndecoratedMenuItem = IUndecoratedMenuCategory | IUndecoratedMenuGroup | IUndecoratedMenuLink | IUndecoratedMenuPage | IUndecoratedMenuCustom;
593
- type IUndecoratedMenu = IEntity & {
559
+
560
+ type IClassNameValue = string | boolean | number | null | undefined;
561
+ type IClassNameCollection = Record<string, IClassNameValue>;
562
+ type IClassName = IClassNameCollection | IClassNameValue;
563
+
564
+ type IEmailConfig = IEntity & {
594
565
  id: string;
595
- items: IUndecoratedMenuItem[];
566
+ subject: string;
567
+ fromAddress: string;
568
+ to: [{
569
+ address: string;
570
+ }];
571
+ cc: [{
572
+ address: string;
573
+ }];
574
+ bcc: [{
575
+ address: string;
576
+ }];
596
577
  };
597
578
 
598
- type ILayout<T extends IAppExtended = IAppExtended> = {
599
- labels: ILabel[];
600
- locale: string;
601
- locales: ILocale[];
602
- market: string;
603
- markets: IMarket[];
604
- app: IPrettify<IApp<T>>;
605
- menu: Record<string, ILocalizedMenu>;
606
- topLevelHrefs: Record<string, string>;
607
- topLevelRoutes: Record<string, IRouteLink>;
608
- tree?: IRouteLink;
579
+ type FetchRequestOptions = {
580
+ method?: string;
581
+ headers?: {
582
+ [key: string]: string;
583
+ };
584
+ body?: Blob | BufferSource | FormData | URLSearchParams | string | ReadableStream;
585
+ mode?: 'cors' | 'no-cors' | 'same-origin';
586
+ credentials?: 'omit' | 'same-origin' | 'include';
587
+ cache?: 'default' | 'no-store' | 'reload' | 'no-cache' | 'force-cache' | 'only-if-cached';
588
+ redirect?: 'follow' | 'error' | 'manual';
589
+ referrer?: string;
590
+ referrerPolicy?: 'no-referrer, no-referrer-when-downgrade, same-origin, origin, strict-origin, origin-when-cross-origin, strict-origin-when-cross-origin, or unsafe-url';
591
+ integrity?: string;
592
+ keepalive?: boolean;
593
+ signal?: AbortSignal;
594
+ };
595
+ type FetchService<T = unknown> = (url: string, options?: FetchRequestOptions, serviceOptions?: any) => Promise<T>;
596
+ type FetchError = any;
597
+
598
+ declare enum ImageStrategy {
599
+ None = "none",
600
+ Next = "next",
601
+ Mixer = "mixer",
602
+ Oven = "oven",
603
+ Token = "token",
604
+ Custom = "custom"
605
+ }
606
+ type IImageResize = {
607
+ q: number;
608
+ w: number;
609
+ h?: number;
610
+ x?: number;
611
+ y?: number;
612
+ src: string;
609
613
  };
610
614
 
611
615
  type IUndecoratedNav = IUndecoratedMenuPage;
package/dist/index.js CHANGED
@@ -1441,8 +1441,7 @@ function qsDeserializeKey(value) {
1441
1441
  return value;
1442
1442
  }
1443
1443
  function qsDeserializeKeys(key) {
1444
- const keys = key.replace(/[\]]/g, "").split("[").map((x) => qsDeserializeKey(x)).filter((x) => Boolean(x));
1445
- return keys;
1444
+ return key.replace(/[\]]/g, "").split("[").map((value) => qsDeserializeKey(value)).filter((value) => value !== "");
1446
1445
  }
1447
1446
  function getNextKeyItem(key) {
1448
1447
  if (typeof key === "number") {
@@ -1536,8 +1535,16 @@ var RouteStrategy = /* @__PURE__ */ ((RouteStrategy2) => {
1536
1535
  return RouteStrategy2;
1537
1536
  })(RouteStrategy || {});
1538
1537
  var ROUTE_STRATEGY = process.env.ROUTE_STRATEGY || "manual" /* Manual */;
1538
+ function getPublicRedirectId(value) {
1539
+ if (value && typeof value === "object" && "relationTo" in value && "value" in value) {
1540
+ const relationValue = value.value;
1541
+ return Array.isArray(relationValue) ? void 0 : asEntityId(relationValue);
1542
+ }
1543
+ return asEntityId(value);
1544
+ }
1539
1545
  function collectRoutes(store, categories, markets, locales, medias) {
1540
1546
  const routes = [];
1547
+ const redirects = /* @__PURE__ */ new Map();
1541
1548
  if (locales.length > 0 && markets.length > 0) {
1542
1549
  const rootCategory = getRootCategory(categories);
1543
1550
  const activeLocales = locales.filter((locale) => locale.isActive !== false);
@@ -1589,6 +1596,7 @@ function collectRoutes(store, categories, markets, locales, medias) {
1589
1596
  isDefault,
1590
1597
  media,
1591
1598
  order,
1599
+ isProtected,
1592
1600
  template,
1593
1601
  updatedAt,
1594
1602
  useSplat
@@ -1610,6 +1618,13 @@ function collectRoutes(store, categories, markets, locales, medias) {
1610
1618
  if (isDefault) {
1611
1619
  route.isDefault = true;
1612
1620
  }
1621
+ if (isProtected) {
1622
+ route.isProtected = true;
1623
+ const publicRedirect = getPublicRedirectId(item.publicRedirect);
1624
+ if (publicRedirect != null) {
1625
+ redirects.set(item.id, publicRedirect);
1626
+ }
1627
+ }
1613
1628
  if (isRootCategory) {
1614
1629
  route.isRoot = true;
1615
1630
  }
@@ -1635,6 +1650,19 @@ function collectRoutes(store, categories, markets, locales, medias) {
1635
1650
  });
1636
1651
  }
1637
1652
  });
1653
+ const routeByPageContext = /* @__PURE__ */ new Map();
1654
+ for (const route of routes) {
1655
+ routeByPageContext.set(JSON.stringify([route.page, route.market, route.locale]), route);
1656
+ }
1657
+ for (const route of routes) {
1658
+ const targetPage = redirects.get(route.page);
1659
+ if (targetPage != null) {
1660
+ const target = routeByPageContext.get(JSON.stringify([targetPage, route.market, route.locale]));
1661
+ if (target) {
1662
+ route.publicRedirect = target.id;
1663
+ }
1664
+ }
1665
+ }
1638
1666
  }
1639
1667
  return routes;
1640
1668
  }
@@ -1717,7 +1745,7 @@ function getRouteHref(segments, market, locale, markets, locales) {
1717
1745
  return `${prefix}${href}`;
1718
1746
  }
1719
1747
  function hasMarket(item, market) {
1720
- return !item.markets || item.markets.length === 0 || item.markets.includes(market.id);
1748
+ return !item.markets || item.markets.length === 0 || item.markets.map((x) => asEquatable(x)).includes(market.id);
1721
1749
  }
1722
1750
  export {
1723
1751
  ImageStrategy,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@websolutespa/bom-core",
3
- "version": "3.0.3",
3
+ "version": "4.0.0-next.0",
4
4
  "description": "Core module of the BOM Repository",
5
5
  "keywords": [
6
6
  "bom",
@@ -31,7 +31,7 @@
31
31
  "@types/pluralize": "0.0.33",
32
32
  "@types/react": "19.2.10",
33
33
  "@websolutespa/eslint-config": "^3.0.0",
34
- "@websolutespa/test": "^3.0.1",
34
+ "@websolutespa/test": "^4.0.0-next.0",
35
35
  "@websolutespa/tsconfig": "^3.0.0",
36
36
  "eslint": "9.31.0",
37
37
  "npm-run-all": "4.1.5",