Skip to content

Commit 2d995dc

Browse files
authored
Merge pull request #13 from movinsilva/react-ui--provider-components
feat(react): add providers & custom hooks
2 parents 2117385 + 23a3785 commit 2d995dc

32 files changed

+1360
-63
lines changed

packages/core/src/branding/get-branding.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ import GetBrandingProps from '../models/get-branding-props';
3131
* @returns {Promise<Branding>} A promise that resolves with the merged branding properties.
3232
*/
3333
const getBranding = async (props: GetBrandingProps): Promise<Branding> => {
34-
const {customization, merged} = props;
34+
const {branding, merged} = props;
3535
let mergedBranding: Branding;
3636

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

4848
if (brandingFromConsole?.preference?.configs?.isBrandingEnabled) {
49-
mergedBranding = merge(DEFAULT_BRANDING, brandingFromConsole ?? {}, customization ?? {});
49+
mergedBranding = merge(DEFAULT_BRANDING, brandingFromConsole ?? {}, branding ?? {});
5050
} else {
51-
mergedBranding = merge(DEFAULT_BRANDING, customization ?? {});
51+
mergedBranding = merge(DEFAULT_BRANDING, branding ?? {});
5252
}
5353
} else {
54-
mergedBranding = merge(merged, customization ?? {});
54+
mergedBranding = merge(merged, branding ?? {});
5555
}
5656

5757
return mergedBranding;

packages/core/src/i18n/get-localization.ts

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,14 @@
1616
* under the License.
1717
*/
1818

19+
import {AuthClientConfig} from '@asgardeo/auth-js';
1920
import merge from 'lodash.merge';
2021
import {TextObject} from './screens/model';
2122
import getBrandingPreferenceText from '../api/get-branding-preference-text';
2223
import {AuthClient} from '../auth-client';
2324
import AsgardeoUIException from '../exception';
25+
import {UIAuthConfig} from '../models/auth-config';
26+
import {BrandingPreferenceTypes} from '../models/branding-api-response';
2427
import {BrandingPreferenceTextAPIResponse} from '../models/branding-text-api-response';
2528
import GetLocalizationProps from '../models/get-localization-props';
2629

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

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

3841
let textFromConsoleBranding: BrandingPreferenceTextAPIResponse;
3942

