@frontegg/ionic-capacitor 0.0.4

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.
@@ -0,0 +1,21 @@
1
+ require 'json'
2
+
3
+ package = JSON.parse(File.read(File.join(__dir__, 'package.json')))
4
+
5
+ Pod::Spec.new do |s|
6
+ s.name = 'FronteggIonicCapacitor'
7
+ s.version = package['version']
8
+ s.summary = package['description']
9
+ s.license = package['license']
10
+ s.homepage = package['repository']['url']
11
+ s.author = package['author']
12
+ s.source = { :git => package['repository']['url'], :tag => s.version.to_s }
13
+ s.source_files = 'ios/Plugin/**/*.{swift,h,m,c,cc,mm,cpp}'
14
+ s.ios.deployment_target = '14.0'
15
+ s.dependency 'Capacitor'
16
+ s.dependency "FronteggSwift", "1.0.4"
17
+ s.swift_version = '5.1'
18
+ s.pod_target_xcconfig = {
19
+ 'CODE_SIGNING_ALLOWED' => 'YES'
20
+ }
21
+ end
package/README.md ADDED
@@ -0,0 +1,230 @@
1
+ # @frontegg/ionic-capacitor
2
+
3
+ Frontegg Ionic Capacitor SDK
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ npm install @frontegg/ionic-capacitor
9
+ npx cap sync
10
+ ```
11
+
12
+ ## API
13
+
14
+ <docgen-index>
15
+
16
+ * [`login()`](#login)
17
+ * [`logout()`](#logout)
18
+ * [`addListener(string, ...)`](#addlistenerstring)
19
+ * [`getConstants()`](#getconstants)
20
+ * [`getAuthState()`](#getauthstate)
21
+ * [Interfaces](#interfaces)
22
+ * [Type Aliases](#type-aliases)
23
+ * [Enums](#enums)
24
+
25
+ </docgen-index>
26
+
27
+ <docgen-api>
28
+ <!--Update the source file JSDoc comments and rerun docgen to update the docs below-->
29
+
30
+ ### login()
31
+
32
+ ```typescript
33
+ login() => void
34
+ ```
35
+
36
+ --------------------
37
+
38
+
39
+ ### logout()
40
+
41
+ ```typescript
42
+ logout() => void
43
+ ```
44
+
45
+ --------------------
46
+
47
+
48
+ ### addListener(string, ...)
49
+
50
+ ```typescript
51
+ addListener(eventName: string, listenerFunc: ListenerCallback) => Promise<PluginListenerHandle> & PluginListenerHandle
52
+ ```
53
+
54
+ | Param | Type |
55
+ | ------------------ | ------------------------------------------------------------- |
56
+ | **`eventName`** | <code>string</code> |
57
+ | **`listenerFunc`** | <code><a href="#listenercallback">ListenerCallback</a></code> |
58
+
59
+ **Returns:** <code>Promise&lt;<a href="#pluginlistenerhandle">PluginListenerHandle</a>&gt; & <a href="#pluginlistenerhandle">PluginListenerHandle</a></code>
60
+
61
+ --------------------
62
+
63
+
64
+ ### getConstants()
65
+
66
+ ```typescript
67
+ getConstants() => Promise<Record<string, string>>
68
+ ```
69
+
70
+ **Returns:** <code>Promise&lt;<a href="#record">Record</a>&lt;string, string&gt;&gt;</code>
71
+
72
+ --------------------
73
+
74
+
75
+ ### getAuthState()
76
+
77
+ ```typescript
78
+ getAuthState() => Promise<FronteggState>
79
+ ```
80
+
81
+ **Returns:** <code>Promise&lt;<a href="#fronteggstate">FronteggState</a>&gt;</code>
82
+
83
+ --------------------
84
+
85
+
86
+ ### Interfaces
87
+
88
+
89
+ #### PluginListenerHandle
90
+
91
+ | Prop | Type |
92
+ | ------------ | ----------------------------------------- |
93
+ | **`remove`** | <code>() =&gt; Promise&lt;void&gt;</code> |
94
+
95
+
96
+ #### FronteggState
97
+
98
+ | Prop | Type |
99
+ | --------------------- | --------------------------------------------------------------------------- |
100
+ | **`accessToken`** | <code>string \| null</code> |
101
+ | **`refreshToken`** | <code>string \| null</code> |
102
+ | **`isAuthenticated`** | <code>boolean</code> |
103
+ | **`user`** | <code><a href="#igetusersv2response">IGetUsersV2Response</a> \| null</code> |
104
+ | **`showLoader`** | <code>boolean</code> |
105
+
106
+
107
+ #### IGetUsersV2Response
108
+
109
+ | Prop | Type |
110
+ | ----------------- | ------------------------------------------------------------------------------------------------------------ |
111
+ | **`roles`** | <code>IRole[]</code> |
112
+ | **`rolesIds`** | <code>string[]</code> |
113
+ | **`permissions`** | <code>ITeamUserPermission[]</code> |
114
+ | **`groups`** | <code><a href="#pick">Pick</a>&lt;<a href="#igroupresponse">IGroupResponse</a>, 'id' \| 'roles'&gt;[]</code> |
115
+
116
+
117
+ #### Date
118
+
119
+ Enables basic storage and retrieval of dates and times.
120
+
121
+ | Method | Signature | Description |
122
+ | ---------------------- | ------------------------------------------------------------------------------------------------------------ | --------------------------------------------------------------------------------------------------------------------------------------- |
123
+ | **toString** | () =&gt; string | Returns a string representation of a date. The format of the string depends on the locale. |
124
+ | **toDateString** | () =&gt; string | Returns a date as a string value. |
125
+ | **toTimeString** | () =&gt; string | Returns a time as a string value. |
126
+ | **toLocaleString** | () =&gt; string | Returns a value as a string value appropriate to the host environment's current locale. |
127
+ | **toLocaleDateString** | () =&gt; string | Returns a date as a string value appropriate to the host environment's current locale. |
128
+ | **toLocaleTimeString** | () =&gt; string | Returns a time as a string value appropriate to the host environment's current locale. |
129
+ | **valueOf** | () =&gt; number | Returns the stored time value in milliseconds since midnight, January 1, 1970 UTC. |
130
+ | **getTime** | () =&gt; number | Gets the time value in milliseconds. |
131
+ | **getFullYear** | () =&gt; number | Gets the year, using local time. |
132
+ | **getUTCFullYear** | () =&gt; number | Gets the year using Universal Coordinated Time (UTC). |
133
+ | **getMonth** | () =&gt; number | Gets the month, using local time. |
134
+ | **getUTCMonth** | () =&gt; number | Gets the month of a <a href="#date">Date</a> object using Universal Coordinated Time (UTC). |
135
+ | **getDate** | () =&gt; number | Gets the day-of-the-month, using local time. |
136
+ | **getUTCDate** | () =&gt; number | Gets the day-of-the-month, using Universal Coordinated Time (UTC). |
137
+ | **getDay** | () =&gt; number | Gets the day of the week, using local time. |
138
+ | **getUTCDay** | () =&gt; number | Gets the day of the week using Universal Coordinated Time (UTC). |
139
+ | **getHours** | () =&gt; number | Gets the hours in a date, using local time. |
140
+ | **getUTCHours** | () =&gt; number | Gets the hours value in a <a href="#date">Date</a> object using Universal Coordinated Time (UTC). |
141
+ | **getMinutes** | () =&gt; number | Gets the minutes of a <a href="#date">Date</a> object, using local time. |
142
+ | **getUTCMinutes** | () =&gt; number | Gets the minutes of a <a href="#date">Date</a> object using Universal Coordinated Time (UTC). |
143
+ | **getSeconds** | () =&gt; number | Gets the seconds of a <a href="#date">Date</a> object, using local time. |
144
+ | **getUTCSeconds** | () =&gt; number | Gets the seconds of a <a href="#date">Date</a> object using Universal Coordinated Time (UTC). |
145
+ | **getMilliseconds** | () =&gt; number | Gets the milliseconds of a <a href="#date">Date</a>, using local time. |
146
+ | **getUTCMilliseconds** | () =&gt; number | Gets the milliseconds of a <a href="#date">Date</a> object using Universal Coordinated Time (UTC). |
147
+ | **getTimezoneOffset** | () =&gt; number | Gets the difference in minutes between the time on the local computer and Universal Coordinated Time (UTC). |
148
+ | **setTime** | (time: number) =&gt; number | Sets the date and time value in the <a href="#date">Date</a> object. |
149
+ | **setMilliseconds** | (ms: number) =&gt; number | Sets the milliseconds value in the <a href="#date">Date</a> object using local time. |
150
+ | **setUTCMilliseconds** | (ms: number) =&gt; number | Sets the milliseconds value in the <a href="#date">Date</a> object using Universal Coordinated Time (UTC). |
151
+ | **setSeconds** | (sec: number, ms?: number \| undefined) =&gt; number | Sets the seconds value in the <a href="#date">Date</a> object using local time. |
152
+ | **setUTCSeconds** | (sec: number, ms?: number \| undefined) =&gt; number | Sets the seconds value in the <a href="#date">Date</a> object using Universal Coordinated Time (UTC). |
153
+ | **setMinutes** | (min: number, sec?: number \| undefined, ms?: number \| undefined) =&gt; number | Sets the minutes value in the <a href="#date">Date</a> object using local time. |
154
+ | **setUTCMinutes** | (min: number, sec?: number \| undefined, ms?: number \| undefined) =&gt; number | Sets the minutes value in the <a href="#date">Date</a> object using Universal Coordinated Time (UTC). |
155
+ | **setHours** | (hours: number, min?: number \| undefined, sec?: number \| undefined, ms?: number \| undefined) =&gt; number | Sets the hour value in the <a href="#date">Date</a> object using local time. |
156
+ | **setUTCHours** | (hours: number, min?: number \| undefined, sec?: number \| undefined, ms?: number \| undefined) =&gt; number | Sets the hours value in the <a href="#date">Date</a> object using Universal Coordinated Time (UTC). |
157
+ | **setDate** | (date: number) =&gt; number | Sets the numeric day-of-the-month value of the <a href="#date">Date</a> object using local time. |
158
+ | **setUTCDate** | (date: number) =&gt; number | Sets the numeric day of the month in the <a href="#date">Date</a> object using Universal Coordinated Time (UTC). |
159
+ | **setMonth** | (month: number, date?: number \| undefined) =&gt; number | Sets the month value in the <a href="#date">Date</a> object using local time. |
160
+ | **setUTCMonth** | (month: number, date?: number \| undefined) =&gt; number | Sets the month value in the <a href="#date">Date</a> object using Universal Coordinated Time (UTC). |
161
+ | **setFullYear** | (year: number, month?: number \| undefined, date?: number \| undefined) =&gt; number | Sets the year of the <a href="#date">Date</a> object using local time. |
162
+ | **setUTCFullYear** | (year: number, month?: number \| undefined, date?: number \| undefined) =&gt; number | Sets the year value in the <a href="#date">Date</a> object using Universal Coordinated Time (UTC). |
163
+ | **toUTCString** | () =&gt; string | Returns a date converted to a string using Universal Coordinated Time (UTC). |
164
+ | **toISOString** | () =&gt; string | Returns a date as a string value in ISO format. |
165
+ | **toJSON** | (key?: any) =&gt; string | Used by the JSON.stringify method to enable the transformation of an object's data for JavaScript Object Notation (JSON) serialization. |
166
+
167
+
168
+ ### Type Aliases
169
+
170
+
171
+ #### ListenerCallback
172
+
173
+ <code>(err: any, ...args: any[]): void</code>
174
+
175
+
176
+ #### Record
177
+
178
+ Construct a type with a set of properties K of type T
179
+
180
+ <code>{
181
  [P in K]: T;
1
182
  }</code>
183
+
184
+
185
+ #### User
186
+
187
+ <code><a href="#iuserprofile">IUserProfile</a></code>
188
+
189
+
190
+ #### IUserProfile
191
+
192
+ <code><a href="#igetusersv2response">IGetUsersV2Response</a></code>
193
+
194
+
195
+ #### IRole
196
+
197
+ <code>{ id: string; key: string; isDefault: boolean; name: string; description?: null; permissions: string[]; tenantId?: string; vendorId: string; createdAt: <a href="#date">Date</a>; updatedAt: <a href="#date">Date</a>; }</code>
198
+
199
+
200
+ #### ITeamUserPermission
201
+
202
+ <code>{ description: string; fePermission: boolean; id: string; key: string; name: string; roleIds: string[]; createdAt: <a href="#date">Date</a>; updatedAt: <a href="#date">Date</a>; categoryId: string; }</code>
203
+
204
+
205
+ #### Pick
206
+
207
+ From T, pick a set of properties whose keys are in the union K
208
+
209
+ <code>{
2
210
  [P in K]: T[P];
3
211
  }</code>
212
+
213
+
214
+ #### IGroupResponse
215
+
216
+ <code>{ id: string; name: string; color?: string; description?: string; metadata?: string; roles?: IRole[]; users?: IGroupUser[]; managedBy: <a href="#groupmanagedbyenum">GroupManagedByEnum</a>; }</code>
217
+
218
+
219
+ #### IGroupUser
220
+
221
+ <code>{ id: string; email: string; name: string; profilePictureUrl: string | null; activatedForTenant?: boolean; createdAt: <a href="#date">Date</a>; }</code>
222
+
223
+
224
+ ### Enums
225
+
226
+
227
+ #### GroupManagedByEnum
228
+
229
+ | Members | Value |
230
+ | -------------- | ----------------------- |
231
+ | **`FRONTEGG`** | <code>"frontegg"</code> |
232
+ | **`SCIM2`** | <code>"scim2"</code> |
233
+
234
+ </docgen-api>
@@ -0,0 +1,63 @@
1
+ ext {
2
+ junitVersion = project.hasProperty('junitVersion') ? rootProject.ext.junitVersion : '4.13.2'
3
+ androidxAppCompatVersion = project.hasProperty('androidxAppCompatVersion') ? rootProject.ext.androidxAppCompatVersion : '1.6.1'
4
+ androidxJunitVersion = project.hasProperty('androidxJunitVersion') ? rootProject.ext.androidxJunitVersion : '1.1.5'
5
+ androidxEspressoCoreVersion = project.hasProperty('androidxEspressoCoreVersion') ? rootProject.ext.androidxEspressoCoreVersion : '3.5.1'
6
+ }
7
+
8
+ buildscript {
9
+ repositories {
10
+ google()
11
+ mavenCentral()
12
+ }
13
+ dependencies {
14
+ classpath 'com.android.tools.build:gradle:8.0.0'
15
+ }
16
+ }
17
+
18
+ apply plugin: 'com.android.library'
19
+
20
+ android {
21
+ namespace "com.frontegg.ionic"
22
+ compileSdkVersion project.hasProperty('compileSdkVersion') ? rootProject.ext.compileSdkVersion : 33
23
+ defaultConfig {
24
+ minSdkVersion project.hasProperty('minSdkVersion') ? rootProject.ext.minSdkVersion : 22
25
+ targetSdkVersion project.hasProperty('targetSdkVersion') ? rootProject.ext.targetSdkVersion : 33
26
+ versionCode 1
27
+ versionName "1.0"
28
+ testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
29
+ }
30
+ buildTypes {
31
+ release {
32
+ minifyEnabled false
33
+ proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
34
+ }
35
+ }
36
+ lintOptions {
37
+ abortOnError false
38
+ }
39
+ compileOptions {
40
+ sourceCompatibility JavaVersion.VERSION_17
41
+ targetCompatibility JavaVersion.VERSION_17
42
+ }
43
+ }
44
+
45
+ repositories {
46
+ google()
47
+ mavenCentral()
48
+ }
49
+
50
+
51
+ dependencies {
52
+ implementation fileTree(dir: 'libs', include: ['*.jar'])
53
+ implementation project(':capacitor-android')
54
+ implementation "androidx.appcompat:appcompat:$androidxAppCompatVersion"
55
+ implementation "androidx.browser:browser:1.5.0"
56
+ implementation 'io.reactivex.rxjava3:rxkotlin:3.0.1'
57
+ implementation 'com.google.code.gson:gson:2.8.9'
58
+ implementation 'com.frontegg.sdk:android:1.0.4'
59
+
60
+ testImplementation "junit:junit:$junitVersion"
61
+ androidTestImplementation "androidx.test.ext:junit:$androidxJunitVersion"
62
+ androidTestImplementation "androidx.test.espresso:espresso-core:$androidxEspressoCoreVersion"
63
+ }
@@ -0,0 +1,2 @@
1
+ <manifest xmlns:android="http://schemas.android.com/apk/res/android">
2
+ </manifest>
@@ -0,0 +1,146 @@
1
+ package com.frontegg.ionic;
2
+
3
+
4
+ import com.frontegg.android.FronteggApp;
5
+ import com.frontegg.android.FronteggAuth;
6
+ import com.frontegg.android.models.User;
7
+ import com.getcapacitor.JSObject;
8
+ import com.getcapacitor.Plugin;
9
+ import com.getcapacitor.PluginCall;
10
+ import com.getcapacitor.PluginMethod;
11
+ import com.getcapacitor.annotation.CapacitorPlugin;
12
+
13
+ import org.json.JSONObject;
14
+
15
+ import java.lang.reflect.Field;
16
+ import java.util.HashMap;
17
+ import java.util.Map;
18
+ import java.util.Objects;
19
+
20
+ import io.reactivex.rxjava3.core.Observable;
21
+ import io.reactivex.rxjava3.disposables.Disposable;
22
+
23
+ @CapacitorPlugin(name = "FronteggNative")
24
+ public class FronteggNativePlugin extends Plugin {
25
+ private Disposable disposable = null;
26
+
27
+ @Override
28
+ public void load() {
29
+ Map<String, String> constants = this.getConstants();
30
+
31
+ FronteggApp.Companion.init(
32
+ Objects.requireNonNull(constants.get("baseUrl")),
33
+ Objects.requireNonNull(constants.get("clientId")),
34
+ this.getContext()
35
+ );
36
+
37
+
38
+ FronteggAuth auth = FronteggAuth.Companion.getInstance();
39
+
40
+ if (this.disposable != null) {
41
+ this.disposable.dispose();
42
+ }
43
+ this.disposable = Observable.mergeArray(
44
+ auth.getAccessToken().getObservable(),
45
+ auth.getRefreshToken().getObservable(),
46
+ auth.getUser().getObservable(),
47
+ auth.isAuthenticated().getObservable(),
48
+ auth.isLoading().getObservable(),
49
+ auth.getInitializing().getObservable(),
50
+ auth.getShowLoader().getObservable()
51
+ ).subscribe(nullableObject -> {
52
+ sendEvent();
53
+ });
54
+ }
55
+
56
+ private void sendEvent() {
57
+ JSObject data = getData();
58
+ notifyListeners("onFronteggAuthEvent", data);
59
+ }
60
+
61
+ private JSObject getData() {
62
+ FronteggAuth auth = FronteggAuth.Companion.getInstance();
63
+ String accessToken = auth.getAccessToken().getValue();
64
+ String refreshToken = auth.getRefreshToken().getValue();
65
+ User user = auth.getUser().getValue();
66
+ boolean isAuthenticated = auth.isAuthenticated().getValue();
67
+ boolean isLoading = auth.isLoading().getValue();
68
+ boolean initializing = auth.getInitializing().getValue();
69
+ boolean showLoader = auth.getShowLoader().getValue();
70
+
71
+ JSObject data = new JSObject();
72
+
73
+ data.put("accessToken", accessToken);
74
+ data.put("refreshToken", refreshToken);
75
+ if (user != null) {
76
+ data.put("user", Parser.userToJSONObject(user));
77
+ }
78
+ data.put("isAuthenticated", isAuthenticated);
79
+ data.put("isLoading", isLoading);
80
+ data.put("initializing", initializing);
81
+ data.put("showLoader", showLoader);
82
+
83
+ return data;
84
+ }
85
+
86
+
87
+ @PluginMethod
88
+ public void login(PluginCall call) {
89
+ FronteggApp.Companion.getInstance().getAuth().login(this.getActivity());
90
+ call.resolve();
91
+ }
92
+
93
+ @PluginMethod
94
+ public void logout(PluginCall call) {
95
+ FronteggApp.Companion.getInstance().getAuth().logout(() -> {
96
+ call.resolve();
97
+ return null;
98
+ });
99
+ }
100
+
101
+ @PluginMethod
102
+ public void getAuthState(PluginCall call) {
103
+ call.resolve(getData());
104
+ }
105
+
106
+
107
+ public Map<String, String> getConstants() {
108
+ String packageName = getContext().getPackageName();
109
+ String className = packageName + ".BuildConfig";
110
+
111
+ try {
112
+ Class<?> buildConfigClass = Class.forName(className);
113
+
114
+ // Get the field from BuildConfig class
115
+ Field baseUrlField = buildConfigClass.getField("FRONTEGG_DOMAIN");
116
+ Field clientIdField = buildConfigClass.getField("FRONTEGG_CLIENT_ID");
117
+ String baseUrl = (String) baseUrlField.get(null); // Assuming it's a String
118
+ String clientId = (String) clientIdField.get(null); // Assuming it's a String
119
+
120
+ Map<String, String> resultMap = new HashMap<>();
121
+ resultMap.put("baseUrl", baseUrl);
122
+ resultMap.put("clientId", clientId);
123
+ resultMap.put("bundleId", packageName);
124
+
125
+ return resultMap;
126
+ } catch (ClassNotFoundException e) {
127
+ System.out.println("Class not found: " + className);
128
+ throw new RuntimeException(e);
129
+ } catch (NoSuchFieldException e) {
130
+ System.out.println(
131
+ "Field not found in BuildConfig: " +
132
+ "buildConfigField \"String\", 'FRONTEGG_DOMAIN', \"\\\"$fronteggDomain\\\"\"\n" +
133
+ "buildConfigField \"String\", 'FRONTEGG_CLIENT_ID', \"\\\"$fronteggClientId\\\"\""
134
+ );
135
+ throw new RuntimeException(e);
136
+ } catch (IllegalAccessException e) {
137
+ System.out.println(
138
+ "Access problem with field in BuildConfig: " +
139
+ "buildConfigField \"String\", 'FRONTEGG_DOMAIN', \"\\\"$fronteggDomain\\\"\"\n" +
140
+ "buildConfigField \"String\", 'FRONTEGG_CLIENT_ID', \"\\\"$fronteggClientId\\\"\""
141
+ );
142
+ throw new RuntimeException(e);
143
+ }
144
+ }
145
+
146
+ }
@@ -0,0 +1,22 @@
1
+ package com.frontegg.ionic;
2
+
3
+ import com.frontegg.android.models.User;
4
+
5
+ import org.json.JSONException;
6
+ import org.json.JSONObject;
7
+
8
+ import com.google.gson.Gson;
9
+
10
+ public class Parser {
11
+
12
+
13
+ public static JSONObject userToJSONObject(User user) {
14
+ String jsonStr = new Gson().toJson(user, User.class);
15
+ try {
16
+ return new JSONObject(jsonStr);
17
+ } catch (JSONException e) {
18
+ return null;
19
+ }
20
+ }
21
+
22
+ }
File without changes