@websolutespa/payload-plugin-bowl 0.0.1 → 0.1.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,11 @@
1
1
  # @websolutespa/payload-plugin-bowl
2
2
 
3
+ ## 0.1.0
4
+
5
+ ### Minor Changes
6
+
7
+ - mock refactor.
8
+
3
9
  ## 0.0.1
4
10
 
5
11
  ### Patch Changes
package/dist/index.d.ts CHANGED
@@ -3,10 +3,12 @@ import { Resource } from 'i18next';
3
3
  import * as payload_dist_fields_config_types from 'payload/dist/fields/config/types';
4
4
  import { Field, FieldHookArgs, Tab, FieldAffectingData, HookName, FieldHook as FieldHook$1, FieldBase, UIField } from 'payload/dist/fields/config/types';
5
5
  import * as payload_types from 'payload/types';
6
- import { PayloadRequest, Block, CollectionConfig, GlobalConfig, RichTextField, RelationshipField, CheckboxField, BlockField, DateField, TextField, GroupField, Field as Field$1, UploadField, ArrayField, SelectField, FieldHook, CollectionAfterChangeHook, CollectionAfterDeleteHook, CollapsibleField, RowField, TabsField } from 'payload/types';
6
+ import { PayloadRequest, CollectionAfterChangeHook, CollectionAfterDeleteHook, Block, CollectionConfig, GlobalConfig, RichTextField, RelationshipField, CheckboxField, BlockField, DateField, TextField, GroupField, Field as Field$1, UploadField, ArrayField, SelectField, FieldHook, CollapsibleField, RowField, TabsField } from 'payload/types';
7
7
  import * as payload_dist_admin_components_forms_FieldDescription_types from 'payload/dist/admin/components/forms/FieldDescription/types';
8
8
  import * as React from 'react';
9
9
  import React__default from 'react';
10
+ import { TypeWithID } from 'payload/dist/collections/config/types';
11
+ import { PaginatedDocs } from 'payload/dist/mongoose/types';
10
12
  import { Props } from 'payload/components/views/Cell';
11
13
  import { Props as Props$1 } from 'payload/components/fields/Text';
12
14
  import { FieldTypes } from 'payload/dist/admin/components/forms/field-types';
@@ -28,7 +30,12 @@ declare class InMemoryCache<T = any> {
28
30
  }
29
31
  declare function keyWithRequest(key: string, req: PayloadRequest<any>): string;
30
32
 
31
- declare const collectionGet: ((slug: string) => Endpoint);
33
+ declare function getCollectionItems<T extends TypeWithID = any>(req: PayloadRequest, slug: string): Promise<T[]>;
34
+ declare function getCollectionItem<T extends TypeWithID = any>(req: PayloadRequest, slug: string, id: string): Promise<T>;
35
+ /**
36
+ * Rest api collection get handler.
37
+ */
38
+ declare const collectionIndexGet: ((slug: string) => Endpoint);
32
39
 
33
40
  declare function getLocale(req: PayloadRequest<any>): Promise<ILocale[]>;
34
41
  declare const localeGet: Endpoint;
@@ -39,8 +46,13 @@ type ILocale = {
39
46
  isDefault?: boolean;
40
47
  };
41
48
 
