@churchapps/content-providers 0.12.0 → 0.13.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
@@ -21606,6 +21606,125 @@ var GoogleDriveProvider = class extends BaseProvider {
21606
21606
  }
21607
21607
  };
21608
21608
 
21609
+ // src/providers/onedrive/OneDriveProvider.ts
21610
+ var API_BASE6 = "https://graph.microsoft.com/v1.0";
21611
+ var MAX_PAGINATION_CALLS3 = 10;
21612
+ var OneDriveProvider = class extends BaseProvider {
21613
+ constructor() {
21614
+ super(...arguments);
21615
+ this.oauthHelper = new OAuthHelper();
21616
+ this.id = "onedrive";
21617
+ this.name = "OneDrive";
21618
+ this.logos = {
21619
+ light: "https://res-1.cdn.office.net/files/fabric-cdn-prod_20230815.002/assets/brand-icons/product/png/onedrive_48x1.png",
21620
+ dark: "https://res-1.cdn.office.net/files/fabric-cdn-prod_20230815.002/assets/brand-icons/product/png/onedrive_48x1.png"
21621
+ };
21622
+ this.config = {
21623
+ id: "onedrive",
21624
+ name: "OneDrive",
21625
+ apiBase: API_BASE6,
21626
+ oauthBase: "https://login.microsoftonline.com/common/oauth2/v2.0",
21627
+ // Azure "FreePlay" registration; relay callbacks are registered as mobile/desktop (public client), so no secret is normally set
21628
+ clientId: "49a15ab2-868f-4612-8b03-c1c7fae485f1",
21629
+ get clientSecret() {
21630
+ return getProviderSecret("onedrive");
21631
+ },
21632
+ scopes: ["Files.Read.All", "offline_access"]
21633
+ };
21634
+ this.requiresAuth = true;
21635
+ this.authTypes = ["oauth_pkce"];
21636
+ this.capabilities = {
21637
+ browse: true,
21638
+ playlist: true,
21639
+ instructions: true,
21640
+ mediaLicensing: false
21641
+ };
21642
+ }
21643
+ // Paths are item ids ("/<id>"); personal-account ids contain "!"
21644
+ itemIdFromPath(path) {
21645
+ return (path || "").replace(/^\//, "") || "root";
21646
+ }
21647
+ isValidId(id) {
21648
+ return /^[\w!.-]+$/.test(id);
21649
+ }
21650
+ itemPath(id) {
21651
+ return id === "root" ? "/me/drive/root" : `/me/drive/items/${encodeURIComponent(id)}`;
21652
+ }
21653
+ async childItems(itemId, auth) {
21654
+ if (!auth) {
21655
+ console.error("[OneDrive] No auth token provided");
21656
+ return { folders: [], mediaFiles: [] };
21657
+ }
21658
+ const all = [];
21659
+ let path = `${this.itemPath(itemId)}/children?$top=999&$expand=thumbnails`;
21660
+ for (let i = 0; i < MAX_PAGINATION_CALLS3 && path; i++) {
21661
+ const response = await this.apiRequest(path, auth);
21662
+ if (!response) break;
21663
+ all.push(...response.value || []);
21664
+ path = response["@odata.nextLink"]?.replace(API_BASE6, "") || "";
21665
+ }
21666
+ const folders = all.filter((e) => e.folder);
21667
+ const mediaFiles = all.filter((e) => e.file && (["video/", "image/", "audio/"].some((prefix) => e.file.mimeType?.startsWith(prefix)) || isMediaFile(e.name)));
21668
+ return { folders, mediaFiles };
21669
+ }
21670
+ // Graph's pre-signed downloadUrl expires in ~1h, so hand out the stable /content URL; players resolve it with the token
21671
+ toContentFile(item) {
21672
+ const url = `${API_BASE6}/me/drive/items/${encodeURIComponent(item.id)}/content`;
21673
+ return {
21674
+ type: "file",
21675
+ id: item.id,
21676
+ title: item.name,
21677
+ mediaType: detectMediaType(item.name, item.file?.mimeType),
21678
+ thumbnail: item.thumbnails?.[0]?.medium?.url,
21679
+ url,
21680
+ downloadUrl: url
21681
+ };
21682
+ }
21683
+ async browse(path, auth) {
21684
+ const itemId = this.itemIdFromPath(path);
21685
+ if (!this.isValidId(itemId)) return [];
21686
+ const { folders, mediaFiles } = await this.childItems(itemId, auth);
21687
+ const folderItems = folders.map((f) => ({ type: "folder", id: f.id, title: f.name, path: `/${f.id}` }));
21688
+ return [...folderItems, ...mediaFiles.map((f) => this.toContentFile(f))];
21689
+ }
21690
+ async getPlaylist(path, auth, _resolution) {
21691
+ const itemId = this.itemIdFromPath(path);
21692
+ if (itemId === "root" || !this.isValidId(itemId)) return null;
21693
+ const { mediaFiles } = await this.childItems(itemId, auth);
21694
+ return mediaFiles.length > 0 ? mediaFiles.map((f) => this.toContentFile(f)) : null;
21695
+ }
21696
+ async getInstructions(path, auth) {
21697
+ const files = await this.getPlaylist(path, auth);
21698
+ if (!files) return null;
21699
+ const meta = await this.apiRequest(`${this.itemPath(this.itemIdFromPath(path))}?$select=name`, auth);
21700
+ const folderName = meta?.name || "OneDrive";
21701
+ return filesToInstructions(folderName, files, { id: "onedrive-section", label: folderName });
21702
+ }
21703
+ generateCodeVerifier() {
21704
+ return this.oauthHelper.generateCodeVerifier();
21705
+ }
21706
+ async buildAuthUrl(codeVerifier, redirectUri, state) {
21707
+ const codeChallenge = await this.oauthHelper.generateCodeChallenge(codeVerifier);
21708
+ return { url: this.buildAuthUrlFromChallenge(codeChallenge, redirectUri, state || this.id), challengeMethod: "S256" };
21709
+ }
21710
+ buildAuthUrlFromChallenge(codeChallenge, redirectUri, state) {
21711
+ const params = new URLSearchParams({
21712
+ response_type: "code",
21713
+ client_id: this.config.clientId,
21714
+ redirect_uri: redirectUri,
21715
+ scope: this.config.scopes.join(" "),
21716
+ code_challenge: codeChallenge,
21717
+ code_challenge_method: "S256",
21718
+ prompt: "select_account",
21719
+ state
21720
+ });
21721
+ return `${this.config.oauthBase}/authorize?${params.toString()}`;
21722
+ }
21723
+ async exchangeCodeForTokens(code, codeVerifier, redirectUri) {
21724
+ return this.oauthHelper.exchangeCodeForTokens(this.config, this.id, code, codeVerifier, redirectUri);
21725
+ }
21726
+ };
21727
+
21609
21728
  // src/providers/index.ts
21610
21729
  var unimplementedProviders = [
21611
21730
  {
@@ -21640,6 +21759,7 @@ function initializeProviders() {
21640
21759
  new DropboxProvider(),
21641
21760
  new GoCurriculumProvider(),
21642
21761
  new GoogleDriveProvider(),
21762
+ new OneDriveProvider(),
21643
21763
  new BibleProjectProvider(),
21644
21764
  new HighVoltageKidsProvider(),
21645
21765
  new JesusFilmProvider(),
@@ -21685,7 +21805,7 @@ function getAvailableProviders(ids) {
21685
21805
  }
21686
21806
 
21687
21807
  // src/index.ts
21688
- var VERSION = true ? "0.12.0" : "dev";
21808
+ var VERSION = true ? "0.13.0" : "dev";
21689
21809
  // Annotate the CommonJS export names for ESM import in node:
21690
21810
  0 && (module.exports = {
21691
21811
  APlayProvider,