43+
const configData: AuthClientConfig<UIAuthConfig> = await AuthClient.getInstance().getDataLayer().getConfigData();
44+
4045
try {
41-
if ((await AuthClient.getInstance().getDataLayer().getConfigData()).enableConsoleTextBranding ?? true) {
42-
textFromConsoleBranding = await getBrandingPreferenceText(
46+
if (configData.enableConsoleTextBranding ?? true) {
47+
textFromConsoleBranding = await getBrandingPreferenceText({
4348
locale,
44-
providerCustomization.name,
49+
name: configData.name ?? 'carbon.super',
4550
screen,
46-
providerCustomization.type,
47-
);
51+
type: configData.type ?? BrandingPreferenceTypes.Org,
52+
});
4853
}
4954
} catch (error) {
5055
throw new AsgardeoUIException(
@@ -69,11 +74,11 @@ const getLocalization = async (props: GetLocalizationProps): Promise<TextObject>
6974
/**
7075
* PRIORITY 02: Text from provider customization
7176
*/
72-
providerCustomization?.preference?.text?.[locale]?.[screen] ?? {},
77+
providerTextOverrides?.[locale]?.[screen] ?? {},
7378
/**
7479
* PRIORITY 01: Text from component customization
7580
*/
76-
componentCustomization?.preference?.text?.[locale]?.[screen] ?? {},
81+
componentTextOverrides?.[locale]?.[screen] ?? {},
7782
);
7883

7984
return mergedText;

packages/core/src/models/auth-config.ts

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
*/
1818

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

2122
/**
2223
* Interface for the configuration extension from the AuthClientConfig of '@asgardeo/auth-js'.
@@ -39,16 +40,7 @@ interface AuthClientConfigExtension {
3940
/**
4041
* Type to filter the retrieval of customizations.
4142
*/
42-
type?: OrgType;
43-
}
44-
45-
/**
46-
* Enum for the organization type.
47-
*/
48-
export enum OrgType {
49-
App = 'APP',
50-
Custom = 'CUSTOM',
51-
Org = 'ORG',
43+
type?: BrandingPreferenceTypes;
5244
}
5345

5446
/**

packages/core/src/models/branding.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ import {TextPreference} from '../i18n/screens/model';
2525
*/
2626
export type BrandingPreferenceText = Record<string, TextPreference>;
2727

28+
export type BrandingPreferenceTextProps = RecursivePartial<BrandingPreferenceText>;
29+
2830
interface BrandingPreferenceWithText extends BrandingPreference {
2931
text?: BrandingPreferenceText;
3032
}

packages/core/src/models/get-branding-props.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ interface GetBrandingProps {
2525
/**
2626
* Customization prop passed to the component/provider.
2727
*/
28-
customization?: BrandingProps;
28+
branding?: BrandingProps;
2929
/**
3030
* Merged customization object.
3131
*/

packages/core/src/models/get-localization-props.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
* under the License.
1717
*/
1818

19-
import {BrandingProps} from './branding';
19+
import {BrandingPreferenceTextProps} from './branding';
2020
import {ScreenType} from './screen-type';
2121

2222
/**
@@ -26,15 +26,15 @@ interface GetLocalizationProps {
2626
/**
2727
* Customiztion prop passed to the component
2828
*/
29-
componentCustomization?: BrandingProps;
29+
componentTextOverrides?: BrandingPreferenceTextProps;
3030
/**
3131
* Locale to filter the retrieval of localization.
3232
*/
3333
locale: string;
3434
/**
3535
* Customization prop passed to the provider
3636
*/
37-
providerCustomization?: BrandingProps;
37+
providerTextOverrides?: BrandingPreferenceTextProps;
3838
/**
3939
* Screen to filter the retrieval of localization.
4040
*/

packages/react/.eslintrc.cjs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,7 @@ module.exports = {
3232
project: [path.resolve(__dirname, 'tsconfig.lib.json'), path.resolve(__dirname, 'tsconfig.eslint.json')],
3333
},
3434
plugins: ['@wso2'],
35+
rules: {
36+
'class-methods-use-this': 'off',
37+
},
3538
};

packages/react/package.json

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
},
3535
"devDependencies": {
3636
"@types/node": "^20.12.7",
37+
"@types/randombytes": "^2.0.3",
3738
"@types/react": "^18.2.79",
3839
"@types/react-dom": "^18.2.25",
3940
"@wso2/eslint-plugin": "https://gitpkg.now.sh/brionmario/wso2-ui-configs/packages/eslint-plugin?fa0b844715320a3953d6d055997c0770f8695082",
@@ -46,12 +47,17 @@
4647
"sass": "^1.75.0",
4748
"stylelint": "15.1.0",
4849
"tslib": "^2.6.2",
49-
"typescript": "^5.4.5"
50+
"typescript": "5.1.6"
5051
},
5152
"dependencies": {
5253
"@asgardeo/js-ui-core": "*",
5354
"@oxygen-ui/react": "^1.11.0",
54-
"clsx": "^2.1.1"
55+
"base64url": "^3.0.1",
56+
"buffer": "^6.0.3",
57+
"clsx": "^2.1.1",
58+
"fast-sha256": "^1.3.0",
59+
"jose": "^5.3.0",
60+
"randombytes": "^2.1.0"
5561
},
5662
"peerDependencies": {
5763
"react": ">=18.0.0",
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/**
2+
* Copyright (c) 2024, WSO2 LLC. (https://www.wso2.com).
3+
*
4+
* WSO2 LLC. licenses this file to you under the Apache License,
5+
* Version 2.0 (the "License"); you may not use this file except
6+
* in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing,
12+
* software distributed under the License is distributed on an
13+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
* KIND, either express or implied. See the License for the
15+
* specific language governing permissions and limitations
16+
* under the License.
17+
*/
18+
19+
import {Context, createContext} from 'react';
20+
import AuthContext from '../models/auth-context';
21+
22+
const AsgardeoContext: Context<AuthContext> = createContext<AuthContext>(undefined);
23+
24+
export default AsgardeoContext;
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/**
2+
* Copyright (c) 2024, WSO2 LLC. (https://www.wso2.com).
3+
*
4+
* WSO2 LLC. licenses this file to you under the Apache License,
5+
* Version 2.0 (the "License"); you may not use this file except
6+
* in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing,
12+
* software distributed under the License is distributed on an
13+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
* KIND, either express or implied. See the License for the
15+
* specific language governing permissions and limitations
16+
* under the License.
17+
*/
18+
19+
import {BrandingProps} from '@asgardeo/js-ui-core';
20+
import {Context, createContext} from 'react';
21+
22+
const BrandingPreferenceContext: Context<BrandingProps> = createContext<BrandingProps>(undefined);
23+
24+
export default BrandingPreferenceContext;

0 commit comments

Comments
 (0)