@treely/strapi-slices 7.5.2 → 7.5.4

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.
@@ -407,45 +407,16 @@ var strapiClient = /*#__PURE__*/axiosCacheInterceptor.setupCache(/*#__PURE__*/ax
407
407
  ttl: /*#__PURE__*/STRAPI_URI.includes('127.0.0.1') || /*#__PURE__*/STRAPI_URI.includes('localhost') ? 0 : 10 * 60 * 1000 // 10 minutes
408
408
  });
409
409
 
410
- var getAvailableLocalesFromStrapi = /*#__PURE__*/function () {
411
- var _ref = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
412
- var _yield$strapiClient$g, data;
413
- return _regeneratorRuntime().wrap(function _callee$(_context) {
414
- while (1) switch (_context.prev = _context.next) {
415
- case 0:
416
- _context.next = 2;
417
- return strapiClient.get('/i18n/locales');
418
- case 2:
419
- _yield$strapiClient$g = _context.sent;
420
- data = _yield$strapiClient$g.data;
421
- return _context.abrupt("return", data.map(function (locale) {
422
- return locale.code;
423
- }));
424
- case 5:
425
- case "end":
426
- return _context.stop();
427
- }
428
- }, _callee);
429
- }));
430
- return function getAvailableLocalesFromStrapi() {
431
- return _ref.apply(this, arguments);
432
- };
433
- }();
434
-
435
410
  var getAllSlugsFromStrapi = /*#__PURE__*/function () {
436
411
  var _ref = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(path, locales, _temp) {
437
- var _ref2, _ref2$filters, filters, allLocales, slugPromises, slugResults, allSlugs, missingLocales;
412
+ var _ref2, _ref2$filters, filters, slugPromises, slugResults, allSlugs, missingLocales;
438
413
  return _regeneratorRuntime().wrap(function _callee$(_context) {
439
414
  while (1) switch (_context.prev = _context.next) {
440
415
  case 0:
441
416
  _ref2 = _temp === void 0 ? {
442
417
  filters: {}
443
418
  } : _temp, _ref2$filters = _ref2.filters, filters = _ref2$filters === void 0 ? {} : _ref2$filters;
444
- _context.next = 3;
445
- return getAvailableLocalesFromStrapi();
446
- case 3:
447
- allLocales = _context.sent;
448
- slugPromises = allLocales.map(function (locale) {
419
+ slugPromises = locales.map(function (locale) {
449
420
  return strapiClient.get(path, {
450
421
  params: {
451
422
  locale: locale,
@@ -469,9 +440,9 @@ var getAllSlugsFromStrapi = /*#__PURE__*/function () {
469
440
  throw error;
470
441
  });
471
442
  });
472
- _context.next = 7;
443
+ _context.next = 4;
473
444
  return Promise.all(slugPromises);
474
- case 7:
445
+ case 4:
475
446
  slugResults = _context.sent;
476
447
  allSlugs = slugResults.flat(); // Identify missing locales for each slug
477
448
  missingLocales = locales.flatMap(function (locale) {
@@ -488,7 +459,7 @@ var getAllSlugsFromStrapi = /*#__PURE__*/function () {
488
459
  }); // Clone only for missing locales
489
460
  });
490
461
  return _context.abrupt("return", [].concat(allSlugs, missingLocales));
491
- case 11:
462
+ case 8:
492
463
  case "end":
493
464
  return _context.stop();
494
465
  }
@@ -532,12 +503,10 @@ var getPortfolioProjects = /*#__PURE__*/function () {
532
503
  params = {
533
504
  pLevel: '6',
534
505
  locale: locale,
535
- 'pagination[pageSize]': STRAPI_DEFAULT_PAGE_SIZE
506
+ 'pagination[pageSize]': STRAPI_DEFAULT_PAGE_SIZE,
507
+ status: preview ? 'draft' : 'published'
536
508
  };
537
- if (preview) {
538
- params.publicationState = 'preview';
539
- }
540
- _context.next = 7;
509
+ _context.next = 6;
541
510
  return Promise.all([fpmClient.get('/public/projects', {
542
511
  cache: cache
543
512
  }), strapiClient.get('/projects', {
@@ -549,7 +518,7 @@ var getPortfolioProjects = /*#__PURE__*/function () {
549
518
  }),
550
519
  cache: cache
551
520
  })]);
552
- case 7:
521
+ case 6:
553
522
  _yield$Promise$all = _context.sent;
554
523
  fpmProjects = _yield$Promise$all[0].data;
555
524
  strapiProjectsLocalized = _yield$Promise$all[1].data;
@@ -576,7 +545,7 @@ var getPortfolioProjects = /*#__PURE__*/function () {
576
545
  }
577
546
  return toReturn;
578
547
  }));
579
- case 14:
548
+ case 13:
580
549
  case "end":
581
550
  return _context.stop();
582
551
  }
@@ -589,61 +558,64 @@ var getPortfolioProjects = /*#__PURE__*/function () {
589
558
 
590
559
  var getStrapiCollectionType = /*#__PURE__*/function () {
591
560
  var _ref2 = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(path, key, _ref) {
592
- var _ref$locale, locale, _ref$preview, preview, _ref$filters, filters, cache, allLocales, promises, responses, results, localizedResponses, fallbackResponses, result;
561
+ var _ref$locale, locale, _ref$preview, preview, _ref$filters, filters, cache, sharedParams, requestedLocaleData, fallbackLocaleData, results;
593
562
  return _regeneratorRuntime().wrap(function _callee$(_context) {
594
563
  while (1) switch (_context.prev = _context.next) {
595
564
  case 0:
596
565
  _ref$locale = _ref.locale, locale = _ref$locale === void 0 ? 'en' : _ref$locale, _ref$preview = _ref.preview, preview = _ref$preview === void 0 ? false : _ref$preview, _ref$filters = _ref.filters, filters = _ref$filters === void 0 ? {} : _ref$filters;
597
566
  cache = preview ? false : undefined;
598
- _context.next = 4;
599
- return getAvailableLocalesFromStrapi();
600
- case 4:
601
- allLocales = _context.sent;
602
- if (!allLocales.includes(STRAPI_FALLBACK_LOCALE)) {
603
- allLocales.push(STRAPI_FALLBACK_LOCALE);
604
- }
605
- promises = allLocales.map(function (loc) {
606
- return strapiClient.get(path, {
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
- } : {}),
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;
626
- });
627
- });
628
- _context.next = 9;
629
- return Promise.all(promises);
630
- case 9:
631
- responses = _context.sent;
632
- results = responses.flat();
633
- localizedResponses = results.filter(function (d) {
634
- return d.attributes.locale === locale;
567
+ sharedParams = {
568
+ pLevel: '6',
569
+ 'pagination[pageSize]': STRAPI_DEFAULT_PAGE_SIZE,
570
+ filters: filters,
571
+ status: preview ? 'draft' : 'published'
572
+ };
573
+ _context.next = 5;
574
+ return strapiClient.get(path, {
575
+ params: _extends({}, sharedParams, {
576
+ locale: locale
577
+ }),
578
+ cache: cache
579
+ }).then(function (response) {
580
+ return response.data.data;
581
+ })
582
+ // 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
583
+ ["catch"](function (error) {
584
+ var _error$response;
585
+ if (((_error$response = error.response) == null ? void 0 : _error$response.status) === 404) {
586
+ return [];
587
+ }
588
+ throw error;
635
589
  });
636
- fallbackResponses = results.filter(function (d) {
637
- return d.attributes.locale === STRAPI_FALLBACK_LOCALE;
590
+ case 5:
591
+ requestedLocaleData = _context.sent;
592
+ _context.next = 8;
593
+ return strapiClient.get(path, {
594
+ params: _extends({}, sharedParams, {
595
+ locale: STRAPI_FALLBACK_LOCALE
596
+ }),
597
+ cache: cache
598
+ }).then(function (response) {
599
+ return response.data.data;
600
+ })
601
+ // 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
602
+ ["catch"](function (error) {
603
+ var _error$response2;
604
+ if (((_error$response2 = error.response) == null ? void 0 : _error$response2.status) === 404) {
605
+ return [];
606
+ }
607
+ throw error;
638
608
  });
639
- result = fallbackResponses.map(function (fallbackResponse) {
640
- var localizedResponse = localizedResponses.find(function (localized) {
641
- return localized.attributes[key] === fallbackResponse.attributes[key];
609
+ case 8:
610
+ fallbackLocaleData = _context.sent;
611
+ results = fallbackLocaleData.map(function (fallbackLocaleDataEntry) {
612
+ var requestedLocale = requestedLocaleData.find(function (localized) {
613
+ return localized.attributes[key] === fallbackLocaleDataEntry.attributes[key];
642
614
  });
643
- return localizedResponse || fallbackResponse;
615
+ return requestedLocale || fallbackLocaleDataEntry;
644
616
  });
645
- return _context.abrupt("return", result);
646
- case 15:
617
+ return _context.abrupt("return", results);
618
+ case 11:
647
619
  case "end":
648
620
  return _context.stop();
649
621
  }
@@ -666,44 +638,42 @@ var getStrapiSingleType = /*#__PURE__*/function () {
666
638
  pLevel: '6',
667
639
  locale: locale,
668
640
  'pagination[pageSize]': STRAPI_DEFAULT_PAGE_SIZE,
669
- filters: filters
641
+ filters: filters,
642
+ status: preview ? 'draft' : 'published'
670
643
  };
671
- if (preview) {
672
- params.publicationState = 'preview';
673
- }
674
- _context.prev = 4;
675
- _context.next = 7;
644
+ _context.prev = 3;
645
+ _context.next = 6;
676
646
  return strapiClient.get(path, {
677
647
  params: params,
678
648
  cache: cache
679
649
  });
680
- case 7:
650
+ case 6:
681
651
  response = _context.sent;
682
652
  return _context.abrupt("return", response.data.data);
683
- case 11:
684
- _context.prev = 11;
685
- _context.t0 = _context["catch"](4);
653
+ case 10:
654
+ _context.prev = 10;
655
+ _context.t0 = _context["catch"](3);
686
656
  if (!(_context.t0.isAxiosError && ((_error$response = _context.t0.response) == null ? void 0 : _error$response.status) === 404)) {
687
- _context.next = 18;
657
+ _context.next = 17;
688
658
  break;
689
659
  }
690
- _context.next = 16;
660
+ _context.next = 15;
691
661
  return strapiClient.get(path, {
692
662
  params: _extends({}, params, {
693
663
  locale: STRAPI_FALLBACK_LOCALE
694
664
  }),
695
665
  cache: cache
696
666
  });
697
- case 16:
667
+ case 15:
698
668
  response = _context.sent;
699
669
  return _context.abrupt("return", response.data.data);
700
- case 18:
670
+ case 17:
701
671
  throw _context.t0;
702
- case 19:
672
+ case 18:
703
673
  case "end":
704
674
  return _context.stop();
705
675
  }
706
- }, _callee, null, [[4, 11]]);
676
+ }, _callee, null, [[3, 10]]);
707
677
  }));
708
678
  return function getStrapiSingleType(_x, _x2) {
709
679
  return _ref2.apply(this, arguments);