@asgardeo/react 0.5.9 → 0.5.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -59,12 +59,24 @@ export type AsgardeoContextProps = {
59
59
  user: any;
60
60
  organization: Organization;
61
61
  /**
62
- * Custom fetch function to make HTTP requests.
63
- * @param url - The URL to fetch.
64
- * @param options - Optional configuration for the HTTP request.
62
+ * HTTP request function to make API calls.
63
+ * @param requestConfig - Configuration for the HTTP request.
65
64
  * @returns A promise that resolves to the HTTP response.
66
65
  */
67
- fetch: (url: string, options?: HttpRequestConfig) => Promise<HttpResponse<any>>;
66
+ http: {
67
+ /**
68
+ * Makes an HTTP request using the provided configuration.
69
+ * @param requestConfig - Configuration for the HTTP request.
70
+ * @returns A promise that resolves to the HTTP response.
71
+ */
72
+ request: (requestConfig?: HttpRequestConfig) => Promise<HttpResponse<any>>;
73
+ /**
74
+ * Makes multiple HTTP requests based on the provided configuration.
75
+ * @param requestConfigs - Set of configurations for the HTTP requests.
76
+ * @returns A promise that resolves to an array of HTTP responses.
77
+ */
78
+ requestAll: (requestConfigs?: HttpRequestConfig[]) => Promise<HttpResponse<any>[]>;
79
+ };
68
80
  };
69
81
  /**
70
82
  * Context object for managing the Authentication flow builder core context.
package/dist/index.js CHANGED
@@ -28,7 +28,10 @@ var AsgardeoContext = createContext({
28
28
  signOut: null,
29
29
  signUp: null,
30
30
  user: null,
31
- fetch: () => null
31
+ http: {
32
+ request: () => null,
33
+ requestAll: () => null
34
+ }
32
35
  });
33
36
  AsgardeoContext.displayName = "AsgardeoContext";
34
37
  var AsgardeoContext_default = AsgardeoContext;
@@ -199,7 +202,7 @@ var _AuthAPI = class _AuthAPI {
199
202
  * @return {Promise<Response | SignInResponse>} - A Promise that resolves with
200
203
  * the value returned by the custom grant request.
201
204
  */
