@frontegg/react-hooks 7.10.0-alpha.0 → 7.11.0-alpha.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/FronteggNativeProvider/FronteggNativeProvider.d.ts +10 -0
- package/FronteggNativeProvider/FronteggNativeProvider.js +81 -0
- package/FronteggNativeProvider/index.d.ts +1 -0
- package/FronteggNativeProvider/index.js +1 -0
- package/FronteggNativeProvider/package.json +6 -0
- package/index.d.ts +1 -0
- package/index.js +2 -1
- package/node/FronteggNativeProvider/FronteggNativeProvider.js +90 -0
- package/node/FronteggNativeProvider/index.js +16 -0
- package/node/index.js +12 -1
- package/package.json +3 -3
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { FC, ReactNode } from 'react';
|
|
2
|
+
import { ContextOptions } from '@frontegg/rest-api';
|
|
3
|
+
import { FronteggAppInstance } from '@frontegg/types';
|
|
4
|
+
export type FronteggNativeProviderProps = {
|
|
5
|
+
app?: FronteggAppInstance;
|
|
6
|
+
contextOptions?: ContextOptions;
|
|
7
|
+
setLoading?: (loading: boolean) => void;
|
|
8
|
+
children?: ReactNode | undefined;
|
|
9
|
+
};
|
|
10
|
+
export declare const FronteggNativeProvider: FC<FronteggNativeProviderProps>;
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
|
+
import React, { useMemo, useRef } from 'react';
|
|
3
|
+
import { createStore } from '@frontegg/redux-store';
|
|
4
|
+
import { ContextHolder } from '@frontegg/rest-api';
|
|
5
|
+
import { Provider } from '../FronteggStoreContext';
|
|
6
|
+
import { useAuth } from '../auth';
|
|
7
|
+
import { Fragment as _Fragment } from "react/jsx-runtime";
|
|
8
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
9
|
+
const defaultSetLoading = loading => {
|
|
10
|
+
if (loading) {
|
|
11
|
+
document.body.classList.add('frontegg-loading');
|
|
12
|
+
} else {
|
|
13
|
+
document.body.classList.remove('frontegg-loading');
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
const FronteggContent = ({
|
|
17
|
+
children,
|
|
18
|
+
setLoading
|
|
19
|
+
}) => {
|
|
20
|
+
const {
|
|
21
|
+
isLoading
|
|
22
|
+
} = useAuth();
|
|
23
|
+
const loadingRef = useRef(undefined);
|
|
24
|
+
if (isLoading !== loadingRef.current) {
|
|
25
|
+
loadingRef.current = isLoading;
|
|
26
|
+
setTimeout(() => {
|
|
27
|
+
setLoading(isLoading);
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
if (isLoading) {
|
|
31
|
+
return null;
|
|
32
|
+
}
|
|
33
|
+
return /*#__PURE__*/_jsx(_Fragment, {
|
|
34
|
+
children: children
|
|
35
|
+
});
|
|
36
|
+
};
|
|
37
|
+
export const FronteggNativeProvider = props => {
|
|
38
|
+
var _app$options$contextO, _app$options, _app$options$previewM, _app$options2, _app$options$builderM, _app$options3, _app$options4, _app$options5, _app$options6, _app$name;
|
|
39
|
+
const {
|
|
40
|
+
children,
|
|
41
|
+
app,
|
|
42
|
+
contextOptions,
|
|
43
|
+
setLoading = defaultSetLoading
|
|
44
|
+
} = props;
|
|
45
|
+
const context = (_app$options$contextO = app == null ? void 0 : (_app$options = app.options) == null ? void 0 : _app$options.contextOptions) != null ? _app$options$contextO : contextOptions;
|
|
46
|
+
if (!context) {
|
|
47
|
+
throw Error('contextOptions must not be null or undefined');
|
|
48
|
+
}
|
|
49
|
+
const previewMode = (_app$options$previewM = app == null ? void 0 : (_app$options2 = app.options) == null ? void 0 : _app$options2.previewMode) != null ? _app$options$previewM : false;
|
|
50
|
+
const builderMode = (_app$options$builderM = app == null ? void 0 : (_app$options3 = app.options) == null ? void 0 : _app$options3.builderMode) != null ? _app$options$builderM : false;
|
|
51
|
+
const auditsOptions = app == null ? void 0 : (_app$options4 = app.options) == null ? void 0 : _app$options4.auditsOptions;
|
|
52
|
+
const authOptions = app != null && (_app$options5 = app.options) != null && _app$options5.authOptions ? _extends({}, app.options.authOptions, {
|
|
53
|
+
hostedLoginBox: app.options.hostedLoginBox
|
|
54
|
+
}) : {
|
|
55
|
+
hostedLoginBox: app == null ? void 0 : (_app$options6 = app.options) == null ? void 0 : _app$options6.hostedLoginBox
|
|
56
|
+
};
|
|
57
|
+
const appName = (_app$name = app == null ? void 0 : app.name) != null ? _app$name : 'default';
|
|
58
|
+
ContextHolder.for(appName).setContext(context);
|
|
59
|
+
const store = useMemo(() => {
|
|
60
|
+
var _app$store, _app$options7;
|
|
61
|
+
return (_app$store = app == null ? void 0 : app.store) != null ? _app$store : createStore({
|
|
62
|
+
name: appName,
|
|
63
|
+
context,
|
|
64
|
+
previewMode,
|
|
65
|
+
builderMode,
|
|
66
|
+
initialState: {
|
|
67
|
+
auth: authOptions,
|
|
68
|
+
audits: auditsOptions
|
|
69
|
+
},
|
|
70
|
+
urlStrategy: app == null ? void 0 : (_app$options7 = app.options) == null ? void 0 : _app$options7.urlStrategy,
|
|
71
|
+
storeHolder: app
|
|
72
|
+
});
|
|
73
|
+
}, [app, previewMode]);
|
|
74
|
+
return /*#__PURE__*/_jsx(Provider, {
|
|
75
|
+
store: store,
|
|
76
|
+
children: /*#__PURE__*/_jsx(FronteggContent, {
|
|
77
|
+
setLoading: setLoading,
|
|
78
|
+
children: children
|
|
79
|
+
})
|
|
80
|
+
});
|
|
81
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './FronteggNativeProvider';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './FronteggNativeProvider';
|
package/index.d.ts
CHANGED
package/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/** @license Frontegg v7.
|
|
1
|
+
/** @license Frontegg v7.11.0-alpha.0
|
|
2
2
|
*
|
|
3
3
|
* This source code is licensed under the MIT license found in the
|
|
4
4
|
* LICENSE file in the root directory of this source tree.
|
|
@@ -11,4 +11,5 @@ export * from './vendor';
|
|
|
11
11
|
export * from './common';
|
|
12
12
|
export * from './flags';
|
|
13
13
|
export * from './FronteggProvider';
|
|
14
|
+
export * from './FronteggNativeProvider';
|
|
14
15
|
export * from './FronteggStoreContext';
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.FronteggNativeProvider = void 0;
|
|
8
|
+
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
|
9
|
+
var _react = _interopRequireWildcard(require("react"));
|
|
10
|
+
var _reduxStore = require("@frontegg/redux-store");
|
|
11
|
+
var _restApi = require("@frontegg/rest-api");
|
|
12
|
+
var _FronteggStoreContext = require("../FronteggStoreContext");
|
|
13
|
+
var _auth = require("../auth");
|
|
14
|
+
var _jsxRuntime = require("react/jsx-runtime");
|
|
15
|
+
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
16
|
+
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
17
|
+
const defaultSetLoading = loading => {
|
|
18
|
+
if (loading) {
|
|
19
|
+
document.body.classList.add('frontegg-loading');
|
|
20
|
+
} else {
|
|
21
|
+
document.body.classList.remove('frontegg-loading');
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
const FronteggContent = ({
|
|
25
|
+
children,
|
|
26
|
+
setLoading
|
|
27
|
+
}) => {
|
|
28
|
+
const {
|
|
29
|
+
isLoading
|
|
30
|
+
} = (0, _auth.useAuth)();
|
|
31
|
+
const loadingRef = (0, _react.useRef)(undefined);
|
|
32
|
+
if (isLoading !== loadingRef.current) {
|
|
33
|
+
loadingRef.current = isLoading;
|
|
34
|
+
setTimeout(() => {
|
|
35
|
+
setLoading(isLoading);
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
if (isLoading) {
|
|
39
|
+
return null;
|
|
40
|
+
}
|
|
41
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_jsxRuntime.Fragment, {
|
|
42
|
+
children: children
|
|
43
|
+
});
|
|
44
|
+
};
|
|
45
|
+
const FronteggNativeProvider = props => {
|
|
46
|
+
var _app$options$contextO, _app$options, _app$options$previewM, _app$options2, _app$options$builderM, _app$options3, _app$options4, _app$options5, _app$options6, _app$name;
|
|
47
|
+
const {
|
|
48
|
+
children,
|
|
49
|
+
app,
|
|
50
|
+
contextOptions,
|
|
51
|
+
setLoading = defaultSetLoading
|
|
52
|
+
} = props;
|
|
53
|
+
const context = (_app$options$contextO = app == null ? void 0 : (_app$options = app.options) == null ? void 0 : _app$options.contextOptions) != null ? _app$options$contextO : contextOptions;
|
|
54
|
+
if (!context) {
|
|
55
|
+
throw Error('contextOptions must not be null or undefined');
|
|
56
|
+
}
|
|
57
|
+
const previewMode = (_app$options$previewM = app == null ? void 0 : (_app$options2 = app.options) == null ? void 0 : _app$options2.previewMode) != null ? _app$options$previewM : false;
|
|
58
|
+
const builderMode = (_app$options$builderM = app == null ? void 0 : (_app$options3 = app.options) == null ? void 0 : _app$options3.builderMode) != null ? _app$options$builderM : false;
|
|
59
|
+
const auditsOptions = app == null ? void 0 : (_app$options4 = app.options) == null ? void 0 : _app$options4.auditsOptions;
|
|
60
|
+
const authOptions = app != null && (_app$options5 = app.options) != null && _app$options5.authOptions ? (0, _extends2.default)({}, app.options.authOptions, {
|
|
61
|
+
hostedLoginBox: app.options.hostedLoginBox
|
|
62
|
+
}) : {
|
|
63
|
+
hostedLoginBox: app == null ? void 0 : (_app$options6 = app.options) == null ? void 0 : _app$options6.hostedLoginBox
|
|
64
|
+
};
|
|
65
|
+
const appName = (_app$name = app == null ? void 0 : app.name) != null ? _app$name : 'default';
|
|
66
|
+
_restApi.ContextHolder.for(appName).setContext(context);
|
|
67
|
+
const store = (0, _react.useMemo)(() => {
|
|
68
|
+
var _app$store, _app$options7;
|
|
69
|
+
return (_app$store = app == null ? void 0 : app.store) != null ? _app$store : (0, _reduxStore.createStore)({
|
|
70
|
+
name: appName,
|
|
71
|
+
context,
|
|
72
|
+
previewMode,
|
|
73
|
+
builderMode,
|
|
74
|
+
initialState: {
|
|
75
|
+
auth: authOptions,
|
|
76
|
+
audits: auditsOptions
|
|
77
|
+
},
|
|
78
|
+
urlStrategy: app == null ? void 0 : (_app$options7 = app.options) == null ? void 0 : _app$options7.urlStrategy,
|
|
79
|
+
storeHolder: app
|
|
80
|
+
});
|
|
81
|
+
}, [app, previewMode]);
|
|
82
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_FronteggStoreContext.Provider, {
|
|
83
|
+
store: store,
|
|
84
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(FronteggContent, {
|
|
85
|
+
setLoading: setLoading,
|
|
86
|
+
children: children
|
|
87
|
+
})
|
|
88
|
+
});
|
|
89
|
+
};
|
|
90
|
+
exports.FronteggNativeProvider = FronteggNativeProvider;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
var _FronteggNativeProvider = require("./FronteggNativeProvider");
|
|
7
|
+
Object.keys(_FronteggNativeProvider).forEach(function (key) {
|
|
8
|
+
if (key === "default" || key === "__esModule") return;
|
|
9
|
+
if (key in exports && exports[key] === _FronteggNativeProvider[key]) return;
|
|
10
|
+
Object.defineProperty(exports, key, {
|
|
11
|
+
enumerable: true,
|
|
12
|
+
get: function () {
|
|
13
|
+
return _FronteggNativeProvider[key];
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
});
|
package/node/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/** @license Frontegg v7.
|
|
1
|
+
/** @license Frontegg v7.11.0-alpha.0
|
|
2
2
|
*
|
|
3
3
|
* This source code is licensed under the MIT license found in the
|
|
4
4
|
* LICENSE file in the root directory of this source tree.
|
|
@@ -96,6 +96,17 @@ Object.keys(_FronteggProvider).forEach(function (key) {
|
|
|
96
96
|
}
|
|
97
97
|
});
|
|
98
98
|
});
|
|
99
|
+
var _FronteggNativeProvider = require("./FronteggNativeProvider");
|
|
100
|
+
Object.keys(_FronteggNativeProvider).forEach(function (key) {
|
|
101
|
+
if (key === "default" || key === "__esModule") return;
|
|
102
|
+
if (key in exports && exports[key] === _FronteggNativeProvider[key]) return;
|
|
103
|
+
Object.defineProperty(exports, key, {
|
|
104
|
+
enumerable: true,
|
|
105
|
+
get: function () {
|
|
106
|
+
return _FronteggNativeProvider[key];
|
|
107
|
+
}
|
|
108
|
+
});
|
|
109
|
+
});
|
|
99
110
|
var _FronteggStoreContext = require("./FronteggStoreContext");
|
|
100
111
|
Object.keys(_FronteggStoreContext).forEach(function (key) {
|
|
101
112
|
if (key === "default" || key === "__esModule") return;
|
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@frontegg/react-hooks",
|
|
3
|
-
"version": "7.
|
|
3
|
+
"version": "7.11.0-alpha.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
|
-
"@frontegg/redux-store": "7.
|
|
10
|
-
"@frontegg/types": "7.
|
|
9
|
+
"@frontegg/redux-store": "7.11.0-alpha.0",
|
|
10
|
+
"@frontegg/types": "7.11.0-alpha.0",
|
|
11
11
|
"@types/react": "*",
|
|
12
12
|
"@types/react-is": "^17.0.7",
|
|
13
13
|
"get-value": "^3.0.1",
|