@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
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { YouVersionPlatformConfiguration } from './YouVersionPlatformConfiguration';
|
|
2
|
-
import type {
|
|
2
|
+
import type { AuthenticationScopes } from './types';
|
|
3
3
|
|
|
4
4
|
type SignInWithYouVersionPKCEParameters = {
|
|
5
5
|
readonly codeVerifier: string;
|
|
@@ -15,8 +15,8 @@ type SignInWithYouVersionPKCEAuthorizationRequest = {
|
|
|
15
15
|
export class SignInWithYouVersionPKCEAuthorizationRequestBuilder {
|
|
16
16
|
public static async make(
|
|
17
17
|
appKey: string,
|
|
18
|
-
permissions: Set<SignInWithYouVersionPermissionValues>,
|
|
19
18
|
redirectURL: URL,
|
|
19
|
+
scopes?: AuthenticationScopes[],
|
|
20
20
|
): Promise<SignInWithYouVersionPKCEAuthorizationRequest> {
|
|
21
21
|
const codeVerifier = this.randomURLSafeString(32);
|
|
22
22
|
const codeChallenge = await this.codeChallenge(codeVerifier);
|
|
@@ -30,16 +30,16 @@ export class SignInWithYouVersionPKCEAuthorizationRequestBuilder {
|
|
|
30
30
|
nonce,
|
|
31
31
|
};
|
|
32
32
|
|
|
33
|
-
const url = this.authorizeURL(appKey,
|
|
33
|
+
const url = this.authorizeURL(appKey, redirectURL, parameters, scopes);
|
|
34
34
|
|
|
35
35
|
return { url, parameters };
|
|
36
36
|
}
|
|
37
37
|
|
|
38
38
|
private static authorizeURL(
|
|
39
39
|
appKey: string,
|
|
40
|
-
permissions: Set<SignInWithYouVersionPermissionValues>,
|
|
41
40
|
redirectURL: URL,
|
|
42
41
|
parameters: SignInWithYouVersionPKCEParameters,
|
|
42
|
+
scopes?: AuthenticationScopes[],
|
|
43
43
|
): URL {
|
|
44
44
|
const components = new URL(`https://${YouVersionPlatformConfiguration.apiHost}/auth/authorize`);
|
|
45
45
|
|
|
@@ -61,7 +61,7 @@ export class SignInWithYouVersionPKCEAuthorizationRequestBuilder {
|
|
|
61
61
|
queryParams.set('x-yvp-installation-id', installId);
|
|
62
62
|
}
|
|
63
63
|
|
|
64
|
-
const scopeValue = this.scopeValue(
|
|
64
|
+
const scopeValue = this.scopeValue(scopes || []);
|
|
65
65
|
if (scopeValue) {
|
|
66
66
|
queryParams.set('scope', scopeValue);
|
|
67
67
|
}
|
|
@@ -109,8 +109,8 @@ export class SignInWithYouVersionPKCEAuthorizationRequestBuilder {
|
|
|
109
109
|
return base64.replace(/\+/g, '-').replace(/\//g, '_').replace(/=/g, '');
|
|
110
110
|
}
|
|
111
111
|
|
|
112
|
-
private static scopeValue(
|
|
113
|
-
const scopeArray = Array.from(
|
|
112
|
+
private static scopeValue(scopes: AuthenticationScopes[]): string | null {
|
|
113
|
+
const scopeArray = Array.from(scopes).sort();
|
|
114
114
|
let scopeWithOpenID = scopeArray.join(' ');
|
|
115
115
|
|
|
116
116
|
if (!scopeWithOpenID.split(' ').includes('openid')) {
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import type { SignInWithYouVersionPermissionValues } from './types';
|
|
2
|
-
|
|
3
1
|
export const SignInWithYouVersionPermission = {
|
|
4
2
|
bibles: 'bibles',
|
|
5
3
|
highlights: 'highlights',
|
|
@@ -13,7 +11,6 @@ type SignInWithYouVersionResultProps = {
|
|
|
13
11
|
expiresIn?: number;
|
|
14
12
|
refreshToken?: string;
|
|
15
13
|
idToken?: string;
|
|
16
|
-
permissions?: SignInWithYouVersionPermissionValues[];
|
|
17
14
|
yvpUserId?: string;
|
|
18
15
|
name?: string;
|
|
19
16
|
profilePicture?: string;
|
|
@@ -24,7 +21,6 @@ export class SignInWithYouVersionResult {
|
|
|
24
21
|
public readonly expiryDate: Date | undefined;
|
|
25
22
|
public readonly refreshToken: string | undefined;
|
|
26
23
|
public readonly idToken: string | undefined;
|
|
27
|
-
public readonly permissions: SignInWithYouVersionPermissionValues[] | undefined;
|
|
28
24
|
public readonly yvpUserId: string | undefined;
|
|
29
25
|
public readonly name: string | undefined;
|
|
30
26
|
public readonly profilePicture: string | undefined;
|
|
@@ -35,7 +31,6 @@ export class SignInWithYouVersionResult {
|
|
|
35
31
|
expiresIn,
|
|
36
32
|
refreshToken,
|
|
37
33
|
idToken,
|
|
38
|
-
permissions,
|
|
39
34
|
yvpUserId,
|
|
40
35
|
name,
|
|
41
36
|
profilePicture,
|
|
@@ -45,7 +40,6 @@ export class SignInWithYouVersionResult {
|
|
|
45
40
|
this.expiryDate = expiresIn ? new Date(Date.now() + expiresIn * 1000) : new Date();
|
|
46
41
|
this.refreshToken = refreshToken;
|
|
47
42
|
this.idToken = idToken;
|
|
48
|
-
this.permissions = permissions;
|
|
49
43
|
this.yvpUserId = yvpUserId;
|
|
50
44
|
this.name = name;
|
|
51
45
|
this.profilePicture = profilePicture;
|
package/src/Users.ts
CHANGED
|
@@ -1,25 +1,21 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { AuthenticationScopes } from './types';
|
|
2
2
|
import { YouVersionUserInfo } from './YouVersionUserInfo';
|
|
3
3
|
import { YouVersionPlatformConfiguration } from './YouVersionPlatformConfiguration';
|
|
4
4
|
import { SignInWithYouVersionPKCEAuthorizationRequestBuilder } from './SignInWithYouVersionPKCE';
|
|
5
5
|
import { SignInWithYouVersionResult } from './SignInWithYouVersionResult';
|
|
6
|
-
import { SignInWithYouVersionPermission } from './SignInWithYouVersionResult';
|
|
7
6
|
|
|
8
7
|
export class YouVersionAPIUsers {
|
|
9
8
|
/**
|
|
10
9
|
* Presents the YouVersion login flow to the user and returns the login result upon completion.
|
|
11
10
|
*
|
|
12
|
-
* This function authenticates the user with YouVersion
|
|
11
|
+
* This function authenticates the user with YouVersion.
|
|
13
12
|
* The function redirects to the YouVersion authorization URL and expects the callback to be handled separately.
|
|
14
13
|
*
|
|
15
|
-
* @param
|
|
14
|
+
* @param scopes - The scopes given to the authentication call.
|
|
16
15
|
* @param redirectURL - The URL to redirect back to after authentication.
|
|
17
16
|
* @throws An error if authentication fails or configuration is invalid.
|
|
18
17
|
*/
|
|
19
|
-
static async signIn(
|
|
20
|
-
permissions: Set<SignInWithYouVersionPermissionValues>,
|
|
21
|
-
redirectURL: string,
|
|
22
|
-
): Promise<void> {
|
|
18
|
+
static async signIn(redirectURL: string, scopes?: AuthenticationScopes[]): Promise<void> {
|
|
23
19
|
const appKey = YouVersionPlatformConfiguration.appKey;
|
|
24
20
|
if (!appKey) {
|
|
25
21
|
throw new Error('YouVersionPlatformConfiguration.appKey must be set before calling signIn');
|
|
@@ -27,8 +23,8 @@ export class YouVersionAPIUsers {
|
|
|
27
23
|
|
|
28
24
|
const authorizationRequest = await SignInWithYouVersionPKCEAuthorizationRequestBuilder.make(
|
|
29
25
|
appKey,
|
|
30
|
-
permissions,
|
|
31
26
|
new URL(redirectURL),
|
|
27
|
+
scopes,
|
|
32
28
|
);
|
|
33
29
|
|
|
34
30
|
// Store auth data for callback handler
|
|
@@ -184,22 +180,11 @@ export class YouVersionAPIUsers {
|
|
|
184
180
|
}): SignInWithYouVersionResult {
|
|
185
181
|
const idClaims = this.decodeJWT(tokens.id_token);
|
|
186
182
|
|
|
187
|
-
const permissions = tokens.scope
|
|
188
|
-
.split(' ')
|
|
189
|
-
.map((p) => p.trim())
|
|
190
|
-
.filter((p) => p.length > 0)
|
|
191
|
-
.filter((p): p is SignInWithYouVersionPermissionValues =>
|
|
192
|
-
Object.values(SignInWithYouVersionPermission).includes(
|
|
193
|
-
p as SignInWithYouVersionPermissionValues,
|
|
194
|
-
),
|
|
195
|
-
);
|
|
196
|
-
|
|
197
183
|
const resultData = {
|
|
198
184
|
accessToken: tokens.access_token,
|
|
199
185
|
expiresIn: tokens.expires_in,
|
|
200
186
|
refreshToken: tokens.refresh_token,
|
|
201
187
|
idToken: tokens.id_token,
|
|
202
|
-
permissions,
|
|
203
188
|
yvpUserId: idClaims.sub as string,
|
|
204
189
|
name: idClaims.name as string,
|
|
205
190
|
profilePicture: idClaims.profile_picture as string,
|
|
@@ -353,15 +338,6 @@ export class YouVersionAPIUsers {
|
|
|
353
338
|
expiresIn: tokens.expires_in,
|
|
354
339
|
refreshToken: tokens.refresh_token,
|
|
355
340
|
idToken: existingIdToken,
|
|
356
|
-
permissions: tokens.scope
|
|
357
|
-
.split(' ')
|
|
358
|
-
.map((p) => p.trim())
|
|
359
|
-
.filter((p) => p.length > 0)
|
|
360
|
-
.filter((p): p is SignInWithYouVersionPermissionValues =>
|
|
361
|
-
Object.values(SignInWithYouVersionPermission).includes(
|
|
362
|
-
p as SignInWithYouVersionPermissionValues,
|
|
363
|
-
),
|
|
364
|
-
),
|
|
365
341
|
});
|
|
366
342
|
|
|
367
343
|
// Store updated tokens
|