202
- exchangeToken(config, callback, dispatch) {
205
+ exchangeToken(config, callback) {
203
206
  return this._client.exchangeToken(config).then((response) => {
204
207
  if (!response) {
205
208
  return null;
@@ -211,7 +214,6 @@ var _AuthAPI = class _AuthAPI {
211
214
  isSignedIn: true,
212
215
  isLoading: false
213
216
  });
214
- dispatch({ ...response, isSignedIn: true, isLoading: false });
215
217
  }
216
218
  callback && callback(response);
217
219
  return response;
@@ -278,8 +280,8 @@ var _AuthAPI = class _AuthAPI {
278
280
  *
279
281
  * @return {Promise<string>} - A Promise that resolves with the access token.
280
282
  */
281
- async getAccessToken() {
282
- return this._client.getAccessToken();
283
+ async getAccessToken(sessionId) {
284
+ return this._client.getAccessToken(sessionId);
283
285
  }
284
286
  /**
285
287
  * This method return a Promise that resolves with the idp access token.
@@ -624,7 +626,6 @@ var AsgardeoReactClient = class extends AsgardeoBrowserClient {
624
626
  return this.withLoading(async () => {
625
627
  try {
626
628
  const configData = await this.asgardeo.getConfigData();
627
- const scopes = configData?.scopes;
628
629
  if (!organization.id) {
629
630
  throw new AsgardeoRuntimeError(
630
631
  "Organization ID is required for switching organizations",
@@ -646,12 +647,8 @@ var AsgardeoReactClient = class extends AsgardeoBrowserClient {
646
647
  returnsSession: true,
647
648
  signInRequired: true
648
649
  };
649
- return await this.asgardeo.exchangeToken(
650
- exchangeConfig,
651
- (user) => {
652
- },
653
- () => null
654
- );
650
+ return await this.asgardeo.exchangeToken(exchangeConfig, (user) => {
651
+ });
655
652
  } catch (error) {
656
653
  throw new AsgardeoRuntimeError(
657
654
  `Failed to switch organization: ${error.message || error}`,
@@ -724,11 +721,14 @@ var AsgardeoReactClient = class extends AsgardeoBrowserClient {
724
721
  "The signUp method with SignUpOptions is not implemented in the React client."
725
722
  );
726
723
  }
727
- async fetch(url, options) {
728
- return this.asgardeo.httpRequest({
729
- url,
730
- ...options
731
- });
724
+ async request(requestConfig) {
725
+ return this.asgardeo.httpRequest(requestConfig);
726
+ }
727
+ async requestAll(requestConfigs) {
728
+ return this.asgardeo.httpRequestAll(requestConfigs);
729
+ }
730
+ async getAccessToken(sessionId) {
731
+ return this.asgardeo.getAccessToken(sessionId);
732
732
  }
733
733
  };
734
734
  var AsgardeoReactClient_default = AsgardeoReactClient;
@@ -1572,19 +1572,6 @@ var AsgardeoProvider = ({
1572
1572
  setIsLoadingSync(asgardeo.isLoading());
1573
1573
  }
1574
1574
  };
1575
- const signUp = async (payload) => {
1576
- try {
1577
- return await asgardeo.signUp(payload);
1578
- } catch (error) {
1579
- throw new AsgardeoRuntimeError3(
1580
- `Error while signing up: ${error.message || error}`,
1581
- "asgardeo-signUp-Error",
1582
- "react",
1583
- "An error occurred while trying to sign up."
1584
- );
1585
- }
1586
- };
1587
- const signOut = async (options, afterSignOut) => asgardeo.signOut(options, afterSignOut);
1588
1575
  const switchOrganization = async (organization) => {
1589
1576
  try {
1590
1577
  setIsLoadingSync(true);
@@ -1617,61 +1604,75 @@ var AsgardeoProvider = ({
1617
1604
  flattenedProfile: generateFlattenedUserProfile2(payload, prev?.schemas)
1618
1605
  }));
1619
1606
  };
1620
- const fetch = async (url, options) => {
1621
- return asgardeo.fetch(url, options);
1622
- };
1623
- return /* @__PURE__ */ jsx7(
1624
- AsgardeoContext_default.Provider,
1607
+ const value = useMemo6(
1608
+ () => ({
1609
+ applicationId,
1610
+ organizationHandle: config?.organizationHandle,
1611
+ signInUrl,
1612
+ signUpUrl,
1613
+ afterSignInUrl,
1614
+ baseUrl,
1615
+ getAccessToken: asgardeo.getAccessToken.bind(asgardeo),
1616
+ isInitialized: isInitializedSync,
1617
+ isLoading: isLoadingSync,
1618
+ isSignedIn: isSignedInSync,
1619
+ organization: currentOrganization,
1620
+ signIn,
1621
+ signInSilently,
1622
+ signOut: asgardeo.signOut.bind(asgardeo),
1623
+ signUp: asgardeo.signUp.bind(asgardeo),
1624
+ user,
1625
+ http: {
1626
+ request: asgardeo.request.bind(asgardeo),
1627
+ requestAll: asgardeo.requestAll.bind(asgardeo)
1628
+ }
1629
+ }),
1630
+ [
1631
+ applicationId,
1632
+ config?.organizationHandle,
1633
+ signInUrl,
1634
+ signUpUrl,
1635
+ afterSignInUrl,
1636
+ baseUrl,
1637
+ isInitializedSync,
1638
+ isLoadingSync,
1639
+ isSignedInSync,
1640
+ currentOrganization,
1641
+ signIn,
1642
+ signInSilently,
1643
+ user,
1644
+ asgardeo
1645
+ ]
1646
+ );
1647
+ return /* @__PURE__ */ jsx7(AsgardeoContext_default.Provider, { value, children: /* @__PURE__ */ jsx7(I18nProvider_default, { preferences: preferences?.i18n, children: /* @__PURE__ */ jsx7(
1648
+ BrandingProvider_default,
1625
1649
  {
1626
- value: {
1627
- applicationId,
1628
- organizationHandle: config?.organizationHandle,
1629
- signInUrl,
1630
- signUpUrl,
1631
- afterSignInUrl,
1632
- baseUrl,
1633
- isInitialized: isInitializedSync,
1634
- isLoading: isLoadingSync,
1635
- isSignedIn: isSignedInSync,
1636
- organization: currentOrganization,
1637
- signIn,
1638
- signInSilently,
1639
- signOut,
1640
- signUp,
1641
- user,
1642
- fetch
1643
- },
1644
- children: /* @__PURE__ */ jsx7(I18nProvider_default, { preferences: preferences?.i18n, children: /* @__PURE__ */ jsx7(
1645
- BrandingProvider_default,
1650
+ brandingPreference,
1651
+ isLoading: isBrandingLoading,
1652
+ error: brandingError,
1653
+ enabled: preferences?.theme?.inheritFromBranding !== false,
1654
+ refetch: refetchBranding,
1655
+ children: /* @__PURE__ */ jsx7(
1656
+ ThemeProvider_default,
1646
1657
  {
1647
- brandingPreference,
1648
- isLoading: isBrandingLoading,
1649
- error: brandingError,
1650
- enabled: preferences?.theme?.inheritFromBranding !== false,
1651
- refetch: refetchBranding,
1652
- children: /* @__PURE__ */ jsx7(
1653
- ThemeProvider_default,
1658
+ inheritFromBranding: preferences?.theme?.inheritFromBranding,
1659
+ theme: preferences?.theme?.overrides,
1660
+ mode: isDarkMode ? "dark" : "light",
1661
+ children: /* @__PURE__ */ jsx7(FlowProvider_default, { children: /* @__PURE__ */ jsx7(UserProvider_default, { profile: userProfile, onUpdateProfile: handleProfileUpdate, children: /* @__PURE__ */ jsx7(
1662
+ OrganizationProvider_default,
1654
1663
  {
1655
- inheritFromBranding: preferences?.theme?.inheritFromBranding,
1656
- theme: preferences?.theme?.overrides,
1657
- mode: isDarkMode ? "dark" : "light",
1658
- children: /* @__PURE__ */ jsx7(FlowProvider_default, { children: /* @__PURE__ */ jsx7(UserProvider_default, { profile: userProfile, onUpdateProfile: handleProfileUpdate, children: /* @__PURE__ */ jsx7(
1659
- OrganizationProvider_default,
1660
- {
1661
- getAllOrganizations: async () => await asgardeo.getAllOrganizations(),
1662
- myOrganizations,
1663
- currentOrganization,
1664
- onOrganizationSwitch: switchOrganization,
1665
- revalidateMyOrganizations: async () => await asgardeo.getMyOrganizations(),
1666
- children
1667
- }
1668
- ) }) })
1664
+ getAllOrganizations: async () => await asgardeo.getAllOrganizations(),
1665
+ myOrganizations,
1666
+ currentOrganization,
1667
+ onOrganizationSwitch: switchOrganization,
1668
+ revalidateMyOrganizations: async () => await asgardeo.getMyOrganizations(),
1669
+ children
1669
1670
  }
1670
- )
1671
+ ) }) })
1671
1672
  }
1672
- ) })
1673
+ )
1673
1674
  }
1674
- );
1675
+ ) }) });
1675
1676
  };
1676
1677
  var AsgardeoProvider_default = AsgardeoProvider;
1677
1678