@churchapps/content-providers 0.14.0 → 0.15.0

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
@@ -12801,6 +12801,30 @@ var GROUPS = [
12801
12801
  { id: "preschool", name: "Preschool" }
12802
12802
  ];
12803
12803
  var CATALOG_TTL_MS = 60 * 60 * 1e3;
12804
+ var SMALL_GROUP = "small-group";
12805
+ function guideAction(item, id, lesson) {
12806
+ const plain = (item.content || "").replace(/\*+/g, "").trim();
12807
+ const label = plain.length > 100 ? plain.slice(0, 100).trimEnd() + "\u2026" : plain;
12808
+ const files = (item.files || []).map((f) => ({
12809
+ id: slugify(f.file),
12810
+ itemType: "file",
12811
+ label: lesson.playlist.find((p) => p.url === f.url)?.title || f.file,
12812
+ seconds: f.seconds,
12813
+ downloadUrl: f.url,
12814
+ mediaType: detectMediaType(`${f.url} ${f.file}`, f.mediaType),
12815
+ thumbnail: f.thumbnail || lesson.thumbnail
12816
+ }));
12817
+ return { id, itemType: "action", actionType: item.type, label, content: item.content !== label ? item.content : void 0, seconds: files[0]?.seconds, children: files.length ? files : void 0 };
12818
+ }
12819
+ function guideToInstructions(name, guide, prefix, lesson) {
12820
+ const items = guide.sections.map((s, i) => ({
12821
+ id: `${prefix}-${i}`,
12822
+ itemType: "section",
12823
+ label: s.name,
12824
+ children: s.items.map((a, j) => guideAction(a, `${prefix}-${i}-${j}`, lesson))
12825
+ }));
12826
+ return { name, items };
12827
+ }
12804
12828
  async function loadFromFeed(groupId) {
12805
12829
  let url;
12806
12830
  try {
@@ -12888,7 +12912,12 @@ var GoCurriculumProvider = class extends BaseProvider {
12888
12912
  if (depth === 1) return ((await this.getData(segments[0], auth))?.catalog || []).map((c) => createFolder(c.id, c.name, `/${segments[0]}/${c.id}`, c.thumbnail));
12889
12913
  const collection = await this.getCollection(segments, auth);
12890
12914
  if (!collection) return [];
12891
- if (depth === 2) return collection.lessons.map((l) => createFolder(l.id, l.name, `/${segments[0]}/${collection.id}/${l.id}`, l.thumbnail || collection.thumbnail, true));
12915
+ const base = `/${segments[0]}/${collection.id}`;
12916
+ if (depth === 2) {
12917
+ const lessons = collection.lessons.map((l) => createFolder(l.id, l.name, `${base}/${l.id}`, l.thumbnail || collection.thumbnail, true));
12918
+ return collection.lessons.some((l) => l.smallGroup) ? [createFolder(SMALL_GROUP, "Small Group Guides", `${base}/${SMALL_GROUP}`, collection.thumbnail), ...lessons] : lessons;
12919
+ }
12920
+ if (depth === 3 && segments[2] === SMALL_GROUP) return collection.lessons.filter((l) => l.smallGroup).map((l) => createFolder(l.id, l.name, `${base}/${SMALL_GROUP}/${l.id}`, l.thumbnail || collection.thumbnail, true));
12892
12921
  if (depth === 3) return this.getLessonFiles(collection, segments[2]);
12893
12922
  return [];
12894
12923
  }
@@ -12907,14 +12936,25 @@ var GoCurriculumProvider = class extends BaseProvider {
12907
12936
  return files.length > 0 ? files : null;
12908
12937
  }
12909
12938
  async getInstructions(path, auth) {
12939
+ if (!auth || !await this.verifyAuth(auth)) return null;
12910
12940
  const { segments, depth } = parsePath(path);
12911
- if (depth !== 3) return null;
12912
- const files = await this.getPlaylist(path, auth);
12913
- if (!files || !auth) return null;
12941
+ const smallGroup = depth === 4 && segments[2] === SMALL_GROUP;
12942
+ if (depth !== 3 && !smallGroup) return null;
12914
12943
  const collection = await this.getCollection(segments, auth);
12915
- const lesson = collection?.lessons.find((l) => l.id === segments[2]);
12916
- const instructions = filesToInstructions(lesson?.name || "Lesson", files);
12917
- const downloads = (lesson?.resources || []).filter((r) => r.url && !isPlaylistMedia(r.url, void 0, r.file)).map((r) => ({ id: slugify(r.file || r.title), title: r.title || r.file, url: r.url }));
12944
+ const lesson = collection?.lessons.find((l) => l.id === segments[depth - 1]);
12945
+ if (!collection || !lesson) return null;
12946
+ let instructions;
12947
+ if (smallGroup) {
12948
+ if (!lesson.smallGroup?.sections?.length) return null;
12949
+ instructions = guideToInstructions(`${lesson.name} - Small Group`, lesson.smallGroup, "sg", lesson);
12950
+ } else if (lesson.script?.sections?.length) {
12951
+ instructions = guideToInstructions(lesson.name, lesson.script, "lg", lesson);
12952
+ } else {
12953
+ const files = this.getLessonFiles(collection, lesson.id);
12954
+ if (files.length === 0) return null;
12955
+ instructions = filesToInstructions(lesson.name, files);
12956
+ }
12957
+ const downloads = (lesson.resources || []).filter((r) => r.url && !isPlaylistMedia(r.url, void 0, r.file)).map((r) => ({ id: slugify(r.file || r.title), title: r.title || r.file, url: r.url }));
12918
12958
  if (downloads.length > 0) instructions.downloads = downloads;
12919
12959
  return instructions;
12920
12960
  }
@@ -17083,7 +17123,7 @@ function getAvailableProviders(ids) {
17083
17123
  }
17084
17124
 
17085
17125
  // src/index.ts
17086
- var VERSION = true ? "0.14.0" : "dev";
17126
+ var VERSION = true ? "0.15.0" : "dev";
17087
17127
  // Annotate the CommonJS export names for ESM import in node:
17088
17128
  0 && (module.exports = {
17089
17129
  APlayProvider,