@youversion/platform-core 0.5.8 → 0.7.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.d.cts CHANGED
@@ -194,12 +194,28 @@ declare const SignInWithYouVersionPermission: {
194
194
  readonly demographics: "demographics";
195
195
  readonly bibleActivity: "bible_activity";
196
196
  };
197
+ type SignInWithYouVersionResultProps = {
198
+ accessToken?: string;
199
+ expiresIn?: number;
200
+ refreshToken?: string;
201
+ idToken?: string;
202
+ permissions?: SignInWithYouVersionPermissionValues[];
203
+ yvpUserId?: string;
204
+ name?: string;
205
+ profilePicture?: string;
206
+ email?: string;
207
+ };
197
208
  declare class SignInWithYouVersionResult {
198
- readonly accessToken: string | null;
199
- readonly permissions: SignInWithYouVersionPermissionValues[];
200
- readonly errorMsg: string | null;
201
- readonly yvpUserId: string | null;
202
- constructor(url: URL);
209
+ readonly accessToken: string | undefined;
210
+ readonly expiryDate: Date | undefined;
211
+ readonly refreshToken: string | undefined;
212
+ readonly idToken: string | undefined;
213
+ readonly permissions: SignInWithYouVersionPermissionValues[] | undefined;
214
+ readonly yvpUserId: string | undefined;
215
+ readonly name: string | undefined;
216
+ readonly profilePicture: string | undefined;
217
+ readonly email: string | undefined;
218
+ constructor({ accessToken, expiresIn, refreshToken, idToken, permissions, yvpUserId, name, profilePicture, email, }: SignInWithYouVersionResultProps);
203
219
  }
204
220
 
205
221
  type SignInWithYouVersionPermissionValues = (typeof SignInWithYouVersionPermission)[keyof typeof SignInWithYouVersionPermission];
@@ -207,6 +223,7 @@ interface AuthenticationState {
207
223
  isAuthenticated: boolean;
208
224
  isLoading: boolean;
209
225
  accessToken: string | null;
226
+ idToken: string | null;
210
227
  result: SignInWithYouVersionResult | null;
211
228
  error: Error | null;
212
229
  }
@@ -502,78 +519,6 @@ declare class HighlightsClient {
502
519
  deleteHighlight(passageId: string, options?: DeleteHighlightOptions, lat?: string): Promise<void>;
503
520
  }
504
521
 
