@frontegg/nextjs 6.7.8 → 6.7.9-alpha.3757258005
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/CHANGELOG.md +6 -0
- package/FronteggClientProviderNext13-b55f477b.js +127 -0
- package/FronteggClientProviderNext13-b55f477b.js.map +1 -0
- package/FronteggConfig-7ae86562.js +123 -0
- package/FronteggConfig-7ae86562.js.map +1 -0
- package/FronteggProvider.d.ts +3 -12
- package/FronteggProviderNoSSR.d.ts +2 -4
- package/README.md +56 -4
- package/api-70f0e81e.js +58 -0
- package/api-70f0e81e.js.map +1 -0
- package/client/FronteggAppRouter.d.ts +10 -0
- package/client/FronteggClientProviderNext13.d.ts +3 -0
- package/client/index.d.ts +2 -0
- package/client/index.js +63 -0
- package/client/index.js.map +1 -0
- package/{FronteggConfig.d.ts → common/FronteggConfig.d.ts} +1 -1
- package/{api.d.ts → common/api.d.ts} +0 -0
- package/{AppContext.d.ts → common/client/AppContext.d.ts} +0 -0
- package/common/client/ExpireInListener.d.ts +1 -0
- package/common/client/FronteggBaseProvider.d.ts +3 -0
- package/common/client/createOrGetFronteggApp.d.ts +11 -0
- package/common/client/hooks/index.d.ts +1 -0
- package/common/client/hooks/useRequestAuthorizeSSR.d.ts +9 -0
- package/common/client/index.d.ts +4 -0
- package/{consts.d.ts → common/consts.d.ts} +0 -0
- package/common/getMeAndTenants.d.ts +2 -0
- package/{helpers.d.ts → common/helpers.d.ts} +7 -9
- package/common/index.d.ts +6 -0
- package/common/index.js +20 -0
- package/common/index.js.map +1 -0
- package/common/types.d.ts +74 -0
- package/common/utils/createGetSession.d.ts +7 -0
- package/common/utils/getCookieFromRequest.d.ts +2 -0
- package/common/utils/index.d.ts +3 -0
- package/common/utils/parseCookie.d.ts +1 -0
- package/createGetSession-81b1748e.js +50 -0
- package/createGetSession-81b1748e.js.map +1 -0
- package/edge/getSessionOnEdge.d.ts +2 -0
- package/edge/index.d.ts +1 -0
- package/edge/index.js +29 -0
- package/edge/index.js.map +1 -0
- package/getCookieFromRequest-624c37b5.js +28 -0
- package/getCookieFromRequest-624c37b5.js.map +1 -0
- package/helpers-dac4dc7b.js +189 -0
- package/helpers-dac4dc7b.js.map +1 -0
- package/index.d.ts +1 -2
- package/index.js +1168 -0
- package/index.js.map +1 -0
- package/package.json +17 -12
- package/refreshToken.d.ts +3 -0
- package/server/FronteggProviderNext13.d.ts +3 -0
- package/server/getSessionNext13.d.ts +4 -0
- package/server/index.d.ts +2 -0
- package/server/index.js +86 -0
- package/server/index.js.map +1 -0
- package/session.d.ts +4 -8
- package/withFronteggApp.d.ts +10 -8
- package/index.cjs.js +0 -2747
- package/index.esm.js +0 -2691
- package/types.d.ts +0 -53
package/index.cjs.js
DELETED
|
@@ -1,2747 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
-
|
|
5
|
-
var jsxRuntime = require('react/jsx-runtime');
|
|
6
|
-
var react = require('react');
|
|
7
|
-
var js = require('@frontegg/js');
|
|
8
|
-
var reduxStore = require('@frontegg/redux-store');
|
|
9
|
-
var reactHooks = require('@frontegg/react-hooks');
|
|
10
|
-
var restApi = require('@frontegg/rest-api');
|
|
11
|
-
var router = require('next/router');
|
|
12
|
-
var jose = require('jose');
|
|
13
|
-
var url = require('url');
|
|
14
|
-
var cookie = require('cookie');
|
|
15
|
-
var ironSession = require('iron-session');
|
|
16
|
-
var zlib = require('zlib');
|
|
17
|
-
var httpProxy = require('http-proxy');
|
|
18
|
-
var types = require('@frontegg/types');
|
|
19
|
-
|
|
20
|
-
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
21
|
-
|
|
22
|
-
function _interopNamespace(e) {
|
|
23
|
-
if (e && e.__esModule) return e;
|
|
24
|
-
var n = Object.create(null);
|
|
25
|
-
if (e) {
|
|
26
|
-
Object.keys(e).forEach(function (k) {
|
|
27
|
-
if (k !== 'default') {
|
|
28
|
-
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
29
|
-
Object.defineProperty(n, k, d.get ? d : {
|
|
30
|
-
enumerable: true,
|
|
31
|
-
get: function () { return e[k]; }
|
|
32
|
-
});
|
|
33
|
-
}
|
|
34
|
-
});
|
|
35
|
-
}
|
|
36
|
-
n["default"] = e;
|
|
37
|
-
return Object.freeze(n);
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
var cookie__default = /*#__PURE__*/_interopDefaultLegacy(cookie);
|
|
41
|
-
var zlib__namespace = /*#__PURE__*/_interopNamespace(zlib);
|
|
42
|
-
var httpProxy__default = /*#__PURE__*/_interopDefaultLegacy(httpProxy);
|
|
43
|
-
|
|
44
|
-
/******************************************************************************
|
|
45
|
-
Copyright (c) Microsoft Corporation.
|
|
46
|
-
|
|
47
|
-
Permission to use, copy, modify, and/or distribute this software for any
|
|
48
|
-
purpose with or without fee is hereby granted.
|
|
49
|
-
|
|
50
|
-
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
51
|
-
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
52
|
-
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
53
|
-
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
54
|
-
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
55
|
-
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
56
|
-
PERFORMANCE OF THIS SOFTWARE.
|
|
57
|
-
***************************************************************************** */
|
|
58
|
-
|
|
59
|
-
function __rest(s, e) {
|
|
60
|
-
var t = {};
|
|
61
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
62
|
-
t[p] = s[p];
|
|
63
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
64
|
-
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
65
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
66
|
-
t[p[i]] = s[p[i]];
|
|
67
|
-
}
|
|
68
|
-
return t;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
function __awaiter(thisArg, _arguments, P, generator) {
|
|
72
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
73
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
74
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
75
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
76
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
77
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
78
|
-
});
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
var AppContext = /*#__PURE__*/react.createContext(null);
|
|
82
|
-
|
|
83
|
-
var Connector$1 = function Connector(_a) {
|
|
84
|
-
var _b;
|
|
85
|
-
|
|
86
|
-
var router = _a.router,
|
|
87
|
-
appName = _a.appName,
|
|
88
|
-
hostedLoginBox = _a.hostedLoginBox,
|
|
89
|
-
customLoginBox = _a.customLoginBox,
|
|
90
|
-
user = _a.user,
|
|
91
|
-
tenants = _a.tenants,
|
|
92
|
-
session = _a.session,
|
|
93
|
-
props = __rest(_a, ["router", "appName", "hostedLoginBox", "customLoginBox", "user", "tenants", "session"]);
|
|
94
|
-
|
|
95
|
-
var _ref = session !== null && session !== void 0 ? session : {},
|
|
96
|
-
accessToken = _ref.accessToken,
|
|
97
|
-
refreshToken = _ref.refreshToken;
|
|
98
|
-
|
|
99
|
-
var isSSR = typeof window === 'undefined';
|
|
100
|
-
var storeHolder = react.useRef({});
|
|
101
|
-
var baseName = (_b = props.basename) !== null && _b !== void 0 ? _b : router.basePath;
|
|
102
|
-
var onRedirectTo = react.useCallback(function (_path, opts) {
|
|
103
|
-
var path = _path;
|
|
104
|
-
|
|
105
|
-
if (path.startsWith(baseName)) {
|
|
106
|
-
path = path.substring(baseName.length);
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
if (opts === null || opts === void 0 ? void 0 : opts.preserveQueryParams) {
|
|
110
|
-
path = "".concat(path).concat(window.location.search);
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
if ((opts === null || opts === void 0 ? void 0 : opts.refresh) && !isSSR) {
|
|
114
|
-
// @ts-ignore
|
|
115
|
-
window.Cypress ? router.push(path) : window.location.href = path;
|
|
116
|
-
} else {
|
|
117
|
-
(opts === null || opts === void 0 ? void 0 : opts.replace) ? router.replace(path) : router.push(path);
|
|
118
|
-
}
|
|
119
|
-
}, []);
|
|
120
|
-
var contextOptions = react.useMemo(function () {
|
|
121
|
-
return Object.assign(Object.assign({
|
|
122
|
-
requestCredentials: 'include'
|
|
123
|
-
}, props.contextOptions), {
|
|
124
|
-
baseUrl: function baseUrl(path) {
|
|
125
|
-
if (restApi.fronteggAuthApiRoutes.indexOf(path) !== -1 || path.endsWith('/postlogin') || path.endsWith('/prelogin') || path === '/oauth/token') {
|
|
126
|
-
return "".concat(props.envAppUrl, "/api");
|
|
127
|
-
} else {
|
|
128
|
-
return props.envBaseUrl;
|
|
129
|
-
}
|
|
130
|
-
},
|
|
131
|
-
clientId: props.envClientId
|
|
132
|
-
});
|
|
133
|
-
}, [props.envAppUrl, props.envBaseUrl, props.envClientId, props.contextOptions]);
|
|
134
|
-
var authOptions = react.useMemo(function () {
|
|
135
|
-
var _a, _b, _c, _d;
|
|
136
|
-
|
|
137
|
-
var tenantsState = tenants ? Object.assign({
|
|
138
|
-
tenantTree: null,
|
|
139
|
-
subTenants: [],
|
|
140
|
-
tenants: tenants,
|
|
141
|
-
loading: false
|
|
142
|
-
}, (_a = props.authOptions) === null || _a === void 0 ? void 0 : _a.tenantsState) : undefined;
|
|
143
|
-
var userData = user ? Object.assign(Object.assign(Object.assign({}, user), {
|
|
144
|
-
accessToken: accessToken !== null && accessToken !== void 0 ? accessToken : '',
|
|
145
|
-
refreshToken: refreshToken !== null && refreshToken !== void 0 ? refreshToken : undefined
|
|
146
|
-
}), (_b = props.authOptions) === null || _b === void 0 ? void 0 : _b.user) : null;
|
|
147
|
-
return Object.assign(Object.assign({}, props.authOptions), {
|
|
148
|
-
onRedirectTo: onRedirectTo,
|
|
149
|
-
isLoading: false,
|
|
150
|
-
isAuthenticated: !!session,
|
|
151
|
-
hostedLoginBox: hostedLoginBox !== null && hostedLoginBox !== void 0 ? hostedLoginBox : false,
|
|
152
|
-
disableSilentRefresh: (_d = (_c = props.authOptions) === null || _c === void 0 ? void 0 : _c.disableSilentRefresh) !== null && _d !== void 0 ? _d : false,
|
|
153
|
-
user: userData,
|
|
154
|
-
tenantsState: tenantsState
|
|
155
|
-
});
|
|
156
|
-
}, [accessToken, hostedLoginBox, onRedirectTo, props.authOptions, refreshToken, session, tenants, user]);
|
|
157
|
-
var sharedStore = react.useMemo(function () {
|
|
158
|
-
var _a;
|
|
159
|
-
|
|
160
|
-
return reduxStore.createFronteggStore({
|
|
161
|
-
context: contextOptions
|
|
162
|
-
}, storeHolder.current, props.previewMode, authOptions, {
|
|
163
|
-
auth: authOptions !== null && authOptions !== void 0 ? authOptions : {},
|
|
164
|
-
audits: (_a = props.auditsOptions) !== null && _a !== void 0 ? _a : {}
|
|
165
|
-
}, false, props.urlStrategy);
|
|
166
|
-
}, [authOptions, contextOptions, props.auditsOptions, props.previewMode, props.urlStrategy]);
|
|
167
|
-
var app = react.useMemo(function () {
|
|
168
|
-
var _a;
|
|
169
|
-
|
|
170
|
-
var createdApp;
|
|
171
|
-
|
|
172
|
-
try {
|
|
173
|
-
createdApp = js.AppHolder.getInstance(appName !== null && appName !== void 0 ? appName : 'default');
|
|
174
|
-
createdApp.store = sharedStore;
|
|
175
|
-
} catch (e) {
|
|
176
|
-
createdApp = js.initialize(Object.assign(Object.assign({}, props), {
|
|
177
|
-
store: sharedStore,
|
|
178
|
-
hostedLoginBox: hostedLoginBox !== null && hostedLoginBox !== void 0 ? hostedLoginBox : false,
|
|
179
|
-
customLoginBox: customLoginBox !== null && customLoginBox !== void 0 ? customLoginBox : false,
|
|
180
|
-
basename: (_a = props.basename) !== null && _a !== void 0 ? _a : baseName,
|
|
181
|
-
authOptions: authOptions,
|
|
182
|
-
contextOptions: contextOptions,
|
|
183
|
-
onRedirectTo: onRedirectTo
|
|
184
|
-
}), appName !== null && appName !== void 0 ? appName : 'default');
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
return createdApp;
|
|
188
|
-
}, [appName, props, hostedLoginBox, baseName, onRedirectTo, contextOptions, customLoginBox, authOptions, sharedStore]);
|
|
189
|
-
restApi.ContextHolder.setOnRedirectTo(onRedirectTo);
|
|
190
|
-
react.useEffect(function () {
|
|
191
|
-
app === null || app === void 0 ? void 0 : app.store.dispatch({
|
|
192
|
-
type: 'auth/requestAuthorizeSSR',
|
|
193
|
-
payload: {
|
|
194
|
-
accessToken: accessToken,
|
|
195
|
-
user: user ? Object.assign(Object.assign({}, user), {
|
|
196
|
-
refreshToken: refreshToken
|
|
197
|
-
}) : null,
|
|
198
|
-
tenants: tenants
|
|
199
|
-
}
|
|
200
|
-
});
|
|
201
|
-
}, [app]);
|
|
202
|
-
return jsxRuntime.jsx(AppContext.Provider, Object.assign({
|
|
203
|
-
value: app
|
|
204
|
-
}, {
|
|
205
|
-
children: jsxRuntime.jsx(reactHooks.FronteggStoreProvider, Object.assign({}, Object.assign(Object.assign({}, props), {
|
|
206
|
-
app: app
|
|
207
|
-
}), {
|
|
208
|
-
children: props.children
|
|
209
|
-
}))
|
|
210
|
-
}));
|
|
211
|
-
};
|
|
212
|
-
|
|
213
|
-
var ExpireInListener$1 = function ExpireInListener() {
|
|
214
|
-
var user = reactHooks.useAuthUserOrNull();
|
|
215
|
-
var actions = reactHooks.useAuthActions();
|
|
216
|
-
react.useEffect(function () {
|
|
217
|
-
if (user && (user === null || user === void 0 ? void 0 : user.expiresIn) == null) {
|
|
218
|
-
actions.setUser(Object.assign(Object.assign({}, user), {
|
|
219
|
-
expiresIn: Math.floor((user['exp'] * 1000 - Date.now()) / 1000)
|
|
220
|
-
}));
|
|
221
|
-
}
|
|
222
|
-
}, [actions, user]); // eslint-disable-next-line react/jsx-no-useless-fragment
|
|
223
|
-
|
|
224
|
-
return jsxRuntime.jsx(jsxRuntime.Fragment, {});
|
|
225
|
-
};
|
|
226
|
-
|
|
227
|
-
var FronteggNextJSProvider$1 = function FronteggNextJSProvider(props) {
|
|
228
|
-
var router$1 = router.useRouter();
|
|
229
|
-
return jsxRuntime.jsxs(Connector$1, Object.assign({}, props, {
|
|
230
|
-
router: router$1
|
|
231
|
-
}, {
|
|
232
|
-
children: [jsxRuntime.jsx(ExpireInListener$1, {}), props.children]
|
|
233
|
-
}));
|
|
234
|
-
};
|
|
235
|
-
|
|
236
|
-
var FronteggProvider = function FronteggProvider(props) {
|
|
237
|
-
return jsxRuntime.jsx(FronteggNextJSProvider$1, Object.assign({}, props, {
|
|
238
|
-
framework: 'nextjs'
|
|
239
|
-
}, {
|
|
240
|
-
children: props.children
|
|
241
|
-
}));
|
|
242
|
-
};
|
|
243
|
-
|
|
244
|
-
var Connector = function Connector(_props) {
|
|
245
|
-
var _a;
|
|
246
|
-
|
|
247
|
-
var router = _props.router,
|
|
248
|
-
appName = _props.appName,
|
|
249
|
-
hostedLoginBox = _props.hostedLoginBox;
|
|
250
|
-
_props.customLoginBox;
|
|
251
|
-
var props = __rest(_props, ["router", "appName", "hostedLoginBox", "customLoginBox"]);
|
|
252
|
-
|
|
253
|
-
var isSSR = typeof window === 'undefined';
|
|
254
|
-
var baseName = (_a = props.basename) !== null && _a !== void 0 ? _a : router.basePath;
|
|
255
|
-
var onRedirectTo = react.useCallback(function (_path, opts) {
|
|
256
|
-
var path = _path;
|
|
257
|
-
|
|
258
|
-
if (path.startsWith(baseName)) {
|
|
259
|
-
path = path.substring(baseName.length);
|
|
260
|
-
}
|
|
261
|
-
|
|
262
|
-
if (opts === null || opts === void 0 ? void 0 : opts.preserveQueryParams) {
|
|
263
|
-
path = "".concat(path).concat(window.location.search);
|
|
264
|
-
}
|
|
265
|
-
|
|
266
|
-
if ((opts === null || opts === void 0 ? void 0 : opts.refresh) && !isSSR) {
|
|
267
|
-
// @ts-ignore
|
|
268
|
-
window.Cypress ? router.push(path) : window.location.href = path;
|
|
269
|
-
} else {
|
|
270
|
-
(opts === null || opts === void 0 ? void 0 : opts.replace) ? router.replace(path) : router.push(path);
|
|
271
|
-
}
|
|
272
|
-
}, []);
|
|
273
|
-
var app = react.useMemo(function () {
|
|
274
|
-
var _a;
|
|
275
|
-
|
|
276
|
-
var createdApp;
|
|
277
|
-
|
|
278
|
-
try {
|
|
279
|
-
createdApp = js.AppHolder.getInstance(appName !== null && appName !== void 0 ? appName : 'default');
|
|
280
|
-
} catch (e) {
|
|
281
|
-
createdApp = js.initialize(Object.assign(Object.assign({}, props), {
|
|
282
|
-
hostedLoginBox: hostedLoginBox !== null && hostedLoginBox !== void 0 ? hostedLoginBox : false,
|
|
283
|
-
basename: (_a = props.basename) !== null && _a !== void 0 ? _a : baseName,
|
|
284
|
-
authOptions: Object.assign(Object.assign({}, props.authOptions), {
|
|
285
|
-
onRedirectTo: onRedirectTo
|
|
286
|
-
}),
|
|
287
|
-
contextOptions: Object.assign({
|
|
288
|
-
requestCredentials: 'include'
|
|
289
|
-
}, props.contextOptions),
|
|
290
|
-
onRedirectTo: onRedirectTo
|
|
291
|
-
}), appName !== null && appName !== void 0 ? appName : 'default');
|
|
292
|
-
}
|
|
293
|
-
|
|
294
|
-
return createdApp;
|
|
295
|
-
}, [appName, props, hostedLoginBox, baseName, onRedirectTo]);
|
|
296
|
-
restApi.ContextHolder.setOnRedirectTo(onRedirectTo);
|
|
297
|
-
react.useEffect(function () {
|
|
298
|
-
app.store.dispatch({
|
|
299
|
-
type: 'auth/requestAuthorize',
|
|
300
|
-
payload: true
|
|
301
|
-
});
|
|
302
|
-
}, [app]);
|
|
303
|
-
return jsxRuntime.jsx(AppContext.Provider, Object.assign({
|
|
304
|
-
value: app
|
|
305
|
-
}, {
|
|
306
|
-
children: jsxRuntime.jsx(reactHooks.FronteggStoreProvider, Object.assign({}, Object.assign(Object.assign({}, props), {
|
|
307
|
-
app: app
|
|
308
|
-
}), {
|
|
309
|
-
children: props.children
|
|
310
|
-
}))
|
|
311
|
-
}));
|
|
312
|
-
};
|
|
313
|
-
|
|
314
|
-
var ExpireInListener = function ExpireInListener() {
|
|
315
|
-
var user = reactHooks.useAuthUserOrNull();
|
|
316
|
-
var actions = reactHooks.useAuthActions();
|
|
317
|
-
react.useEffect(function () {
|
|
318
|
-
if (user && (user === null || user === void 0 ? void 0 : user.expiresIn) == null) {
|
|
319
|
-
actions.setUser(Object.assign(Object.assign({}, user), {
|
|
320
|
-
expiresIn: Math.floor((user['exp'] * 1000 - Date.now()) / 1000)
|
|
321
|
-
}));
|
|
322
|
-
}
|
|
323
|
-
}, [actions, user]); // eslint-disable-next-line react/jsx-no-useless-fragment
|
|
324
|
-
|
|
325
|
-
return jsxRuntime.jsx(jsxRuntime.Fragment, {});
|
|
326
|
-
};
|
|
327
|
-
|
|
328
|
-
var FronteggNextJSProvider = function FronteggNextJSProvider(props) {
|
|
329
|
-
var router$1 = router.useRouter();
|
|
330
|
-
return jsxRuntime.jsxs(Connector, Object.assign({}, props, {
|
|
331
|
-
router: router$1
|
|
332
|
-
}, {
|
|
333
|
-
children: [jsxRuntime.jsx(ExpireInListener, {}), props.children]
|
|
334
|
-
}));
|
|
335
|
-
};
|
|
336
|
-
|
|
337
|
-
var FronteggProviderNoSSR = function FronteggProviderNoSSR(props) {
|
|
338
|
-
return jsxRuntime.jsx(FronteggNextJSProvider, Object.assign({}, props, {
|
|
339
|
-
framework: 'nextjs'
|
|
340
|
-
}, {
|
|
341
|
-
children: props.children
|
|
342
|
-
}));
|
|
343
|
-
};
|
|
344
|
-
|
|
345
|
-
function _createForOfIteratorHelper$1(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray$2(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; }
|
|
346
|
-
|
|
347
|
-
function _unsupportedIterableToArray$2(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray$2(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray$2(o, minLen); }
|
|
348
|
-
|
|
349
|
-
function _arrayLikeToArray$2(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
|
|
350
|
-
var AuthorizedContent = function AuthorizedContent(props) {
|
|
351
|
-
var _a, _b;
|
|
352
|
-
|
|
353
|
-
var isAuthorized = true; // Initially
|
|
354
|
-
|
|
355
|
-
var user = reactHooks.useAuthUserOrNull();
|
|
356
|
-
|
|
357
|
-
if (!(user === null || user === void 0 ? void 0 : user.superUser)) {
|
|
358
|
-
if (props.requiredPermissions) {
|
|
359
|
-
if (!(user === null || user === void 0 ? void 0 : user.permissions) || (user === null || user === void 0 ? void 0 : user.permissions.length) === 0) {
|
|
360
|
-
isAuthorized = false;
|
|
361
|
-
}
|
|
362
|
-
|
|
363
|
-
var _iterator = _createForOfIteratorHelper$1(props.requiredPermissions),
|
|
364
|
-
_step;
|
|
365
|
-
|
|
366
|
-
try {
|
|
367
|
-
var _loop = function _loop() {
|
|
368
|
-
var permission = _step.value;
|
|
369
|
-
|
|
370
|
-
if (!((_a = user === null || user === void 0 ? void 0 : user.permissions) === null || _a === void 0 ? void 0 : _a.find(function (_ref) {
|
|
371
|
-
var key = _ref.key;
|
|
372
|
-
return key === permission;
|
|
373
|
-
}))) {
|
|
374
|
-
isAuthorized = false;
|
|
375
|
-
}
|
|
376
|
-
};
|
|
377
|
-
|
|
378
|
-
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
379
|
-
_loop();
|
|
380
|
-
}
|
|
381
|
-
} catch (err) {
|
|
382
|
-
_iterator.e(err);
|
|
383
|
-
} finally {
|
|
384
|
-
_iterator.f();
|
|
385
|
-
}
|
|
386
|
-
}
|
|
387
|
-
|
|
388
|
-
if (props.requiredRoles) {
|
|
389
|
-
if (!(user === null || user === void 0 ? void 0 : user.roles) || (user === null || user === void 0 ? void 0 : user.roles.length) === 0) {
|
|
390
|
-
isAuthorized = false;
|
|
391
|
-
}
|
|
392
|
-
|
|
393
|
-
var _iterator2 = _createForOfIteratorHelper$1(props.requiredRoles),
|
|
394
|
-
_step2;
|
|
395
|
-
|
|
396
|
-
try {
|
|
397
|
-
var _loop2 = function _loop2() {
|
|
398
|
-
var role = _step2.value;
|
|
399
|
-
|
|
400
|
-
if (!((_b = user === null || user === void 0 ? void 0 : user.roles) === null || _b === void 0 ? void 0 : _b.find(function (_ref2) {
|
|
401
|
-
var key = _ref2.key;
|
|
402
|
-
return key === role;
|
|
403
|
-
}))) {
|
|
404
|
-
isAuthorized = false;
|
|
405
|
-
}
|
|
406
|
-
};
|
|
407
|
-
|
|
408
|
-
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
409
|
-
_loop2();
|
|
410
|
-
}
|
|
411
|
-
} catch (err) {
|
|
412
|
-
_iterator2.e(err);
|
|
413
|
-
} finally {
|
|
414
|
-
_iterator2.f();
|
|
415
|
-
}
|
|
416
|
-
}
|
|
417
|
-
}
|
|
418
|
-
|
|
419
|
-
if (typeof props.render === 'function') {
|
|
420
|
-
return jsxRuntime.jsx(jsxRuntime.Fragment, {
|
|
421
|
-
children: props.render(isAuthorized)
|
|
422
|
-
});
|
|
423
|
-
}
|
|
424
|
-
|
|
425
|
-
return isAuthorized ? jsxRuntime.jsx(jsxRuntime.Fragment, {
|
|
426
|
-
children: props.children
|
|
427
|
-
}) : null;
|
|
428
|
-
};
|
|
429
|
-
|
|
430
|
-
function _classCallCheck(instance, Constructor) {
|
|
431
|
-
if (!(instance instanceof Constructor)) {
|
|
432
|
-
throw new TypeError("Cannot call a class as a function");
|
|
433
|
-
}
|
|
434
|
-
}
|
|
435
|
-
|
|
436
|
-
function _defineProperties(target, props) {
|
|
437
|
-
for (var i = 0; i < props.length; i++) {
|
|
438
|
-
var descriptor = props[i];
|
|
439
|
-
descriptor.enumerable = descriptor.enumerable || false;
|
|
440
|
-
descriptor.configurable = true;
|
|
441
|
-
if ("value" in descriptor) descriptor.writable = true;
|
|
442
|
-
Object.defineProperty(target, descriptor.key, descriptor);
|
|
443
|
-
}
|
|
444
|
-
}
|
|
445
|
-
|
|
446
|
-
function _createClass(Constructor, protoProps, staticProps) {
|
|
447
|
-
if (protoProps) _defineProperties(Constructor.prototype, protoProps);
|
|
448
|
-
if (staticProps) _defineProperties(Constructor, staticProps);
|
|
449
|
-
Object.defineProperty(Constructor, "prototype", {
|
|
450
|
-
writable: false
|
|
451
|
-
});
|
|
452
|
-
return Constructor;
|
|
453
|
-
}
|
|
454
|
-
|
|
455
|
-
var runtime = {exports: {}};
|
|
456
|
-
|
|
457
|
-
/**
|
|
458
|
-
* Copyright (c) 2014-present, Facebook, Inc.
|
|
459
|
-
*
|
|
460
|
-
* This source code is licensed under the MIT license found in the
|
|
461
|
-
* LICENSE file in the root directory of this source tree.
|
|
462
|
-
*/
|
|
463
|
-
|
|
464
|
-
(function (module) {
|
|
465
|
-
var runtime = (function (exports) {
|
|
466
|
-
|
|
467
|
-
var Op = Object.prototype;
|
|
468
|
-
var hasOwn = Op.hasOwnProperty;
|
|
469
|
-
var undefined$1; // More compressible than void 0.
|
|
470
|
-
var $Symbol = typeof Symbol === "function" ? Symbol : {};
|
|
471
|
-
var iteratorSymbol = $Symbol.iterator || "@@iterator";
|
|
472
|
-
var asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator";
|
|
473
|
-
var toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag";
|
|
474
|
-
|
|
475
|
-
function define(obj, key, value) {
|
|
476
|
-
Object.defineProperty(obj, key, {
|
|
477
|
-
value: value,
|
|
478
|
-
enumerable: true,
|
|
479
|
-
configurable: true,
|
|
480
|
-
writable: true
|
|
481
|
-
});
|
|
482
|
-
return obj[key];
|
|
483
|
-
}
|
|
484
|
-
try {
|
|
485
|
-
// IE 8 has a broken Object.defineProperty that only works on DOM objects.
|
|
486
|
-
define({}, "");
|
|
487
|
-
} catch (err) {
|
|
488
|
-
define = function(obj, key, value) {
|
|
489
|
-
return obj[key] = value;
|
|
490
|
-
};
|
|
491
|
-
}
|
|
492
|
-
|
|
493
|
-
function wrap(innerFn, outerFn, self, tryLocsList) {
|
|
494
|
-
// If outerFn provided and outerFn.prototype is a Generator, then outerFn.prototype instanceof Generator.
|
|
495
|
-
var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator;
|
|
496
|
-
var generator = Object.create(protoGenerator.prototype);
|
|
497
|
-
var context = new Context(tryLocsList || []);
|
|
498
|
-
|
|
499
|
-
// The ._invoke method unifies the implementations of the .next,
|
|
500
|
-
// .throw, and .return methods.
|
|
501
|
-
generator._invoke = makeInvokeMethod(innerFn, self, context);
|
|
502
|
-
|
|
503
|
-
return generator;
|
|
504
|
-
}
|
|
505
|
-
exports.wrap = wrap;
|
|
506
|
-
|
|
507
|
-
// Try/catch helper to minimize deoptimizations. Returns a completion
|
|
508
|
-
// record like context.tryEntries[i].completion. This interface could
|
|
509
|
-
// have been (and was previously) designed to take a closure to be
|
|
510
|
-
// invoked without arguments, but in all the cases we care about we
|
|
511
|
-
// already have an existing method we want to call, so there's no need
|
|
512
|
-
// to create a new function object. We can even get away with assuming
|
|
513
|
-
// the method takes exactly one argument, since that happens to be true
|
|
514
|
-
// in every case, so we don't have to touch the arguments object. The
|
|
515
|
-
// only additional allocation required is the completion record, which
|
|
516
|
-
// has a stable shape and so hopefully should be cheap to allocate.
|
|
517
|
-
function tryCatch(fn, obj, arg) {
|
|
518
|
-
try {
|
|
519
|
-
return { type: "normal", arg: fn.call(obj, arg) };
|
|
520
|
-
} catch (err) {
|
|
521
|
-
return { type: "throw", arg: err };
|
|
522
|
-
}
|
|
523
|
-
}
|
|
524
|
-
|
|
525
|
-
var GenStateSuspendedStart = "suspendedStart";
|
|
526
|
-
var GenStateSuspendedYield = "suspendedYield";
|
|
527
|
-
var GenStateExecuting = "executing";
|
|
528
|
-
var GenStateCompleted = "completed";
|
|
529
|
-
|
|
530
|
-
// Returning this object from the innerFn has the same effect as
|
|
531
|
-
// breaking out of the dispatch switch statement.
|
|
532
|
-
var ContinueSentinel = {};
|
|
533
|
-
|
|
534
|
-
// Dummy constructor functions that we use as the .constructor and
|
|
535
|
-
// .constructor.prototype properties for functions that return Generator
|
|
536
|
-
// objects. For full spec compliance, you may wish to configure your
|
|
537
|
-
// minifier not to mangle the names of these two functions.
|
|
538
|
-
function Generator() {}
|
|
539
|
-
function GeneratorFunction() {}
|
|
540
|
-
function GeneratorFunctionPrototype() {}
|
|
541
|
-
|
|
542
|
-
// This is a polyfill for %IteratorPrototype% for environments that
|
|
543
|
-
// don't natively support it.
|
|
544
|
-
var IteratorPrototype = {};
|
|
545
|
-
define(IteratorPrototype, iteratorSymbol, function () {
|
|
546
|
-
return this;
|
|
547
|
-
});
|
|
548
|
-
|
|
549
|
-
var getProto = Object.getPrototypeOf;
|
|
550
|
-
var NativeIteratorPrototype = getProto && getProto(getProto(values([])));
|
|
551
|
-
if (NativeIteratorPrototype &&
|
|
552
|
-
NativeIteratorPrototype !== Op &&
|
|
553
|
-
hasOwn.call(NativeIteratorPrototype, iteratorSymbol)) {
|
|
554
|
-
// This environment has a native %IteratorPrototype%; use it instead
|
|
555
|
-
// of the polyfill.
|
|
556
|
-
IteratorPrototype = NativeIteratorPrototype;
|
|
557
|
-
}
|
|
558
|
-
|
|
559
|
-
var Gp = GeneratorFunctionPrototype.prototype =
|
|
560
|
-
Generator.prototype = Object.create(IteratorPrototype);
|
|
561
|
-
GeneratorFunction.prototype = GeneratorFunctionPrototype;
|
|
562
|
-
define(Gp, "constructor", GeneratorFunctionPrototype);
|
|
563
|
-
define(GeneratorFunctionPrototype, "constructor", GeneratorFunction);
|
|
564
|
-
GeneratorFunction.displayName = define(
|
|
565
|
-
GeneratorFunctionPrototype,
|
|
566
|
-
toStringTagSymbol,
|
|
567
|
-
"GeneratorFunction"
|
|
568
|
-
);
|
|
569
|
-
|
|
570
|
-
// Helper for defining the .next, .throw, and .return methods of the
|
|
571
|
-
// Iterator interface in terms of a single ._invoke method.
|
|
572
|
-
function defineIteratorMethods(prototype) {
|
|
573
|
-
["next", "throw", "return"].forEach(function(method) {
|
|
574
|
-
define(prototype, method, function(arg) {
|
|
575
|
-
return this._invoke(method, arg);
|
|
576
|
-
});
|
|
577
|
-
});
|
|
578
|
-
}
|
|
579
|
-
|
|
580
|
-
exports.isGeneratorFunction = function(genFun) {
|
|
581
|
-
var ctor = typeof genFun === "function" && genFun.constructor;
|
|
582
|
-
return ctor
|
|
583
|
-
? ctor === GeneratorFunction ||
|
|
584
|
-
// For the native GeneratorFunction constructor, the best we can
|
|
585
|
-
// do is to check its .name property.
|
|
586
|
-
(ctor.displayName || ctor.name) === "GeneratorFunction"
|
|
587
|
-
: false;
|
|
588
|
-
};
|
|
589
|
-
|
|
590
|
-
exports.mark = function(genFun) {
|
|
591
|
-
if (Object.setPrototypeOf) {
|
|
592
|
-
Object.setPrototypeOf(genFun, GeneratorFunctionPrototype);
|
|
593
|
-
} else {
|
|
594
|
-
genFun.__proto__ = GeneratorFunctionPrototype;
|
|
595
|
-
define(genFun, toStringTagSymbol, "GeneratorFunction");
|
|
596
|
-
}
|
|
597
|
-
genFun.prototype = Object.create(Gp);
|
|
598
|
-
return genFun;
|
|
599
|
-
};
|
|
600
|
-
|
|
601
|
-
// Within the body of any async function, `await x` is transformed to
|
|
602
|
-
// `yield regeneratorRuntime.awrap(x)`, so that the runtime can test
|
|
603
|
-
// `hasOwn.call(value, "__await")` to determine if the yielded value is
|
|
604
|
-
// meant to be awaited.
|
|
605
|
-
exports.awrap = function(arg) {
|
|
606
|
-
return { __await: arg };
|
|
607
|
-
};
|
|
608
|
-
|
|
609
|
-
function AsyncIterator(generator, PromiseImpl) {
|
|
610
|
-
function invoke(method, arg, resolve, reject) {
|
|
611
|
-
var record = tryCatch(generator[method], generator, arg);
|
|
612
|
-
if (record.type === "throw") {
|
|
613
|
-
reject(record.arg);
|
|
614
|
-
} else {
|
|
615
|
-
var result = record.arg;
|
|
616
|
-
var value = result.value;
|
|
617
|
-
if (value &&
|
|
618
|
-
typeof value === "object" &&
|
|
619
|
-
hasOwn.call(value, "__await")) {
|
|
620
|
-
return PromiseImpl.resolve(value.__await).then(function(value) {
|
|
621
|
-
invoke("next", value, resolve, reject);
|
|
622
|
-
}, function(err) {
|
|
623
|
-
invoke("throw", err, resolve, reject);
|
|
624
|
-
});
|
|
625
|
-
}
|
|
626
|
-
|
|
627
|
-
return PromiseImpl.resolve(value).then(function(unwrapped) {
|
|
628
|
-
// When a yielded Promise is resolved, its final value becomes
|
|
629
|
-
// the .value of the Promise<{value,done}> result for the
|
|
630
|
-
// current iteration.
|
|
631
|
-
result.value = unwrapped;
|
|
632
|
-
resolve(result);
|
|
633
|
-
}, function(error) {
|
|
634
|
-
// If a rejected Promise was yielded, throw the rejection back
|
|
635
|
-
// into the async generator function so it can be handled there.
|
|
636
|
-
return invoke("throw", error, resolve, reject);
|
|
637
|
-
});
|
|
638
|
-
}
|
|
639
|
-
}
|
|
640
|
-
|
|
641
|
-
var previousPromise;
|
|
642
|
-
|
|
643
|
-
function enqueue(method, arg) {
|
|
644
|
-
function callInvokeWithMethodAndArg() {
|
|
645
|
-
return new PromiseImpl(function(resolve, reject) {
|
|
646
|
-
invoke(method, arg, resolve, reject);
|
|
647
|
-
});
|
|
648
|
-
}
|
|
649
|
-
|
|
650
|
-
return previousPromise =
|
|
651
|
-
// If enqueue has been called before, then we want to wait until
|
|
652
|
-
// all previous Promises have been resolved before calling invoke,
|
|
653
|
-
// so that results are always delivered in the correct order. If
|
|
654
|
-
// enqueue has not been called before, then it is important to
|
|
655
|
-
// call invoke immediately, without waiting on a callback to fire,
|
|
656
|
-
// so that the async generator function has the opportunity to do
|
|
657
|
-
// any necessary setup in a predictable way. This predictability
|
|
658
|
-
// is why the Promise constructor synchronously invokes its
|
|
659
|
-
// executor callback, and why async functions synchronously
|
|
660
|
-
// execute code before the first await. Since we implement simple
|
|
661
|
-
// async functions in terms of async generators, it is especially
|
|
662
|
-
// important to get this right, even though it requires care.
|
|
663
|
-
previousPromise ? previousPromise.then(
|
|
664
|
-
callInvokeWithMethodAndArg,
|
|
665
|
-
// Avoid propagating failures to Promises returned by later
|
|
666
|
-
// invocations of the iterator.
|
|
667
|
-
callInvokeWithMethodAndArg
|
|
668
|
-
) : callInvokeWithMethodAndArg();
|
|
669
|
-
}
|
|
670
|
-
|
|
671
|
-
// Define the unified helper method that is used to implement .next,
|
|
672
|
-
// .throw, and .return (see defineIteratorMethods).
|
|
673
|
-
this._invoke = enqueue;
|
|
674
|
-
}
|
|
675
|
-
|
|
676
|
-
defineIteratorMethods(AsyncIterator.prototype);
|
|
677
|
-
define(AsyncIterator.prototype, asyncIteratorSymbol, function () {
|
|
678
|
-
return this;
|
|
679
|
-
});
|
|
680
|
-
exports.AsyncIterator = AsyncIterator;
|
|
681
|
-
|
|
682
|
-
// Note that simple async functions are implemented on top of
|
|
683
|
-
// AsyncIterator objects; they just return a Promise for the value of
|
|
684
|
-
// the final result produced by the iterator.
|
|
685
|
-
exports.async = function(innerFn, outerFn, self, tryLocsList, PromiseImpl) {
|
|
686
|
-
if (PromiseImpl === void 0) PromiseImpl = Promise;
|
|
687
|
-
|
|
688
|
-
var iter = new AsyncIterator(
|
|
689
|
-
wrap(innerFn, outerFn, self, tryLocsList),
|
|
690
|
-
PromiseImpl
|
|
691
|
-
);
|
|
692
|
-
|
|
693
|
-
return exports.isGeneratorFunction(outerFn)
|
|
694
|
-
? iter // If outerFn is a generator, return the full iterator.
|
|
695
|
-
: iter.next().then(function(result) {
|
|
696
|
-
return result.done ? result.value : iter.next();
|
|
697
|
-
});
|
|
698
|
-
};
|
|
699
|
-
|
|
700
|
-
function makeInvokeMethod(innerFn, self, context) {
|
|
701
|
-
var state = GenStateSuspendedStart;
|
|
702
|
-
|
|
703
|
-
return function invoke(method, arg) {
|
|
704
|
-
if (state === GenStateExecuting) {
|
|
705
|
-
throw new Error("Generator is already running");
|
|
706
|
-
}
|
|
707
|
-
|
|
708
|
-
if (state === GenStateCompleted) {
|
|
709
|
-
if (method === "throw") {
|
|
710
|
-
throw arg;
|
|
711
|
-
}
|
|
712
|
-
|
|
713
|
-
// Be forgiving, per 25.3.3.3.3 of the spec:
|
|
714
|
-
// https://people.mozilla.org/~jorendorff/es6-draft.html#sec-generatorresume
|
|
715
|
-
return doneResult();
|
|
716
|
-
}
|
|
717
|
-
|
|
718
|
-
context.method = method;
|
|
719
|
-
context.arg = arg;
|
|
720
|
-
|
|
721
|
-
while (true) {
|
|
722
|
-
var delegate = context.delegate;
|
|
723
|
-
if (delegate) {
|
|
724
|
-
var delegateResult = maybeInvokeDelegate(delegate, context);
|
|
725
|
-
if (delegateResult) {
|
|
726
|
-
if (delegateResult === ContinueSentinel) continue;
|
|
727
|
-
return delegateResult;
|
|
728
|
-
}
|
|
729
|
-
}
|
|
730
|
-
|
|
731
|
-
if (context.method === "next") {
|
|
732
|
-
// Setting context._sent for legacy support of Babel's
|
|
733
|
-
// function.sent implementation.
|
|
734
|
-
context.sent = context._sent = context.arg;
|
|
735
|
-
|
|
736
|
-
} else if (context.method === "throw") {
|
|
737
|
-
if (state === GenStateSuspendedStart) {
|
|
738
|
-
state = GenStateCompleted;
|
|
739
|
-
throw context.arg;
|
|
740
|
-
}
|
|
741
|
-
|
|
742
|
-
context.dispatchException(context.arg);
|
|
743
|
-
|
|
744
|
-
} else if (context.method === "return") {
|
|
745
|
-
context.abrupt("return", context.arg);
|
|
746
|
-
}
|
|
747
|
-
|
|
748
|
-
state = GenStateExecuting;
|
|
749
|
-
|
|
750
|
-
var record = tryCatch(innerFn, self, context);
|
|
751
|
-
if (record.type === "normal") {
|
|
752
|
-
// If an exception is thrown from innerFn, we leave state ===
|
|
753
|
-
// GenStateExecuting and loop back for another invocation.
|
|
754
|
-
state = context.done
|
|
755
|
-
? GenStateCompleted
|
|
756
|
-
: GenStateSuspendedYield;
|
|
757
|
-
|
|
758
|
-
if (record.arg === ContinueSentinel) {
|
|
759
|
-
continue;
|
|
760
|
-
}
|
|
761
|
-
|
|
762
|
-
return {
|
|
763
|
-
value: record.arg,
|
|
764
|
-
done: context.done
|
|
765
|
-
};
|
|
766
|
-
|
|
767
|
-
} else if (record.type === "throw") {
|
|
768
|
-
state = GenStateCompleted;
|
|
769
|
-
// Dispatch the exception by looping back around to the
|
|
770
|
-
// context.dispatchException(context.arg) call above.
|
|
771
|
-
context.method = "throw";
|
|
772
|
-
context.arg = record.arg;
|
|
773
|
-
}
|
|
774
|
-
}
|
|
775
|
-
};
|
|
776
|
-
}
|
|
777
|
-
|
|
778
|
-
// Call delegate.iterator[context.method](context.arg) and handle the
|
|
779
|
-
// result, either by returning a { value, done } result from the
|
|
780
|
-
// delegate iterator, or by modifying context.method and context.arg,
|
|
781
|
-
// setting context.delegate to null, and returning the ContinueSentinel.
|
|
782
|
-
function maybeInvokeDelegate(delegate, context) {
|
|
783
|
-
var method = delegate.iterator[context.method];
|
|
784
|
-
if (method === undefined$1) {
|
|
785
|
-
// A .throw or .return when the delegate iterator has no .throw
|
|
786
|
-
// method always terminates the yield* loop.
|
|
787
|
-
context.delegate = null;
|
|
788
|
-
|
|
789
|
-
if (context.method === "throw") {
|
|
790
|
-
// Note: ["return"] must be used for ES3 parsing compatibility.
|
|
791
|
-
if (delegate.iterator["return"]) {
|
|
792
|
-
// If the delegate iterator has a return method, give it a
|
|
793
|
-
// chance to clean up.
|
|
794
|
-
context.method = "return";
|
|
795
|
-
context.arg = undefined$1;
|
|
796
|
-
maybeInvokeDelegate(delegate, context);
|
|
797
|
-
|
|
798
|
-
if (context.method === "throw") {
|
|
799
|
-
// If maybeInvokeDelegate(context) changed context.method from
|
|
800
|
-
// "return" to "throw", let that override the TypeError below.
|
|
801
|
-
return ContinueSentinel;
|
|
802
|
-
}
|
|
803
|
-
}
|
|
804
|
-
|
|
805
|
-
context.method = "throw";
|
|
806
|
-
context.arg = new TypeError(
|
|
807
|
-
"The iterator does not provide a 'throw' method");
|
|
808
|
-
}
|
|
809
|
-
|
|
810
|
-
return ContinueSentinel;
|
|
811
|
-
}
|
|
812
|
-
|
|
813
|
-
var record = tryCatch(method, delegate.iterator, context.arg);
|
|
814
|
-
|
|
815
|
-
if (record.type === "throw") {
|
|
816
|
-
context.method = "throw";
|
|
817
|
-
context.arg = record.arg;
|
|
818
|
-
context.delegate = null;
|
|
819
|
-
return ContinueSentinel;
|
|
820
|
-
}
|
|
821
|
-
|
|
822
|
-
var info = record.arg;
|
|
823
|
-
|
|
824
|
-
if (! info) {
|
|
825
|
-
context.method = "throw";
|
|
826
|
-
context.arg = new TypeError("iterator result is not an object");
|
|
827
|
-
context.delegate = null;
|
|
828
|
-
return ContinueSentinel;
|
|
829
|
-
}
|
|
830
|
-
|
|
831
|
-
if (info.done) {
|
|
832
|
-
// Assign the result of the finished delegate to the temporary
|
|
833
|
-
// variable specified by delegate.resultName (see delegateYield).
|
|
834
|
-
context[delegate.resultName] = info.value;
|
|
835
|
-
|
|
836
|
-
// Resume execution at the desired location (see delegateYield).
|
|
837
|
-
context.next = delegate.nextLoc;
|
|
838
|
-
|
|
839
|
-
// If context.method was "throw" but the delegate handled the
|
|
840
|
-
// exception, let the outer generator proceed normally. If
|
|
841
|
-
// context.method was "next", forget context.arg since it has been
|
|
842
|
-
// "consumed" by the delegate iterator. If context.method was
|
|
843
|
-
// "return", allow the original .return call to continue in the
|
|
844
|
-
// outer generator.
|
|
845
|
-
if (context.method !== "return") {
|
|
846
|
-
context.method = "next";
|
|
847
|
-
context.arg = undefined$1;
|
|
848
|
-
}
|
|
849
|
-
|
|
850
|
-
} else {
|
|
851
|
-
// Re-yield the result returned by the delegate method.
|
|
852
|
-
return info;
|
|
853
|
-
}
|
|
854
|
-
|
|
855
|
-
// The delegate iterator is finished, so forget it and continue with
|
|
856
|
-
// the outer generator.
|
|
857
|
-
context.delegate = null;
|
|
858
|
-
return ContinueSentinel;
|
|
859
|
-
}
|
|
860
|
-
|
|
861
|
-
// Define Generator.prototype.{next,throw,return} in terms of the
|
|
862
|
-
// unified ._invoke helper method.
|
|
863
|
-
defineIteratorMethods(Gp);
|
|
864
|
-
|
|
865
|
-
define(Gp, toStringTagSymbol, "Generator");
|
|
866
|
-
|
|
867
|
-
// A Generator should always return itself as the iterator object when the
|
|
868
|
-
// @@iterator function is called on it. Some browsers' implementations of the
|
|
869
|
-
// iterator prototype chain incorrectly implement this, causing the Generator
|
|
870
|
-
// object to not be returned from this call. This ensures that doesn't happen.
|
|
871
|
-
// See https://github.com/facebook/regenerator/issues/274 for more details.
|
|
872
|
-
define(Gp, iteratorSymbol, function() {
|
|
873
|
-
return this;
|
|
874
|
-
});
|
|
875
|
-
|
|
876
|
-
define(Gp, "toString", function() {
|
|
877
|
-
return "[object Generator]";
|
|
878
|
-
});
|
|
879
|
-
|
|
880
|
-
function pushTryEntry(locs) {
|
|
881
|
-
var entry = { tryLoc: locs[0] };
|
|
882
|
-
|
|
883
|
-
if (1 in locs) {
|
|
884
|
-
entry.catchLoc = locs[1];
|
|
885
|
-
}
|
|
886
|
-
|
|
887
|
-
if (2 in locs) {
|
|
888
|
-
entry.finallyLoc = locs[2];
|
|
889
|
-
entry.afterLoc = locs[3];
|
|
890
|
-
}
|
|
891
|
-
|
|
892
|
-
this.tryEntries.push(entry);
|
|
893
|
-
}
|
|
894
|
-
|
|
895
|
-
function resetTryEntry(entry) {
|
|
896
|
-
var record = entry.completion || {};
|
|
897
|
-
record.type = "normal";
|
|
898
|
-
delete record.arg;
|
|
899
|
-
entry.completion = record;
|
|
900
|
-
}
|
|
901
|
-
|
|
902
|
-
function Context(tryLocsList) {
|
|
903
|
-
// The root entry object (effectively a try statement without a catch
|
|
904
|
-
// or a finally block) gives us a place to store values thrown from
|
|
905
|
-
// locations where there is no enclosing try statement.
|
|
906
|
-
this.tryEntries = [{ tryLoc: "root" }];
|
|
907
|
-
tryLocsList.forEach(pushTryEntry, this);
|
|
908
|
-
this.reset(true);
|
|
909
|
-
}
|
|
910
|
-
|
|
911
|
-
exports.keys = function(object) {
|
|
912
|
-
var keys = [];
|
|
913
|
-
for (var key in object) {
|
|
914
|
-
keys.push(key);
|
|
915
|
-
}
|
|
916
|
-
keys.reverse();
|
|
917
|
-
|
|
918
|
-
// Rather than returning an object with a next method, we keep
|
|
919
|
-
// things simple and return the next function itself.
|
|
920
|
-
return function next() {
|
|
921
|
-
while (keys.length) {
|
|
922
|
-
var key = keys.pop();
|
|
923
|
-
if (key in object) {
|
|
924
|
-
next.value = key;
|
|
925
|
-
next.done = false;
|
|
926
|
-
return next;
|
|
927
|
-
}
|
|
928
|
-
}
|
|
929
|
-
|
|
930
|
-
// To avoid creating an additional object, we just hang the .value
|
|
931
|
-
// and .done properties off the next function object itself. This
|
|
932
|
-
// also ensures that the minifier will not anonymize the function.
|
|
933
|
-
next.done = true;
|
|
934
|
-
return next;
|
|
935
|
-
};
|
|
936
|
-
};
|
|
937
|
-
|
|
938
|
-
function values(iterable) {
|
|
939
|
-
if (iterable) {
|
|
940
|
-
var iteratorMethod = iterable[iteratorSymbol];
|
|
941
|
-
if (iteratorMethod) {
|
|
942
|
-
return iteratorMethod.call(iterable);
|
|
943
|
-
}
|
|
944
|
-
|
|
945
|
-
if (typeof iterable.next === "function") {
|
|
946
|
-
return iterable;
|
|
947
|
-
}
|
|
948
|
-
|
|
949
|
-
if (!isNaN(iterable.length)) {
|
|
950
|
-
var i = -1, next = function next() {
|
|
951
|
-
while (++i < iterable.length) {
|
|
952
|
-
if (hasOwn.call(iterable, i)) {
|
|
953
|
-
next.value = iterable[i];
|
|
954
|
-
next.done = false;
|
|
955
|
-
return next;
|
|
956
|
-
}
|
|
957
|
-
}
|
|
958
|
-
|
|
959
|
-
next.value = undefined$1;
|
|
960
|
-
next.done = true;
|
|
961
|
-
|
|
962
|
-
return next;
|
|
963
|
-
};
|
|
964
|
-
|
|
965
|
-
return next.next = next;
|
|
966
|
-
}
|
|
967
|
-
}
|
|
968
|
-
|
|
969
|
-
// Return an iterator with no values.
|
|
970
|
-
return { next: doneResult };
|
|
971
|
-
}
|
|
972
|
-
exports.values = values;
|
|
973
|
-
|
|
974
|
-
function doneResult() {
|
|
975
|
-
return { value: undefined$1, done: true };
|
|
976
|
-
}
|
|
977
|
-
|
|
978
|
-
Context.prototype = {
|
|
979
|
-
constructor: Context,
|
|
980
|
-
|
|
981
|
-
reset: function(skipTempReset) {
|
|
982
|
-
this.prev = 0;
|
|
983
|
-
this.next = 0;
|
|
984
|
-
// Resetting context._sent for legacy support of Babel's
|
|
985
|
-
// function.sent implementation.
|
|
986
|
-
this.sent = this._sent = undefined$1;
|
|
987
|
-
this.done = false;
|
|
988
|
-
this.delegate = null;
|
|
989
|
-
|
|
990
|
-
this.method = "next";
|
|
991
|
-
this.arg = undefined$1;
|
|
992
|
-
|
|
993
|
-
this.tryEntries.forEach(resetTryEntry);
|
|
994
|
-
|
|
995
|
-
if (!skipTempReset) {
|
|
996
|
-
for (var name in this) {
|
|
997
|
-
// Not sure about the optimal order of these conditions:
|
|
998
|
-
if (name.charAt(0) === "t" &&
|
|
999
|
-
hasOwn.call(this, name) &&
|
|
1000
|
-
!isNaN(+name.slice(1))) {
|
|
1001
|
-
this[name] = undefined$1;
|
|
1002
|
-
}
|
|
1003
|
-
}
|
|
1004
|
-
}
|
|
1005
|
-
},
|
|
1006
|
-
|
|
1007
|
-
stop: function() {
|
|
1008
|
-
this.done = true;
|
|
1009
|
-
|
|
1010
|
-
var rootEntry = this.tryEntries[0];
|
|
1011
|
-
var rootRecord = rootEntry.completion;
|
|
1012
|
-
if (rootRecord.type === "throw") {
|
|
1013
|
-
throw rootRecord.arg;
|
|
1014
|
-
}
|
|
1015
|
-
|
|
1016
|
-
return this.rval;
|
|
1017
|
-
},
|
|
1018
|
-
|
|
1019
|
-
dispatchException: function(exception) {
|
|
1020
|
-
if (this.done) {
|
|
1021
|
-
throw exception;
|
|
1022
|
-
}
|
|
1023
|
-
|
|
1024
|
-
var context = this;
|
|
1025
|
-
function handle(loc, caught) {
|
|
1026
|
-
record.type = "throw";
|
|
1027
|
-
record.arg = exception;
|
|
1028
|
-
context.next = loc;
|
|
1029
|
-
|
|
1030
|
-
if (caught) {
|
|
1031
|
-
// If the dispatched exception was caught by a catch block,
|
|
1032
|
-
// then let that catch block handle the exception normally.
|
|
1033
|
-
context.method = "next";
|
|
1034
|
-
context.arg = undefined$1;
|
|
1035
|
-
}
|
|
1036
|
-
|
|
1037
|
-
return !! caught;
|
|
1038
|
-
}
|
|
1039
|
-
|
|
1040
|
-
for (var i = this.tryEntries.length - 1; i >= 0; --i) {
|
|
1041
|
-
var entry = this.tryEntries[i];
|
|
1042
|
-
var record = entry.completion;
|
|
1043
|
-
|
|
1044
|
-
if (entry.tryLoc === "root") {
|
|
1045
|
-
// Exception thrown outside of any try block that could handle
|
|
1046
|
-
// it, so set the completion value of the entire function to
|
|
1047
|
-
// throw the exception.
|
|
1048
|
-
return handle("end");
|
|
1049
|
-
}
|
|
1050
|
-
|
|
1051
|
-
if (entry.tryLoc <= this.prev) {
|
|
1052
|
-
var hasCatch = hasOwn.call(entry, "catchLoc");
|
|
1053
|
-
var hasFinally = hasOwn.call(entry, "finallyLoc");
|
|
1054
|
-
|
|
1055
|
-
if (hasCatch && hasFinally) {
|
|
1056
|
-
if (this.prev < entry.catchLoc) {
|
|
1057
|
-
return handle(entry.catchLoc, true);
|
|
1058
|
-
} else if (this.prev < entry.finallyLoc) {
|
|
1059
|
-
return handle(entry.finallyLoc);
|
|
1060
|
-
}
|
|
1061
|
-
|
|
1062
|
-
} else if (hasCatch) {
|
|
1063
|
-
if (this.prev < entry.catchLoc) {
|
|
1064
|
-
return handle(entry.catchLoc, true);
|
|
1065
|
-
}
|
|
1066
|
-
|
|
1067
|
-
} else if (hasFinally) {
|
|
1068
|
-
if (this.prev < entry.finallyLoc) {
|
|
1069
|
-
return handle(entry.finallyLoc);
|
|
1070
|
-
}
|
|
1071
|
-
|
|
1072
|
-
} else {
|
|
1073
|
-
throw new Error("try statement without catch or finally");
|
|
1074
|
-
}
|
|
1075
|
-
}
|
|
1076
|
-
}
|
|
1077
|
-
},
|
|
1078
|
-
|
|
1079
|
-
abrupt: function(type, arg) {
|
|
1080
|
-
for (var i = this.tryEntries.length - 1; i >= 0; --i) {
|
|
1081
|
-
var entry = this.tryEntries[i];
|
|
1082
|
-
if (entry.tryLoc <= this.prev &&
|
|
1083
|
-
hasOwn.call(entry, "finallyLoc") &&
|
|
1084
|
-
this.prev < entry.finallyLoc) {
|
|
1085
|
-
var finallyEntry = entry;
|
|
1086
|
-
break;
|
|
1087
|
-
}
|
|
1088
|
-
}
|
|
1089
|
-
|
|
1090
|
-
if (finallyEntry &&
|
|
1091
|
-
(type === "break" ||
|
|
1092
|
-
type === "continue") &&
|
|
1093
|
-
finallyEntry.tryLoc <= arg &&
|
|
1094
|
-
arg <= finallyEntry.finallyLoc) {
|
|
1095
|
-
// Ignore the finally entry if control is not jumping to a
|
|
1096
|
-
// location outside the try/catch block.
|
|
1097
|
-
finallyEntry = null;
|
|
1098
|
-
}
|
|
1099
|
-
|
|
1100
|
-
var record = finallyEntry ? finallyEntry.completion : {};
|
|
1101
|
-
record.type = type;
|
|
1102
|
-
record.arg = arg;
|
|
1103
|
-
|
|
1104
|
-
if (finallyEntry) {
|
|
1105
|
-
this.method = "next";
|
|
1106
|
-
this.next = finallyEntry.finallyLoc;
|
|
1107
|
-
return ContinueSentinel;
|
|
1108
|
-
}
|
|
1109
|
-
|
|
1110
|
-
return this.complete(record);
|
|
1111
|
-
},
|
|
1112
|
-
|
|
1113
|
-
complete: function(record, afterLoc) {
|
|
1114
|
-
if (record.type === "throw") {
|
|
1115
|
-
throw record.arg;
|
|
1116
|
-
}
|
|
1117
|
-
|
|
1118
|
-
if (record.type === "break" ||
|
|
1119
|
-
record.type === "continue") {
|
|
1120
|
-
this.next = record.arg;
|
|
1121
|
-
} else if (record.type === "return") {
|
|
1122
|
-
this.rval = this.arg = record.arg;
|
|
1123
|
-
this.method = "return";
|
|
1124
|
-
this.next = "end";
|
|
1125
|
-
} else if (record.type === "normal" && afterLoc) {
|
|
1126
|
-
this.next = afterLoc;
|
|
1127
|
-
}
|
|
1128
|
-
|
|
1129
|
-
return ContinueSentinel;
|
|
1130
|
-
},
|
|
1131
|
-
|
|
1132
|
-
finish: function(finallyLoc) {
|
|
1133
|
-
for (var i = this.tryEntries.length - 1; i >= 0; --i) {
|
|
1134
|
-
var entry = this.tryEntries[i];
|
|
1135
|
-
if (entry.finallyLoc === finallyLoc) {
|
|
1136
|
-
this.complete(entry.completion, entry.afterLoc);
|
|
1137
|
-
resetTryEntry(entry);
|
|
1138
|
-
return ContinueSentinel;
|
|
1139
|
-
}
|
|
1140
|
-
}
|
|
1141
|
-
},
|
|
1142
|
-
|
|
1143
|
-
"catch": function(tryLoc) {
|
|
1144
|
-
for (var i = this.tryEntries.length - 1; i >= 0; --i) {
|
|
1145
|
-
var entry = this.tryEntries[i];
|
|
1146
|
-
if (entry.tryLoc === tryLoc) {
|
|
1147
|
-
var record = entry.completion;
|
|
1148
|
-
if (record.type === "throw") {
|
|
1149
|
-
var thrown = record.arg;
|
|
1150
|
-
resetTryEntry(entry);
|
|
1151
|
-
}
|
|
1152
|
-
return thrown;
|
|
1153
|
-
}
|
|
1154
|
-
}
|
|
1155
|
-
|
|
1156
|
-
// The context.catch method must only be called with a location
|
|
1157
|
-
// argument that corresponds to a known catch block.
|
|
1158
|
-
throw new Error("illegal catch attempt");
|
|
1159
|
-
},
|
|
1160
|
-
|
|
1161
|
-
delegateYield: function(iterable, resultName, nextLoc) {
|
|
1162
|
-
this.delegate = {
|
|
1163
|
-
iterator: values(iterable),
|
|
1164
|
-
resultName: resultName,
|
|
1165
|
-
nextLoc: nextLoc
|
|
1166
|
-
};
|
|
1167
|
-
|
|
1168
|
-
if (this.method === "next") {
|
|
1169
|
-
// Deliberately forget the last sent value so that we don't
|
|
1170
|
-
// accidentally pass it on to the delegate.
|
|
1171
|
-
this.arg = undefined$1;
|
|
1172
|
-
}
|
|
1173
|
-
|
|
1174
|
-
return ContinueSentinel;
|
|
1175
|
-
}
|
|
1176
|
-
};
|
|
1177
|
-
|
|
1178
|
-
// Regardless of whether this script is executing as a CommonJS module
|
|
1179
|
-
// or not, return the runtime object so that we can declare the variable
|
|
1180
|
-
// regeneratorRuntime in the outer scope, which allows this module to be
|
|
1181
|
-
// injected easily by `bin/regenerator --include-runtime script.js`.
|
|
1182
|
-
return exports;
|
|
1183
|
-
|
|
1184
|
-
}(
|
|
1185
|
-
// If this script is executing as a CommonJS module, use module.exports
|
|
1186
|
-
// as the regeneratorRuntime namespace. Otherwise create a new empty
|
|
1187
|
-
// object. Either way, the resulting object will be used to initialize
|
|
1188
|
-
// the regeneratorRuntime variable at the top of this file.
|
|
1189
|
-
module.exports
|
|
1190
|
-
));
|
|
1191
|
-
|
|
1192
|
-
try {
|
|
1193
|
-
regeneratorRuntime = runtime;
|
|
1194
|
-
} catch (accidentalStrictMode) {
|
|
1195
|
-
// This module should not be running in strict mode, so the above
|
|
1196
|
-
// assignment should always work unless something is misconfigured. Just
|
|
1197
|
-
// in case runtime.js accidentally runs in strict mode, in modern engines
|
|
1198
|
-
// we can explicitly access globalThis. In older engines we can escape
|
|
1199
|
-
// strict mode using a global Function call. This could conceivably fail
|
|
1200
|
-
// if a Content Security Policy forbids using Function, but in that case
|
|
1201
|
-
// the proper solution is to fix the accidental strict mode problem. If
|
|
1202
|
-
// you've misconfigured your bundler to force strict mode and applied a
|
|
1203
|
-
// CSP to forbid Function, and you're not willing to fix either of those
|
|
1204
|
-
// problems, please detail your unique predicament in a GitHub issue.
|
|
1205
|
-
if (typeof globalThis === "object") {
|
|
1206
|
-
globalThis.regeneratorRuntime = runtime;
|
|
1207
|
-
} else {
|
|
1208
|
-
Function("r", "regeneratorRuntime = r")(runtime);
|
|
1209
|
-
}
|
|
1210
|
-
}
|
|
1211
|
-
}(runtime));
|
|
1212
|
-
|
|
1213
|
-
var regenerator = runtime.exports;
|
|
1214
|
-
|
|
1215
|
-
function normalizeStringPasswordToMap(password) {
|
|
1216
|
-
return typeof password === 'string' ? {
|
|
1217
|
-
1: password
|
|
1218
|
-
} : password;
|
|
1219
|
-
}
|
|
1220
|
-
|
|
1221
|
-
var FronteggConfig = /*#__PURE__*/function () {
|
|
1222
|
-
function FronteggConfig() {
|
|
1223
|
-
_classCallCheck(this, FronteggConfig);
|
|
1224
|
-
|
|
1225
|
-
var _a, _b, _c;
|
|
1226
|
-
|
|
1227
|
-
this.authRoutes = {};
|
|
1228
|
-
this.fronteggAppOptions = {};
|
|
1229
|
-
this._clientId = (_a = process.env['FRONTEGG_CLIENT_ID']) !== null && _a !== void 0 ? _a : '';
|
|
1230
|
-
this._cookieName = (_b = process.env['FRONTEGG_COOKIE_NAME']) !== null && _b !== void 0 ? _b : "fe_next_session";
|
|
1231
|
-
this._password = (_c = process.env['FRONTEGG_ENCRYPTION_PASSWORD']) !== null && _c !== void 0 ? _c : '';
|
|
1232
|
-
this._passwordsAsMap = normalizeStringPasswordToMap(this._password);
|
|
1233
|
-
}
|
|
1234
|
-
|
|
1235
|
-
_createClass(FronteggConfig, [{
|
|
1236
|
-
key: "cookieName",
|
|
1237
|
-
get: function get() {
|
|
1238
|
-
return "".concat(this._cookieName, "-").concat(this._clientId.replace(/-/g, ''));
|
|
1239
|
-
}
|
|
1240
|
-
}, {
|
|
1241
|
-
key: "password",
|
|
1242
|
-
get: function get() {
|
|
1243
|
-
return this._password;
|
|
1244
|
-
}
|
|
1245
|
-
}, {
|
|
1246
|
-
key: "clientId",
|
|
1247
|
-
get: function get() {
|
|
1248
|
-
return this._clientId;
|
|
1249
|
-
}
|
|
1250
|
-
}, {
|
|
1251
|
-
key: "baseUrlHost",
|
|
1252
|
-
get: function get() {
|
|
1253
|
-
var _a;
|
|
1254
|
-
|
|
1255
|
-
return new URL((_a = process.env['FRONTEGG_BASE_URL']) !== null && _a !== void 0 ? _a : '').hostname;
|
|
1256
|
-
}
|
|
1257
|
-
}, {
|
|
1258
|
-
key: "getEnvAppUrl",
|
|
1259
|
-
value: function getEnvAppUrl() {
|
|
1260
|
-
var url = undefined;
|
|
1261
|
-
|
|
1262
|
-
if (process.env['FRONTEGG_APP_URL']) {
|
|
1263
|
-
url = process.env['FRONTEGG_APP_URL'];
|
|
1264
|
-
} else if (process.env['VERCEL'] && process.env['VERCEL_URL']) {
|
|
1265
|
-
url = process.env['VERCEL_URL'];
|
|
1266
|
-
}
|
|
1267
|
-
|
|
1268
|
-
if (url && !url.startsWith('http')) {
|
|
1269
|
-
var protocol = url.startsWith('localhost') ? 'http://' : 'https://';
|
|
1270
|
-
url = "".concat(protocol).concat(url);
|
|
1271
|
-
}
|
|
1272
|
-
|
|
1273
|
-
return url;
|
|
1274
|
-
}
|
|
1275
|
-
}, {
|
|
1276
|
-
key: "appUrl",
|
|
1277
|
-
get: function get() {
|
|
1278
|
-
var _a;
|
|
1279
|
-
|
|
1280
|
-
return (_a = this.getEnvAppUrl()) !== null && _a !== void 0 ? _a : 'http://localhost:3000';
|
|
1281
|
-
}
|
|
1282
|
-
}, {
|
|
1283
|
-
key: "appEnvConfig",
|
|
1284
|
-
get: function get() {
|
|
1285
|
-
return {
|
|
1286
|
-
envAppUrl: this.getEnvAppUrl(),
|
|
1287
|
-
envBaseUrl: process.env['FRONTEGG_BASE_URL'],
|
|
1288
|
-
envClientId: process.env['FRONTEGG_CLIENT_ID']
|
|
1289
|
-
};
|
|
1290
|
-
}
|
|
1291
|
-
}, {
|
|
1292
|
-
key: "cookieDomain",
|
|
1293
|
-
get: function get() {
|
|
1294
|
-
var _a;
|
|
1295
|
-
|
|
1296
|
-
return new URL((_a = this.getEnvAppUrl()) !== null && _a !== void 0 ? _a : '').hostname.replace(/:(\d)+$/, '');
|
|
1297
|
-
}
|
|
1298
|
-
}, {
|
|
1299
|
-
key: "getJwtPublicKey",
|
|
1300
|
-
value: function getJwtPublicKey() {
|
|
1301
|
-
return __awaiter(this, void 0, void 0, /*#__PURE__*/regenerator.mark(function _callee() {
|
|
1302
|
-
var response, data, publicKey;
|
|
1303
|
-
return regenerator.wrap(function _callee$(_context) {
|
|
1304
|
-
while (1) {
|
|
1305
|
-
switch (_context.prev = _context.next) {
|
|
1306
|
-
case 0:
|
|
1307
|
-
if (this._jwtPublicKey) {
|
|
1308
|
-
_context.next = 11;
|
|
1309
|
-
break;
|
|
1310
|
-
}
|
|
1311
|
-
|
|
1312
|
-
_context.next = 3;
|
|
1313
|
-
return fetch("".concat(process.env['FRONTEGG_BASE_URL'], "/.well-known/jwks.json"));
|
|
1314
|
-
|
|
1315
|
-
case 3:
|
|
1316
|
-
response = _context.sent;
|
|
1317
|
-
_context.next = 6;
|
|
1318
|
-
return response.json();
|
|
1319
|
-
|
|
1320
|
-
case 6:
|
|
1321
|
-
data = _context.sent;
|
|
1322
|
-
publicKey = data.keys.find(function (key) {
|
|
1323
|
-
return key.kty === 'RSA';
|
|
1324
|
-
});
|
|
1325
|
-
_context.next = 10;
|
|
1326
|
-
return jose.importJWK(publicKey);
|
|
1327
|
-
|
|
1328
|
-
case 10:
|
|
1329
|
-
this._jwtPublicKey = _context.sent;
|
|
1330
|
-
|
|
1331
|
-
case 11:
|
|
1332
|
-
return _context.abrupt("return", this._jwtPublicKey);
|
|
1333
|
-
|
|
1334
|
-
case 12:
|
|
1335
|
-
case "end":
|
|
1336
|
-
return _context.stop();
|
|
1337
|
-
}
|
|
1338
|
-
}
|
|
1339
|
-
}, _callee, this);
|
|
1340
|
-
}));
|
|
1341
|
-
}
|
|
1342
|
-
}, {
|
|
1343
|
-
key: "passwordsAsMap",
|
|
1344
|
-
get: function get() {
|
|
1345
|
-
return this._passwordsAsMap;
|
|
1346
|
-
}
|
|
1347
|
-
}]);
|
|
1348
|
-
|
|
1349
|
-
return FronteggConfig;
|
|
1350
|
-
}();
|
|
1351
|
-
|
|
1352
|
-
var fronteggConfig = new FronteggConfig();
|
|
1353
|
-
|
|
1354
|
-
function _arrayLikeToArray$1(arr, len) {
|
|
1355
|
-
if (len == null || len > arr.length) len = arr.length;
|
|
1356
|
-
|
|
1357
|
-
for (var i = 0, arr2 = new Array(len); i < len; i++) {
|
|
1358
|
-
arr2[i] = arr[i];
|
|
1359
|
-
}
|
|
1360
|
-
|
|
1361
|
-
return arr2;
|
|
1362
|
-
}
|
|
1363
|
-
|
|
1364
|
-
function _arrayWithoutHoles(arr) {
|
|
1365
|
-
if (Array.isArray(arr)) return _arrayLikeToArray$1(arr);
|
|
1366
|
-
}
|
|
1367
|
-
|
|
1368
|
-
function _iterableToArray(iter) {
|
|
1369
|
-
if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
|
|
1370
|
-
}
|
|
1371
|
-
|
|
1372
|
-
function _unsupportedIterableToArray$1(o, minLen) {
|
|
1373
|
-
if (!o) return;
|
|
1374
|
-
if (typeof o === "string") return _arrayLikeToArray$1(o, minLen);
|
|
1375
|
-
var n = Object.prototype.toString.call(o).slice(8, -1);
|
|
1376
|
-
if (n === "Object" && o.constructor) n = o.constructor.name;
|
|
1377
|
-
if (n === "Map" || n === "Set") return Array.from(o);
|
|
1378
|
-
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray$1(o, minLen);
|
|
1379
|
-
}
|
|
1380
|
-
|
|
1381
|
-
function _nonIterableSpread() {
|
|
1382
|
-
throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
1383
|
-
}
|
|
1384
|
-
|
|
1385
|
-
function _toConsumableArray(arr) {
|
|
1386
|
-
return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray$1(arr) || _nonIterableSpread();
|
|
1387
|
-
}
|
|
1388
|
-
|
|
1389
|
-
function FronteggRouter() {
|
|
1390
|
-
var app = react.useContext(AppContext);
|
|
1391
|
-
|
|
1392
|
-
var _useRouter = router.useRouter(),
|
|
1393
|
-
query = _useRouter.query,
|
|
1394
|
-
replace = _useRouter.replace;
|
|
1395
|
-
|
|
1396
|
-
var loginWithRedirect = reactHooks.useLoginWithRedirect();
|
|
1397
|
-
|
|
1398
|
-
var _useLoginActions = reactHooks.useLoginActions(),
|
|
1399
|
-
logout = _useLoginActions.logout;
|
|
1400
|
-
|
|
1401
|
-
react.useEffect(function () {
|
|
1402
|
-
if (!app) {
|
|
1403
|
-
return;
|
|
1404
|
-
}
|
|
1405
|
-
|
|
1406
|
-
if (app.options.hostedLoginBox) {
|
|
1407
|
-
var routesObj = Object.assign(Object.assign({}, reduxStore.authInitialState.routes), fronteggConfig.authRoutes);
|
|
1408
|
-
|
|
1409
|
-
var _a = query,
|
|
1410
|
-
pathArr = _a['frontegg-router'],
|
|
1411
|
-
queryParams = __rest(_a, ['frontegg-router']);
|
|
1412
|
-
|
|
1413
|
-
var pathname = "/".concat(pathArr.join('/'));
|
|
1414
|
-
|
|
1415
|
-
if (pathname === routesObj.loginUrl) {
|
|
1416
|
-
if (queryParams.redirectUrl) {
|
|
1417
|
-
localStorage.setItem('FRONTEGG_AFTER_AUTH_REDIRECT_URL', "".concat(window.location.origin).concat(queryParams.redirectUrl));
|
|
1418
|
-
}
|
|
1419
|
-
|
|
1420
|
-
loginWithRedirect();
|
|
1421
|
-
} else if (pathname === routesObj.logoutUrl) {
|
|
1422
|
-
var _baseUrl = app.options.contextOptions.baseUrl;
|
|
1423
|
-
var baseUrl = typeof _baseUrl === 'string' ? _baseUrl : _baseUrl('');
|
|
1424
|
-
logout(function () {
|
|
1425
|
-
window.location.href = "".concat(baseUrl, "/oauth/logout?post_logout_redirect_uri=").concat(encodeURIComponent(window.location.origin));
|
|
1426
|
-
});
|
|
1427
|
-
}
|
|
1428
|
-
}
|
|
1429
|
-
}, [app, query, loginWithRedirect, logout, replace]);
|
|
1430
|
-
return '';
|
|
1431
|
-
}
|
|
1432
|
-
function FronteggRouterProps(context) {
|
|
1433
|
-
var _a;
|
|
1434
|
-
|
|
1435
|
-
var routesObj = Object.assign(Object.assign({}, reduxStore.authInitialState.routes), fronteggConfig.authRoutes);
|
|
1436
|
-
var routesArr = Object.keys(routesObj).reduce(function (p, key) {
|
|
1437
|
-
return [].concat(_toConsumableArray(p), [routesObj[key]]);
|
|
1438
|
-
}, []);
|
|
1439
|
-
|
|
1440
|
-
var _parse = url.parse((_a = context.resolvedUrl) !== null && _a !== void 0 ? _a : context.req.url, true),
|
|
1441
|
-
pathname = _parse.pathname;
|
|
1442
|
-
|
|
1443
|
-
if (!pathname || pathname.startsWith('/_next/data')) {
|
|
1444
|
-
var query = context.req.query[Object.keys(context.req.query)[0]];
|
|
1445
|
-
pathname = "/".concat(Array.isArray(query) ? query.join('/') : query);
|
|
1446
|
-
}
|
|
1447
|
-
|
|
1448
|
-
var notFound = routesArr.indexOf(pathname) === -1;
|
|
1449
|
-
|
|
1450
|
-
if (fronteggConfig.fronteggAppOptions.hostedLoginBox) {
|
|
1451
|
-
var _notFound = !(routesObj.loginUrl === pathname || routesObj.logoutUrl === pathname || routesObj.hostedLoginRedirectUrl === pathname);
|
|
1452
|
-
|
|
1453
|
-
return {
|
|
1454
|
-
notFound: _notFound,
|
|
1455
|
-
props: {}
|
|
1456
|
-
};
|
|
1457
|
-
}
|
|
1458
|
-
|
|
1459
|
-
return {
|
|
1460
|
-
notFound: notFound,
|
|
1461
|
-
props: {}
|
|
1462
|
-
};
|
|
1463
|
-
}
|
|
1464
|
-
|
|
1465
|
-
function _arrayWithHoles(arr) {
|
|
1466
|
-
if (Array.isArray(arr)) return arr;
|
|
1467
|
-
}
|
|
1468
|
-
|
|
1469
|
-
function _iterableToArrayLimit(arr, i) {
|
|
1470
|
-
var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
|
|
1471
|
-
|
|
1472
|
-
if (_i == null) return;
|
|
1473
|
-
var _arr = [];
|
|
1474
|
-
var _n = true;
|
|
1475
|
-
var _d = false;
|
|
1476
|
-
|
|
1477
|
-
var _s, _e;
|
|
1478
|
-
|
|
1479
|
-
try {
|
|
1480
|
-
for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) {
|
|
1481
|
-
_arr.push(_s.value);
|
|
1482
|
-
|
|
1483
|
-
if (i && _arr.length === i) break;
|
|
1484
|
-
}
|
|
1485
|
-
} catch (err) {
|
|
1486
|
-
_d = true;
|
|
1487
|
-
_e = err;
|
|
1488
|
-
} finally {
|
|
1489
|
-
try {
|
|
1490
|
-
if (!_n && _i["return"] != null) _i["return"]();
|
|
1491
|
-
} finally {
|
|
1492
|
-
if (_d) throw _e;
|
|
1493
|
-
}
|
|
1494
|
-
}
|
|
1495
|
-
|
|
1496
|
-
return _arr;
|
|
1497
|
-
}
|
|
1498
|
-
|
|
1499
|
-
function _nonIterableRest() {
|
|
1500
|
-
throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
1501
|
-
}
|
|
1502
|
-
|
|
1503
|
-
function _slicedToArray(arr, i) {
|
|
1504
|
-
return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray$1(arr, i) || _nonIterableRest();
|
|
1505
|
-
}
|
|
1506
|
-
|
|
1507
|
-
function _defineProperty(obj, key, value) {
|
|
1508
|
-
if (key in obj) {
|
|
1509
|
-
Object.defineProperty(obj, key, {
|
|
1510
|
-
value: value,
|
|
1511
|
-
enumerable: true,
|
|
1512
|
-
configurable: true,
|
|
1513
|
-
writable: true
|
|
1514
|
-
});
|
|
1515
|
-
} else {
|
|
1516
|
-
obj[key] = value;
|
|
1517
|
-
}
|
|
1518
|
-
|
|
1519
|
-
return obj;
|
|
1520
|
-
}
|
|
1521
|
-
|
|
1522
|
-
function getHostedLoginRefreshToken(req) {
|
|
1523
|
-
return __awaiter(this, void 0, void 0, /*#__PURE__*/regenerator.mark(function _callee() {
|
|
1524
|
-
var cookieStr, sealFromCookies, compressedJwt, _JSON$parse, refreshToken;
|
|
1525
|
-
|
|
1526
|
-
return regenerator.wrap(function _callee$(_context) {
|
|
1527
|
-
while (1) {
|
|
1528
|
-
switch (_context.prev = _context.next) {
|
|
1529
|
-
case 0:
|
|
1530
|
-
_context.prev = 0;
|
|
1531
|
-
cookieStr = 'credentials' in req ? req.headers.get('cookie') || '' : req.headers.cookie || '';
|
|
1532
|
-
sealFromCookies = parseCookie(cookieStr);
|
|
1533
|
-
|
|
1534
|
-
if (sealFromCookies) {
|
|
1535
|
-
_context.next = 5;
|
|
1536
|
-
break;
|
|
1537
|
-
}
|
|
1538
|
-
|
|
1539
|
-
return _context.abrupt("return", undefined);
|
|
1540
|
-
|
|
1541
|
-
case 5:
|
|
1542
|
-
_context.next = 7;
|
|
1543
|
-
return ironSession.unsealData(sealFromCookies, {
|
|
1544
|
-
password: fronteggConfig.passwordsAsMap
|
|
1545
|
-
});
|
|
1546
|
-
|
|
1547
|
-
case 7:
|
|
1548
|
-
compressedJwt = _context.sent;
|
|
1549
|
-
_context.t0 = JSON;
|
|
1550
|
-
_context.next = 11;
|
|
1551
|
-
return uncompress(compressedJwt);
|
|
1552
|
-
|
|
1553
|
-
case 11:
|
|
1554
|
-
_context.t1 = _context.sent;
|
|
1555
|
-
_JSON$parse = _context.t0.parse.call(_context.t0, _context.t1);
|
|
1556
|
-
refreshToken = _JSON$parse.refreshToken;
|
|
1557
|
-
return _context.abrupt("return", refreshToken);
|
|
1558
|
-
|
|
1559
|
-
case 17:
|
|
1560
|
-
_context.prev = 17;
|
|
1561
|
-
_context.t2 = _context["catch"](0);
|
|
1562
|
-
return _context.abrupt("return", undefined);
|
|
1563
|
-
|
|
1564
|
-
case 20:
|
|
1565
|
-
case "end":
|
|
1566
|
-
return _context.stop();
|
|
1567
|
-
}
|
|
1568
|
-
}
|
|
1569
|
-
}, _callee, null, [[0, 17]]);
|
|
1570
|
-
}));
|
|
1571
|
-
}
|
|
1572
|
-
function getSession(req) {
|
|
1573
|
-
return __awaiter(this, void 0, void 0, /*#__PURE__*/regenerator.mark(function _callee2() {
|
|
1574
|
-
var cookieStr, sealFromCookies, compressedJwt, uncompressedJwt, _JSON$parse2, accessToken, refreshToken, publicKey, _yield$jwtVerify, payload, session;
|
|
1575
|
-
|
|
1576
|
-
return regenerator.wrap(function _callee2$(_context2) {
|
|
1577
|
-
while (1) {
|
|
1578
|
-
switch (_context2.prev = _context2.next) {
|
|
1579
|
-
case 0:
|
|
1580
|
-
_context2.prev = 0;
|
|
1581
|
-
cookieStr = 'credentials' in req ? req.headers.get('cookie') || '' : req.headers.cookie || '';
|
|
1582
|
-
sealFromCookies = parseCookie(cookieStr);
|
|
1583
|
-
|
|
1584
|
-
if (sealFromCookies) {
|
|
1585
|
-
_context2.next = 5;
|
|
1586
|
-
break;
|
|
1587
|
-
}
|
|
1588
|
-
|
|
1589
|
-
return _context2.abrupt("return", undefined);
|
|
1590
|
-
|
|
1591
|
-
case 5:
|
|
1592
|
-
_context2.next = 7;
|
|
1593
|
-
return ironSession.unsealData(sealFromCookies, {
|
|
1594
|
-
password: fronteggConfig.passwordsAsMap
|
|
1595
|
-
});
|
|
1596
|
-
|
|
1597
|
-
case 7:
|
|
1598
|
-
compressedJwt = _context2.sent;
|
|
1599
|
-
_context2.next = 10;
|
|
1600
|
-
return uncompress(compressedJwt);
|
|
1601
|
-
|
|
1602
|
-
case 10:
|
|
1603
|
-
uncompressedJwt = _context2.sent;
|
|
1604
|
-
_JSON$parse2 = JSON.parse(uncompressedJwt), accessToken = _JSON$parse2.accessToken, refreshToken = _JSON$parse2.refreshToken;
|
|
1605
|
-
|
|
1606
|
-
if (accessToken) {
|
|
1607
|
-
_context2.next = 14;
|
|
1608
|
-
break;
|
|
1609
|
-
}
|
|
1610
|
-
|
|
1611
|
-
return _context2.abrupt("return", undefined);
|
|
1612
|
-
|
|
1613
|
-
case 14:
|
|
1614
|
-
_context2.next = 16;
|
|
1615
|
-
return fronteggConfig.getJwtPublicKey();
|
|
1616
|
-
|
|
1617
|
-
case 16:
|
|
1618
|
-
publicKey = _context2.sent;
|
|
1619
|
-
_context2.next = 19;
|
|
1620
|
-
return jose.jwtVerify(accessToken, publicKey);
|
|
1621
|
-
|
|
1622
|
-
case 19:
|
|
1623
|
-
_yield$jwtVerify = _context2.sent;
|
|
1624
|
-
payload = _yield$jwtVerify.payload;
|
|
1625
|
-
session = {
|
|
1626
|
-
accessToken: accessToken,
|
|
1627
|
-
user: payload,
|
|
1628
|
-
refreshToken: refreshToken
|
|
1629
|
-
};
|
|
1630
|
-
|
|
1631
|
-
if (!(session.user.exp * 1000 < Date.now())) {
|
|
1632
|
-
_context2.next = 24;
|
|
1633
|
-
break;
|
|
1634
|
-
}
|
|
1635
|
-
|
|
1636
|
-
return _context2.abrupt("return", undefined);
|
|
1637
|
-
|
|
1638
|
-
case 24:
|
|
1639
|
-
return _context2.abrupt("return", session);
|
|
1640
|
-
|
|
1641
|
-
case 27:
|
|
1642
|
-
_context2.prev = 27;
|
|
1643
|
-
_context2.t0 = _context2["catch"](0);
|
|
1644
|
-
console.error(_context2.t0);
|
|
1645
|
-
return _context2.abrupt("return", undefined);
|
|
1646
|
-
|
|
1647
|
-
case 31:
|
|
1648
|
-
case "end":
|
|
1649
|
-
return _context2.stop();
|
|
1650
|
-
}
|
|
1651
|
-
}
|
|
1652
|
-
}, _callee2, null, [[0, 27]]);
|
|
1653
|
-
}));
|
|
1654
|
-
}
|
|
1655
|
-
function withSSRSession(handler) {
|
|
1656
|
-
var _this = this;
|
|
1657
|
-
|
|
1658
|
-
return function (context) {
|
|
1659
|
-
return __awaiter(_this, void 0, void 0, /*#__PURE__*/regenerator.mark(function _callee3() {
|
|
1660
|
-
var _a, _b, session, loginUrl;
|
|
1661
|
-
|
|
1662
|
-
return regenerator.wrap(function _callee3$(_context3) {
|
|
1663
|
-
while (1) {
|
|
1664
|
-
switch (_context3.prev = _context3.next) {
|
|
1665
|
-
case 0:
|
|
1666
|
-
_context3.next = 2;
|
|
1667
|
-
return getSession(context.req);
|
|
1668
|
-
|
|
1669
|
-
case 2:
|
|
1670
|
-
session = _context3.sent;
|
|
1671
|
-
|
|
1672
|
-
if (!session) {
|
|
1673
|
-
_context3.next = 7;
|
|
1674
|
-
break;
|
|
1675
|
-
}
|
|
1676
|
-
|
|
1677
|
-
return _context3.abrupt("return", handler(context, session));
|
|
1678
|
-
|
|
1679
|
-
case 7:
|
|
1680
|
-
loginUrl = (_a = fronteggConfig.authRoutes.loginUrl) !== null && _a !== void 0 ? _a : reduxStore.authInitialState.routes.loginUrl;
|
|
1681
|
-
|
|
1682
|
-
if (!loginUrl.startsWith('/')) {
|
|
1683
|
-
loginUrl = "/".concat(loginUrl);
|
|
1684
|
-
}
|
|
1685
|
-
|
|
1686
|
-
return _context3.abrupt("return", {
|
|
1687
|
-
redirect: {
|
|
1688
|
-
permanent: false,
|
|
1689
|
-
destination: "".concat(loginUrl, "?redirectUrl=").concat(encodeURIComponent((_b = context.resolvedUrl) !== null && _b !== void 0 ? _b : context.req.url))
|
|
1690
|
-
},
|
|
1691
|
-
props: {}
|
|
1692
|
-
});
|
|
1693
|
-
|
|
1694
|
-
case 10:
|
|
1695
|
-
case "end":
|
|
1696
|
-
return _context3.stop();
|
|
1697
|
-
}
|
|
1698
|
-
}
|
|
1699
|
-
}, _callee3);
|
|
1700
|
-
}));
|
|
1701
|
-
};
|
|
1702
|
-
}
|
|
1703
|
-
|
|
1704
|
-
var BASE_URL = "".concat(process.env['FRONTEGG_BASE_URL'], "/frontegg");
|
|
1705
|
-
|
|
1706
|
-
var Get = function Get(_ref) {
|
|
1707
|
-
var url = _ref.url,
|
|
1708
|
-
_ref$credentials = _ref.credentials,
|
|
1709
|
-
credentials = _ref$credentials === void 0 ? 'include' : _ref$credentials,
|
|
1710
|
-
headers = _ref.headers;
|
|
1711
|
-
return fetch(url, {
|
|
1712
|
-
method: 'GET',
|
|
1713
|
-
credentials: credentials,
|
|
1714
|
-
headers: headers
|
|
1715
|
-
});
|
|
1716
|
-
};
|
|
1717
|
-
|
|
1718
|
-
var extractHeaders = function extractHeaders(headers) {
|
|
1719
|
-
return {
|
|
1720
|
-
'accept-encoding': headers['accept-encoding'],
|
|
1721
|
-
'accept-language': headers['accept-language'],
|
|
1722
|
-
cookie: headers['cookie'],
|
|
1723
|
-
accept: headers['accept'],
|
|
1724
|
-
'user-agent': headers['user-agent'],
|
|
1725
|
-
connection: headers['connection'],
|
|
1726
|
-
'cache-control': headers['cache-control'],
|
|
1727
|
-
'Authorization': headers['Authorization']
|
|
1728
|
-
};
|
|
1729
|
-
};
|
|
1730
|
-
|
|
1731
|
-
var parseResponse = function parseResponse(res) {
|
|
1732
|
-
return __awaiter(void 0, void 0, void 0, /*#__PURE__*/regenerator.mark(function _callee() {
|
|
1733
|
-
var resText;
|
|
1734
|
-
return regenerator.wrap(function _callee$(_context) {
|
|
1735
|
-
while (1) {
|
|
1736
|
-
switch (_context.prev = _context.next) {
|
|
1737
|
-
case 0:
|
|
1738
|
-
if (res.ok) {
|
|
1739
|
-
_context.next = 2;
|
|
1740
|
-
break;
|
|
1741
|
-
}
|
|
1742
|
-
|
|
1743
|
-
return _context.abrupt("return", undefined);
|
|
1744
|
-
|
|
1745
|
-
case 2:
|
|
1746
|
-
_context.next = 4;
|
|
1747
|
-
return res.text();
|
|
1748
|
-
|
|
1749
|
-
case 4:
|
|
1750
|
-
resText = _context.sent;
|
|
1751
|
-
return _context.abrupt("return", JSON.parse(resText));
|
|
1752
|
-
|
|
1753
|
-
case 6:
|
|
1754
|
-
case "end":
|
|
1755
|
-
return _context.stop();
|
|
1756
|
-
}
|
|
1757
|
-
}
|
|
1758
|
-
}, _callee);
|
|
1759
|
-
}));
|
|
1760
|
-
};
|
|
1761
|
-
|
|
1762
|
-
var getUsers = function getUsers(headers) {
|
|
1763
|
-
return __awaiter(void 0, void 0, void 0, /*#__PURE__*/regenerator.mark(function _callee2() {
|
|
1764
|
-
var res;
|
|
1765
|
-
return regenerator.wrap(function _callee2$(_context2) {
|
|
1766
|
-
while (1) {
|
|
1767
|
-
switch (_context2.prev = _context2.next) {
|
|
1768
|
-
case 0:
|
|
1769
|
-
_context2.next = 2;
|
|
1770
|
-
return Get({
|
|
1771
|
-
url: "".concat(BASE_URL).concat(restApi.fronteggUsersUrl),
|
|
1772
|
-
headers: extractHeaders(headers)
|
|
1773
|
-
});
|
|
1774
|
-
|
|
1775
|
-
case 2:
|
|
1776
|
-
res = _context2.sent;
|
|
1777
|
-
return _context2.abrupt("return", parseResponse(res));
|
|
1778
|
-
|
|
1779
|
-
case 4:
|
|
1780
|
-
case "end":
|
|
1781
|
-
return _context2.stop();
|
|
1782
|
-
}
|
|
1783
|
-
}
|
|
1784
|
-
}, _callee2);
|
|
1785
|
-
}));
|
|
1786
|
-
};
|
|
1787
|
-
var getTenants = function getTenants(headers) {
|
|
1788
|
-
return __awaiter(void 0, void 0, void 0, /*#__PURE__*/regenerator.mark(function _callee3() {
|
|
1789
|
-
var res;
|
|
1790
|
-
return regenerator.wrap(function _callee3$(_context3) {
|
|
1791
|
-
while (1) {
|
|
1792
|
-
switch (_context3.prev = _context3.next) {
|
|
1793
|
-
case 0:
|
|
1794
|
-
_context3.next = 2;
|
|
1795
|
-
return Get({
|
|
1796
|
-
url: "".concat(BASE_URL).concat(restApi.fronteggTenantsUrl),
|
|
1797
|
-
headers: extractHeaders(headers)
|
|
1798
|
-
});
|
|
1799
|
-
|
|
1800
|
-
case 2:
|
|
1801
|
-
res = _context3.sent;
|
|
1802
|
-
return _context3.abrupt("return", parseResponse(res));
|
|
1803
|
-
|
|
1804
|
-
case 4:
|
|
1805
|
-
case "end":
|
|
1806
|
-
return _context3.stop();
|
|
1807
|
-
}
|
|
1808
|
-
}
|
|
1809
|
-
}, _callee3);
|
|
1810
|
-
}));
|
|
1811
|
-
};
|
|
1812
|
-
|
|
1813
|
-
function rewriteCookieProperty(header, config, property) {
|
|
1814
|
-
if (Array.isArray(header)) {
|
|
1815
|
-
return header.map(function (headerElement) {
|
|
1816
|
-
return rewriteCookieProperty(headerElement, config, property);
|
|
1817
|
-
});
|
|
1818
|
-
}
|
|
1819
|
-
|
|
1820
|
-
return header.replace(new RegExp('(;\\s*' + property + '=)([^;]+)', 'i'), function (match, prefix, previousValue) {
|
|
1821
|
-
var newValue;
|
|
1822
|
-
|
|
1823
|
-
if (previousValue in config) {
|
|
1824
|
-
newValue = config[previousValue];
|
|
1825
|
-
} else if ('*' in config) {
|
|
1826
|
-
newValue = config['*'];
|
|
1827
|
-
} else {
|
|
1828
|
-
// no match, return previous value
|
|
1829
|
-
return match;
|
|
1830
|
-
}
|
|
1831
|
-
|
|
1832
|
-
if (newValue) {
|
|
1833
|
-
// replace value
|
|
1834
|
-
return prefix + newValue;
|
|
1835
|
-
} else {
|
|
1836
|
-
// remove value
|
|
1837
|
-
return '';
|
|
1838
|
-
}
|
|
1839
|
-
});
|
|
1840
|
-
}
|
|
1841
|
-
|
|
1842
|
-
function refreshTokenHostedLogin(ctx, headers) {
|
|
1843
|
-
return __awaiter(this, void 0, void 0, /*#__PURE__*/regenerator.mark(function _callee() {
|
|
1844
|
-
var refreshToken;
|
|
1845
|
-
return regenerator.wrap(function _callee$(_context) {
|
|
1846
|
-
while (1) {
|
|
1847
|
-
switch (_context.prev = _context.next) {
|
|
1848
|
-
case 0:
|
|
1849
|
-
_context.next = 2;
|
|
1850
|
-
return getHostedLoginRefreshToken(ctx.req);
|
|
1851
|
-
|
|
1852
|
-
case 2:
|
|
1853
|
-
refreshToken = _context.sent;
|
|
1854
|
-
|
|
1855
|
-
if (refreshToken) {
|
|
1856
|
-
_context.next = 5;
|
|
1857
|
-
break;
|
|
1858
|
-
}
|
|
1859
|
-
|
|
1860
|
-
return _context.abrupt("return", null);
|
|
1861
|
-
|
|
1862
|
-
case 5:
|
|
1863
|
-
_context.next = 7;
|
|
1864
|
-
return fetch("".concat(process.env['FRONTEGG_BASE_URL'], "/frontegg").concat(restApi.fronteggSilentRefreshTokenUrl), {
|
|
1865
|
-
method: 'POST',
|
|
1866
|
-
credentials: 'include',
|
|
1867
|
-
body: JSON.stringify({
|
|
1868
|
-
grant_type: 'refresh_token',
|
|
1869
|
-
refresh_token: refreshToken
|
|
1870
|
-
}),
|
|
1871
|
-
headers: {
|
|
1872
|
-
'accept-encoding': headers['accept-encoding'],
|
|
1873
|
-
'accept-language': headers['accept-language'],
|
|
1874
|
-
cookie: headers['cookie'],
|
|
1875
|
-
accept: headers['accept'],
|
|
1876
|
-
'user-agent': headers['user-agent'],
|
|
1877
|
-
connection: headers['connection'],
|
|
1878
|
-
'cache-control': headers['cache-control']
|
|
1879
|
-
}
|
|
1880
|
-
});
|
|
1881
|
-
|
|
1882
|
-
case 7:
|
|
1883
|
-
return _context.abrupt("return", _context.sent);
|
|
1884
|
-
|
|
1885
|
-
case 8:
|
|
1886
|
-
case "end":
|
|
1887
|
-
return _context.stop();
|
|
1888
|
-
}
|
|
1889
|
-
}
|
|
1890
|
-
}, _callee);
|
|
1891
|
-
}));
|
|
1892
|
-
}
|
|
1893
|
-
|
|
1894
|
-
function refreshTokenEmbedded(ctx, headers, cookies) {
|
|
1895
|
-
return __awaiter(this, void 0, void 0, /*#__PURE__*/regenerator.mark(function _callee2() {
|
|
1896
|
-
var refreshTokenKey, cookieKey;
|
|
1897
|
-
return regenerator.wrap(function _callee2$(_context2) {
|
|
1898
|
-
while (1) {
|
|
1899
|
-
switch (_context2.prev = _context2.next) {
|
|
1900
|
-
case 0:
|
|
1901
|
-
refreshTokenKey = "fe_refresh_".concat(fronteggConfig.clientId).replace(/-/g, '');
|
|
1902
|
-
cookieKey = Object.keys(cookies).find(function (cookie) {
|
|
1903
|
-
return cookie.replace(/-/g, '') === refreshTokenKey;
|
|
1904
|
-
});
|
|
1905
|
-
|
|
1906
|
-
if (cookieKey) {
|
|
1907
|
-
_context2.next = 4;
|
|
1908
|
-
break;
|
|
1909
|
-
}
|
|
1910
|
-
|
|
1911
|
-
return _context2.abrupt("return", null);
|
|
1912
|
-
|
|
1913
|
-
case 4:
|
|
1914
|
-
_context2.next = 6;
|
|
1915
|
-
return fetch("".concat(process.env['FRONTEGG_BASE_URL'], "/frontegg").concat(restApi.fronteggRefreshTokenUrl), {
|
|
1916
|
-
method: 'POST',
|
|
1917
|
-
credentials: 'include',
|
|
1918
|
-
body: '{}',
|
|
1919
|
-
headers: {
|
|
1920
|
-
'accept-encoding': headers['accept-encoding'],
|
|
1921
|
-
'accept-language': headers['accept-language'],
|
|
1922
|
-
cookie: headers['cookie'],
|
|
1923
|
-
accept: headers['accept'],
|
|
1924
|
-
'user-agent': headers['user-agent'],
|
|
1925
|
-
connection: headers['connection'],
|
|
1926
|
-
'cache-control': headers['cache-control']
|
|
1927
|
-
}
|
|
1928
|
-
});
|
|
1929
|
-
|
|
1930
|
-
case 6:
|
|
1931
|
-
return _context2.abrupt("return", _context2.sent);
|
|
1932
|
-
|
|
1933
|
-
case 7:
|
|
1934
|
-
case "end":
|
|
1935
|
-
return _context2.stop();
|
|
1936
|
-
}
|
|
1937
|
-
}
|
|
1938
|
-
}, _callee2);
|
|
1939
|
-
}));
|
|
1940
|
-
}
|
|
1941
|
-
|
|
1942
|
-
function refreshToken(ctx) {
|
|
1943
|
-
var _a;
|
|
1944
|
-
|
|
1945
|
-
return __awaiter(this, void 0, void 0, /*#__PURE__*/regenerator.mark(function _callee3() {
|
|
1946
|
-
var request, session, isSecured, headers, cookies, response, _newSetCookie, data, rewriteCookieDomainConfig, cookieHeader, newSetCookie, _yield$createSessionF, _yield$createSessionF2, _session, decodedJwt, _refreshToken, cookieValue;
|
|
1947
|
-
|
|
1948
|
-
return regenerator.wrap(function _callee3$(_context3) {
|
|
1949
|
-
while (1) {
|
|
1950
|
-
switch (_context3.prev = _context3.next) {
|
|
1951
|
-
case 0:
|
|
1952
|
-
_context3.prev = 0;
|
|
1953
|
-
request = ctx.req;
|
|
1954
|
-
|
|
1955
|
-
if (request) {
|
|
1956
|
-
_context3.next = 4;
|
|
1957
|
-
break;
|
|
1958
|
-
}
|
|
1959
|
-
|
|
1960
|
-
return _context3.abrupt("return", null);
|
|
1961
|
-
|
|
1962
|
-
case 4:
|
|
1963
|
-
_context3.prev = 4;
|
|
1964
|
-
_context3.next = 7;
|
|
1965
|
-
return getSession(ctx.req);
|
|
1966
|
-
|
|
1967
|
-
case 7:
|
|
1968
|
-
session = _context3.sent;
|
|
1969
|
-
|
|
1970
|
-
if (!session) {
|
|
1971
|
-
_context3.next = 10;
|
|
1972
|
-
break;
|
|
1973
|
-
}
|
|
1974
|
-
|
|
1975
|
-
return _context3.abrupt("return", session);
|
|
1976
|
-
|
|
1977
|
-
case 10:
|
|
1978
|
-
_context3.next = 14;
|
|
1979
|
-
break;
|
|
1980
|
-
|
|
1981
|
-
case 12:
|
|
1982
|
-
_context3.prev = 12;
|
|
1983
|
-
_context3.t0 = _context3["catch"](4);
|
|
1984
|
-
|
|
1985
|
-
case 14:
|
|
1986
|
-
isSecured = new URL(fronteggConfig.appUrl).protocol === 'https:';
|
|
1987
|
-
headers = request.headers;
|
|
1988
|
-
cookies = request.cookies;
|
|
1989
|
-
|
|
1990
|
-
if (!ctx.req.url.startsWith('/oauth/callback')) {
|
|
1991
|
-
_context3.next = 19;
|
|
1992
|
-
break;
|
|
1993
|
-
}
|
|
1994
|
-
|
|
1995
|
-
return _context3.abrupt("return", null);
|
|
1996
|
-
|
|
1997
|
-
case 19:
|
|
1998
|
-
if (!fronteggConfig.fronteggAppOptions.hostedLoginBox) {
|
|
1999
|
-
_context3.next = 25;
|
|
2000
|
-
break;
|
|
2001
|
-
}
|
|
2002
|
-
|
|
2003
|
-
_context3.next = 22;
|
|
2004
|
-
return refreshTokenHostedLogin(ctx, headers);
|
|
2005
|
-
|
|
2006
|
-
case 22:
|
|
2007
|
-
response = _context3.sent;
|
|
2008
|
-
_context3.next = 28;
|
|
2009
|
-
break;
|
|
2010
|
-
|
|
2011
|
-
case 25:
|
|
2012
|
-
_context3.next = 27;
|
|
2013
|
-
return refreshTokenEmbedded(ctx, headers, cookies);
|
|
2014
|
-
|
|
2015
|
-
case 27:
|
|
2016
|
-
response = _context3.sent;
|
|
2017
|
-
|
|
2018
|
-
case 28:
|
|
2019
|
-
if (response) {
|
|
2020
|
-
_context3.next = 31;
|
|
2021
|
-
break;
|
|
2022
|
-
}
|
|
2023
|
-
|
|
2024
|
-
removeCookies(fronteggConfig.cookieName, isSecured, fronteggConfig.cookieDomain, ctx.res);
|
|
2025
|
-
return _context3.abrupt("return", null);
|
|
2026
|
-
|
|
2027
|
-
case 31:
|
|
2028
|
-
if (!response.ok) {
|
|
2029
|
-
_context3.next = 54;
|
|
2030
|
-
break;
|
|
2031
|
-
}
|
|
2032
|
-
|
|
2033
|
-
_context3.next = 34;
|
|
2034
|
-
return response.text();
|
|
2035
|
-
|
|
2036
|
-
case 34:
|
|
2037
|
-
data = _context3.sent;
|
|
2038
|
-
rewriteCookieDomainConfig = _defineProperty({}, fronteggConfig.baseUrlHost, fronteggConfig.cookieDomain); // @ts-ignore
|
|
2039
|
-
|
|
2040
|
-
cookieHeader = response.headers.raw()['set-cookie'];
|
|
2041
|
-
newSetCookie = rewriteCookieProperty(cookieHeader, rewriteCookieDomainConfig, 'domain');
|
|
2042
|
-
_context3.next = 40;
|
|
2043
|
-
return createSessionFromAccessToken(data);
|
|
2044
|
-
|
|
2045
|
-
case 40:
|
|
2046
|
-
_yield$createSessionF = _context3.sent;
|
|
2047
|
-
_yield$createSessionF2 = _slicedToArray(_yield$createSessionF, 3);
|
|
2048
|
-
_session = _yield$createSessionF2[0];
|
|
2049
|
-
decodedJwt = _yield$createSessionF2[1];
|
|
2050
|
-
_refreshToken = _yield$createSessionF2[2];
|
|
2051
|
-
|
|
2052
|
-
if (_session) {
|
|
2053
|
-
_context3.next = 47;
|
|
2054
|
-
break;
|
|
2055
|
-
}
|
|
2056
|
-
|
|
2057
|
-
return _context3.abrupt("return", null);
|
|
2058
|
-
|
|
2059
|
-
case 47:
|
|
2060
|
-
cookieValue = createCookie({
|
|
2061
|
-
session: _session,
|
|
2062
|
-
expires: new Date(decodedJwt.exp * 1000),
|
|
2063
|
-
isSecured: isSecured
|
|
2064
|
-
});
|
|
2065
|
-
|
|
2066
|
-
if (typeof newSetCookie === 'string') {
|
|
2067
|
-
newSetCookie = [newSetCookie];
|
|
2068
|
-
}
|
|
2069
|
-
|
|
2070
|
-
(_newSetCookie = newSetCookie).push.apply(_newSetCookie, _toConsumableArray(cookieValue));
|
|
2071
|
-
|
|
2072
|
-
(_a = ctx.res) === null || _a === void 0 ? void 0 : _a.setHeader('set-cookie', newSetCookie);
|
|
2073
|
-
return _context3.abrupt("return", {
|
|
2074
|
-
accessToken: JSON.parse(data).accessToken,
|
|
2075
|
-
user: decodedJwt,
|
|
2076
|
-
refreshToken: _refreshToken
|
|
2077
|
-
});
|
|
2078
|
-
|
|
2079
|
-
case 54:
|
|
2080
|
-
return _context3.abrupt("return", null);
|
|
2081
|
-
|
|
2082
|
-
case 55:
|
|
2083
|
-
_context3.next = 60;
|
|
2084
|
-
break;
|
|
2085
|
-
|
|
2086
|
-
case 57:
|
|
2087
|
-
_context3.prev = 57;
|
|
2088
|
-
_context3.t1 = _context3["catch"](0);
|
|
2089
|
-
return _context3.abrupt("return", null);
|
|
2090
|
-
|
|
2091
|
-
case 60:
|
|
2092
|
-
case "end":
|
|
2093
|
-
return _context3.stop();
|
|
2094
|
-
}
|
|
2095
|
-
}
|
|
2096
|
-
}, _callee3, null, [[0, 57], [4, 12]]);
|
|
2097
|
-
}));
|
|
2098
|
-
}
|
|
2099
|
-
var COOKIE_MAX_LENGTH = 4096;
|
|
2100
|
-
function createCookie(_ref) {
|
|
2101
|
-
var _ref$cookieName = _ref.cookieName,
|
|
2102
|
-
cookieName = _ref$cookieName === void 0 ? fronteggConfig.cookieName : _ref$cookieName,
|
|
2103
|
-
session = _ref.session,
|
|
2104
|
-
expires = _ref.expires,
|
|
2105
|
-
isSecured = _ref.isSecured,
|
|
2106
|
-
_ref$cookieDomain = _ref.cookieDomain,
|
|
2107
|
-
cookieDomain = _ref$cookieDomain === void 0 ? fronteggConfig.cookieDomain : _ref$cookieDomain,
|
|
2108
|
-
_ref$httpOnly = _ref.httpOnly,
|
|
2109
|
-
httpOnly = _ref$httpOnly === void 0 ? true : _ref$httpOnly,
|
|
2110
|
-
_ref$path = _ref.path,
|
|
2111
|
-
path = _ref$path === void 0 ? '/' : _ref$path;
|
|
2112
|
-
var options = {
|
|
2113
|
-
expires: expires,
|
|
2114
|
-
httpOnly: httpOnly,
|
|
2115
|
-
domain: cookieDomain,
|
|
2116
|
-
path: path,
|
|
2117
|
-
sameSite: isSecured ? 'none' : undefined,
|
|
2118
|
-
secure: isSecured
|
|
2119
|
-
};
|
|
2120
|
-
var cookieValue = cookie__default["default"].serialize(cookieName, session, options);
|
|
2121
|
-
|
|
2122
|
-
if (cookieValue.length < COOKIE_MAX_LENGTH) {
|
|
2123
|
-
return [cookieValue];
|
|
2124
|
-
}
|
|
2125
|
-
|
|
2126
|
-
return createSplitCookie(cookieName, session, options, cookieValue.length);
|
|
2127
|
-
}
|
|
2128
|
-
|
|
2129
|
-
function createSplitCookie(cookieName, session, options, cookieLength) {
|
|
2130
|
-
var numberOfCookies = Math.ceil(cookieLength / COOKIE_MAX_LENGTH);
|
|
2131
|
-
var splitSession = chunkString(session, numberOfCookies);
|
|
2132
|
-
var allCookies = [];
|
|
2133
|
-
|
|
2134
|
-
for (var i = 1; i <= numberOfCookies; i++) {
|
|
2135
|
-
allCookies.push(cookie__default["default"].serialize("".concat(cookieName, "-").concat(i), splitSession[i - 1], options));
|
|
2136
|
-
}
|
|
2137
|
-
|
|
2138
|
-
return allCookies;
|
|
2139
|
-
}
|
|
2140
|
-
|
|
2141
|
-
function chunkString(str, numChunks) {
|
|
2142
|
-
var chunkSize = Math.ceil(str.length / numChunks);
|
|
2143
|
-
var chunks = [];
|
|
2144
|
-
|
|
2145
|
-
for (var i = 0; i < numChunks; i + chunkSize) {
|
|
2146
|
-
var limit = i + chunkSize;
|
|
2147
|
-
chunks.push(str.substring(i, limit < str.length ? limit : str.length));
|
|
2148
|
-
}
|
|
2149
|
-
|
|
2150
|
-
return chunks;
|
|
2151
|
-
}
|
|
2152
|
-
|
|
2153
|
-
function parseCookie(cookieStr) {
|
|
2154
|
-
var sealFromCookies = '';
|
|
2155
|
-
|
|
2156
|
-
if (cookie__default["default"].parse(cookieStr)[fronteggConfig.cookieName]) {
|
|
2157
|
-
sealFromCookies = cookie__default["default"].parse(cookieStr)[fronteggConfig.cookieName];
|
|
2158
|
-
} else {
|
|
2159
|
-
var i = 1;
|
|
2160
|
-
|
|
2161
|
-
while (cookie__default["default"].parse(cookieStr)["".concat(fronteggConfig.cookieName, "-").concat(i)]) {
|
|
2162
|
-
sealFromCookies += cookie__default["default"].parse(cookieStr)["".concat(fronteggConfig.cookieName, "-").concat(i)];
|
|
2163
|
-
i++;
|
|
2164
|
-
}
|
|
2165
|
-
}
|
|
2166
|
-
|
|
2167
|
-
return sealFromCookies !== '' ? sealFromCookies : undefined;
|
|
2168
|
-
}
|
|
2169
|
-
function addToCookies(newCookies, res) {
|
|
2170
|
-
var _a;
|
|
2171
|
-
|
|
2172
|
-
var existingSetCookie = (_a = res.getHeader('set-cookie')) !== null && _a !== void 0 ? _a : [];
|
|
2173
|
-
|
|
2174
|
-
if (typeof existingSetCookie === 'string') {
|
|
2175
|
-
existingSetCookie = [existingSetCookie];
|
|
2176
|
-
}
|
|
2177
|
-
|
|
2178
|
-
res.setHeader('set-cookie', [].concat(_toConsumableArray(existingSetCookie), _toConsumableArray(newCookies)));
|
|
2179
|
-
}
|
|
2180
|
-
function removeCookies(cookieName, isSecured, cookieDomain, res) {
|
|
2181
|
-
var _a;
|
|
2182
|
-
|
|
2183
|
-
var cookieValue = createCookie({
|
|
2184
|
-
cookieName: cookieName,
|
|
2185
|
-
session: '',
|
|
2186
|
-
expires: new Date(),
|
|
2187
|
-
isSecured: isSecured,
|
|
2188
|
-
cookieDomain: cookieDomain
|
|
2189
|
-
});
|
|
2190
|
-
var existingSetCookie = (_a = res.getHeader('set-cookie')) !== null && _a !== void 0 ? _a : [];
|
|
2191
|
-
|
|
2192
|
-
if (typeof existingSetCookie === 'string') {
|
|
2193
|
-
existingSetCookie = [existingSetCookie];
|
|
2194
|
-
}
|
|
2195
|
-
|
|
2196
|
-
res.setHeader('set-cookie', [].concat(_toConsumableArray(existingSetCookie), _toConsumableArray(cookieValue)));
|
|
2197
|
-
}
|
|
2198
|
-
function compress(input) {
|
|
2199
|
-
return new Promise(function (resolve, reject) {
|
|
2200
|
-
zlib__namespace.brotliCompress(input, function (error, result) {
|
|
2201
|
-
if (error) {
|
|
2202
|
-
reject(error);
|
|
2203
|
-
} else {
|
|
2204
|
-
resolve(result.toString('base64'));
|
|
2205
|
-
}
|
|
2206
|
-
});
|
|
2207
|
-
});
|
|
2208
|
-
}
|
|
2209
|
-
function uncompress(input) {
|
|
2210
|
-
return new Promise(function (resolve, reject) {
|
|
2211
|
-
zlib__namespace.brotliDecompress(Buffer.from(input, 'base64'), function (error, result) {
|
|
2212
|
-
if (error) {
|
|
2213
|
-
reject(error);
|
|
2214
|
-
} else {
|
|
2215
|
-
resolve(result.toString('utf-8'));
|
|
2216
|
-
}
|
|
2217
|
-
});
|
|
2218
|
-
});
|
|
2219
|
-
}
|
|
2220
|
-
function createSessionFromAccessToken(output) {
|
|
2221
|
-
var _a, _b;
|
|
2222
|
-
|
|
2223
|
-
return __awaiter(this, void 0, void 0, /*#__PURE__*/regenerator.mark(function _callee4() {
|
|
2224
|
-
var data, accessToken, _refreshToken2, decodedJwt, uncompressedSession, compressedAccessToken, session;
|
|
2225
|
-
|
|
2226
|
-
return regenerator.wrap(function _callee4$(_context4) {
|
|
2227
|
-
while (1) {
|
|
2228
|
-
switch (_context4.prev = _context4.next) {
|
|
2229
|
-
case 0:
|
|
2230
|
-
_context4.prev = 0;
|
|
2231
|
-
data = JSON.parse(output);
|
|
2232
|
-
accessToken = (_a = data === null || data === void 0 ? void 0 : data.accessToken) !== null && _a !== void 0 ? _a : data.access_token;
|
|
2233
|
-
_refreshToken2 = (_b = data === null || data === void 0 ? void 0 : data.refreshToken) !== null && _b !== void 0 ? _b : data.refresh_token;
|
|
2234
|
-
decodedJwt = jose.decodeJwt(accessToken);
|
|
2235
|
-
decodedJwt.expiresIn = Math.floor((decodedJwt.exp * 1000 - Date.now()) / 1000);
|
|
2236
|
-
uncompressedSession = JSON.stringify({
|
|
2237
|
-
accessToken: accessToken,
|
|
2238
|
-
refreshToken: _refreshToken2
|
|
2239
|
-
});
|
|
2240
|
-
_context4.next = 9;
|
|
2241
|
-
return compress(uncompressedSession);
|
|
2242
|
-
|
|
2243
|
-
case 9:
|
|
2244
|
-
compressedAccessToken = _context4.sent;
|
|
2245
|
-
_context4.next = 12;
|
|
2246
|
-
return ironSession.sealData(compressedAccessToken, {
|
|
2247
|
-
password: fronteggConfig.passwordsAsMap,
|
|
2248
|
-
ttl: decodedJwt.exp
|
|
2249
|
-
});
|
|
2250
|
-
|
|
2251
|
-
case 12:
|
|
2252
|
-
session = _context4.sent;
|
|
2253
|
-
return _context4.abrupt("return", [session, decodedJwt, _refreshToken2]);
|
|
2254
|
-
|
|
2255
|
-
case 16:
|
|
2256
|
-
_context4.prev = 16;
|
|
2257
|
-
_context4.t0 = _context4["catch"](0);
|
|
2258
|
-
return _context4.abrupt("return", []);
|
|
2259
|
-
|
|
2260
|
-
case 19:
|
|
2261
|
-
case "end":
|
|
2262
|
-
return _context4.stop();
|
|
2263
|
-
}
|
|
2264
|
-
}
|
|
2265
|
-
}, _callee4, null, [[0, 16]]);
|
|
2266
|
-
}));
|
|
2267
|
-
}
|
|
2268
|
-
var modifySetCookieIfUnsecure = function modifySetCookieIfUnsecure(setCookieValue, isSecured) {
|
|
2269
|
-
if (!setCookieValue) {
|
|
2270
|
-
return setCookieValue;
|
|
2271
|
-
}
|
|
2272
|
-
|
|
2273
|
-
if (setCookieValue.length > 0) {
|
|
2274
|
-
return setCookieValue.map(function (c) {
|
|
2275
|
-
var cookie = c.split('; ');
|
|
2276
|
-
|
|
2277
|
-
if (isSecured) {
|
|
2278
|
-
return c;
|
|
2279
|
-
}
|
|
2280
|
-
|
|
2281
|
-
return cookie.filter(function (property) {
|
|
2282
|
-
return property !== 'Secure' && property !== 'SameSite=None';
|
|
2283
|
-
}).join('; ');
|
|
2284
|
-
});
|
|
2285
|
-
}
|
|
2286
|
-
|
|
2287
|
-
return setCookieValue;
|
|
2288
|
-
};
|
|
2289
|
-
function meAndTenants(ctx, accessToken) {
|
|
2290
|
-
return __awaiter(this, void 0, void 0, /*#__PURE__*/regenerator.mark(function _callee5() {
|
|
2291
|
-
var request, headers, _yield$Promise$all, _yield$Promise$all2, user, tenants;
|
|
2292
|
-
|
|
2293
|
-
return regenerator.wrap(function _callee5$(_context5) {
|
|
2294
|
-
while (1) {
|
|
2295
|
-
switch (_context5.prev = _context5.next) {
|
|
2296
|
-
case 0:
|
|
2297
|
-
request = ctx.req;
|
|
2298
|
-
|
|
2299
|
-
if (!(!request || !accessToken)) {
|
|
2300
|
-
_context5.next = 3;
|
|
2301
|
-
break;
|
|
2302
|
-
}
|
|
2303
|
-
|
|
2304
|
-
return _context5.abrupt("return", {});
|
|
2305
|
-
|
|
2306
|
-
case 3:
|
|
2307
|
-
headers = Object.assign(Object.assign({}, request.headers), {
|
|
2308
|
-
Authorization: "Bearer ".concat(accessToken)
|
|
2309
|
-
});
|
|
2310
|
-
_context5.next = 6;
|
|
2311
|
-
return Promise.all([getUsers(headers), getTenants(headers)]);
|
|
2312
|
-
|
|
2313
|
-
case 6:
|
|
2314
|
-
_yield$Promise$all = _context5.sent;
|
|
2315
|
-
_yield$Promise$all2 = _slicedToArray(_yield$Promise$all, 2);
|
|
2316
|
-
user = _yield$Promise$all2[0];
|
|
2317
|
-
tenants = _yield$Promise$all2[1];
|
|
2318
|
-
return _context5.abrupt("return", {
|
|
2319
|
-
user: user,
|
|
2320
|
-
tenants: tenants
|
|
2321
|
-
});
|
|
2322
|
-
|
|
2323
|
-
case 11:
|
|
2324
|
-
case "end":
|
|
2325
|
-
return _context5.stop();
|
|
2326
|
-
}
|
|
2327
|
-
}
|
|
2328
|
-
}, _callee5);
|
|
2329
|
-
}));
|
|
2330
|
-
}
|
|
2331
|
-
|
|
2332
|
-
var envError = function envError(varName) {
|
|
2333
|
-
return "@frontegg/nextjs: .env.local must contain ".concat(varName);
|
|
2334
|
-
};
|
|
2335
|
-
|
|
2336
|
-
var fronteggErrors = {
|
|
2337
|
-
envAppUrl: envError('FRONTEGG_APP_URL'),
|
|
2338
|
-
envBaseUrl: envError('FRONTEGG_BASE_URL'),
|
|
2339
|
-
envClientId: envError('FRONTEGG_CLIENT_ID')
|
|
2340
|
-
};
|
|
2341
|
-
|
|
2342
|
-
var withFronteggApp = function withFronteggApp(app, options) {
|
|
2343
|
-
var _a, _b;
|
|
2344
|
-
|
|
2345
|
-
var originalGetInitialProps = app.getInitialProps;
|
|
2346
|
-
|
|
2347
|
-
app.getInitialProps = function (appContext) {
|
|
2348
|
-
return __awaiter(void 0, void 0, void 0, /*#__PURE__*/regenerator.mark(function _callee() {
|
|
2349
|
-
var ctx, Component, session, _yield$meAndTenants, user, tenants, _fronteggConfig$appEn, envAppUrl, envBaseUrl, envClientId;
|
|
2350
|
-
|
|
2351
|
-
return regenerator.wrap(function _callee$(_context) {
|
|
2352
|
-
while (1) {
|
|
2353
|
-
switch (_context.prev = _context.next) {
|
|
2354
|
-
case 0:
|
|
2355
|
-
ctx = appContext.ctx, Component = appContext.Component;
|
|
2356
|
-
|
|
2357
|
-
if (!ctx.req) {
|
|
2358
|
-
_context.next = 47;
|
|
2359
|
-
break;
|
|
2360
|
-
}
|
|
2361
|
-
|
|
2362
|
-
_context.next = 4;
|
|
2363
|
-
return refreshToken(ctx);
|
|
2364
|
-
|
|
2365
|
-
case 4:
|
|
2366
|
-
session = _context.sent;
|
|
2367
|
-
_context.next = 7;
|
|
2368
|
-
return meAndTenants(ctx, session === null || session === void 0 ? void 0 : session.accessToken);
|
|
2369
|
-
|
|
2370
|
-
case 7:
|
|
2371
|
-
_yield$meAndTenants = _context.sent;
|
|
2372
|
-
user = _yield$meAndTenants.user;
|
|
2373
|
-
tenants = _yield$meAndTenants.tenants;
|
|
2374
|
-
appContext.session = session;
|
|
2375
|
-
appContext.user = user;
|
|
2376
|
-
appContext.tenants = tenants;
|
|
2377
|
-
_fronteggConfig$appEn = fronteggConfig.appEnvConfig, envAppUrl = _fronteggConfig$appEn.envAppUrl, envBaseUrl = _fronteggConfig$appEn.envBaseUrl, envClientId = _fronteggConfig$appEn.envClientId;
|
|
2378
|
-
|
|
2379
|
-
if (envAppUrl) {
|
|
2380
|
-
_context.next = 16;
|
|
2381
|
-
break;
|
|
2382
|
-
}
|
|
2383
|
-
|
|
2384
|
-
throw Error(fronteggErrors.envAppUrl);
|
|
2385
|
-
|
|
2386
|
-
case 16:
|
|
2387
|
-
if (envBaseUrl) {
|
|
2388
|
-
_context.next = 18;
|
|
2389
|
-
break;
|
|
2390
|
-
}
|
|
2391
|
-
|
|
2392
|
-
throw Error(fronteggErrors.envBaseUrl);
|
|
2393
|
-
|
|
2394
|
-
case 18:
|
|
2395
|
-
if (envClientId) {
|
|
2396
|
-
_context.next = 20;
|
|
2397
|
-
break;
|
|
2398
|
-
}
|
|
2399
|
-
|
|
2400
|
-
throw Error(fronteggErrors.envClientId);
|
|
2401
|
-
|
|
2402
|
-
case 20:
|
|
2403
|
-
_context.t0 = Object;
|
|
2404
|
-
_context.t1 = Object;
|
|
2405
|
-
_context.t2 = Object;
|
|
2406
|
-
_context.t3 = {};
|
|
2407
|
-
|
|
2408
|
-
if (!originalGetInitialProps) {
|
|
2409
|
-
_context.next = 30;
|
|
2410
|
-
break;
|
|
2411
|
-
}
|
|
2412
|
-
|
|
2413
|
-
_context.next = 27;
|
|
2414
|
-
return originalGetInitialProps(appContext);
|
|
2415
|
-
|
|
2416
|
-
case 27:
|
|
2417
|
-
_context.t4 = _context.sent;
|
|
2418
|
-
_context.next = 31;
|
|
2419
|
-
break;
|
|
2420
|
-
|
|
2421
|
-
case 30:
|
|
2422
|
-
_context.t4 = {};
|
|
2423
|
-
|
|
2424
|
-
case 31:
|
|
2425
|
-
_context.t5 = _context.t4;
|
|
2426
|
-
_context.t6 = _context.t2.assign.call(_context.t2, _context.t3, _context.t5);
|
|
2427
|
-
|
|
2428
|
-
if (!Component.getInitialProps) {
|
|
2429
|
-
_context.next = 39;
|
|
2430
|
-
break;
|
|
2431
|
-
}
|
|
2432
|
-
|
|
2433
|
-
_context.next = 36;
|
|
2434
|
-
return Component.getInitialProps(ctx);
|
|
2435
|
-
|
|
2436
|
-
case 36:
|
|
2437
|
-
_context.t7 = _context.sent;
|
|
2438
|
-
_context.next = 40;
|
|
2439
|
-
break;
|
|
2440
|
-
|
|
2441
|
-
case 39:
|
|
2442
|
-
_context.t7 = {};
|
|
2443
|
-
|
|
2444
|
-
case 40:
|
|
2445
|
-
_context.t8 = _context.t7;
|
|
2446
|
-
_context.t9 = _context.t1.assign.call(_context.t1, _context.t6, _context.t8);
|
|
2447
|
-
_context.t10 = {
|
|
2448
|
-
session: session,
|
|
2449
|
-
user: user,
|
|
2450
|
-
tenants: tenants,
|
|
2451
|
-
envAppUrl: envAppUrl,
|
|
2452
|
-
envBaseUrl: process.env['FRONTEGG_BASE_URL'],
|
|
2453
|
-
envClientId: process.env['FRONTEGG_CLIENT_ID']
|
|
2454
|
-
};
|
|
2455
|
-
_context.t11 = _context.t0.assign.call(_context.t0, _context.t9, _context.t10);
|
|
2456
|
-
return _context.abrupt("return", {
|
|
2457
|
-
pageProps: _context.t11
|
|
2458
|
-
});
|
|
2459
|
-
|
|
2460
|
-
case 47:
|
|
2461
|
-
appContext.session = null;
|
|
2462
|
-
_context.t12 = Object;
|
|
2463
|
-
_context.t13 = Object;
|
|
2464
|
-
_context.t14 = {};
|
|
2465
|
-
|
|
2466
|
-
if (!originalGetInitialProps) {
|
|
2467
|
-
_context.next = 57;
|
|
2468
|
-
break;
|
|
2469
|
-
}
|
|
2470
|
-
|
|
2471
|
-
_context.next = 54;
|
|
2472
|
-
return originalGetInitialProps(appContext);
|
|
2473
|
-
|
|
2474
|
-
case 54:
|
|
2475
|
-
_context.t15 = _context.sent;
|
|
2476
|
-
_context.next = 58;
|
|
2477
|
-
break;
|
|
2478
|
-
|
|
2479
|
-
case 57:
|
|
2480
|
-
_context.t15 = {};
|
|
2481
|
-
|
|
2482
|
-
case 58:
|
|
2483
|
-
_context.t16 = _context.t15;
|
|
2484
|
-
_context.t17 = _context.t13.assign.call(_context.t13, _context.t14, _context.t16);
|
|
2485
|
-
|
|
2486
|
-
if (!Component.getInitialProps) {
|
|
2487
|
-
_context.next = 66;
|
|
2488
|
-
break;
|
|
2489
|
-
}
|
|
2490
|
-
|
|
2491
|
-
_context.next = 63;
|
|
2492
|
-
return Component.getInitialProps(ctx);
|
|
2493
|
-
|
|
2494
|
-
case 63:
|
|
2495
|
-
_context.t18 = _context.sent;
|
|
2496
|
-
_context.next = 67;
|
|
2497
|
-
break;
|
|
2498
|
-
|
|
2499
|
-
case 66:
|
|
2500
|
-
_context.t18 = {};
|
|
2501
|
-
|
|
2502
|
-
case 67:
|
|
2503
|
-
_context.t19 = _context.t18;
|
|
2504
|
-
_context.t20 = _context.t12.assign.call(_context.t12, _context.t17, _context.t19);
|
|
2505
|
-
return _context.abrupt("return", {
|
|
2506
|
-
pageProps: _context.t20
|
|
2507
|
-
});
|
|
2508
|
-
|
|
2509
|
-
case 70:
|
|
2510
|
-
case "end":
|
|
2511
|
-
return _context.stop();
|
|
2512
|
-
}
|
|
2513
|
-
}
|
|
2514
|
-
}, _callee);
|
|
2515
|
-
}));
|
|
2516
|
-
};
|
|
2517
|
-
|
|
2518
|
-
fronteggConfig.authRoutes = (_b = (_a = options === null || options === void 0 ? void 0 : options.authOptions) === null || _a === void 0 ? void 0 : _a.routes) !== null && _b !== void 0 ? _b : {};
|
|
2519
|
-
fronteggConfig.fronteggAppOptions = options !== null && options !== void 0 ? options : {};
|
|
2520
|
-
|
|
2521
|
-
function CustomFronteggApp(appProps) {
|
|
2522
|
-
var _appProps$pageProps = appProps.pageProps,
|
|
2523
|
-
user = _appProps$pageProps.user,
|
|
2524
|
-
tenants = _appProps$pageProps.tenants,
|
|
2525
|
-
session = _appProps$pageProps.session,
|
|
2526
|
-
envAppUrl = _appProps$pageProps.envAppUrl,
|
|
2527
|
-
envBaseUrl = _appProps$pageProps.envBaseUrl,
|
|
2528
|
-
envClientId = _appProps$pageProps.envClientId;
|
|
2529
|
-
return jsxRuntime.jsx(FronteggProvider, Object.assign({}, options, {
|
|
2530
|
-
user: user,
|
|
2531
|
-
tenants: tenants,
|
|
2532
|
-
session: session,
|
|
2533
|
-
envAppUrl: envAppUrl,
|
|
2534
|
-
envBaseUrl: envBaseUrl,
|
|
2535
|
-
envClientId: envClientId
|
|
2536
|
-
}, {
|
|
2537
|
-
children: app(appProps)
|
|
2538
|
-
}));
|
|
2539
|
-
}
|
|
2540
|
-
|
|
2541
|
-
CustomFronteggApp.getInitialProps = app.getInitialProps;
|
|
2542
|
-
return CustomFronteggApp;
|
|
2543
|
-
};
|
|
2544
|
-
|
|
2545
|
-
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; }
|
|
2546
|
-
|
|
2547
|
-
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
2548
|
-
|
|
2549
|
-
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
|
|
2550
|
-
/**
|
|
2551
|
-
* @see https://www.npmjs.com/package/http-proxy
|
|
2552
|
-
*/
|
|
2553
|
-
|
|
2554
|
-
var proxy = httpProxy__default["default"].createProxyServer({
|
|
2555
|
-
target: process.env['FRONTEGG_BASE_URL']
|
|
2556
|
-
});
|
|
2557
|
-
/**
|
|
2558
|
-
* Please refer to the following links for the specification document for HTTP.
|
|
2559
|
-
* @see https://tools.ietf.org/html/rfc7231
|
|
2560
|
-
* @see https://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol
|
|
2561
|
-
*/
|
|
2562
|
-
|
|
2563
|
-
var hasRequestBodyMethods = ['HEAD', 'POST', 'PUT', 'DELETE', 'CONNECT', 'OPTIONS', 'PATCH'];
|
|
2564
|
-
/**
|
|
2565
|
-
* If pattern information matching the input url information is found in the `pathRewrite` array,
|
|
2566
|
-
* the url value is partially replaced with the `pathRewrite.replaceStr` value.
|
|
2567
|
-
* @param url
|
|
2568
|
-
* @param pathRewrite
|
|
2569
|
-
*/
|
|
2570
|
-
|
|
2571
|
-
var rewritePath = function rewritePath(url, pathRewrite) {
|
|
2572
|
-
if (Array.isArray(pathRewrite)) {
|
|
2573
|
-
var _iterator = _createForOfIteratorHelper(pathRewrite),
|
|
2574
|
-
_step;
|
|
2575
|
-
|
|
2576
|
-
try {
|
|
2577
|
-
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
2578
|
-
var item = _step.value;
|
|
2579
|
-
var patternStr = item.patternStr,
|
|
2580
|
-
replaceStr = item.replaceStr;
|
|
2581
|
-
var pattern = RegExp(patternStr);
|
|
2582
|
-
|
|
2583
|
-
if (pattern.test(url)) {
|
|
2584
|
-
return url.replace(pattern, replaceStr);
|
|
2585
|
-
}
|
|
2586
|
-
}
|
|
2587
|
-
} catch (err) {
|
|
2588
|
-
_iterator.e(err);
|
|
2589
|
-
} finally {
|
|
2590
|
-
_iterator.f();
|
|
2591
|
-
}
|
|
2592
|
-
} else {
|
|
2593
|
-
// tslint:disable-next-line:forin
|
|
2594
|
-
for (var _patternStr in pathRewrite) {
|
|
2595
|
-
var _pattern = RegExp(_patternStr);
|
|
2596
|
-
|
|
2597
|
-
var path = pathRewrite[_patternStr];
|
|
2598
|
-
|
|
2599
|
-
if (_pattern.test(url)) {
|
|
2600
|
-
return url.replace(_pattern, path);
|
|
2601
|
-
}
|
|
2602
|
-
}
|
|
2603
|
-
}
|
|
2604
|
-
|
|
2605
|
-
return url;
|
|
2606
|
-
};
|
|
2607
|
-
/**
|
|
2608
|
-
* Next.js HTTP Proxy Middleware
|
|
2609
|
-
* @see https://nextjs.org/docs/api-routes/api-middlewares
|
|
2610
|
-
* @param {NextApiRequest} req
|
|
2611
|
-
* @param {NextApiResponse} res
|
|
2612
|
-
*/
|
|
2613
|
-
|
|
2614
|
-
function fronteggMiddleware(req, res) {
|
|
2615
|
-
var _this = this;
|
|
2616
|
-
|
|
2617
|
-
return new Promise(function (resolve, reject) {
|
|
2618
|
-
var pathRewrite = [{
|
|
2619
|
-
patternStr: '^/api/',
|
|
2620
|
-
replaceStr: '/'
|
|
2621
|
-
}];
|
|
2622
|
-
|
|
2623
|
-
if (pathRewrite) {
|
|
2624
|
-
req.url = rewritePath(req.url, pathRewrite);
|
|
2625
|
-
}
|
|
2626
|
-
|
|
2627
|
-
if (hasRequestBodyMethods.indexOf(req.method) >= 0 && typeof req.body === 'object') {
|
|
2628
|
-
req.body = JSON.stringify(req.body);
|
|
2629
|
-
}
|
|
2630
|
-
|
|
2631
|
-
var isSecured = new URL(fronteggConfig.appUrl).protocol === 'https:';
|
|
2632
|
-
proxy.once('proxyReq', function (proxyReq, req) {
|
|
2633
|
-
if (hasRequestBodyMethods.indexOf(req.method) >= 0 && typeof req.body === 'string') {
|
|
2634
|
-
proxyReq.write(req.body);
|
|
2635
|
-
proxyReq.end();
|
|
2636
|
-
}
|
|
2637
|
-
}).once('proxyRes', function (proxyRes, req, serverResponse) {
|
|
2638
|
-
proxyRes.headers['set-cookie'] = modifySetCookieIfUnsecure(proxyRes.headers['set-cookie'], isSecured);
|
|
2639
|
-
var _end = res.end;
|
|
2640
|
-
var buffer = new Buffer('');
|
|
2641
|
-
proxyRes.on('data', function (chunk) {
|
|
2642
|
-
buffer = Buffer.concat([buffer, chunk]);
|
|
2643
|
-
}).on('end', function () {
|
|
2644
|
-
return __awaiter(_this, void 0, void 0, /*#__PURE__*/regenerator.mark(function _callee() {
|
|
2645
|
-
var _a, _b, output, isLogout, _yield$createSessionF, _yield$createSessionF2, session, decodedJwt, sessionCookie;
|
|
2646
|
-
|
|
2647
|
-
return regenerator.wrap(function _callee$(_context) {
|
|
2648
|
-
while (1) {
|
|
2649
|
-
switch (_context.prev = _context.next) {
|
|
2650
|
-
case 0:
|
|
2651
|
-
output = buffer.toString('utf-8');
|
|
2652
|
-
isLogout = (_a = req === null || req === void 0 ? void 0 : req.url) === null || _a === void 0 ? void 0 : _a.endsWith((_b = restApi.fronteggAuthApiRoutes.find(function (path) {
|
|
2653
|
-
return path.endsWith('/logout');
|
|
2654
|
-
})) !== null && _b !== void 0 ? _b : '/logout');
|
|
2655
|
-
|
|
2656
|
-
if (!isLogout) {
|
|
2657
|
-
_context.next = 6;
|
|
2658
|
-
break;
|
|
2659
|
-
}
|
|
2660
|
-
|
|
2661
|
-
removeCookies(fronteggConfig.cookieName, isSecured, fronteggConfig.cookieDomain, serverResponse);
|
|
2662
|
-
_context.next = 13;
|
|
2663
|
-
break;
|
|
2664
|
-
|
|
2665
|
-
case 6:
|
|
2666
|
-
_context.next = 8;
|
|
2667
|
-
return createSessionFromAccessToken(output);
|
|
2668
|
-
|
|
2669
|
-
case 8:
|
|
2670
|
-
_yield$createSessionF = _context.sent;
|
|
2671
|
-
_yield$createSessionF2 = _slicedToArray(_yield$createSessionF, 2);
|
|
2672
|
-
session = _yield$createSessionF2[0];
|
|
2673
|
-
decodedJwt = _yield$createSessionF2[1];
|
|
2674
|
-
|
|
2675
|
-
if (session) {
|
|
2676
|
-
sessionCookie = createCookie({
|
|
2677
|
-
session: session,
|
|
2678
|
-
expires: new Date(decodedJwt.exp * 1000),
|
|
2679
|
-
isSecured: isSecured
|
|
2680
|
-
});
|
|
2681
|
-
addToCookies(sessionCookie, serverResponse);
|
|
2682
|
-
}
|
|
2683
|
-
|
|
2684
|
-
case 13:
|
|
2685
|
-
res.setHeader('content-length', output.length);
|
|
2686
|
-
res.setHeader('content-encoding', ''); // @ts-ignore
|
|
2687
|
-
|
|
2688
|
-
_end.apply(res, [output]);
|
|
2689
|
-
|
|
2690
|
-
case 16:
|
|
2691
|
-
case "end":
|
|
2692
|
-
return _context.stop();
|
|
2693
|
-
}
|
|
2694
|
-
}
|
|
2695
|
-
}, _callee);
|
|
2696
|
-
}));
|
|
2697
|
-
}); // disable default behavior to read jwt
|
|
2698
|
-
// @ts-ignore
|
|
2699
|
-
|
|
2700
|
-
serverResponse.write = function () {
|
|
2701
|
-
return undefined;
|
|
2702
|
-
}; // @ts-ignore
|
|
2703
|
-
|
|
2704
|
-
|
|
2705
|
-
serverResponse.end = function () {
|
|
2706
|
-
return undefined;
|
|
2707
|
-
};
|
|
2708
|
-
}).once('error', reject).web(req, res, {
|
|
2709
|
-
changeOrigin: true,
|
|
2710
|
-
cookieDomainRewrite: _defineProperty({}, fronteggConfig.baseUrlHost, fronteggConfig.cookieDomain) // ...serverOptions
|
|
2711
|
-
|
|
2712
|
-
});
|
|
2713
|
-
});
|
|
2714
|
-
}
|
|
2715
|
-
|
|
2716
|
-
Object.defineProperty(exports, 'AdminPortal', {
|
|
2717
|
-
enumerable: true,
|
|
2718
|
-
get: function () { return js.AdminPortal; }
|
|
2719
|
-
});
|
|
2720
|
-
Object.defineProperty(exports, 'ContextHolder', {
|
|
2721
|
-
enumerable: true,
|
|
2722
|
-
get: function () { return restApi.ContextHolder; }
|
|
2723
|
-
});
|
|
2724
|
-
exports.AuthorizedContent = AuthorizedContent;
|
|
2725
|
-
exports.FronteggConfig = fronteggConfig;
|
|
2726
|
-
exports.FronteggProvider = FronteggProvider;
|
|
2727
|
-
exports.FronteggProviderNoSSR = FronteggProviderNoSSR;
|
|
2728
|
-
exports.FronteggRouter = FronteggRouter;
|
|
2729
|
-
exports.FronteggRouterProps = FronteggRouterProps;
|
|
2730
|
-
exports.fronteggMiddleware = fronteggMiddleware;
|
|
2731
|
-
exports.getHostedLoginRefreshToken = getHostedLoginRefreshToken;
|
|
2732
|
-
exports.getSession = getSession;
|
|
2733
|
-
exports.rewritePath = rewritePath;
|
|
2734
|
-
exports.withFronteggApp = withFronteggApp;
|
|
2735
|
-
exports.withSSRSession = withSSRSession;
|
|
2736
|
-
Object.keys(reactHooks).forEach(function (k) {
|
|
2737
|
-
if (k !== 'default' && !exports.hasOwnProperty(k)) Object.defineProperty(exports, k, {
|
|
2738
|
-
enumerable: true,
|
|
2739
|
-
get: function () { return reactHooks[k]; }
|
|
2740
|
-
});
|
|
2741
|
-
});
|
|
2742
|
-
Object.keys(types).forEach(function (k) {
|
|
2743
|
-
if (k !== 'default' && !exports.hasOwnProperty(k)) Object.defineProperty(exports, k, {
|
|
2744
|
-
enumerable: true,
|
|
2745
|
-
get: function () { return types[k]; }
|
|
2746
|
-
});
|
|
2747
|
-
});
|