Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions packages/core/src/api/authenticate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,16 @@

import {AuthClient} from '../auth-client';
import AsgardeoUIException from '../exception';
import {AuthApiRequestBody} from '../models/auth-api-request';
import {AuthenticateProps} from '../models/auth-api-request';
import {AuthApiResponse} from '../models/auth-api-response';

/**
* Send an authentication request to the authentication API.
*
* @param {AuthApiRequestBody} props - The authentication request body.
* @param {AuthenticateProps} props - The authentication request body.
* @returns {Promise<AuthApiResponse>} A promise that resolves with the authentication API response.
*/
const authenticate = async (props: AuthApiRequestBody): Promise<AuthApiResponse> => {
const authenticate = async (props: AuthenticateProps): Promise<AuthApiResponse> => {
let authnRequest: Request;
let response: Response;

Expand Down
9 changes: 4 additions & 5 deletions packages/core/src/api/get-branding-preference-text.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

import {AuthClient} from '../auth-client';
import AsgardeoUIException from '../exception';
import {BrandingPreferenceTextAPIResponse} from '../models/branding-text-api-response';
import {BrandingPreferenceTextAPIResponse, GetBrandingPreferenceTextProps} from '../models/branding-text-api-response';

/**
* Fetch the branding preference text from the server.
Expand All @@ -31,11 +31,10 @@ import {BrandingPreferenceTextAPIResponse} from '../models/branding-text-api-res
* @throws {AsgardeoUIException} If the API call fails or when the response is not successful.
*/
const getBrandingPreferenceText = async (
locale: string,
name: string,
screen: string,
type: string,
props: GetBrandingPreferenceTextProps,
): Promise<BrandingPreferenceTextAPIResponse> => {
const {locale, name, screen, type} = props;

const headers: Headers = new Headers();
headers.append('Accept', 'application/json');
headers.append('Content-Type', 'application/json');
Expand Down
8 changes: 4 additions & 4 deletions packages/core/src/api/get-branding-preference.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@

import {AuthClient} from '../auth-client';
import AsgardeoUIException from '../exception';
import {BrandingPreferenceAPIResponseInterface, BrandingPreferenceTypes} from '../models/branding-api-response';
import {BrandingPreferenceAPIResponse, BrandingPreferenceTypes} from '../models/branding-api-response';

/**
* Fetch branding preferences from the server.
*
* @returns {Promise<BrandingPreferenceAPIResponseInterface>} A promise that resolves with the branding preferences.
* @returns {Promise<BrandingPreferenceAPIResponse>} A promise that resolves with the branding preferences.
* @throws {AsgardeoUIException} If an error occurs while fetching the branding preferences or when the response is unsuccessful.
*/
const getBrandingPreference = async (): Promise<BrandingPreferenceAPIResponseInterface> => {
const getBrandingPreference = async (): Promise<BrandingPreferenceAPIResponse> => {
const {
baseUrl,
type = BrandingPreferenceTypes.Org,
Expand All @@ -42,7 +42,7 @@ const getBrandingPreference = async (): Promise<BrandingPreferenceAPIResponseInt
}

if (response.ok) {
return (await response.json()) as Promise<BrandingPreferenceAPIResponseInterface>;
return (await response.json()) as Promise<BrandingPreferenceAPIResponse>;
}

throw new AsgardeoUIException(
Expand Down
9 changes: 7 additions & 2 deletions packages/core/src/auth-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* under the License.
*/

import {AsgardeoAuthClient, Store, CryptoUtils} from '@asgardeo/auth-js';
import {AsgardeoAuthClient, Store, CryptoUtils, ResponseMode} from '@asgardeo/auth-js';
import {UIAuthClient, UIAuthConfig} from './models/auth-config';

/**
Expand All @@ -42,8 +42,13 @@ export class AuthClient {
*/
static getInstance(authClientConfig?: UIAuthConfig, store?: Store, cryptoUtils?: CryptoUtils): UIAuthClient {
if (!AuthClient.instance) {
const extendedAuthClientConfig: UIAuthConfig = {
...authClientConfig,
responseMode: ResponseMode.direct,
};

AuthClient.instance = new AsgardeoAuthClient();
AuthClient.instance.initialize(authClientConfig, store, cryptoUtils);
AuthClient.instance.initialize(extendedAuthClientConfig, store, cryptoUtils);
}

return AuthClient.instance;
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/branding/default-branding/dark-theme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
* under the License.
*/

import {ThemeConfigInterface} from '../../models/branding-api-response';
import {ThemeConfig} from '../../models/branding-api-response';

const DARK_THEME: ThemeConfigInterface = {
const DARK_THEME: ThemeConfig = {
buttons: {
externalConnection: {
base: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@
import DARK_THEME from './dark-theme';
import LIGHT_THEME from './light-theme';
import {
BrandingPreferenceAPIResponseInterface,
BrandingPreferenceAPIResponse,
PredefinedThemes,
PredefinedLayouts,
BrandingPreferenceTypes,
} from '../../models/branding-api-response';

const DEFAULT_BRANDING: BrandingPreferenceAPIResponseInterface = {
const DEFAULT_BRANDING: BrandingPreferenceAPIResponse = {
locale: 'en-US',
name: '',
preference: {
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/branding/default-branding/light-theme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
* under the License.
*/

import {ThemeConfigInterface} from '../../models/branding-api-response';
import {ThemeConfig} from '../../models/branding-api-response';

const LIGHT_THEME: ThemeConfigInterface = {
const LIGHT_THEME: ThemeConfig = {
buttons: {
externalConnection: {
base: {
Expand Down
26 changes: 23 additions & 3 deletions packages/core/src/branding/get-branding-css.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,34 @@
* under the License.
*/

import {BrandingPreferenceThemeInterface, ThemeConfigInterface} from '../models/branding-api-response';
import isEmpty from 'lodash.isempty';
import getBranding from './get-branding';
import {ThemeConfig} from '../models/branding-api-response';
import GetBrandingProps from '../models/get-branding-props';

/**
* Generate a CSS string based on branding properties.
*
* This function retrieves the branding preferences based on the provided props,
* then generates a CSS string based on the active theme within those preferences.
* If no active theme is found, an empty string is returned.
*
* @param {GetBrandingProps} props - The properties used to retrieve the branding preferences.
* @returns {Promise<string>} A promise that resolves to a CSS string. If no theme is found,
* the promise resolves to an empty string.
*
* @example
* getBrandingCSS(props).then(css => {
* // do something with the css string
* });
*/
const getBrandingCSS = async (props: GetBrandingProps): Promise<string> => {
const {theme} = (await getBranding(props)).preference;

const getBrandingCSS = (theme: BrandingPreferenceThemeInterface): string => {
if (!theme) {
return '';
}
const activeTheme: ThemeConfigInterface = theme[theme.activeTheme];
const activeTheme: ThemeConfig = theme[theme.activeTheme];

const footerFontColor: string = !isEmpty(activeTheme.footer.font.color) ? activeTheme.footer.font.color : 'inherit';
const headingFontColor: string = !isEmpty(activeTheme.typography.heading.font.color)
Expand Down
17 changes: 9 additions & 8 deletions packages/core/src/branding/get-branding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,25 +20,26 @@ import merge from 'lodash.merge';
import DEFAULT_BRANDING from './default-branding/default-branding';
import getBrandingPreference from '../api/get-branding-preference';
import {AuthClient} from '../auth-client';
import {BrandingPreferenceAPIResponseInterface} from '../models/branding-api-response';
import {Customization, GetBranding} from '../models/customization';
import {Branding} from '../models/branding';
import {BrandingPreferenceAPIResponse} from '../models/branding-api-response';
import GetBrandingProps from '../models/get-branding-props';

/**
* Fetch and merge branding properties.
*
* @param {GetBranding} props - Branding properties.
* @returns {Promise<Customization>} A promise that resolves with the merged branding properties.
* @param {GetBrandingProps} props - Branding properties.
* @returns {Promise<Branding>} A promise that resolves with the merged branding properties.
*/
export const getBranding = async (props: GetBranding): Promise<Customization> => {
const getBranding = async (props: GetBrandingProps): Promise<Branding> => {
const {customization, merged} = props;
let mergedBranding: Customization;
let mergedBranding: Branding;

/**
* If the `merged` prop is not provided, fetch the branding from the console and merge it with the default branding.
* If the `merged` prop is provided, merge it with the branding props.
*/
if (!merged) {
let brandingFromConsole: BrandingPreferenceAPIResponseInterface;
let brandingFromConsole: BrandingPreferenceAPIResponse;

if ((await AuthClient.getInstance().getDataLayer().getConfigData()).enableConsoleBranding ?? true) {
brandingFromConsole = await getBrandingPreference();
Expand All @@ -50,7 +51,7 @@ export const getBranding = async (props: GetBranding): Promise<Customization> =>
mergedBranding = merge(DEFAULT_BRANDING, customization ?? {});
}
} else {
mergedBranding = merge(merged ?? {}, customization ?? {});
mergedBranding = merge(merged, customization ?? {});
}

return mergedBranding;
Expand Down
26 changes: 18 additions & 8 deletions packages/core/src/i18n/get-localization.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,30 +17,40 @@
*/

import merge from 'lodash.merge';
import {GetLocalization, TextObject} from './screens/model';
import {TextObject} from './screens/model';
import getBrandingPreferenceText from '../api/get-branding-preference-text';
import {AuthClient} from '../auth-client';
import AsgardeoUIException from '../exception';
import {BrandingPreferenceTextAPIResponse} from '../models/branding-text-api-response';
import GetLocalizationProps from '../models/get-localization-props';

/**
* Fetch and merge branding properties.
*
* @param {BrandingProps} props - Branding properties.
* @returns {Promise<Customization>} A promise that resolves with the merged branding properties.
*/
const getLocalization = async (props: GetLocalization): Promise<TextObject> => {
const getLocalization = async (props: GetLocalizationProps): Promise<TextObject> => {
const {componentCustomization, locale, providerCustomization, screen} = props;

const module: TextObject = await import(`./screens/${screen}/${locale}.ts`);

let textFromConsoleBranding: BrandingPreferenceTextAPIResponse;

if ((await AuthClient.getInstance().getDataLayer().getConfigData()).enableConsoleTextBranding ?? true) {
textFromConsoleBranding = await getBrandingPreferenceText(
locale,
providerCustomization.name,
screen,
providerCustomization.type,
try {
if ((await AuthClient.getInstance().getDataLayer().getConfigData()).enableConsoleTextBranding ?? true) {
textFromConsoleBranding = await getBrandingPreferenceText(
locale,
providerCustomization.name,
screen,
providerCustomization.type,
);
}
} catch (error) {
throw new AsgardeoUIException(
'JS_UI_CORE-LOCALIZATION-IV',
'Error occurred while fetching text from console branding.',
error.stack,
);
}

Expand Down
24 changes: 0 additions & 24 deletions packages/core/src/i18n/screens/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@
import {Common} from './common/model';
import {Login} from './login/model';
import {TOTP} from './totp/model';
import {Customization} from '../../models/customization';
import {ScreenType} from '../../models/screen-type';

/**
* Interface for the text preference.
Expand All @@ -35,25 +33,3 @@ export interface TextPreference {
* Interface for the return type of the getLocalization function.
*/
export type TextObject = Login | TOTP | Common;

/**
* Interface for getLocalization function props.
*/
export interface GetLocalization {
/**
* Customiztion prop passed to the component
*/
componentCustomization?: Customization;
/**
* Locale to filter the retrieval of localization.
*/
locale: string;
/**
* Customization prop passed to the provider
*/
providerCustomization?: Customization;
/**
* Screen to filter the retrieval of localization.
*/
screen: ScreenType;
}
2 changes: 1 addition & 1 deletion packages/core/src/models/auth-api-request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
/**
* Interface for the Authn API request body.
*/
export interface AuthApiRequestBody {
export interface AuthenticateProps {
/**
* The authentication flow id.
*/
Expand Down
Loading