@frontegg/ionic-capacitor 2.0.9-alpha.10655751692 → 2.0.9-alpha.10738173625

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.
@@ -13,7 +13,7 @@ Pod::Spec.new do |s|
13
13
  s.source_files = 'ios/Plugin/**/*.{swift,h,m,c,cc,mm,cpp}'
14
14
  s.ios.deployment_target = '14.0'
15
15
  s.dependency 'Capacitor'
16
- s.dependency "FronteggSwift", "1.2.16"
16
+ s.dependency "FronteggSwift", "1.2.20"
17
17
  s.swift_version = '5.1'
18
18
  s.pod_target_xcconfig = {
19
19
  'CODE_SIGNING_ALLOWED' => 'YES'
@@ -55,7 +55,7 @@ dependencies {
55
55
  implementation "androidx.browser:browser:1.5.0"
56
56
  implementation 'io.reactivex.rxjava3:rxkotlin:3.0.1'
57
57
  implementation 'com.google.code.gson:gson:2.10'
58
- implementation 'com.frontegg.sdk:android:1.2.18'
58
+ implementation 'com.frontegg.sdk:android:1.2.24'
59
59
 
60
60
  testImplementation "junit:junit:$junitVersion"
61
61
  androidTestImplementation "androidx.test.ext:junit:$androidxJunitVersion"
@@ -56,10 +56,10 @@ public class FronteggNativePlugin extends Plugin {
56
56
  applicationId = regionJson.getString("applicationId");
57
57
  }
58
58
  regions.add(new RegionConfig(
59
- regionJson.getString("key"),
60
- regionJson.getString("baseUrl"),
61
- regionJson.getString("clientId"),
62
- applicationId
59
+ regionJson.getString("key"),
60
+ regionJson.getString("baseUrl"),
61
+ regionJson.getString("clientId"),
62
+ applicationId
63
63
  ));
64
64
  }
65
65
 
@@ -67,7 +67,7 @@ public class FronteggNativePlugin extends Plugin {
67
67
  throw new RuntimeException(e);
68
68
  }
69
69
 
70
- if(regions.isEmpty()) {
70
+ if (regions.isEmpty()) {
71
71
  PluginConfig config = this.getConfig();
72
72
  String baseUrl = config.getString("baseUrl");
73
73
  String clientId = config.getString("clientId");
@@ -76,25 +76,25 @@ public class FronteggNativePlugin extends Plugin {
76
76
  if (baseUrl == null || clientId == null) {
77
77
  throw new RuntimeException("Missing required config parameters: baseUrl, clientId");
78
78
  }
79
- if(baseUrl.startsWith("https://")) {
79
+ if (baseUrl.startsWith("https://")) {
80
80
  baseUrl = baseUrl.substring(baseUrl.indexOf("://") + 3);
81
81
  }
82
82
  FronteggApp.Companion.init(
83
- baseUrl,
84
- clientId,
85
- this.getContext(),
86
- applicationId,
87
- useAssetLinks,
88
- useChromeCustomTabs,
89
- null
83
+ baseUrl,
84
+ clientId,
85
+ this.getContext(),
86
+ applicationId,
87
+ useAssetLinks,
88
+ useChromeCustomTabs,
89
+ null
90
90
  );
91
- }else {
91
+ } else {
92
92
  FronteggApp.Companion.initWithRegions(
93
- regions,
94
- this.getContext(),
95
- useAssetLinks,
96
- useChromeCustomTabs,
97
- null
93
+ regions,
94
+ this.getContext(),
95
+ useAssetLinks,
96
+ useChromeCustomTabs,
97
+ null
98
98
  );
99
99
  }
100
100
 
@@ -104,13 +104,13 @@ public class FronteggNativePlugin extends Plugin {
104
104
  this.disposable.dispose();
105
105
  }
106
106
  this.disposable = Observable.mergeArray(
107
- auth.getAccessToken().getObservable(),
108
- auth.getRefreshToken().getObservable(),
109
- auth.getUser().getObservable(),
110
- auth.isAuthenticated().getObservable(),
111
- auth.isLoading().getObservable(),
112
- auth.getInitializing().getObservable(),
113
- auth.getShowLoader().getObservable()
107
+ auth.getAccessToken().getObservable(),
108
+ auth.getRefreshToken().getObservable(),
109
+ auth.getUser().getObservable(),
110
+ auth.isAuthenticated().getObservable(),
111
+ auth.isLoading().getObservable(),
112
+ auth.getInitializing().getObservable(),
113
+ auth.getShowLoader().getObservable()
114
114
  ).subscribe(nullableObject -> {
115
115
  debouncer.debounce(this::sendEvent);
116
116
  });
@@ -166,8 +166,10 @@ public class FronteggNativePlugin extends Plugin {
166
166
  call.reject("No type or data provided");
167
167
  return;
168
168
  }
169
- FronteggApp.Companion.getInstance().getAuth().directLoginAction(this.getActivity(), type, data);
170
- call.resolve();
169
+ FronteggApp.Companion.getInstance().getAuth().directLoginAction(this.getActivity(), type, data, () -> {
170
+ call.resolve();
171
+ return null;
172
+ });
171
173
  }
172
174
 
173
175
  @PluginMethod
@@ -186,7 +188,9 @@ public class FronteggNativePlugin extends Plugin {
186
188
  return;
187
189
  }
188
190
  FronteggApp.Companion.getInstance().getAuth().switchTenant(tenantId, (success) -> {
189
- call.resolve();
191
+ JSObject result = new JSObject();
192
+ result.put("success", success);
193
+ call.resolve((JSObject) result);
190
194
  return null;
191
195
  });
192
196
  }
@@ -194,17 +198,17 @@ public class FronteggNativePlugin extends Plugin {
194
198
 
195
199
  @PluginMethod
196
200
  public void initWithRegion(PluginCall call) {
197
- String regionKey = call.getString("regionKey");
198
- if (regionKey == null) {
199
- call.reject("No regionKey provided");
200
- return;
201
- }
202
- ExecutorService executor = Executors.newSingleThreadExecutor();
203
- executor.submit(() -> {
204
- FronteggApp.Companion.getInstance().initWithRegion(regionKey);
205
- Handler handler = new Handler(Looper.getMainLooper());
206
- handler.post(call::resolve);
207
- });
201
+ String regionKey = call.getString("regionKey");
202
+ if (regionKey == null) {
203
+ call.reject("No regionKey provided");
204
+ return;
205
+ }
206
+ ExecutorService executor = Executors.newSingleThreadExecutor();
207
+ executor.submit(() -> {
208
+ FronteggApp.Companion.getInstance().initWithRegion(regionKey);
209
+ Handler handler = new Handler(Looper.getMainLooper());
210
+ handler.post(call::resolve);
211
+ });
208
212
  }
209
213
 
210
214
  @PluginMethod
@@ -1,72 +1,215 @@
1
1
  import type { ListenerCallback, PluginListenerHandle } from '@capacitor/core';
2
2
  import type { ITenantsResponse, IUserProfile } from '@frontegg/rest-api';
3
+ import type { LogLevel } from './logger';
3
4
  export declare type User = IUserProfile & {
4
5
  tenants: ITenantsResponse[];
5
6
  activeTenant: ITenantsResponse;
6
7
  };
8
+ /**
9
+ * Represents the state of the Frontegg authentication.
10
+ */
7
11
  export interface FronteggState {
12
+ /**
13
+ * The access token used for authenticating API requests.
14
+ * This token is typically a JWT and should be refreshed periodically before it expires.
15
+ * It is `null` when the user is not authenticated.
16
+ */
8
17
  accessToken: string | null;
18
+ /**
19
+ * The refresh token used to obtain a new access token.
20
+ * This token is used when the access token has expired and a new token is required.
21
+ * It is `null` when the user is not authenticated.
22
+ */
9
23
  refreshToken: string | null;
24
+ /**
25
+ * Indicates whether the user is currently authenticated.
26
+ * It is `true` if the user has successfully logged in and holds a valid access token; otherwise, `false`.
27
+ */
10
28
  isAuthenticated: boolean;
29
+ /**
30
+ * Represents the current authenticated user.
31
+ * It is an object containing user details if the user is authenticated; otherwise, `null`.
32
+ */
11
33
  user: User | null;
34
+ /**
35
+ * Controls whether the loader or spinner should be displayed.
36
+ * This is `true` when the application is loading or performing an action that requires user feedback.
37
+ * @deprecated use isLoading instead
38
+ */
12
39
  showLoader: boolean;
40
+ /**
41
+ * Controls whether the loader or spinner should be displayed.
42
+ * This is `true` when the application is loading or performing an action that requires user feedback.
43
+ */
44
+ isLoading: boolean;
45
+ /**
46
+ * The selected region configuration.
47
+ * This is typically used in multi-regional setups where different regions have different configurations.
48
+ * It is `null` if no region is selected or if the application is not configured for multiple regions.
49
+ */
13
50
  selectedRegion: string | null;
51
+ /**
52
+ * Indicates whether a token refresh operation is currently in progress.
53
+ * This is `true` when the refresh token is being used to obtain a new access token.
54
+ */
55
+ refreshingToken: boolean;
56
+ /**
57
+ * Indicates whether the application is in the initialization phase.
58
+ * This is `true` when the application is initializing, such as during the initial load or when setting up the authentication state.
59
+ */
60
+ initializing: boolean;
14
61
  }
15
62
  export declare type SubscribeFunc<T, K extends keyof T> = (value: T[K]) => void;
16
63
  export declare type SubscribeMap<T> = {
17
64
  [K in keyof T]: Set<SubscribeFunc<T, K>>;
18
65
  };
66
+ /**
67
+ * Represents the constant configuration values used by the Frontegg authentication module.
68
+ */
19
69
  export interface FronteggConstants {
70
+ /**
71
+ * The base URL of the Frontegg API.
72
+ * This is the primary endpoint for all API requests.
73
+ */
20
74
  baseUrl: string;
75
+ /**
76
+ * The client ID used for authenticating API requests.
77
+ * This is a unique identifier for the client application.
78
+ */
21
79
  clientId: string;
80
+ /**
81
+ * The application ID associated with the Frontegg setup.
82
+ * It may be `null` if the application ID is not required.
83
+ */
22
84
  applicationId: string | null;
85
+ /**
86
+ * The bundle ID of the application.
87
+ * This is typically used to uniquely identify the application in a multi-app environment.
88
+ */
23
89
  bundleId: string;
90
+ /**
91
+ * Indicates whether the application is configured for regional deployment.
92
+ * This is `true` if the application supports multiple regions, otherwise `false`.
93
+ */
24
94
  isRegional: boolean;
95
+ /**
96
+ * The data associated with each region.
97
+ * This is an optional array containing configuration details for each region, including the region key, base URL, and client ID.
98
+ * It is present only if `isRegional` is `true`.
99
+ */
25
100
  regionData?: {
26
101
  key: string;
27
102
  baseUrl: string;
28
103
  clientId: string;
29
104
  }[];
30
105
  }
106
+ /**
107
+ * Represents the Frontegg Native Plugin interface that provides methods for interacting with the Frontegg authentication system.
108
+ */
31
109
  export interface FronteggNativePlugin {
110
+ /**
111
+ * Adds an event listener for the specified event name.
112
+ * @param eventName - The name of the event to listen for.
113
+ * @param listenerFunc - The callback function that will be called when the event is triggered.
114
+ * @returns A promise that resolves to a PluginListenerHandle, which can be used to manage the listener.
115
+ */
32
116
  addListener(eventName: string, listenerFunc: ListenerCallback): Promise<PluginListenerHandle> & PluginListenerHandle;
117
+ /**
118
+ * Retrieves the constant configuration values used by the Frontegg authentication module.
119
+ * @returns A promise that resolves to an object containing the FronteggConstants.
120
+ */
33
121
  getConstants(): Promise<FronteggConstants>;
122
+ /**
123
+ * Retrieves the current authentication state.
124
+ * @returns A promise that resolves to an object containing the current FronteggState.
125
+ */
34
126
  getAuthState(): Promise<FronteggState>;
127
+ /**
128
+ * Initiates the login process.
129
+ * @returns A promise that resolves when the login process is completed.
130
+ */
35
131
  login(): Promise<void>;
36
132
  /**
37
- * Used to log in with social login provider directly without visiting the login page
38
- * @param payload
39
- * @param payload.type - the direct login type (direct, social-login, custom-social-login)
40
- * @param payload.data - the direct login data (for direct it's saml url request, for social-login it's the provider name, for custom-social-login it's the provider entity id)
133
+ * Used to log in with a social login provider directly without visiting the login page.
134
+ * @param payload - The payload containing the details for the direct login action.
135
+ * @param payload.type - The direct login type (e.g., direct, social-login, custom-social-login).
136
+ * @param payload.data - The direct login data (e.g., SAML URL request, provider name, provider entity ID).
137
+ * @param payload.ephemeralSession - If true, the session will be ephemeral and will not be saved in the browser.
138
+ * @returns A promise that resolves when the direct login action is completed.
41
139
  */
42
140
  directLoginAction(payload: {
43
141
  type: string;
44
142
  data: string;
45
- }): Promise<void>;
143
+ ephemeralSession: boolean;
144
+ }): Promise<boolean>;
145
+ /**
146
+ * Logs out the current user.
147
+ * This method does not return a promise, and the logout process is performed asynchronously.
148
+ */
46
149
  logout(): void;
150
+ /**
151
+ * Switches the current tenant in the application.
152
+ * @param payload - The payload containing the tenant ID to switch to.
153
+ * @returns A promise that resolves when the tenant switch is completed.
154
+ */
47
155
  switchTenant(payload: {
48
156
  tenantId: string;
49
157
  }): Promise<void>;
50
158
  /**
51
- * used to initialize the plugin with multiple regions
52
- * for more information see:
53
- * iOS: https://github.com/frontegg/frontegg-ios-swift#multi-region-support
54
- * Android: https://github.com/frontegg/frontegg-android-kotlin#multi-region-support
159
+ * Initializes the plugin with the specified region.
160
+ * This method is used to set up the plugin for multi-region support.
161
+ * For more information, see the documentation for iOS and Android multi-region support.
162
+ * @param payload - The payload containing the region key to initialize.
163
+ * @returns A promise that resolves when the initialization with the region is completed.
55
164
  */
56
165
  initWithRegion(payload: {
57
166
  regionKey: string;
58
167
  }): Promise<void>;
168
+ /**
169
+ * Refreshes the authentication token.
170
+ * @returns A promise that resolves when the token refresh is completed.
171
+ */
59
172
  refreshToken(): Promise<void>;
60
173
  }
174
+ /**
175
+ * Represents the configuration for a specific region.
176
+ * This is used in multi-regional setups where different regions have different configurations.
177
+ */
61
178
  export declare type RegionConfig = {
179
+ /**
180
+ * The unique key identifying the region.
181
+ */
62
182
  key: string;
183
+ /**
184
+ * The base URL for the API endpoint in this region.
185
+ */
63
186
  baseUrl: string;
187
+ /**
188
+ * The client ID used for authenticating API requests in this region.
189
+ */
64
190
  clientId: string;
191
+ /**
192
+ * The application ID associated with this region.
193
+ * This is optional and may be undefined.
194
+ */
65
195
  applicationId?: string;
66
196
  };
197
+ /**
198
+ * Represents the standard options for initializing the Frontegg Native Plugin.
199
+ */
67
200
  declare type FronteggNativeStandardOptions = {
201
+ /**
202
+ * The base URL of the Frontegg API.
203
+ */
68
204
  baseUrl: string;
205
+ /**
206
+ * The client ID used for authenticating API requests.
207
+ */
69
208
  clientId: string;
209
+ /**
210
+ * The application ID associated with the Frontegg setup.
211
+ * This is optional and may be undefined.
212
+ */
70
213
  applicationId?: string;
71
214
  };
72
215
  declare type FronteggNativeRegionOptions = {
@@ -112,6 +255,9 @@ declare type FronteggNativeOptions = (FronteggNativeStandardOptions | FronteggNa
112
255
  */
113
256
  useChromeCustomTabs?: boolean;
114
257
  };
258
+ export interface FronteggServiceOptions {
259
+ logLevel: LogLevel;
260
+ }
115
261
  declare module '@capacitor/cli' {
116
262
  interface PluginsConfig {
117
263
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"definitions.js","sourceRoot":"","sources":["../../src/definitions.ts"],"names":[],"mappings":"","sourcesContent":["import type { ListenerCallback, PluginListenerHandle } from '@capacitor/core';\nimport type { ITenantsResponse, IUserProfile } from '@frontegg/rest-api';\n\nexport type User = IUserProfile & {\n tenants: ITenantsResponse[];\n activeTenant: ITenantsResponse;\n};\n\nexport interface FronteggState {\n accessToken: string | null;\n refreshToken: string | null;\n isAuthenticated: boolean;\n user: User | null;\n showLoader: boolean;\n selectedRegion: string | null;\n}\n\nexport type SubscribeFunc<T, K extends keyof T> = (value: T[K]) => void;\nexport type SubscribeMap<T> = {\n [K in keyof T]: Set<SubscribeFunc<T, K>>;\n};\n\nexport interface FronteggConstants {\n baseUrl: string;\n clientId: string;\n applicationId: string | null;\n bundleId: string;\n isRegional: boolean;\n regionData?: { key: string; baseUrl: string; clientId: string }[];\n}\n\nexport interface FronteggNativePlugin {\n addListener(\n eventName: string,\n listenerFunc: ListenerCallback,\n ): Promise<PluginListenerHandle> & PluginListenerHandle;\n\n getConstants(): Promise<FronteggConstants>;\n\n getAuthState(): Promise<FronteggState>;\n\n login(): Promise<void>;\n\n /**\n * Used to log in with social login provider directly without visiting the login page\n * @param payload\n * @param payload.type - the direct login type (direct, social-login, custom-social-login)\n * @param payload.data - the direct login data (for direct it's saml url request, for social-login it's the provider name, for custom-social-login it's the provider entity id)\n */\n directLoginAction(payload: { type: string; data: string }): Promise<void>;\n\n logout(): void;\n\n switchTenant(payload: { tenantId: string }): Promise<void>;\n\n /**\n * used to initialize the plugin with multiple regions\n * for more information see:\n * iOS: https://github.com/frontegg/frontegg-ios-swift#multi-region-support\n * Android: https://github.com/frontegg/frontegg-android-kotlin#multi-region-support\n */\n initWithRegion(payload: { regionKey: string }): Promise<void>;\n\n refreshToken(): Promise<void>;\n}\n\nexport type RegionConfig = {\n key: string;\n baseUrl: string;\n clientId: string;\n applicationId?: string;\n};\n\ntype FronteggNativeStandardOptions = {\n baseUrl: string;\n clientId: string;\n applicationId?: string;\n};\ntype FronteggNativeRegionOptions = {\n /**\n * This is an array of regions to be used as frontegg app.\n *\n * @since 1.0.0\n * @example [{key: \"us\", baseUrl: \"https://us-api.frontegg.com\", clientId: \"us-client-id\"}]\n */\n regions: RegionConfig[];\n};\ntype FronteggNativeOptions = (\n | FronteggNativeStandardOptions\n | FronteggNativeRegionOptions\n) & {\n /**\n * Weather to handle login with social login in external browser.\n * If set to false, the plugin will navigate to the social login page with application webview.\n *\n * NOTE: some of the social login providers prevent login from embedded webview.\n *\n * @default true\n */\n handleLoginWithSocialLogin?: boolean;\n /**\n * Weather to handle login with SSO in external browser.\n * If set to false, the plugin will navigate to the sso page with application webview.\n *\n * @default false\n */\n handleLoginWithSSO?: boolean;\n /**\n * Weather to use the assetlinks to for oauth/callback, this is the default behavior.\n * disabling this will cause the plugin to use custom url scheme for oauth/callback.\n *\n * NOTE: custom url scheme require user interaction to return to the app.\n * @default true\n */\n useAssetLinks?: boolean;\n\n /**\n * Weather to To enable social login via Chrome Custom Tabs, set the useChromeCustomTabs flag to true.\n * By default, the SDK uses the Chrome browser for social login.\n *\n * NOTE: custom url scheme require user interaction to return to the app.\n * @default true\n */\n useChromeCustomTabs?: boolean;\n};\n// eslint-disable-next-line @typescript-eslint/ban-ts-comment\n// @ts-ignore\ndeclare module '@capacitor/cli' {\n export interface PluginsConfig {\n /**\n * You can configure the way the push notifications are displayed when the app is in foreground.\n */\n FronteggNative?: FronteggNativeOptions;\n }\n}\n"]}
1
+ {"version":3,"file":"definitions.js","sourceRoot":"","sources":["../../src/definitions.ts"],"names":[],"mappings":"","sourcesContent":["import type { ListenerCallback, PluginListenerHandle } from '@capacitor/core';\nimport type { ITenantsResponse, IUserProfile } from '@frontegg/rest-api';\n\nimport type { LogLevel } from './logger';\n\nexport type User = IUserProfile & {\n tenants: ITenantsResponse[];\n activeTenant: ITenantsResponse;\n};\n\n/**\n * Represents the state of the Frontegg authentication.\n */\nexport interface FronteggState {\n /**\n * The access token used for authenticating API requests.\n * This token is typically a JWT and should be refreshed periodically before it expires.\n * It is `null` when the user is not authenticated.\n */\n accessToken: string | null;\n\n /**\n * The refresh token used to obtain a new access token.\n * This token is used when the access token has expired and a new token is required.\n * It is `null` when the user is not authenticated.\n */\n refreshToken: string | null;\n\n /**\n * Indicates whether the user is currently authenticated.\n * It is `true` if the user has successfully logged in and holds a valid access token; otherwise, `false`.\n */\n isAuthenticated: boolean;\n\n /**\n * Represents the current authenticated user.\n * It is an object containing user details if the user is authenticated; otherwise, `null`.\n */\n user: User | null;\n\n /**\n * Controls whether the loader or spinner should be displayed.\n * This is `true` when the application is loading or performing an action that requires user feedback.\n * @deprecated use isLoading instead\n */\n showLoader: boolean;\n\n /**\n * Controls whether the loader or spinner should be displayed.\n * This is `true` when the application is loading or performing an action that requires user feedback.\n */\n isLoading: boolean;\n\n /**\n * The selected region configuration.\n * This is typically used in multi-regional setups where different regions have different configurations.\n * It is `null` if no region is selected or if the application is not configured for multiple regions.\n */\n selectedRegion: string | null;\n\n /**\n * Indicates whether a token refresh operation is currently in progress.\n * This is `true` when the refresh token is being used to obtain a new access token.\n */\n refreshingToken: boolean;\n\n /**\n * Indicates whether the application is in the initialization phase.\n * This is `true` when the application is initializing, such as during the initial load or when setting up the authentication state.\n */\n initializing: boolean;\n}\n\nexport type SubscribeFunc<T, K extends keyof T> = (value: T[K]) => void;\nexport type SubscribeMap<T> = {\n [K in keyof T]: Set<SubscribeFunc<T, K>>;\n};\n\n/**\n * Represents the constant configuration values used by the Frontegg authentication module.\n */\nexport interface FronteggConstants {\n /**\n * The base URL of the Frontegg API.\n * This is the primary endpoint for all API requests.\n */\n baseUrl: string;\n\n /**\n * The client ID used for authenticating API requests.\n * This is a unique identifier for the client application.\n */\n clientId: string;\n\n /**\n * The application ID associated with the Frontegg setup.\n * It may be `null` if the application ID is not required.\n */\n applicationId: string | null;\n\n /**\n * The bundle ID of the application.\n * This is typically used to uniquely identify the application in a multi-app environment.\n */\n bundleId: string;\n\n /**\n * Indicates whether the application is configured for regional deployment.\n * This is `true` if the application supports multiple regions, otherwise `false`.\n */\n isRegional: boolean;\n\n /**\n * The data associated with each region.\n * This is an optional array containing configuration details for each region, including the region key, base URL, and client ID.\n * It is present only if `isRegional` is `true`.\n */\n regionData?: { key: string; baseUrl: string; clientId: string }[];\n}\n\n/**\n * Represents the Frontegg Native Plugin interface that provides methods for interacting with the Frontegg authentication system.\n */\nexport interface FronteggNativePlugin {\n /**\n * Adds an event listener for the specified event name.\n * @param eventName - The name of the event to listen for.\n * @param listenerFunc - The callback function that will be called when the event is triggered.\n * @returns A promise that resolves to a PluginListenerHandle, which can be used to manage the listener.\n */\n addListener(\n eventName: string,\n listenerFunc: ListenerCallback,\n ): Promise<PluginListenerHandle> & PluginListenerHandle;\n\n /**\n * Retrieves the constant configuration values used by the Frontegg authentication module.\n * @returns A promise that resolves to an object containing the FronteggConstants.\n */\n getConstants(): Promise<FronteggConstants>;\n\n /**\n * Retrieves the current authentication state.\n * @returns A promise that resolves to an object containing the current FronteggState.\n */\n getAuthState(): Promise<FronteggState>;\n\n /**\n * Initiates the login process.\n * @returns A promise that resolves when the login process is completed.\n */\n login(): Promise<void>;\n\n /**\n * Used to log in with a social login provider directly without visiting the login page.\n * @param payload - The payload containing the details for the direct login action.\n * @param payload.type - The direct login type (e.g., direct, social-login, custom-social-login).\n * @param payload.data - The direct login data (e.g., SAML URL request, provider name, provider entity ID).\n * @param payload.ephemeralSession - If true, the session will be ephemeral and will not be saved in the browser.\n * @returns A promise that resolves when the direct login action is completed.\n */\n directLoginAction(payload: {\n type: string;\n data: string;\n ephemeralSession: boolean;\n }): Promise<boolean>;\n\n /**\n * Logs out the current user.\n * This method does not return a promise, and the logout process is performed asynchronously.\n */\n logout(): void;\n\n /**\n * Switches the current tenant in the application.\n * @param payload - The payload containing the tenant ID to switch to.\n * @returns A promise that resolves when the tenant switch is completed.\n */\n switchTenant(payload: { tenantId: string }): Promise<void>;\n\n /**\n * Initializes the plugin with the specified region.\n * This method is used to set up the plugin for multi-region support.\n * For more information, see the documentation for iOS and Android multi-region support.\n * @param payload - The payload containing the region key to initialize.\n * @returns A promise that resolves when the initialization with the region is completed.\n */\n initWithRegion(payload: { regionKey: string }): Promise<void>;\n\n /**\n * Refreshes the authentication token.\n * @returns A promise that resolves when the token refresh is completed.\n */\n refreshToken(): Promise<void>;\n}\n\n/**\n * Represents the configuration for a specific region.\n * This is used in multi-regional setups where different regions have different configurations.\n */\nexport type RegionConfig = {\n /**\n * The unique key identifying the region.\n */\n key: string;\n\n /**\n * The base URL for the API endpoint in this region.\n */\n baseUrl: string;\n\n /**\n * The client ID used for authenticating API requests in this region.\n */\n clientId: string;\n\n /**\n * The application ID associated with this region.\n * This is optional and may be undefined.\n */\n applicationId?: string;\n};\n\n/**\n * Represents the standard options for initializing the Frontegg Native Plugin.\n */\ntype FronteggNativeStandardOptions = {\n /**\n * The base URL of the Frontegg API.\n */\n baseUrl: string;\n\n /**\n * The client ID used for authenticating API requests.\n */\n clientId: string;\n\n /**\n * The application ID associated with the Frontegg setup.\n * This is optional and may be undefined.\n */\n applicationId?: string;\n};\n\ntype FronteggNativeRegionOptions = {\n /**\n * This is an array of regions to be used as frontegg app.\n *\n * @since 1.0.0\n * @example [{key: \"us\", baseUrl: \"https://us-api.frontegg.com\", clientId: \"us-client-id\"}]\n */\n regions: RegionConfig[];\n};\ntype FronteggNativeOptions = (\n | FronteggNativeStandardOptions\n | FronteggNativeRegionOptions\n) & {\n /**\n * Weather to handle login with social login in external browser.\n * If set to false, the plugin will navigate to the social login page with application webview.\n *\n * NOTE: some of the social login providers prevent login from embedded webview.\n *\n * @default true\n */\n handleLoginWithSocialLogin?: boolean;\n /**\n * Weather to handle login with SSO in external browser.\n * If set to false, the plugin will navigate to the sso page with application webview.\n *\n * @default false\n */\n handleLoginWithSSO?: boolean;\n /**\n * Weather to use the assetlinks to for oauth/callback, this is the default behavior.\n * disabling this will cause the plugin to use custom url scheme for oauth/callback.\n *\n * NOTE: custom url scheme require user interaction to return to the app.\n * @default true\n */\n useAssetLinks?: boolean;\n\n /**\n * Weather to To enable social login via Chrome Custom Tabs, set the useChromeCustomTabs flag to true.\n * By default, the SDK uses the Chrome browser for social login.\n *\n * NOTE: custom url scheme require user interaction to return to the app.\n * @default true\n */\n useChromeCustomTabs?: boolean;\n};\n\nexport interface FronteggServiceOptions {\n logLevel: LogLevel;\n}\n\n// eslint-disable-next-line @typescript-eslint/ban-ts-comment\n// @ts-ignore\ndeclare module '@capacitor/cli' {\n export interface PluginsConfig {\n /**\n * You can configure the way the push notifications are displayed when the app is in foreground.\n */\n FronteggNative?: FronteggNativeOptions;\n }\n}\n"]}
@@ -1,14 +1,15 @@
1
- import type { FronteggConstants, FronteggState } from './definitions';
1
+ import type { FronteggConstants, FronteggServiceOptions, FronteggState } from './definitions';
2
2
  import type { FronteggObservable } from './observables';
3
3
  export declare class FronteggService {
4
4
  private state;
5
+ private logger;
5
6
  private mapListeners;
6
7
  private readonly orderedListenerKeys;
7
- constructor();
8
+ constructor(options?: FronteggServiceOptions);
8
9
  private isChanged;
9
10
  getState(): FronteggState;
10
11
  getNativeState(): Promise<FronteggState>;
11
- get $isLoading(): FronteggObservable<'showLoader'>;
12
+ get $isLoading(): FronteggObservable<'isLoading'>;
12
13
  get $isAuthenticated(): FronteggObservable<'isAuthenticated'>;
13
14
  get $user(): FronteggObservable<'user'>;
14
15
  get $accessToken(): FronteggObservable<'accessToken'>;
@@ -21,8 +22,9 @@ export declare class FronteggService {
21
22
  * Used to log in with social login provider directly without visiting the login page
22
23
  * @param type - the direct login type (direct, social-login, custom-social-login)
23
24
  * @param data - the direct login data (for direct it's saml url request, for social-login it's the provider name, for custom-social-login it's the provider entity id)
25
+ * @param ephemeralSession - if true, the session will be ephemeral and will not be saved in the browser
24
26
  */
25
- directLoginAction(type: string, data: string): Promise<void>;
27
+ directLoginAction(type: string, data: string, ephemeralSession?: boolean): Promise<boolean>;
26
28
  logout(): void;
27
29
  getConstants(): Promise<FronteggConstants>;
28
30
  switchTenant(tenantId: string): Promise<void>;
@@ -1,10 +1,11 @@
1
1
  import { registerPlugin } from '@capacitor/core';
2
+ import { Logger } from './logger';
2
3
  import { createObservable } from './observables';
3
4
  const FronteggNative = registerPlugin('FronteggNative', {
4
5
  web: () => import('./web').then(m => new m.FronteggNativeWeb()),
5
6
  });
6
7
  export class FronteggService {
7
- constructor() {
8
+ constructor(options) {
8
9
  this.orderedListenerKeys = [
9
10
  'refreshToken',
10
11
  'accessToken',
@@ -12,38 +13,48 @@ export class FronteggService {
12
13
  'isAuthenticated',
13
14
  'selectedRegion',
14
15
  'showLoader',
16
+ 'refreshingToken',
17
+ 'initializing',
15
18
  ];
19
+ this.logger = new Logger(options === null || options === void 0 ? void 0 : options.logLevel);
20
+ this.logger.info('FronteggService created');
16
21
  this.state = {
17
22
  isAuthenticated: false,
18
23
  showLoader: true,
24
+ isLoading: true,
19
25
  user: null,
20
26
  accessToken: null,
21
27
  refreshToken: null,
22
28
  selectedRegion: null,
29
+ refreshingToken: false,
30
+ initializing: true,
23
31
  };
24
32
  this.mapListeners = {
25
33
  isAuthenticated: new Set(),
26
34
  showLoader: new Set(),
35
+ isLoading: new Set(),
27
36
  user: new Set(),
28
37
  accessToken: new Set(),
29
38
  refreshToken: new Set(),
30
39
  selectedRegion: new Set(),
40
+ refreshingToken: new Set(),
41
+ initializing: new Set(),
31
42
  };
32
43
  FronteggNative.addListener('onFronteggAuthEvent', (state) => {
33
- console.log('onFronteggAuthEvent', {
44
+ this.logger.info('onFronteggAuthEvent', {
34
45
  isAuthenticated: state.isAuthenticated,
35
- showLoader: state.showLoader,
46
+ showLoader: state.isLoading,
36
47
  user: `${state.user}`,
37
- accessToken: state.accessToken && state.accessToken.length > 50
38
- ? `${state.accessToken.slice(0, 50)}...`
39
- : state.accessToken,
48
+ accessToken: state.accessToken ? '****' : null,
40
49
  refreshToken: state.refreshToken,
41
50
  selectedRegion: state.selectedRegion,
51
+ refreshingToken: state.refreshingToken,
52
+ initializing: state.initializing,
42
53
  });
43
54
  const keys = this.orderedListenerKeys;
44
55
  keys.forEach(key => {
45
56
  if (this.isChanged(this.state[key], state[key])) {
46
- console.log('onFronteggAuthEvent key: ', key);
57
+ this.logger.info('onFronteggAuthEvent', key, state[key]);
47
58
  this.state[key] = state[key];
48
59
  this.mapListeners[key].forEach((listener) => listener(state[key]));
49
60
  }
@@ -51,7 +62,7 @@ export class FronteggService {
51
62
  this.state = state;
52
63
  });
53
64
  FronteggNative.getAuthState().then((state) => {
54
- console.log('getAuthState()', state);
65
+ this.logger.info('getAuthState()', state);
55
66
  const keys = Object.keys(this.mapListeners);
56
67
  for (const item of keys) {
57
68
  const key = item;
@@ -62,11 +73,50 @@ export class FronteggService {
62
73
  }
63
74
  });
64
75
  }
65
- isChanged(value1, value2) {
66
- if (value1 == value2) {
76
+ isChanged(obj1, obj2) {
77
+ // Strict equality check
78
+ if (obj1 === obj2) {
67
79
  return false;
68
80
  }
69
- return JSON.stringify(value1) != JSON.stringify(value2);
81
+ // Check for null and undefined
82
+ if (obj1 === null ||
83
+ obj1 === undefined ||
84
+ obj2 === null ||
85
+ obj2 === undefined) {
86
+ return obj1 !== obj2;
87
+ }
88
+ // Handle primitive types (number, string, boolean)
89
+ if (typeof obj1 !== 'object' && typeof obj2 !== 'object') {
90
+ return obj1 !== obj2;
91
+ }
92
+ // Handle arrays
93
+ if (Array.isArray(obj1) && Array.isArray(obj2)) {
94
+ if (obj1.length !== obj2.length) {
95
+ return true;
96
+ }
97
+ for (let i = 0; i < obj1.length; i++) {
98
+ if (this.isChanged(obj1[i], obj2[i])) {
99
+ return true;
100
+ }
101
+ }
102
+ return false;
103
+ }
104
+ // Handle objects
105
+ if (typeof obj1 === 'object' && typeof obj2 === 'object') {
106
+ const keys1 = Object.keys(obj1);
107
+ const keys2 = Object.keys(obj2);
108
+ if (keys1.length !== keys2.length) {
109
+ return true;
110
+ }
111
+ for (const key of keys1) {
112
+ if (!keys2.includes(key) || this.isChanged(obj1[key], obj2[key])) {
113
+ return true;
114
+ }
115
+ }
116
+ return false;
117
+ }
118
+ // If none of the above conditions match, the values have changed
119
+ return true;
70
120
  }
71
121
  getState() {
72
122
  return this.state;
@@ -75,7 +125,7 @@ export class FronteggService {
75
125
  return FronteggNative.getAuthState();
76
126
  }
77
127
  get $isLoading() {
78
- return createObservable(this.mapListeners, this.state, 'showLoader');
128
+ return createObservable(this.mapListeners, this.state, 'isLoading');
79
129
  }
80
130
  get $isAuthenticated() {
81
131
  return createObservable(this.mapListeners, this.state, 'isAuthenticated');
@@ -99,9 +149,10 @@ export class FronteggService {
99
149
  * Used to log in with social login provider directly without visiting the login page
100
150
  * @param type - the direct login type (direct, social-login, custom-social-login)
101
151
  * @param data - the direct login data (for direct it's saml url request, for social-login it's the provider name, for custom-social-login it's the provider entity id)
152
+ * @param ephemeralSession - if true, the session will be ephemeral and will not be saved in the browser
102
153
  */
103
- directLoginAction(type, data) {
104
- return FronteggNative.directLoginAction({ type, data });
154
+ directLoginAction(type, data, ephemeralSession = true) {
155
+ return FronteggNative.directLoginAction({ type, data, ephemeralSession });
105
156
  }
106
157
  logout() {
107
158
  FronteggNative.logout();