@websolutespa/bom-core 4.0.0-next.0 → 4.0.0-next.1

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,14 @@
1
1
  # @websolutespa/bom-core
2
2
 
3
+ ## 4.0.0-next.1
4
+
5
+ ### Patch Changes
6
+
7
+ - `getMetaRobots` reads `meta.robots` or `meta.robot` (the `@payloadcms/plugin-seo` field); `IMeta.robot` is added and route `noindex` uses it.
8
+ - `ILayout.homeHref` is added.
9
+ - `ROOT_CATEGORY` is read when `getRootCategory` is called instead of once at module load.
10
+ - `httpFetch` logs 4xx responses in development only; server errors and network errors are always logged.
11
+
3
12
  ## 4.0.0-next.0
4
13
 
5
14
  ### Major Changes
package/dist/index.d.ts CHANGED
@@ -267,6 +267,8 @@ type IMeta = {
267
267
  description?: string;
268
268
  keywords?: string;
269
269
  robots?: string;
270
+ /** Robots directive as stored by `@payloadcms/plugin-seo` setups. Read through `getMetaRobots`. */
271
+ robot?: string;
270
272
  image?: IMedia;
271
273
  };
272
274
 
@@ -453,9 +455,17 @@ type ILayout<T extends IAppExtended = IAppExtended> = {
453
455
  markets: IMarket[];
454
456
  app: IPrettify<IApp<T>>;
455
457
  menu: Record<string, ILocalizedMenu>;
458
+ /**
459
+ * Root and first-level hrefs keyed by route schema (template or collection
460
+ * slug), so renaming a collection changes the key. Use `homeHref` for the
461
+ * home page.
462
+ */
456
463
  topLevelHrefs: Record<string, string>;
464
+ /** Root and first-level routes, keyed like `topLevelHrefs`. */
457
465
  topLevelRoutes: Record<string, IRouteLink>;
458
466
  tree?: IRouteLink;
467
+ /** Href of the root page for the current market and locale (`tree.href`). */
468
+ homeHref?: string;
459
469
  };
460
470
 
461
471
  /**
@@ -757,7 +767,10 @@ type ITemplate = {
757
767
  };
758
768
 
759
769
  /**
760
- * Retrieves the root category from the given list of categories.
770
+ * Retrieves the root category from the given list of categories: the one with
771
+ * id `ROOT_CATEGORY` when set and present, otherwise the first category
772
+ * without a parent. The root and hidden categories (`isHidden`) do not add a
773
+ * segment to page URLs.
761
774
  * @param categories - The list of categories.
762
775
  * @returns The root category, if found; otherwise undefined.
763
776
  */
