-
Notifications
You must be signed in to change notification settings - Fork 37
feat(core): add branding #3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
158d04d
feat(core): :sparkles: add branding function to retrieve branding pre…
movinsilva bbb4d6c
style(core): :art: update naming for enums in branding
movinsilva 3e8daa4
feat(core): :label: add recursivePartial type & customization interface
movinsilva 88a053d
feat(core): :sparkles: add default translations for en-US & fr-FR
movinsilva 95e37f4
feat(core): :sparkles: add default branding objects
movinsilva 5f71aca
feat(core): :sparkles: add getBranding function
movinsilva bdb44e4
feat(core): :technologist: improve branding function
movinsilva 8e979f7
feat(core): :sparkles: add brandingText function
movinsilva 32d8480
refactor(core): :art: update error codes
movinsilva d0cfea9
feat(core): :sparkles: add getLocalization function
movinsilva 7219dfd
fix(core): :bug: modify getBranding function
movinsilva b47a515
refactor(core): :label: add types in getLocalization function
movinsilva 89f9529
docs(core): :memo: update internal header
movinsilva 936e4fb
fix(core): :art: fix formatting issues
movinsilva 39532ad
refactor(core): :recycle: relocate GetLocalization interface
movinsilva e10a6e9
refactor(core): :art: reorganize variables
movinsilva 3df960e
docs(core): :memo: update js docs for functions
movinsilva db71f90
refactor(core): :recycle: relocate & rename GetBranding props interface
movinsilva 3249e99
docs(core): :memo: add comments for interfaces and types in customiza…
movinsilva 72d1d33
chore(core): :wrench: override lint rule
movinsilva d78cd70
docs(core): :art: improve comments in getLocalization function
movinsilva 556a906
fix(core): :bug: update copyright string
movinsilva 4a57977
docs(core): :memo: add comments for BrandingPreferenceTypes enum
movinsilva adb5461
refactor(core): :recycle: rename branding function and file
movinsilva 3951760
refactor(core): :recycle: rename brandingText function, file and the …
movinsilva File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
/** | ||
* 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 {AuthClient} from 'src/auth-client'; | ||
import AsgardeoUIException from 'src/exception'; | ||
import {BrandingPreferenceTextAPIResponse} from 'src/models/branding-text-api-response'; | ||
|
||
/** | ||
* Fetch the branding preference text from the server. | ||
* | ||
* @param locale - The locale of the branding text. | ||
* @param name - The name of the branding text. | ||
* @param screen - The screen of the branding text. | ||
* @param type - The type of the branding text. | ||
* @returns A Promise that resolves to the response from the server. | ||
* @throws {AsgardeoUIException} If the API call fails or when the response is not successful. | ||
*/ | ||
export const getBrandingPreferenceText = async ( | ||
locale: string, | ||
name: string, | ||
screen: string, | ||
type: string, | ||
): Promise<BrandingPreferenceTextAPIResponse> => { | ||
const headers: Headers = new Headers(); | ||
headers.append('Accept', 'application/json'); | ||
headers.append('Content-Type', 'application/json'); | ||
|
||
const requestOptions: RequestInit = { | ||
headers, | ||
method: 'GET', | ||
}; | ||
|
||
const params: URLSearchParams = new URLSearchParams(); | ||
params.append('locale', locale); | ||
params.append('name', name); | ||
params.append('screen', screen); | ||
params.append('type', type); | ||
|
||
const {baseUrl} = await AuthClient.getInstance().getDataLayer().getConfigData(); | ||
const textUrl: string = `${baseUrl}/api/server/v1/branding-preference/text/resolve`; | ||
const urlWithParams: string = `${textUrl}?${params.toString()}`; | ||
let response: Response; | ||
|
||
try { | ||
response = await fetch(new Request(urlWithParams, requestOptions)); | ||
} catch (error) { | ||
throw new AsgardeoUIException('JS_UI_CORE-BT-GBPT-NE', 'Branding Text API call failed', error.stack); | ||
} | ||
|
||
if (response.ok) { | ||
return (await response.json()) as BrandingPreferenceTextAPIResponse; | ||
} | ||
|
||
throw new AsgardeoUIException( | ||
'JS_UI_CORE-BT-GBPT-HE', | ||
'Failed to receive a successful response from the branding text endpoint', | ||
); | ||
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/** | ||
* 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 {AuthClient} from '../auth-client'; | ||
import AsgardeoUIException from '../exception'; | ||
import {BrandingPreferenceAPIResponseInterface, BrandingPreferenceTypes} from '../models/branding-api-response'; | ||
|
||
/** | ||
* Fetch branding preferences from the server. | ||
* | ||
* @returns {Promise<BrandingPreferenceAPIResponseInterface>} 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 { | ||
baseUrl, | ||
type = BrandingPreferenceTypes.Org, | ||
name = 'WSO2', | ||
} = await AuthClient.getInstance().getDataLayer().getConfigData(); | ||
const brandingUrl: string = `${baseUrl}/api/server/v1/branding-preference?type=${type}&name=${name}`; | ||
let response: Response; | ||
|
||
try { | ||
response = await fetch(brandingUrl); | ||
} catch (error) { | ||
throw new AsgardeoUIException('JS_UI_CORE-BR-GBP-NE', 'Error while fetching branding data.', error.stack); | ||
} | ||
|
||
if (response.ok) { | ||
return (await response.json()) as Promise<BrandingPreferenceAPIResponseInterface>; | ||
} | ||
|
||
throw new AsgardeoUIException( | ||
'JS_UI_CORE-BR-GBP-HE', | ||
'Failed to receive a successful response from the branding API.', | ||
); | ||
}; | ||
|
||
export default getBrandingPreference; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/** | ||
* 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 merge from 'lodash.merge'; | ||
import getBrandingPreference from 'src/api/branding-preference'; | ||
import {AuthClient} from 'src/auth-client'; | ||
import {BrandingPreferenceAPIResponseInterface} from 'src/models/branding-api-response'; | ||
import DEFAULT_BRANDING from './default-branding/default-branding'; | ||
import {Customization, GetBranding} from '../models/customization'; | ||
|
||
/** | ||
* Fetch and merge branding properties. | ||
* | ||
* @param {GetBranding} props - Branding properties. | ||
* @returns {Promise<Customization>} A promise that resolves with the merged branding properties. | ||
*/ | ||
export const getBranding = async (props: GetBranding): Promise<Customization> => { | ||
const {customization, merged} = props; | ||
let mergedBranding: Customization; | ||
|
||
/** | ||
* 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; | ||
|
||
if ((await AuthClient.getInstance().getDataLayer().getConfigData()).enableConsoleBranding ?? true) { | ||
brandingFromConsole = await getBrandingPreference(); | ||
} | ||
|
||
if (brandingFromConsole?.preference?.configs?.isBrandingEnabled) { | ||
mergedBranding = await merge(DEFAULT_BRANDING, brandingFromConsole ?? {}, customization ?? {}); | ||
} else { | ||
mergedBranding = await merge(DEFAULT_BRANDING, customization ?? {}); | ||
} | ||
} else { | ||
mergedBranding = await merge(merged ?? {}, customization ?? {}); | ||
} | ||
|
||
return mergedBranding; | ||
}; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shall we have space after
{
. Let's check why this is not checked in Eslint?