@frontegg/rest-api 3.0.2 → 3.0.5

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/ContextHolder.js CHANGED
@@ -44,7 +44,9 @@ export class ContextHolder {
44
44
  }
45
45
 
46
46
  static getContext() {
47
- return ContextHolder.getInstance().context ?? {
47
+ var _ContextHolder$getIns;
48
+
49
+ return (_ContextHolder$getIns = ContextHolder.getInstance().context) != null ? _ContextHolder$getIns : {
48
50
  baseUrl: window.location.href,
49
51
  tokenResolver: () => 'my-authentication-token',
50
52
  logLevel: 'error'
package/auth/index.d.ts CHANGED
@@ -243,6 +243,10 @@ export declare function signUpUser(body: ISignUpUser): Promise<ISignUpResponse>;
243
243
  * Get all current user active sessions
244
244
  */
245
245
  export declare function getCurrentUserSessions(): Promise<ISessionResponse[]>;
246
+ /**
247
+ * Get current user session
248
+ */
249
+ export declare function getCurrentUserSession(): Promise<ISessionResponse>;
246
250
  /**
247
251
  * Get session configurations
248
252
  */
package/auth/index.js CHANGED
@@ -246,6 +246,9 @@ export async function signUpUser(body) {
246
246
  export async function getCurrentUserSessions() {
247
247
  return Get(urls.identity.users.sessions.currentUser.v1);
248
248
  }
249
+ export async function getCurrentUserSession() {
250
+ return Get(`${urls.identity.users.sessions.currentUser.v1}/current`);
251
+ }
249
252
  export async function getSessionConfigurations() {
250
253
  return Get(urls.identity.users.sessions.configurations.v1);
251
254
  }
@@ -322,9 +322,10 @@ export interface ISSOConfiguration {
322
322
  groups: ISamlRolesGroup[];
323
323
  }
324
324
  export interface IExchangeOAuthTokens {
325
- code: string;
326
- redirect_uri: string;
327
- code_verifier: string;
325
+ code?: string;
326
+ code_verifier?: string;
327
+ redirect_uri?: string;
328
+ refresh_token?: string;
328
329
  }
329
330
  export interface IOAuthTokenResponse {
330
331
  access_token: string;
package/fetch.js CHANGED
@@ -38,7 +38,9 @@ async function prepareUrl(context, url, params) {
38
38
  }
39
39
 
40
40
  async function buildRequestHeaders(context, contentType) {
41
- const authToken = await (context?.tokenResolver ?? ContextHolder.getAccessToken)();
41
+ var _context$tokenResolve;
42
+
43
+ const authToken = await ((_context$tokenResolve = context == null ? void 0 : context.tokenResolver) != null ? _context$tokenResolve : ContextHolder.getAccessToken)();
42
44
  const headers = {};
43
45
 
44
46
  if (authToken) {
@@ -99,14 +101,16 @@ async function getAdditionalHeaders(context) {
99
101
  }
100
102
 
101
103
  const sendRequest = async opts => {
104
+ var _opts$method, _ref, _opts$credentials;
105
+
102
106
  const context = ContextHolder.getContext();
103
107
  const headers = await buildRequestHeaders(context, opts.contentType);
104
108
  const url = await prepareUrl(context, opts.url, opts.params);
105
109
  const response = await fetch(url, {
106
110
  body: opts.body ? opts.contentType === 'application/json' ? JSON.stringify(opts.body) : opts.body : null,
107
- method: opts.method ?? 'GET',
111
+ method: (_opts$method = opts.method) != null ? _opts$method : 'GET',
108
112
  headers: _extends({}, headers, opts.headers),
109
- credentials: opts.credentials ?? context.requestCredentials ?? 'same-origin'
113
+ credentials: (_ref = (_opts$credentials = opts.credentials) != null ? _opts$credentials : context.requestCredentials) != null ? _ref : 'same-origin'
110
114
  });
111
115
 
112
116
  if (response.status === 302) {
@@ -115,6 +119,8 @@ const sendRequest = async opts => {
115
119
  }
116
120
 
117
121
  if (!response.ok) {
122
+ var _context$logLevel, _context$logLevel2;
123
+
118
124
  if (response.status === 413) {
119
125
  throw new FronteggApiError('Error request is too large', response.status);
120
126
  }
@@ -132,7 +138,7 @@ const sendRequest = async opts => {
132
138
  errorMessage = `Error ${response.status} - ${response.statusText}`;
133
139
  }
134
140
 
135
- if (response.status >= 400 && response.status < 500 && ['warn'].includes(context.logLevel ?? '')) console.warn(errorMessage);else if (response.status === 500 && ['warn', 'error'].includes(context.logLevel ?? '')) console.error(errorMessage);
141
+ if (response.status >= 400 && response.status < 500 && ['warn'].includes((_context$logLevel = context.logLevel) != null ? _context$logLevel : '')) console.warn(errorMessage);else if (response.status === 500 && ['warn', 'error'].includes((_context$logLevel2 = context.logLevel) != null ? _context$logLevel2 : '')) console.error(errorMessage);
136
142
  throw new FronteggApiError(errorMessage, response.status);
137
143
  }
138
144
 
package/index.js CHANGED
@@ -1,4 +1,4 @@
1
- /** @license Frontegg v3.0.2
1
+ /** @license Frontegg v3.0.5
2
2
  *
3
3
  * This source code is licensed under the MIT license found in the
4
4
  * LICENSE file in the root directory of this source tree.
package/metadata/index.js CHANGED
@@ -1,8 +1,10 @@
1
1
  import { Get } from '../fetch';
2
2
 
3
3
  async function getMetadata(body) {
4
+ var _data$rows, _data$rows2;
5
+
4
6
  const data = await Get('/metadata', body);
5
- if (data?.rows?.[0]) return data?.rows?.[0];
7
+ if (data != null && (_data$rows = data.rows) != null && _data$rows[0]) return data == null ? void 0 : (_data$rows2 = data.rows) == null ? void 0 : _data$rows2[0];
6
8
  throw new Error(`metadata not found: ${body.entityName}`);
7
9
  }
8
10
 
@@ -48,6 +48,7 @@ var _exportNames = {
48
48
  getVendorConfig: true,
49
49
  signUpUser: true,
50
50
  getCurrentUserSessions: true,
51
+ getCurrentUserSession: true,
51
52
  getSessionConfigurations: true,
52
53
  createOrUpdateSessionConfigrations: true,
53
54
  deleteSessionForUser: true,
@@ -119,6 +120,7 @@ exports.generateLoginResponse = generateLoginResponse;
119
120
  exports.generateLoginResponseFromOAuthResponse = generateLoginResponseFromOAuthResponse;
120
121
  exports.generateLoginResponseV2 = generateLoginResponseV2;
121
122
  exports.getActivateAccountStrategy = getActivateAccountStrategy;
123
+ exports.getCurrentUserSession = getCurrentUserSession;
122
124
  exports.getCurrentUserSessions = getCurrentUserSessions;
123
125
  exports.getOidcConfiguration = getOidcConfiguration;
124
126
  exports.getSSOConfigurations = getSSOConfigurations;
@@ -505,6 +507,10 @@ async function getCurrentUserSessions() {
505
507
  return (0, _fetch.Get)(_constants.urls.identity.users.sessions.currentUser.v1);
506
508
  }
507
509
 
510
+ async function getCurrentUserSession() {
511
+ return (0, _fetch.Get)(`${_constants.urls.identity.users.sessions.currentUser.v1}/current`);
512
+ }
513
+
508
514
  async function getSessionConfigurations() {
509
515
  return (0, _fetch.Get)(_constants.urls.identity.users.sessions.configurations.v1);
510
516
  }
package/node/index.js CHANGED
@@ -1,4 +1,4 @@
1
- /** @license Frontegg v3.0.2
1
+ /** @license Frontegg v3.0.5
2
2
  *
3
3
  * This source code is licensed under the MIT license found in the
4
4
  * LICENSE file in the root directory of this source tree.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@frontegg/rest-api",
3
- "version": "3.0.2",
3
+ "version": "3.0.5",
4
4
  "main": "./node/index.js",
5
5
  "license": "MIT",
6
6
  "dependencies": {
package/teams/index.js CHANGED
@@ -2,7 +2,7 @@ import _extends from "@babel/runtime/helpers/esm/extends";
2
2
  import { Get, Post, Put, Delete, Patch } from '../fetch';
3
3
  import { urls } from '../constants';
4
4
  export async function getProfile(params) {
5
- return Get(`${urls.identity.users.v2}/me`, params ?? {
5
+ return Get(`${urls.identity.users.v2}/me`, params != null ? params : {
6
6
  addRoles: true
7
7
  });
8
8
  }
@@ -19,12 +19,14 @@ export async function changePassword(body) {
19
19
  return Post(`${urls.identity.users.v1}/passwords/change`, body);
20
20
  }
21
21
  export async function loadUsers(params) {
22
+ var _params$sort, _params$sort$0$id, _params$sort2, _params$sort2$, _params$sort3, _params$sort3$;
23
+
22
24
  const filters = (params.filter || []).reduce((p, n) => _extends({}, p, {
23
25
  [n.id]: n.value
24
26
  }), {});
25
- const sorts = params.sort?.length ? {
26
- sortBy: params.sort?.[0]?.id ?? 'name',
27
- sortDirection: params.sort?.[0]?.desc ? 'desc' : 'asc'
27
+ const sorts = (_params$sort = params.sort) != null && _params$sort.length ? {
28
+ sortBy: (_params$sort$0$id = (_params$sort2 = params.sort) == null ? void 0 : (_params$sort2$ = _params$sort2[0]) == null ? void 0 : _params$sort2$.id) != null ? _params$sort$0$id : 'name',
29
+ sortDirection: (_params$sort3 = params.sort) != null && (_params$sort3$ = _params$sort3[0]) != null && _params$sort3$.desc ? 'desc' : 'asc'
28
30
  } : null;
29
31
  return Get(urls.team.members.v1, _extends({
30
32
  pageOffset: params.pageOffset,