@@ -1050,6 +1063,13 @@ declare class Logger {
1050
1063
 
1051
1064
  declare const defaultMarket: string;
1052
1065
 
1066
+ /**
1067
+ * Returns the robots directive of a page's meta. Bowl's SEO rules write
1068
+ * `meta.robots`, while `@payloadcms/plugin-seo` setups store the editor value
1069
+ * in `meta.robot`; `robots` wins when both are set.
1070
+ */
1071
+ declare function getMetaRobots(meta?: Pick<IMeta, 'robots' | 'robot'> | null): string | undefined;
1072
+
1053
1073
  /**
1054
1074
  * STORE
1055
1075
  */
@@ -1580,4 +1600,4 @@ declare function asServerProps(props: any): any;
1580
1600
  declare function awaitAll(array: any, callback: (item: any, index: number) => Promise<any>): Promise<any[]>;
1581
1601
  declare function merge(target: any, source: any): any;
1582
1602
 
1583
- export { type DeepPartial, type DeepRequired, type DeepRequiredProps, type Dynamic, type FetchError, type FetchRequestOptions, type FetchService, type FindParams, type FindWhereParams, type GlobalQueryParams, type Headings, type IAction, type IActionEmailData, type IAnchor, type IApp, type IAppExtended, type ICategorized, type ICategory, type ICategoryItem, type IClassName, type IClassNameCollection, type IClassNameValue, type ICollectionDescription, type IComponent, type IConfig, type IConsentPreference, type IContextBaseParams, type IContextParams, type IDecoratedNav, type IEmailConfig, type IEndUser, type IEntity, type IEquatable, type IFeature, type IFeatureType, type IImageResize, type ILabel, type ILayout, type ILegalNotice, type ILetter, type ILocale, type ILocaleId, type ILocalizable, type ILocalized, type ILocalizedMenu, type ILocalizedString, type IMarket, type IMedia, type IMediaImage, type IMediaInfo, type IMediaJson, type IMediaPdf, type IMediaType, type IMediaVideo, type IMemoryStore, type IMenu, type IMenuBase, type IMenuCategory, type IMenuCustom, type IMenuGroup, type IMenuHref, type IMenuItem, type IMenuLink, type IMenuPage, type IMenuRoute, type IMockCategory, type IMockCollection, type IMockComponent, type IMockLabel, type IMockLocale, type IMockManyRelation, type IMockMarket, type IMockMedia, type IMockMenu, type IMockMenuBase, type IMockMenuCategory, type IMockMenuCustom, type IMockMenuExtra, type IMockMenuGroup, type IMockMenuItem, type IMockMenuLink, type IMockMenuPage, type IMockMeta, type IMockPage, type IMockRedirect, type IMockRelation, type IMockSingleRelation, type IMockStore, type IMockTemplate, type INamedEntity, type IOption, type IOverride, type IOverrideReturnValue, type IOverrideValue, type IPackages, type IPage, type IPageItem, type IPageRelation, type IPageRelationResult, type IPageUnresolvedRelation, type IPagedResult, type IPaginationResult, type IPartial, type IPreference, type IPrettify, type IQuerable, type IRedirect, type IRoute, type IRouteCanonical, type IRouteLink, type IRouteParams, type ISchema, type ISerializedCollection, type ISerializedStore, type IServerSideContext, type IServerSideSplatContext, type IStaticContext, type IStore, type ITemplate, type ITitledEntity, type IUndecoratedMenu, type IUndecoratedMenuBase, type IUndecoratedMenuCategory, type IUndecoratedMenuCustom, type IUndecoratedMenuGroup, type IUndecoratedMenuItem, type IUndecoratedMenuLink, type IUndecoratedMenuPage, type IUndecoratedNav, ImageStrategy, type Json, JsonService, type LiteralUnion, Logger, LoggerLevel, MenuCategoryStrategy, type NextApiRequestCookies, type Operator, type PageProps, type Pagination, type PreviewData, type Primitive, type QueryParams, RedirectReason, type RequireAtLeastOne, RouteStrategy, type SchemaType, type ServerSidePropsContext, type Shift, type ShiftUnion, type StaticPropsContext, type User, type UserRole, type UserWithRoles, type ValueOf, type Where, type WhereAndOr, type WhereBase, type WhereField, arrayShuffle, asCategoryId, asEntityId, asEquatable, asEquatableNumber, asEquatableString, asServerProps, asSortedOptions, awaitAll, base64ToString, camelToSnakeCase, cloneItem, collectFeatureTypes, collectFeatureTypes__, collectOptions, collectRoutes, consoleWarn, decryptImageResize, deepMerge, defaultLocale, defaultMarket, eachCategorized, eachMarketLocale, eachMedia, eachValue, encryptImageToken, enumToList, excludeComponent, findCategoryInCategories, findChildCategories, findRouteOfCategory, findRoutesOfCategory, getCategorySegments, getCategorySegmentsByCategory, getClassNames, getCollectionDescription, getEnv, getHost, getIsDevelopment, getIsProduction, getOrigin, getParentCategoriesById, getParentCategory, getProto, getRootCategory, getRouteHref, groupComponents, hasComponents, hasMarket, httpDelete, httpFetch, httpGet, httpPatch, httpPost, httpPut, isArray, isBrowser, isComponent, isComponentOfType, isDevelopment, isEntity, isEquatable, isHeaders, isIncomingHttpHeaders, isLocalizedString, isMedia, isMediaImage, isMediaJson, isMediaPdf, isMediaVideo, isMenuCategory, isMenuGroup, isMenuHref, isMenuLink, isMenuPage, isMenuRoute, isNonEmptyArray, isNotNullString, isNumber, isObject, isProduction, isPromise, isRelation, isReservedCollectionDescription, isStage, isString, isUndecoratedCategory, isUndecoratedMenuCategory, isUndecoratedMenuItem, isUndecoratedMenuPage, isUndecoratedNav, isUnresolvedCategory, isUnresolvedRelation, isValidCollectionDescription, isValidString, localize, localizeItem, localizeValue, localizedToString, merge, pascalCaseToCamelCase, pascalCaseToCharCase, pascalCaseToKebabCase, pascalCaseToSnakeCase, passwordStrategy, pickComponent, pickHero, prependHero, qsDeserialize, qsDeserializeRaw, qsSerialize, qsSerializeRaw, resolveMediaType, stringToBase64, toCamelCase, toCharCase, toDisplayName, toFindParams, toKebabCase, toPascalCase, toPluralName, toSnakeCase, toTitleCase, toValidCollectionName, unknownCaseToPascalCase, uuidv4, withSchema };
1603
+ export { type DeepPartial, type DeepRequired, type DeepRequiredProps, type Dynamic, type FetchError, type FetchRequestOptions, type FetchService, type FindParams, type FindWhereParams, type GlobalQueryParams, type Headings, type IAction, type IActionEmailData, type IAnchor, type IApp, type IAppExtended, type ICategorized, type ICategory, type ICategoryItem, type IClassName, type IClassNameCollection, type IClassNameValue, type ICollectionDescription, type IComponent, type IConfig, type IConsentPreference, type IContextBaseParams, type IContextParams, type IDecoratedNav, type IEmailConfig, type IEndUser, type IEntity, type IEquatable, type IFeature, type IFeatureType, type IImageResize, type ILabel, type ILayout, type ILegalNotice, type ILetter, type ILocale, type ILocaleId, type ILocalizable, type ILocalized, type ILocalizedMenu, type ILocalizedString, type IMarket, type IMedia, type IMediaImage, type IMediaInfo, type IMediaJson, type IMediaPdf, type IMediaType, type IMediaVideo, type IMemoryStore, type IMenu, type IMenuBase, type IMenuCategory, type IMenuCustom, type IMenuGroup, type IMenuHref, type IMenuItem, type IMenuLink, type IMenuPage, type IMenuRoute, type IMockCategory, type IMockCollection, type IMockComponent, type IMockLabel, type IMockLocale, type IMockManyRelation, type IMockMarket, type IMockMedia, type IMockMenu, type IMockMenuBase, type IMockMenuCategory, type IMockMenuCustom, type IMockMenuExtra, type IMockMenuGroup, type IMockMenuItem, type IMockMenuLink, type IMockMenuPage, type IMockMeta, type IMockPage, type IMockRedirect, type IMockRelation, type IMockSingleRelation, type IMockStore, type IMockTemplate, type INamedEntity, type IOption, type IOverride, type IOverrideReturnValue, type IOverrideValue, type IPackages, type IPage, type IPageItem, type IPageRelation, type IPageRelationResult, type IPageUnresolvedRelation, type IPagedResult, type IPaginationResult, type IPartial, type IPreference, type IPrettify, type IQuerable, type IRedirect, type IRoute, type IRouteCanonical, type IRouteLink, type IRouteParams, type ISchema, type ISerializedCollection, type ISerializedStore, type IServerSideContext, type IServerSideSplatContext, type IStaticContext, type IStore, type ITemplate, type ITitledEntity, type IUndecoratedMenu, type IUndecoratedMenuBase, type IUndecoratedMenuCategory, type IUndecoratedMenuCustom, type IUndecoratedMenuGroup, type IUndecoratedMenuItem, type IUndecoratedMenuLink, type IUndecoratedMenuPage, type IUndecoratedNav, ImageStrategy, type Json, JsonService, type LiteralUnion, Logger, LoggerLevel, MenuCategoryStrategy, type NextApiRequestCookies, type Operator, type PageProps, type Pagination, type PreviewData, type Primitive, type QueryParams, RedirectReason, type RequireAtLeastOne, RouteStrategy, type SchemaType, type ServerSidePropsContext, type Shift, type ShiftUnion, type StaticPropsContext, type User, type UserRole, type UserWithRoles, type ValueOf, type Where, type WhereAndOr, type WhereBase, type WhereField, arrayShuffle, asCategoryId, asEntityId, asEquatable, asEquatableNumber, asEquatableString, asServerProps, asSortedOptions, awaitAll, base64ToString, camelToSnakeCase, cloneItem, collectFeatureTypes, collectFeatureTypes__, collectOptions, collectRoutes, consoleWarn, decryptImageResize, deepMerge, defaultLocale, defaultMarket, eachCategorized, eachMarketLocale, eachMedia, eachValue, encryptImageToken, enumToList, excludeComponent, findCategoryInCategories, findChildCategories, findRouteOfCategory, findRoutesOfCategory, getCategorySegments, getCategorySegmentsByCategory, getClassNames, getCollectionDescription, getEnv, getHost, getIsDevelopment, getIsProduction, getMetaRobots, getOrigin, getParentCategoriesById, getParentCategory, getProto, getRootCategory, getRouteHref, groupComponents, hasComponents, hasMarket, httpDelete, httpFetch, httpGet, httpPatch, httpPost, httpPut, isArray, isBrowser, isComponent, isComponentOfType, isDevelopment, isEntity, isEquatable, isHeaders, isIncomingHttpHeaders, isLocalizedString, isMedia, isMediaImage, isMediaJson, isMediaPdf, isMediaVideo, isMenuCategory, isMenuGroup, isMenuHref, isMenuLink, isMenuPage, isMenuRoute, isNonEmptyArray, isNotNullString, isNumber, isObject, isProduction, isPromise, isRelation, isReservedCollectionDescription, isStage, isString, isUndecoratedCategory, isUndecoratedMenuCategory, isUndecoratedMenuItem, isUndecoratedMenuPage, isUndecoratedNav, isUnresolvedCategory, isUnresolvedRelation, isValidCollectionDescription, isValidString, localize, localizeItem, localizeValue, localizedToString, merge, pascalCaseToCamelCase, pascalCaseToCharCase, pascalCaseToKebabCase, pascalCaseToSnakeCase, passwordStrategy, pickComponent, pickHero, prependHero, qsDeserialize, qsDeserializeRaw, qsSerialize, qsSerializeRaw, resolveMediaType, stringToBase64, toCamelCase, toCharCase, toDisplayName, toFindParams, toKebabCase, toPascalCase, toPluralName, toSnakeCase, toTitleCase, toValidCollectionName, unknownCaseToPascalCase, uuidv4, withSchema };
package/dist/index.js CHANGED
@@ -556,9 +556,12 @@ function stringToBase64(text) {
556
556
  }
557
557
 
558
558
  // src/category/category.ts
559
- var ROOT_CATEGORY = process.env.ROOT_CATEGORY || "";
559
+ function getRootCategoryId() {
560
+ return (typeof process !== "undefined" ? process.env?.ROOT_CATEGORY : void 0) || "";
561
+ }
560
562
  function getRootCategory(categories) {
561
- const rootCategory = ROOT_CATEGORY && categories.find((x) => x.id == ROOT_CATEGORY);
563
+ const rootCategoryId = getRootCategoryId();
564
+ const rootCategory = rootCategoryId && categories.find((x) => x.id == rootCategoryId);
562
565
  if (rootCategory) {
563
566
  return rootCategory;
564
567
  } else {
@@ -756,9 +759,11 @@ async function httpFetch(url, options = {}, serviceOptions) {
756
759
  return response;
757
760
  } catch (error) {
758
761
  if (typeof error === "object" && error.status) {
759
- console.log("httpFetch.error", options.method, url, error.status, error.statusText);
762
+ if (error.status >= 500 || isDevelopment) {
763
+ console.warn("httpFetch.error", options.method, url, error.status, error.statusText);
764
+ }
760
765
  } else {
761
- console.log("httpFetch.error", options.method, url, error);
766
+ console.warn("httpFetch.error", options.method, url, error);
762
767
  }
763
768
  throw error;
764
769
  }
@@ -1374,6 +1379,11 @@ function getDefaultMarket() {
1374
1379
  }
1375
1380
  var defaultMarket = getDefaultMarket();
1376
1381
 
1382
+ // src/meta/meta.ts
1383
+ function getMetaRobots(meta) {
1384
+ return meta?.robots || meta?.robot || void 0;
1385
+ }
1386
+
1377
1387
  // src/password/password.ts
1378
1388
  function getPasswordStrategy() {
1379
1389
  const passwordStrategy2 = typeof process !== "undefined" && process.env.NEXT_PUBLIC_PASSWORD_STRATEGY ? process.env.NEXT_PUBLIC_PASSWORD_STRATEGY : "^(?=.*[0-9])(?=.*[A-Z])(?=.*[a-z])[a-zA-Z0-9._\\-\\W]{8,}$";
@@ -1628,7 +1638,7 @@ function collectRoutes(store, categories, markets, locales, medias) {
1628
1638
  if (isRootCategory) {
1629
1639
  route.isRoot = true;
1630
1640
  }
1631
- const noindex = (item.meta?.robots || "").includes("noindex");
1641
+ const noindex = (getMetaRobots(item.meta) || "").includes("noindex");
1632
1642
  if (noindex) {
1633
1643
  route.noindex = true;
1634
1644
  }
@@ -1795,6 +1805,7 @@ export {
1795
1805
  getHost,
1796
1806
  getIsDevelopment,
1797
1807
  getIsProduction,
1808
+ getMetaRobots,
1798
1809
  getOrigin,
1799
1810
  getParentCategoriesById,
1800
1811
  getParentCategory,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@websolutespa/bom-core",
3
- "version": "4.0.0-next.0",
3
+ "version": "4.0.0-next.1",
4
4
  "description": "Core module of the BOM Repository",
5
5
  "keywords": [
6
6
  "bom",