@frontegg/nextjs 6.7.9-alpha.3787429476 → 6.7.9-alpha.3787447063

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.
Files changed (43) hide show
  1. package/CHANGELOG.md +1 -0
  2. package/CookieManager-c1d6c5b0.js +303 -0
  3. package/CookieManager-c1d6c5b0.js.map +1 -0
  4. package/{FronteggClientProviderNext13-b55f477b.js → FronteggClientProviderNext13-3259fcd9.js} +4 -6
  5. package/FronteggClientProviderNext13-3259fcd9.js.map +1 -0
  6. package/FronteggProviderNoSSR.d.ts +1 -1
  7. package/{api-70f0e81e.js → api-25516652.js} +4 -4
  8. package/api-25516652.js.map +1 -0
  9. package/client/FronteggAppRouter.d.ts +1 -1
  10. package/client/index.js +11 -11
  11. package/common/CookieManager.d.ts +41 -0
  12. package/common/FronteggConfig.d.ts +2 -2
  13. package/common/client/createOrGetFronteggApp.d.ts +1 -1
  14. package/common/client/hooks/useRequestAuthorizeSSR.d.ts +1 -1
  15. package/common/{utils/createGetSession.d.ts → createGetSession.d.ts} +2 -2
  16. package/common/helpers.d.ts +0 -20
  17. package/common/index.d.ts +2 -1
  18. package/common/index.js +6 -7
  19. package/common/types.d.ts +1 -1
  20. package/common/utils.d.ts +1 -0
  21. package/{createGetSession-81b1748e.js → createGetSession-b2281638.js} +2 -2
  22. package/createGetSession-b2281638.js.map +1 -0
  23. package/edge/index.js +6 -4
  24. package/helpers-942ef431.js +81 -0
  25. package/helpers-942ef431.js.map +1 -0
  26. package/index.js +251 -195
  27. package/package.json +1 -1
  28. package/server/getSessionNext13.d.ts +1 -1
  29. package/server/index.js +7 -7
  30. package/session.d.ts +1 -1
  31. package/withFronteggApp.d.ts +6 -6
  32. package/FronteggClientProviderNext13-b55f477b.js.map +0 -1
  33. package/FronteggConfig-7ae86562.js +0 -123
  34. package/FronteggConfig-7ae86562.js.map +0 -1
  35. package/api-70f0e81e.js.map +0 -1
  36. package/common/utils/getCookieFromRequest.d.ts +0 -2
  37. package/common/utils/index.d.ts +0 -3
  38. package/common/utils/parseCookie.d.ts +0 -1
  39. package/createGetSession-81b1748e.js.map +0 -1
  40. package/getCookieFromRequest-624c37b5.js +0 -28
  41. package/getCookieFromRequest-624c37b5.js.map +0 -1
  42. package/helpers-dac4dc7b.js +0 -189
  43. package/helpers-dac4dc7b.js.map +0 -1
package/CHANGELOG.md CHANGED
@@ -5,6 +5,7 @@
5
5
 
6
6
  ### NextJS Wrapper 6.7.9:
7
7
  - FR-10166 - update code owners
8
+ - FR-10132 - split cookie and type fixes
8
9
  - FR-10106-FR-10103- Make package output both cjs and esm and support useAuthUser for SSR
9
10
 
10
11
  ## [6.7.8](https://github.com/frontegg/frontegg-nextjs/compare/v6.7.7...v6.7.8) (2022-12-20)
