diff --git a/packages/core/src/api/authenticate.ts b/packages/core/src/api/authenticate.ts index 8a7e164a..7d6f0c2c 100644 --- a/packages/core/src/api/authenticate.ts +++ b/packages/core/src/api/authenticate.ts @@ -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} A promise that resolves with the authentication API response. */ -const authenticate = async (props: AuthApiRequestBody): Promise => { +const authenticate = async (props: AuthenticateProps): Promise => { let authnRequest: Request; let response: Response; diff --git a/packages/core/src/api/get-branding-preference-text.ts b/packages/core/src/api/get-branding-preference-text.ts index c57c4810..ef5031df 100644 --- a/packages/core/src/api/get-branding-preference-text.ts +++ b/packages/core/src/api/get-branding-preference-text.ts @@ -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. @@ -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 => { + const {locale, name, screen, type} = props; + const headers: Headers = new Headers(); headers.append('Accept', 'application/json'); headers.append('Content-Type', 'application/json'); diff --git a/packages/core/src/api/get-branding-preference.ts b/packages/core/src/api/get-branding-preference.ts index 50a5e300..4167ffaf 100644 --- a/packages/core/src/api/get-branding-preference.ts +++ b/packages/core/src/api/get-branding-preference.ts @@ -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} A promise that resolves with the branding preferences. + * @returns {Promise} 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 => { +const getBrandingPreference = async (): Promise => { const { baseUrl, type = BrandingPreferenceTypes.Org, @@ -42,7 +42,7 @@ const getBrandingPreference = async (): Promise; + return (await response.json()) as Promise; } throw new AsgardeoUIException( diff --git a/packages/core/src/auth-client.ts b/packages/core/src/auth-client.ts index 9e1786ed..955a334c 100644 --- a/packages/core/src/auth-client.ts +++ b/packages/core/src/auth-client.ts @@ -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'; /** @@ -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; diff --git a/packages/core/src/branding/default-branding/dark-theme.ts b/packages/core/src/branding/default-branding/dark-theme.ts index 1b1d11d3..3a0a3d15 100644 --- a/packages/core/src/branding/default-branding/dark-theme.ts +++ b/packages/core/src/branding/default-branding/dark-theme.ts @@ -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: { diff --git a/packages/core/src/branding/default-branding/default-branding.ts b/packages/core/src/branding/default-branding/default-branding.ts index 87810469..ad658d0e 100644 --- a/packages/core/src/branding/default-branding/default-branding.ts +++ b/packages/core/src/branding/default-branding/default-branding.ts @@ -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: { diff --git a/packages/core/src/branding/default-branding/light-theme.ts b/packages/core/src/branding/default-branding/light-theme.ts index 77dbb298..745c6d1e 100644 --- a/packages/core/src/branding/default-branding/light-theme.ts +++ b/packages/core/src/branding/default-branding/light-theme.ts @@ -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: { diff --git a/packages/core/src/branding/get-branding-css.ts b/packages/core/src/branding/get-branding-css.ts index c0219905..b0d64e25 100644 --- a/packages/core/src/branding/get-branding-css.ts +++ b/packages/core/src/branding/get-branding-css.ts @@ -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} 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 => { + 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) diff --git a/packages/core/src/branding/get-branding.ts b/packages/core/src/branding/get-branding.ts index c9516de2..64fb3754 100644 --- a/packages/core/src/branding/get-branding.ts +++ b/packages/core/src/branding/get-branding.ts @@ -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} A promise that resolves with the merged branding properties. + * @param {GetBrandingProps} props - Branding properties. + * @returns {Promise} A promise that resolves with the merged branding properties. */ -export const getBranding = async (props: GetBranding): Promise => { +const getBranding = async (props: GetBrandingProps): Promise => { 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(); @@ -50,7 +51,7 @@ export const getBranding = async (props: GetBranding): Promise => mergedBranding = merge(DEFAULT_BRANDING, customization ?? {}); } } else { - mergedBranding = merge(merged ?? {}, customization ?? {}); + mergedBranding = merge(merged, customization ?? {}); } return mergedBranding; diff --git a/packages/core/src/i18n/get-localization.ts b/packages/core/src/i18n/get-localization.ts index 934eb612..c8c0c96b 100644 --- a/packages/core/src/i18n/get-localization.ts +++ b/packages/core/src/i18n/get-localization.ts @@ -17,10 +17,12 @@ */ 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. @@ -28,19 +30,27 @@ import {BrandingPreferenceTextAPIResponse} from '../models/branding-text-api-res * @param {BrandingProps} props - Branding properties. * @returns {Promise} A promise that resolves with the merged branding properties. */ -const getLocalization = async (props: GetLocalization): Promise => { +const getLocalization = async (props: GetLocalizationProps): Promise => { 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, ); } diff --git a/packages/core/src/i18n/screens/model.ts b/packages/core/src/i18n/screens/model.ts index 32ba3cb1..3c15943d 100644 --- a/packages/core/src/i18n/screens/model.ts +++ b/packages/core/src/i18n/screens/model.ts @@ -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. @@ -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; -} diff --git a/packages/core/src/models/auth-api-request.ts b/packages/core/src/models/auth-api-request.ts index 6e48bb49..59ce7dea 100644 --- a/packages/core/src/models/auth-api-request.ts +++ b/packages/core/src/models/auth-api-request.ts @@ -19,7 +19,7 @@ /** * Interface for the Authn API request body. */ -export interface AuthApiRequestBody { +export interface AuthenticateProps { /** * The authentication flow id. */ diff --git a/packages/core/src/models/branding-api-response.ts b/packages/core/src/models/branding-api-response.ts index 3ba8e107..7e0dfbab 100644 --- a/packages/core/src/models/branding-api-response.ts +++ b/packages/core/src/models/branding-api-response.ts @@ -17,18 +17,18 @@ */ import { - BackgroundStyleAttributesInterface, - BorderStyleAttributesInterface, - ButtonStyleAttributesInterface, - ColorStyleAttributesInterface, - ElementStateInterface, - FontStyleAttributesInterface, + BackgroundStyleAttributes, + BorderStyleAttributes, + ButtonStyleAttributes, + ColorStyleAttributes, + ElementState, + FontStyleAttributes, } from './element-styles'; /** * Interface for the Branding Preference API response. */ -export interface BrandingPreferenceAPIResponseInterface { +export interface BrandingPreferenceAPIResponse { /** * Resource locale. */ @@ -40,7 +40,7 @@ export interface BrandingPreferenceAPIResponseInterface { /** * Preference object. */ - preference: BrandingPreferenceInterface; + preference: BrandingPreference; /** * Preference type. */ @@ -50,42 +50,42 @@ export interface BrandingPreferenceAPIResponseInterface { /** * Interface Branding preference object. */ -export interface BrandingPreferenceInterface { +export interface BrandingPreference { /** * Configurations. */ - configs: BrandingPreferenceConfigInterface; + configs: BrandingPreferenceConfig; /** * images such as Logo, Favicon, etc. * @deprecated Use the images object in `theme.[].images`. */ - images?: BrandingPreferenceImagesInterface; + images?: BrandingPreferenceImages; /** * Layout. */ - layout: BrandingPreferenceLayoutInterface; + layout: BrandingPreferenceLayout; /** * Organization's basic details. */ - organizationDetails: BrandingPreferenceOrganizationDetailsInterface; + organizationDetails: BrandingPreferenceOrganizationDetails; /** * Stylesheets for login pages etc.. */ - stylesheets?: BrandingPreferenceStylesheetsInterface; + stylesheets?: BrandingPreferenceStylesheets; /** * Theme. */ - theme: BrandingPreferenceThemeInterface; + theme: BrandingPreferenceTheme; /** * Links for policies, etc. */ - urls: BrandingPreferenceURLInterface; + urls: BrandingPreferenceURL; } /** * Interface Branding preference organization details. */ -export interface BrandingPreferenceOrganizationDetailsInterface { +export interface BrandingPreferenceOrganizationDetails { /** * Copyright for the footer. * @deprecated Moved to the `/branding-preference/text` API. @@ -109,25 +109,25 @@ export interface BrandingPreferenceOrganizationDetailsInterface { /** * Interface Branding preference images. */ -export interface BrandingPreferenceImagesInterface { +export interface BrandingPreferenceImages { /** * Organization Favicon. */ - favicon: Omit; + favicon: Omit; /** * Organization Logo. */ - logo: BrandingPreferenceImageInterface; + logo: BrandingPreferenceImage; /** * Organization My Account Logo. */ - myAccountLogo: BrandingPreferenceImageInterface; + myAccountLogo: BrandingPreferenceImage; } /** * Interface Branding preference image. */ -export interface BrandingPreferenceImageInterface { +export interface BrandingPreferenceImage { /** * Image Alt. */ @@ -145,7 +145,7 @@ export interface BrandingPreferenceImageInterface { /** * Interface Branding preference URLs. */ -export interface BrandingPreferenceURLInterface { +export interface BrandingPreferenceURL { /** * Link for Cookie Policy. */ @@ -163,70 +163,69 @@ export interface BrandingPreferenceURLInterface { /** * Interface Branding preference stylesheets. */ -export interface BrandingPreferenceStylesheetsInterface { +export interface BrandingPreferenceStylesheets { /** * Login portal stylesheet. */ accountApp: PredefinedThemes; } -export type BrandingPreferenceThemeInterface = StrictBrandingPreferenceThemeInterface & - DynamicBrandingPreferenceThemeInterface; +export type BrandingPreferenceTheme = StrictBrandingPreferenceTheme & DynamicBrandingPreferenceTheme; /** * Interface Branding preference theme. */ -export type DynamicBrandingPreferenceThemeInterface = { - [key in PredefinedThemesKeys]: ThemeConfigInterface; +export type DynamicBrandingPreferenceTheme = { + [key in PredefinedThemesKeys]: ThemeConfig; }; /** * Theme Configurations Interface. */ -export interface ThemeConfigInterface { +export interface ThemeConfig { /** * Button Preferences. */ - buttons: BrandingPreferenceButtonsInterface; + buttons: BrandingPreferenceButtons; /** * Color Palette. */ - colors: BrandingPreferenceColorsInterface; + colors: BrandingPreferenceColors; /** * Footer Preferences. */ - footer: BrandingPreferenceFooterInterface; + footer: BrandingPreferenceFooter; /** * images such as Logo, Favicon, etc. */ - images: BrandingPreferenceImagesInterface; + images: BrandingPreferenceImages; /** * Input Fields Preferences. */ - inputs: ElementStateInterface; + inputs: ElementState; /** * Login Box Preferences. */ - loginBox: BrandingPreferenceLoginBoxInterface; + loginBox: BrandingPreferenceLoginBox; /** * Login Page Preferences. */ - loginPage?: BrandingPreferencePageInterface; + loginPage?: BrandingPreferencePage; /** * Page Preferences. * @deprecated Renamed to `loginPage` to keep it specific for login page. */ - page?: BrandingPreferencePageInterface; + page?: BrandingPreferencePage; /** * Typography Preferences. */ - typography: BrandingPreferenceTypographyInterface; + typography: BrandingPreferenceTypography; } /** * Strict Interface Branding preference theme. */ -export interface StrictBrandingPreferenceThemeInterface { +export interface StrictBrandingPreferenceTheme { /** * The active theme. */ @@ -266,7 +265,7 @@ export interface PaletteColor { /** * Interface defining the color palette for a branding preference theme. */ -export interface BrandingPreferenceColorsInterface { +export interface BrandingPreferenceColors { /** * The alerts color palette of the theme. */ @@ -361,39 +360,39 @@ export interface BrandingPreferenceColorsInterface { /** * Interface Branding preference footer preferences. */ -export interface BrandingPreferenceFooterInterface { +export interface BrandingPreferenceFooter { /** * Page Body Font. */ - border: Pick; + border: Pick; /** * Page Body Font. */ - font: FontStyleAttributesInterface; + font: FontStyleAttributes; } /** * Interface Branding preference page preferences. */ -export interface BrandingPreferencePageInterface { +export interface BrandingPreferencePage { /** * Page Background. */ - background: BackgroundStyleAttributesInterface; + background: BackgroundStyleAttributes; /** * Page Body Font. */ - font: FontStyleAttributesInterface; + font: FontStyleAttributes; } /** * Interface for the Branding Preference Typography. */ -export interface BrandingPreferenceTypographyInterface { +export interface BrandingPreferenceTypography { /** * Page Font. */ - font: BrandingPreferenceTypographyFontInterface; + font: BrandingPreferenceTypographyFont; /** * Page Heading Typography. */ @@ -401,14 +400,14 @@ export interface BrandingPreferenceTypographyInterface { /** * Page Heading Font Preferences. */ - font: ColorStyleAttributesInterface; + font: ColorStyleAttributes; }; } /** * Interface for the Font Typography Font. */ -export interface BrandingPreferenceTypographyFontInterface { +export interface BrandingPreferenceTypographyFont { /** * Font Family. */ @@ -422,37 +421,37 @@ export interface BrandingPreferenceTypographyFontInterface { /** * Interface for the Login Box Preferences. */ -export interface BrandingPreferenceButtonsInterface { +export interface BrandingPreferenceButtons { /** * Social, External IDP Connection Button Preference. */ - externalConnection: ElementStateInterface; + externalConnection: ElementState; /** * Primary Button Preferences. */ - primary: ElementStateInterface>; + primary: ElementState>; /** * Secondary Button Preferences. */ - secondary: ElementStateInterface>; + secondary: ElementState>; } /** * Interface for the Login Box Preferences. */ -export interface BrandingPreferenceInputInterface { +export interface BrandingPreferenceInput { /** * Input field background. */ - background: BackgroundStyleAttributesInterface; + background: BackgroundStyleAttributes; /** * Secondary Button Preferences. */ - border: Pick; + border: Pick; /** * Input Field Font Preferences. */ - font: FontStyleAttributesInterface; + font: FontStyleAttributes; /** * Input Labels Preferences. */ @@ -460,35 +459,34 @@ export interface BrandingPreferenceInputInterface { /** * Input Labels Font Preferences. */ - font: FontStyleAttributesInterface; + font: FontStyleAttributes; }; } -export interface BrandingPreferenceLoginBoxInterface { +export interface BrandingPreferenceLoginBox { /** * Login Box Background. */ - background: BackgroundStyleAttributesInterface; + background: BackgroundStyleAttributes; /** * Login Box Border. */ - border: BorderStyleAttributesInterface; + border: BorderStyleAttributes; /** * Login Box Font. */ - font: FontStyleAttributesInterface; + font: FontStyleAttributes; } /** * Interface Branding preference layout. */ -export type BrandingPreferenceLayoutInterface = StrictBrandingPreferenceLayoutInterface & - Partial; +export type BrandingPreferenceLayout = StrictBrandingPreferenceLayout & Partial; /** * Strict Interface Branding preference layout. */ -export interface StrictBrandingPreferenceLayoutInterface { +export interface StrictBrandingPreferenceLayout { /** * The active layout. */ @@ -498,27 +496,26 @@ export interface StrictBrandingPreferenceLayoutInterface { /** * Interface dynamic branding preference layout. */ -export type DynamicBrandingPreferenceLayoutInterface = BrandingPreferenceSideImageLayoutInterface & - BrandingPreferenceSideAlignedLayoutInterface; +export type DynamicBrandingPreferenceLayout = BrandingPreferenceSideImageLayout & BrandingPreferenceSideAlignedLayout; /** * Left Image and Right Image layouts preference interface. */ -export interface BrandingPreferenceSideImageLayoutInterface { - sideImg: BrandingPreferenceImageInterface; +export interface BrandingPreferenceSideImageLayout { + sideImg: BrandingPreferenceImage; } /** * Left Aligned and Right Aligned layouts preference interface. */ -export interface BrandingPreferenceSideAlignedLayoutInterface { +export interface BrandingPreferenceSideAlignedLayout { productTagLine: string; } /** * Interface Branding preference configurations. */ -export interface BrandingPreferenceConfigInterface { +export interface BrandingPreferenceConfig { /** * Should the changes be published? */ diff --git a/packages/core/src/models/branding-text-api-response.ts b/packages/core/src/models/branding-text-api-response.ts index 2ae1a49f..30bb6bf0 100644 --- a/packages/core/src/models/branding-text-api-response.ts +++ b/packages/core/src/models/branding-text-api-response.ts @@ -20,9 +20,9 @@ import {BrandingPreferenceTypes} from './branding-api-response'; import {ScreenType} from './screen-type'; /** - * Branding preference text response interface. + * Interface for the props of the `getBrandingPreferenceText` function. */ -export interface BrandingPreferenceTextAPIResponse { +export interface GetBrandingPreferenceTextProps { /** * Locale to filter the retrieval of customizations. */ @@ -31,10 +31,6 @@ export interface BrandingPreferenceTextAPIResponse { * Tenant/Application name to filter the retrieval of customizations. */ name: string; - /** - * Branding text preference. - */ - preference: BrandingTextPreference; /** * Screen to filter the retrieval of customizations. */ @@ -45,6 +41,16 @@ export interface BrandingPreferenceTextAPIResponse { type: BrandingPreferenceTypes; } +/** + * Branding preference text response interface. + */ +export interface BrandingPreferenceTextAPIResponse extends GetBrandingPreferenceTextProps { + /** + * Branding text preference. + */ + preference: BrandingTextPreference; +} + /** * Branding text preference interface. */ diff --git a/packages/core/src/models/customization.ts b/packages/core/src/models/branding.ts similarity index 60% rename from packages/core/src/models/customization.ts rename to packages/core/src/models/branding.ts index 2a1fc058..972e929f 100644 --- a/packages/core/src/models/customization.ts +++ b/packages/core/src/models/branding.ts @@ -16,7 +16,7 @@ * under the License. */ -import {BrandingPreferenceInterface, BrandingPreferenceTypes} from './branding-api-response'; +import {BrandingPreference, BrandingPreferenceTypes} from './branding-api-response'; import {RecursivePartial} from './common'; import {TextPreference} from '../i18n/screens/model'; @@ -25,39 +25,30 @@ import {TextPreference} from '../i18n/screens/model'; */ export type BrandingPreferenceText = Record; -interface BrandingPreferenceWithText extends BrandingPreferenceInterface { - text: BrandingPreferenceText; +interface BrandingPreferenceWithText extends BrandingPreference { + text?: BrandingPreferenceText; } /** - * Interface for the customization object. + * Interface for the branding object. */ -export interface Customization { - locale?: string; +export interface Branding { + locale: string; /** * Requested resource name. */ - name?: string; + name: string; /** * Preference object. */ - preference?: RecursivePartial; + preference: BrandingPreferenceWithText; /** * Preference type. */ - type?: BrandingPreferenceTypes; + type: BrandingPreferenceTypes; } /** - * Interface for the getBranding function props. + * Type for the branding props. */ -export interface GetBranding { - /** - * Customization prop passed to the component/provider. - */ - customization?: Customization; - /** - * Merged customization object. - */ - merged?: Customization; -} +export type BrandingProps = RecursivePartial; diff --git a/packages/core/src/models/element-styles.ts b/packages/core/src/models/element-styles.ts index 7ef2afb3..3c86e8ae 100644 --- a/packages/core/src/models/element-styles.ts +++ b/packages/core/src/models/element-styles.ts @@ -21,38 +21,38 @@ import type * as CSS from 'csstype'; /** * Interface for the Primary Button Style Attributes.. */ -export interface ButtonStyleAttributesInterface { +export interface ButtonStyleAttributes { /** * Button Background. */ - background: BackgroundStyleAttributesInterface; + background: BackgroundStyleAttributes; /** * Button Border. */ - border: Pick; + border: Pick; /** * Button Text. */ - font: FontStyleAttributesInterface; + font: FontStyleAttributes; } /** * Color styles interface. * @remarks Extend with contrast, alpha. whenever necessary. */ -export type ColorStyleAttributesInterface = Pick; +export type ColorStyleAttributes = Pick; /** * Font styles interface. * @remarks Extend with font size, weight. whenever necessary. */ -export type FontStyleAttributesInterface = ColorStyleAttributesInterface; +export type FontStyleAttributes = ColorStyleAttributes; /** * Border styles interface. * @remarks Extend with borderStyle, etc. whenever necessary. */ -export type BorderStyleAttributesInterface = Pick & +export type BorderStyleAttributes = Pick & Pick & Pick; @@ -60,12 +60,12 @@ export type BorderStyleAttributesInterface = Pick * Background styles interface. * @remarks Extend with backgroundImage, backgroundSize, etc. whenever necessary. */ -export type BackgroundStyleAttributesInterface = Pick; +export type BackgroundStyleAttributes = Pick; /** * Generic interface for element states. * @remarks Extend with hover, active & other possible element states. */ -export interface ElementStateInterface { +export interface ElementState { base: T; } diff --git a/packages/core/src/models/get-branding-props.ts b/packages/core/src/models/get-branding-props.ts new file mode 100644 index 00000000..3beec285 --- /dev/null +++ b/packages/core/src/models/get-branding-props.ts @@ -0,0 +1,35 @@ +/** + * Copyright (c) 2024, WSO2 LLC. (https://www.wso2.com). + * + * WSO2 LLC. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import {Branding, BrandingProps} from './branding'; + +/** + * Interface for the getBranding function props. + */ +interface GetBrandingProps { + /** + * Customization prop passed to the component/provider. + */ + customization?: BrandingProps; + /** + * Merged customization object. + */ + merged?: Branding; +} + +export default GetBrandingProps; diff --git a/packages/core/src/models/get-localization-props.ts b/packages/core/src/models/get-localization-props.ts new file mode 100644 index 00000000..63abeb47 --- /dev/null +++ b/packages/core/src/models/get-localization-props.ts @@ -0,0 +1,44 @@ +/** + * Copyright (c) 2024, WSO2 LLC. (https://www.wso2.com). + * + * WSO2 LLC. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import {BrandingProps} from './branding'; +import {ScreenType} from './screen-type'; + +/** + * Interface for getLocalization function props. + */ +interface GetLocalizationProps { + /** + * Customiztion prop passed to the component + */ + componentCustomization?: BrandingProps; + /** + * Locale to filter the retrieval of localization. + */ + locale: string; + /** + * Customization prop passed to the provider + */ + providerCustomization?: BrandingProps; + /** + * Screen to filter the retrieval of localization. + */ + screen: ScreenType; +} + +export default GetLocalizationProps; diff --git a/packages/core/src/models/public-models.ts b/packages/core/src/models/public-models.ts index f770cf47..0e6b3dfa 100644 --- a/packages/core/src/models/public-models.ts +++ b/packages/core/src/models/public-models.ts @@ -20,6 +20,6 @@ export * from './auth-api-request'; export * from './auth-api-response'; export * from './auth-config'; export * from './branding-api-response'; -export * from './customization'; +export * from './branding'; export * from './me-api-response'; export * from './screen-type';