@websolutespa/bom-core 0.6.6 → 1.7.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,17 @@
1
1
  # @websolutespa/bom-core
2
2
 
3
+ ## 1.7.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 28e86bd: Modified: IPage, Store services & decorators
8
+
9
+ ## 1.6.0
10
+
11
+ ### Patch Changes
12
+
13
+ - 6cbf4cb: Added: IAction, IEndUser, IConsentPreference, IPreference, ILegalNotice
14
+
3
15
  ## 0.6.6
4
16
 
5
17
  ### Patch Changes
package/dist/index.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import { IncomingMessage, ServerResponse } from 'http';
2
2
  import { ParsedUrlQuery } from 'querystring';
3
+ import React from 'react';
3
4
 
4
5
  type Json = string | number | boolean | null | Json[] | {
5
6
  [key: string]: Json;
@@ -51,19 +52,70 @@ type IPartial<T> = {
51
52
  type IPrettify<T> = {
52
53
  [K in keyof T]: T[K];
53
54
  } & {};
54
- type IOverride<T, TypeToReplace, TypeToReplaceWith> = {
55
- [K in keyof T]: T[K] extends Record<string, unknown> ? IOverride<T[K], TypeToReplace, TypeToReplaceWith> : T[K] extends TypeToReplace ? TypeToReplaceWith : T[K];
55
+ type IOverrideReturnValue<T, FromType, ToType> = T extends Record<string, unknown> ? IOverride<T, FromType, ToType> : T;
56
+ type IOverrideValue<T, FromType, ToType> = T extends FromType ? ToType : IOverrideReturnValue<T, FromType, ToType>;
57
+ type IOverride<T, FromType, ToType> = {
58
+ [Property in keyof T]: IOverrideValue<T[Property], FromType, ToType>;
56
59
  };
57
60
 
58
- type ILocalizedString = Record<string, string>;
61
+ /**
62
+ * List of ISO 639 language codes (set 1)
63
+ * https://en.wikipedia.org/wiki/List_of_ISO_639_language_codes
64
+ */
65
+ type ILetter = 'a' | 'b' | 'c' | 'd' | 'e' | 'f' | 'g' | 'h' | 'i' | 'j' | 'k' | 'l' | 'm' | 'n' | 'o' | 'p' | 'q' | 'r' | 's' | 't' | 'u' | 'v' | 'w' | 'x' | 'y' | 'z';
66
+ type ILocaleId = `${ILetter}${ILetter}`;
67
+ type ILocalizedString = Record<ILocaleId, string>;
59
68
  type ILocalizable = string | ILocalizedString;
60
69
  type ILocalized<T> = IOverride<T, ILocalizable, string>;
61
70
 
71
+ type ILegalNotice = {
72
+ id: string;
73
+ text: ILocalizable;
74
+ };
75
+ type IPreference = {
76
+ id: string;
77
+ description: string;
78
+ legalNotice: ILegalNotice;
79
+ };
80
+ type IConsentPreference = {
81
+ id: string;
82
+ consentPreference: IPreference;
83
+ date: Date | string;
84
+ };
85
+
86
+ type User = Record<string, unknown> & {
87
+ collection: string;
88
+ id: string;
89
+ email: string;
90
+ };
91
+ type UserRole = 'admin' | 'editor' | 'user' | string;
92
+ type UserWithRoles = User & {
93
+ roles: UserRole[];
94
+ };
95
+ type IEndUser = UserWithRoles & {
96
+ email: string;
97
+ consentPreferences: IConsentPreference[];
98
+ };
99
+
100
+ type IAction = Record<string, unknown> & {
101
+ id: string;
102
+ consentPreferences: IConsentPreference[];
103
+ endUser: IEndUser;
104
+ loggedEndUser?: IEndUser;
105
+ email?: string;
106
+ password?: string;
107
+ };
108
+
62
109
  type IAnchor = {
63
110
  id: string;
64
111
  title?: ILocalizable;
65
112
  };
66
113
 
114
+ type IComponent = {
115
+ schema: string;
116
+ [key: string]: unknown;
117
+ };
118
+
67
119
  type IEquatable = number | string;
68
120
  type SchemaType = string;
69
121
  type ISchema = {
@@ -108,6 +160,13 @@ type IMedia = {
108
160
  };
109
161
  declare function resolveMediaType(media: IMedia): IMediaType;
110
162
 
163
+ type IMeta = {
164
+ title?: string;
165
+ description?: string;
166
+ keywords?: string;
167
+ robots?: string;
168
+ };
169
+
111
170
  type ICategory = IEntity & {
112
171
  category?: IEquatable | ICategory;
113
172
  id: IEquatable;
@@ -119,19 +178,20 @@ type ICategory = IEntity & {
119
178
  type ICategoryItem = ICategory & {
120
179
  items: ICategory[];
121
180
  };
122
- type ICategorized = {
123
- abstract?: ILocalizable;
124
- category: IEquatable | ICategory;
125
- id: IEquatable;
126
- isDefault?: boolean;
127
- markets?: string[];
181
+ type ICategorized = IEntity & {
182
+ title: ILocalizable;
183
+ abstract?: string;
184
+ description?: string;
128
185
  media?: IMedia;
129
- order?: number;
130
- schema?: string;
186
+ meta?: IMeta;
187
+ components?: IComponent[];
188
+ category: IEquatable | ICategory;
131
189
  slug: ILocalizable;
132
190
  template?: string;
133
- title: ILocalizable;
191
+ isDefault?: boolean;
134
192
  useSplat?: boolean;
193
+ order?: number;
194
+ markets?: string[];
135
195
  createdAt?: Date;
136
196
  updatedAt?: Date;
137
197
  };
@@ -183,13 +243,6 @@ type IMarket = IEntity & {
183
243
  isHidden?: boolean;
184
244
  };
185
245
 
186
- type IMeta = {
187
- title?: string;
188
- description?: string;
189
- keywords?: string;
190
- robots?: string;
191
- };
192
-
193
246
  type IRoute = {
194
247
  category: IEquatable | ICategory;
195
248
  id: string;
@@ -223,20 +276,25 @@ type IRouteParams = Record<string, any> & {
223
276
  market: string;
224
277
  };
225
278
 
226
- type IPage = Record<string, any> & ICategorized & {
227
- abstract?: string;
279
+ type IPage<T extends ICategorized = ICategorized> = ILocalized<T> & {
228
280
  alternates: IRoute[];
229
281
  breadcrumb: IRouteLink[];
230
- content?: string;
231
- description?: string;
282
+ category: ILocalized<ICategory>;
232
283
  href: string;
233
284
  locale: string;
234
285
  market: string;
235
- meta?: IMeta;
236
286
  parentRoute?: IRouteLink;
237
287
  slug: string;
238
288
  title: string;
239
289
  };
290
+ type PageProps<T extends ICategorized = ICategorized> = {
291
+ layout: ILayout;
292
+ page: IPage<T>;
293
+ params: IRouteParams;
294
+ locales?: string[];
295
+ locale?: string;
296
+ defaultLocale?: string;
297
+ };
240
298
  type IPageRelationResult<T extends ICategorized = ICategorized> = {
241
299
  href: string;
242
300
  } & T;
@@ -248,15 +306,6 @@ type IPageUnresolvedRelation = {
248
306
  relationTo: string;
249
307
  value: IEquatable | IEquatable[];
250
308
  };
251
- type IPageResult<T extends ICategorized = ICategorized> = IPage & T;
252
- type PageProps<T extends ICategorized = ICategorized> = {
253
- layout: ILayout;
254
- page: IPageResult<T>;
255
- params: IRouteParams;
256
- locales?: string[];
257
- locale?: string;
258
- defaultLocale?: string;
259
- };
260
309
 
261
310
  type IMenuBase = {
262
311
  abstract?: ILocalizable;
@@ -297,6 +346,8 @@ type IMenuCustom = Record<string, unknown> & {
297
346
  type: string;
298
347
  };
299
348
  type IMenuItem = IMenuCategory | IMenuGroup | IMenuLink | IMenuPage | IMenuRoute;
349
+ type IMenuHref = IMenuCategory | IMenuLink | IMenuPage | IMenuRoute;
350
+ declare function isMenuHref(item: IMenuItem): item is IMenuHref;
300
351
  type IMenu = {
301
352
  id: string;
302
353
  items: IMenuItem[];
@@ -351,7 +402,7 @@ type ILayout = {
351
402
  locales: ILocale[];
352
403
  market: string;
353
404
  markets: IMarket[];
354
- menu: Record<string, IMenu>;
405
+ menu: Record<string, ILocalized<IMenu>>;
355
406
  topLevelHrefs: Record<string, string>;
356
407
  topLevelRoutes: Record<string, IRouteLink>;
357
408
  tree?: IRouteLink;
@@ -449,7 +500,7 @@ type IRedirect = {
449
500
  };
450
501
 
451
502
  type IMemoryStore<T extends IEntity = IEntity> = Record<string, T[]>;
452
- type IStore = Record<string, IQuerable<IEntity>>;
503
+ type IStore = Record<string, IQuerable>;
453
504
  type IConfig = {
454
505
  collections: string[];
455
506
  mocks: string[];
@@ -637,9 +688,9 @@ declare const isProduction: boolean;
637
688
  declare const isStage: boolean;
638
689
  declare const isBrowser: boolean;
639
690
  declare function getEnv(): Record<string, Json>;
640
- declare function withSchema<Component extends {}, Schema>(component: Component, schema: Schema): Component & Schema;
691
+ declare function withSchema<Component extends React.FC<any>, Schema>(component: Component, schema: Schema): Component & Schema;
641
692
  declare function asServerProps(props: any): any;
642
693
  declare function awaitAll(array: any, callback: (item: any, index: number) => Promise<any>): Promise<any[]>;
643
694
  declare function merge(target: any, source: any): any;
644
695
 
645
- export { FetchError, FetchRequestOptions, FetchService, FindParams, FindWhereParams, IAnchor, ICategorized, ICategory, ICategoryItem, IClassName, IClassNameCollection, IClassNameValue, ICollectionDescription, IConfig, IContextBaseParams, IContextParams, IDecoratedNav, IEntity, IEquatable, IFeature, IFeatureType, ILabel, ILayout, ILocale, ILocalizable, ILocalized, ILocalizedString, IMarket, IMedia, IMediaType, IMemoryStore, IMenu, IMenuBase, IMenuCategory, IMenuCustom, IMenuGroup, IMenuItem, IMenuLink, IMenuPage, IMenuRoute, INamedEntity, IOption, IOverride, IPackages, IPage, IPageRelation, IPageRelationResult, IPageResult, IPageUnresolvedRelation, IPagedResult, IPaginationResult, IPartial, IPrettify, IQuerable, IRedirect, IRoute, IRouteCanonical, IRouteLink, IRouteParams, ISchema, ISerializedCollection, ISerializedStore, IServerSideContext, IServerSideSplatContext, IStaticContext, IStore, ITemplate, ITitledEntity, IUndecoratedMenu, IUndecoratedMenuBase, IUndecoratedMenuCategory, IUndecoratedMenuCustom, IUndecoratedMenuGroup, IUndecoratedMenuItem, IUndecoratedMenuLink, IUndecoratedMenuPage, IUndecoratedNav, Json, JsonService, LiteralUnion, Logger, LoggerLevel, NextApiRequestCookies, Operator, PageProps, Pagination, PreviewData, QueryParams, RedirectReason, RouteStrategy, SchemaType, ServerSidePropsContext, StateValue, StaticPropsContext, ValueOf, Where, WhereAndOr, WhereBase, WhereField, asCategoryId, asEquatable, asServerProps, awaitAll, camelToSnakeCase, cloneItem, collectFeatureTypes, collectOptions, collectRoutes, consoleWarn, defaultLocale, defaultMarket, eachCategorized, eachMarketLocale, enumToList, getCategorySegments, getCategorySegmentsByCategory, getClassNames, getCollectionDescription, getEnv, getIsDevelopment, getIsProduction, getParentCategoriesById, getRootCategory, getRouteHref, httpDelete, httpFetch, httpGet, httpPatch, httpPost, httpPut, isArray, isBrowser, isCategory, isDevelopment, isEntity, isEquatable, isLocalizedString, isNotNullString, isObject, isProduction, isRelation, isReservedCollectionDescription, isStage, isUndecoratedMenuCategory, isUndecoratedMenuItem, isUndecoratedMenuPage, isUndecoratedNav, isUnresolvedRelation, isValidCollectionDescription, localize, localizeItem, localizeValue, localizedToString, merge, pascalCaseToCamelCase, pascalCaseToCharCase, pascalCaseToKebabCase, pascalCaseToSnakeCase, qsDeserialize, qsDeserializeRaw, qsSerialize, qsSerializeRaw, resolveMediaType, textToSlug, toCamelCase, toCharCase, toDisplayName, toFindParams, toKebabCase, toPascalCase, toPluralName, toSnakeCase, toTitleCase, toValidCollectionName, unknownCaseToPascalCase, withSchema };
696
+ export { FetchError, FetchRequestOptions, FetchService, FindParams, FindWhereParams, IAction, IAnchor, ICategorized, ICategory, ICategoryItem, IClassName, IClassNameCollection, IClassNameValue, ICollectionDescription, IComponent, IConfig, IConsentPreference, IContextBaseParams, IContextParams, IDecoratedNav, IEndUser, IEntity, IEquatable, IFeature, IFeatureType, ILabel, ILayout, ILegalNotice, ILetter, ILocale, ILocaleId, ILocalizable, ILocalized, ILocalizedString, IMarket, IMedia, IMediaType, IMemoryStore, IMenu, IMenuBase, IMenuCategory, IMenuCustom, IMenuGroup, IMenuHref, IMenuItem, IMenuLink, IMenuPage, IMenuRoute, INamedEntity, IOption, IOverride, IOverrideReturnValue, IOverrideValue, IPackages, IPage, IPageRelation, IPageRelationResult, IPageUnresolvedRelation, IPagedResult, IPaginationResult, IPartial, IPreference, IPrettify, IQuerable, IRedirect, IRoute, IRouteCanonical, IRouteLink, IRouteParams, ISchema, ISerializedCollection, ISerializedStore, IServerSideContext, IServerSideSplatContext, IStaticContext, IStore, ITemplate, ITitledEntity, IUndecoratedMenu, IUndecoratedMenuBase, IUndecoratedMenuCategory, IUndecoratedMenuCustom, IUndecoratedMenuGroup, IUndecoratedMenuItem, IUndecoratedMenuLink, IUndecoratedMenuPage, IUndecoratedNav, Json, JsonService, LiteralUnion, Logger, LoggerLevel, NextApiRequestCookies, Operator, PageProps, Pagination, PreviewData, QueryParams, RedirectReason, RouteStrategy, SchemaType, ServerSidePropsContext, StateValue, StaticPropsContext, User, UserRole, UserWithRoles, ValueOf, Where, WhereAndOr, WhereBase, WhereField, asCategoryId, asEquatable, asServerProps, awaitAll, camelToSnakeCase, cloneItem, collectFeatureTypes, collectOptions, collectRoutes, consoleWarn, defaultLocale, defaultMarket, eachCategorized, eachMarketLocale, enumToList, getCategorySegments, getCategorySegmentsByCategory, getClassNames, getCollectionDescription, getEnv, getIsDevelopment, getIsProduction, getParentCategoriesById, getRootCategory, getRouteHref, httpDelete, httpFetch, httpGet, httpPatch, httpPost, httpPut, isArray, isBrowser, isCategory, isDevelopment, isEntity, isEquatable, isLocalizedString, isMenuHref, isNotNullString, isObject, isProduction, isRelation, isReservedCollectionDescription, isStage, isUndecoratedMenuCategory, isUndecoratedMenuItem, isUndecoratedMenuPage, isUndecoratedNav, isUnresolvedRelation, isValidCollectionDescription, localize, localizeItem, localizeValue, localizedToString, merge, pascalCaseToCamelCase, pascalCaseToCharCase, pascalCaseToKebabCase, pascalCaseToSnakeCase, qsDeserialize, qsDeserializeRaw, qsSerialize, qsSerializeRaw, resolveMediaType, textToSlug, toCamelCase, toCharCase, toDisplayName, toFindParams, toKebabCase, toPascalCase, toPluralName, toSnakeCase, toTitleCase, toValidCollectionName, unknownCaseToPascalCase, withSchema };
package/dist/index.js CHANGED
@@ -73,6 +73,7 @@ __export(src_exports, {
73
73
  isEntity: () => isEntity,
74
74
  isEquatable: () => isEquatable,
75
75
  isLocalizedString: () => isLocalizedString,
76
+ isMenuHref: () => isMenuHref,
76
77
  isNotNullString: () => isNotNullString,
77
78
  isObject: () => isObject,
78
79
  isProduction: () => isProduction,
@@ -1129,6 +1130,11 @@ function resolveMediaType(media) {
1129
1130
  return media.type || (media.mimeType ? media.mimeType.split("/")[0] : "image");
1130
1131
  }
1131
1132
 
1133
+ // src/types/menu.ts
1134
+ function isMenuHref(item) {
1135
+ return ["category", "link", "page", "route"].includes(item.type);
1136
+ }
1137
+
1132
1138
  // src/types/querable.ts
1133
1139
  function toFindParams(idOrParams) {
1134
1140
  if (typeof idOrParams === "number" || typeof idOrParams === "string") {
@@ -1192,6 +1198,7 @@ var RedirectReason = /* @__PURE__ */ ((RedirectReason2) => {
1192
1198
  isEntity,
1193
1199
  isEquatable,
1194
1200
  isLocalizedString,
1201
+ isMenuHref,
1195
1202
  isNotNullString,
1196
1203
  isObject,
1197
1204
  isProduction,
package/dist/index.mjs CHANGED
@@ -1012,6 +1012,11 @@ function resolveMediaType(media) {
1012
1012
  return media.type || (media.mimeType ? media.mimeType.split("/")[0] : "image");
1013
1013
  }
1014
1014
 
1015
+ // src/types/menu.ts
1016
+ function isMenuHref(item) {
1017
+ return ["category", "link", "page", "route"].includes(item.type);
1018
+ }
1019
+
1015
1020
  // src/types/querable.ts
1016
1021
  function toFindParams(idOrParams) {
1017
1022
  if (typeof idOrParams === "number" || typeof idOrParams === "string") {
@@ -1074,6 +1079,7 @@ export {
1074
1079
  isEntity,
1075
1080
  isEquatable,
1076
1081
  isLocalizedString,
1082
+ isMenuHref,
1077
1083
  isNotNullString,
1078
1084
  isObject,
1079
1085
  isProduction,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@websolutespa/bom-core",
3
- "version": "0.6.6",
3
+ "version": "1.7.0",
4
4
  "description": "Core module of the BOM Repository",
5
5
  "keywords": [
6
6
  "bom",