@@ -0,0 +1,303 @@
1
+ import { __awaiter, __generator, __spreadArray } from 'tslib';
2
+ import cookie from 'cookie';
3
+ import { importJWK } from 'jose';
4
+
5
+ function normalizeStringPasswordToMap(password) {
6
+ return typeof password === 'string' ? { 1: password } : password;
7
+ }
8
+ var FronteggConfig = /** @class */ (function () {
9
+ function FronteggConfig() {
10
+ var _a, _b, _c;
11
+ this.authRoutes = {};
12
+ this.fronteggAppOptions = {};
13
+ this._clientId = (_a = process.env['FRONTEGG_CLIENT_ID']) !== null && _a !== void 0 ? _a : '';
14
+ this._cookieName = (_b = process.env['FRONTEGG_COOKIE_NAME']) !== null && _b !== void 0 ? _b : "fe_next_session";
15
+ this._password = (_c = process.env['FRONTEGG_ENCRYPTION_PASSWORD']) !== null && _c !== void 0 ? _c : '';
16
+ this._passwordsAsMap = normalizeStringPasswordToMap(this._password);
17
+ }
18
+ Object.defineProperty(FronteggConfig.prototype, "cookieName", {
19
+ get: function () {
20
+ return "".concat(this._cookieName, "-").concat(this._clientId.replace(/-/g, ''));
21
+ },
22
+ enumerable: false,
23
+ configurable: true
24
+ });
25
+ Object.defineProperty(FronteggConfig.prototype, "password", {
26
+ get: function () {
27
+ return this._password;
28
+ },
29
+ enumerable: false,
30
+ configurable: true
31
+ });
32
+ Object.defineProperty(FronteggConfig.prototype, "clientId", {
33
+ get: function () {
34
+ return this._clientId;
35
+ },
36
+ enumerable: false,
37
+ configurable: true
38
+ });
39
+ Object.defineProperty(FronteggConfig.prototype, "baseUrlHost", {
40
+ get: function () {
41
+ var _a;
42
+ return new URL((_a = process.env['FRONTEGG_BASE_URL']) !== null && _a !== void 0 ? _a : '').hostname;
43
+ },
44
+ enumerable: false,
45
+ configurable: true
46
+ });
47
+ FronteggConfig.prototype.getEnvAppUrl = function () {
48
+ var url = undefined;
49
+ if (process.env['FRONTEGG_APP_URL']) {
50
+ url = process.env['FRONTEGG_APP_URL'];
51
+ }
52
+ else if (process.env['VERCEL'] && process.env['VERCEL_URL']) {
53
+ url = process.env['VERCEL_URL'];
54
+ }
55
+ if (url && !url.startsWith('http')) {
56
+ var protocol = url.startsWith('localhost') ? 'http://' : 'https://';
57
+ url = "".concat(protocol).concat(url);
58
+ }
59
+ return url;
60
+ };
61
+ Object.defineProperty(FronteggConfig.prototype, "appUrl", {
62
+ get: function () {
63
+ var _a;
64
+ return (_a = this.getEnvAppUrl()) !== null && _a !== void 0 ? _a : 'http://localhost:3000';
65
+ },
66
+ enumerable: false,
67
+ configurable: true
68
+ });
69
+ Object.defineProperty(FronteggConfig.prototype, "appEnvConfig", {
70
+ get: function () {
71
+ return {
72
+ envAppUrl: this.getEnvAppUrl(),
73
+ envBaseUrl: process.env['FRONTEGG_BASE_URL'],
74
+ envClientId: process.env['FRONTEGG_CLIENT_ID'],
75
+ };
76
+ },
77
+ enumerable: false,
78
+ configurable: true
79
+ });
80
+ Object.defineProperty(FronteggConfig.prototype, "cookieDomain", {
81
+ get: function () {
82
+ var _a;
83
+ return new URL((_a = this.getEnvAppUrl()) !== null && _a !== void 0 ? _a : '').hostname.replace(/:(\d)+$/, '');
84
+ },
85
+ enumerable: false,
86
+ configurable: true
87
+ });
88
+ FronteggConfig.prototype.getJwtPublicKey = function () {
89
+ return __awaiter(this, void 0, void 0, function () {
90
+ var response, data, publicKey, _a;
91
+ return __generator(this, function (_b) {
92
+ switch (_b.label) {
93
+ case 0:
94
+ if (!!this._jwtPublicKey) return [3 /*break*/, 4];
95
+ return [4 /*yield*/, fetch("".concat(process.env['FRONTEGG_BASE_URL'], "/.well-known/jwks.json"))];
96
+ case 1:
97
+ response = _b.sent();
98
+ return [4 /*yield*/, response.json()];
99
+ case 2:
100
+ data = _b.sent();
101
+ publicKey = data.keys.find(function (key) { return key.kty === 'RSA'; });
102
+ _a = this;
103
+ return [4 /*yield*/, importJWK(publicKey)];
104
+ case 3:
105
+ _a._jwtPublicKey = _b.sent();
106
+ _b.label = 4;
107
+ case 4: return [2 /*return*/, this._jwtPublicKey];
108
+ }
109
+ });
110
+ });
111
+ };
112
+ Object.defineProperty(FronteggConfig.prototype, "passwordsAsMap", {
113
+ get: function () {
114
+ return this._passwordsAsMap;
115
+ },
116
+ enumerable: false,
117
+ configurable: true
118
+ });
119
+ return FronteggConfig;
120
+ }());
121
+ var FronteggConfig$1 = new FronteggConfig();
122
+
123
+ function chunkString(str, chunkSize) {
124
+ var numChunks = Math.ceil(str.length / chunkSize);
125
+ var chunks = [];
126
+ for (var i = 0; i < numChunks; i++) {
127
+ var start = i * chunkSize;
128
+ var end = start + chunkSize;
129
+ chunks.push(str.substring(start, end < str.length ? end : str.length));
130
+ }
131
+ return chunks;
132
+ }
133
+
134
+ var COOKIE_MAX_LENGTH = 4096;
135
+ var CookieManager = /** @class */ (function () {
136
+ function CookieManager() {
137
+ var _this = this;
138
+ this.getCookieName = function (cookieNumber, cookieName) {
139
+ return "".concat(cookieName !== null && cookieName !== void 0 ? cookieName : FronteggConfig$1.cookieName, "-").concat(cookieNumber);
140
+ };
141
+ this.mapValueChunksToCookies = function (cookieName, valueChunks, options) {
142
+ return valueChunks.map(function (chunk, index) { return cookie.serialize(_this.getCookieName(index + 1, cookieName), chunk, options); });
143
+ };
144
+ this.getCookieStringFromRequest = function (req) {
145
+ return 'credentials' in req ? req.headers.get('cookie') || '' : req.headers.cookie || '';
146
+ };
147
+ this.createEmptySingleCookie = function (cookieName, isSecured, cookieDomain) {
148
+ return _this.createCookie({ cookieName: cookieName, value: '', expires: new Date(), isSecured: isSecured, cookieDomain: cookieDomain });
149
+ };
150
+ this.createEmptyCookies = function (isSecured, cookieDomain, cookiesToRemove) {
151
+ var allEmptyCookies = [];
152
+ cookiesToRemove.forEach(function (name) {
153
+ allEmptyCookies.push.apply(allEmptyCookies, _this.createEmptySingleCookie(name, isSecured, cookieDomain));
154
+ });
155
+ return allEmptyCookies;
156
+ };
157
+ this.getCookiesToRemove = function (req) {
158
+ if (!req) {
159
+ return [];
160
+ }
161
+ try {
162
+ var cookieStr = _this.getCookieStringFromRequest(req);
163
+ var allCookies = cookieStr && cookie.parse(cookieStr);
164
+ if (!allCookies) {
165
+ return [];
166
+ }
167
+ var cookieNumber = 1;
168
+ var cookieToRemove = [];
169
+ while (allCookies[_this.getCookieName(cookieNumber)]) {
170
+ cookieToRemove.push(_this.getCookieName(cookieNumber));
171
+ cookieNumber++;
172
+ }
173
+ return cookieToRemove;
174
+ }
175
+ catch (e) {
176
+ console.error(e);
177
+ return [];
178
+ }
179
+ };
180
+ this.modifySetCookieIfUnsecure = function (setCookieValue, isSecured) {
181
+ if (!setCookieValue) {
182
+ return setCookieValue;
183
+ }
184
+ if (setCookieValue.length > 0) {
185
+ return setCookieValue.map(function (c) {
186
+ var cookie = c.split('; ');
187
+ if (isSecured) {
188
+ return c;
189
+ }
190
+ return cookie.filter(function (property) { return property !== 'Secure' && property !== 'SameSite=None'; }).join('; ');
191
+ });
192
+ }
193
+ return setCookieValue;
194
+ };
195
+ }
196
+ CookieManager.prototype.rewriteCookieProperty = function (header, config, property) {
197
+ var _this = this;
198
+ if (Array.isArray(header)) {
199
+ return header.map(function (headerElement) {
200
+ return _this.rewriteCookieProperty(headerElement, config, property);
201
+ });
202
+ }
203
+ return header.replace(new RegExp('(;\\s*' + property + '=)([^;]+)', 'i'), function (match, prefix, previousValue) {
204
+ var newValue;
205
+ if (previousValue in config) {
206
+ newValue = config[previousValue];
207
+ }
208
+ else if ('*' in config) {
209
+ newValue = config['*'];
210
+ }
211
+ else {
212
+ // no match, return previous value
213
+ return match;
214
+ }
215
+ if (newValue) {
216
+ // replace value
217
+ return prefix + newValue;
218
+ }
219
+ else {
220
+ // remove value
221
+ return '';
222
+ }
223
+ });
224
+ };
225
+ CookieManager.prototype.createCookie = function (_a) {
226
+ var cookieName = _a.cookieName, value = _a.value, expires = _a.expires, isSecured = _a.isSecured, _b = _a.cookieDomain, cookieDomain = _b === void 0 ? FronteggConfig$1.cookieDomain : _b, _c = _a.httpOnly, httpOnly = _c === void 0 ? true : _c, _d = _a.path, path = _d === void 0 ? '/' : _d;
227
+ var options = {
228
+ expires: expires,
229
+ httpOnly: httpOnly,
230
+ domain: cookieDomain,
231
+ path: path,
232
+ sameSite: isSecured ? 'none' : undefined,
233
+ secure: isSecured,
234
+ };
235
+ var cookieValue = cookie.serialize(cookieName !== null && cookieName !== void 0 ? cookieName : this.getCookieName(1), value, options);
236
+ if (cookieValue.length < COOKIE_MAX_LENGTH) {
237
+ return [cookieValue];
238
+ }
239
+ var valueChunks = this.splitValueToChunks(cookieName, value, options);
240
+ return this.mapValueChunksToCookies(cookieName, valueChunks, options);
241
+ };
242
+ CookieManager.prototype.splitValueToChunks = function (cookieName, value, options) {
243
+ var cookieOptionLength = cookie.serialize(this.getCookieName(1, cookieName), '', options).length;
244
+ var maxValueLength = COOKIE_MAX_LENGTH - cookieOptionLength;
245
+ return chunkString(value, maxValueLength);
246
+ };
247
+ CookieManager.prototype.getParsedCookieFromRequest = function (req) {
248
+ if (!req) {
249
+ return undefined;
250
+ }
251
+ var cookieStr = this.getCookieStringFromRequest(req);
252
+ return this.parseCookie(cookieStr);
253
+ };
254
+ CookieManager.prototype.parseCookie = function (cookieStr) {
255
+ var sealFromCookies = '';
256
+ var i = 1;
257
+ while (cookie.parse(cookieStr)[this.getCookieName(i)]) {
258
+ sealFromCookies += cookie.parse(cookieStr)[this.getCookieName(i)];
259
+ i++;
260
+ }
261
+ return sealFromCookies !== '' ? sealFromCookies : undefined;
262
+ };
263
+ CookieManager.prototype.parseCookieFromArray = function (cookies) {
264
+ var userCookie = cookies.find(function (c) { return c.name === FronteggConfig$1.cookieName; });
265
+ if (userCookie) {
266
+ return userCookie.value;
267
+ }
268
+ var cookieChunks = cookies.filter(function (c) { return c.name.includes(FronteggConfig$1.cookieName); });
269
+ if (!cookieChunks) {
270
+ return undefined;
271
+ }
272
+ cookieChunks.sort(function (a, b) {
273
+ var firstCookieNumber = parseInt(a.name.slice(-1));
274
+ var secondCookieNumber = parseInt(b.name.slice(-1));
275
+ return firstCookieNumber > secondCookieNumber ? 1 : -1;
276
+ });
277
+ return cookieChunks.map(function (c) { return c.value; }).join('');
278
+ };
279
+ CookieManager.prototype.addToCookies = function (newCookies, res) {
280
+ var _a;
281
+ var existingSetCookie = (_a = res.getHeader('set-cookie')) !== null && _a !== void 0 ? _a : [];
282
+ if (typeof existingSetCookie === 'string') {
283
+ existingSetCookie = [existingSetCookie];
284
+ }
285
+ res.setHeader('set-cookie', __spreadArray(__spreadArray([], existingSetCookie, true), newCookies, true));
286
+ };
287
+ CookieManager.prototype.removeCookies = function (_a) {
288
+ var _b;
289
+ var cookieNames = _a.cookieNames, isSecured = _a.isSecured, cookieDomain = _a.cookieDomain, res = _a.res, req = _a.req;
290
+ var cookiesToRemove = this.getCookiesToRemove(req);
291
+ var cookieValue = this.createEmptyCookies(isSecured, cookieDomain, cookieNames !== null && cookieNames !== void 0 ? cookieNames : cookiesToRemove);
292
+ var existingSetCookie = (_b = res.getHeader('set-cookie')) !== null && _b !== void 0 ? _b : [];
293
+ if (typeof existingSetCookie === 'string') {
294
+ existingSetCookie = [existingSetCookie];
295
+ }
296
+ res.setHeader('set-cookie', __spreadArray(__spreadArray([], existingSetCookie, true), cookieValue, true));
297
+ };
298
+ return CookieManager;
299
+ }());
300
+ var CookieManager$1 = new CookieManager();
301
+
302
+ export { CookieManager$1 as C, FronteggConfig$1 as F };
303
+ //# sourceMappingURL=CookieManager-c1d6c5b0.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CookieManager-c1d6c5b0.js","sources":[],"sourcesContent":[],"names":[],"mappings":""}
@@ -18,7 +18,7 @@ var createOrGetFronteggApp = function (_a) {
18
18
  path.endsWith('/postlogin') ||
19
19
  path.endsWith('/prelogin') ||
20
20
  path === '/oauth/token') {
21
- return options.envAppUrl + "/api";
21
+ return "".concat(options.envAppUrl, "/api");
22
22
  }
