@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 +57 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +57 -3
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
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 = [];
|
|
@@ -1673,8 +1688,10 @@ var B1ChurchProvider = class {
|
|
|
1673
1688
|
const ministryId = segments[1];
|
|
1674
1689
|
const planTypeId = segments[2];
|
|
1675
1690
|
const plans = await fetchPlans(planTypeId, authData);
|
|
1691
|
+
plans.sort((a, b) => new Date(a.serviceDate).getTime() - new Date(b.serviceDate).getTime());
|
|
1692
|
+
const imageMap = await this.fetchPlanImages(plans, ministryId, authData);
|
|
1676
1693
|
return plans.map((p) => {
|
|
1677
|
-
const folder = planToFolder(p);
|
|
1694
|
+
const folder = planToFolder(p, imageMap.get(p.id));
|
|
1678
1695
|
return {
|
|
1679
1696
|
...folder,
|
|
1680
1697
|
isLeaf: true,
|
|
@@ -1684,6 +1701,43 @@ var B1ChurchProvider = class {
|
|
|
1684
1701
|
}
|
|
1685
1702
|
return [];
|
|
1686
1703
|
}
|
|
1704
|
+
async fetchPlanImages(plans, ministryId, authData) {
|
|
1705
|
+
const imageMap = /* @__PURE__ */ new Map();
|
|
1706
|
+
console.log(`[B1Church] fetchPlanImages: ${plans.length} plans, fields:`, plans.map((p) => ({ id: p.id, contentId: p.contentId, providerId: p.providerId, providerPlanId: p.providerPlanId })));
|
|
1707
|
+
const lessonsChurchPlans = plans.filter((p) => p.contentId && (!p.providerId || p.providerId === "lessonschurch"));
|
|
1708
|
+
const venueIds = lessonsChurchPlans.map((p) => p.contentId);
|
|
1709
|
+
console.log(`[B1Church] fetchPlanImages: ${lessonsChurchPlans.length} lessons.church plans, venueIds=${JSON.stringify(venueIds)}`);
|
|
1710
|
+
if (venueIds.length > 0) {
|
|
1711
|
+
const lcImages = await fetchVenueImages(venueIds);
|
|
1712
|
+
console.log(`[B1Church] fetchPlanImages: fetchVenueImages returned ${lcImages.size} images`);
|
|
1713
|
+
lcImages.forEach((img, venueId) => {
|
|
1714
|
+
const plan = lessonsChurchPlans.find((p) => p.contentId === venueId);
|
|
1715
|
+
if (plan) imageMap.set(plan.id, img);
|
|
1716
|
+
});
|
|
1717
|
+
}
|
|
1718
|
+
const externalPlans = plans.filter((p) => p.providerId && p.providerId !== "lessonschurch" && p.providerId !== "b1church" && p.providerPlanId);
|
|
1719
|
+
if (externalPlans.length > 0) {
|
|
1720
|
+
const groupKey = (p) => `${p.providerId}::${p.providerPlanId.split("/").slice(0, -1).join("/")}`;
|
|
1721
|
+
const groups = /* @__PURE__ */ new Map();
|
|
1722
|
+
for (const p of externalPlans) {
|
|
1723
|
+
const key = groupKey(p);
|
|
1724
|
+
if (!groups.has(key)) groups.set(key, []);
|
|
1725
|
+
groups.get(key).push(p);
|
|
1726
|
+
}
|
|
1727
|
+
await Promise.all(Array.from(groups.entries()).map(async ([key, groupPlans]) => {
|
|
1728
|
+
const [providerId, parentPath] = [key.split("::")[0], key.split("::").slice(1).join("::")];
|
|
1729
|
+
const items = await fetchFromProviderProxy("browse", ministryId, providerId, parentPath, authData);
|
|
1730
|
+
if (Array.isArray(items)) {
|
|
1731
|
+
for (const plan of groupPlans) {
|
|
1732
|
+
const leafId = plan.providerPlanId.split("/").pop();
|
|
1733
|
+
const match = items.find((item) => item.id === leafId || item.id === plan.contentId);
|
|
1734
|
+
if (match?.thumbnail) imageMap.set(plan.id, match.thumbnail);
|
|
1735
|
+
}
|
|
1736
|
+
}
|
|
1737
|
+
}));
|
|
1738
|
+
}
|
|
1739
|
+
return imageMap;
|
|
1740
|
+
}
|
|
1687
1741
|
// async getPresentations(path: string, authData?: ContentProviderAuthData | null): Promise<Plan | null> {
|
|
1688
1742
|
// const { segments, depth } = parsePath(path);
|
|
1689
1743
|
// if (depth < 4 || segments[0] !== "ministries") return null;
|