Skip to content

Commit 29262a6

Browse files
Refactor API methods to support instance ID for multi-instance functionality
1 parent a024481 commit 29262a6

8 files changed

Lines changed: 64 additions & 22 deletions

File tree

packages/react/src/api/createOrganization.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,6 @@ import {
2626
CreateOrganizationConfig as BaseCreateOrganizationConfig,
2727
} from '@asgardeo/browser';
2828

29-
const httpClient: HttpInstance = AsgardeoSPAClient.getInstance().httpRequest.bind(AsgardeoSPAClient.getInstance());
30-
3129
/**
3230
* Configuration for the createOrganization request (React-specific)
3331
*/
@@ -37,6 +35,10 @@ export interface CreateOrganizationConfig extends Omit<BaseCreateOrganizationCon
3735
* which is a wrapper around axios http.request
3836
*/
3937
fetcher?: (url: string, config: RequestInit) => Promise<Response>;
38+
/**
39+
* Optional instance ID for multi-instance support. Defaults to 0.
40+
*/
41+
instanceId?: number;
4042
}
4143

4244
/**
@@ -90,8 +92,11 @@ export interface CreateOrganizationConfig extends Omit<BaseCreateOrganizationCon
9092
* }
9193
* ```
9294
*/
93-
const createOrganization = async ({fetcher, ...requestConfig}: CreateOrganizationConfig): Promise<Organization> => {
95+
const createOrganization = async ({fetcher, instanceId = 0, ...requestConfig}: CreateOrganizationConfig): Promise<Organization> => {
9496
const defaultFetcher = async (url: string, config: RequestInit): Promise<Response> => {
97+
const httpClient: HttpInstance = AsgardeoSPAClient.getInstance(instanceId).httpRequest.bind(
98+
AsgardeoSPAClient.getInstance(instanceId)
99+
);
95100
const response: HttpResponse<any> = await httpClient({
96101
data: config.body ? JSON.parse(config.body as string) : undefined,
97102
headers: config.headers as Record<string, string>,

packages/react/src/api/getAllOrganizations.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,6 @@ import {
2626
AllOrganizationsApiResponse,
2727
} from '@asgardeo/browser';
2828

29-
const httpClient: HttpInstance = AsgardeoSPAClient.getInstance().httpRequest.bind(AsgardeoSPAClient.getInstance());
30-
3129
/**
3230
* Configuration for the getAllOrganizations request (React-specific)
3331
*/
@@ -37,6 +35,10 @@ export interface GetAllOrganizationsConfig extends Omit<BaseGetAllOrganizationsC
3735
* which is a wrapper around axios http.request
3836
*/
3937
fetcher?: (url: string, config: RequestInit) => Promise<Response>;
38+
/**
39+
* Optional instance ID for multi-instance support. Defaults to 0.
40+
*/
41+
instanceId?: number;
4042
}
4143

4244
/**
@@ -84,9 +86,13 @@ export interface GetAllOrganizationsConfig extends Omit<BaseGetAllOrganizationsC
8486
*/
8587
const getAllOrganizations = async ({
8688
fetcher,
89+
instanceId = 0,
8790
...requestConfig
8891
}: GetAllOrganizationsConfig): Promise<AllOrganizationsApiResponse> => {
8992
const defaultFetcher = async (url: string, config: RequestInit): Promise<Response> => {
93+
const httpClient: HttpInstance = AsgardeoSPAClient.getInstance(instanceId).httpRequest.bind(
94+
AsgardeoSPAClient.getInstance(instanceId)
95+
);
9096
const response: HttpResponse<any> = await httpClient({
9197
headers: config.headers as Record<string, string>,
9298
method: config.method || 'GET',

packages/react/src/api/getMeOrganizations.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,6 @@ import {
2626
GetMeOrganizationsConfig as BaseGetMeOrganizationsConfig,
2727
} from '@asgardeo/browser';
2828

29-
const httpClient: HttpInstance = AsgardeoSPAClient.getInstance().httpRequest.bind(AsgardeoSPAClient.getInstance());
30-
3129
/**
3230
* Configuration for the getMeOrganizations request (React-specific)
3331
*/
@@ -37,6 +35,10 @@ export interface GetMeOrganizationsConfig extends Omit<BaseGetMeOrganizationsCon
3735
* which is a wrapper around axios http.request
3836
*/
3937
fetcher?: (url: string, config: RequestInit) => Promise<Response>;
38+
/**
39+
* Optional instance ID for multi-instance support. Defaults to 0.
40+
*/
41+
instanceId?: number;
4042
}
4143

4244
/**
@@ -86,8 +88,11 @@ export interface GetMeOrganizationsConfig extends Omit<BaseGetMeOrganizationsCon
8688
* }
8789
* ```
8890
*/
89-
const getMeOrganizations = async ({fetcher, ...requestConfig}: GetMeOrganizationsConfig): Promise<Organization[]> => {
91+
const getMeOrganizations = async ({fetcher, instanceId = 0, ...requestConfig}: GetMeOrganizationsConfig): Promise<Organization[]> => {
9092
const defaultFetcher = async (url: string, config: RequestInit): Promise<Response> => {
93+
const httpClient: HttpInstance = AsgardeoSPAClient.getInstance(instanceId).httpRequest.bind(
94+
AsgardeoSPAClient.getInstance(instanceId)
95+
);
9196
const response: HttpResponse<any> = await httpClient({
9297
headers: config.headers as Record<string, string>,
9398
method: config.method || 'GET',

packages/react/src/api/getOrganization.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,6 @@ import {
2626
OrganizationDetails,
2727
} from '@asgardeo/browser';
2828

29-
const httpClient: HttpInstance = AsgardeoSPAClient.getInstance().httpRequest.bind(AsgardeoSPAClient.getInstance());
30-
3129
/**
3230
* Configuration for the getOrganization request (React-specific)
3331
*/
@@ -37,6 +35,10 @@ export interface GetOrganizationConfig extends Omit<BaseGetOrganizationConfig, '
3735
* which is a wrapper around axios http.request
3836
*/
3937
fetcher?: (url: string, config: RequestInit) => Promise<Response>;
38+
/**
39+
* Optional instance ID for multi-instance support. Defaults to 0.
40+
*/
41+
instanceId?: number;
4042
}
4143

4244
/**
@@ -78,8 +80,11 @@ export interface GetOrganizationConfig extends Omit<BaseGetOrganizationConfig, '
7880
* }
7981
* ```
8082
*/
81-
const getOrganization = async ({fetcher, ...requestConfig}: GetOrganizationConfig): Promise<OrganizationDetails> => {
83+
const getOrganization = async ({fetcher, instanceId = 0, ...requestConfig}: GetOrganizationConfig): Promise<OrganizationDetails> => {
8284
const defaultFetcher = async (url: string, config: RequestInit): Promise<Response> => {
85+
const httpClient: HttpInstance = AsgardeoSPAClient.getInstance(instanceId).httpRequest.bind(
86+
AsgardeoSPAClient.getInstance(instanceId)
87+
);
8388
const response: HttpResponse<any> = await httpClient({
8489
headers: config.headers as Record<string, string>,
8590
method: config.method || 'GET',

packages/react/src/api/getSchemas.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,6 @@ import {
2626
GetSchemasConfig as BaseGetSchemasConfig,
2727
} from '@asgardeo/browser';
2828

29-
const httpClient: HttpInstance = AsgardeoSPAClient.getInstance().httpRequest.bind(AsgardeoSPAClient.getInstance());
30-
3129
/**
3230
* Configuration for the getSchemas request (React-specific)
3331
*/
@@ -37,6 +35,10 @@ export interface GetSchemasConfig extends Omit<BaseGetSchemasConfig, 'fetcher'>
3735
* which is a wrapper around axios http.request
3836
*/
3937
fetcher?: (url: string, config: RequestInit) => Promise<Response>;
38+
/**
39+
* Optional instance ID for multi-instance support. Defaults to 0.
40+
*/
41+
instanceId?: number;
4042
}
4143

4244
/**
@@ -76,8 +78,11 @@ export interface GetSchemasConfig extends Omit<BaseGetSchemasConfig, 'fetcher'>
7678
* }
7779
* ```
7880
*/
79-
const getSchemas = async ({fetcher, ...requestConfig}: GetSchemasConfig): Promise<Schema[]> => {
81+
const getSchemas = async ({fetcher, instanceId = 0, ...requestConfig}: GetSchemasConfig): Promise<Schema[]> => {
8082
const defaultFetcher = async (url: string, config: RequestInit): Promise<Response> => {
83+
const httpClient: HttpInstance = AsgardeoSPAClient.getInstance(instanceId).httpRequest.bind(
84+
AsgardeoSPAClient.getInstance(instanceId)
85+
);
8186
const response: HttpResponse<any> = await httpClient({
8287
headers: config.headers as Record<string, string>,
8388
method: config.method || 'GET',

packages/react/src/api/getScim2Me.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,6 @@ import {
2626
GetScim2MeConfig as BaseGetScim2MeConfig,
2727
} from '@asgardeo/browser';
2828

29-
const httpClient: HttpInstance = AsgardeoSPAClient.getInstance().httpRequest.bind(AsgardeoSPAClient.getInstance());
30-
3129
/**
3230
* Configuration for the getScim2Me request (React-specific)
3331
*/
@@ -37,6 +35,10 @@ export interface GetScim2MeConfig extends Omit<BaseGetScim2MeConfig, 'fetcher'>
3735
* which is a wrapper around axios http.request
3836
*/
3937
fetcher?: (url: string, config: RequestInit) => Promise<Response>;
38+
/**
39+
* Optional instance ID for multi-instance support. Defaults to 0.
40+
*/
41+
instanceId?: number;
4042
}
4143

4244
/**
@@ -76,8 +78,11 @@ export interface GetScim2MeConfig extends Omit<BaseGetScim2MeConfig, 'fetcher'>
7678
* }
7779
* ```
7880
*/
79-
const getScim2Me = async ({fetcher, ...requestConfig}: GetScim2MeConfig): Promise<User> => {
81+
const getScim2Me = async ({fetcher, instanceId = 0, ...requestConfig}: GetScim2MeConfig): Promise<User> => {
8082
const defaultFetcher = async (url: string, config: RequestInit): Promise<Response> => {
83+
const httpClient: HttpInstance = AsgardeoSPAClient.getInstance(instanceId).httpRequest.bind(
84+
AsgardeoSPAClient.getInstance(instanceId)
85+
);
8186
const response: HttpResponse<any> = await httpClient({
8287
headers: config.headers as Record<string, string>,
8388
method: config.method || 'GET',

packages/react/src/api/updateMeProfile.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,6 @@ import {
2626
UpdateMeProfileConfig as BaseUpdateMeProfileConfig,
2727
} from '@asgardeo/browser';
2828

29-
const httpClient: HttpInstance = AsgardeoSPAClient.getInstance().httpRequest.bind(AsgardeoSPAClient.getInstance());
30-
3129
/**
3230
* Configuration for the updateMeProfile request (React-specific)
3331
*/
@@ -37,6 +35,10 @@ export interface UpdateMeProfileConfig extends Omit<BaseUpdateMeProfileConfig, '
3735
* which is a wrapper around axios http.request
3836
*/
3937
fetcher?: (url: string, config: RequestInit) => Promise<Response>;
38+
/**
39+
* Optional instance ID for multi-instance support. Defaults to 0.
40+
*/
41+
instanceId?: number;
4042
}
4143

4244
/**
@@ -64,8 +66,11 @@ export interface UpdateMeProfileConfig extends Omit<BaseUpdateMeProfileConfig, '
6466
* });
6567
* ```
6668
*/
67-
const updateMeProfile = async ({fetcher, ...requestConfig}: UpdateMeProfileConfig): Promise<User> => {
69+
const updateMeProfile = async ({fetcher, instanceId = 0, ...requestConfig}: UpdateMeProfileConfig): Promise<User> => {
6870
const defaultFetcher = async (url: string, config: RequestInit): Promise<Response> => {
71+
const httpClient: HttpInstance = AsgardeoSPAClient.getInstance(instanceId).httpRequest.bind(
72+
AsgardeoSPAClient.getInstance(instanceId)
73+
);
6974
const response: HttpResponse<any> = await httpClient({
7075
data: config.body ? JSON.parse(config.body as string) : undefined,
7176
headers: config.headers as Record<string, string>,

packages/react/src/api/updateOrganization.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@ import {
2727
createPatchOperations,
2828
} from '@asgardeo/browser';
2929

30-
const httpClient: HttpInstance = AsgardeoSPAClient.getInstance().httpRequest.bind(AsgardeoSPAClient.getInstance());
31-
3230
/**
3331
* Configuration for the updateOrganization request (React-specific)
3432
*/
@@ -38,6 +36,10 @@ export interface UpdateOrganizationConfig extends Omit<BaseUpdateOrganizationCon
3836
* which is a wrapper around axios http.request
3937
*/
4038
fetcher?: (url: string, config: RequestInit) => Promise<Response>;
39+
/**
40+
* Optional instance ID for multi-instance support. Defaults to 0.
41+
*/
42+
instanceId?: number;
4143
}
4244

4345
/**
@@ -87,9 +89,13 @@ export interface UpdateOrganizationConfig extends Omit<BaseUpdateOrganizationCon
8789
*/
8890
const updateOrganization = async ({
8991
fetcher,
92+
instanceId = 0,
9093
...requestConfig
9194
}: UpdateOrganizationConfig): Promise<OrganizationDetails> => {
9295
const defaultFetcher = async (url: string, config: RequestInit): Promise<Response> => {
96+
const httpClient: HttpInstance = AsgardeoSPAClient.getInstance(instanceId).httpRequest.bind(
97+
AsgardeoSPAClient.getInstance(instanceId)
98+
);
9399
const response: HttpResponse<any> = await httpClient({
94100
data: config.body ? JSON.parse(config.body as string) : undefined,
95101
headers: config.headers as Record<string, string>,

0 commit comments

Comments
 (0)