Skip to content

Commit ddd4d02

Browse files
Refactor API methods to support instance ID for multi-instance functionality
1 parent e578dbb commit ddd4d02

File tree

8 files changed

+64
-22
lines changed

8 files changed

+64
-22
lines changed

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
CreateOrganizationPayload,
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 = await httpClient({
96101
url,
97102
method: config.method || 'POST',

packages/react/src/api/getAllOrganizations.ts

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

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

4143
/**
@@ -83,9 +85,13 @@ export interface GetAllOrganizationsConfig extends Omit<BaseGetAllOrganizationsC
8385
*/
8486
const getAllOrganizations = async ({
8587
fetcher,
88+
instanceId = 0,
8689
...requestConfig
8790
}: GetAllOrganizationsConfig): Promise<AllOrganizationsApiResponse> => {
8891
const defaultFetcher = async (url: string, config: RequestInit): Promise<Response> => {
92+
const httpClient: HttpInstance = AsgardeoSPAClient.getInstance(instanceId).httpRequest.bind(
93+
AsgardeoSPAClient.getInstance(instanceId)
94+
);
8995
const response = await httpClient({
9096
url,
9197
method: config.method || 'GET',

packages/react/src/api/getMeOrganizations.ts

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

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

4143
/**
@@ -85,8 +87,11 @@ export interface GetMeOrganizationsConfig extends Omit<BaseGetMeOrganizationsCon
8587
* }
8688
* ```
8789
*/
88-
const getMeOrganizations = async ({fetcher, ...requestConfig}: GetMeOrganizationsConfig): Promise<Organization[]> => {
90+
const getMeOrganizations = async ({fetcher, instanceId = 0, ...requestConfig}: GetMeOrganizationsConfig): Promise<Organization[]> => {
8991
const defaultFetcher = async (url: string, config: RequestInit): Promise<Response> => {
92+
const httpClient: HttpInstance = AsgardeoSPAClient.getInstance(instanceId).httpRequest.bind(
93+
AsgardeoSPAClient.getInstance(instanceId)
94+
);
9095
const response = await httpClient({
9196
url,
9297
method: config.method || 'GET',

packages/react/src/api/getOrganization.ts

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

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

4143
/**
@@ -77,8 +79,11 @@ export interface GetOrganizationConfig extends Omit<BaseGetOrganizationConfig, '
7779
* }
7880
* ```
7981
*/
80-
const getOrganization = async ({fetcher, ...requestConfig}: GetOrganizationConfig): Promise<OrganizationDetails> => {
82+
const getOrganization = async ({fetcher, instanceId = 0, ...requestConfig}: GetOrganizationConfig): Promise<OrganizationDetails> => {
8183
const defaultFetcher = async (url: string, config: RequestInit): Promise<Response> => {
84+
const httpClient: HttpInstance = AsgardeoSPAClient.getInstance(instanceId).httpRequest.bind(
85+
AsgardeoSPAClient.getInstance(instanceId)
86+
);
8287
const response = await httpClient({
8388
url,
8489
method: config.method || 'GET',

packages/react/src/api/getSchemas.ts

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

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

4143
/**
@@ -75,8 +77,11 @@ export interface GetSchemasConfig extends Omit<BaseGetSchemasConfig, 'fetcher'>
7577
* }
7678
* ```
7779
*/
78-
const getSchemas = async ({fetcher, ...requestConfig}: GetSchemasConfig): Promise<Schema[]> => {
80+
const getSchemas = async ({fetcher, instanceId = 0, ...requestConfig}: GetSchemasConfig): Promise<Schema[]> => {
7981
const defaultFetcher = async (url: string, config: RequestInit): Promise<Response> => {
82+
const httpClient: HttpInstance = AsgardeoSPAClient.getInstance(instanceId).httpRequest.bind(
83+
AsgardeoSPAClient.getInstance(instanceId)
84+
);
8085
const response = await httpClient({
8186
url,
8287
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 = await httpClient({
8287
url,
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
@@ -25,8 +25,6 @@ import {
2525
UpdateMeProfileConfig as BaseUpdateMeProfileConfig,
2626
} from '@asgardeo/browser';
2727

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

4143
/**
@@ -63,8 +65,11 @@ export interface UpdateMeProfileConfig extends Omit<BaseUpdateMeProfileConfig, '
6365
* });
6466
* ```
6567
*/
66-
const updateMeProfile = async ({fetcher, ...requestConfig}: UpdateMeProfileConfig): Promise<User> => {
68+
const updateMeProfile = async ({fetcher, instanceId = 0, ...requestConfig}: UpdateMeProfileConfig): Promise<User> => {
6769
const defaultFetcher = async (url: string, config: RequestInit): Promise<Response> => {
70+
const httpClient: HttpInstance = AsgardeoSPAClient.getInstance(instanceId).httpRequest.bind(
71+
AsgardeoSPAClient.getInstance(instanceId)
72+
);
6873
const response = await httpClient({
6974
url,
7075
method: config.method || 'PATCH',

packages/react/src/api/updateOrganization.ts

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

29-
const httpClient: HttpInstance = AsgardeoSPAClient.getInstance().httpRequest.bind(AsgardeoSPAClient.getInstance());
30-
3129
/**
3230
* Configuration for the updateOrganization request (React-specific)
3331
*/
@@ -37,6 +35,10 @@ export interface UpdateOrganizationConfig extends Omit<BaseUpdateOrganizationCon
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,9 +88,13 @@ export interface UpdateOrganizationConfig extends Omit<BaseUpdateOrganizationCon
8688
*/
8789
const updateOrganization = async ({
8890
fetcher,
91+
instanceId = 0,
8992
...requestConfig
9093
}: UpdateOrganizationConfig): Promise<OrganizationDetails> => {
9194
const defaultFetcher = async (url: string, config: RequestInit): Promise<Response> => {
95+
const httpClient: HttpInstance = AsgardeoSPAClient.getInstance(instanceId).httpRequest.bind(
96+
AsgardeoSPAClient.getInstance(instanceId)
97+
);
9298
const response = await httpClient({
9399
url,
94100
method: config.method || 'PATCH',

0 commit comments

Comments
 (0)