@churchapps/content-providers 0.1.10 → 0.1.12

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.d.cts CHANGED
@@ -499,6 +499,7 @@ declare class B1ChurchProvider implements IProvider {
499
499
  initiateDeviceFlow(): Promise<DeviceAuthorizationResponse | null>;
500
500
  pollDeviceFlowToken(deviceCode: string): Promise<DeviceFlowPollResult>;
501
501
  browse(path?: string | null, authData?: ContentProviderAuthData | null): Promise<ContentItem[]>;
502
+ private fetchPlanImages;
502
503
  getInstructions(path: string, authData?: ContentProviderAuthData | null): Promise<Instructions | null>;
503
504
  private processInstructionItems;
504
505
  private findItemByPath;
package/dist/index.d.ts CHANGED
@@ -499,6 +499,7 @@ declare class B1ChurchProvider implements IProvider {
499
499
  initiateDeviceFlow(): Promise<DeviceAuthorizationResponse | null>;
500
500
  pollDeviceFlowToken(deviceCode: string): Promise<DeviceFlowPollResult>;
501
501
  browse(path?: string | null, authData?: ContentProviderAuthData | null): Promise<ContentItem[]>;
502
+ private fetchPlanImages;
502
503
  getInstructions(path: string, authData?: ContentProviderAuthData | null): Promise<Instructions | null>;
503
504
  private processInstructionItems;
504
505
  private findItemByPath;
package/dist/index.js CHANGED
@@ -1437,6 +1437,21 @@ async function fetchVenueActions(venueId) {
1437
1437
  return null;
1438
1438
  }
1439
1439
  }
1440
+ async function fetchVenueImages(venueIds) {
1441
+ const map = /* @__PURE__ */ new Map();
1442
+ if (venueIds.length === 0) return map;
1443
+ try {
1444
+ const url = `${LESSONS_API_BASE}/venues/public/images?ids=${venueIds.join(",")}`;
1445
+ const response = await fetch(url, { method: "GET", headers: { Accept: "application/json" } });
1446
+ if (!response.ok) return map;
1447
+ const data = await response.json();
1448
+ for (const row of data) {
1449
+ if (row.venueId && row.lessonImage) map.set(row.venueId, row.lessonImage);
1450
+ }
1451
+ } catch {
1452
+ }
1453
+ return map;
1454
+ }
1440
1455
  async function fetchFromProviderProxy(method, ministryId, providerId, path, authData, resolution) {
1441
1456
  try {
1442
1457
  const url = `${API_BASE3}/doing/providerProxy/${method}`;
@@ -1475,8 +1490,8 @@ function ministryToFolder(ministry) {
1475
1490
  function planTypeToFolder(planType) {
1476
1491
  return { type: "folder", id: planType.id, title: planType.name, path: "" };
1477
1492
  }
1478
- function planToFolder(plan) {
1479
- return { type: "folder", id: plan.id, title: plan.name, path: "", isLeaf: true };
1493
+ function planToFolder(plan, thumbnail) {
1494
+ return { type: "folder", id: plan.id, title: plan.name, path: "", isLeaf: true, thumbnail };
1480
1495
  }
1481
1496
  function getFilesFromVenueFeed(venueFeed, itemType, relatedId) {
1482
1497
  const files = [];
@@ -1672,9 +1687,15 @@ var B1ChurchProvider = class {
1672
1687
  if (depth === 3) {
1673
1688
  const ministryId = segments[1];
1674
1689
  const planTypeId = segments[2];
1675
- const plans = await fetchPlans(planTypeId, authData);
1690
+ const allPlans = await fetchPlans(planTypeId, authData);
1691
+ const yesterday = /* @__PURE__ */ new Date();
1692
+ yesterday.setDate(yesterday.getDate() - 1);
1693
+ yesterday.setHours(0, 0, 0, 0);
1694
+ const plans = allPlans.filter((p) => new Date(p.serviceDate).getTime() >= yesterday.getTime());
1695
+ plans.sort((a, b) => new Date(a.serviceDate).getTime() - new Date(b.serviceDate).getTime());
1696
+ const imageMap = await this.fetchPlanImages(plans, ministryId, authData);
1676
1697
  return plans.map((p) => {
1677
- const folder = planToFolder(p);
1698
+ const folder = planToFolder(p, imageMap.get(p.id));
1678
1699
  return {
1679
1700
  ...folder,
1680
1701
  isLeaf: true,
@@ -1684,6 +1705,43 @@ var B1ChurchProvider = class {
1684
1705
  }
1685
1706
  return [];
1686
1707
  }
1708
+ async fetchPlanImages(plans, ministryId, authData) {
1709
+ const imageMap = /* @__PURE__ */ new Map();
1710
+ console.log(`[B1Church] fetchPlanImages: ${plans.length} plans, fields:`, plans.map((p) => ({ id: p.id, contentId: p.contentId, providerId: p.providerId, providerPlanId: p.providerPlanId })));
1711
+ const lessonsChurchPlans = plans.filter((p) => p.contentId && (!p.providerId || p.providerId === "lessonschurch"));
1712
+ const venueIds = lessonsChurchPlans.map((p) => p.contentId);
1713
+ console.log(`[B1Church] fetchPlanImages: ${lessonsChurchPlans.length} lessons.church plans, venueIds=${JSON.stringify(venueIds)}`);
1714
+ if (venueIds.length > 0) {
1715
+ const lcImages = await fetchVenueImages(venueIds);
1716
+ console.log(`[B1Church] fetchPlanImages: fetchVenueImages returned ${lcImages.size} images`);
1717
+ lcImages.forEach((img, venueId) => {
1718
+ const plan = lessonsChurchPlans.find((p) => p.contentId === venueId);
1719
+ if (plan) imageMap.set(plan.id, img);
1720
+ });
1721
+ }
1722
+ const externalPlans = plans.filter((p) => p.providerId && p.providerId !== "lessonschurch" && p.providerId !== "b1church" && p.providerPlanId);
1723
+ if (externalPlans.length > 0) {
1724
+ const groupKey = (p) => `${p.providerId}::${p.providerPlanId.split("/").slice(0, -1).join("/")}`;
1725
+ const groups = /* @__PURE__ */ new Map();
1726
+ for (const p of externalPlans) {
1727
+ const key = groupKey(p);
1728
+ if (!groups.has(key)) groups.set(key, []);
1729
+ groups.get(key).push(p);
1730
+ }
1731
+ await Promise.all(Array.from(groups.entries()).map(async ([key, groupPlans]) => {
1732
+ const [providerId, parentPath] = [key.split("::")[0], key.split("::").slice(1).join("::")];
1733
+ const items = await fetchFromProviderProxy("browse", ministryId, providerId, parentPath, authData);
1734
+ if (Array.isArray(items)) {
1735
+ for (const plan of groupPlans) {
1736
+ const leafId = plan.providerPlanId.split("/").pop();
1737
+ const match = items.find((item) => item.id === leafId || item.id === plan.contentId);
1738
+ if (match?.thumbnail) imageMap.set(plan.id, match.thumbnail);
1739
+ }
1740
+ }
1741
+ }));
1742
+ }
1743
+ return imageMap;
1744
+ }
1687
1745
  // async getPresentations(path: string, authData?: ContentProviderAuthData | null): Promise<Plan | null> {
1688
1746
  // const { segments, depth } = parsePath(path);
1689
1747
  // if (depth < 4 || segments[0] !== "ministries") return null;