@youversion/platform-core 0.8.1 → 0.9.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/.turbo/turbo-build.log +8 -8
- package/CHANGELOG.md +23 -0
- package/dist/index.cjs +116 -169
- package/dist/index.d.cts +39 -35
- package/dist/index.d.ts +39 -35
- package/dist/index.js +116 -168
- package/package.json +2 -1
- package/src/SignInWithYouVersionPKCE.ts +7 -7
- package/src/SignInWithYouVersionResult.ts +0 -6
- package/src/Users.ts +5 -29
- package/src/__tests__/MockBibles.ts +1196 -1294
- package/src/__tests__/MockChapters.ts +171 -1950
- package/src/__tests__/MockPassages.ts +7 -14
- package/src/__tests__/MockVerses.ts +60 -75
- package/src/__tests__/MockVersions.ts +30 -30
- package/src/__tests__/SignInWithYouVersionPKCE.test.ts +8 -77
- package/src/__tests__/SignInWithYouVersionResult.test.ts +0 -2
- package/src/__tests__/Users.test.ts +4 -38
- package/src/__tests__/bible.test.ts +9 -18
- package/src/__tests__/client.test.ts +10 -1
- package/src/__tests__/setup.ts +12 -9
- package/src/bible.ts +1 -1
- package/src/index.ts +0 -1
- package/src/schemas/book.ts +5 -8
- package/src/schemas/chapter.ts +3 -12
- package/src/schemas/passage.ts +1 -3
- package/src/schemas/verse.ts +2 -7
- package/src/schemas/version.ts +2 -2
- package/src/types/auth.ts +2 -0
- package/src/types/index.ts +5 -1
- package/src/utils/constants.ts +103 -103
- package/src/URLBuilder.ts +0 -50
- package/src/__tests__/URLBuilder.test.ts +0 -190
package/dist/index.d.ts
CHANGED
|
@@ -8,8 +8,8 @@ declare const BibleVersionSchema: z.ZodObject<{
|
|
|
8
8
|
info: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
9
9
|
publisher_url: z.ZodOptional<z.ZodNullable<z.ZodURL>>;
|
|
10
10
|
language_tag: z.ZodString;
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
localized_abbreviation: z.ZodString;
|
|
12
|
+
localized_title: z.ZodString;
|
|
13
13
|
organization_id: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
14
14
|
title: z.ZodString;
|
|
15
15
|
books: z.ZodArray<z.ZodUnion<readonly [...z.ZodLiteral<"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">[], z.ZodType<string & {}, unknown, z.core.$ZodTypeInternals<string & {}, unknown>>]>>;
|
|
@@ -18,9 +18,9 @@ declare const BibleVersionSchema: z.ZodObject<{
|
|
|
18
18
|
type BibleVersion = z.infer<typeof BibleVersionSchema>;
|
|
19
19
|
|
|
20
20
|
declare const CanonSchema: z.ZodEnum<{
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
21
|
+
old_testament: "old_testament";
|
|
22
|
+
new_testament: "new_testament";
|
|
23
|
+
deuterocanon: "deuterocanon";
|
|
24
24
|
}>;
|
|
25
25
|
type Canon = z.infer<typeof CanonSchema>;
|
|
26
26
|
declare const BookUsfmSchema: z.ZodUnion<readonly [...z.ZodLiteral<"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">[], z.ZodType<string & {}, unknown, z.core.$ZodTypeInternals<string & {}, unknown>>]>;
|
|
@@ -28,40 +28,50 @@ type BookUsfm = z.infer<typeof BookUsfmSchema>;
|
|
|
28
28
|
declare const BibleBookSchema: z.ZodObject<{
|
|
29
29
|
id: z.ZodUnion<readonly [...z.ZodLiteral<"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">[], z.ZodType<string & {}, unknown, z.core.$ZodTypeInternals<string & {}, unknown>>]>;
|
|
30
30
|
title: z.ZodString;
|
|
31
|
+
full_title: z.ZodString;
|
|
31
32
|
abbreviation: z.ZodOptional<z.ZodString>;
|
|
32
33
|
canon: z.ZodEnum<{
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
34
|
+
old_testament: "old_testament";
|
|
35
|
+
new_testament: "new_testament";
|
|
36
|
+
deuterocanon: "deuterocanon";
|
|
36
37
|
}>;
|
|
37
|
-
chapters: z.ZodOptional<z.ZodArray<z.
|
|
38
|
+
chapters: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
39
|
+
id: z.ZodString;
|
|
40
|
+
passage_id: z.ZodString;
|
|
41
|
+
title: z.ZodString;
|
|
42
|
+
verses: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
43
|
+
id: z.ZodString;
|
|
44
|
+
passage_id: z.ZodString;
|
|
45
|
+
title: z.ZodString;
|
|
46
|
+
}, z.core.$strip>>>;
|
|
47
|
+
}, z.core.$strip>>>;
|
|
38
48
|
}, z.core.$strip>;
|
|
39
49
|
type BibleBook = z.infer<typeof BibleBookSchema>;
|
|
40
50
|
type CANON = z.infer<typeof CanonSchema>;
|
|
41
51
|
|
|
42
52
|
declare const BibleChapterSchema: z.ZodObject<{
|
|
43
53
|
id: z.ZodString;
|
|
44
|
-
book_id: z.ZodUnion<readonly [...z.ZodLiteral<"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">[], z.ZodType<string & {}, unknown, z.core.$ZodTypeInternals<string & {}, unknown>>]>;
|
|
45
54
|
passage_id: z.ZodString;
|
|
46
55
|
title: z.ZodString;
|
|
47
|
-
verses: z.ZodOptional<z.ZodArray<z.
|
|
56
|
+
verses: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
57
|
+
id: z.ZodString;
|
|
58
|
+
passage_id: z.ZodString;
|
|
59
|
+
title: z.ZodString;
|
|
60
|
+
}, z.core.$strip>>>;
|
|
48
61
|
}, z.core.$strip>;
|
|
49
62
|
type BibleChapter = z.infer<typeof BibleChapterSchema>;
|
|
50
63
|
|
|
51
64
|
declare const BibleVerseSchema: z.ZodObject<{
|
|
52
65
|
id: z.ZodString;
|
|
53
|
-
book_id: z.ZodUnion<readonly [...z.ZodLiteral<"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">[], z.ZodType<string & {}, unknown, z.core.$ZodTypeInternals<string & {}, unknown>>]>;
|
|
54
|
-
chapter_id: z.ZodString;
|
|
55
66
|
passage_id: z.ZodString;
|
|
56
|
-
|
|
67
|
+
title: z.ZodString;
|
|
57
68
|
}, z.core.$strip>;
|
|
58
69
|
type BibleVerse = z.infer<typeof BibleVerseSchema>;
|
|
59
70
|
|
|
60
71
|
declare const BiblePassageSchema: z.ZodObject<{
|
|
61
72
|
id: z.ZodString;
|
|
62
73
|
content: z.ZodString;
|
|
63
|
-
|
|
64
|
-
human_reference: z.ZodString;
|
|
74
|
+
reference: z.ZodString;
|
|
65
75
|
}, z.core.$strip>;
|
|
66
76
|
type BiblePassage = z.infer<typeof BiblePassageSchema>;
|
|
67
77
|
|
|
@@ -91,9 +101,9 @@ declare const BibleIndexBookSchema: z.ZodObject<{
|
|
|
91
101
|
full_title: z.ZodString;
|
|
92
102
|
abbreviation: z.ZodString;
|
|
93
103
|
canon: z.ZodEnum<{
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
104
|
+
old_testament: "old_testament";
|
|
105
|
+
new_testament: "new_testament";
|
|
106
|
+
deuterocanon: "deuterocanon";
|
|
97
107
|
}>;
|
|
98
108
|
chapters: z.ZodArray<z.ZodObject<{
|
|
99
109
|
id: z.ZodString;
|
|
@@ -113,9 +123,9 @@ declare const _BibleIndexSchema: z.ZodObject<{
|
|
|
113
123
|
full_title: z.ZodString;
|
|
114
124
|
abbreviation: z.ZodString;
|
|
115
125
|
canon: z.ZodEnum<{
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
126
|
+
old_testament: "old_testament";
|
|
127
|
+
new_testament: "new_testament";
|
|
128
|
+
deuterocanon: "deuterocanon";
|
|
119
129
|
}>;
|
|
120
130
|
chapters: z.ZodArray<z.ZodObject<{
|
|
121
131
|
id: z.ZodString;
|
|
@@ -199,7 +209,6 @@ type SignInWithYouVersionResultProps = {
|
|
|
199
209
|
expiresIn?: number;
|
|
200
210
|
refreshToken?: string;
|
|
201
211
|
idToken?: string;
|
|
202
|
-
permissions?: SignInWithYouVersionPermissionValues[];
|
|
203
212
|
yvpUserId?: string;
|
|
204
213
|
name?: string;
|
|
205
214
|
profilePicture?: string;
|
|
@@ -210,12 +219,11 @@ declare class SignInWithYouVersionResult {
|
|
|
210
219
|
readonly expiryDate: Date | undefined;
|
|
211
220
|
readonly refreshToken: string | undefined;
|
|
212
221
|
readonly idToken: string | undefined;
|
|
213
|
-
readonly permissions: SignInWithYouVersionPermissionValues[] | undefined;
|
|
214
222
|
readonly yvpUserId: string | undefined;
|
|
215
223
|
readonly name: string | undefined;
|
|
216
224
|
readonly profilePicture: string | undefined;
|
|
217
225
|
readonly email: string | undefined;
|
|
218
|
-
constructor({ accessToken, expiresIn, refreshToken, idToken,
|
|
226
|
+
constructor({ accessToken, expiresIn, refreshToken, idToken, yvpUserId, name, profilePicture, email, }: SignInWithYouVersionResultProps);
|
|
219
227
|
}
|
|
220
228
|
|
|
221
229
|
type SignInWithYouVersionPermissionValues = (typeof SignInWithYouVersionPermission)[keyof typeof SignInWithYouVersionPermission];
|
|
@@ -227,6 +235,7 @@ interface AuthenticationState {
|
|
|
227
235
|
result: SignInWithYouVersionResult | null;
|
|
228
236
|
error: Error | null;
|
|
229
237
|
}
|
|
238
|
+
type AuthenticationScopes = 'profile' | 'email';
|
|
230
239
|
|
|
231
240
|
/**
|
|
232
241
|
* Legacy type for highlight colors (constants only)
|
|
@@ -327,7 +336,7 @@ declare class BibleClient {
|
|
|
327
336
|
/**
|
|
328
337
|
* Fetches all books for a given Bible version.
|
|
329
338
|
* @param versionId The version ID.
|
|
330
|
-
* @param canon Optional canon filter (
|
|
339
|
+
* @param canon Optional canon filter ("old_testament", 'new_testament', 'deuterocanon').
|
|
331
340
|
* @returns An array of BibleBook objects.
|
|
332
341
|
*/
|
|
333
342
|
getBooks(versionId: number, canon?: CANON): Promise<Collection<BibleBook>>;
|
|
@@ -583,14 +592,14 @@ declare class YouVersionAPIUsers {
|
|
|
583
592
|
/**
|
|
584
593
|
* Presents the YouVersion login flow to the user and returns the login result upon completion.
|
|
585
594
|
*
|
|
586
|
-
* This function authenticates the user with YouVersion
|
|
595
|
+
* This function authenticates the user with YouVersion.
|
|
587
596
|
* The function redirects to the YouVersion authorization URL and expects the callback to be handled separately.
|
|
588
597
|
*
|
|
589
|
-
* @param
|
|
598
|
+
* @param scopes - The scopes given to the authentication call.
|
|
590
599
|
* @param redirectURL - The URL to redirect back to after authentication.
|
|
591
600
|
* @throws An error if authentication fails or configuration is invalid.
|
|
592
601
|
*/
|
|
593
|
-
static signIn(
|
|
602
|
+
static signIn(redirectURL: string, scopes?: AuthenticationScopes[]): Promise<void>;
|
|
594
603
|
/**
|
|
595
604
|
* Handles the OAuth callback after user authentication.
|
|
596
605
|
*
|
|
@@ -658,11 +667,6 @@ declare class YouVersionAPI {
|
|
|
658
667
|
static addStandardHeaders(url: URL): Request;
|
|
659
668
|
}
|
|
660
669
|
|
|
661
|
-
declare class URLBuilder {
|
|
662
|
-
private static get baseURL();
|
|
663
|
-
static authURL(appKey: string, requiredPermissions?: Set<SignInWithYouVersionPermissionValues>, optionalPermissions?: Set<SignInWithYouVersionPermissionValues>): URL;
|
|
664
|
-
}
|
|
665
|
-
|
|
666
670
|
/**
|
|
667
671
|
* Security Note: Tokens are stored in localStorage for persistence.
|
|
668
672
|
* Ensure your application follows XSS prevention best practices:
|
|
@@ -702,4 +706,4 @@ declare const BOOK_IDS: readonly ["GEN", "EXO", "LEV", "NUM", "DEU", "JOS", "JDG
|
|
|
702
706
|
*/
|
|
703
707
|
declare const BOOK_CANON: Record<BookUsfm, Canon>;
|
|
704
708
|
|
|
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,
|
|
709
|
+
export { ApiClient, type ApiConfig, type AuthenticationScopes, 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, type User, type VOTD, YouVersionAPI, YouVersionAPIUsers, YouVersionPlatformConfiguration, YouVersionUserInfo, type YouVersionUserInfoJSON };
|
package/dist/index.js
CHANGED
|
@@ -192,7 +192,7 @@ var BibleClient = class {
|
|
|
192
192
|
/**
|
|
193
193
|
* Fetches all books for a given Bible version.
|
|
194
194
|
* @param versionId The version ID.
|
|
195
|
-
* @param canon Optional canon filter (
|
|
195
|
+
* @param canon Optional canon filter ("old_testament", 'new_testament', 'deuterocanon').
|
|
196
196
|
* @returns An array of BibleBook objects.
|
|
197
197
|
*/
|
|
198
198
|
async getBooks(versionId, canon) {
|
|
@@ -692,7 +692,7 @@ var YouVersionUserInfo = class {
|
|
|
692
692
|
|
|
693
693
|
// src/SignInWithYouVersionPKCE.ts
|
|
694
694
|
var SignInWithYouVersionPKCEAuthorizationRequestBuilder = class {
|
|
695
|
-
static async make(appKey,
|
|
695
|
+
static async make(appKey, redirectURL, scopes) {
|
|
696
696
|
const codeVerifier = this.randomURLSafeString(32);
|
|
697
697
|
const codeChallenge = await this.codeChallenge(codeVerifier);
|
|
698
698
|
const state = this.randomURLSafeString(24);
|
|
@@ -703,10 +703,10 @@ var SignInWithYouVersionPKCEAuthorizationRequestBuilder = class {
|
|
|
703
703
|
state,
|
|
704
704
|
nonce
|
|
705
705
|
};
|
|
706
|
-
const url = this.authorizeURL(appKey,
|
|
706
|
+
const url = this.authorizeURL(appKey, redirectURL, parameters, scopes);
|
|
707
707
|
return { url, parameters };
|
|
708
708
|
}
|
|
709
|
-
static authorizeURL(appKey,
|
|
709
|
+
static authorizeURL(appKey, redirectURL, parameters, scopes) {
|
|
710
710
|
const components = new URL(`https://${YouVersionPlatformConfiguration.apiHost}/auth/authorize`);
|
|
711
711
|
const redirectUrlString = redirectURL.toString().endsWith("/") ? redirectURL.toString().slice(0, -1) : redirectURL.toString();
|
|
712
712
|
const queryParams = new URLSearchParams({
|
|
@@ -722,7 +722,7 @@ var SignInWithYouVersionPKCEAuthorizationRequestBuilder = class {
|
|
|
722
722
|
if (installId) {
|
|
723
723
|
queryParams.set("x-yvp-installation-id", installId);
|
|
724
724
|
}
|
|
725
|
-
const scopeValue = this.scopeValue(
|
|
725
|
+
const scopeValue = this.scopeValue(scopes || []);
|
|
726
726
|
if (scopeValue) {
|
|
727
727
|
queryParams.set("scope", scopeValue);
|
|
728
728
|
}
|
|
@@ -762,8 +762,8 @@ var SignInWithYouVersionPKCEAuthorizationRequestBuilder = class {
|
|
|
762
762
|
const base64 = btoa(String.fromCharCode.apply(null, Array.from(data)));
|
|
763
763
|
return base64.replace(/\+/g, "-").replace(/\//g, "_").replace(/=/g, "");
|
|
764
764
|
}
|
|
765
|
-
static scopeValue(
|
|
766
|
-
const scopeArray = Array.from(
|
|
765
|
+
static scopeValue(scopes) {
|
|
766
|
+
const scopeArray = Array.from(scopes).sort();
|
|
767
767
|
let scopeWithOpenID = scopeArray.join(" ");
|
|
768
768
|
if (!scopeWithOpenID.split(" ").includes("openid")) {
|
|
769
769
|
scopeWithOpenID += (scopeWithOpenID === "" ? "" : " ") + "openid";
|
|
@@ -785,7 +785,6 @@ var SignInWithYouVersionResult = class {
|
|
|
785
785
|
expiryDate;
|
|
786
786
|
refreshToken;
|
|
787
787
|
idToken;
|
|
788
|
-
permissions;
|
|
789
788
|
yvpUserId;
|
|
790
789
|
name;
|
|
791
790
|
profilePicture;
|
|
@@ -795,7 +794,6 @@ var SignInWithYouVersionResult = class {
|
|
|
795
794
|
expiresIn,
|
|
796
795
|
refreshToken,
|
|
797
796
|
idToken,
|
|
798
|
-
permissions,
|
|
799
797
|
yvpUserId,
|
|
800
798
|
name,
|
|
801
799
|
profilePicture,
|
|
@@ -805,7 +803,6 @@ var SignInWithYouVersionResult = class {
|
|
|
805
803
|
this.expiryDate = expiresIn ? new Date(Date.now() + expiresIn * 1e3) : /* @__PURE__ */ new Date();
|
|
806
804
|
this.refreshToken = refreshToken;
|
|
807
805
|
this.idToken = idToken;
|
|
808
|
-
this.permissions = permissions;
|
|
809
806
|
this.yvpUserId = yvpUserId;
|
|
810
807
|
this.name = name;
|
|
811
808
|
this.profilePicture = profilePicture;
|
|
@@ -818,22 +815,22 @@ var YouVersionAPIUsers = class {
|
|
|
818
815
|
/**
|
|
819
816
|
* Presents the YouVersion login flow to the user and returns the login result upon completion.
|
|
820
817
|
*
|
|
821
|
-
* This function authenticates the user with YouVersion
|
|
818
|
+
* This function authenticates the user with YouVersion.
|
|
822
819
|
* The function redirects to the YouVersion authorization URL and expects the callback to be handled separately.
|
|
823
820
|
*
|
|
824
|
-
* @param
|
|
821
|
+
* @param scopes - The scopes given to the authentication call.
|
|
825
822
|
* @param redirectURL - The URL to redirect back to after authentication.
|
|
826
823
|
* @throws An error if authentication fails or configuration is invalid.
|
|
827
824
|
*/
|
|
828
|
-
static async signIn(
|
|
825
|
+
static async signIn(redirectURL, scopes) {
|
|
829
826
|
const appKey = YouVersionPlatformConfiguration.appKey;
|
|
830
827
|
if (!appKey) {
|
|
831
828
|
throw new Error("YouVersionPlatformConfiguration.appKey must be set before calling signIn");
|
|
832
829
|
}
|
|
833
830
|
const authorizationRequest = await SignInWithYouVersionPKCEAuthorizationRequestBuilder.make(
|
|
834
831
|
appKey,
|
|
835
|
-
|
|
836
|
-
|
|
832
|
+
new URL(redirectURL),
|
|
833
|
+
scopes
|
|
837
834
|
);
|
|
838
835
|
localStorage.setItem(
|
|
839
836
|
"youversion-auth-code-verifier",
|
|
@@ -933,17 +930,11 @@ var YouVersionAPIUsers = class {
|
|
|
933
930
|
*/
|
|
934
931
|
static extractSignInResult(tokens) {
|
|
935
932
|
const idClaims = this.decodeJWT(tokens.id_token);
|
|
936
|
-
const permissions = tokens.scope.split(" ").map((p) => p.trim()).filter((p) => p.length > 0).filter(
|
|
937
|
-
(p) => Object.values(SignInWithYouVersionPermission).includes(
|
|
938
|
-
p
|
|
939
|
-
)
|
|
940
|
-
);
|
|
941
933
|
const resultData = {
|
|
942
934
|
accessToken: tokens.access_token,
|
|
943
935
|
expiresIn: tokens.expires_in,
|
|
944
936
|
refreshToken: tokens.refresh_token,
|
|
945
937
|
idToken: tokens.id_token,
|
|
946
|
-
permissions,
|
|
947
938
|
yvpUserId: idClaims.sub,
|
|
948
939
|
name: idClaims.name,
|
|
949
940
|
profilePicture: idClaims.profile_picture,
|
|
@@ -1062,12 +1053,7 @@ var YouVersionAPIUsers = class {
|
|
|
1062
1053
|
accessToken: tokens.access_token,
|
|
1063
1054
|
expiresIn: tokens.expires_in,
|
|
1064
1055
|
refreshToken: tokens.refresh_token,
|
|
1065
|
-
idToken: existingIdToken
|
|
1066
|
-
permissions: tokens.scope.split(" ").map((p) => p.trim()).filter((p) => p.length > 0).filter(
|
|
1067
|
-
(p) => Object.values(SignInWithYouVersionPermission).includes(
|
|
1068
|
-
p
|
|
1069
|
-
)
|
|
1070
|
-
)
|
|
1056
|
+
idToken: existingIdToken
|
|
1071
1057
|
});
|
|
1072
1058
|
YouVersionPlatformConfiguration.saveAuthData(
|
|
1073
1059
|
result.accessToken || null,
|
|
@@ -1137,43 +1123,6 @@ var YouVersionAPI = class {
|
|
|
1137
1123
|
}
|
|
1138
1124
|
};
|
|
1139
1125
|
|
|
1140
|
-
// src/URLBuilder.ts
|
|
1141
|
-
var URLBuilder = class {
|
|
1142
|
-
static get baseURL() {
|
|
1143
|
-
return new URL(`https://${YouVersionPlatformConfiguration.apiHost}`);
|
|
1144
|
-
}
|
|
1145
|
-
static authURL(appKey, requiredPermissions = /* @__PURE__ */ new Set(), optionalPermissions = /* @__PURE__ */ new Set()) {
|
|
1146
|
-
if (typeof appKey !== "string" || appKey.trim().length === 0) {
|
|
1147
|
-
throw new Error("appKey must be a non-empty string");
|
|
1148
|
-
}
|
|
1149
|
-
try {
|
|
1150
|
-
const url = new URL(this.baseURL);
|
|
1151
|
-
url.pathname = "/auth/login";
|
|
1152
|
-
const searchParams = new URLSearchParams();
|
|
1153
|
-
searchParams.append("APP_KEY", appKey);
|
|
1154
|
-
searchParams.append("language", "en");
|
|
1155
|
-
if (requiredPermissions.size > 0) {
|
|
1156
|
-
const requiredList = Array.from(requiredPermissions).map((p) => p.toString());
|
|
1157
|
-
searchParams.append("required_perms", requiredList.join(","));
|
|
1158
|
-
}
|
|
1159
|
-
if (optionalPermissions.size > 0) {
|
|
1160
|
-
const optionalList = Array.from(optionalPermissions).map((p) => p.toString());
|
|
1161
|
-
searchParams.append("opt_perms", optionalList.join(","));
|
|
1162
|
-
}
|
|
1163
|
-
const installationId = YouVersionPlatformConfiguration.installationId;
|
|
1164
|
-
if (installationId) {
|
|
1165
|
-
searchParams.append("x-yvp-installation-id", installationId);
|
|
1166
|
-
}
|
|
1167
|
-
url.search = searchParams.toString();
|
|
1168
|
-
return url;
|
|
1169
|
-
} catch (error) {
|
|
1170
|
-
throw new Error(
|
|
1171
|
-
`Failed to construct auth URL: ${error instanceof Error ? error.message : "Unknown error"}`
|
|
1172
|
-
);
|
|
1173
|
-
}
|
|
1174
|
-
}
|
|
1175
|
-
};
|
|
1176
|
-
|
|
1177
1126
|
// src/utils/constants.ts
|
|
1178
1127
|
var BOOK_IDS = [
|
|
1179
1128
|
"GEN",
|
|
@@ -1283,109 +1232,109 @@ var BOOK_IDS = [
|
|
|
1283
1232
|
"LKA"
|
|
1284
1233
|
];
|
|
1285
1234
|
var BOOK_CANON = {
|
|
1286
|
-
GEN: "
|
|
1287
|
-
EXO: "
|
|
1288
|
-
LEV: "
|
|
1289
|
-
NUM: "
|
|
1290
|
-
DEU: "
|
|
1291
|
-
JOS: "
|
|
1292
|
-
JDG: "
|
|
1293
|
-
RUT: "
|
|
1294
|
-
"1SA": "
|
|
1295
|
-
"2SA": "
|
|
1296
|
-
"1KI": "
|
|
1297
|
-
"2KI": "
|
|
1298
|
-
"1CH": "
|
|
1299
|
-
"2CH": "
|
|
1300
|
-
EZR: "
|
|
1301
|
-
NEH: "
|
|
1302
|
-
EST: "
|
|
1303
|
-
JOB: "
|
|
1304
|
-
PSA: "
|
|
1305
|
-
PRO: "
|
|
1306
|
-
ECC: "
|
|
1307
|
-
SNG: "
|
|
1308
|
-
ISA: "
|
|
1309
|
-
JER: "
|
|
1310
|
-
LAM: "
|
|
1311
|
-
EZK: "
|
|
1312
|
-
DAN: "
|
|
1313
|
-
HOS: "
|
|
1314
|
-
JOL: "
|
|
1315
|
-
AMO: "
|
|
1316
|
-
OBA: "
|
|
1317
|
-
JON: "
|
|
1318
|
-
MIC: "
|
|
1319
|
-
NAM: "
|
|
1320
|
-
HAB: "
|
|
1321
|
-
ZEP: "
|
|
1322
|
-
HAG: "
|
|
1323
|
-
ZEC: "
|
|
1324
|
-
MAL: "
|
|
1325
|
-
MAT: "
|
|
1326
|
-
MRK: "
|
|
1327
|
-
LUK: "
|
|
1328
|
-
JHN: "
|
|
1329
|
-
ACT: "
|
|
1330
|
-
ROM: "
|
|
1331
|
-
"1CO": "
|
|
1332
|
-
"2CO": "
|
|
1333
|
-
GAL: "
|
|
1334
|
-
EPH: "
|
|
1335
|
-
PHP: "
|
|
1336
|
-
COL: "
|
|
1337
|
-
"1TH": "
|
|
1338
|
-
"2TH": "
|
|
1339
|
-
"1TI": "
|
|
1340
|
-
"2TI": "
|
|
1341
|
-
TIT: "
|
|
1342
|
-
PHM: "
|
|
1343
|
-
HEB: "
|
|
1344
|
-
JAS: "
|
|
1345
|
-
"1PE": "
|
|
1346
|
-
"2PE": "
|
|
1347
|
-
"1JN": "
|
|
1348
|
-
"2JN": "
|
|
1349
|
-
"3JN": "
|
|
1350
|
-
JUD: "
|
|
1351
|
-
REV: "
|
|
1352
|
-
TOB: "
|
|
1353
|
-
JDT: "
|
|
1354
|
-
ESG: "
|
|
1355
|
-
WIS: "
|
|
1356
|
-
SIR: "
|
|
1357
|
-
BAR: "
|
|
1358
|
-
LJE: "
|
|
1359
|
-
S3Y: "
|
|
1360
|
-
SUS: "
|
|
1361
|
-
BEL: "
|
|
1362
|
-
"1MA": "
|
|
1363
|
-
"2MA": "
|
|
1364
|
-
"3MA": "
|
|
1365
|
-
"4MA": "
|
|
1366
|
-
"1ES": "
|
|
1367
|
-
"2ES": "
|
|
1368
|
-
MAN: "
|
|
1369
|
-
PS2: "
|
|
1370
|
-
ODA: "
|
|
1371
|
-
PSS: "
|
|
1372
|
-
"3ES": "
|
|
1373
|
-
EZA: "
|
|
1374
|
-
"5EZ": "
|
|
1375
|
-
"6EZ": "
|
|
1376
|
-
DAG: "
|
|
1377
|
-
PS3: "
|
|
1378
|
-
"2BA": "
|
|
1379
|
-
LBA: "
|
|
1380
|
-
JUB: "
|
|
1381
|
-
ENO: "
|
|
1382
|
-
"1MQ": "
|
|
1383
|
-
"2MQ": "
|
|
1384
|
-
"3MQ": "
|
|
1385
|
-
REP: "
|
|
1386
|
-
"4BA": "
|
|
1387
|
-
LAO: "
|
|
1388
|
-
LKA: "
|
|
1235
|
+
GEN: "old_testament",
|
|
1236
|
+
EXO: "old_testament",
|
|
1237
|
+
LEV: "old_testament",
|
|
1238
|
+
NUM: "old_testament",
|
|
1239
|
+
DEU: "old_testament",
|
|
1240
|
+
JOS: "old_testament",
|
|
1241
|
+
JDG: "old_testament",
|
|
1242
|
+
RUT: "old_testament",
|
|
1243
|
+
"1SA": "old_testament",
|
|
1244
|
+
"2SA": "old_testament",
|
|
1245
|
+
"1KI": "old_testament",
|
|
1246
|
+
"2KI": "old_testament",
|
|
1247
|
+
"1CH": "old_testament",
|
|
1248
|
+
"2CH": "old_testament",
|
|
1249
|
+
EZR: "old_testament",
|
|
1250
|
+
NEH: "old_testament",
|
|
1251
|
+
EST: "old_testament",
|
|
1252
|
+
JOB: "old_testament",
|
|
1253
|
+
PSA: "old_testament",
|
|
1254
|
+
PRO: "old_testament",
|
|
1255
|
+
ECC: "old_testament",
|
|
1256
|
+
SNG: "old_testament",
|
|
1257
|
+
ISA: "old_testament",
|
|
1258
|
+
JER: "old_testament",
|
|
1259
|
+
LAM: "old_testament",
|
|
1260
|
+
EZK: "old_testament",
|
|
1261
|
+
DAN: "old_testament",
|
|
1262
|
+
HOS: "old_testament",
|
|
1263
|
+
JOL: "old_testament",
|
|
1264
|
+
AMO: "old_testament",
|
|
1265
|
+
OBA: "old_testament",
|
|
1266
|
+
JON: "old_testament",
|
|
1267
|
+
MIC: "old_testament",
|
|
1268
|
+
NAM: "old_testament",
|
|
1269
|
+
HAB: "old_testament",
|
|
1270
|
+
ZEP: "old_testament",
|
|
1271
|
+
HAG: "old_testament",
|
|
1272
|
+
ZEC: "old_testament",
|
|
1273
|
+
MAL: "old_testament",
|
|
1274
|
+
MAT: "new_testament",
|
|
1275
|
+
MRK: "new_testament",
|
|
1276
|
+
LUK: "new_testament",
|
|
1277
|
+
JHN: "new_testament",
|
|
1278
|
+
ACT: "new_testament",
|
|
1279
|
+
ROM: "new_testament",
|
|
1280
|
+
"1CO": "new_testament",
|
|
1281
|
+
"2CO": "new_testament",
|
|
1282
|
+
GAL: "new_testament",
|
|
1283
|
+
EPH: "new_testament",
|
|
1284
|
+
PHP: "new_testament",
|
|
1285
|
+
COL: "new_testament",
|
|
1286
|
+
"1TH": "new_testament",
|
|
1287
|
+
"2TH": "new_testament",
|
|
1288
|
+
"1TI": "new_testament",
|
|
1289
|
+
"2TI": "new_testament",
|
|
1290
|
+
TIT: "new_testament",
|
|
1291
|
+
PHM: "new_testament",
|
|
1292
|
+
HEB: "new_testament",
|
|
1293
|
+
JAS: "new_testament",
|
|
1294
|
+
"1PE": "new_testament",
|
|
1295
|
+
"2PE": "new_testament",
|
|
1296
|
+
"1JN": "new_testament",
|
|
1297
|
+
"2JN": "new_testament",
|
|
1298
|
+
"3JN": "new_testament",
|
|
1299
|
+
JUD: "new_testament",
|
|
1300
|
+
REV: "new_testament",
|
|
1301
|
+
TOB: "deuterocanon",
|
|
1302
|
+
JDT: "deuterocanon",
|
|
1303
|
+
ESG: "deuterocanon",
|
|
1304
|
+
WIS: "deuterocanon",
|
|
1305
|
+
SIR: "deuterocanon",
|
|
1306
|
+
BAR: "deuterocanon",
|
|
1307
|
+
LJE: "deuterocanon",
|
|
1308
|
+
S3Y: "deuterocanon",
|
|
1309
|
+
SUS: "deuterocanon",
|
|
1310
|
+
BEL: "deuterocanon",
|
|
1311
|
+
"1MA": "deuterocanon",
|
|
1312
|
+
"2MA": "deuterocanon",
|
|
1313
|
+
"3MA": "deuterocanon",
|
|
1314
|
+
"4MA": "deuterocanon",
|
|
1315
|
+
"1ES": "deuterocanon",
|
|
1316
|
+
"2ES": "deuterocanon",
|
|
1317
|
+
MAN: "deuterocanon",
|
|
1318
|
+
PS2: "deuterocanon",
|
|
1319
|
+
ODA: "deuterocanon",
|
|
1320
|
+
PSS: "deuterocanon",
|
|
1321
|
+
"3ES": "deuterocanon",
|
|
1322
|
+
EZA: "deuterocanon",
|
|
1323
|
+
"5EZ": "deuterocanon",
|
|
1324
|
+
"6EZ": "deuterocanon",
|
|
1325
|
+
DAG: "deuterocanon",
|
|
1326
|
+
PS3: "deuterocanon",
|
|
1327
|
+
"2BA": "deuterocanon",
|
|
1328
|
+
LBA: "deuterocanon",
|
|
1329
|
+
JUB: "deuterocanon",
|
|
1330
|
+
ENO: "deuterocanon",
|
|
1331
|
+
"1MQ": "deuterocanon",
|
|
1332
|
+
"2MQ": "deuterocanon",
|
|
1333
|
+
"3MQ": "deuterocanon",
|
|
1334
|
+
REP: "deuterocanon",
|
|
1335
|
+
"4BA": "deuterocanon",
|
|
1336
|
+
LAO: "deuterocanon",
|
|
1337
|
+
LKA: "new_testament"
|
|
1389
1338
|
// Luke-Acts combo, treated canonically as New Testament
|
|
1390
1339
|
};
|
|
1391
1340
|
export {
|
|
@@ -1399,7 +1348,6 @@ export {
|
|
|
1399
1348
|
SessionStorageStrategy,
|
|
1400
1349
|
SignInWithYouVersionPermission,
|
|
1401
1350
|
SignInWithYouVersionResult,
|
|
1402
|
-
URLBuilder,
|
|
1403
1351
|
YouVersionAPI,
|
|
1404
1352
|
YouVersionAPIUsers,
|
|
1405
1353
|
YouVersionPlatformConfiguration,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@youversion/platform-core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.9.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public",
|
|
@@ -42,6 +42,7 @@
|
|
|
42
42
|
"lint": "eslint . --max-warnings 0",
|
|
43
43
|
"typecheck": "tsc --noEmit",
|
|
44
44
|
"test": "dotenv -e .env.local -- vitest run",
|
|
45
|
+
"test:integration": "INTEGRATION_TESTS=true dotenv -e .env.local -- vitest run",
|
|
45
46
|
"test:watch": "dotenv -e .env.local -- vitest",
|
|
46
47
|
"test:coverage": "dotenv -e .env.local -- vitest run --coverage"
|
|
47
48
|
}
|