@asgardeo/react 0.5.8 → 0.5.10

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.
@@ -15,7 +15,7 @@
15
15
  * specific language governing permissions and limitations
16
16
  * under the License.
17
17
  */
18
- import { AsgardeoBrowserClient, UserProfile, SignInOptions, SignOutOptions, User, EmbeddedFlowExecuteResponse, SignUpOptions, EmbeddedFlowExecuteRequestPayload, EmbeddedSignInFlowHandleRequestPayload, Organization, IdToken, EmbeddedFlowExecuteRequestConfig, AllOrganizationsApiResponse, TokenResponse } from '@asgardeo/browser';
18
+ import { AsgardeoBrowserClient, UserProfile, SignInOptions, SignOutOptions, User, EmbeddedFlowExecuteResponse, SignUpOptions, EmbeddedFlowExecuteRequestPayload, EmbeddedSignInFlowHandleRequestPayload, Organization, IdToken, EmbeddedFlowExecuteRequestConfig, AllOrganizationsApiResponse, TokenResponse, HttpRequestConfig, HttpResponse } from '@asgardeo/browser';
19
19
  import { AsgardeoReactConfig } from './models/config';
20
20
  /**
21
21
  * Client for mplementing Asgardeo in React applications.
@@ -58,5 +58,8 @@ declare class AsgardeoReactClient<T extends AsgardeoReactConfig = AsgardeoReactC
58
58
  signOut(options?: SignOutOptions, sessionId?: string, afterSignOut?: (afterSignOutUrl: string) => void): Promise<string>;
59
59
  signUp(options?: SignUpOptions): Promise<void>;
60
60
  signUp(payload: EmbeddedFlowExecuteRequestPayload): Promise<EmbeddedFlowExecuteResponse>;
61
+ request(requestConfig?: HttpRequestConfig): Promise<HttpResponse<any>>;
62
+ requestAll(requestConfigs?: HttpRequestConfig[]): Promise<HttpResponse<any>[]>;
63
+ getAccessToken(sessionId?: string): Promise<string>;
61
64
  }
62
65
  export default AsgardeoReactClient;
@@ -110,7 +110,7 @@ declare class AuthAPI {
110
110
  * @return {Promise<Response | SignInResponse>} - A Promise that resolves with
111
111
  * the value returned by the custom grant request.
112
112
  */
113
- exchangeToken(config: SPACustomGrantConfig, callback: (response: User | Response) => void, dispatch: (state: AuthStateInterface) => void): Promise<User | Response>;
113
+ exchangeToken(config: SPACustomGrantConfig, callback: (response: User | Response) => void): Promise<User | Response>;
114
114
  /**
115
115
  * This method ends a user session. The access token is revoked and the session information is destroyed.
116
116
  *
@@ -156,7 +156,7 @@ declare class AuthAPI {
156
156
  *
157
157
  * @return {Promise<string>} - A Promise that resolves with the access token.
158
158
  */
159
- getAccessToken(): Promise<string>;
159
+ getAccessToken(sessionId?: string): Promise<string>;
160
160
  /**
161
161
  * This method return a Promise that resolves with the idp access token.
162
162
  *
package/dist/cjs/index.js CHANGED
@@ -171,7 +171,11 @@ var AsgardeoContext = (0, import_react.createContext)({
171
171
  signInSilently: null,
172
172
  signOut: null,
173
173
  signUp: null,
174
- user: null
174
+ user: null,
175
+ http: {
176
+ request: () => null,
177
+ requestAll: () => null
178
+ }
175
179
  });
176
180
  AsgardeoContext.displayName = "AsgardeoContext";
177
181
  var AsgardeoContext_default = AsgardeoContext;
@@ -329,7 +333,7 @@ var _AuthAPI = class _AuthAPI {
329
333
  * @return {Promise<Response | SignInResponse>} - A Promise that resolves with
330
334
  * the value returned by the custom grant request.
331
335
  */
