@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.js CHANGED
@@ -21549,6 +21549,125 @@ var GoogleDriveProvider = class extends BaseProvider {
21549
21549
  }
21550
21550
  };
21551
21551
 
21552
+ // src/providers/onedrive/OneDriveProvider.ts
21553
+ var API_BASE6 = "https://graph.microsoft.com/v1.0";
21554
+ var MAX_PAGINATION_CALLS3 = 10;
21555
+ var OneDriveProvider = class extends BaseProvider {
21556
+ constructor() {
21557
+ super(...arguments);
21558
+ this.oauthHelper = new OAuthHelper();
21559
+ this.id = "onedrive";
21560
+ this.name = "OneDrive";
21561
+ this.logos = {
21562
+ light: "https://res-1.cdn.office.net/files/fabric-cdn-prod_20230815.002/assets/brand-icons/product/png/onedrive_48x1.png",
21563
+ dark: "https://res-1.cdn.office.net/files/fabric-cdn-prod_20230815.002/assets/brand-icons/product/png/onedrive_48x1.png"
21564
+ };
21565
+ this.config = {
21566
+ id: "onedrive",
21567
+ name: "OneDrive",
21568
+ apiBase: API_BASE6,
21569
+ oauthBase: "https://login.microsoftonline.com/common/oauth2/v2.0",
21570
+ // Azure "FreePlay" registration; relay callbacks are registered as mobile/desktop (public client), so no secret is normally set
21571
+ clientId: "49a15ab2-868f-4612-8b03-c1c7fae485f1",
21572
+ get clientSecret() {
21573
+ return getProviderSecret("onedrive");
21574
+ },
21575
+ scopes: ["Files.Read.All", "offline_access"]
21576
+ };
21577
+ this.requiresAuth = true;
21578
+ this.authTypes = ["oauth_pkce"];
21579
+ this.capabilities = {
21580
+ browse: true,
21581
+ playlist: true,
21582
+ instructions: true,
21583
+ mediaLicensing: false
21584
+ };
21585
+ }
21586
+ // Paths are item ids ("/<id>"); personal-account ids contain "!"
21587
+ itemIdFromPath(path) {
21588
+ return (path || "").replace(/^\//, "") || "root";
21589
+ }
21590
+ isValidId(id) {
21591
+ return /^[\w!.-]+$/.test(id);
21592
+ }
21593
+ itemPath(id) {
21594
+ return id === "root" ? "/me/drive/root" : `/me/drive/items/${encodeURIComponent(id)}`;
21595
+ }
21596
+ async childItems(itemId, auth) {
21597
+ if (!auth) {
21598
+ console.error("[OneDrive] No auth token provided");
21599
+ return { folders: [], mediaFiles: [] };
21600
+ }
21601
+ const all = [];
21602
+ let path = `${this.itemPath(itemId)}/children?$top=999&$expand=thumbnails`;
21603
+ for (let i = 0; i < MAX_PAGINATION_CALLS3 && path; i++) {
21604
+ const response = await this.apiRequest(path, auth);
21605
+ if (!response) break;
21606
+ all.push(...response.value || []);
21607
+ path = response["@odata.nextLink"]?.replace(API_BASE6, "") || "";
21608
+ }
21609
+ const folders = all.filter((e) => e.folder);
21610
+ const mediaFiles = all.filter((e) => e.file && (["video/", "image/", "audio/"].some((prefix) => e.file.mimeType?.startsWith(prefix)) || isMediaFile(e.name)));
21611
+ return { folders, mediaFiles };
21612
+ }
21613
+ // Graph's pre-signed downloadUrl expires in ~1h, so hand out the stable /content URL; players resolve it with the token
21614
+ toContentFile(item) {
21615
+ const url = `${API_BASE6}/me/drive/items/${encodeURIComponent(item.id)}/content`;
21616
+ return {
21617
+ type: "file",
21618
+ id: item.id,
21619
+ title: item.name,
21620
+ mediaType: detectMediaType(item.name, item.file?.mimeType),
21621
+ thumbnail: item.thumbnails?.[0]?.medium?.url,
21622
+ url,
21623
+ downloadUrl: url
21624
+ };
21625
+ }
21626
+ async browse(path, auth) {
21627
+ const itemId = this.itemIdFromPath(path);
21628
+ if (!this.isValidId(itemId)) return [];
21629
+ const { folders, mediaFiles } = await this.childItems(itemId, auth);
21630
+ const folderItems = folders.map((f) => ({ type: "folder", id: f.id, title: f.name, path: `/${f.id}` }));
21631
+ return [...folderItems, ...mediaFiles.map((f) => this.toContentFile(f))];
21632
+ }
21633
+ async getPlaylist(path, auth, _resolution) {
21634
+ const itemId = this.itemIdFromPath(path);
21635
+ if (itemId === "root" || !this.isValidId(itemId)) return null;
21636
+ const { mediaFiles } = await this.childItems(itemId, auth);
21637
+ return mediaFiles.length > 0 ? mediaFiles.map((f) => this.toContentFile(f)) : null;
21638
+ }
21639
+ async getInstructions(path, auth) {
21640
+ const files = await this.getPlaylist(path, auth);
21641
+ if (!files) return null;
21642
+ const meta = await this.apiRequest(`${this.itemPath(this.itemIdFromPath(path))}?$select=name`, auth);
21643
+ const folderName = meta?.name || "OneDrive";
21644
+ return filesToInstructions(folderName, files, { id: "onedrive-section", label: folderName });
21645
+ }
21646
+ generateCodeVerifier() {
21647
+ return this.oauthHelper.generateCodeVerifier();
21648
+ }
21649
+ async buildAuthUrl(codeVerifier, redirectUri, state) {
21650
+ const codeChallenge = await this.oauthHelper.generateCodeChallenge(codeVerifier);
21651
+ return { url: this.buildAuthUrlFromChallenge(codeChallenge, redirectUri, state || this.id), challengeMethod: "S256" };
21652
+ }
21653
+ buildAuthUrlFromChallenge(codeChallenge, redirectUri, state) {
21654
+ const params = new URLSearchParams({
21655
+ response_type: "code",
21656
+ client_id: this.config.clientId,
21657
+ redirect_uri: redirectUri,
21658
+ scope: this.config.scopes.join(" "),
21659
+ code_challenge: codeChallenge,
21660
+ code_challenge_method: "S256",
21661
+ prompt: "select_account",
21662
+ state
21663
+ });
21664
+ return `${this.config.oauthBase}/authorize?${params.toString()}`;
21665
+ }
21666
+ async exchangeCodeForTokens(code, codeVerifier, redirectUri) {
21667
+ return this.oauthHelper.exchangeCodeForTokens(this.config, this.id, code, codeVerifier, redirectUri);
21668
+ }
21669
+ };
21670
+
21552
21671
  // src/providers/index.ts
21553
21672
  var unimplementedProviders = [
21554
21673
  {
@@ -21583,6 +21702,7 @@ function initializeProviders() {
21583
21702
  new DropboxProvider(),
21584
21703
  new GoCurriculumProvider(),
21585
21704
  new GoogleDriveProvider(),
21705
+ new OneDriveProvider(),
21586
21706
  new BibleProjectProvider(),
21587
21707
  new HighVoltageKidsProvider(),
21588
21708
  new JesusFilmProvider(),
@@ -21628,7 +21748,7 @@ function getAvailableProviders(ids) {
21628
21748
  }
21629
21749
 
21630
21750
  // src/index.ts
21631
- var VERSION = true ? "0.12.0" : "dev";
21751
+ var VERSION = true ? "0.13.0" : "dev";
21632
21752
  export {
21633
21753
  APlayProvider,
21634
21754
  B1ChurchProvider,