@churchapps/content-providers 0.7.1 → 0.7.2

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.js CHANGED
@@ -1659,6 +1659,9 @@ function filterMediaEntries(entries) {
1659
1659
  if (entry[".tag"] === "folder") folders.push(entry);
1660
1660
  else if (entry[".tag"] === "file" && isMediaFile(entry.name)) mediaFiles.push(entry);
1661
1661
  }
1662
+ const byName = (a, b) => a.name.localeCompare(b.name, void 0, { numeric: true, sensitivity: "base" });
1663
+ folders.sort(byName);
1664
+ mediaFiles.sort(byName);
1662
1665
  return { folders, mediaFiles };
1663
1666
  }
1664
1667
 
@@ -17596,6 +17599,8 @@ var data_default4 = {
17596
17599
  };
17597
17600
 
17598
17601
  // src/providers/goCurriculum/GoCurriculumProvider.ts
17602
+ var CATALOG_URL = "https://dl.dropboxusercontent.com/scl/fi/kb3qlgspv92x8m3mk5s8d/data.json?rlkey=z13qq7aghyszv2w1yud2obtqm";
17603
+ var CATALOG_TTL_MS = 60 * 60 * 1e3;
17599
17604
  var GoCurriculumProvider = class extends BaseProvider {
17600
17605
  constructor() {
17601
17606
  super(...arguments);
@@ -17620,10 +17625,21 @@ var GoCurriculumProvider = class extends BaseProvider {
17620
17625
  scopes: ["basic"]
17621
17626
  };
17622
17627
  this.data = data_default4;
17628
+ this.dataFetchedAt = 0;
17623
17629
  this.requiresAuth = true;
17624
17630
  this.authTypes = ["oauth_pkce"];
17625
17631
  this.capabilities = { browse: true, playlist: true, instructions: true, mediaLicensing: false };
17626
17632
  }
17633
+ async getData() {
17634
+ if (Date.now() - this.dataFetchedAt < CATALOG_TTL_MS) return this.data;
17635
+ try {
17636
+ const response = await fetch(CATALOG_URL);
17637
+ if (response.ok) this.data = await response.json();
17638
+ } catch {
17639
+ }
17640
+ this.dataFetchedAt = Date.now();
17641
+ return this.data;
17642
+ }
17627
17643
  // ponytail: any valid login unlocks everything for the pilot — per-tier (MemberPress) filtering waits on Go's membership endpoint
17628
17644
  async verifyAuth(auth) {
17629
17645
  const token = auth?.access_token;
@@ -17641,8 +17657,9 @@ var GoCurriculumProvider = class extends BaseProvider {
17641
17657
  async browse(path, auth) {
17642
17658
  if (!await this.verifyAuth(auth)) return [];
17643
17659
  const { segments, depth } = parsePath(path);
17644
- if (depth === 0) return this.data.catalog.map((c) => createFolder(c.id, c.name, `/${c.id}`, c.thumbnail));
17645
- const collection = this.data.catalog.find((c) => c.id === segments[0]);
17660
+ const data = await this.getData();
17661
+ if (depth === 0) return data.catalog.map((c) => createFolder(c.id, c.name, `/${c.id}`, c.thumbnail));
17662
+ const collection = data.catalog.find((c) => c.id === segments[0]);
17646
17663
  if (!collection) return [];
17647
17664
  if (depth === 1) return collection.lessons.map((l) => createFolder(l.id, l.name, `/${collection.id}/${l.id}`, l.thumbnail || collection.thumbnail, true));
17648
17665
  if (depth === 2) return this.getLessonFiles(collection, segments[1]);
@@ -17657,7 +17674,7 @@ var GoCurriculumProvider = class extends BaseProvider {
17657
17674
  if (!await this.verifyAuth(auth)) return null;
17658
17675
  const { segments, depth } = parsePath(path);
17659
17676
  if (depth !== 2) return null;
17660
- const collection = this.data.catalog.find((c) => c.id === segments[0]);
17677
+ const collection = (await this.getData()).catalog.find((c) => c.id === segments[0]);
17661
17678
  if (!collection) return null;
17662
17679
  const files = this.getLessonFiles(collection, segments[1]);
17663
17680
  return files.length > 0 ? files : null;
@@ -17667,7 +17684,7 @@ var GoCurriculumProvider = class extends BaseProvider {
17667
17684
  if (depth !== 2) return null;
17668
17685
  const files = await this.getPlaylist(path, auth);
17669
17686
  if (!files) return null;
17670
- const collection = this.data.catalog.find((c) => c.id === segments[0]);
17687
+ const collection = (await this.getData()).catalog.find((c) => c.id === segments[0]);
17671
17688
  const lesson = collection?.lessons.find((l) => l.id === segments[1]);
17672
17689
  return filesToInstructions(lesson?.name || "Lesson", files);
17673
17690
  }
@@ -17770,7 +17787,7 @@ function getAvailableProviders(ids) {
17770
17787
  }
17771
17788
 
17772
17789
  // src/index.ts
17773
- var VERSION = true ? "0.7.1" : "dev";
17790
+ var VERSION = true ? "0.7.2" : "dev";
17774
17791
  export {
17775
17792
  APlayProvider,
17776
17793
  B1ChurchProvider,