332
- exchangeToken(config, callback, dispatch) {
336
+ exchangeToken(config, callback) {
333
337
  return this._client.exchangeToken(config).then((response) => {
334
338
  if (!response) {
335
339
  return null;
@@ -341,7 +345,6 @@ var _AuthAPI = class _AuthAPI {
341
345
  isSignedIn: true,
342
346
  isLoading: false
343
347
  });
344
- dispatch({ ...response, isSignedIn: true, isLoading: false });
345
348
  }
346
349
  callback && callback(response);
347
350
  return response;
@@ -408,8 +411,8 @@ var _AuthAPI = class _AuthAPI {
408
411
  *
409
412
  * @return {Promise<string>} - A Promise that resolves with the access token.
410
413
  */
411
- async getAccessToken() {
412
- return this._client.getAccessToken();
414
+ async getAccessToken(sessionId) {
415
+ return this._client.getAccessToken(sessionId);
413
416
  }
414
417
  /**
415
418
  * This method return a Promise that resolves with the idp access token.
@@ -742,7 +745,6 @@ var AsgardeoReactClient = class extends import_browser6.AsgardeoBrowserClient {
742
745
  return this.withLoading(async () => {
743
746
  try {
744
747
  const configData = await this.asgardeo.getConfigData();
745
- const scopes = configData?.scopes;
746
748
  if (!organization.id) {
747
749
  throw new import_browser6.AsgardeoRuntimeError(
748
750
  "Organization ID is required for switching organizations",
@@ -764,12 +766,8 @@ var AsgardeoReactClient = class extends import_browser6.AsgardeoBrowserClient {
764
766
  returnsSession: true,
765
767
  signInRequired: true
766
768
  };
767
- return await this.asgardeo.exchangeToken(
768
- exchangeConfig,
769
- (user) => {
770
- },
771
- () => null
772
- );
769
+ return await this.asgardeo.exchangeToken(exchangeConfig, (user) => {
770
+ });
773
771
  } catch (error) {
774
772
  throw new import_browser6.AsgardeoRuntimeError(
775
773
  `Failed to switch organization: ${error.message || error}`,
@@ -842,6 +840,15 @@ var AsgardeoReactClient = class extends import_browser6.AsgardeoBrowserClient {
842
840
  "The signUp method with SignUpOptions is not implemented in the React client."
843
841
  );
844
842
  }
843
+ async request(requestConfig) {
844
+ return this.asgardeo.httpRequest(requestConfig);
845
+ }
846
+ async requestAll(requestConfigs) {
847
+ return this.asgardeo.httpRequestAll(requestConfigs);
848
+ }
849
+ async getAccessToken(sessionId) {
850
+ return this.asgardeo.getAccessToken(sessionId);
851
+ }
845
852
  };
846
853
  var AsgardeoReactClient_default = AsgardeoReactClient;
847
854
 
@@ -1677,19 +1684,6 @@ var AsgardeoProvider = ({
1677
1684
  setIsLoadingSync(asgardeo.isLoading());
1678
1685
  }
1679
1686
  };
1680
- const signUp = async (payload) => {
1681
- try {
1682
- return await asgardeo.signUp(payload);
1683
- } catch (error) {
1684
- throw new import_browser13.AsgardeoRuntimeError(
1685
- `Error while signing up: ${error.message || error}`,
1686
- "asgardeo-signUp-Error",
1687
- "react",
1688
- "An error occurred while trying to sign up."
1689
- );
1690
- }
1691
- };
1692
- const signOut = async (options, afterSignOut) => asgardeo.signOut(options, afterSignOut);
1693
1687
  const switchOrganization = async (organization) => {
1694
1688
  try {
1695
1689
  setIsLoadingSync(true);
@@ -1722,57 +1716,75 @@ var AsgardeoProvider = ({
1722
1716
  flattenedProfile: (0, import_browser13.generateFlattenedUserProfile)(payload, prev?.schemas)
1723
1717
  }));
1724
1718
  };
1725
- return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
1726
- AsgardeoContext_default.Provider,
1719
+ const value = (0, import_react15.useMemo)(
1720
+ () => ({
1721
+ applicationId,
1722
+ organizationHandle: config?.organizationHandle,
1723
+ signInUrl,
1724
+ signUpUrl,
1725
+ afterSignInUrl,
1726
+ baseUrl,
1727
+ getAccessToken: asgardeo.getAccessToken.bind(asgardeo),
1728
+ isInitialized: isInitializedSync,
1729
+ isLoading: isLoadingSync,
1730
+ isSignedIn: isSignedInSync,
1731
+ organization: currentOrganization,
1732
+ signIn,
1733
+ signInSilently,
1734
+ signOut: asgardeo.signOut.bind(asgardeo),
1735
+ signUp: asgardeo.signUp.bind(asgardeo),
1736
+ user,
1737
+ http: {
1738
+ request: asgardeo.request.bind(asgardeo),
1739
+ requestAll: asgardeo.requestAll.bind(asgardeo)
1740
+ }
1741
+ }),
1742
+ [
1743
+ applicationId,
1744
+ config?.organizationHandle,
1745
+ signInUrl,
1746
+ signUpUrl,
1747
+ afterSignInUrl,
1748
+ baseUrl,
1749
+ isInitializedSync,
1750
+ isLoadingSync,
1751
+ isSignedInSync,
1752
+ currentOrganization,
1753
+ signIn,
1754
+ signInSilently,
1755
+ user,
1756
+ asgardeo
1757
+ ]
1758
+ );
1759
+ return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(AsgardeoContext_default.Provider, { value, children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(I18nProvider_default, { preferences: preferences?.i18n, children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
1760
+ BrandingProvider_default,
1727
1761
  {
1728
- value: {
1729
- applicationId,
1730
- organizationHandle: config?.organizationHandle,
1731
- signInUrl,
1732
- signUpUrl,
1733
- afterSignInUrl,
1734
- baseUrl,
1735
- isInitialized: isInitializedSync,
1736
- isLoading: isLoadingSync,
1737
- isSignedIn: isSignedInSync,
1738
- organization: currentOrganization,
1739
- signIn,
1740
- signInSilently,
1741
- signOut,
1742
- signUp,
1743
- user
1744
- },
1745
- children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(I18nProvider_default, { preferences: preferences?.i18n, children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
1746
- BrandingProvider_default,
1762
+ brandingPreference,
1763
+ isLoading: isBrandingLoading,
1764
+ error: brandingError,
1765
+ enabled: preferences?.theme?.inheritFromBranding !== false,
1766
+ refetch: refetchBranding,
1767
+ children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
1768
+ ThemeProvider_default,
1747
1769
  {
1748
- brandingPreference,
1749
- isLoading: isBrandingLoading,
1750
- error: brandingError,
1751
- enabled: preferences?.theme?.inheritFromBranding !== false,
1752
- refetch: refetchBranding,
1753
- children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
1754
- ThemeProvider_default,
1770
+ inheritFromBranding: preferences?.theme?.inheritFromBranding,
1771
+ theme: preferences?.theme?.overrides,
1772
+ mode: isDarkMode ? "dark" : "light",
1773
+ children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(FlowProvider_default, { children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(UserProvider_default, { profile: userProfile, onUpdateProfile: handleProfileUpdate, children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
1774
+ OrganizationProvider_default,
1755
1775
  {
1756
- inheritFromBranding: preferences?.theme?.inheritFromBranding,
1757
- theme: preferences?.theme?.overrides,
1758
- mode: isDarkMode ? "dark" : "light",
1759
- children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(FlowProvider_default, { children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(UserProvider_default, { profile: userProfile, onUpdateProfile: handleProfileUpdate, children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
1760
- OrganizationProvider_default,
1761
- {
1762
- getAllOrganizations: async () => await asgardeo.getAllOrganizations(),
1763
- myOrganizations,
1764
- currentOrganization,
1765
- onOrganizationSwitch: switchOrganization,
1766
- revalidateMyOrganizations: async () => await asgardeo.getMyOrganizations(),
1767
- children
1768
- }
1769
- ) }) })
1776
+ getAllOrganizations: async () => await asgardeo.getAllOrganizations(),
1777
+ myOrganizations,
1778
+ currentOrganization,
1779
+ onOrganizationSwitch: switchOrganization,
1780
+ revalidateMyOrganizations: async () => await asgardeo.getMyOrganizations(),
1781
+ children
1770
1782
  }
1771
- )
1783
+ ) }) })
1772
1784
  }
1773
- ) })
1785
+ )
1774
1786
  }
1775
- );
1787
+ ) }) });
1776
1788
  };
1777
1789
  var AsgardeoProvider_default = AsgardeoProvider;
1778
1790