Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
c11bfd3
feat(react): :sparkles: add cryptoutils class and required packages
movinsilva May 11, 2024
57aadea
feat(react): :sparkles: add SessionStore class
movinsilva May 11, 2024
5b32856
feat(react): :sparkles: add AsgardeoProvider & asgardeoContext
movinsilva May 11, 2024
c0bd7e8
fix(core): :bug: fix parameter passing to getLocalization function
movinsilva May 11, 2024
d17f0b0
feat(react): :sparkles: add BrandingPreferenceProvider and brandingPr…
movinsilva May 11, 2024
41be6db
refactor(core): :recycle: rename a parameter of getBranding function
movinsilva May 11, 2024
8c949e1
fix(react): :coffin: update parameter name of getBranding function
movinsilva May 11, 2024
d8f21aa
fix(auth-components): :lipstick: update styling of SignInTypography a…
movinsilva May 14, 2024
34fad5f
refactor(auth-components): :recycle: refactor SignInComponent's child…
movinsilva May 14, 2024
cb1129e
fix(react): :fire: remove branding css functions from BrandingPrefere…
movinsilva May 14, 2024
f0e60a6
feat(react): :sparkles: add generateTheme
movinsilva May 14, 2024
83cc49b
feat(react): :sparkles: add i18n context
movinsilva May 14, 2024
16346d4
feat(react): :sparkles: add I18nProvider
movinsilva May 14, 2024
f95920a
refactor(core): :recycle: refactor getLocalization function
movinsilva May 14, 2024
92a994f
feat(react): :sparkles: add useAuthentication hook
movinsilva May 14, 2024
b620fc0
feat(react): :sparkles: add useConfig hook
movinsilva May 14, 2024
7280565
feat(react): :sparkles: add useTranslations hook
movinsilva May 14, 2024
0090aa9
refactor(react): :recycle: refactor and add comments for useAuthentic…
movinsilva May 14, 2024
23a3785
docs(react): :memo: add jsdocs
movinsilva May 14, 2024
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
8 changes: 4 additions & 4 deletions packages/core/src/branding/get-branding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import GetBrandingProps from '../models/get-branding-props';
* @returns {Promise<Branding>} A promise that resolves with the merged branding properties.
*/
const getBranding = async (props: GetBrandingProps): Promise<Branding> => {
const {customization, merged} = props;
const {branding, merged} = props;
let mergedBranding: Branding;

/**
Expand All @@ -46,12 +46,12 @@ const getBranding = async (props: GetBrandingProps): Promise<Branding> => {
}

if (brandingFromConsole?.preference?.configs?.isBrandingEnabled) {
mergedBranding = merge(DEFAULT_BRANDING, brandingFromConsole ?? {}, customization ?? {});
mergedBranding = merge(DEFAULT_BRANDING, brandingFromConsole ?? {}, branding ?? {});
} else {
mergedBranding = merge(DEFAULT_BRANDING, customization ?? {});
mergedBranding = merge(DEFAULT_BRANDING, branding ?? {});
}
} else {
mergedBranding = merge(merged, customization ?? {});
mergedBranding = merge(merged, branding ?? {});
}

return mergedBranding;
Expand Down
21 changes: 13 additions & 8 deletions packages/core/src/i18n/get-localization.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,14 @@
* under the License.
*/

import {AuthClientConfig} from '@asgardeo/auth-js';
import merge from 'lodash.merge';
import {TextObject} from './screens/model';
import getBrandingPreferenceText from '../api/get-branding-preference-text';
import {AuthClient} from '../auth-client';
import AsgardeoUIException from '../exception';
import {UIAuthConfig} from '../models/auth-config';
import {BrandingPreferenceTypes} from '../models/branding-api-response';
import {BrandingPreferenceTextAPIResponse} from '../models/branding-text-api-response';
import GetLocalizationProps from '../models/get-localization-props';

Expand All @@ -31,20 +34,22 @@ import GetLocalizationProps from '../models/get-localization-props';
* @returns {Promise<Customization>} A promise that resolves with the merged branding properties.
*/
const getLocalization = async (props: GetLocalizationProps): Promise<TextObject> => {
const {componentCustomization, locale, providerCustomization, screen} = props;
const {componentTextOverrides, locale, providerTextOverrides, screen} = props;

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

let textFromConsoleBranding: BrandingPreferenceTextAPIResponse;

const configData: AuthClientConfig<UIAuthConfig> = await AuthClient.getInstance().getDataLayer().getConfigData();

try {
if ((await AuthClient.getInstance().getDataLayer().getConfigData()).enableConsoleTextBranding ?? true) {
textFromConsoleBranding = await getBrandingPreferenceText(
if (configData.enableConsoleTextBranding ?? true) {
textFromConsoleBranding = await getBrandingPreferenceText({
locale,
providerCustomization.name,
name: configData.name ?? 'carbon.super',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's move to a seperate constant?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wil address this in the next PR.

screen,
providerCustomization.type,
);
type: configData.type ?? BrandingPreferenceTypes.Org,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's check and nullable checks if required.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wil address this in the next PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The config cannot be nullable. Application cannot reach this far, if this is nullable. I think it is expected to break, in case this becomes nullable.

});
}
} catch (error) {
throw new AsgardeoUIException(
Expand All @@ -69,11 +74,11 @@ const getLocalization = async (props: GetLocalizationProps): Promise<TextObject>
/**
* PRIORITY 02: Text from provider customization
*/
providerCustomization?.preference?.text?.[locale]?.[screen] ?? {},
providerTextOverrides?.[locale]?.[screen] ?? {},
/**
* PRIORITY 01: Text from component customization
*/
componentCustomization?.preference?.text?.[locale]?.[screen] ?? {},
componentTextOverrides?.[locale]?.[screen] ?? {},
);

return mergedText;
Expand Down
12 changes: 2 additions & 10 deletions packages/core/src/models/auth-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
*/

import {AsgardeoAuthClient, AuthClientConfig} from '@asgardeo/auth-js';
import {BrandingPreferenceTypes} from './branding-api-response';

/**
* Interface for the configuration extension from the AuthClientConfig of '@asgardeo/auth-js'.
Expand All @@ -39,16 +40,7 @@ interface AuthClientConfigExtension {
/**
* Type to filter the retrieval of customizations.
*/
type?: OrgType;
}

/**
* Enum for the organization type.
*/
export enum OrgType {
App = 'APP',
Custom = 'CUSTOM',
Org = 'ORG',
type?: BrandingPreferenceTypes;
}

/**
Expand Down
2 changes: 2 additions & 0 deletions packages/core/src/models/branding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ import {TextPreference} from '../i18n/screens/model';
*/
export type BrandingPreferenceText = Record<string, TextPreference>;

export type BrandingPreferenceTextProps = RecursivePartial<BrandingPreferenceText>;

interface BrandingPreferenceWithText extends BrandingPreference {
text?: BrandingPreferenceText;
}
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/models/get-branding-props.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ interface GetBrandingProps {
/**
* Customization prop passed to the component/provider.
*/
customization?: BrandingProps;
branding?: BrandingProps;
/**
* Merged customization object.
*/
Expand Down
6 changes: 3 additions & 3 deletions packages/core/src/models/get-localization-props.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* under the License.
*/

import {BrandingProps} from './branding';
import {BrandingPreferenceTextProps} from './branding';
import {ScreenType} from './screen-type';

/**
Expand All @@ -26,15 +26,15 @@ interface GetLocalizationProps {
/**
* Customiztion prop passed to the component
*/
componentCustomization?: BrandingProps;
componentTextOverrides?: BrandingPreferenceTextProps;
/**
* Locale to filter the retrieval of localization.
*/
locale: string;
/**
* Customization prop passed to the provider
*/
providerCustomization?: BrandingProps;
providerTextOverrides?: BrandingPreferenceTextProps;
/**
* Screen to filter the retrieval of localization.
*/
Expand Down
3 changes: 3 additions & 0 deletions packages/react/.eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,7 @@ module.exports = {
project: [path.resolve(__dirname, 'tsconfig.lib.json'), path.resolve(__dirname, 'tsconfig.eslint.json')],
},
plugins: ['@wso2'],
rules: {
'class-methods-use-this': 'off',
},
};
10 changes: 8 additions & 2 deletions packages/react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
},
"devDependencies": {
"@types/node": "^20.12.7",
"@types/randombytes": "^2.0.3",
"@types/react": "^18.2.79",
"@types/react-dom": "^18.2.25",
"@wso2/eslint-plugin": "https://gitpkg.now.sh/brionmario/wso2-ui-configs/packages/eslint-plugin?fa0b844715320a3953d6d055997c0770f8695082",
Expand All @@ -46,12 +47,17 @@
"sass": "^1.75.0",
"stylelint": "15.1.0",
"tslib": "^2.6.2",
"typescript": "^5.4.5"
"typescript": "5.1.6"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this intentional?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

caret ^ symbol will update to all future minor/patch versions, without incrementing the major version. (npm docs)
since current eslint version supports only upto typescript 5.2, need to avoid this.

},
"dependencies": {
"@asgardeo/js-ui-core": "*",
"@oxygen-ui/react": "^1.11.0",
"clsx": "^2.1.1"
"base64url": "^3.0.1",
"buffer": "^6.0.3",
"clsx": "^2.1.1",
"fast-sha256": "^1.3.0",
"jose": "^5.3.0",
"randombytes": "^2.1.0"
},
"peerDependencies": {
"react": ">=18.0.0",
Expand Down
24 changes: 24 additions & 0 deletions packages/react/src/contexts/asgardeo-context.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/**
* 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 {Context, createContext} from 'react';
import AuthContext from '../models/auth-context';

const AsgardeoContext: Context<AuthContext> = createContext<AuthContext>(undefined);

export default AsgardeoContext;
24 changes: 24 additions & 0 deletions packages/react/src/contexts/branding-preference-context.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/**
* 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 '@asgardeo/js-ui-core';
import {Context, createContext} from 'react';

const BrandingPreferenceContext: Context<BrandingProps> = createContext<BrandingProps>(undefined);

export default BrandingPreferenceContext;
24 changes: 24 additions & 0 deletions packages/react/src/contexts/i18n-context.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/**
* 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 {Context, createContext} from 'react';
import {I18n} from '../models/i18n';

const I18nContext: Context<I18n> = createContext<I18n>(undefined);

export default I18nContext;
46 changes: 46 additions & 0 deletions packages/react/src/hooks/use-authentication.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/**
* 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 {signOut as signOutApiCall} from '@asgardeo/js-ui-core';
import {useContext} from 'react';
import AsgardeoContext from '../contexts/asgardeo-context';
import AuthContext from '../models/auth-context';
import UseAuthentication from '../models/use-authentication';

/**
* `useAuthentication` is a custom hook that provides access to the authentication context.
* It returns an object containing the current user, the authentication status, the access token, and a sign out function.
*
* @returns {UseAuthentication} An object containing the current user (`user`), the authentication status (`isAuthenticated`),
* the access token (`accessToken`), and a sign out function (`signOut`).
*/
const useAuthentication = (): UseAuthentication => {
const contextValue: AuthContext = useContext(AsgardeoContext);

const {user, isAuthenticated, accessToken} = contextValue;

const signOut: () => void = () => {
signOutApiCall();
sessionStorage.clear();
window.location.reload();
};

return {accessToken, isAuthenticated, signOut, user};
};

export default useAuthentication;
34 changes: 34 additions & 0 deletions packages/react/src/hooks/use-config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/**
* 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 {UIAuthConfig} from '@asgardeo/js-ui-core';
import {useContext} from 'react';
import AsgardeoContext from '../contexts/asgardeo-context';
import UseConfig from '../models/use-config';

/**
* Custom hook to access the authentication configuration from the AsgardeoProviderContext.
* @returns An object containing the authentication configuration.
*/
export const useConfig = (): UseConfig => {
const {config} = useContext(AsgardeoContext) as {
config: UIAuthConfig;
};

return {config};
};
Loading