@frontegg/nextjs 6.7.13 → 6.7.14
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/{CookieManager-0b48b7ab.js → CookieManager-09a8df0d.js} +3 -3
- package/CookieManager-09a8df0d.js.map +1 -0
- package/client/index.js +1 -1
- package/common/index.js +3 -3
- package/{createGetSession-ba9eb34d.js → createGetSession-59d7e8fc.js} +2 -2
- package/createGetSession-59d7e8fc.js.map +1 -0
- package/edge/index.js +2 -2
- package/{helpers-52cd4d67.js → helpers-d1972132.js} +2 -2
- package/helpers-d1972132.js.map +1 -0
- package/index.js +102 -96
- package/package.json +1 -1
- package/server/index.js +3 -3
- package/CookieManager-0b48b7ab.js.map +0 -1
- package/createGetSession-ba9eb34d.js.map +0 -1
- package/helpers-52cd4d67.js.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
# Change Log
|
|
2
2
|
|
|
3
|
+
## [6.7.14](https://github.com/frontegg/frontegg-nextjs/compare/v6.7.13...v6.7.14) (2023-2-1)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### NextJS Wrapper 6.7.14:
|
|
7
|
+
- FR-10557 - Create proxy single request handler instead of handler per request
|
|
8
|
+
|
|
3
9
|
## [6.7.13](https://github.com/frontegg/frontegg-nextjs/compare/v6.7.12...v6.7.13) (2023-1-31)
|
|
4
10
|
|
|
5
11
|
|
|
@@ -201,14 +201,14 @@ var CookieManager = /** @class */ (function () {
|
|
|
201
201
|
if (!isSecured) {
|
|
202
202
|
cookie = cookie.filter(function (property) { return property !== 'Secure' && property !== 'SameSite=None'; });
|
|
203
203
|
}
|
|
204
|
-
return cookie
|
|
204
|
+
return (cookie
|
|
205
205
|
.map(function (property) {
|
|
206
206
|
if (property.toLowerCase() === "domain=".concat(FronteggConfig$1.baseUrlHost)) {
|
|
207
207
|
return "Domain=".concat(FronteggConfig$1.cookieDomain);
|
|
208
208
|
}
|
|
209
209
|
return property;
|
|
210
210
|
})
|
|
211
|
-
.join(';');
|
|
211
|
+
.join(';') + ';');
|
|
212
212
|
});
|
|
213
213
|
}
|
|
214
214
|
return setCookieValue;
|
|
@@ -319,4 +319,4 @@ var CookieManager = /** @class */ (function () {
|
|
|
319
319
|
var CookieManager$1 = new CookieManager();
|
|
320
320
|
|
|
321
321
|
export { CookieManager$1 as C, FronteggConfig$1 as F, COOKIE_MAX_LENGTH as a, fronteggErrors as f };
|
|
322
|
-
//# sourceMappingURL=CookieManager-
|
|
322
|
+
//# sourceMappingURL=CookieManager-09a8df0d.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CookieManager-09a8df0d.js","sources":[],"sourcesContent":[],"names":[],"mappings":""}
|
package/client/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
import { __assign, __spreadArray } from 'tslib';
|
|
3
|
-
import { F as FronteggConfig } from '../CookieManager-
|
|
3
|
+
import { F as FronteggConfig } from '../CookieManager-09a8df0d.js';
|
|
4
4
|
import 'iron-session';
|
|
5
5
|
import 'jose';
|
|
6
6
|
import '../api-25516652.js';
|
package/common/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export { a as COOKIE_MAX_LENGTH, C as CookieManager, F as FronteggConfig, f as fronteggErrors } from '../CookieManager-
|
|
2
|
-
export { c as createSessionFromAccessToken, a as getAllUserData, g as getTokensFromCookie } from '../helpers-
|
|
3
|
-
export { c as createGetSession } from '../createGetSession-
|
|
1
|
+
export { a as COOKIE_MAX_LENGTH, C as CookieManager, F as FronteggConfig, f as fronteggErrors } from '../CookieManager-09a8df0d.js';
|
|
2
|
+
export { c as createSessionFromAccessToken, a as getAllUserData, g as getTokensFromCookie } from '../helpers-d1972132.js';
|
|
3
|
+
export { c as createGetSession } from '../createGetSession-59d7e8fc.js';
|
|
4
4
|
import 'tslib';
|
|
5
5
|
import 'cookie';
|
|
6
6
|
import 'jose';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { __awaiter, __generator } from 'tslib';
|
|
2
2
|
import { jwtVerify } from 'jose';
|
|
3
|
-
import { F as FronteggConfig } from './CookieManager-
|
|
3
|
+
import { F as FronteggConfig } from './CookieManager-09a8df0d.js';
|
|
4
4
|
|
|
5
5
|
var createGetSession = function (_a) {
|
|
6
6
|
var getCookie = _a.getCookie, cookieResolver = _a.cookieResolver;
|
|
@@ -47,4 +47,4 @@ var createGetSession = function (_a) {
|
|
|
47
47
|
};
|
|
48
48
|
|
|
49
49
|
export { createGetSession as c };
|
|
50
|
-
//# sourceMappingURL=createGetSession-
|
|
50
|
+
//# sourceMappingURL=createGetSession-59d7e8fc.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createGetSession-59d7e8fc.js","sources":[],"sourcesContent":[],"names":[],"mappings":""}
|
package/edge/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { __awaiter, __generator } from 'tslib';
|
|
2
2
|
import { unsealData } from 'iron-session/edge';
|
|
3
|
-
import { C as CookieManager, F as FronteggConfig } from '../CookieManager-
|
|
4
|
-
import { c as createGetSession } from '../createGetSession-
|
|
3
|
+
import { C as CookieManager, F as FronteggConfig } from '../CookieManager-09a8df0d.js';
|
|
4
|
+
import { c as createGetSession } from '../createGetSession-59d7e8fc.js';
|
|
5
5
|
import 'cookie';
|
|
6
6
|
import 'jose';
|
|
7
7
|
|
|
@@ -4,7 +4,7 @@ import { jwtVerify } from 'jose';
|
|
|
4
4
|
import { g as getUsers, a as getTenants } from './api-25516652.js';
|
|
5
5
|
import 'react';
|
|
6
6
|
import '@frontegg/react-hooks';
|
|
7
|
-
import { F as FronteggConfig } from './CookieManager-
|
|
7
|
+
import { F as FronteggConfig } from './CookieManager-09a8df0d.js';
|
|
8
8
|
|
|
9
9
|
var calculateExpiresInFromExp = function (exp) { return Math.floor((exp * 1000 - Date.now()) / 1000); };
|
|
10
10
|
|
|
@@ -87,4 +87,4 @@ var getAllUserData = function (_a) {
|
|
|
87
87
|
};
|
|
88
88
|
|
|
89
89
|
export { getAllUserData as a, createSessionFromAccessToken as c, getTokensFromCookie as g };
|
|
90
|
-
//# sourceMappingURL=helpers-
|
|
90
|
+
//# sourceMappingURL=helpers-d1972132.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"helpers-d1972132.js","sources":[],"sourcesContent":[],"names":[],"mappings":""}
|
package/index.js
CHANGED
|
@@ -599,14 +599,14 @@ var CookieManager = /** @class */ (function () {
|
|
|
599
599
|
if (!isSecured) {
|
|
600
600
|
cookie = cookie.filter(function (property) { return property !== 'Secure' && property !== 'SameSite=None'; });
|
|
601
601
|
}
|
|
602
|
-
return cookie
|
|
602
|
+
return (cookie
|
|
603
603
|
.map(function (property) {
|
|
604
604
|
if (property.toLowerCase() === "domain=".concat(fronteggConfig.baseUrlHost)) {
|
|
605
605
|
return "Domain=".concat(fronteggConfig.cookieDomain);
|
|
606
606
|
}
|
|
607
607
|
return property;
|
|
608
608
|
})
|
|
609
|
-
.join(';');
|
|
609
|
+
.join(';') + ';');
|
|
610
610
|
});
|
|
611
611
|
}
|
|
612
612
|
return setCookieValue;
|
|
@@ -1079,6 +1079,104 @@ var FronteggProxy = httpProxy__default["default"].createProxyServer({
|
|
|
1079
1079
|
autoRewrite: false,
|
|
1080
1080
|
followRedirects: true,
|
|
1081
1081
|
});
|
|
1082
|
+
var proxyReqCallback = function (proxyReq, req) {
|
|
1083
|
+
try {
|
|
1084
|
+
if (req.body) {
|
|
1085
|
+
var bodyData = JSON.stringify(req.body);
|
|
1086
|
+
// in case if content-type is application/x-www-form-urlencoded -> we need to change to application/json
|
|
1087
|
+
proxyReq.setHeader('Content-Type', 'application/json');
|
|
1088
|
+
proxyReq.setHeader('Content-Length', Buffer.byteLength(bodyData));
|
|
1089
|
+
// stream the content
|
|
1090
|
+
proxyReq.write(bodyData);
|
|
1091
|
+
}
|
|
1092
|
+
}
|
|
1093
|
+
catch (e) {
|
|
1094
|
+
console.error("once('proxyReq'), ERROR", e);
|
|
1095
|
+
}
|
|
1096
|
+
};
|
|
1097
|
+
/**
|
|
1098
|
+
* Set proxy request callback handler
|
|
1099
|
+
*/
|
|
1100
|
+
// @ts-ignore
|
|
1101
|
+
FronteggProxy.on('proxyReq', proxyReqCallback);
|
|
1102
|
+
var proxyResCallback = function (proxyRes, req, res) {
|
|
1103
|
+
var buffer = new Buffer('');
|
|
1104
|
+
var totalLength = 0;
|
|
1105
|
+
var isSecured = new URL(fronteggConfig.appUrl).protocol === 'https:';
|
|
1106
|
+
proxyRes.on('data', function (chunk) {
|
|
1107
|
+
totalLength += chunk.length;
|
|
1108
|
+
buffer = Buffer.concat([buffer, chunk], totalLength);
|
|
1109
|
+
});
|
|
1110
|
+
proxyRes.on('end', function () { return tslib.__awaiter(void 0, void 0, void 0, function () {
|
|
1111
|
+
var url, statusCode, isSuccess, bodyStr, isLogout, cookies, body, _a, session, decodedJwt, sessionCookie, e_1, e_2;
|
|
1112
|
+
var _b, _c;
|
|
1113
|
+
return tslib.__generator(this, function (_d) {
|
|
1114
|
+
switch (_d.label) {
|
|
1115
|
+
case 0:
|
|
1116
|
+
_d.trys.push([0, 7, , 8]);
|
|
1117
|
+
url = req.url;
|
|
1118
|
+
statusCode = (_b = proxyRes.statusCode) !== null && _b !== void 0 ? _b : 500;
|
|
1119
|
+
isSuccess = statusCode >= 200 && statusCode < 300;
|
|
1120
|
+
bodyStr = buffer.toString('utf-8');
|
|
1121
|
+
isLogout = isFronteggLogoutUrl(url);
|
|
1122
|
+
if (isLogout) {
|
|
1123
|
+
CookieManager$1.removeCookies({
|
|
1124
|
+
isSecured: isSecured,
|
|
1125
|
+
cookieDomain: fronteggConfig.cookieDomain,
|
|
1126
|
+
res: res,
|
|
1127
|
+
req: req,
|
|
1128
|
+
});
|
|
1129
|
+
res.status(statusCode).end(bodyStr);
|
|
1130
|
+
return [2 /*return*/];
|
|
1131
|
+
}
|
|
1132
|
+
if (!isSuccess) return [3 /*break*/, 5];
|
|
1133
|
+
cookies = (_c = CookieManager$1.modifySetCookie(proxyRes.headers['set-cookie'], isSecured)) !== null && _c !== void 0 ? _c : [];
|
|
1134
|
+
_d.label = 1;
|
|
1135
|
+
case 1:
|
|
1136
|
+
_d.trys.push([1, 3, , 4]);
|
|
1137
|
+
body = JSON.parse(bodyStr);
|
|
1138
|
+
return [4 /*yield*/, createSessionFromAccessToken(body)];
|
|
1139
|
+
case 2:
|
|
1140
|
+
_a = _d.sent(), session = _a[0], decodedJwt = _a[1];
|
|
1141
|
+
if (session) {
|
|
1142
|
+
sessionCookie = CookieManager$1.createCookie({
|
|
1143
|
+
value: session,
|
|
1144
|
+
expires: new Date(decodedJwt.exp * 1000),
|
|
1145
|
+
isSecured: isSecured,
|
|
1146
|
+
});
|
|
1147
|
+
cookies.push.apply(cookies, sessionCookie);
|
|
1148
|
+
}
|
|
1149
|
+
return [3 /*break*/, 4];
|
|
1150
|
+
case 3:
|
|
1151
|
+
e_1 = _d.sent();
|
|
1152
|
+
if (bodyStr !== '') {
|
|
1153
|
+
console.error('[ERROR] FronteggMiddleware', 'proxy failed to parse response body', bodyStr, e_1);
|
|
1154
|
+
}
|
|
1155
|
+
return [3 /*break*/, 4];
|
|
1156
|
+
case 4:
|
|
1157
|
+
res.setHeader('set-cookie', cookies);
|
|
1158
|
+
res.status(statusCode).end(bodyStr);
|
|
1159
|
+
return [3 /*break*/, 6];
|
|
1160
|
+
case 5:
|
|
1161
|
+
console.error('[ERROR] FronteggMiddleware', { url: url, statusCode: statusCode, bodyStr: bodyStr });
|
|
1162
|
+
res.status(statusCode).end(bodyStr);
|
|
1163
|
+
_d.label = 6;
|
|
1164
|
+
case 6: return [3 /*break*/, 8];
|
|
1165
|
+
case 7:
|
|
1166
|
+
e_2 = _d.sent();
|
|
1167
|
+
console.error('[ERROR] FronteggMiddleware', 'proxy failed to send request', e_2);
|
|
1168
|
+
res.status(500).end('Internal Server Error');
|
|
1169
|
+
return [3 /*break*/, 8];
|
|
1170
|
+
case 8: return [2 /*return*/];
|
|
1171
|
+
}
|
|
1172
|
+
});
|
|
1173
|
+
}); });
|
|
1174
|
+
};
|
|
1175
|
+
/**
|
|
1176
|
+
* Set proxy resonse callback handler
|
|
1177
|
+
*/
|
|
1178
|
+
// @ts-ignore
|
|
1179
|
+
FronteggProxy.on('proxyRes', proxyResCallback);
|
|
1082
1180
|
/**
|
|
1083
1181
|
* If pattern information matching the input url information is found in the `pathRewrite` array,
|
|
1084
1182
|
* the url value is partially replaced with the `pathRewrite.replaceStr` value.
|
|
@@ -1129,100 +1227,8 @@ var middlewarePromise = function (req, res) {
|
|
|
1129
1227
|
return new Promise(function (resolve) {
|
|
1130
1228
|
var _a;
|
|
1131
1229
|
req.url = rewritePath((_a = req.url) !== null && _a !== void 0 ? _a : '/', fronteggPathRewrite);
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
FronteggProxy.once('proxyReq', function (proxyReq, req) {
|
|
1135
|
-
try {
|
|
1136
|
-
if (req.body) {
|
|
1137
|
-
var bodyData = JSON.stringify(req.body);
|
|
1138
|
-
// in case if content-type is application/x-www-form-urlencoded -> we need to change to application/json
|
|
1139
|
-
proxyReq.setHeader('Content-Type', 'application/json');
|
|
1140
|
-
proxyReq.setHeader('Content-Length', Buffer.byteLength(bodyData));
|
|
1141
|
-
// stream the content
|
|
1142
|
-
proxyReq.write(bodyData);
|
|
1143
|
-
}
|
|
1144
|
-
}
|
|
1145
|
-
catch (e) {
|
|
1146
|
-
console.error("once('proxyReq'), ERROR", e);
|
|
1147
|
-
}
|
|
1148
|
-
})
|
|
1149
|
-
.once('proxyRes', function (proxyRes, req) {
|
|
1150
|
-
var buffer = new Buffer('');
|
|
1151
|
-
var totalLength = 0;
|
|
1152
|
-
proxyRes.on('data', function (chunk) {
|
|
1153
|
-
totalLength += chunk.length;
|
|
1154
|
-
buffer = Buffer.concat([buffer, chunk], totalLength);
|
|
1155
|
-
});
|
|
1156
|
-
proxyRes.on('end', function () { return tslib.__awaiter(void 0, void 0, void 0, function () {
|
|
1157
|
-
var url, statusCode, isSuccess, bodyStr, isLogout, cookies, body, _a, session, decodedJwt, sessionCookie, e_1, e_2;
|
|
1158
|
-
var _b, _c;
|
|
1159
|
-
return tslib.__generator(this, function (_d) {
|
|
1160
|
-
switch (_d.label) {
|
|
1161
|
-
case 0:
|
|
1162
|
-
_d.trys.push([0, 7, , 8]);
|
|
1163
|
-
url = req.url;
|
|
1164
|
-
statusCode = (_b = proxyRes.statusCode) !== null && _b !== void 0 ? _b : 500;
|
|
1165
|
-
isSuccess = statusCode >= 200 && statusCode < 300;
|
|
1166
|
-
bodyStr = buffer.toString('utf-8');
|
|
1167
|
-
isLogout = isFronteggLogoutUrl(url);
|
|
1168
|
-
if (isLogout) {
|
|
1169
|
-
CookieManager$1.removeCookies({
|
|
1170
|
-
isSecured: isSecured,
|
|
1171
|
-
cookieDomain: fronteggConfig.cookieDomain,
|
|
1172
|
-
res: res,
|
|
1173
|
-
req: req,
|
|
1174
|
-
});
|
|
1175
|
-
res.status(statusCode).end(bodyStr);
|
|
1176
|
-
resolve();
|
|
1177
|
-
return [2 /*return*/];
|
|
1178
|
-
}
|
|
1179
|
-
if (!isSuccess) return [3 /*break*/, 5];
|
|
1180
|
-
cookies = (_c = CookieManager$1.modifySetCookie(proxyRes.headers['set-cookie'], isSecured)) !== null && _c !== void 0 ? _c : [];
|
|
1181
|
-
_d.label = 1;
|
|
1182
|
-
case 1:
|
|
1183
|
-
_d.trys.push([1, 3, , 4]);
|
|
1184
|
-
body = JSON.parse(bodyStr);
|
|
1185
|
-
return [4 /*yield*/, createSessionFromAccessToken(body)];
|
|
1186
|
-
case 2:
|
|
1187
|
-
_a = _d.sent(), session = _a[0], decodedJwt = _a[1];
|
|
1188
|
-
if (session) {
|
|
1189
|
-
sessionCookie = CookieManager$1.createCookie({
|
|
1190
|
-
value: session,
|
|
1191
|
-
expires: new Date(decodedJwt.exp * 1000),
|
|
1192
|
-
isSecured: isSecured,
|
|
1193
|
-
});
|
|
1194
|
-
cookies.push.apply(cookies, sessionCookie);
|
|
1195
|
-
}
|
|
1196
|
-
return [3 /*break*/, 4];
|
|
1197
|
-
case 3:
|
|
1198
|
-
e_1 = _d.sent();
|
|
1199
|
-
if (bodyStr !== '') {
|
|
1200
|
-
console.error('[ERROR] FronteggMiddleware', 'proxy failed to parse response body', bodyStr, e_1);
|
|
1201
|
-
}
|
|
1202
|
-
return [3 /*break*/, 4];
|
|
1203
|
-
case 4:
|
|
1204
|
-
res.setHeader('set-cookie', cookies);
|
|
1205
|
-
res.status(statusCode).end(bodyStr);
|
|
1206
|
-
return [3 /*break*/, 6];
|
|
1207
|
-
case 5:
|
|
1208
|
-
console.error('[ERROR] FronteggMiddleware', { url: url, statusCode: statusCode, bodyStr: bodyStr });
|
|
1209
|
-
res.status(statusCode).send(bodyStr);
|
|
1210
|
-
_d.label = 6;
|
|
1211
|
-
case 6:
|
|
1212
|
-
resolve();
|
|
1213
|
-
return [3 /*break*/, 8];
|
|
1214
|
-
case 7:
|
|
1215
|
-
e_2 = _d.sent();
|
|
1216
|
-
console.error('[ERROR] FronteggMiddleware', 'proxy failed to send request', e_2);
|
|
1217
|
-
res.status(500).end('Internal Server Error');
|
|
1218
|
-
resolve();
|
|
1219
|
-
return [3 /*break*/, 8];
|
|
1220
|
-
case 8: return [2 /*return*/];
|
|
1221
|
-
}
|
|
1222
|
-
});
|
|
1223
|
-
}); });
|
|
1224
|
-
})
|
|
1225
|
-
.web(req, res, {
|
|
1230
|
+
res.on('close', function () { return resolve(); });
|
|
1231
|
+
FronteggProxy.web(req, res, {
|
|
1226
1232
|
changeOrigin: true,
|
|
1227
1233
|
selfHandleResponse: true,
|
|
1228
1234
|
});
|
package/package.json
CHANGED
package/server/index.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { __awaiter, __generator, __rest, __assign } from 'tslib';
|
|
2
2
|
import React from 'react';
|
|
3
3
|
import { cookies, headers } from 'next/headers';
|
|
4
|
-
import { C as CookieManager } from '../CookieManager-
|
|
5
|
-
import { g as getTokensFromCookie, a as getAllUserData } from '../helpers-
|
|
6
|
-
import { c as createGetSession } from '../createGetSession-
|
|
4
|
+
import { C as CookieManager } from '../CookieManager-09a8df0d.js';
|
|
5
|
+
import { g as getTokensFromCookie, a as getAllUserData } from '../helpers-d1972132.js';
|
|
6
|
+
import { c as createGetSession } from '../createGetSession-59d7e8fc.js';
|
|
7
7
|
import 'jose';
|
|
8
8
|
import '@frontegg/react-hooks';
|
|
9
9
|
import '@frontegg/rest-api';
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"CookieManager-0b48b7ab.js","sources":[],"sourcesContent":[],"names":[],"mappings":""}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"createGetSession-ba9eb34d.js","sources":[],"sourcesContent":[],"names":[],"mappings":""}
|
package/helpers-52cd4d67.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"helpers-52cd4d67.js","sources":[],"sourcesContent":[],"names":[],"mappings":""}
|