Skip to content

Commit 43d8efa

Browse files
authored
Merge pull request #87 from brionmario/next
2 parents 666662e + c0b7ebd commit 43d8efa

File tree

88 files changed

+3723
-2642
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

88 files changed

+3723
-2642
lines changed

.changeset/tiny-worms-repeat.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
'@asgardeo/browser': patch
3+
'@asgardeo/express': patch
4+
'@asgardeo/javascript': patch
5+
'@asgardeo/nextjs': patch
6+
'@asgardeo/node': patch
7+
'@asgardeo/react': patch
8+
'@asgardeo/vue': patch
9+
---
10+
11+
Fix B2B components

packages/javascript/src/AsgardeoJavaScriptClient.ts

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

19+
import {AllOrganizationsApiResponse} from './models/organization';
1920
import {AsgardeoClient, SignInOptions, SignOutOptions, SignUpOptions} from './models/client';
2021
import {Config} from './models/config';
2122
import {EmbeddedFlowExecuteRequestPayload, EmbeddedFlowExecuteResponse} from './models/embedded-flow';
2223
import {EmbeddedSignInFlowHandleRequestPayload} from './models/embedded-signin-flow';
24+
import {TokenResponse} from './models/token';
2325
import {Organization} from './models/organization';
2426
import {User, UserProfile} from './models/user';
2527