42
- declare function getRoutes(req: PayloadRequest<any>): Promise<IRoute[]>;
43
- declare function getRoute(req: PayloadRequest<any>, id: string): Promise<IRoute>;
49
+ type IEquatable = number | string;
50
+ type IEntity = Record<string, any> & {
51
+ id: IEquatable;
52
+ };
53
+ type ISchema = IEntity & {
54
+ schema?: string;
55
+ };
44
56
  type IRoute = {
45
57
  id: string;
46
58
  market: string;
@@ -133,7 +145,46 @@ type ICollectionItem = {
133
145
  _status: string;
134
146
  createdAt: Date;
135
147
  updatedAt: Date;
148
+ };
149
+
150
+ declare function decorateHref<T extends ISchema = ISchema>(req: PayloadRequest<any>, item: T, slug: string, market?: string, locale?: string): Promise<T & {
151
+ href: string | null;
152
+ }>;
153
+ declare function decorateHrefs<T extends ISchema = ISchema>(req: PayloadRequest<any>, items: T[], slug: string, market?: string, locale?: string): Promise<(T & {
154
+ href: string | null;
155
+ })[]>;
156
+ /**
157
+ * Rest api page collection get handler.
158
+ */
159
+ declare const pageIndexGet: ((slug: string) => Endpoint);
160
+ /**
161
+ * Rest api page collection detail get handler.
162
+ */
163
+ declare const pageDetailGet: ((slug: string) => Endpoint);
164
+ /**
165
+ * Create a record of the pages collection related to the created document.
166
+ */
167
+ declare const afterPageChangeHook: CollectionAfterChangeHook;
168
+ /**
169
+ * Delete records of the pages collection related to the deleted document.
170
+ */
171
+ declare const afterPageDeleteHook: CollectionAfterDeleteHook;
172
+
173
+ type IPagination = {
174
+ hasNextPage: boolean;
175
+ hasPrevPage: boolean;
176
+ limit: number;
177
+ nextPage: number | null;
178
+ page: number;
179
+ pagingCounter: number;
180
+ prevPage: number | null;
181
+ totalDocs: number;
182
+ totalPages: number;
136
183
  };
184
+ declare function getPagination<T = IEntity>(items: T[], page?: number, limit?: number): Promise<PaginatedDocs<T>>;
185
+
186
+ declare function getRoutes(req: PayloadRequest<any>): Promise<IRoute[]>;
187
+ declare function getRoute(req: PayloadRequest<any>, id: string): Promise<IRoute>;
137
188
  declare const routeGet: Endpoint;
138
189
 
139
190
  type IStore = {
@@ -153,6 +204,10 @@ declare function fetchCollectionItems<T = any>(req: PayloadRequest<T>, slug: str
153
204
  declare function fetchGlobalItems<T = any>(req: PayloadRequest, slug: string, query?: {}): Promise<T[]>;
154
205
  declare const storeGet: Endpoint;
155
206
 
207
+ declare function getObjectParam(value: unknown): {} | undefined;
208
+ declare function getNumericParam(value: unknown): number | undefined;
209
+ declare function getStringParam(value: unknown): string | undefined;
210
+
156
211
  type WithBlockProps = (Omit<Block, 'fields'> & {
157
212
  fields: BowlField[];
158
213
  });
@@ -216,9 +271,6 @@ type WithStaticProps = (Omit<CollectionConfig, 'fields'> & StaticCollectionConfi
216
271
  type WithStatic = WithStaticProps & {
217
272
  type: 'withStatic';
218
273
  };
219
- type IEntity = {
220
- id: string | number;
221
- };
222
274
  type Option = {
223
275
  id: string;
224
276
  name: string;
@@ -232,9 +284,6 @@ type StaticCollectionConfig = {
232
284
  src: StaticCollectionSrc;
233
285
  map?: KeyMapper;
234
286
  };
235
- declare function getObjectParam(value: unknown): {} | undefined;
236
- declare function getNumericParam(value: unknown): number | undefined;
237
- declare function getStringParam(value: unknown): string | undefined;
238
287
  declare function whereCollection<T = IEntity>(items: T[], where?: {
239
288
  [key: string]: any;
240
289
  }): Promise<T[]>;
@@ -536,15 +585,6 @@ declare function withCollectionHook(config: CollectionConfig, name: string, hook
536
585
  declare function withGlobalHook(config: GlobalConfig, name: string, hook: (...args: any[]) => unknown | Promise<unknown>): GlobalConfig;
537
586
  declare function withFieldHook(field: FieldAffectingData, name: HookName, hook: FieldHook$1): FieldAffectingData;
538
587
 
539
- /**
540
- * Create a record of the pages collection related to the created document.
541
- */
542
- declare const afterPageChangeHook: CollectionAfterChangeHook;
543
- /**
544
- * Delete records of the pages collection related to the deleted document.
545
- */
546
- declare const afterPageDeleteHook: CollectionAfterDeleteHook;
547
-
548
588
  type WithColorProps = (Omit<TextField, 'type' | 'name'> & {
549
589
  name?: string;
550
590
  });
@@ -762,4 +802,4 @@ declare function toField(item: BowlField): Field$1;
762
802
  declare function toBlock(item: BowlBlock): Block;
763
803
  declare function toTab(item: BowlTab): Tab;
764
804
 
765
- export { BlockDefaults, BowlArrayField, BowlBlock, BowlBlockField, BowlCollapsibleField, BowlCollection, BowlConfig, BowlField, BowlGlobal, BowlGroup, BowlGroupField, BowlInitOptions, BowlOptions, BowlRowField, BowlSlug, BowlTab, BowlTabsField, CategoryDefaults, CheckboxDefaults, CollectionDefault, CollectionHelper, ColorCell, ColorConfig, ColorField, ComponentsDefaults, DateDefaults, DebugField, FieldsConfig, GlobalDefault, GlobalHelper, ICache, ICategorized, ICategory, ICategoryItem, ICollectionItem, IEntity, ILocale, ILocalizedString, IMarket, IMedia, IMediaType, IPage, IPageFull, IRoute, IStore, InMemoryCache, InMemoryCacheOptions, LocalizedField, MarketDefaults, MediaDefaults, MediasDefaults, Option, PageDefault, RelatedDefaults, RichTextDefaults, SelectDefaults, StaticCollectionConfig, StaticCollectionDefault, TemplateDefaults, TextDefaults, UILanguagesCell, UILanguagesField, UIStaticCell, UIStaticField, WithAbstract, WithAbstractProps, WithBlock, WithBlockProps, WithCategory, WithCategoryProps, WithCheckbox, WithCheckboxProps, WithCollection, WithCollectionProps, WithColor, WithColorProps, WithComponents, WithComponentsProps, WithDate, WithDateProps, WithDescription, WithDescriptionProps, WithGlobal, WithGlobalProps, WithId, WithIdProps, WithIsActive, WithIsActiveProps, WithIsDefault, WithIsDefaultProps, WithLink, WithLinkOptions, WithLinkProps, WithMarkets, WithMarketsProps, WithMedia, WithMediaProps, WithMedias, WithMediasProps, WithName, WithNameProps, WithPage, WithPageProps, WithRelated, WithRelatedProps, WithRichText, WithRichTextProps, WithSelect, WithSelectProps, WithSlug, WithSlugProps, WithStatic, WithStaticProps, WithTemplate, WithTemplateProps, WithText, WithTextProps, WithTitle, WithTitleProps, afterPageChangeHook, afterPageDeleteHook, appearanceOptions, bowl, collectionGet, debugField, deepMerge, bowl as default, defaultGroup, defaultLocale, defaultLocales, defaultSlug, fetchCollection, fetchCollectionItems, fetchEndpoint, fetchGlobal, fetchGlobalItems, formatSlug, getApiUrl, getLocale, getNumericParam, getObjectParam, getRoute, getRoutes, getSearchUrl, getStaticLoader, getStore, getStringParam, getTranslation, getTranslations, internalSlugs, isObject, keyWithRequest, localeGet, localizeCollection, localizedField, logMissingTranslations, options, populateStaticFields, richTextAfterReadHook, richTextSerialize, routeGet, slugToLabel, slugToLabels, storeGet, toBlock, toCollection, toField, toGlobal, toTab, translateBlock, translateBlocks, translateCollection, translateField, translateFields, translateGlobal, translateTab, translateTabs, validateHexColor, whereCollection, withAbstract, withAbstractRequired, withBlock, withCategory, withCategoryRequired, withCheckbox, withCheckboxRequired, withCollection, withCollectionHook, withColor, withColorRequired, withComponents, withDate, withDateRequired, withDescription, withDescriptionRequired, withFieldHook, withGlobal, withGlobalHook, withId, withIdRequired, withIsActive, withIsActiveRequired, withIsDefault, withIsDefaultRequired, withLink, withLocalized, withMarkets, withMarketsRequired, withMedia, withMediaRequired, withMedias, withMediasRequired, withName, withNameRequired, withPage, withRelated, withRichText, withRichTextRequired, withSelect, withSelectRequired, withSlug, withSlugRequired, withStaticCollection, withTemplate, withTemplateRequired, withText, withTextRequired, withTitle, withTitleRequired, withUILanguages, withUIStatic };
805
+ export { BlockDefaults, BowlArrayField, BowlBlock, BowlBlockField, BowlCollapsibleField, BowlCollection, BowlConfig, BowlField, BowlGlobal, BowlGroup, BowlGroupField, BowlInitOptions, BowlOptions, BowlRowField, BowlSlug, BowlTab, BowlTabsField, CategoryDefaults, CheckboxDefaults, CollectionDefault, CollectionHelper, ColorCell, ColorConfig, ColorField, ComponentsDefaults, DateDefaults, DebugField, FieldsConfig, GlobalDefault, GlobalHelper, ICache, ICategorized, ICategory, ICategoryItem, ICollectionItem, IEntity, IEquatable, ILocale, ILocalizedString, IMarket, IMedia, IMediaType, IPage, IPageFull, IPagination, IRoute, ISchema, IStore, InMemoryCache, InMemoryCacheOptions, LocalizedField, MarketDefaults, MediaDefaults, MediasDefaults, Option, PageDefault, RelatedDefaults, RichTextDefaults, SelectDefaults, StaticCollectionConfig, StaticCollectionDefault, TemplateDefaults, TextDefaults, UILanguagesCell, UILanguagesField, UIStaticCell, UIStaticField, WithAbstract, WithAbstractProps, WithBlock, WithBlockProps, WithCategory, WithCategoryProps, WithCheckbox, WithCheckboxProps, WithCollection, WithCollectionProps, WithColor, WithColorProps, WithComponents, WithComponentsProps, WithDate, WithDateProps, WithDescription, WithDescriptionProps, WithGlobal, WithGlobalProps, WithId, WithIdProps, WithIsActive, WithIsActiveProps, WithIsDefault, WithIsDefaultProps, WithLink, WithLinkOptions, WithLinkProps, WithMarkets, WithMarketsProps, WithMedia, WithMediaProps, WithMedias, WithMediasProps, WithName, WithNameProps, WithPage, WithPageProps, WithRelated, WithRelatedProps, WithRichText, WithRichTextProps, WithSelect, WithSelectProps, WithSlug, WithSlugProps, WithStatic, WithStaticProps, WithTemplate, WithTemplateProps, WithText, WithTextProps, WithTitle, WithTitleProps, afterPageChangeHook, afterPageDeleteHook, appearanceOptions, bowl, collectionIndexGet, debugField, decorateHref, decorateHrefs, deepMerge, bowl as default, defaultGroup, defaultLocale, defaultLocales, defaultSlug, fetchCollection, fetchCollectionItems, fetchEndpoint, fetchGlobal, fetchGlobalItems, formatSlug, getApiUrl, getCollectionItem, getCollectionItems, getLocale, getNumericParam, getObjectParam, getPagination, getRoute, getRoutes, getSearchUrl, getStaticLoader, getStore, getStringParam, getTranslation, getTranslations, internalSlugs, isObject, keyWithRequest, localeGet, localizeCollection, localizedField, logMissingTranslations, options, pageDetailGet, pageIndexGet, populateStaticFields, richTextAfterReadHook, richTextSerialize, routeGet, slugToLabel, slugToLabels, storeGet, toBlock, toCollection, toField, toGlobal, toTab, translateBlock, translateBlocks, translateCollection, translateField, translateFields, translateGlobal, translateTab, translateTabs, validateHexColor, whereCollection, withAbstract, withAbstractRequired, withBlock, withCategory, withCategoryRequired, withCheckbox, withCheckboxRequired, withCollection, withCollectionHook, withColor, withColorRequired, withComponents, withDate, withDateRequired, withDescription, withDescriptionRequired, withFieldHook, withGlobal, withGlobalHook, withId, withIdRequired, withIsActive, withIsActiveRequired, withIsDefault, withIsDefaultRequired, withLink, withLocalized, withMarkets, withMarketsRequired, withMedia, withMediaRequired, withMedias, withMediasRequired, withName, withNameRequired, withPage, withRelated, withRichText, withRichTextRequired, withSelect, withSelectRequired, withSlug, withSlugRequired, withStaticCollection, withTemplate, withTemplateRequired, withText, withTextRequired, withTitle, withTitleRequired, withUILanguages, withUIStatic };
package/dist/index.js CHANGED
@@ -61,8 +61,10 @@ __export(src_exports, {
61
61
  afterPageDeleteHook: () => afterPageDeleteHook,
62
62
  appearanceOptions: () => appearanceOptions,
63
63
  bowl: () => bowl,
64
- collectionGet: () => collectionGet,
64
+ collectionIndexGet: () => collectionIndexGet,
65
65
  debugField: () => debugField,
66
+ decorateHref: () => decorateHref,
67
+ decorateHrefs: () => decorateHrefs,
66
68
  deepMerge: () => deepMerge,
67
69
  default: () => src_default,
68
70
  defaultGroup: () => defaultGroup,
@@ -76,9 +78,12 @@ __export(src_exports, {
76
78
  fetchGlobalItems: () => fetchGlobalItems,
77
79
  formatSlug: () => formatSlug,
78
80
  getApiUrl: () => getApiUrl,
81
+ getCollectionItem: () => getCollectionItem,
82
+ getCollectionItems: () => getCollectionItems,
79
83
  getLocale: () => getLocale,
80
84
  getNumericParam: () => getNumericParam,
81
85
  getObjectParam: () => getObjectParam,
86
+ getPagination: () => getPagination,
82
87
  getRoute: () => getRoute,
83
88
  getRoutes: () => getRoutes,
84
89
  getSearchUrl: () => getSearchUrl,
@@ -95,6 +100,8 @@ __export(src_exports, {
95
100
  localizedField: () => localizedField,
96
101
  logMissingTranslations: () => logMissingTranslations,
97
102
  options: () => options,
103
+ pageDetailGet: () => pageDetailGet,
104
+ pageIndexGet: () => pageIndexGet,
98
105
  populateStaticFields: () => populateStaticFields,
99
106
  richTextAfterReadHook: () => richTextAfterReadHook,
100
107
  richTextSerialize: () => richTextSerialize,
@@ -747,43 +754,6 @@ function keyWithRequest(key, req) {
747
754
  }
748
755
  __name(keyWithRequest, "keyWithRequest");
749
756
 
750
- // src/core/api/collection.service.ts
751
- async function getCollectionItems(req, slug) {
752
- const { url, query, params, payload } = req;
753
- const { locale, where, sort, depth, draft, page, limit, pagination } = query;
754
- const response = await payload.find({
755
- collection: slug,
756
- draft: draft === "true",
757
- locale,
758
- where,
759
- sort,
760
- depth: parseInt(String(depth), 10),
761
- limit: 1e4,
762
- pagination: false
763
- });
764
- const items = response.docs ? response.docs : [];
765
- return items;
766
- }
767
- __name(getCollectionItems, "getCollectionItems");
768
- var collectionGet = /* @__PURE__ */ __name((slug) => ({
769
- path: "/",
770
- method: "get",
771
- handler: async (req, res, next) => {
772
- const { query } = req;
773
- const { pagination } = query;
774
- if (pagination !== "false") {
775
- return next();
776
- }
777
- try {
778
- const items = await getCollectionItems(req, slug);
779
- res.status(200).send(items);
780
- } catch (error) {
781
- console.log("collectionGet.error", error);
782
- res.status(500).send(error);
783
- }
784
- }
785
- }), "collectionGet");
786
-
787
757
  // src/translations.ts
788
758
  var translations = {
789
759
  en: {
@@ -1058,6 +1028,60 @@ var options = {
1058
1028
  };
1059
1029
  var internalSlugs = Object.entries(defaultSlug).map((x) => x[1]);
1060
1030
 
1031
+ // src/core/api/collection.service.ts
1032
+ async function getCollectionItems(req, slug) {
1033
+ const { url, query, params, payload } = req;
1034
+ const { locale, where, sort, depth, draft, page, limit, pagination } = query;
1035
+ const response = await payload.find({
1036
+ collection: slug,
1037
+ draft: draft === "true",
1038
+ locale,
1039
+ fallbackLocale: options.defaultLocale,
1040
+ where,
1041
+ sort,
1042
+ depth: parseInt(String(depth), 10),
1043
+ limit: 1e4,
1044
+ pagination: false,
1045
+ req
1046
+ });
1047
+ const items = response.docs ? response.docs : [];
1048
+ return items;
1049
+ }
1050
+ __name(getCollectionItems, "getCollectionItems");
1051
+ async function getCollectionItem(req, slug, id) {
1052
+ const { url, query, params, payload } = req;
1053
+ const { locale, depth, draft } = query;
1054
+ const item = await payload.findByID({
1055
+ collection: slug,
1056
+ id,
1057
+ draft: draft === "true",
1058
+ locale,
1059
+ fallbackLocale: options.defaultLocale,
1060
+ depth: parseInt(String(depth), 10),
1061
+ req
1062
+ });
1063
+ return item;
1064
+ }
1065
+ __name(getCollectionItem, "getCollectionItem");
1066
+ var collectionIndexGet = /* @__PURE__ */ __name((slug) => ({
1067
+ path: "/",
1068
+ method: "get",
1069
+ handler: async (req, res, next) => {
1070
+ const { query } = req;
1071
+ const { pagination } = query;
1072
+ if (pagination !== "false") {
1073
+ return next();
1074
+ }
1075
+ try {
1076
+ const items = await getCollectionItems(req, slug);
1077
+ res.status(200).send(items);
1078
+ } catch (error) {
1079
+ console.log("collectionGet.error", error);
1080
+ res.status(500).send(error);
1081
+ }
1082
+ }
1083
+ }), "collectionIndexGet");
1084
+
1061
1085
  // src/fields/ui-languages/UILanguagesCell.tsx
1062
1086
  var import_jsx_runtime = require("react/jsx-runtime");
1063
1087
  var UILanguagesCell = /* @__PURE__ */ __name(({ cellData, colIndex, collection, field, rowData }) => {
@@ -1834,58 +1858,6 @@ function withFieldHook(field, name, hook) {
1834
1858
  }
1835
1859
  __name(withFieldHook, "withFieldHook");
1836
1860
 
1837
- // src/core/utils/syncPages.ts
1838
- var afterPageChangeHook = /* @__PURE__ */ __name(async ({
1839
- doc,
1840
- // full document data
1841
- req,
1842
- // full express request
1843
- previousDoc,
1844
- // document data before updating the collection
1845
- operation
1846
- // name of the operation ie. 'create', 'update'
1847
- }) => {
1848
- if (operation === "create") {
1849
- const pages = await req.payload.find({
1850
- collection: "page",
1851
- where: { "content.value": { equals: doc.id } }
1852
- });
1853
- if (pages.totalDocs == 0) {
1854
- await req.payload.create({
1855
- collection: "page",
1856
- data: {
1857
- content: {
1858
- value: doc.id,
1859
- relationTo: req.collection.config.slug
1860
- }
1861
- }
1862
- });
1863
- }
1864
- }
1865
- return doc;
1866
- }, "afterPageChangeHook");
1867
- var afterPageDeleteHook = /* @__PURE__ */ __name(async ({
1868
- req,
1869
- // full express request
1870
- id,
1871
- // id of document to delete
1872
- doc
1873
- // deleted document
1874
- }) => {
1875
- const pages = await req.payload.find({
1876
- collection: "page",
1877
- where: { "content.value": { equals: id } }
1878
- });
1879
- if (pages.totalDocs > 0) {
1880
- pages.docs.map(async ({ id: pageId }) => {
1881
- await req.payload.delete({
1882
- collection: "page",
1883
- id: pageId
1884
- });
1885
- });
1886
- }
1887
- }, "afterPageDeleteHook");
1888
-
1889
1861
  // src/core/collections/withBlock.ts
1890
1862
  var BlockDefaults = {};
1891
1863
  var withBlock = /* @__PURE__ */ __name((options2) => {
@@ -1945,27 +1917,6 @@ function getLoader(config, src, map) {
1945
1917
  };
1946
1918
  }
1947
1919
  __name(getLoader, "getLoader");
1948
- function getObjectParam(value) {
1949
- if (typeof value === "object") {
1950
- return value;
1951
- }
1952
- return void 0;
1953
- }
1954
- __name(getObjectParam, "getObjectParam");
1955
- function getNumericParam(value) {
1956
- if (typeof value === "string") {
1957
- return parseInt(value);
1958
- }
1959
- return void 0;
1960
- }
1961
- __name(getNumericParam, "getNumericParam");
1962
- function getStringParam(value) {
1963
- if (typeof value === "string") {
1964
- return value;
1965
- }
1966
- return void 0;
1967
- }
1968
- __name(getStringParam, "getStringParam");
1969
1920
  function existsClause(value, exists) {
1970
1921
  if (typeof exists === "boolean") {
1971
1922
  return value != null === exists;
@@ -2101,32 +2052,6 @@ async function sortCollection(items, sort) {
2101
2052
  return items;
2102
2053
  }
2103
2054
  __name(sortCollection, "sortCollection");
2104
- async function getPagination(items, page = 1, limit = 10) {
2105
- const totalDocs = items.length;
2106
- const totalPages = Math.ceil(items.length / limit);
2107
- const hasNextPage = page < totalPages;
2108
- const hasPrevPage = page > 1;
2109
- const index = page - 1;
2110
- const from = index * limit;
2111
- const to = Math.min(page * limit, totalDocs);
2112
- const docs = items.slice(from, to);
2113
- const pagination = {
2114
- totalDocs,
2115
- totalPages,
2116
- page,
2117
- limit,
2118
- hasNextPage,
2119
- hasPrevPage,
2120
- nextPage: hasNextPage ? page + 1 : null,
2121
- prevPage: hasPrevPage ? page - 1 : null,
2122
- pagingCounter: from + 1
2123
- };
2124
- return {
2125
- docs,
2126
- ...pagination
2127
- };
2128
- }
2129
- __name(getPagination, "getPagination");
2130
2055
  function getStaticLoader(slug) {
2131
2056
  return staticCollectionLoaders[slug];
2132
2057
  }
@@ -2161,16 +2086,20 @@ var withStaticCollection = /* @__PURE__ */ __name(({ src, map, ...config }) => {
2161
2086
  try {
2162
2087
  const collection = await loader();
2163
2088
  const { url, query, params } = req;
2164
- const { locale, where, sort, page, limit, depth, draft } = query;
2089
+ const { locale, where, sort, pagination, page, limit, depth, draft } = query;
2165
2090
  let items = await whereCollection(collection, getObjectParam(where));
2166
2091
  items = await localizeCollection(items, localizedFields, getStringParam(locale));
2167
2092
  items = await sortCollection(items, getStringParam(sort));
2168
- const pagination = await getPagination(
2169
- items,
2170
- getNumericParam(page),
2171
- getNumericParam(limit)
2172
- );
2173
- res.status(200).send(pagination);
2093
+ if (pagination !== "false") {
2094
+ const result = await getPagination(
2095
+ items,
2096
+ getNumericParam(page),
2097
+ getNumericParam(limit)
2098
+ );
2099
+ res.status(200).send(result);
2100
+ } else {
2101
+ res.status(200).send(items);
2102
+ }
2174
2103
  } catch (error) {
2175
2104
  console.log("withStaticCollection.get.error", error);
2176
2105
  res.status(500).send(error);
@@ -2195,7 +2124,7 @@ var withStaticCollection = /* @__PURE__ */ __name(({ src, map, ...config }) => {
2195
2124
  item = localizeItem(item, localizedFields, getStringParam(locale));
2196
2125
  res.status(200).send(item);
2197
2126
  } else {
2198
- res.status(404);
2127
+ res.status(404).send("not found");
2199
2128
  }
2200
2129
  } catch (error) {
2201
2130
  console.log("withStaticCollection.get:id.error", error);
@@ -2247,7 +2176,7 @@ var withCollection = /* @__PURE__ */ __name((config) => {
2247
2176
  return doc;
2248
2177
  });
2249
2178
  collectionConfig.endpoints = [
2250
- collectionGet(config.slug)
2179
+ collectionIndexGet(config.slug)
2251
2180
  ];
2252
2181
  translateCollection(collectionConfig);
2253
2182
  return withLocalized(collectionConfig);
@@ -2288,48 +2217,459 @@ var withGlobal = /* @__PURE__ */ __name((config) => {
2288
2217
  return withLocalized(globalConfig);
2289
2218
  }, "withGlobal");
2290
2219
 
2291
- // src/core/fields/withRichText.ts
2292
- var import_escape_html2 = __toESM(require("escape-html"));
2293
- var import_slate2 = require("slate");
2294
- var richTextAfterReadHook = /* @__PURE__ */ __name((args) => {
2295
- const {
2296
- value,
2297
- // Typed as `string` as shown above
2298
- operation,
2299
- findMany,
2300
- data,
2301
- // Typed as a Partial of your ExampleDocumentType
2302
- siblingData,
2303
- // Typed as a Partial of SiblingDataType
2304
- originalDoc,
2305
- // Typed as ExampleDocumentType
2306
- req
2307
- } = args;
2308
- if (operation === "read" && (findMany || req.query && req.query.richText === "false")) {
2309
- return richTextSerialize(value);
2220
+ // src/core/api/pagination.service.ts
2221
+ async function getPagination(items, page = 1, limit = 10) {
2222
+ const totalDocs = items.length;
2223
+ const totalPages = Math.ceil(items.length / limit);
2224
+ const hasNextPage = page < totalPages;
2225
+ const hasPrevPage = page > 1;
2226
+ const index = page - 1;
2227
+ const from = index * limit;
2228
+ const to = Math.min(page * limit, totalDocs);
2229
+ const docs = items.slice(from, to);
2230
+ const pagination = {
2231
+ totalDocs,
2232
+ totalPages,
2233
+ page,
2234
+ limit,
2235
+ hasNextPage,
2236
+ hasPrevPage,
2237
+ nextPage: hasNextPage ? page + 1 : null,
2238
+ prevPage: hasPrevPage ? page - 1 : null,
2239
+ pagingCounter: from + 1
2240
+ };
2241
+ return {
2242
+ docs,
2243
+ ...pagination
2244
+ };
2245
+ }
2246
+ __name(getPagination, "getPagination");
2247
+
2248
+ // src/core/api/store.service.ts
2249
+ var import_qs3 = __toESM(require("qs"));
2250
+ var CACHE_ = new InMemoryCache();
2251
+ async function getStore(req) {
2252
+ const key = keyWithRequest("store", req);
2253
+ if (CACHE_.has(key)) {
2254
+ return CACHE_.get(key);
2310
2255
  }
2311
- return value;
2312
- }, "richTextAfterReadHook");
2313
- var RichTextDefaults = {
2314
- name: "richText",
2315
- type: "richText",
2316
- localized: true,
2317
- hooks: {
2318
- afterRead: [
2319
- richTextAfterReadHook
2320
- ]
2256
+ const store = {};
2257
+ for (const slug of options.collections) {
2258
+ const collection = await fetchCollection(req, slug);
2259
+ store[slug] = collection.docs;
2321
2260
  }
2322
- };
2323
- var withRichText = /* @__PURE__ */ __name((options2 = {}) => {
2324
- const field = deepMerge(RichTextDefaults, options2);
2325
- return field;
2326
- }, "withRichText");
2327
- var withRichTextRequired = /* @__PURE__ */ __name((options2 = {}) => {
2328
- const field = deepMerge({
2329
- ...RichTextDefaults,
2330
- required: true
2331
- }, options2);
2332
- return field;
2261
+ const locale = await fetchGlobal(req, "locale");
2262
+ store.locale = locale.items;
2263
+ const routes = await getRoutes(req);
2264
+ store.route = routes;
2265
+ CACHE_.set(key, store);
2266
+ return store;
2267
+ }
2268
+ __name(getStore, "getStore");
2269
+ function getApiUrl(req) {
2270
+ const { payload } = req;
2271
+ const { config } = payload;
2272
+ const url = `${config.serverURL}${config.routes.api}/`;
2273
+ return url;
2274
+ }
2275
+ __name(getApiUrl, "getApiUrl");
2276
+ function getSearchUrl(req, overrideQuery) {
2277
+ const { query } = req;
2278
+ const params = Object.assign({
2279
+ locale: "*",
2280
+ depth: 1,
2281
+ limit: 1e4
2282
+ }, overrideQuery || query);
2283
+ const search = import_qs3.default.stringify(params);
2284
+ const url = search ? `?${search}` : "";
2285
+ return url;
2286
+ }
2287
+ __name(getSearchUrl, "getSearchUrl");
2288
+ async function fetchEndpoint(req, endpoint, query) {
2289
+ try {
2290
+ const apiUrl = getApiUrl(req);
2291
+ const searchUrl = getSearchUrl(req, query);
2292
+ const url = `${apiUrl}${endpoint}${searchUrl}`;
2293
+ const httpGetResponse = await fetch(url, {
2294
+ method: "GET",
2295
+ headers: {
2296
+ "Content-Type": "application/json"
2297
+ }
2298
+ });
2299
+ if (!httpGetResponse.ok) {
2300
+ throw httpGetResponse;
2301
+ }
2302
+ const json = await httpGetResponse.json();
2303
+ return json;
2304
+ } catch (error) {
2305
+ console.log("StoreService.fetchEndpoint.error", error);
2306
+ throw error;
2307
+ }
2308
+ }
2309
+ __name(fetchEndpoint, "fetchEndpoint");
2310
+ async function fetchCollection(req, slug, query) {
2311
+ return await fetchEndpoint(req, slug, query);
2312
+ }
2313
+ __name(fetchCollection, "fetchCollection");
2314
+ async function fetchGlobal(req, slug, query) {
2315
+ return await fetchEndpoint(req, `globals/${slug}`, query);
2316
+ }
2317
+ __name(fetchGlobal, "fetchGlobal");
2318
+ async function fetchCollectionItems(req, slug, query) {
2319
+ const collection = await fetchCollection(req, slug, query);
2320
+ if (collection) {
2321
+ return collection.docs;
2322
+ }
2323
+ return [];
2324
+ }
2325
+ __name(fetchCollectionItems, "fetchCollectionItems");
2326
+ async function fetchGlobalItems(req, slug, query) {
2327
+ const collection = await fetchGlobal(req, slug, query);
2328
+ if (collection) {
2329
+ return collection.items;
2330
+ }
2331
+ return [];
2332
+ }
2333
+ __name(fetchGlobalItems, "fetchGlobalItems");
2334
+ var storeGet = {
2335
+ path: "/store",
2336
+ method: "get",
2337
+ handler: async (req, res, next) => {
2338
+ const store = await getStore(req);
2339
+ res.status(200).send(store);
2340
+ }
2341
+ };
2342
+
2343
+ // src/core/api/route.service.ts
2344
+ var CACHE_2 = new InMemoryCache();
2345
+ function isLocalizedString(value) {
2346
+ let isLocalizedString2 = false;
2347
+ if (value) {
2348
+ if (!Array.isArray(value) && typeof value === "object") {
2349
+ const matchKeys = Object.keys(value).reduce((p, c) => p && /^(\w{2})(-\w{2})?$/.test(c), true);
2350
+ const matchValues = Object.values(value).reduce((p, c) => p && typeof c === "string", true);
2351
+ isLocalizedString2 = Boolean(matchKeys && matchValues);
2352
+ }
2353
+ }
2354
+ return isLocalizedString2;
2355
+ }
2356
+ __name(isLocalizedString, "isLocalizedString");
2357
+ function localizedToString(json, locale = "en", defaultLocale2 = "en") {
2358
+ const localizedString = json[locale] || json[defaultLocale2] || Object.values(json)[0];
2359
+ return localizedString;
2360
+ }
2361
+ __name(localizedToString, "localizedToString");
2362
+ function getRouteSegments(schema, item, categories) {
2363
+ const segments = [];
2364
+ let parentId = item.category || null;
2365
+ while (parentId != null) {
2366
+ const parentCategory = categories.find((c) => c.id === parentId);
2367
+ if (parentCategory) {
2368
+ if (parentCategory.slug) {
2369
+ const segment = { ...parentCategory };
2370
+ segments.unshift(segment);
2371
+ }
2372
+ parentId = parentCategory.category ? parentCategory.category.id : null;
2373
+ } else {
2374
+ parentId = null;
2375
+ }
2376
+ }
2377
+ if (item.isDefault !== true) {
2378
+ segments.push({
2379
+ id: item.id,
2380
+ title: item.title,
2381
+ slug: item.slug,
2382
+ schema,
2383
+ page: item.id,
2384
+ media: null
2385
+ // item.media,
2386
+ });
2387
+ }
2388
+ return segments;
2389
+ }
2390
+ __name(getRouteSegments, "getRouteSegments");
2391
+ async function getRoutes(req) {
2392
+ const key = "route";
2393
+ if (CACHE_2.has(key)) {
2394
+ return CACHE_2.get(key);
2395
+ }
2396
+ const routes = [];
2397
+ let locales = await fetchGlobalItems(req, options.slug.locale, { depth: 0 });
2398
+ locales = locales.filter((x) => x.isActive);
2399
+ const languages = locales.map((x) => x.id);
2400
+ let markets = await fetchCollectionItems(req, options.slug.market, { depth: 0 });
2401
+ markets = markets.filter((x) => x.isActive).map((x) => ({
2402
+ id: x.id,
2403
+ languages: x.languages && x.languages.length ? x.languages : languages
2404
+ }));
2405
+ const categories = await fetchCollectionItems(req, options.slug.category, { depth: 1 });
2406
+ const keys = options.pages;
2407
+ for (const key2 of keys) {
2408
+ const items = await fetchCollectionItems(req, key2, { depth: 0 });
2409
+ for (const item of items) {
2410
+ const segments = getRouteSegments(key2, item, categories);
2411
+ const availableMarkets = item.markets ? markets.filter((x) => item.markets.indexOf(x.id) !== -1) : markets;
2412
+ availableMarkets.forEach((m) => {
2413
+ m.languages.forEach((l) => {
2414
+ const href = segments.reduce((p, c, i) => {
2415
+ let slug = c.slug;
2416
+ if (isLocalizedString(slug)) {
2417
+ slug = localizedToString(slug, l);
2418
+ }
2419
+ slug = `${p}/${slug}`;
2420
+ return slug === "/" ? "" : slug;
2421
+ }, "");
2422
+ let prefix = "";
2423
+ if (languages.length > 1 || markets.length > 1) {
2424
+ prefix = `/${l}`;
2425
+ }
2426
+ if (markets.length > 1) {
2427
+ prefix = `${prefix}-${m.id}`;
2428
+ }
2429
+ const route = {
2430
+ id: `${prefix}${href}`,
2431
+ market: m.id,
2432
+ locale: l,
2433
+ category: item.category,
2434
+ page: item.id,
2435
+ schema: key2,
2436
+ template: item.template
2437
+ };
2438
+ routes.push(route);
2439
+ });
2440
+ });
2441
+ if (key2 === "homepage") {
2442
+ const defaultLanguage = locales.find((x) => x.isDefault);
2443
+ const defaultMarket = markets.find((x) => x.isDefault) || markets[0];
2444
+ const defaultMarketLanguage = defaultMarket && defaultMarket.defaultLanguage ? defaultMarket.defaultLanguage : defaultLanguage.id;
2445
+ const route = {
2446
+ id: "/",
2447
+ market: defaultMarket.id,
2448
+ locale: defaultMarketLanguage,
2449
+ category: item.category,
2450
+ page: item.id,
2451
+ schema: key2,
2452
+ template: item.template
2453
+ };
2454
+ routes.push(route);
2455
+ }
2456
+ }
2457
+ }
2458
+ CACHE_2.set(key, routes);
2459
+ return routes;
2460
+ }
2461
+ __name(getRoutes, "getRoutes");
2462
+ async function getRoute(req, id) {
2463
+ const routes = await getRoutes(req);
2464
+ const route = routes.find((x) => x.id === id);
2465
+ return route || null;
2466
+ }
2467
+ __name(getRoute, "getRoute");
2468
+ var routeGet = {
2469
+ path: "/route",
2470
+ method: "get",
2471
+ handler: async (req, res, next) => {
2472
+ const routes = await getRoutes(req);
2473
+ if (typeof req.query.where === "object") {
2474
+ const items = await whereCollection(routes, req.query.where);
2475
+ if (items.length) {
2476
+ res.status(200).send(items);
2477
+ } else {
2478
+ res.status(404).send("not found");
2479
+ }
2480
+ } else {
2481
+ res.status(200).send(routes);
2482
+ }
2483
+ }
2484
+ };
2485
+
2486
+ // src/core/api/utils.ts
2487
+ function getObjectParam(value) {
2488
+ if (typeof value === "object") {
2489
+ return value;
2490
+ }
2491
+ return void 0;
2492
+ }
2493
+ __name(getObjectParam, "getObjectParam");
2494
+ function getNumericParam(value) {
2495
+ if (typeof value === "string") {
2496
+ return parseInt(value);
2497
+ }
2498
+ return void 0;
2499
+ }
2500
+ __name(getNumericParam, "getNumericParam");
2501
+ function getStringParam(value) {
2502
+ if (typeof value === "string") {
2503
+ return value;
2504
+ }
2505
+ return void 0;
2506
+ }
2507
+ __name(getStringParam, "getStringParam");
2508
+
2509
+ // src/core/api/page.service.ts
2510
+ async function decorateHref(req, item, slug, market = "ww", locale = "en") {
2511
+ const route = (await getRoutes(req)).find(
2512
+ (x) => x.schema === slug && x.page === item.id && x.market === market && x.locale === locale
2513
+ );
2514
+ const href = route ? route.id : null;
2515
+ return { ...item, href };
2516
+ }
2517
+ __name(decorateHref, "decorateHref");
2518
+ async function decorateHrefs(req, items, slug, market = "ww", locale = "en") {
2519
+ const routes = (await getRoutes(req)).filter(
2520
+ (x) => x.schema === slug && x.market === market && x.locale === locale
2521
+ );
2522
+ return items.map((item) => {
2523
+ const route = routes.find(
2524
+ (x) => x.page === item.id
2525
+ );
2526
+ const href = route ? route.id : null;
2527
+ return { ...item, href };
2528
+ });
2529
+ }
2530
+ __name(decorateHrefs, "decorateHrefs");
2531
+ var pageIndexGet = /* @__PURE__ */ __name((slug) => ({
2532
+ path: "/",
2533
+ method: "get",
2534
+ handler: async (req, res, next) => {
2535
+ const { query } = req;
2536
+ const { locale, market, pagination, page, limit } = query;
2537
+ if (pagination !== "false" || !locale || !market) {
2538
+ return next();
2539
+ }
2540
+ try {
2541
+ let items = await getCollectionItems(req, slug);
2542
+ if (pagination !== "false") {
2543
+ const response = await getPagination(items, getNumericParam(page), getNumericParam(limit));
2544
+ if (locale && market) {
2545
+ response.docs = await decorateHrefs(req, response.docs, slug, String(market), String(locale));
2546
+ }
2547
+ res.status(200).send(response);
2548
+ } else {
2549
+ if (locale && market) {
2550
+ items = await decorateHrefs(req, items, slug, String(market), String(locale));
2551
+ }
2552
+ res.status(200).send(items);
2553
+ }
2554
+ } catch (error) {
2555
+ console.log("pageIndexGet.error", error);
2556
+ res.status(500).send(error);
2557
+ }
2558
+ }
2559
+ }), "pageIndexGet");
2560
+ var pageDetailGet = /* @__PURE__ */ __name((slug) => ({
2561
+ path: "/:id/",
2562
+ method: "get",
2563
+ handler: async (req, res, next) => {
2564
+ const { id } = req.params;
2565
+ const { query } = req;
2566
+ const { market, locale } = query;
2567
+ if (!locale || !market) {
2568
+ return next();
2569
+ }
2570
+ try {
2571
+ let item = await getCollectionItem(req, slug, id);
2572
+ item = await decorateHref(req, item, slug, String(market), String(locale));
2573
+ res.status(200).send(item);
2574
+ } catch (error) {
2575
+ console.log("pageDetailGet.error", error);
2576
+ res.status(500).send(error);
2577
+ }
2578
+ }
2579
+ }), "pageDetailGet");
2580
+ var afterPageChangeHook = /* @__PURE__ */ __name(async ({
2581
+ doc,
2582
+ // full document data
2583
+ req,
2584
+ // full express request
2585
+ previousDoc,
2586
+ // document data before updating the collection
2587
+ operation
2588
+ // name of the operation ie. 'create', 'update'
2589
+ }) => {
2590
+ if (operation === "create") {
2591
+ const pages = await req.payload.find({
2592
+ collection: "page",
2593
+ where: { "content.value": { equals: doc.id } }
2594
+ });
2595
+ if (pages.totalDocs == 0) {
2596
+ await req.payload.create({
2597
+ collection: "page",
2598
+ data: {
2599
+ content: {
2600
+ value: doc.id,
2601
+ relationTo: req.collection.config.slug
2602
+ }
2603
+ }
2604
+ });
2605
+ }
2606
+ }
2607
+ return doc;
2608
+ }, "afterPageChangeHook");
2609
+ var afterPageDeleteHook = /* @__PURE__ */ __name(async ({
2610
+ req,
2611
+ // full express request
2612
+ id,
2613
+ // id of document to delete
2614
+ doc
2615
+ // deleted document
2616
+ }) => {
2617
+ const pages = await req.payload.find({
2618
+ collection: "page",
2619
+ where: { "content.value": { equals: id } }
2620
+ });
2621
+ if (pages.totalDocs > 0) {
2622
+ pages.docs.map(async ({ id: pageId }) => {
2623
+ await req.payload.delete({
2624
+ collection: "page",
2625
+ id: pageId
2626
+ });
2627
+ });
2628
+ }
2629
+ }, "afterPageDeleteHook");
2630
+
2631
+ // src/core/fields/withRichText.ts
2632
+ var import_escape_html2 = __toESM(require("escape-html"));
2633
+ var import_slate2 = require("slate");
2634
+ var richTextAfterReadHook = /* @__PURE__ */ __name((args) => {
2635
+ const {
2636
+ value,
2637
+ // Typed as `string` as shown above
2638
+ operation,
2639
+ findMany,
2640
+ data,
2641
+ // Typed as a Partial of your ExampleDocumentType
2642
+ siblingData,
2643
+ // Typed as a Partial of SiblingDataType
2644
+ originalDoc,
2645
+ // Typed as ExampleDocumentType
2646
+ req
2647
+ } = args;
2648
+ if (operation === "read" && (findMany || req.query && req.query.richText === "false")) {
2649
+ return richTextSerialize(value);
2650
+ }
2651
+ return value;
2652
+ }, "richTextAfterReadHook");
2653
+ var RichTextDefaults = {
2654
+ name: "richText",
2655
+ type: "richText",
2656
+ localized: true,
2657
+ hooks: {
2658
+ afterRead: [
2659
+ richTextAfterReadHook
2660
+ ]
2661
+ }
2662
+ };
2663
+ var withRichText = /* @__PURE__ */ __name((options2 = {}) => {
2664
+ const field = deepMerge(RichTextDefaults, options2);
2665
+ return field;
2666
+ }, "withRichText");
2667
+ var withRichTextRequired = /* @__PURE__ */ __name((options2 = {}) => {
2668
+ const field = deepMerge({
2669
+ ...RichTextDefaults,
2670
+ required: true
2671
+ }, options2);
2672
+ return field;
2333
2673
  }, "withRichTextRequired");
2334
2674
  function richTextSerialize(children) {
2335
2675
  if (Array.isArray(children)) {
@@ -2841,6 +3181,7 @@ var PageDefault = {
2841
3181
  // beforeValidate: [beforeValidateHook],
2842
3182
  afterChange: [afterPageChangeHook],
2843
3183
  afterDelete: [afterPageDeleteHook]
3184
+ // afterRead: [afterPageReadHook],
2844
3185
  }
2845
3186
  };
2846
3187
  var withPage = /* @__PURE__ */ __name((config) => {
@@ -2882,253 +3223,14 @@ var withPage = /* @__PURE__ */ __name((config) => {
2882
3223
  ...config.fields
2883
3224
  ];
2884
3225
  pageConfig.endpoints = [
2885
- collectionGet(pageConfig.slug)
3226
+ pageIndexGet(pageConfig.slug),
3227
+ pageDetailGet(pageConfig.slug)
2886
3228
  ];
2887
3229
  translateCollection(pageConfig);
2888
3230
  const localizedConfig = withLocalized(pageConfig);
2889
3231
  return localizedConfig;
2890
3232
  }, "withPage");
2891
3233
 
2892
- // src/core/api/store.service.ts
2893
- var import_qs3 = __toESM(require("qs"));
2894
-
2895
- // src/core/api/route.service.ts
2896
- var CACHE_ = new InMemoryCache();
2897
- async function getRoutes(req) {
2898
- const key = "route";
2899
- if (CACHE_.has(key)) {
2900
- return CACHE_.get(key);
2901
- }
2902
- const routes = [];
2903
- let locales = await fetchGlobalItems(req, options.slug.locale, { depth: 0 });
2904
- locales = locales.filter((x) => x.isActive);
2905
- const languages = locales.map((x) => x.id);
2906
- let markets = await fetchCollectionItems(req, options.slug.market, { depth: 0 });
2907
- markets = markets.filter((x) => x.isActive).map((x) => ({
2908
- id: x.id,
2909
- languages: x.languages && x.languages.length ? x.languages : languages
2910
- }));
2911
- const categories = await fetchCollectionItems(req, options.slug.category, { depth: 1 });
2912
- const keys = options.pages;
2913
- for (const key2 of keys) {
2914
- const items = await fetchCollectionItems(req, key2, { depth: 0 });
2915
- for (const item of items) {
2916
- const segments = getRouteSegments(key2, item, categories);
2917
- const availableMarkets = item.markets ? markets.filter((x) => item.markets.indexOf(x.id) !== -1) : markets;
2918
- availableMarkets.forEach((m) => {
2919
- m.languages.forEach((l) => {
2920
- const href = segments.reduce((p, c, i) => {
2921
- let slug = c.slug;
2922
- if (isLocalizedString(slug)) {
2923
- slug = localizedToString(slug, l);
2924
- }
2925
- slug = `${p}/${slug}`;
2926
- return slug === "/" ? "" : slug;
2927
- }, "");
2928
- let prefix = "";
2929
- if (languages.length > 1 || markets.length > 1) {
2930
- prefix = `/${l}`;
2931
- }
2932
- if (markets.length > 1) {
2933
- prefix = `${prefix}-${m.id}`;
2934
- }
2935
- const route = {
2936
- id: `${prefix}${href}`,
2937
- market: m.id,
2938
- locale: l,
2939
- category: item.category,
2940
- page: item.id,
2941
- schema: key2,
2942
- template: item.template
2943
- };
2944
- routes.push(route);
2945
- });
2946
- });
2947
- if (key2 === "homepage") {
2948
- const defaultLanguage = locales.find((x) => x.isDefault);
2949
- const defaultMarket = markets.find((x) => x.isDefault) || markets[0];
2950
- const defaultMarketLanguage = defaultMarket && defaultMarket.defaultLanguage ? defaultMarket.defaultLanguage : defaultLanguage.id;
2951
- const route = {
2952
- id: "/",
2953
- market: defaultMarket.id,
2954
- locale: defaultMarketLanguage,
2955
- category: item.category,
2956
- page: item.id,
2957
- schema: key2,
2958
- template: item.template
2959
- };
2960
- routes.push(route);
2961
- }
2962
- }
2963
- }
2964
- CACHE_.set(key, routes);
2965
- return routes;
2966
- }
2967
- __name(getRoutes, "getRoutes");
2968
- async function getRoute(req, id) {
2969
- const routes = await getRoutes(req);
2970
- const route = routes.find((x) => x.id === id);
2971
- return route || null;
2972
- }
2973
- __name(getRoute, "getRoute");
2974
- function isLocalizedString(value) {
2975
- let isLocalizedString2 = false;
2976
- if (value) {
2977
- if (!Array.isArray(value) && typeof value === "object") {
2978
- const matchKeys = Object.keys(value).reduce((p, c) => p && /^(\w{2})(-\w{2})?$/.test(c), true);
2979
- const matchValues = Object.values(value).reduce((p, c) => p && typeof c === "string", true);
2980
- isLocalizedString2 = Boolean(matchKeys && matchValues);
2981
- }
2982
- }
2983
- return isLocalizedString2;
2984
- }
2985
- __name(isLocalizedString, "isLocalizedString");
2986
- function localizedToString(json, locale = "en", defaultLocale2 = "en") {
2987
- const localizedString = json[locale] || json[defaultLocale2] || Object.values(json)[0];
2988
- return localizedString;
2989
- }
2990
- __name(localizedToString, "localizedToString");
2991
- function getRouteSegments(schema, item, categories) {
2992
- const segments = [];
2993
- let parentId = item.category || null;
2994
- while (parentId != null) {
2995
- const parentCategory = categories.find((c) => c.id === parentId);
2996
- if (parentCategory) {
2997
- if (parentCategory.slug) {
2998
- const segment = { ...parentCategory };
2999
- segments.unshift(segment);
3000
- }
3001
- parentId = parentCategory.category ? parentCategory.category.id : null;
3002
- } else {
3003
- parentId = null;
3004
- }
3005
- }
3006
- if (item.isDefault !== true) {
3007
- segments.push({
3008
- id: item.id,
3009
- title: item.title,
3010
- slug: item.slug,
3011
- schema,
3012
- page: item.id,
3013
- media: null
3014
- // item.media,
3015
- });
3016
- }
3017
- return segments;
3018
- }
3019
- __name(getRouteSegments, "getRouteSegments");
3020
- var routeGet = {
3021
- path: "/route",
3022
- method: "get",
3023
- handler: async (req, res, next) => {
3024
- const routes = await getRoutes(req);
3025
- if (typeof req.query.where === "object") {
3026
- const items = await whereCollection(routes, req.query.where);
3027
- if (items.length) {
3028
- res.status(200).send(items);
3029
- } else {
3030
- res.status(404);
3031
- }
3032
- } else {
3033
- res.status(200).send(routes);
3034
- }
3035
- }
3036
- };
3037
-
3038
- // src/core/api/store.service.ts
3039
- var CACHE_2 = new InMemoryCache();
3040
- async function getStore(req) {
3041
- const key = keyWithRequest("store", req);
3042
- if (CACHE_2.has(key)) {
3043
- return CACHE_2.get(key);
3044
- }
3045
- const store = {};
3046
- for (const slug of options.collections) {
3047
- const collection = await fetchCollection(req, slug);
3048
- store[slug] = collection.docs;
3049
- }
3050
- const locale = await fetchGlobal(req, "locale");
3051
- store.locale = locale.items;
3052
- const routes = await getRoutes(req);
3053
- store.route = routes;
3054
- CACHE_2.set(key, store);
3055
- return store;
3056
- }
3057
- __name(getStore, "getStore");
3058
- function getApiUrl(req) {
3059
- const { payload } = req;
3060
- const { config } = payload;
3061
- const url = `${config.serverURL}${config.routes.api}/`;
3062
- return url;
3063
- }
3064
- __name(getApiUrl, "getApiUrl");
3065
- function getSearchUrl(req, overrideQuery) {
3066
- const { query } = req;
3067
- const params = Object.assign({
3068
- locale: "*",
3069
- depth: 1,
3070
- limit: 1e4
3071
- }, overrideQuery || query);
3072
- const search = import_qs3.default.stringify(params);
3073
- const url = search ? `?${search}` : "";
3074
- return url;
3075
- }
3076
- __name(getSearchUrl, "getSearchUrl");
3077
- async function fetchEndpoint(req, endpoint, query) {
3078
- try {
3079
- const apiUrl = getApiUrl(req);
3080
- const searchUrl = getSearchUrl(req, query);
3081
- const url = `${apiUrl}${endpoint}${searchUrl}`;
3082
- const httpGetResponse = await fetch(url, {
3083
- method: "GET",
3084
- headers: {
3085
- "Content-Type": "application/json"
3086
- }
3087
- });
3088
- if (!httpGetResponse.ok) {
3089
- throw httpGetResponse;
3090
- }
3091
- const json = await httpGetResponse.json();
3092
- return json;
3093
- } catch (error) {
3094
- console.log("StoreService.fetchEndpoint.error", error);
3095
- throw error;
3096
- }
3097
- }
3098
- __name(fetchEndpoint, "fetchEndpoint");
3099
- async function fetchCollection(req, slug, query) {
3100
- return await fetchEndpoint(req, slug, query);
3101
- }
3102
- __name(fetchCollection, "fetchCollection");
3103
- async function fetchGlobal(req, slug, query) {
3104
- return await fetchEndpoint(req, `globals/${slug}`, query);
3105
- }
3106
- __name(fetchGlobal, "fetchGlobal");
3107
- async function fetchCollectionItems(req, slug, query) {
3108
- const collection = await fetchCollection(req, slug, query);
3109
- if (collection) {
3110
- return collection.docs;
3111
- }
3112
- return [];
3113
- }
3114
- __name(fetchCollectionItems, "fetchCollectionItems");
3115
- async function fetchGlobalItems(req, slug, query) {
3116
- const collection = await fetchGlobal(req, slug, query);
3117
- if (collection) {
3118
- return collection.items;
3119
- }
3120
- return [];
3121
- }
3122
- __name(fetchGlobalItems, "fetchGlobalItems");
3123
- var storeGet = {
3124
- path: "/store",
3125
- method: "get",
3126
- handler: async (req, res, next) => {
3127
- const store = await getStore(req);
3128
- res.status(200).send(store);
3129
- }
3130
- };
3131
-
3132
3234
  // src/core/api/locale.service.ts
3133
3235
  async function getLocale(req) {
3134
3236
  let locales = await fetchGlobalItems(req, options.slug.locale, { depth: 0 });
@@ -3155,7 +3257,7 @@ var localeGet = {
3155
3257
  if (items.length) {
3156
3258
  res.status(200).send(items);
3157
3259
  } else {
3158
- res.status(404);
3260
+ res.status(404).send("not found");
3159
3261
  }
3160
3262
  }
3161
3263
  };
@@ -3725,8 +3827,10 @@ var src_default = bowl;
3725
3827
  afterPageDeleteHook,
3726
3828
  appearanceOptions,
3727
3829
  bowl,
3728
- collectionGet,
3830
+ collectionIndexGet,
3729
3831
  debugField,
3832
+ decorateHref,
3833
+ decorateHrefs,
3730
3834
  deepMerge,
3731
3835
  defaultGroup,
3732
3836
  defaultLocale,
@@ -3739,9 +3843,12 @@ var src_default = bowl;
3739
3843
  fetchGlobalItems,
3740
3844
  formatSlug,
3741
3845
  getApiUrl,
3846
+ getCollectionItem,
3847
+ getCollectionItems,
3742
3848
  getLocale,
3743
3849
  getNumericParam,
3744
3850
  getObjectParam,
3851
+ getPagination,
3745
3852
  getRoute,
3746
3853
  getRoutes,
3747
3854
  getSearchUrl,
@@ -3758,6 +3865,8 @@ var src_default = bowl;
3758
3865
  localizedField,
3759
3866
  logMissingTranslations,
3760
3867
  options,
3868
+ pageDetailGet,
3869
+ pageIndexGet,
3761
3870
  populateStaticFields,
3762
3871
  richTextAfterReadHook,
3763
3872
  richTextSerialize,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@websolutespa/payload-plugin-bowl",
3
- "version": "0.0.1",
3
+ "version": "0.1.0",
4
4
  "description": "Bowl PayloadCms plugin of the BOM Repository",
5
5
  "keywords": [
6
6
  "payload",