505
- /**
506
- * Client for authentication-related API calls.
507
- */
508
- declare class AuthClient {
509
- private client;
510
- /**
511
- * Creates an instance of AuthClient.
512
- * @param client - The ApiClient instance to use for requests.
513
- */
514
- constructor(client: ApiClient);
515
- /**
516
- * Retrieves the current authenticated user.
517
- *
518
- * @param lat - The long access token (LAT) used for authentication.
519
- * @returns A promise that resolves to the authenticated User.
520
- */
521
- getUser(lat: string): Promise<User>;
522
- }
523
-
524
- /**
525
- * Platform-agnostic authentication strategy interface
526
- *
527
- * Implementations should handle platform-specific authentication flows
528
- * and return the callback URL containing the authentication result.
529
- */
530
- interface AuthenticationStrategy {
531
- /**
532
- * Opens the authentication flow and returns the callback URL
533
- *
534
- * @param authUrl - The YouVersion authorization URL to open
535
- * @returns Promise that resolves to the callback URL with auth result
536
- * @throws Error if authentication fails or is cancelled
537
- */
538
- authenticate(authUrl: URL): Promise<URL>;
539
- }
540
- /**
541
- * Registry for platform-specific authentication strategies
542
- *
543
- * This singleton registry manages the current authentication strategy
544
- * and ensures only one strategy is active at a time.
545
- */
546
- declare class AuthenticationStrategyRegistry {
547
- private static strategy;
548
- /**
549
- * Registers a platform-specific authentication strategy
550
- *
551
- * @param strategy - The authentication strategy to register
552
- * @throws Error if strategy is null, undefined, or missing required methods
553
- */
554
- static register(strategy: AuthenticationStrategy): void;
555
- /**
556
- * Gets the currently registered authentication strategy
557
- *
558
- * @returns The registered authentication strategy
559
- * @throws Error if no strategy has been registered
560
- */
561
- static get(): AuthenticationStrategy;
562
- /**
563
- * Checks if a strategy is currently registered
564
- *
565
- * @returns true if a strategy is registered, false otherwise
566
- */
567
- static isRegistered(): boolean;
568
- /**
569
- * Resets the registry by removing the current strategy
570
- *
571
- * This method is primarily intended for testing scenarios
572
- * where you need to clean up between test cases.
573
- */
574
- static reset(): void;
575
- }
576
-
577
522
  /**
578
523
  * Abstract storage strategy for auth-related data (callbacks, return URLs).
579
524
  * Implementations can use different mechanisms (sessionStorage, memory, etc.)
@@ -618,46 +563,16 @@ declare class MemoryStorageStrategy implements StorageStrategy {
618
563
  clear(): void;
619
564
  }
620
565
 
621
- declare class WebAuthenticationStrategy implements AuthenticationStrategy {
622
- private redirectUri;
623
- private callbackPath;
624
- private timeout;
625
- private storage;
626
- private static pendingAuthResolve;
627
- private static pendingAuthReject;
628
- private static timeoutId;
629
- constructor(options?: {
630
- redirectUri?: string;
631
- callbackPath?: string;
632
- timeout?: number;
633
- storage?: StorageStrategy;
634
- });
635
- authenticate(authUrl: URL): Promise<URL>;
636
- /**
637
- * Call this method when your app loads to handle the redirect callback
638
- */
639
- static handleCallback(callbackPath?: string): boolean;
640
- /**
641
- * Clean up pending authentication state
642
- */
643
- static cleanup(): void;
644
- /**
645
- * Retrieve stored callback result if available
646
- */
647
- static getStoredCallback(): URL | null;
648
- private authenticateWithRedirect;
649
- }
650
-
651
566
  interface YouVersionUserInfoJSON {
652
- first_name?: string;
653
- last_name?: string;
567
+ name?: string;
654
568
  id?: string;
655
569
  avatar_url?: string;
570
+ email?: string;
656
571
  }
