From 6cc94ab21cd37baf9915dc14d72e8cf0b9cea3f1 Mon Sep 17 00:00:00 2001 From: Leo Chen Date: Wed, 20 Mar 2024 10:17:06 +1100 Subject: [PATCH] chore: prettier fix --- CHANGELOG.md | 2 -- .../utilities/generateRandomString.spec.ts | 3 +-- .../utilities/validate-client-secret.spec.ts | 2 +- lib/sdk/clients/browser/authcode-with-pkce.ts | 12 ++++----- lib/sdk/clients/server/authorization-code.ts | 8 +++--- lib/sdk/oauth2-flows/AuthCodeAbstract.ts | 26 ++++++++++++------- lib/sdk/oauth2-flows/ClientCredentials.ts | 11 ++++---- lib/sdk/utilities/random-string.ts | 6 +++-- lib/sdk/utilities/validate-client-secret.ts | 6 ++--- 9 files changed, 40 insertions(+), 36 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 130f05d..769c544 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,5 @@ # Changelog - ## b6bda8a4ff4564a6ae8fd8e180f3b57d2eaa5eb6...main [compare changes](https://github.com/kinde-oss/kinde-typescript-sdk/compare/b6bda8a4ff4564a6ae8fd8e180f3b57d2eaa5eb6...main) @@ -39,4 +38,3 @@ ## 2.7.0...2.7.0 [compare changes](https://github.com/kinde-oss/kinde-typescript-sdk/compare/2.7.0...2.7.0) - diff --git a/lib/__tests__/sdk/utilities/generateRandomString.spec.ts b/lib/__tests__/sdk/utilities/generateRandomString.spec.ts index 12f4f4d..902822f 100644 --- a/lib/__tests__/sdk/utilities/generateRandomString.spec.ts +++ b/lib/__tests__/sdk/utilities/generateRandomString.spec.ts @@ -6,7 +6,6 @@ describe('validateClientSecret', () => { expect(result.length).toBe(25); }); - it('should return false for invalid secrets - odd length', () => { const result = generateRandomString(47); expect(result.length).toBe(47); @@ -16,4 +15,4 @@ describe('validateClientSecret', () => { const result = generateRandomString(50); expect(result.length).toBe(50); }); -}); \ No newline at end of file +}); diff --git a/lib/__tests__/sdk/utilities/validate-client-secret.spec.ts b/lib/__tests__/sdk/utilities/validate-client-secret.spec.ts index bc3e34d..e49c979 100644 --- a/lib/__tests__/sdk/utilities/validate-client-secret.spec.ts +++ b/lib/__tests__/sdk/utilities/validate-client-secret.spec.ts @@ -12,4 +12,4 @@ describe('validateClientSecret', () => { const result = validateClientSecret(invalidSecret); expect(result).toBe(false); }); -}); \ No newline at end of file +}); diff --git a/lib/sdk/clients/browser/authcode-with-pkce.ts b/lib/sdk/clients/browser/authcode-with-pkce.ts index 166050a..ebfd6f4 100644 --- a/lib/sdk/clients/browser/authcode-with-pkce.ts +++ b/lib/sdk/clients/browser/authcode-with-pkce.ts @@ -16,9 +16,7 @@ import type { BrowserPKCEClientOptions, } from '../types.js'; -import type { - OAuth2CodeExchangeResponse, -} from '../../oauth2-flows/types.js'; +import type { OAuth2CodeExchangeResponse } from '../../oauth2-flows/types.js'; const createAuthCodeWithPKCEClient = (options: BrowserPKCEClientOptions) => { const { featureFlags, tokenClaims } = utilities; @@ -271,15 +269,15 @@ const createAuthCodeWithPKCEClient = (options: BrowserPKCEClientOptions) => { const getToken = async (): Promise => { return await client.getToken(sessionManager); }; - + /** * Method makes user of the `refreshTokens` method of the `AuthCodeWithPKCE` client * to use the refresh token to get new tokens * @returns {Promise} */ - const refreshTokens = async (): Promise => { - return await client.refreshTokens(sessionManager); - }; + const refreshTokens = async (): Promise => { + return await client.refreshTokens(sessionManager); + }; /** * Method extracts the provided feature flag from the access token in the diff --git a/lib/sdk/clients/server/authorization-code.ts b/lib/sdk/clients/server/authorization-code.ts index 616494c..b841b52 100644 --- a/lib/sdk/clients/server/authorization-code.ts +++ b/lib/sdk/clients/server/authorization-code.ts @@ -11,9 +11,7 @@ import type { ACClientOptions, } from '../types.js'; -import type { - OAuth2CodeExchangeResponse, -} from '../../oauth2-flows/types.js'; +import type { OAuth2CodeExchangeResponse } from '../../oauth2-flows/types.js'; const createAuthorizationCodeClient = ( options: ACClientOptions, @@ -143,7 +141,9 @@ const createAuthorizationCodeClient = ( * @param {SessionManager} sessionManager * @returns {Promise} */ - const refreshTokens = async (sessionManager: SessionManager): Promise => { + const refreshTokens = async ( + sessionManager: SessionManager + ): Promise => { return await client.refreshTokens(sessionManager); }; diff --git a/lib/sdk/oauth2-flows/AuthCodeAbstract.ts b/lib/sdk/oauth2-flows/AuthCodeAbstract.ts index 788d680..f163240 100644 --- a/lib/sdk/oauth2-flows/AuthCodeAbstract.ts +++ b/lib/sdk/oauth2-flows/AuthCodeAbstract.ts @@ -243,7 +243,7 @@ export abstract class AuthCodeAbstract { protected generateAuthURLParams(options: AuthURLOptions = {}): URLSearchParams { const searchParams = this.getBaseAuthURLParams(); - let scope = this.config.scope ?? AuthCodeAbstract.DEFAULT_TOKEN_SCOPES + let scope = this.config.scope ?? AuthCodeAbstract.DEFAULT_TOKEN_SCOPES; scope = scope.split(' ').includes('openid') ? scope : `${scope} openid`; let searchParamsObject: Record = { @@ -264,17 +264,22 @@ export abstract class AuthCodeAbstract { } if (options.authUrlParams) { - const { lang, login_hint: loginHint, connection_id: connectionId, ...rest } = options.authUrlParams; + const { + lang, + login_hint: loginHint, + connection_id: connectionId, + ...rest + } = options.authUrlParams; searchParamsObject = { ...rest, ...searchParamsObject }; - + if (lang) { searchParamsObject.lang = lang; } - + if (loginHint) { searchParamsObject.login_hint = loginHint; } - + if (connectionId) { searchParamsObject.connection_id = connectionId; } @@ -290,12 +295,13 @@ export abstract class AuthCodeAbstract { } if (this.config.audience) { - const audienceArray = Array.isArray(this.config.audience) ? this.config.audience : [this.config.audience]; + const audienceArray = Array.isArray(this.config.audience) + ? this.config.audience + : [this.config.audience]; - audienceArray - .forEach((aud) => { - searchParams.append('audience', aud); - }); + audienceArray.forEach((aud) => { + searchParams.append('audience', aud); + }); } return searchParams; diff --git a/lib/sdk/oauth2-flows/ClientCredentials.ts b/lib/sdk/oauth2-flows/ClientCredentials.ts index 0b09e13..118e971 100644 --- a/lib/sdk/oauth2-flows/ClientCredentials.ts +++ b/lib/sdk/oauth2-flows/ClientCredentials.ts @@ -121,12 +121,13 @@ export class ClientCredentials { } if (this.config.audience) { - const audienceArray = Array.isArray(this.config.audience) ? this.config.audience : [this.config.audience]; + const audienceArray = Array.isArray(this.config.audience) + ? this.config.audience + : [this.config.audience]; - audienceArray - .forEach((aud) => { - searchParams.append('audience', aud); - }); + audienceArray.forEach((aud) => { + searchParams.append('audience', aud); + }); } return new URLSearchParams(searchParams); diff --git a/lib/sdk/utilities/random-string.ts b/lib/sdk/utilities/random-string.ts index 8cbf6d4..abea87b 100644 --- a/lib/sdk/utilities/random-string.ts +++ b/lib/sdk/utilities/random-string.ts @@ -9,10 +9,12 @@ export const generateRandomString = (length: number = 28): string => { const bytesNeeded = Math.ceil(length / 2); const array = new Uint32Array(bytesNeeded); getRandomValues(array); - let result = Array.from(array, (dec) => ('0' + dec.toString(16)).slice(-2)).join(''); + let result = Array.from(array, (dec) => ('0' + dec.toString(16)).slice(-2)).join( + '' + ); if (length % 2 !== 0) { // If the requested length is odd, remove the last character to adjust the length result = result.slice(0, -1); } return result; -}; \ No newline at end of file +}; diff --git a/lib/sdk/utilities/validate-client-secret.ts b/lib/sdk/utilities/validate-client-secret.ts index 0290eff..ee8f054 100644 --- a/lib/sdk/utilities/validate-client-secret.ts +++ b/lib/sdk/utilities/validate-client-secret.ts @@ -1,8 +1,8 @@ /** * Validates that the supplied client secret is in the correct format. * @param {string} secret - * @returns {boolean} + * @returns {boolean} */ export const validateClientSecret = (secret: string): boolean => { - return !!secret.match('^[a-zA-Z0-9]{40,60}$')?.length -}; \ No newline at end of file + return !!secret.match('^[a-zA-Z0-9]{40,60}$')?.length; +};