@churchapps/content-providers 0.1.9 → 0.1.11

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/dist/index.cjs CHANGED
@@ -1493,6 +1493,21 @@ async function fetchVenueActions(venueId) {
1493
1493
  return null;
1494
1494
  }
1495
1495
  }
1496
+ async function fetchVenueImages(venueIds) {
1497
+ const map = /* @__PURE__ */ new Map();
1498
+ if (venueIds.length === 0) return map;
1499
+ try {
1500
+ const url = `${LESSONS_API_BASE}/venues/public/images?ids=${venueIds.join(",")}`;
1501
+ const response = await fetch(url, { method: "GET", headers: { Accept: "application/json" } });
1502
+ if (!response.ok) return map;
1503
+ const data = await response.json();
1504
+ for (const row of data) {
1505
+ if (row.venueId && row.lessonImage) map.set(row.venueId, row.lessonImage);
1506
+ }
1507
+ } catch {
1508
+ }
1509
+ return map;
1510
+ }
1496
1511
  async function fetchFromProviderProxy(method, ministryId, providerId, path, authData, resolution) {
1497
1512
  try {
1498
1513
  const url = `${API_BASE3}/doing/providerProxy/${method}`;
@@ -1531,8 +1546,8 @@ function ministryToFolder(ministry) {
1531
1546
  function planTypeToFolder(planType) {
1532
1547
  return { type: "folder", id: planType.id, title: planType.name, path: "" };
1533
1548
  }
1534
- function planToFolder(plan) {
1535
- return { type: "folder", id: plan.id, title: plan.name, path: "", isLeaf: true };
1549
+ function planToFolder(plan, thumbnail) {
1550
+ return { type: "folder", id: plan.id, title: plan.name, path: "", isLeaf: true, thumbnail };
1536
1551
  }
1537
1552
  function getFilesFromVenueFeed(venueFeed, itemType, relatedId) {
1538
1553
  const files = [];
@@ -1729,8 +1744,10 @@ var B1ChurchProvider = class {
1729
1744
  const ministryId = segments[1];
1730
1745
  const planTypeId = segments[2];
1731
1746
  const plans = await fetchPlans(planTypeId, authData);
1747
+ plans.sort((a, b) => new Date(a.serviceDate).getTime() - new Date(b.serviceDate).getTime());
1748
+ const imageMap = await this.fetchPlanImages(plans, ministryId, authData);
1732
1749
  return plans.map((p) => {
1733
- const folder = planToFolder(p);
1750
+ const folder = planToFolder(p, imageMap.get(p.id));
1734
1751
  return {
1735
1752
  ...folder,
1736
1753
  isLeaf: true,
@@ -1740,6 +1757,43 @@ var B1ChurchProvider = class {
1740
1757
  }
1741
1758
  return [];
1742
1759
  }
1760
+ async fetchPlanImages(plans, ministryId, authData) {
1761
+ const imageMap = /* @__PURE__ */ new Map();
1762
+ console.log(`[B1Church] fetchPlanImages: ${plans.length} plans, fields:`, plans.map((p) => ({ id: p.id, contentId: p.contentId, providerId: p.providerId, providerPlanId: p.providerPlanId })));
1763
+ const lessonsChurchPlans = plans.filter((p) => p.contentId && (!p.providerId || p.providerId === "lessonschurch"));
1764
+ const venueIds = lessonsChurchPlans.map((p) => p.contentId);
1765
+ console.log(`[B1Church] fetchPlanImages: ${lessonsChurchPlans.length} lessons.church plans, venueIds=${JSON.stringify(venueIds)}`);
1766
+ if (venueIds.length > 0) {
1767
+ const lcImages = await fetchVenueImages(venueIds);
1768
+ console.log(`[B1Church] fetchPlanImages: fetchVenueImages returned ${lcImages.size} images`);
1769
+ lcImages.forEach((img, venueId) => {
1770
+ const plan = lessonsChurchPlans.find((p) => p.contentId === venueId);
1771
+ if (plan) imageMap.set(plan.id, img);
1772
+ });
1773
+ }
1774
+ const externalPlans = plans.filter((p) => p.providerId && p.providerId !== "lessonschurch" && p.providerId !== "b1church" && p.providerPlanId);
1775
+ if (externalPlans.length > 0) {
1776
+ const groupKey = (p) => `${p.providerId}::${p.providerPlanId.split("/").slice(0, -1).join("/")}`;
1777
+ const groups = /* @__PURE__ */ new Map();
1778
+ for (const p of externalPlans) {
1779
+ const key = groupKey(p);
1780
+ if (!groups.has(key)) groups.set(key, []);
1781
+ groups.get(key).push(p);
1782
+ }
1783
+ await Promise.all(Array.from(groups.entries()).map(async ([key, groupPlans]) => {
1784
+ const [providerId, parentPath] = [key.split("::")[0], key.split("::").slice(1).join("::")];
1785
+ const items = await fetchFromProviderProxy("browse", ministryId, providerId, parentPath, authData);
1786
+ if (Array.isArray(items)) {
1787
+ for (const plan of groupPlans) {
1788
+ const leafId = plan.providerPlanId.split("/").pop();
1789
+ const match = items.find((item) => item.id === leafId || item.id === plan.contentId);
1790
+ if (match?.thumbnail) imageMap.set(plan.id, match.thumbnail);
1791
+ }
1792
+ }
1793
+ }));
1794
+ }
1795
+ return imageMap;
1796
+ }
1743
1797
  // async getPresentations(path: string, authData?: ContentProviderAuthData | null): Promise<Plan | null> {
1744
1798
  // const { segments, depth } = parsePath(path);
1745
1799
  // if (depth < 4 || segments[0] !== "ministries") return null;