657
572
  declare class YouVersionUserInfo {
658
- readonly firstName?: string;
659
- readonly lastName?: string;
573
+ readonly name?: string;
660
574
  readonly userId?: string;
575
+ readonly email?: string;
661
576
  readonly avatarUrlFormat?: string;
662
577
  constructor(data: YouVersionUserInfoJSON);
663
578
  getAvatarUrl(width?: number, height?: number): URL | null;
@@ -669,26 +584,74 @@ declare class YouVersionAPIUsers {
669
584
  * Presents the YouVersion login flow to the user and returns the login result upon completion.
670
585
  *
671
586
  * This function authenticates the user with YouVersion, requesting the specified required and optional permissions.
672
- * The function returns a promise that resolves when the user completes or cancels the login flow,
673
- * returning the login result containing the authorization code and granted permissions.
587
+ * The function redirects to the YouVersion authorization URL and expects the callback to be handled separately.
674
588
  *
675
- * @param requiredPermissions - The set of permissions that must be granted by the user for successful login.
676
- * @param optionalPermissions - The set of permissions that will be requested from the user but are not required for successful login.
677
- * @returns A Promise resolving to a SignInWithYouVersionResult containing the authorization code and granted permissions upon successful login.
678
- * @throws An error if authentication fails or is cancelled by the user.
589
+ * @param permissions - The set of permissions that must be granted by the user for successful login.
590
+ * @param redirectURL - The URL to redirect back to after authentication.
591
+ * @throws An error if authentication fails or configuration is invalid.
679
592
  */
680
- static signIn(requiredPermissions: Set<SignInWithYouVersionPermissionValues>, optionalPermissions: Set<SignInWithYouVersionPermissionValues>): Promise<SignInWithYouVersionResult>;
593
+ static signIn(permissions: Set<SignInWithYouVersionPermissionValues>, redirectURL: string): Promise<void>;
594
+ /**
595
+ * Handles the OAuth callback after user authentication.
596
+ *
597
+ * Call this method when your app loads to check if the current URL contains
598
+ * an OAuth callback with authorization code. If found, it exchanges the code
599
+ * for tokens and stores them.
600
+ *
601
+ * @returns Promise<SignInWithYouVersionResult | null> - SignInWithYouVersionResult if callback was handled, null otherwise
602
+ * @throws An error if token exchange fails
603
+ */
604
+ static handleAuthCallback(): Promise<SignInWithYouVersionResult | null>;
605
+ /**
606
+ * Redirects to the server callback endpoint to obtain authorization code
607
+ */
608
+ private static obtainLocation;
609
+ /**
610
+ * Extracts sign-in result from token response
611
+ */
612
+ private static extractSignInResult;
613
+ /**
614
+ * Decodes JWT payload for UI display purposes.
615
+ *
616
+ * Note: We intentionally do not verify the JWT signature here because:
617
+ *
618
+ * 1. YouVersion's backend verifies all tokens on API requests
619
+ * 2. This decoded data is only used for UI display
620
+ * 3. No security decisions are made based on these claims
621
+ *
622
+ * @private
623
+ */
624
+ private static decodeJWT;
681
625
  static signOut(): void;
682
626
  /**
683
- * Retrieves user information for the authenticated user using the provided access token.
627
+ * Retrieves user information for the authenticated user by decoding the provided JWT access token.
684
628
  *
685
- * This function fetches the user's profile information from the YouVersion API, decoding it into a YouVersionUserInfo model.
629
+ * This function extracts the user's profile information directly from the JWT token payload.
686
630
  *
687
- * @param accessToken - The access token obtained from the login process.
631
+ * @param accessToken - The JWT access token obtained from the login process.
688
632
  * @returns A Promise resolving to a YouVersionUserInfo object containing the user's profile information.
689
- * @throws An error if the URL is invalid, the network request fails, or the response cannot be decoded.
633
+ * @throws An error if the access token is invalid or cannot be decoded.
690
634
  */
691
- static userInfo(accessToken: string): Promise<YouVersionUserInfo>;
635
+ static userInfo(idToken: string): YouVersionUserInfo;
636
+ /**
637
+ * Refreshes the access token using the stored refresh token.
638
+ *
639
+ * @returns Promise<SignInWithYouVersionResult | null> - New tokens if refresh succeeds, null otherwise
640
+ * @throws An error if refresh fails or no refresh token is available
641
+ */
642
+ static refreshTokens(): Promise<SignInWithYouVersionResult | null>;
643
+ /**
644
+ * Checks if the current access token is expired or about to expire.
645
+ *
646
+ * @returns true if token is expired or about to expire
647
+ */
648
+ static isTokenExpired(): boolean;
649
+ /**
650
+ * Refreshes the access token if it's expired or about to expire.
651
+ *
652
+ * @returns Promise<boolean> - true if refresh was successful or not needed, false if failed
653
+ */
654
+ static refreshTokenIfNeeded(): Promise<boolean>;
692
655
  }
693
656
 
694
657
  declare class YouVersionAPI {
@@ -698,29 +661,38 @@ declare class YouVersionAPI {
698
661
  declare class URLBuilder {
699
662
  private static get baseURL();
700
663
  static authURL(appKey: string, requiredPermissions?: Set<SignInWithYouVersionPermissionValues>, optionalPermissions?: Set<SignInWithYouVersionPermissionValues>): URL;
701
- static userURL(accessToken: string): URL;
702
664
  }
703
665
 
666
+ /**
667
+ * Security Note: Tokens are stored in localStorage for persistence.
668
+ * Ensure your application follows XSS prevention best practices:
669
+ * - Sanitize user input
670
+ * - Use Content Security Policy headers
671
+ * - Avoid innerHTML with untrusted content
672
+ */
704
673
  declare class YouVersionPlatformConfiguration {
705
674
  private static _appKey;
706
675
  private static _installationId;
707
- private static _accessToken;
708
676
  private static _apiHost;
709
- private static _isPreviewMode;
710
- private static _previewUserInfo;
677
+ private static _refreshTokenKey;
678
+ private static _expiryDateKey;
711
679
  private static getOrSetInstallationId;
680
+ static saveAuthData(accessToken: string | null, refreshToken: string | null, idToken: string | null, expiryDate: Date | null): void;
681
+ static clearAuthTokens(): void;
682
+ static get accessToken(): string | null;
683
+ static get refreshToken(): string | null;
684
+ static get idToken(): string | null;
685
+ static get tokenExpiryDate(): Date | null;
712
686
  static get appKey(): string | null;
713
687
  static set appKey(value: string | null);
714
688
  static get installationId(): string;
715
689
  static set installationId(value: string | null);
716
- static setAccessToken(token: string | null): void;
717
- static get accessToken(): string | null;
718
690
  static get apiHost(): string;
719
691
  static set apiHost(value: string);
720
- static get isPreviewMode(): boolean;
721
- static set isPreviewMode(value: boolean);
722
- static get previewUserInfo(): YouVersionUserInfo | null;
723
- static set previewUserInfo(value: YouVersionUserInfo | null);
692
+ static get refreshTokenKey(): string | null;
693
+ static set refreshTokenKey(value: string);
694
+ static get expiryDateKey(): string | null;
695
+ static set expiryDateKey(value: string);
724
696
  }
725
697
 
726
698
  declare const BOOK_IDS: readonly ["GEN", "EXO", "LEV", "NUM", "DEU", "JOS", "JDG", "RUT", "1SA", "2SA", "1KI", "2KI", "1CH", "2CH", "EZR", "NEH", "EST", "JOB", "PSA", "PRO", "ECC", "SNG", "ISA", "JER", "LAM", "EZK", "DAN", "HOS", "JOL", "AMO", "OBA", "JON", "MIC", "NAM", "HAB", "ZEP", "HAG", "ZEC", "MAL", "MAT", "MRK", "LUK", "JHN", "ACT", "ROM", "1CO", "2CO", "GAL", "EPH", "PHP", "COL", "1TH", "2TH", "1TI", "2TI", "TIT", "PHM", "HEB", "JAS", "1PE", "2PE", "1JN", "2JN", "3JN", "JUD", "REV", "TOB", "JDT", "ESG", "WIS", "SIR", "BAR", "LJE", "S3Y", "SUS", "BEL", "1MA", "2MA", "3MA", "4MA", "1ES", "2ES", "MAN", "PS2", "ODA", "PSS", "3ES", "EZA", "5EZ", "6EZ", "DAG", "PS3", "2BA", "LBA", "JUB", "ENO", "1MQ", "2MQ", "3MQ", "REP", "4BA", "LAO", "LKA"];
@@ -730,4 +702,4 @@ declare const BOOK_IDS: readonly ["GEN", "EXO", "LEV", "NUM", "DEU", "JOS", "JDG
730
702
  */
731
703
  declare const BOOK_CANON: Record<BookUsfm, Canon>;
732
704
 
733
- export { ApiClient, type ApiConfig, AuthClient, type AuthenticationState, type AuthenticationStrategy, AuthenticationStrategyRegistry, BOOK_CANON, BOOK_IDS, type BibleBook, type BibleChapter, BibleClient, type BibleIndex, type BibleIndexBook, type BibleIndexChapter, type BibleIndexVerse, type BiblePassage, type BibleVerse, type BibleVersion, type CANON, type Collection, type CreateHighlight, type DeleteHighlightOptions, type GetHighlightsOptions, type GetLanguagesOptions, type Highlight, type HighlightColor, HighlightsClient, type Language, LanguagesClient, MemoryStorageStrategy, SessionStorageStrategy, SignInWithYouVersionPermission, type SignInWithYouVersionPermissionValues, SignInWithYouVersionResult, type StorageStrategy, URLBuilder, type User, type VOTD, WebAuthenticationStrategy, YouVersionAPI, YouVersionAPIUsers, YouVersionPlatformConfiguration, YouVersionUserInfo, type YouVersionUserInfoJSON };
705
+ export { ApiClient, type ApiConfig, type AuthenticationState, BOOK_CANON, BOOK_IDS, type BibleBook, type BibleChapter, BibleClient, type BibleIndex, type BibleIndexBook, type BibleIndexChapter, type BibleIndexVerse, type BiblePassage, type BibleVerse, type BibleVersion, type CANON, type Collection, type CreateHighlight, type DeleteHighlightOptions, type GetHighlightsOptions, type GetLanguagesOptions, type Highlight, type HighlightColor, HighlightsClient, type Language, LanguagesClient, MemoryStorageStrategy, SessionStorageStrategy, SignInWithYouVersionPermission, type SignInWithYouVersionPermissionValues, SignInWithYouVersionResult, type StorageStrategy, URLBuilder, type User, type VOTD, YouVersionAPI, YouVersionAPIUsers, YouVersionPlatformConfiguration, YouVersionUserInfo, type YouVersionUserInfoJSON };
package/dist/index.d.ts CHANGED
@@ -194,12 +194,28 @@ declare const SignInWithYouVersionPermission: {
194
194
  readonly demographics: "demographics";
195
195
  readonly bibleActivity: "bible_activity";
196
196
  };
197
+ type SignInWithYouVersionResultProps = {
198
+ accessToken?: string;
199
+ expiresIn?: number;
200
+ refreshToken?: string;
201
+ idToken?: string;
202
+ permissions?: SignInWithYouVersionPermissionValues[];
203
+ yvpUserId?: string;
204
+ name?: string;
205
+ profilePicture?: string;
206
+ email?: string;
207
+ };
197
208
  declare class SignInWithYouVersionResult {
198
- readonly accessToken: string | null;
199
- readonly permissions: SignInWithYouVersionPermissionValues[];
200
- readonly errorMsg: string | null;
201
- readonly yvpUserId: string | null;
202
- constructor(url: URL);
209
+ readonly accessToken: string | undefined;
210
+ readonly expiryDate: Date | undefined;
211
+ readonly refreshToken: string | undefined;
212
+ readonly idToken: string | undefined;
213
+ readonly permissions: SignInWithYouVersionPermissionValues[] | undefined;
214
+ readonly yvpUserId: string | undefined;
215
+ readonly name: string | undefined;
216
+ readonly profilePicture: string | undefined;
217
+ readonly email: string | undefined;
218
+ constructor({ accessToken, expiresIn, refreshToken, idToken, permissions, yvpUserId, name, profilePicture, email, }: SignInWithYouVersionResultProps);
203
219
  }
204
220
 
205
221
  type SignInWithYouVersionPermissionValues = (typeof SignInWithYouVersionPermission)[keyof typeof SignInWithYouVersionPermission];
@@ -207,6 +223,7 @@ interface AuthenticationState {
207
223
  isAuthenticated: boolean;
208
224
  isLoading: boolean;
209
225
  accessToken: string | null;
226
+ idToken: string | null;
210
227
  result: SignInWithYouVersionResult | null;
211
228
  error: Error | null;
212
229
  }
@@ -502,78 +519,6 @@ declare class HighlightsClient {
502
519
  deleteHighlight(passageId: string, options?: DeleteHighlightOptions, lat?: string): Promise<void>;
503
520
  }
504
521
 
505
- /**
506
- * Client for authentication-related API calls.
507
- */
508
- declare class AuthClient {
509
- private client;
510
- /**
511
- * Creates an instance of AuthClient.
512
- * @param client - The ApiClient instance to use for requests.
513
- */
514
- constructor(client: ApiClient);
515
- /**
516
- * Retrieves the current authenticated user.
517
- *
518
- * @param lat - The long access token (LAT) used for authentication.
519
- * @returns A promise that resolves to the authenticated User.
520
- */
521
- getUser(lat: string): Promise<User>;
522
- }
523
-
524
- /**
525
- * Platform-agnostic authentication strategy interface
526
- *
527
- * Implementations should handle platform-specific authentication flows
528
- * and return the callback URL containing the authentication result.
529
- */
530
- interface AuthenticationStrategy {
531
- /**
532
- * Opens the authentication flow and returns the callback URL
533
- *
534
- * @param authUrl - The YouVersion authorization URL to open
535
- * @returns Promise that resolves to the callback URL with auth result
536
- * @throws Error if authentication fails or is cancelled
537
- */
538
- authenticate(authUrl: URL): Promise<URL>;
539
- }
540
- /**
541
- * Registry for platform-specific authentication strategies
542
- *
543
- * This singleton registry manages the current authentication strategy
544
- * and ensures only one strategy is active at a time.
545
- */
546
- declare class AuthenticationStrategyRegistry {
547
- private static strategy;
548
- /**
549
- * Registers a platform-specific authentication strategy
550
- *
551
- * @param strategy - The authentication strategy to register
552
- * @throws Error if strategy is null, undefined, or missing required methods
553
- */
554
- static register(strategy: AuthenticationStrategy): void;
555
- /**
556
- * Gets the currently registered authentication strategy
557
- *
558
- * @returns The registered authentication strategy
559
- * @throws Error if no strategy has been registered
560
- */
561
- static get(): AuthenticationStrategy;
562
- /**
563
- * Checks if a strategy is currently registered
564
- *
565
- * @returns true if a strategy is registered, false otherwise
566
- */
567
- static isRegistered(): boolean;
568
- /**
569
- * Resets the registry by removing the current strategy
570
- *
571
- * This method is primarily intended for testing scenarios
572
- * where you need to clean up between test cases.
573
- */
574
- static reset(): void;
575
- }
576
-
577
522
  /**
578
523
  * Abstract storage strategy for auth-related data (callbacks, return URLs).
579
524
  * Implementations can use different mechanisms (sessionStorage, memory, etc.)
@@ -618,46 +563,16 @@ declare class MemoryStorageStrategy implements StorageStrategy {
618
563
  clear(): void;
619
564
  }
620
565
 
621
- declare class WebAuthenticationStrategy implements AuthenticationStrategy {
622
- private redirectUri;
623
- private callbackPath;
624
- private timeout;
625
- private storage;
626
- private static pendingAuthResolve;
627
- private static pendingAuthReject;
628
- private static timeoutId;
629
- constructor(options?: {
630
- redirectUri?: string;
631
- callbackPath?: string;
632
- timeout?: number;
633
- storage?: StorageStrategy;
634
- });
635
- authenticate(authUrl: URL): Promise<URL>;
636
- /**
637
- * Call this method when your app loads to handle the redirect callback
638
- */
639
- static handleCallback(callbackPath?: string): boolean;
640
- /**
641
- * Clean up pending authentication state
642
- */
643
- static cleanup(): void;
644
- /**
645
- * Retrieve stored callback result if available
646
- */
647
- static getStoredCallback(): URL | null;
648
- private authenticateWithRedirect;
649
- }
650
-
651
566
  interface YouVersionUserInfoJSON {
652
- first_name?: string;
653
- last_name?: string;
567
+ name?: string;
654
568
  id?: string;
655
569
  avatar_url?: string;
570
+ email?: string;
656
571
  }
657
572
  declare class YouVersionUserInfo {
658
- readonly firstName?: string;
659
- readonly lastName?: string;
573
+ readonly name?: string;
660
574
  readonly userId?: string;
575
+ readonly email?: string;
661
576
  readonly avatarUrlFormat?: string;
662
577
  constructor(data: YouVersionUserInfoJSON);
663
578
  getAvatarUrl(width?: number, height?: number): URL | null;
@@ -669,26 +584,74 @@ declare class YouVersionAPIUsers {
669
584
  * Presents the YouVersion login flow to the user and returns the login result upon completion.
670
585
  *
671
586
  * This function authenticates the user with YouVersion, requesting the specified required and optional permissions.
672
- * The function returns a promise that resolves when the user completes or cancels the login flow,
673
- * returning the login result containing the authorization code and granted permissions.
587
+ * The function redirects to the YouVersion authorization URL and expects the callback to be handled separately.
674
588
  *
675
- * @param requiredPermissions - The set of permissions that must be granted by the user for successful login.
676
- * @param optionalPermissions - The set of permissions that will be requested from the user but are not required for successful login.
677
- * @returns A Promise resolving to a SignInWithYouVersionResult containing the authorization code and granted permissions upon successful login.
678
- * @throws An error if authentication fails or is cancelled by the user.
589
+ * @param permissions - The set of permissions that must be granted by the user for successful login.
590
+ * @param redirectURL - The URL to redirect back to after authentication.
591
+ * @throws An error if authentication fails or configuration is invalid.
679
592
  */
680
- static signIn(requiredPermissions: Set<SignInWithYouVersionPermissionValues>, optionalPermissions: Set<SignInWithYouVersionPermissionValues>): Promise<SignInWithYouVersionResult>;
593
+ static signIn(permissions: Set<SignInWithYouVersionPermissionValues>, redirectURL: string): Promise<void>;
594
+ /**
595
+ * Handles the OAuth callback after user authentication.
596
+ *
597
+ * Call this method when your app loads to check if the current URL contains
598
+ * an OAuth callback with authorization code. If found, it exchanges the code
599
+ * for tokens and stores them.
600
+ *
601
+ * @returns Promise<SignInWithYouVersionResult | null> - SignInWithYouVersionResult if callback was handled, null otherwise
602
+ * @throws An error if token exchange fails
603
+ */
604
+ static handleAuthCallback(): Promise<SignInWithYouVersionResult | null>;
605
+ /**
606
+ * Redirects to the server callback endpoint to obtain authorization code
607
+ */
608
+ private static obtainLocation;
609
+ /**
610
+ * Extracts sign-in result from token response
611
+ */
612
+ private static extractSignInResult;
613
+ /**
614
+ * Decodes JWT payload for UI display purposes.
615
+ *
616
+ * Note: We intentionally do not verify the JWT signature here because:
617
+ *
618
+ * 1. YouVersion's backend verifies all tokens on API requests
619
+ * 2. This decoded data is only used for UI display
620
+ * 3. No security decisions are made based on these claims
621
+ *
622
+ * @private
623
+ */
624
+ private static decodeJWT;
681
625
  static signOut(): void;
682
626
  /**
683
- * Retrieves user information for the authenticated user using the provided access token.
627
+ * Retrieves user information for the authenticated user by decoding the provided JWT access token.
684
628
  *
685
- * This function fetches the user's profile information from the YouVersion API, decoding it into a YouVersionUserInfo model.
629
+ * This function extracts the user's profile information directly from the JWT token payload.
686
630
  *
687
- * @param accessToken - The access token obtained from the login process.
631
+ * @param accessToken - The JWT access token obtained from the login process.
688
632
  * @returns A Promise resolving to a YouVersionUserInfo object containing the user's profile information.
689
- * @throws An error if the URL is invalid, the network request fails, or the response cannot be decoded.
633
+ * @throws An error if the access token is invalid or cannot be decoded.
690
634
  */
691
- static userInfo(accessToken: string): Promise<YouVersionUserInfo>;
635
+ static userInfo(idToken: string): YouVersionUserInfo;
636
+ /**
637
+ * Refreshes the access token using the stored refresh token.
638
+ *
639
+ * @returns Promise<SignInWithYouVersionResult | null> - New tokens if refresh succeeds, null otherwise
640
+ * @throws An error if refresh fails or no refresh token is available
641
+ */
642
+ static refreshTokens(): Promise<SignInWithYouVersionResult | null>;
643
+ /**
644
+ * Checks if the current access token is expired or about to expire.
645
+ *
646
+ * @returns true if token is expired or about to expire
647
+ */
648
+ static isTokenExpired(): boolean;
649
+ /**
650
+ * Refreshes the access token if it's expired or about to expire.
651
+ *
652
+ * @returns Promise<boolean> - true if refresh was successful or not needed, false if failed
653
+ */
654
+ static refreshTokenIfNeeded(): Promise<boolean>;
692
655
  }
693
656
 
694
657
  declare class YouVersionAPI {
@@ -698,29 +661,38 @@ declare class YouVersionAPI {
698
661
  declare class URLBuilder {
699
662
  private static get baseURL();
700
663
  static authURL(appKey: string, requiredPermissions?: Set<SignInWithYouVersionPermissionValues>, optionalPermissions?: Set<SignInWithYouVersionPermissionValues>): URL;
701
- static userURL(accessToken: string): URL;
702
664
  }
703
665
 
666
+ /**
667
+ * Security Note: Tokens are stored in localStorage for persistence.
668
+ * Ensure your application follows XSS prevention best practices:
669
+ * - Sanitize user input
670
+ * - Use Content Security Policy headers
671
+ * - Avoid innerHTML with untrusted content
672
+ */
704
673
  declare class YouVersionPlatformConfiguration {
705
674
  private static _appKey;
706
675
  private static _installationId;
707
- private static _accessToken;
708
676
  private static _apiHost;
709
- private static _isPreviewMode;
710
- private static _previewUserInfo;
677
+ private static _refreshTokenKey;
678
+ private static _expiryDateKey;
711
679
  private static getOrSetInstallationId;
680
+ static saveAuthData(accessToken: string | null, refreshToken: string | null, idToken: string | null, expiryDate: Date | null): void;
681
+ static clearAuthTokens(): void;
682
+ static get accessToken(): string | null;
683
+ static get refreshToken(): string | null;
684
+ static get idToken(): string | null;
685
+ static get tokenExpiryDate(): Date | null;
712
686
  static get appKey(): string | null;
713
687
  static set appKey(value: string | null);
714
688
  static get installationId(): string;
715
689
  static set installationId(value: string | null);
716
- static setAccessToken(token: string | null): void;
717
- static get accessToken(): string | null;
718
690
  static get apiHost(): string;
719
691
  static set apiHost(value: string);
720
- static get isPreviewMode(): boolean;
721
- static set isPreviewMode(value: boolean);
722
- static get previewUserInfo(): YouVersionUserInfo | null;
723
- static set previewUserInfo(value: YouVersionUserInfo | null);
692
+ static get refreshTokenKey(): string | null;
693
+ static set refreshTokenKey(value: string);
694
+ static get expiryDateKey(): string | null;
695
+ static set expiryDateKey(value: string);
724
696
  }
725
697
 
726
698
  declare const BOOK_IDS: readonly ["GEN", "EXO", "LEV", "NUM", "DEU", "JOS", "JDG", "RUT", "1SA", "2SA", "1KI", "2KI", "1CH", "2CH", "EZR", "NEH", "EST", "JOB", "PSA", "PRO", "ECC", "SNG", "ISA", "JER", "LAM", "EZK", "DAN", "HOS", "JOL", "AMO", "OBA", "JON", "MIC", "NAM", "HAB", "ZEP", "HAG", "ZEC", "MAL", "MAT", "MRK", "LUK", "JHN", "ACT", "ROM", "1CO", "2CO", "GAL", "EPH", "PHP", "COL", "1TH", "2TH", "1TI", "2TI", "TIT", "PHM", "HEB", "JAS", "1PE", "2PE", "1JN", "2JN", "3JN", "JUD", "REV", "TOB", "JDT", "ESG", "WIS", "SIR", "BAR", "LJE", "S3Y", "SUS", "BEL", "1MA", "2MA", "3MA", "4MA", "1ES", "2ES", "MAN", "PS2", "ODA", "PSS", "3ES", "EZA", "5EZ", "6EZ", "DAG", "PS3", "2BA", "LBA", "JUB", "ENO", "1MQ", "2MQ", "3MQ", "REP", "4BA", "LAO", "LKA"];
@@ -730,4 +702,4 @@ declare const BOOK_IDS: readonly ["GEN", "EXO", "LEV", "NUM", "DEU", "JOS", "JDG
730
702
  */
731
703
  declare const BOOK_CANON: Record<BookUsfm, Canon>;
732
704
 
733
- export { ApiClient, type ApiConfig, AuthClient, type AuthenticationState, type AuthenticationStrategy, AuthenticationStrategyRegistry, BOOK_CANON, BOOK_IDS, type BibleBook, type BibleChapter, BibleClient, type BibleIndex, type BibleIndexBook, type BibleIndexChapter, type BibleIndexVerse, type BiblePassage, type BibleVerse, type BibleVersion, type CANON, type Collection, type CreateHighlight, type DeleteHighlightOptions, type GetHighlightsOptions, type GetLanguagesOptions, type Highlight, type HighlightColor, HighlightsClient, type Language, LanguagesClient, MemoryStorageStrategy, SessionStorageStrategy, SignInWithYouVersionPermission, type SignInWithYouVersionPermissionValues, SignInWithYouVersionResult, type StorageStrategy, URLBuilder, type User, type VOTD, WebAuthenticationStrategy, YouVersionAPI, YouVersionAPIUsers, YouVersionPlatformConfiguration, YouVersionUserInfo, type YouVersionUserInfoJSON };
705
+ export { ApiClient, type ApiConfig, type AuthenticationState, BOOK_CANON, BOOK_IDS, type BibleBook, type BibleChapter, BibleClient, type BibleIndex, type BibleIndexBook, type BibleIndexChapter, type BibleIndexVerse, type BiblePassage, type BibleVerse, type BibleVersion, type CANON, type Collection, type CreateHighlight, type DeleteHighlightOptions, type GetHighlightsOptions, type GetLanguagesOptions, type Highlight, type HighlightColor, HighlightsClient, type Language, LanguagesClient, MemoryStorageStrategy, SessionStorageStrategy, SignInWithYouVersionPermission, type SignInWithYouVersionPermissionValues, SignInWithYouVersionResult, type StorageStrategy, URLBuilder, type User, type VOTD, YouVersionAPI, YouVersionAPIUsers, YouVersionPlatformConfiguration, YouVersionUserInfo, type YouVersionUserInfoJSON };