23
23
  else {
24
24
  return options.envBaseUrl;
@@ -39,9 +39,7 @@ var createOrGetFronteggApp = function (_a) {
39
39
  createdApp.store = sharedStore;
40
40
  }
41
41
  catch (e) {
42
- createdApp = initialize(__assign(__assign({}, options), { store: sharedStore, hostedLoginBox: (_j = options.hostedLoginBox) !== null && _j !== void 0 ? _j : false, customLoginBox: (_k = options.customLoginBox) !== null && _k !== void 0 ? _k : false, basename: options.basename, authOptions: authOptions,
43
- contextOptions: contextOptions,
44
- onRedirectTo: onRedirectTo }), appName !== null && appName !== void 0 ? appName : 'default');
42
+ createdApp = initialize(__assign(__assign({}, options), { store: sharedStore, hostedLoginBox: (_j = options.hostedLoginBox) !== null && _j !== void 0 ? _j : false, customLoginBox: (_k = options.customLoginBox) !== null && _k !== void 0 ? _k : false, basename: options.basename, authOptions: authOptions, contextOptions: contextOptions, onRedirectTo: onRedirectTo }), appName !== null && appName !== void 0 ? appName : 'default');
45
43
  }
46
44
  return createdApp;
47
45
  };
@@ -85,7 +83,7 @@ var Connector = function (_a) {
85
83
  path = path.substring(baseName.length);
86
84
  }
