@websolutespa/payload-plugin-bowl 1.8.1 → 1.8.2

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,12 @@
1
1
  # @websolutespa/payload-plugin-bowl
2
2
 
3
+ ## 1.8.2
4
+
5
+ ### Patch Changes
6
+
7
+ - Modified: Media collection
8
+ - Fixing: destructuring request query
9
+
3
10
  ## 1.8.1
4
11
 
5
12
  ### Patch Changes
package/dist/index.js CHANGED
@@ -1446,7 +1446,7 @@ var afterStaticReadHook = /* @__PURE__ */ __name((collectionConfig) => async ({
1446
1446
  doc,
1447
1447
  req
1448
1448
  }) => {
1449
- const { query } = req;
1449
+ const { query = {} } = req;
1450
1450
  const { locale, market } = query;
1451
1451
  const depth = query.depth ? getNumericParam(query.depth) : 1;
1452
1452
  const withStatic = depth > 0 && typeof locale === "string" ? await decorateStatic_(doc, collectionConfig.fields, locale, depth) : doc;
@@ -1481,7 +1481,7 @@ var staticIndexGet = /* @__PURE__ */ __name((collectionConfig) => ({
1481
1481
  method: "get",
1482
1482
  handler: async (req, res, next) => {
1483
1483
  try {
1484
- const { query } = req;
1484
+ const { query = {} } = req;
1485
1485
  const { market, locale, where, sort, pagination, page, limit } = query;
1486
1486
  let usePagination = pagination !== "false";
1487
1487
  if (typeof market === "string" && typeof locale === "string" && pagination !== "true") {
@@ -1521,7 +1521,7 @@ var staticDetailGet = /* @__PURE__ */ __name((collectionConfig) => ({
1521
1521
  try {
1522
1522
  const loader = getStaticLoader(collectionConfig.slug);
1523
1523
  const collection = await loader();
1524
- const { query, params } = req;
1524
+ const { query = {}, params = {} } = req;
1525
1525
  const { id } = params;
1526
1526
  let item = collection.find((x) => x.id === id);
1527
1527
  if (item) {
@@ -1710,7 +1710,7 @@ function parseDepth(depth) {
1710
1710
  }
1711
1711
  __name(parseDepth, "parseDepth");
1712
1712
  async function getCollectionItems(req, slug, depth) {
1713
- const { query, payload: payload2, user } = req;
1713
+ const { query = {}, payload: payload2, user } = req;
1714
1714
  const { locale, where, sort, draft } = query;
1715
1715
  depth = depth !== void 0 ? depth : parseDepth(query.depth);
1716
1716
  query.depth = String(depth);
@@ -1733,7 +1733,7 @@ async function getCollectionItems(req, slug, depth) {
1733
1733
  }
1734
1734
  __name(getCollectionItems, "getCollectionItems");
1735
1735
  async function getCollectionItem(req, slug, id, depth) {
1736
- const { query, payload: payload2, user } = req;
1736
+ const { query = {}, payload: payload2, user } = req;
1737
1737
  const { locale, draft } = query;
1738
1738
  depth = depth !== void 0 ? depth : parseDepth(query.depth);
1739
1739
  query.depth = String(depth);
@@ -1752,7 +1752,7 @@ async function getCollectionItem(req, slug, id, depth) {
1752
1752
  }
1753
1753
  __name(getCollectionItem, "getCollectionItem");
1754
1754
  async function getGlobalItems(req, slug, depth) {
1755
- const { query, payload: payload2, user } = req;
1755
+ const { query = {}, payload: payload2, user } = req;
1756
1756
  const { locale, draft } = query;
1757
1757
  depth = depth !== void 0 ? depth : parseDepth(query.depth);
1758
1758
  query.depth = String(depth);
@@ -2043,7 +2043,7 @@ var afterCollectionReadHook = /* @__PURE__ */ __name((collectionConfig) => async
2043
2043
  doc,
2044
2044
  req
2045
2045
  }) => {
2046
- const { query } = req;
2046
+ const { query = {} } = req;
2047
2047
  const { locale, market } = query;
2048
2048
  const depth = query.depth ? getNumericParam(query.depth) : 1;
2049
2049
  const withStatic = depth > 0 && typeof locale === "string" ? await decorateStatic_(doc, collectionConfig.fields, locale, depth) : doc;
@@ -2194,12 +2194,21 @@ var routeGet = {
2194
2194
  path: "/route",
2195
2195
  method: "get",
2196
2196
  handler: async (req, res, next) => {
2197
- const routes = await getRoutes(req);
2198
- if (typeof req.query.where === "object") {
2199
- const items = await whereCollection(routes, req.query.where);
2200
- res.status(200).send(items);
2201
- } else {
2202
- res.status(200).send(routes);
2197
+ try {
2198
+ const routes = await getRoutes(req);
2199
+ if (typeof req.query.where === "object") {
2200
+ const items = await whereCollection(routes, req.query.where);
2201
+ return res.status(200).send(items);
2202
+ } else {
2203
+ return res.status(200).send(routes);
2204
+ }
2205
+ } catch (error) {
2206
+ console.error("RouteService.routeGet.error", error);
2207
+ return res.status(error.status || 500).json({
2208
+ errors: [{
2209
+ message: error.message || error.name || error.statusText || "An error occurred"
2210
+ }]
2211
+ });
2203
2212
  }
2204
2213
  }
2205
2214
  };
@@ -2425,7 +2434,7 @@ async function collectPageRedirects(req, previousItem, newItem) {
2425
2434
  const collectedRedirects = [];
2426
2435
  const isProduction = (0, import_bom_core3.getIsProduction)();
2427
2436
  if (isProduction) {
2428
- const { query, collection, payload: payload2, user } = req;
2437
+ const { query = {}, collection, payload: payload2, user } = req;
2429
2438
  const { locale } = query;
2430
2439
  const slug = collection.config.slug;
2431
2440
  const previousRoutes = await getRouteByItemAndLocale(req, previousItem, locale, slug);
@@ -2468,7 +2477,7 @@ async function collectCategoryRedirects(req, previousItem, newItem) {
2468
2477
  const collectedRedirects = [];
2469
2478
  const isProduction = (0, import_bom_core3.getIsProduction)();
2470
2479
  if (isProduction) {
2471
- const { query, collection, payload: payload2, user } = req;
2480
+ const { query = {}, collection, payload: payload2, user } = req;
2472
2481
  const { locale } = query;
2473
2482
  const slug = collection.config.slug;
2474
2483
  const previousRoutes = await getRouteByCategoryAndLocale(req, previousItem, locale, slug);
@@ -4078,7 +4087,12 @@ var optinGet = {
4078
4087
  await optin(req.params.id, req.params.slug);
4079
4088
  return res.status(200).send({ status: 200, message: "optin success" });
4080
4089
  } catch (error) {
4081
- return res.status(error.status).send(error);
4090
+ console.error("ActionService.optinGet.error", error);
4091
+ return res.status(error.status || 500).json({
4092
+ errors: [{
4093
+ message: error.message || error.name || error.statusText || "An error occurred"
4094
+ }]
4095
+ });
4082
4096
  }
4083
4097
  }
4084
4098
  };
@@ -4090,7 +4104,12 @@ var optoutGet = {
4090
4104
  await optout(req.params.id, req.params.slug);
4091
4105
  return res.status(200).send({ status: 200, message: "optout success" });
4092
4106
  } catch (error) {
4093
- return res.status(error.status).send(error);
4107
+ console.error("ActionService.optoutGet.error", error);
4108
+ return res.status(error.status || 500).json({
4109
+ errors: [{
4110
+ message: error.message || error.name || error.statusText || "An error occurred"
4111
+ }]
4112
+ });
4094
4113
  }
4095
4114
  }
4096
4115
  };
@@ -4106,28 +4125,37 @@ var localeGet = {
4106
4125
  path: "/locale",
4107
4126
  method: "get",
4108
4127
  handler: async (req, res, next) => {
4109
- const { url, query, params } = req;
4110
- const { locale, where, sort, pagination, page, limit, depth, draft } = query;
4111
- const loader = getStaticLoader(options.slug.language);
4112
- const languages = await loader();
4113
- let items = await getLocale(req);
4114
- items = items.map((item) => {
4115
- const language = languages.find((x) => x.id === item.id);
4116
- item.title = language ? language.name : null;
4117
- return item;
4118
- });
4119
- items = await whereCollection(items, getObjectParam(where));
4120
- items = await localizeCollection(items, ["title"], getStringParam(locale));
4121
- items = await sortCollection(items, getStringParam(sort));
4122
- if (pagination !== "false") {
4123
- const result = await getPagination(
4124
- items,
4125
- getNumericParam(page),
4126
- getNumericParam(limit)
4127
- );
4128
- res.status(200).send(result);
4129
- } else {
4130
- res.status(200).send(items);
4128
+ try {
4129
+ const { query = {} } = req;
4130
+ const { locale, where, sort, pagination, page, limit } = query;
4131
+ const loader = getStaticLoader(options.slug.language);
4132
+ const languages = await loader();
4133
+ let items = await getLocale(req);
4134
+ items = items.map((item) => {
4135
+ const language = languages.find((x) => x.id === item.id);
4136
+ item.title = language ? language.name : null;
4137
+ return item;
4138
+ });
4139
+ items = await whereCollection(items, getObjectParam(where));
4140
+ items = await localizeCollection(items, ["title"], getStringParam(locale));
4141
+ items = await sortCollection(items, getStringParam(sort));
4142
+ if (pagination !== "false") {
4143
+ const result = await getPagination(
4144
+ items,
4145
+ getNumericParam(page),
4146
+ getNumericParam(limit)
4147
+ );
4148
+ return res.status(200).send(result);
4149
+ } else {
4150
+ return res.status(200).send(items);
4151
+ }
4152
+ } catch (error) {
4153
+ console.error("RouteService.routeGet.error", error);
4154
+ return res.status(error.status || 500).json({
4155
+ errors: [{
4156
+ message: error.message || error.name || error.statusText || "An error occurred"
4157
+ }]
4158
+ });
4131
4159
  }
4132
4160
  }
4133
4161
  };
@@ -4526,7 +4554,7 @@ var afterMenuReadHook = /* @__PURE__ */ __name((collectionConfig) => async ({
4526
4554
  req,
4527
4555
  context
4528
4556
  }) => {
4529
- const { query } = req;
4557
+ const { query = {} } = req;
4530
4558
  const depth = query.depth ? getNumericParam(query.depth) : 1;
4531
4559
  const withStatic = depth > 0 && typeof query.locale === "string" ? await decorateStatic_(doc, collectionConfig.fields, query.locale, depth) : doc;
4532
4560
  const { market, locale, markets, locales: locales2, routes, categories } = context;
@@ -4616,7 +4644,7 @@ var afterPageReadHook = /* @__PURE__ */ __name((collectionConfig) => async ({
4616
4644
  req,
4617
4645
  context
4618
4646
  }) => {
4619
- const { query } = req;
4647
+ const { query = {} } = req;
4620
4648
  const depth = query.depth ? getNumericParam(query.depth) : 1;
4621
4649
  const withStatic = depth > 0 && typeof query.locale === "string" ? await decorateStatic_(doc, collectionConfig.fields, query.locale, depth) : doc;
4622
4650
  const { market, locale, routes, categories } = context;
@@ -4640,7 +4668,7 @@ var afterPageChangeHook = /* @__PURE__ */ __name(async ({
4640
4668
  // name of the operation ie. 'create', 'update'
4641
4669
  }) => {
4642
4670
  if (operation === "update") {
4643
- const { query } = req;
4671
+ const { query = {} } = req;
4644
4672
  const { draft } = query;
4645
4673
  if (!draft && doc.isDefault !== true && previousDoc.slug && doc.slug) {
4646
4674
  const redirects = await collectPageRedirects(req, previousDoc, doc);
@@ -4656,7 +4684,7 @@ var afterPageDeleteHook = /* @__PURE__ */ __name(async ({
4656
4684
  doc
4657
4685
  // deleted document
4658
4686
  }) => {
4659
- const { query } = req;
4687
+ const { query = {} } = req;
4660
4688
  const { draft } = query;
4661
4689
  if (!draft && doc.isDefault !== true && doc.slug) {
4662
4690
  console.log("RedirectService.deletePage !!!");
@@ -4669,7 +4697,8 @@ var import_qs2 = __toESM(require("qs"));
4669
4697
  var USE_CACHE = true;
4670
4698
  var CACHE_2 = new InMemoryCache();
4671
4699
  function getStoreRequest_(req, market = "all", locale = "all") {
4672
- const { where: w, market: m, locale: l, ...rest } = req.query;
4700
+ const { query = {} } = req;
4701
+ const { where: w, market: m, locale: l, ...rest } = query;
4673
4702
  const subQuery = {
4674
4703
  market,
4675
4704
  locale
@@ -4684,7 +4713,7 @@ function getStoreRequest_(req, market = "all", locale = "all") {
4684
4713
  __name(getStoreRequest_, "getStoreRequest_");
4685
4714
  async function getStore_(req) {
4686
4715
  const key = keyWithRequest("store", req);
4687
- if (CACHE_2.has(key) && USE_CACHE && req.query.nocache != null) {
4716
+ if (CACHE_2.has(key) && USE_CACHE && req.query?.nocache != null) {
4688
4717
  return CACHE_2.get(key);
4689
4718
  }
4690
4719
  const market = "all";
@@ -4736,9 +4765,17 @@ async function getStore_(req) {
4736
4765
  store[slug] = [];
4737
4766
  }
4738
4767
  }
4739
- const localeCollection = await fetchCollection_(req, "locale", { richText: false });
4740
- store.locale = localeCollection.docs;
4741
- const routes = await getRoutes(req);
4768
+ try {
4769
+ const localeCollection = await fetchCollection_(subRequest, "locale", { richText: false });
4770
+ store.locale = localeCollection.docs;
4771
+ } catch (error) {
4772
+ if (error.status !== 403) {
4773
+ throw error;
4774
+ }
4775
+ console.log("StoreService", "no access granted for collection 'locale'");
4776
+ store.locale = [];
4777
+ }
4778
+ const routes = await getRoutes(subRequest);
4742
4779
  store.route = routes;
4743
4780
  CACHE_2.set(key, store);
4744
4781
  return store;
@@ -4771,7 +4808,7 @@ function getApiUrl(req) {
4771
4808
  }
4772
4809
  __name(getApiUrl, "getApiUrl");
4773
4810
  function getSearchUrl(req, overrideQuery) {
4774
- const { query } = req;
4811
+ const { query = {} } = req;
4775
4812
  const params = Object.assign({
4776
4813
  locale: "all",
4777
4814
  depth: 1,
@@ -5224,7 +5261,7 @@ var afterGlobalReadHook = /* @__PURE__ */ __name((globalConfig) => async ({
5224
5261
  doc,
5225
5262
  req
5226
5263
  }) => {
5227
- const { query } = req;
5264
+ const { query = {} } = req;
5228
5265
  const { locale, market } = query;
5229
5266
  const depth = query.depth ? getNumericParam(query.depth) : 1;
5230
5267
  const withStatic = depth > 0 && typeof locale === "string" ? await decorateStatic_(doc, globalConfig.fields, locale, depth) : doc;
@@ -6641,6 +6678,8 @@ var Market = /* @__PURE__ */ __name((options2) => ({
6641
6678
  }), "Market");
6642
6679
 
6643
6680
  // src/collections/Media.ts
6681
+ var PAYLOAD_IMAGE_MAX_WIDTH = process.env.PAYLOAD_IMAGE_MAX_WIDTH ? parseInt(process.env.PAYLOAD_IMAGE_MAX_WIDTH) : 3840;
6682
+ var PAYLOAD_IMAGE_MAX_HEIGHT = process.env.PAYLOAD_IMAGE_MAX_HEIGHT ? parseInt(process.env.PAYLOAD_IMAGE_MAX_HEIGHT) : 3840;
6644
6683
  var Media = /* @__PURE__ */ __name((options2) => ({
6645
6684
  type: "withCollection",
6646
6685
  slug: options2.slug.media,
@@ -6656,19 +6695,12 @@ var Media = /* @__PURE__ */ __name((options2) => ({
6656
6695
  delete: isRole(roles.Admin, roles.Contributor, roles.Editor)
6657
6696
  },
6658
6697
  upload: {
6659
- adminThumbnail: "card",
6660
- imageSizes: [
6661
- {
6662
- name: "card",
6663
- width: 640,
6664
- height: 480
6665
- },
6666
- {
6667
- name: "feature",
6668
- width: 1024,
6669
- height: 576
6670
- }
6671
- ]
6698
+ focalPoint: true,
6699
+ resizeOptions: {
6700
+ withoutEnlargement: true,
6701
+ width: PAYLOAD_IMAGE_MAX_WIDTH,
6702
+ height: PAYLOAD_IMAGE_MAX_HEIGHT
6703
+ }
6672
6704
  },
6673
6705
  fields: [
6674
6706
  // inherited fields: id, createdAt, updatedAt
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@websolutespa/payload-plugin-bowl",
3
- "version": "1.8.1",
3
+ "version": "1.8.2",
4
4
  "description": "Bowl PayloadCms plugin of the BOM Repository",
5
5
  "keywords": [
6
6
  "payload",