@treely/strapi-slices 7.5.1 → 7.5.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.
@@ -446,27 +446,34 @@ var getAllSlugsFromStrapi = /*#__PURE__*/function () {
446
446
  case 3:
447
447
  allLocales = _context.sent;
448
448
  slugPromises = allLocales.map(function (locale) {
449
- var params = {
450
- locale: locale,
451
- 'pagination[pageSize]': STRAPI_DEFAULT_PAGE_SIZE,
452
- filters: filters
453
- };
454
449
  return strapiClient.get(path, {
455
- params: params
450
+ params: {
451
+ locale: locale,
452
+ 'pagination[pageSize]': STRAPI_DEFAULT_PAGE_SIZE,
453
+ filters: filters
454
+ }
455
+ }).then(function (response) {
456
+ return response.data.data.map(function (page) {
457
+ return {
458
+ slug: page.attributes.slug,
459
+ locale: page.attributes.locale
460
+ };
461
+ });
462
+ })
463
+ // when a collection type for a requested locale does not exist, Strapi returns a 404. In this case, we return an empty array instead of throwing an error
464
+ ["catch"](function (error) {
465
+ var _error$response;
466
+ if (((_error$response = error.response) == null ? void 0 : _error$response.status) === 404) {
467
+ return [];
468
+ }
469
+ throw error;
456
470
  });
457
471
  });
458
472
  _context.next = 7;
459
473
  return Promise.all(slugPromises);
460
474
  case 7:
461
475
  slugResults = _context.sent;
462
- allSlugs = slugResults.map(function (result) {
463
- return result.data.data.map(function (page) {
464
- return {
465
- slug: page.attributes.slug,
466
- locale: page.attributes.locale
467
- };
468
- });
469
- }).flat(); // Identify missing locales for each slug
476
+ allSlugs = slugResults.flat(); // Identify missing locales for each slug
470
477
  missingLocales = locales.flatMap(function (locale) {
471
478
  return allSlugs.filter(function (slug) {
472
479
  return slug.locale === STRAPI_FALLBACK_LOCALE;
@@ -596,27 +603,33 @@ var getStrapiCollectionType = /*#__PURE__*/function () {
596
603
  allLocales.push(STRAPI_FALLBACK_LOCALE);
597
604
  }
598
605
  promises = allLocales.map(function (loc) {
599
- var params = {
600
- pLevel: '6',
601
- locale: loc,
602
- 'pagination[pageSize]': STRAPI_DEFAULT_PAGE_SIZE,
603
- filters: filters
604
- };
605
- if (preview) {
606
- params.publicationState = 'preview';
607
- }
608
606
  return strapiClient.get(path, {
609
- params: params,
607
+ params: _extends({
608
+ pLevel: '6',
609
+ locale: loc,
610
+ 'pagination[pageSize]': STRAPI_DEFAULT_PAGE_SIZE,
611
+ filters: filters
612
+ }, preview ? {
613
+ publicationState: 'preview'
614
+ } : {}),
610
615
  cache: cache
616
+ }).then(function (response) {
617
+ return response.data.data;
618
+ })
619
+ // when a collection type for a requested locale does not exist, Strapi returns a 404. In this case, we return an empty array instead of throwing an error
620
+ ["catch"](function (error) {
621
+ var _error$response;
622
+ if (((_error$response = error.response) == null ? void 0 : _error$response.status) === 404) {
623
+ return [];
624
+ }
625
+ throw error;
611
626
  });
612
627
  });
613
628
  _context.next = 9;
614
629
  return Promise.all(promises);
615
630
  case 9:
616
631
  responses = _context.sent;
617
- results = responses.flatMap(function (response) {
618
- return response.data.data;
619
- });
632
+ results = responses.flat();
620
633
  localizedResponses = results.filter(function (d) {
621
634
  return d.attributes.locale === locale;
622
635
  });