@frontegg/redux-store 7.111.0-alpha.4 → 7.112.0
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.
- package/auth/LoginState/actions/hostedLoginAuthorize.actions.js +16 -2
- package/auth/LoginState/actions/index.js +11 -5
- package/index.js +1 -1
- package/node/auth/LoginState/actions/hostedLoginAuthorize.actions.js +16 -2
- package/node/auth/LoginState/actions/index.js +10 -4
- package/node/index.js +1 -1
- package/node/toolkit/FronteggNativeModule.js +79 -2
- package/package.json +2 -2
- package/toolkit/FronteggNativeModule.d.ts +21 -0
- package/toolkit/FronteggNativeModule.js +79 -2
|
@@ -4,6 +4,7 @@ import { HOSTED_LOGIN_VERIFIER_KEY } from '../../../constants';
|
|
|
4
4
|
import { getBaseNameWithoutSlashSuffix, getSearchParam, isOauthCallbackRoute, TENANT_ID_PARAM_KEY } from '../helpers';
|
|
5
5
|
import { getUri, isSteppedUp } from '../../helpers';
|
|
6
6
|
import { SHOULD_STEP_UP_KEY } from '../../StepUpState/consts';
|
|
7
|
+
import { FronteggNativeModule } from '../../../toolkit';
|
|
7
8
|
export default ((store, api, sharedActions) => {
|
|
8
9
|
const actions = sharedActions;
|
|
9
10
|
|
|
@@ -11,8 +12,15 @@ export default ((store, api, sharedActions) => {
|
|
|
11
12
|
* @protected
|
|
12
13
|
*/
|
|
13
14
|
const __requestHostedLoginSilentAuthorize = async () => {
|
|
14
|
-
|
|
15
|
-
|
|
15
|
+
var _response;
|
|
16
|
+
let response;
|
|
17
|
+
if (FronteggNativeModule.isGetTokensAvailable()) {
|
|
18
|
+
const tokens = await FronteggNativeModule.getTokens();
|
|
19
|
+
response = await api.auth.silentOAuthRefreshTokenV3(tokens);
|
|
20
|
+
} else {
|
|
21
|
+
response = await api.auth.silentOAuthRefreshTokenV2();
|
|
22
|
+
}
|
|
23
|
+
if ((_response = response) != null && _response.user) {
|
|
16
24
|
await actions.afterAuthenticationStateUpdate(response, {
|
|
17
25
|
isAuthenticated: true,
|
|
18
26
|
isLoading: false
|
|
@@ -79,6 +87,9 @@ export default ((store, api, sharedActions) => {
|
|
|
79
87
|
if (tenantId) {
|
|
80
88
|
params['tenantId'] = tenantId;
|
|
81
89
|
}
|
|
90
|
+
if (FronteggNativeModule.isAvailable('closeWindow')) {
|
|
91
|
+
return FronteggNativeModule.closeWindow('not_authorized');
|
|
92
|
+
}
|
|
82
93
|
const searchParams = new URLSearchParams(params);
|
|
83
94
|
const url = `${oauthUrl}?${searchParams.toString()}`;
|
|
84
95
|
onRedirectTo(url, {
|
|
@@ -129,6 +140,9 @@ export default ((store, api, sharedActions) => {
|
|
|
129
140
|
additionalParams = additionalParams || {};
|
|
130
141
|
additionalParams['login_direct_action'] = btoa(JSON.stringify(loginDirectAction));
|
|
131
142
|
}
|
|
143
|
+
if (FronteggNativeModule.isAvailable('requestAuthorize')) {
|
|
144
|
+
return FronteggNativeModule.requestAuthorize(payload);
|
|
145
|
+
}
|
|
132
146
|
if (((_additionalParams = additionalParams) == null ? void 0 : _additionalParams['prompt']) === 'login') {
|
|
133
147
|
return await requestHostedLoginAuthorize(additionalParams);
|
|
134
148
|
}
|
|
@@ -26,7 +26,7 @@ import { LoginFlow, LoginStep } from '../interfaces';
|
|
|
26
26
|
import { base64urlDecode, deepResetState, delay, errorHandler, errorTraceId, GTMEventAction, publicKeyCredentialToJSON, reportGTMEvent, retryIfNeeded, withRetryConfig } from '../../../helpers';
|
|
27
27
|
import { initialState } from '../state';
|
|
28
28
|
import { getSearchParam, isEmailPayload, isUsernamePayload, shouldShowPasswordRotationPromptFunc, TENANT_ID_PARAM_KEY } from '../helpers';
|
|
29
|
-
import { AuthStrategyEnum, ContextHolder, FeatureFlags, removeTabTenantFromSessionStorage, WebAuthnDeviceType } from '@frontegg/rest-api';
|
|
29
|
+
import { AuthStrategyEnum, ContextHolder, FeatureFlags, getTabTenantFromSessionStorage, removeTabTenantFromSessionStorage, WebAuthnDeviceType } from '@frontegg/rest-api';
|
|
30
30
|
import hostedLoginAuthorizeActions from './hostedLoginAuthorize.actions';
|
|
31
31
|
import { FronteggNativeModule, isEntitlementsDeeplyEqual } from '../../../toolkit';
|
|
32
32
|
import { REQUEST_NAME, UserVerifiedOriginTypes } from '../../interfaces';
|
|
@@ -51,10 +51,13 @@ export default ((store, api, sharedActions) => {
|
|
|
51
51
|
return;
|
|
52
52
|
}
|
|
53
53
|
try {
|
|
54
|
-
const
|
|
54
|
+
const tabTenantId = getTabTenantFromSessionStorage(store.root.appName);
|
|
55
|
+
const body = _extends({
|
|
55
56
|
grant_type: 'refresh_token',
|
|
56
57
|
refresh_token: user == null ? void 0 : user.refreshToken
|
|
57
|
-
}
|
|
58
|
+
}, tabTenantId ? {
|
|
59
|
+
tenantId: tabTenantId
|
|
60
|
+
} : {});
|
|
58
61
|
const response = await api.auth.exchangeOAuthTokensV2(body);
|
|
59
62
|
const updatedUser = await __handleUnnecessaryEntitlementsUpdate(response.user);
|
|
60
63
|
actions.afterAuthenticationStateUpdate(_extends({}, response, {
|
|
@@ -1316,10 +1319,13 @@ export default ((store, api, sharedActions) => {
|
|
|
1316
1319
|
return;
|
|
1317
1320
|
}
|
|
1318
1321
|
try {
|
|
1319
|
-
const
|
|
1322
|
+
const tabTenantId = getTabTenantFromSessionStorage(store.root.appName);
|
|
1323
|
+
const body = _extends({
|
|
1320
1324
|
grant_type: 'refresh_token',
|
|
1321
1325
|
refresh_token: currentUser == null ? void 0 : currentUser.refreshToken
|
|
1322
|
-
}
|
|
1326
|
+
}, tabTenantId ? {
|
|
1327
|
+
tenantId: tabTenantId
|
|
1328
|
+
} : {});
|
|
1323
1329
|
const response = await api.auth.exchangeOAuthTokensV2(body);
|
|
1324
1330
|
const updatedUser = await __handleUnnecessaryEntitlementsUpdate(response.user);
|
|
1325
1331
|
actions.afterAuthenticationStateUpdate(_extends({}, response, {
|
package/index.js
CHANGED
|
@@ -11,6 +11,7 @@ var _constants = require("../../../constants");
|
|
|
11
11
|
var _helpers2 = require("../helpers");
|
|
12
12
|
var _helpers3 = require("../../helpers");
|
|
13
13
|
var _consts = require("../../StepUpState/consts");
|
|
14
|
+
var _toolkit = require("../../../toolkit");
|
|
14
15
|
var _default = (store, api, sharedActions) => {
|
|
15
16
|
const actions = sharedActions;
|
|
16
17
|
|
|
@@ -18,8 +19,15 @@ var _default = (store, api, sharedActions) => {
|
|
|
18
19
|
* @protected
|
|
19
20
|
*/
|
|
20
21
|
const __requestHostedLoginSilentAuthorize = async () => {
|
|
21
|
-
|
|
22
|
-
|
|
22
|
+
var _response;
|
|
23
|
+
let response;
|
|
24
|
+
if (_toolkit.FronteggNativeModule.isGetTokensAvailable()) {
|
|
25
|
+
const tokens = await _toolkit.FronteggNativeModule.getTokens();
|
|
26
|
+
response = await api.auth.silentOAuthRefreshTokenV3(tokens);
|
|
27
|
+
} else {
|
|
28
|
+
response = await api.auth.silentOAuthRefreshTokenV2();
|
|
29
|
+
}
|
|
30
|
+
if ((_response = response) != null && _response.user) {
|
|
23
31
|
await actions.afterAuthenticationStateUpdate(response, {
|
|
24
32
|
isAuthenticated: true,
|
|
25
33
|
isLoading: false
|
|
@@ -86,6 +94,9 @@ var _default = (store, api, sharedActions) => {
|
|
|
86
94
|
if (tenantId) {
|
|
87
95
|
params['tenantId'] = tenantId;
|
|
88
96
|
}
|
|
97
|
+
if (_toolkit.FronteggNativeModule.isAvailable('closeWindow')) {
|
|
98
|
+
return _toolkit.FronteggNativeModule.closeWindow('not_authorized');
|
|
99
|
+
}
|
|
89
100
|
const searchParams = new URLSearchParams(params);
|
|
90
101
|
const url = `${oauthUrl}?${searchParams.toString()}`;
|
|
91
102
|
onRedirectTo(url, {
|
|
@@ -136,6 +147,9 @@ var _default = (store, api, sharedActions) => {
|
|
|
136
147
|
additionalParams = additionalParams || {};
|
|
137
148
|
additionalParams['login_direct_action'] = btoa(JSON.stringify(loginDirectAction));
|
|
138
149
|
}
|
|
150
|
+
if (_toolkit.FronteggNativeModule.isAvailable('requestAuthorize')) {
|
|
151
|
+
return _toolkit.FronteggNativeModule.requestAuthorize(payload);
|
|
152
|
+
}
|
|
139
153
|
if (((_additionalParams = additionalParams) == null ? void 0 : _additionalParams['prompt']) === 'login') {
|
|
140
154
|
return await requestHostedLoginAuthorize(additionalParams);
|
|
141
155
|
}
|
|
@@ -58,10 +58,13 @@ var _default = (store, api, sharedActions) => {
|
|
|
58
58
|
return;
|
|
59
59
|
}
|
|
60
60
|
try {
|
|
61
|
-
const
|
|
61
|
+
const tabTenantId = (0, _restApi.getTabTenantFromSessionStorage)(store.root.appName);
|
|
62
|
+
const body = (0, _extends2.default)({
|
|
62
63
|
grant_type: 'refresh_token',
|
|
63
64
|
refresh_token: user == null ? void 0 : user.refreshToken
|
|
64
|
-
}
|
|
65
|
+
}, tabTenantId ? {
|
|
66
|
+
tenantId: tabTenantId
|
|
67
|
+
} : {});
|
|
65
68
|
const response = await api.auth.exchangeOAuthTokensV2(body);
|
|
66
69
|
const updatedUser = await __handleUnnecessaryEntitlementsUpdate(response.user);
|
|
67
70
|
actions.afterAuthenticationStateUpdate((0, _extends2.default)({}, response, {
|
|
@@ -1323,10 +1326,13 @@ var _default = (store, api, sharedActions) => {
|
|
|
1323
1326
|
return;
|
|
1324
1327
|
}
|
|
1325
1328
|
try {
|
|
1326
|
-
const
|
|
1329
|
+
const tabTenantId = (0, _restApi.getTabTenantFromSessionStorage)(store.root.appName);
|
|
1330
|
+
const body = (0, _extends2.default)({
|
|
1327
1331
|
grant_type: 'refresh_token',
|
|
1328
1332
|
refresh_token: currentUser == null ? void 0 : currentUser.refreshToken
|
|
1329
|
-
}
|
|
1333
|
+
}, tabTenantId ? {
|
|
1334
|
+
tenantId: tabTenantId
|
|
1335
|
+
} : {});
|
|
1330
1336
|
const response = await api.auth.exchangeOAuthTokensV2(body);
|
|
1331
1337
|
const updatedUser = await __handleUnnecessaryEntitlementsUpdate(response.user);
|
|
1332
1338
|
actions.afterAuthenticationStateUpdate((0, _extends2.default)({}, response, {
|
package/node/index.js
CHANGED
|
@@ -8,6 +8,7 @@ const FRONTEGG_EXTERNAL_MOBILE_BROWSER_KEY = 'frontegg_external_mobile_browser';
|
|
|
8
8
|
class FronteggNativeModule {
|
|
9
9
|
constructor() {
|
|
10
10
|
this.backToLoginImpl = undefined;
|
|
11
|
+
this.callbackSeq = 0;
|
|
11
12
|
this.loginWithSSO = identifier => {
|
|
12
13
|
if (this.isIOSNativeBridgeAvailable()) {
|
|
13
14
|
var _window$webkit, _window$webkit$messag, _window$webkit$messag2;
|
|
@@ -85,6 +86,46 @@ class FronteggNativeModule {
|
|
|
85
86
|
var _window$FronteggNativ6, _window$FronteggNativ7;
|
|
86
87
|
return (_window$FronteggNativ6 = (_window$FronteggNativ7 = window.FronteggNativeBridgeFunctions) == null ? void 0 : _window$FronteggNativ7['shouldPromptSocialLoginConsent']) != null ? _window$FronteggNativ6 : false;
|
|
87
88
|
};
|
|
89
|
+
this.isMobileSDK = () => {
|
|
90
|
+
return this.isIOSNativeBridgeAvailable() || this.isAndroidNativeBridgeAvailable();
|
|
91
|
+
};
|
|
92
|
+
this.isGetTokensAvailable = () => {
|
|
93
|
+
return this.isAvailable('getTokens');
|
|
94
|
+
};
|
|
95
|
+
this.getTokens = () => {
|
|
96
|
+
if (!this.isIOSNativeBridgeAvailable() && !this.isAndroidNativeBridgeAvailable()) {
|
|
97
|
+
return Promise.reject(new Error('FronteggNativeBridge is not available'));
|
|
98
|
+
}
|
|
99
|
+
const {
|
|
100
|
+
callbackId,
|
|
101
|
+
promise
|
|
102
|
+
} = this.registerCallback();
|
|
103
|
+
if (this.isIOSNativeBridgeAvailable()) {
|
|
104
|
+
this.postMessageIOS('getTokens', '', callbackId);
|
|
105
|
+
} else {
|
|
106
|
+
var _window$FronteggNativ8, _window$FronteggNativ9;
|
|
107
|
+
(_window$FronteggNativ8 = window.FronteggNativeBridge) == null ? void 0 : (_window$FronteggNativ9 = _window$FronteggNativ8.getTokens) == null ? void 0 : _window$FronteggNativ9.call(_window$FronteggNativ8, callbackId);
|
|
108
|
+
}
|
|
109
|
+
return promise;
|
|
110
|
+
};
|
|
111
|
+
this.requestAuthorize = payload => {
|
|
112
|
+
const serialized = JSON.stringify(payload != null ? payload : {});
|
|
113
|
+
if (this.isIOSNativeBridgeAvailable()) {
|
|
114
|
+
this.postMessageIOS('requestAuthorize', serialized);
|
|
115
|
+
} else if (this.isAndroidNativeBridgeAvailable()) {
|
|
116
|
+
var _window$FronteggNativ10, _window$FronteggNativ11;
|
|
117
|
+
(_window$FronteggNativ10 = window.FronteggNativeBridge) == null ? void 0 : (_window$FronteggNativ11 = _window$FronteggNativ10.requestAuthorize) == null ? void 0 : _window$FronteggNativ11.call(_window$FronteggNativ10, serialized);
|
|
118
|
+
}
|
|
119
|
+
};
|
|
120
|
+
this.closeWindow = reason => {
|
|
121
|
+
const r = reason != null ? reason : '';
|
|
122
|
+
if (this.isIOSNativeBridgeAvailable()) {
|
|
123
|
+
this.postMessageIOS('closeWindow', r);
|
|
124
|
+
} else if (this.isAndroidNativeBridgeAvailable()) {
|
|
125
|
+
var _window$FronteggNativ12, _window$FronteggNativ13;
|
|
126
|
+
(_window$FronteggNativ12 = window.FronteggNativeBridge) == null ? void 0 : (_window$FronteggNativ13 = _window$FronteggNativ12.closeWindow) == null ? void 0 : _window$FronteggNativ13.call(_window$FronteggNativ12, r);
|
|
127
|
+
}
|
|
128
|
+
};
|
|
88
129
|
}
|
|
89
130
|
isIOSNativeBridgeAvailable() {
|
|
90
131
|
var _window$webkit6, _window$webkit6$messa;
|
|
@@ -132,11 +173,47 @@ class FronteggNativeModule {
|
|
|
132
173
|
}
|
|
133
174
|
isAvailable(method) {
|
|
134
175
|
if (this.isIOSNativeBridgeAvailable() || this.isAndroidNativeBridgeAvailable()) {
|
|
135
|
-
var _window$
|
|
136
|
-
return (_window$
|
|
176
|
+
var _window$FronteggNativ14, _window$FronteggNativ15;
|
|
177
|
+
return (_window$FronteggNativ14 = (_window$FronteggNativ15 = window.FronteggNativeBridgeFunctions) == null ? void 0 : _window$FronteggNativ15[method]) != null ? _window$FronteggNativ14 : false;
|
|
137
178
|
}
|
|
138
179
|
return false;
|
|
139
180
|
}
|
|
181
|
+
postMessageIOS(action, payload, callbackId) {
|
|
182
|
+
var _window$webkit7, _window$webkit7$messa, _window$webkit7$messa2;
|
|
183
|
+
(_window$webkit7 = window.webkit) == null ? void 0 : (_window$webkit7$messa = _window$webkit7.messageHandlers) == null ? void 0 : (_window$webkit7$messa2 = _window$webkit7$messa.FronteggNativeBridge) == null ? void 0 : _window$webkit7$messa2.postMessage(JSON.stringify({
|
|
184
|
+
action,
|
|
185
|
+
payload,
|
|
186
|
+
callbackId
|
|
187
|
+
}));
|
|
188
|
+
}
|
|
189
|
+
registerCallback(timeoutMs = 20000) {
|
|
190
|
+
if (!window.FronteggNativeBridgeCallbacks) {
|
|
191
|
+
window.FronteggNativeBridgeCallbacks = {};
|
|
192
|
+
}
|
|
193
|
+
this.callbackSeq += 1;
|
|
194
|
+
const callbackId = `fe_cb_${Date.now()}_${this.callbackSeq}`;
|
|
195
|
+
const promise = new Promise((resolve, reject) => {
|
|
196
|
+
const timer = setTimeout(() => {
|
|
197
|
+
var _window$FronteggNativ16;
|
|
198
|
+
(_window$FronteggNativ16 = window.FronteggNativeBridgeCallbacks) == null ? true : delete _window$FronteggNativ16[callbackId];
|
|
199
|
+
reject(new Error('native_bridge_timeout'));
|
|
200
|
+
}, timeoutMs);
|
|
201
|
+
window.FronteggNativeBridgeCallbacks[callbackId] = {
|
|
202
|
+
resolve: value => {
|
|
203
|
+
clearTimeout(timer);
|
|
204
|
+
resolve(value);
|
|
205
|
+
},
|
|
206
|
+
reject: reason => {
|
|
207
|
+
clearTimeout(timer);
|
|
208
|
+
reject(reason instanceof Error ? reason : new Error(String(reason != null ? reason : 'native_bridge_error')));
|
|
209
|
+
}
|
|
210
|
+
};
|
|
211
|
+
});
|
|
212
|
+
return {
|
|
213
|
+
callbackId,
|
|
214
|
+
promise
|
|
215
|
+
};
|
|
216
|
+
}
|
|
140
217
|
}
|
|
141
218
|
var _default = new FronteggNativeModule();
|
|
142
219
|
exports.default = _default;
|
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@frontegg/redux-store",
|
|
3
|
-
"version": "7.
|
|
3
|
+
"version": "7.112.0",
|
|
4
4
|
"main": "./node/index.js",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Frontegg LTD",
|
|
7
7
|
"dependencies": {
|
|
8
8
|
"@babel/runtime": "^7.18.6",
|
|
9
9
|
"@frontegg/entitlements-javascript-commons": "1.1.2",
|
|
10
|
-
"@frontegg/rest-api": "7.
|
|
10
|
+
"@frontegg/rest-api": "7.112.0",
|
|
11
11
|
"fast-deep-equal": "3.1.3",
|
|
12
12
|
"get-value": "^3.0.1",
|
|
13
13
|
"proxy-compare": "^3.0.0",
|
|
@@ -1,9 +1,21 @@
|
|
|
1
|
+
export interface FronteggNativeOAuthTokens {
|
|
2
|
+
accessToken: string;
|
|
3
|
+
refreshToken: string;
|
|
4
|
+
}
|
|
1
5
|
export interface FronteggNativeBridge {
|
|
2
6
|
loginWithSSO: (email: string) => void;
|
|
3
7
|
loginWithSocialLogin: (url: string) => void;
|
|
4
8
|
loginWithSocialLoginProvider: (provider: string) => void;
|
|
5
9
|
loginWithCustomSocialLoginProvider: (providerId: string) => void;
|
|
6
10
|
suggestSavePassword: (email: string, password: string) => void;
|
|
11
|
+
isMobileSDK?: () => boolean;
|
|
12
|
+
getTokens?: (callbackId: string) => void;
|
|
13
|
+
requestAuthorize?: (payload: string) => void;
|
|
14
|
+
closeWindow?: (reason: string) => void;
|
|
15
|
+
}
|
|
16
|
+
export interface FronteggNativeBridgeCallback {
|
|
17
|
+
resolve: (value: any) => void;
|
|
18
|
+
reject: (reason?: any) => void;
|
|
7
19
|
}
|
|
8
20
|
declare global {
|
|
9
21
|
interface Window {
|
|
@@ -16,10 +28,12 @@ declare global {
|
|
|
16
28
|
};
|
|
17
29
|
FronteggNativeBridge?: FronteggNativeBridge;
|
|
18
30
|
FronteggNativeBridgeFunctions?: Record<string, boolean>;
|
|
31
|
+
FronteggNativeBridgeCallbacks?: Record<string, FronteggNativeBridgeCallback>;
|
|
19
32
|
}
|
|
20
33
|
}
|
|
21
34
|
declare class FronteggNativeModule {
|
|
22
35
|
private backToLoginImpl?;
|
|
36
|
+
private callbackSeq;
|
|
23
37
|
isIOSNativeBridgeAvailable(): boolean;
|
|
24
38
|
isAndroidNativeBridgeAvailable(): boolean;
|
|
25
39
|
/**
|
|
@@ -50,6 +64,13 @@ declare class FronteggNativeModule {
|
|
|
50
64
|
loginWithCustomSocialLoginProvider: (providerId: string) => void;
|
|
51
65
|
suggestSavePassword: (email: string, password: string) => void;
|
|
52
66
|
promptSocialLoginConsent: () => boolean;
|
|
67
|
+
isMobileSDK: () => boolean;
|
|
68
|
+
isGetTokensAvailable: () => boolean;
|
|
69
|
+
private postMessageIOS;
|
|
70
|
+
private registerCallback;
|
|
71
|
+
getTokens: () => Promise<FronteggNativeOAuthTokens>;
|
|
72
|
+
requestAuthorize: (payload?: Record<string, any>) => void;
|
|
73
|
+
closeWindow: (reason?: string) => void;
|
|
53
74
|
}
|
|
54
75
|
declare const _default: FronteggNativeModule;
|
|
55
76
|
export default _default;
|
|
@@ -2,6 +2,7 @@ const FRONTEGG_EXTERNAL_MOBILE_BROWSER_KEY = 'frontegg_external_mobile_browser';
|
|
|
2
2
|
class FronteggNativeModule {
|
|
3
3
|
constructor() {
|
|
4
4
|
this.backToLoginImpl = undefined;
|
|
5
|
+
this.callbackSeq = 0;
|
|
5
6
|
this.loginWithSSO = identifier => {
|
|
6
7
|
if (this.isIOSNativeBridgeAvailable()) {
|
|
7
8
|
var _window$webkit, _window$webkit$messag, _window$webkit$messag2;
|
|
@@ -79,6 +80,46 @@ class FronteggNativeModule {
|
|
|
79
80
|
var _window$FronteggNativ6, _window$FronteggNativ7;
|
|
80
81
|
return (_window$FronteggNativ6 = (_window$FronteggNativ7 = window.FronteggNativeBridgeFunctions) == null ? void 0 : _window$FronteggNativ7['shouldPromptSocialLoginConsent']) != null ? _window$FronteggNativ6 : false;
|
|
81
82
|
};
|
|
83
|
+
this.isMobileSDK = () => {
|
|
84
|
+
return this.isIOSNativeBridgeAvailable() || this.isAndroidNativeBridgeAvailable();
|
|
85
|
+
};
|
|
86
|
+
this.isGetTokensAvailable = () => {
|
|
87
|
+
return this.isAvailable('getTokens');
|
|
88
|
+
};
|
|
89
|
+
this.getTokens = () => {
|
|
90
|
+
if (!this.isIOSNativeBridgeAvailable() && !this.isAndroidNativeBridgeAvailable()) {
|
|
91
|
+
return Promise.reject(new Error('FronteggNativeBridge is not available'));
|
|
92
|
+
}
|
|
93
|
+
const {
|
|
94
|
+
callbackId,
|
|
95
|
+
promise
|
|
96
|
+
} = this.registerCallback();
|
|
97
|
+
if (this.isIOSNativeBridgeAvailable()) {
|
|
98
|
+
this.postMessageIOS('getTokens', '', callbackId);
|
|
99
|
+
} else {
|
|
100
|
+
var _window$FronteggNativ8, _window$FronteggNativ9;
|
|
101
|
+
(_window$FronteggNativ8 = window.FronteggNativeBridge) == null ? void 0 : (_window$FronteggNativ9 = _window$FronteggNativ8.getTokens) == null ? void 0 : _window$FronteggNativ9.call(_window$FronteggNativ8, callbackId);
|
|
102
|
+
}
|
|
103
|
+
return promise;
|
|
104
|
+
};
|
|
105
|
+
this.requestAuthorize = payload => {
|
|
106
|
+
const serialized = JSON.stringify(payload != null ? payload : {});
|
|
107
|
+
if (this.isIOSNativeBridgeAvailable()) {
|
|
108
|
+
this.postMessageIOS('requestAuthorize', serialized);
|
|
109
|
+
} else if (this.isAndroidNativeBridgeAvailable()) {
|
|
110
|
+
var _window$FronteggNativ10, _window$FronteggNativ11;
|
|
111
|
+
(_window$FronteggNativ10 = window.FronteggNativeBridge) == null ? void 0 : (_window$FronteggNativ11 = _window$FronteggNativ10.requestAuthorize) == null ? void 0 : _window$FronteggNativ11.call(_window$FronteggNativ10, serialized);
|
|
112
|
+
}
|
|
113
|
+
};
|
|
114
|
+
this.closeWindow = reason => {
|
|
115
|
+
const r = reason != null ? reason : '';
|
|
116
|
+
if (this.isIOSNativeBridgeAvailable()) {
|
|
117
|
+
this.postMessageIOS('closeWindow', r);
|
|
118
|
+
} else if (this.isAndroidNativeBridgeAvailable()) {
|
|
119
|
+
var _window$FronteggNativ12, _window$FronteggNativ13;
|
|
120
|
+
(_window$FronteggNativ12 = window.FronteggNativeBridge) == null ? void 0 : (_window$FronteggNativ13 = _window$FronteggNativ12.closeWindow) == null ? void 0 : _window$FronteggNativ13.call(_window$FronteggNativ12, r);
|
|
121
|
+
}
|
|
122
|
+
};
|
|
82
123
|
}
|
|
83
124
|
isIOSNativeBridgeAvailable() {
|
|
84
125
|
var _window$webkit6, _window$webkit6$messa;
|
|
@@ -126,10 +167,46 @@ class FronteggNativeModule {
|
|
|
126
167
|
}
|
|
127
168
|
isAvailable(method) {
|
|
128
169
|
if (this.isIOSNativeBridgeAvailable() || this.isAndroidNativeBridgeAvailable()) {
|
|
129
|
-
var _window$
|
|
130
|
-
return (_window$
|
|
170
|
+
var _window$FronteggNativ14, _window$FronteggNativ15;
|
|
171
|
+
return (_window$FronteggNativ14 = (_window$FronteggNativ15 = window.FronteggNativeBridgeFunctions) == null ? void 0 : _window$FronteggNativ15[method]) != null ? _window$FronteggNativ14 : false;
|
|
131
172
|
}
|
|
132
173
|
return false;
|
|
133
174
|
}
|
|
175
|
+
postMessageIOS(action, payload, callbackId) {
|
|
176
|
+
var _window$webkit7, _window$webkit7$messa, _window$webkit7$messa2;
|
|
177
|
+
(_window$webkit7 = window.webkit) == null ? void 0 : (_window$webkit7$messa = _window$webkit7.messageHandlers) == null ? void 0 : (_window$webkit7$messa2 = _window$webkit7$messa.FronteggNativeBridge) == null ? void 0 : _window$webkit7$messa2.postMessage(JSON.stringify({
|
|
178
|
+
action,
|
|
179
|
+
payload,
|
|
180
|
+
callbackId
|
|
181
|
+
}));
|
|
182
|
+
}
|
|
183
|
+
registerCallback(timeoutMs = 20000) {
|
|
184
|
+
if (!window.FronteggNativeBridgeCallbacks) {
|
|
185
|
+
window.FronteggNativeBridgeCallbacks = {};
|
|
186
|
+
}
|
|
187
|
+
this.callbackSeq += 1;
|
|
188
|
+
const callbackId = `fe_cb_${Date.now()}_${this.callbackSeq}`;
|
|
189
|
+
const promise = new Promise((resolve, reject) => {
|
|
190
|
+
const timer = setTimeout(() => {
|
|
191
|
+
var _window$FronteggNativ16;
|
|
192
|
+
(_window$FronteggNativ16 = window.FronteggNativeBridgeCallbacks) == null ? true : delete _window$FronteggNativ16[callbackId];
|
|
193
|
+
reject(new Error('native_bridge_timeout'));
|
|
194
|
+
}, timeoutMs);
|
|
195
|
+
window.FronteggNativeBridgeCallbacks[callbackId] = {
|
|
196
|
+
resolve: value => {
|
|
197
|
+
clearTimeout(timer);
|
|
198
|
+
resolve(value);
|
|
199
|
+
},
|
|
200
|
+
reject: reason => {
|
|
201
|
+
clearTimeout(timer);
|
|
202
|
+
reject(reason instanceof Error ? reason : new Error(String(reason != null ? reason : 'native_bridge_error')));
|
|
203
|
+
}
|
|
204
|
+
};
|
|
205
|
+
});
|
|
206
|
+
return {
|
|
207
|
+
callbackId,
|
|
208
|
+
promise
|
|
209
|
+
};
|
|
210
|
+
}
|
|
134
211
|
}
|
|
135
212
|
export default new FronteggNativeModule();
|