@@ -30,13 +32,15 @@ import {User, UserProfile} from './models/user';
3032
* @typeParam T - Configuration type that extends Config.
3133
*/
3234
abstract class AsgardeoJavaScriptClient<T = Config> implements AsgardeoClient<T> {
33-
abstract switchOrganization(organization: Organization): Promise<void>;
35+
abstract switchOrganization(organization: Organization, sessionId?: string): Promise<TokenResponse | Response>;
3436

3537
abstract initialize(config: T): Promise<boolean>;
3638

3739
abstract getUser(options?: any): Promise<User>;
3840

39-
abstract getOrganizations(options?: any): Promise<Organization[]>;
41+
abstract getAllOrganizations(options?: any, sessionId?: string): Promise<AllOrganizationsApiResponse>;
42+
43+
abstract getMyOrganizations(options?: any, sessionId?: string): Promise<Organization[]>;
4044

4145
abstract getCurrentOrganization(sessionId?: string): Promise<Organization | null>;
4246

packages/javascript/src/api/getAllOrganizations.ts

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

19-
import {Organization} from '../models/organization';
19+
import {AllOrganizationsApiResponse} from '../models/organization';
2020
import AsgardeoAPIError from '../errors/AsgardeoAPIError';
2121

22-
/**
23-
* Interface for paginated organization response.
24-
*/
25-
export interface PaginatedOrganizationsResponse {
26-
hasMore?: boolean;
27-
nextCursor?: string;
28-
organizations: Organization[];
29-
totalCount?: number;
30-
}
31-
3222
/**
3323
* Configuration for the getAllOrganizations request
3424
*/
@@ -120,7 +110,7 @@ const getAllOrganizations = async ({
120110
recursive = false,
121111
fetcher,
122112
...requestConfig
123-
}: GetAllOrganizationsConfig): Promise<PaginatedOrganizationsResponse> => {
113+
}: GetAllOrganizationsConfig): Promise<AllOrganizationsApiResponse> => {
124114
try {
125115
new URL(baseUrl);
126116
} catch (error) {
@@ -150,9 +140,9 @@ const getAllOrganizations = async ({
150140
...requestConfig,
151141
method: 'GET',
152142
headers: {
143+
...requestConfig.headers,
153144
'Content-Type': 'application/json',
154145
Accept: 'application/json',
155-
...requestConfig.headers,
156146
},
157147
};
158148

packages/javascript/src/api/getBrandingPreference.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ const getBrandingPreference = async ({
134134
);
135135

136136
const fetchFn = fetcher || fetch;
137-
const resolvedUrl = `${baseUrl}/api/server/v1/branding-preference${
137+
const resolvedUrl = `${baseUrl}/api/server/v1/branding-preference/resolve${
138138
queryParams.toString() ? `?${queryParams.toString()}` : ''
139139
}`;
140140

packages/javascript/src/api/getScim2Me.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import {User} from '../models/user';
2020
import AsgardeoAPIError from '../errors/AsgardeoAPIError';
21+
import processUserUsername from '../utils/processUsername';
2122

2223
/**
2324
* Configuration for the getScim2Me request
@@ -103,7 +104,7 @@ const getScim2Me = async ({url, baseUrl, fetcher, ...requestConfig}: GetScim2MeC
103104
}
104105

105106
const fetchFn = fetcher || fetch;
106-
const resolvedUrl: string = url ?? `${baseUrl}/scim2/Me`
107+
const resolvedUrl: string = url ?? `${baseUrl}/scim2/Me`;
107108

108109
const requestInit: RequestInit = {
109110
...requestConfig,
@@ -130,7 +131,9 @@ const getScim2Me = async ({url, baseUrl, fetcher, ...requestConfig}: GetScim2MeC
130131
);
131132
}
132133

133-
return (await response.json()) as User;
134+
const user = (await response.json()) as User;
135+
136+
return processUserUsername(user);
134137
} catch (error) {
135138
if (error instanceof AsgardeoAPIError) {
136139
throw error;

packages/javascript/src/api/initializeEmbeddedSignInFlow.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,9 @@ const initializeEmbeddedSignInFlow = async ({
7777
...requestConfig,
7878
method: requestConfig.method || 'POST',
7979
headers: {
80+
...requestConfig.headers,
8081
'Content-Type': 'application/x-www-form-urlencoded',
8182
Accept: 'application/json',
82-
...requestConfig.headers,
8383
},
8484
body: searchParams.toString(),
8585
});

packages/javascript/src/i18n/en-US.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,18 @@ const translations: I18nTranslations = {
8888
'organization.switcher.members': 'members',
8989
'organization.switcher.member': 'member',
9090
'organization.switcher.create.organization': 'Create Organization',
91-
'organization.switcher.manage.organizations': 'Manage Organization',
91+
'organization.switcher.manage.organizations': 'Manage Organizations',
9292
'organization.switcher.manage.button': 'Manage',
93+
'organization.switcher.organizations.title': 'Organizations',
94+
'organization.switcher.switch.button': 'Switch',
95+
'organization.switcher.no.access': 'No Access',
96+
'organization.switcher.status.label': 'Status:',
97+
'organization.switcher.showing.count': 'Showing {showing} of {total} organizations',
98+
'organization.switcher.refresh.button': 'Refresh',
99+
'organization.switcher.load.more': 'Load More Organizations',
100+
'organization.switcher.loading.more': 'Loading...',
101+
'organization.switcher.no.organizations': 'No organizations found',
102+
'organization.switcher.error.prefix': 'Error:',
93103
'organization.profile.title': 'Organization Profile',
94104
'organization.profile.loading': 'Loading organization...',
95105
'organization.profile.error': 'Failed to load organization',

packages/javascript/src/index.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,7 @@ export {default as executeEmbeddedSignUpFlow} from './api/executeEmbeddedSignUpF
2727
export {default as getUserInfo} from './api/getUserInfo';
2828
export {default as getScim2Me, GetScim2MeConfig} from './api/getScim2Me';
2929
export {default as getSchemas, GetSchemasConfig} from './api/getSchemas';
30-
export {
31-
default as getAllOrganizations,
32-
PaginatedOrganizationsResponse,
33-
GetAllOrganizationsConfig,
34-
} from './api/getAllOrganizations';
30+
export {default as getAllOrganizations, GetAllOrganizationsConfig} from './api/getAllOrganizations';
3531
export {
3632
default as createOrganization,
3733
CreateOrganizationPayload,
@@ -53,6 +49,7 @@ export {default as AsgardeoAPIError} from './errors/AsgardeoAPIError';
5349
export {default as AsgardeoRuntimeError} from './errors/AsgardeoRuntimeError';
5450
export {AsgardeoAuthException} from './errors/exception';
5551

52+
export {AllOrganizationsApiResponse} from './models/organization';
5653
export {
5754
EmbeddedSignInFlowInitiateResponse,
5855
EmbeddedSignInFlowStatus,
@@ -115,6 +112,7 @@ export {default as AsgardeoJavaScriptClient} from './AsgardeoJavaScriptClient';
115112
export {default as createTheme} from './theme/createTheme';
116113
export {ThemeColors, ThemeConfig, Theme, ThemeMode, ThemeDetection} from './theme/types';
117114

115+
export {default as processUsername} from './utils/processUsername';
118116
export {default as deepMerge} from './utils/deepMerge';
119117
export {default as deriveOrganizationHandleFromBaseUrl} from './utils/deriveOrganizationHandleFromBaseUrl';
120118
export {default as extractUserClaimsFromIdToken} from './utils/extractUserClaimsFromIdToken';
@@ -132,5 +130,6 @@ export {default as resolveFieldType} from './utils/resolveFieldType';
132130
export {default as resolveFieldName} from './utils/resolveFieldName';
133131
export {default as processOpenIDScopes} from './utils/processOpenIDScopes';
134132
export {default as withVendorCSSClassPrefix} from './utils/withVendorCSSClassPrefix';
133+
export {default as transformBrandingPreferenceToTheme} from './utils/transformBrandingPreferenceToTheme';
135134

136135
export {default as StorageManager} from './StorageManager';

packages/javascript/src/models/client.ts

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

19-
import {EmbeddedFlowExecuteRequestConfig, EmbeddedFlowExecuteRequestPayload, EmbeddedFlowExecuteResponse} from './embedded-flow';
19+
import {AllOrganizationsApiResponse} from '../models/organization';
20+
import {
21+
EmbeddedFlowExecuteRequestConfig,
22+
EmbeddedFlowExecuteRequestPayload,
23+
EmbeddedFlowExecuteResponse,
24+
} from './embedded-flow';
2025
import {EmbeddedSignInFlowHandleRequestPayload} from './embedded-signin-flow';
2126
import {Organization} from './organization';
2227
import {User, UserProfile} from './user';
28+
import {TokenResponse} from './token';
2329

2430
export type SignInOptions = Record<string, unknown>;
2531
export type SignOutOptions = Record<string, unknown>;
@@ -37,11 +43,13 @@ export type SignUpOptions = Record<string, unknown>;
3743
*/
3844
export interface AsgardeoClient<T> {
3945
/**
40-
* Gets the users associated organizations.
46+
* Gets the current signed-in user's associated organizations.
4147
*
4248
* @returns Associated organizations.
4349
*/
44-
getOrganizations(options?: any): Promise<Organization[]>;
50+
getMyOrganizations(options?: any, sessionId?: string): Promise<Organization[]>;
51+
52+
getAllOrganizations(options?: any, sessionId?: string): Promise<AllOrganizationsApiResponse>;
4553

4654
/**
4755
* Gets the current organization of the user.
@@ -55,7 +63,7 @@ export interface AsgardeoClient<T> {
5563
* @param organization - The organization to switch to.
5664
* @returns A promise that resolves when the switch is complete.
5765
*/
58-
switchOrganization(organization: Organization): Promise<void>;
66+
switchOrganization(organization: Organization, sessionId?: string): Promise<TokenResponse | Response> ;
5967

6068
getConfiguration(): T;
6169

@@ -147,7 +155,11 @@ export interface AsgardeoClient<T> {
147155
* @param afterSignOut - Callback function to be executed after sign-out is complete.
148156
* @returns A promise that resolves to true if sign-out is successful
149157
*/
150-
signOut(options?: SignOutOptions, sessionId?: string, afterSignOut?: (afterSignOutUrl: string) => void): Promise<string>;
158+
signOut(
159+
options?: SignOutOptions,
160+
sessionId?: string,
161+
afterSignOut?: (afterSignOutUrl: string) => void,
162+
): Promise<string>;
151163

152164
/**
153165
* Initiates a redirection-based sign-up process for the user.

packages/javascript/src/models/i18n.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,16 @@ export interface I18nTranslations {
8888
'organization.switcher.create.organization': string;
8989
'organization.switcher.manage.organizations': string;
9090
'organization.switcher.manage.button': string;
91+
'organization.switcher.organizations.title': string;
92+
'organization.switcher.switch.button': string;
93+
'organization.switcher.no.access': string;
94+
'organization.switcher.status.label': string;
95+
'organization.switcher.showing.count': string;
96+
'organization.switcher.refresh.button': string;
97+
'organization.switcher.load.more': string;
98+
'organization.switcher.loading.more': string;
99+
'organization.switcher.no.organizations': string;
100+
'organization.switcher.error.prefix': string;
91101
'organization.profile.title': string;
92102
'organization.profile.loading': string;
93103
'organization.profile.error': string;

0 commit comments

Comments
 (0)