87
85
  if (opts === null || opts === void 0 ? void 0 : opts.preserveQueryParams) {
88
- path = "" + path + window.location.search;
86
+ path = "".concat(path).concat(window.location.search);
89
87
  }
90
88
  if ((opts === null || opts === void 0 ? void 0 : opts.refresh) && !isSSR) {
91
89
  // @ts-ignore
@@ -124,4 +122,4 @@ var FronteggClientProviderNext13 = function (_a) {
124
122
  };
125
123
 
126
124
  export { AppContext as A, FronteggClientProviderNext13 as F };
127
- //# sourceMappingURL=FronteggClientProviderNext13-b55f477b.js.map
125
+ //# sourceMappingURL=FronteggClientProviderNext13-3259fcd9.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"FronteggClientProviderNext13-3259fcd9.js","sources":[],"sourcesContent":[],"names":[],"mappings":""}
@@ -1,4 +1,4 @@
1
1
  import { FronteggAppOptions } from '@frontegg/types';
2
2
  import { FC, PropsWithChildren } from 'react';
3
- export declare type FronteggProviderNoSSRProps = PropsWithChildren<FronteggAppOptions>;
3
+ export type FronteggProviderNoSSRProps = PropsWithChildren<FronteggAppOptions>;
4
4
  export declare const FronteggProviderNoSSR: FC<FronteggProviderNoSSRProps>;
@@ -1,7 +1,7 @@
1
1
  import { __awaiter, __generator } from 'tslib';
2
2
  import { fronteggUsersUrl, fronteggTenantsUrl } from '@frontegg/rest-api';
3
3
 
4
- var BASE_URL = process.env['FRONTEGG_BASE_URL'] + "/frontegg";
4
+ var BASE_URL = "".concat(process.env['FRONTEGG_BASE_URL'], "/frontegg");
5
5
  var Get = function (_a) {
6
6
  var url = _a.url, _b = _a.credentials, credentials = _b === void 0 ? 'include' : _b, headers = _a.headers;
7
7
  return fetch(url, { method: 'GET', credentials: credentials, headers: headers });
@@ -35,7 +35,7 @@ var getUsers = function (headers) { return __awaiter(void 0, void 0, void 0, fun
35
35
  var res;
36
36
  return __generator(this, function (_a) {
37
37
  switch (_a.label) {
38
- case 0: return [4 /*yield*/, Get({ url: "" + BASE_URL + fronteggUsersUrl, headers: extractHeaders(headers) })];
38
+ case 0: return [4 /*yield*/, Get({ url: "".concat(BASE_URL).concat(fronteggUsersUrl), headers: extractHeaders(headers) })];
39
39
  case 1:
40
40
  res = _a.sent();
41
41
  return [2 /*return*/, parseResponse(res)];
@@ -46,7 +46,7 @@ var getTenants = function (headers) { return __awaiter(void 0, void 0, void 0, f
46
46
  var res;
47
47
  return __generator(this, function (_a) {
48
48
  switch (_a.label) {
49
- case 0: return [4 /*yield*/, Get({ url: "" + BASE_URL + fronteggTenantsUrl, headers: extractHeaders(headers) })];
49
+ case 0: return [4 /*yield*/, Get({ url: "".concat(BASE_URL).concat(fronteggTenantsUrl), headers: extractHeaders(headers) })];
50
50
  case 1:
51
51
  res = _a.sent();
52
52
  return [2 /*return*/, parseResponse(res)];
@@ -55,4 +55,4 @@ var getTenants = function (headers) { return __awaiter(void 0, void 0, void 0, f
55
55
  }); };
56
56
 
57
57
  export { getTenants as a, getUsers as g };
58
- //# sourceMappingURL=api-70f0e81e.js.map
58
+ //# sourceMappingURL=api-25516652.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"api-25516652.js","sources":[],"sourcesContent":[],"names":[],"mappings":""}
@@ -1,6 +1,6 @@
1
1
  /// <reference types="node" />
2
2
  import { ParsedUrlQuery } from 'querystring';
3
- declare type FronteggRouterProps = {
3
+ type FronteggRouterProps = {
4
4
  params: ParsedUrlQuery & {
5
5
  'frontegg-router'?: string[];
6
6
  };
package/client/index.js CHANGED
@@ -1,31 +1,31 @@
1
1
  'use client';
2
- import { __assign, __spreadArrays } from 'tslib';
3
- import { F as FronteggConfig } from '../FronteggConfig-7ae86562.js';
4
- import '../api-70f0e81e.js';
5
- import 'cookie';
2
+ import { __assign, __spreadArray } from 'tslib';
3
+ import { F as FronteggConfig } from '../CookieManager-c1d6c5b0.js';
4
+ import '../api-25516652.js';
6
5
  import 'iron-session';
7
6
  import 'jose';
8
7
  import { useLoginWithRedirect, useLoginActions } from '@frontegg/react-hooks';
9
8
  import '@frontegg/rest-api';
10
9
  import { useContext, useEffect } from 'react';
11
- import { A as AppContext } from '../FronteggClientProviderNext13-b55f477b.js';
12
- export { F as FronteggClientProviderNext13 } from '../FronteggClientProviderNext13-b55f477b.js';
10
+ import { A as AppContext } from '../FronteggClientProviderNext13-3259fcd9.js';
11
+ export { F as FronteggClientProviderNext13 } from '../FronteggClientProviderNext13-3259fcd9.js';
13
12
  import '@frontegg/js';
14
13
  import { authInitialState } from '@frontegg/redux-store';
15
14
  import { useRouter, notFound } from 'next/navigation';
15
+ import 'cookie';
16
16
 
17
17
  function FronteggAppRouter(_a) {
18
18
  var _b = _a.params["frontegg-router"], pathArr = _b === void 0 ? [] : _b, searchParams = _a.searchParams;
19
19
  var routesObj = __assign(__assign({}, authInitialState.routes), FronteggConfig.authRoutes);
20
- var routesArr = Object.keys(routesObj).reduce(function (p, key) { return __spreadArrays(p, [routesObj[key]]); }, []);
20
+ var routesArr = Object.keys(routesObj).reduce(function (p, key) { return __spreadArray(__spreadArray([], p, true), [routesObj[key]], false); }, []);
21
21
  var app = useContext(AppContext);
22
22
  var replace = useRouter().replace;
23
23
  var loginWithRedirect = useLoginWithRedirect();
24
24
  var logout = useLoginActions().logout;
25
- var pathname = "/" + pathArr.join('/');
25
+ var pathname = "/".concat(pathArr.join('/'));
26
26
  if (!pathname || pathname.startsWith('/_next/data')) {
27
27
  var query = searchParams[Object.keys(searchParams)[0]];
28
- pathname = "/" + (Array.isArray(query) ? query.join('/') : query);
28
+ pathname = "/".concat(Array.isArray(query) ? query.join('/') : query);
29
29
  }
30
30
  if (routesArr.indexOf(pathname) === -1) {
31
31
  notFound();
@@ -43,7 +43,7 @@ function FronteggAppRouter(_a) {
43
43
  if (app.options.hostedLoginBox) {
44
44
  if (pathname === routesObj.loginUrl) {
45
45
  if (searchParams.redirectUrl) {
46
- localStorage.setItem('FRONTEGG_AFTER_AUTH_REDIRECT_URL', "" + window.location.origin + searchParams.redirectUrl);
46
+ localStorage.setItem('FRONTEGG_AFTER_AUTH_REDIRECT_URL', "".concat(window.location.origin).concat(searchParams.redirectUrl));
47
47
  }
48
48
  loginWithRedirect();
49
49
  }
@@ -51,7 +51,7 @@ function FronteggAppRouter(_a) {
51
51
  var _baseUrl = app.options.contextOptions.baseUrl;
52
52
  var baseUrl_1 = typeof _baseUrl === 'string' ? _baseUrl : _baseUrl('');
53
53
  logout(function () {
54
- window.location.href = baseUrl_1 + "/oauth/logout?post_logout_redirect_uri=" + encodeURIComponent(window.location.origin);
54
+ window.location.href = "".concat(baseUrl_1, "/oauth/logout?post_logout_redirect_uri=").concat(encodeURIComponent(window.location.origin));
55
55
  });
56
56
  }
57
57
  }
@@ -0,0 +1,41 @@
1
+ /// <reference types="node" />
2
+ import { CookieSerializeOptions } from 'cookie';
3
+ import { ServerResponse } from 'http';
4
+ import { RequestCookie } from 'next/dist/server/web/spec-extension/cookies';
5
+ import { RequestType } from './types';
6
+ type CreateCookieArguments = {
7
+ cookieName?: string;
8
+ value: string;
9
+ expires: CookieSerializeOptions['expires'];
10
+ isSecured: CookieSerializeOptions['secure'];
11
+ cookieDomain?: CookieSerializeOptions['domain'];
12
+ httpOnly?: CookieSerializeOptions['httpOnly'];
13
+ path?: CookieSerializeOptions['path'];
14
+ };
15
+ type RemoveCookiesArguments = {
16
+ cookieNames?: string[];
17
+ isSecured: boolean;
18
+ cookieDomain: string;
19
+ res: ServerResponse;
20
+ req?: RequestType;
21
+ };
22
+ declare class CookieManager {
23
+ constructor();
24
+ getCookieName: (cookieNumber: number, cookieName?: string) => string;
25
+ rewriteCookieProperty(header: string | string[], config: any, property: string): string | string[];
26
+ createCookie({ cookieName, value, expires, isSecured, cookieDomain, httpOnly, path, }: CreateCookieArguments): string[];
27
+ splitValueToChunks(cookieName: string | undefined, value: string, options: CookieSerializeOptions): string[];
28
+ mapValueChunksToCookies: (cookieName: string | undefined, valueChunks: string[], options: CookieSerializeOptions) => string[];
29
+ getCookieStringFromRequest: (req: RequestType) => string;
30
+ getParsedCookieFromRequest(req?: RequestType): string | undefined;
31
+ parseCookie(cookieStr: string): string | undefined;
32
+ parseCookieFromArray(cookies: RequestCookie[]): string | undefined;
33
+ addToCookies(newCookies: string[], res: ServerResponse): void;
34
+ createEmptySingleCookie: (cookieName: string, isSecured: boolean, cookieDomain: string) => string[];
35
+ createEmptyCookies: (isSecured: boolean, cookieDomain: string, cookiesToRemove: string[]) => string[];
36
+ getCookiesToRemove: (req?: RequestType) => string[];
37
+ removeCookies({ cookieNames, isSecured, cookieDomain, res, req }: RemoveCookiesArguments): void;
38
+ modifySetCookieIfUnsecure: (setCookieValue: string[] | undefined, isSecured: boolean) => string[] | undefined;
39
+ }
40
+ declare const _default: CookieManager;
41
+ export default _default;
@@ -2,10 +2,10 @@ import { AppEnvConfig } from './types';
2
2
  import { KeyLike } from 'jose';
3
3
  import { AuthPageRoutes } from '@frontegg/redux-store';
4
4
  import { FronteggAppOptions } from '@frontegg/types';
5
- export declare type PasswordsMap = {
5
+ export type PasswordsMap = {
6
6
  [id: string]: string;
7
7
  };
8
- export declare type Password = string | PasswordsMap;
8
+ export type Password = string | PasswordsMap;
9
9
  export declare function normalizeStringPasswordToMap(password: Password): PasswordsMap;
10
10
  declare class FronteggConfig {
11
11
  private readonly _cookieName;
@@ -1,7 +1,7 @@
1
1
  import { FronteggApp } from '@frontegg/js';
2
2
  import { AuthState } from '@frontegg/redux-store';
3
3
  import { FronteggProviderOptions, MeAndTenantsResponse } from '../types';
4
- declare type CreateOrGetFronteggAppParams = {
4
+ type CreateOrGetFronteggAppParams = {
5
5
  options: FronteggProviderOptions;
6
6
  onRedirectTo: AuthState['onRedirectTo'];
7
7
  appName?: string;
@@ -1,6 +1,6 @@
1
1
  import { FronteggApp } from '@frontegg/js';
2
2
  import { MeAndTenantsResponse } from '../../types';
3
- declare type useRequestAuthorizeSSR = {
3
+ type useRequestAuthorizeSSR = {
4
4
  app: FronteggApp;
5
5
  accessToken?: string;
6
6
  refreshToken?: string;
@@ -1,5 +1,5 @@
1
- import { FronteggNextJSSession, FronteggUserTokens } from '../types';
2
- declare type CreateGetSessionParams = {
1
+ import { FronteggNextJSSession, FronteggUserTokens } from './types';
2
+ type CreateGetSessionParams = {
3
3
  getCookie: () => string | undefined;
4
4
  cookieResolver: (cookie: string) => Promise<FronteggUserTokens | undefined>;
5
5
  };
@@ -1,23 +1,3 @@
1
- /// <reference types="node" />
2
- import { CookieSerializeOptions } from 'cookie';
3
- import { ServerResponse } from 'http';
4
- import { RequestCookie } from 'next/dist/server/web/spec-extension/cookies';
5
1
  import { FronteggUserTokens } from './types';
6
- export declare function rewriteCookieProperty(header: string | string[], config: any, property: string): string | string[];
7
- declare type CreateCookieArguments = {
8
- cookieName?: string;
9
- session: string;
10
- expires: CookieSerializeOptions['expires'];
11
- isSecured: CookieSerializeOptions['secure'];
12
- cookieDomain?: CookieSerializeOptions['domain'];
13
- httpOnly?: CookieSerializeOptions['httpOnly'];
14
- path?: CookieSerializeOptions['path'];
15
- };
16
- export declare function createCookie({ cookieName, session, expires, isSecured, cookieDomain, httpOnly, path, }: CreateCookieArguments): string[];
17
- export declare function parseCookieFromArray(cookies: RequestCookie[]): string | undefined;
18
- export declare function addToCookies(newCookies: string[], res: ServerResponse): void;
19
- export declare function removeCookies(cookieName: string, isSecured: boolean, cookieDomain: string, res: ServerResponse): void;
20
2
  export declare function createSessionFromAccessToken(output: string): Promise<[string, any, string] | []>;
21
- export declare const modifySetCookieIfUnsecure: (setCookieValue: string[] | undefined, isSecured: boolean) => string[] | undefined;
22
3
  export declare function getTokensFromCookie(cookie?: string): Promise<FronteggUserTokens | undefined>;
23
- export {};
package/common/index.d.ts CHANGED
@@ -2,5 +2,6 @@ export { default as FronteggConfig } from './FronteggConfig';
2
2
  export * from './types';
3
3
  export * from './getMeAndTenants';
4
4
  export * from './helpers';
5
- export * from './utils';
5
+ export * from './createGetSession';
6
6
  export * from './consts';
7
+ export { default as CookieManager } from './CookieManager';
package/common/index.js CHANGED
@@ -1,15 +1,14 @@
1
- export { F as FronteggConfig } from '../FronteggConfig-7ae86562.js';
2
- export { b as addToCookies, c as createCookie, e as createSessionFromAccessToken, a as getMeAndTenants, g as getTokensFromCookie, m as modifySetCookieIfUnsecure, p as parseCookieFromArray, d as removeCookies, r as rewriteCookieProperty } from '../helpers-dac4dc7b.js';
3
- export { g as getCookieFromRequest, p as parseCookie } from '../getCookieFromRequest-624c37b5.js';
4
- export { c as createGetSession } from '../createGetSession-81b1748e.js';
1
+ export { C as CookieManager, F as FronteggConfig } from '../CookieManager-c1d6c5b0.js';
2
+ export { c as createSessionFromAccessToken, a as getMeAndTenants, g as getTokensFromCookie } from '../helpers-942ef431.js';
3
+ export { c as createGetSession } from '../createGetSession-b2281638.js';
5
4
  import 'tslib';
5
+ import 'cookie';
6
6
  import 'jose';
7
- import '../api-70f0e81e.js';
7
+ import '../api-25516652.js';
8
8
  import '@frontegg/rest-api';
9
- import 'cookie';
10
9
  import 'iron-session';
11
10
 
12
- var envError = function (varName) { return "@frontegg/nextjs: .env.local must contain " + varName; };
11
+ var envError = function (varName) { return "@frontegg/nextjs: .env.local must contain ".concat(varName); };
13
12
  var fronteggErrors = {
14
13
  envAppUrl: envError('FRONTEGG_APP_URL'),
15
14
  envBaseUrl: envError('FRONTEGG_BASE_URL'),
package/common/types.d.ts CHANGED
@@ -4,7 +4,7 @@ import { IncomingMessage } from 'http';
4
4
  import { ReactNode } from 'react';
5
5
  import { AppRouterInstance } from 'next/dist/shared/lib/app-router-context';
6
6
  import { NextRouter } from 'next/router';
7
- export declare type RequestType = IncomingMessage | Request;
7
+ export type RequestType = IncomingMessage | Request;
8
8
  export interface AccountEnvironment {
9
9
  id: string;
10
10
  createdAt: string;
@@ -0,0 +1 @@
1
+ export declare function chunkString(str: string, chunkSize: number): string[];
@@ -1,6 +1,6 @@
1
1
  import { __awaiter, __generator } from 'tslib';
2
2
  import { jwtVerify } from 'jose';
3
- import { F as FronteggConfig } from './FronteggConfig-7ae86562.js';
3
+ import { F as FronteggConfig } from './CookieManager-c1d6c5b0.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-81b1748e.js.map
50
+ //# sourceMappingURL=createGetSession-b2281638.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createGetSession-b2281638.js","sources":[],"sourcesContent":[],"names":[],"mappings":""}