@frontegg/js 6.117.0-alpha.0 → 6.118.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
- import { EnhancedStore, Entitlements } from '@frontegg/redux-store';
1
+ import { EnhancedStore, EntitledToOptions, Entitlement } from '@frontegg/redux-store';
2
2
  import { FronteggAppOptions, FronteggCheckoutDialogOptions, LocalizationsOverrides } from '@frontegg/types';
3
3
  declare type FronteggAppContainers = {
4
4
  adminPortalEl: HTMLElement;
@@ -45,10 +45,27 @@ export declare class FronteggApp {
45
45
  showCheckoutDialog(opts: FronteggCheckoutDialogOptions): Promise<void>;
46
46
  hideCheckoutDialog(): void;
47
47
  /**
48
- @param keys The requested entitlement keys
49
- @returns Entitlements contain true/false for every key (state of is key entitled)
48
+ * @returns entitlements store data
49
+ */
50
+ private getEntitlementsFromStore;
51
+ /**
52
+ @param key
53
+ @returns if the user is entitled to the given feature. Attaching the justification if not
54
+ @throws when entitlement is not enabled via frontegg options
55
+ */
56
+ getFeatureEntitlements(key: string): Entitlement;
57
+ /**
58
+ @param key
59
+ @returns if the user is entitled to the given permission. Attaching the justification if not
60
+ @throws when entitlement is not enabled via frontegg options
61
+ */
62
+ getPermissionEntitlements(key: string): Entitlement;
63
+ /**
64
+ @param options - including permission or feature key
65
+ @returns if the user is entitled to the given permission or feature. Attaching the justification if not
66
+ @throws when entitlement is not enabled via frontegg options
50
67
  */
51
- getEntitlements(keys: string[]): Entitlements;
68
+ getEntitlements(options: EntitledToOptions): Entitlement;
52
69
  close(): void;
53
70
  }
54
71
  export {};
@@ -3,7 +3,7 @@ import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
3
3
  import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
4
4
  import _createClass from "@babel/runtime/helpers/esm/createClass";
5
5
  import _regeneratorRuntime from "@babel/runtime/regenerator";
6
- import { createFronteggStore, getEntitlements as _getEntitlements } from '@frontegg/redux-store';
6
+ import { createFronteggStore, getPermissionEntitlements as _getPermissionEntitlements, getFeatureEntitlements as _getFeatureEntitlements } from '@frontegg/redux-store';
7
7
  import { Metadata } from '@frontegg/types';
8
8
  import { formatName, restoreSearchParams } from '../utils';
9
9
  import { AppHolder } from '../AppHolder';
@@ -123,6 +123,9 @@ export var FronteggApp = /*#__PURE__*/function () {
123
123
  this.updateLocalizationsSetter = function (localizationUpdateFn) {
124
124
  _this.updateLocalizations = localizationUpdateFn;
125
125
  };
126
+ this.getEntitlementsFromStore = function () {
127
+ return _this.store.getState().auth.entitlementsState;
128
+ };
126
129
  var appName = formatName(name);
127
130
  var customElementName = "frontegg-app-".concat(appName);
128
131
  this.iframeRendering = iframeRendering;
@@ -148,13 +151,14 @@ export var FronteggApp = /*#__PURE__*/function () {
148
151
  throw Error('Mismatch in store names');
149
152
  }
150
153
  } else {
151
- var _this$options$authOpt2, _this$options$auditsO;
154
+ var _this$options$authOpt2, _this$options$auditsO, _this$options$entitle;
152
155
  this.store = createFronteggStore({
153
156
  context: this.options.contextOptions,
154
157
  appName: this.name
155
158
  }, this, this.options.previewMode, authOptions, {
156
159
  auth: (_this$options$authOpt2 = this.options.authOptions) != null ? _this$options$authOpt2 : {},
157
- audits: (_this$options$auditsO = this.options.auditsOptions) != null ? _this$options$auditsO : {}
160
+ audits: (_this$options$auditsO = this.options.auditsOptions) != null ? _this$options$auditsO : {},
161
+ entitlementsOptions: (_this$options$entitle = this.options.entitlementsOptions) != null ? _this$options$entitle : {}
158
162
  }, false, this.options.urlStrategy);
159
163
  }
160
164
  AppHolder.setInstance(appName, this);
@@ -414,15 +418,50 @@ export var FronteggApp = /*#__PURE__*/function () {
414
418
  }
415
419
 
416
420
  /**
417
- @param keys The requested entitlement keys
418
- @returns Entitlements contain true/false for every key (state of is key entitled)
421
+ * @returns entitlements store data
422
+ */
423
+ }, {
424
+ key: "getFeatureEntitlements",
425
+ value:
426
+ /**
427
+ @param key
428
+ @returns if the user is entitled to the given feature. Attaching the justification if not
429
+ @throws when entitlement is not enabled via frontegg options
430
+ */
431
+ function getFeatureEntitlements(key) {
432
+ var _ref4 = this.getEntitlementsFromStore() || {},
433
+ entitlements = _ref4.entitlements,
434
+ options = _ref4.options;
435
+ return _getFeatureEntitlements(entitlements, key, options);
436
+ }
437
+
438
+ /**
439
+ @param key
440
+ @returns if the user is entitled to the given permission. Attaching the justification if not
441
+ @throws when entitlement is not enabled via frontegg options
442
+ */
443
+ }, {
444
+ key: "getPermissionEntitlements",
445
+ value: function getPermissionEntitlements(key) {
446
+ var _ref5 = this.getEntitlementsFromStore() || {},
447
+ entitlements = _ref5.entitlements,
448
+ options = _ref5.options;
449
+ return _getPermissionEntitlements(entitlements, key, options);
450
+ }
451
+
452
+ /**
453
+ @param options - including permission or feature key
454
+ @returns if the user is entitled to the given permission or feature. Attaching the justification if not
455
+ @throws when entitlement is not enabled via frontegg options
419
456
  */
420
457
  }, {
421
458
  key: "getEntitlements",
422
- value: function getEntitlements(keys) {
423
- var _this$store$getState$;
424
- var entitlements = (_this$store$getState$ = this.store.getState().auth.entitlementsState) == null ? void 0 : _this$store$getState$.entitlements;
425
- return _getEntitlements(entitlements, keys);
459
+ value: function getEntitlements(options) {
460
+ // we use permissionKey (options key) to decide if the user is using permission key or feature key
461
+ if ('permissionKey' in options) {
462
+ return this.getPermissionEntitlements(options.permissionKey);
463
+ }
464
+ return this.getFeatureEntitlements(options.featureKey);
426
465
  }
427
466
  }, {
428
467
  key: "close",
package/index.js CHANGED
@@ -1,4 +1,4 @@
1
- /** @license Frontegg v6.117.0-alpha.0
1
+ /** @license Frontegg v6.118.0
2
2
  *
3
3
  * This source code is licensed under the MIT license found in the
4
4
  * LICENSE file in the root directory of this source tree.
@@ -130,6 +130,9 @@ var FronteggApp = /*#__PURE__*/function () {
130
130
  this.updateLocalizationsSetter = function (localizationUpdateFn) {
131
131
  _this.updateLocalizations = localizationUpdateFn;
132
132
  };
133
+ this.getEntitlementsFromStore = function () {
134
+ return _this.store.getState().auth.entitlementsState;
135
+ };
133
136
  var appName = (0, _utils.formatName)(name);
134
137
  var customElementName = "frontegg-app-".concat(appName);
135
138
  this.iframeRendering = iframeRendering;
@@ -155,13 +158,14 @@ var FronteggApp = /*#__PURE__*/function () {
155
158
  throw Error('Mismatch in store names');
156
159
  }
157
160
  } else {
158
- var _this$options$authOpt2, _this$options$auditsO;
161
+ var _this$options$authOpt2, _this$options$auditsO, _this$options$entitle;
159
162
  this.store = (0, _reduxStore.createFronteggStore)({
160
163
  context: this.options.contextOptions,
161
164
  appName: this.name
162
165
  }, this, this.options.previewMode, authOptions, {
163
166
  auth: (_this$options$authOpt2 = this.options.authOptions) != null ? _this$options$authOpt2 : {},
164
- audits: (_this$options$auditsO = this.options.auditsOptions) != null ? _this$options$auditsO : {}
167
+ audits: (_this$options$auditsO = this.options.auditsOptions) != null ? _this$options$auditsO : {},
168
+ entitlementsOptions: (_this$options$entitle = this.options.entitlementsOptions) != null ? _this$options$entitle : {}
165
169
  }, false, this.options.urlStrategy);
166
170
  }
167
171
  _AppHolder.AppHolder.setInstance(appName, this);
@@ -421,15 +425,50 @@ var FronteggApp = /*#__PURE__*/function () {
421
425
  }
422
426
 
423
427
  /**
424
- @param keys The requested entitlement keys
425
- @returns Entitlements contain true/false for every key (state of is key entitled)
428
+ * @returns entitlements store data
429
+ */
430
+ }, {
431
+ key: "getFeatureEntitlements",
432
+ value:
433
+ /**
434
+ @param key
435
+ @returns if the user is entitled to the given feature. Attaching the justification if not
436
+ @throws when entitlement is not enabled via frontegg options
437
+ */
438
+ function getFeatureEntitlements(key) {
439
+ var _ref4 = this.getEntitlementsFromStore() || {},
440
+ entitlements = _ref4.entitlements,
441
+ options = _ref4.options;
442
+ return (0, _reduxStore.getFeatureEntitlements)(entitlements, key, options);
443
+ }
444
+
445
+ /**
446
+ @param key
447
+ @returns if the user is entitled to the given permission. Attaching the justification if not
448
+ @throws when entitlement is not enabled via frontegg options
449
+ */
450
+ }, {
451
+ key: "getPermissionEntitlements",
452
+ value: function getPermissionEntitlements(key) {
453
+ var _ref5 = this.getEntitlementsFromStore() || {},
454
+ entitlements = _ref5.entitlements,
455
+ options = _ref5.options;
456
+ return (0, _reduxStore.getPermissionEntitlements)(entitlements, key, options);
457
+ }
458
+
459
+ /**
460
+ @param options - including permission or feature key
461
+ @returns if the user is entitled to the given permission or feature. Attaching the justification if not
462
+ @throws when entitlement is not enabled via frontegg options
426
463
  */
427
464
  }, {
428
465
  key: "getEntitlements",
429
- value: function getEntitlements(keys) {
430
- var _this$store$getState$;
431
- var entitlements = (_this$store$getState$ = this.store.getState().auth.entitlementsState) == null ? void 0 : _this$store$getState$.entitlements;
432
- return (0, _reduxStore.getEntitlements)(entitlements, keys);
466
+ value: function getEntitlements(options) {
467
+ // we use permissionKey (options key) to decide if the user is using permission key or feature key
468
+ if ('permissionKey' in options) {
469
+ return this.getPermissionEntitlements(options.permissionKey);
470
+ }
471
+ return this.getFeatureEntitlements(options.featureKey);
433
472
  }
434
473
  }, {
435
474
  key: "close",
package/node/index.js CHANGED
@@ -1,4 +1,4 @@
1
- /** @license Frontegg v6.117.0-alpha.0
1
+ /** @license Frontegg v6.118.0
2
2
  *
3
3
  * This source code is licensed under the MIT license found in the
4
4
  * LICENSE file in the root directory of this source tree.
package/node/version.js CHANGED
@@ -5,6 +5,6 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports["default"] = void 0;
7
7
  var _default = {
8
- cdnVersion: '6.117.0-alpha.0'
8
+ cdnVersion: '6.118.0'
9
9
  };
10
10
  exports["default"] = _default;
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@frontegg/js",
3
- "version": "6.117.0-alpha.0",
3
+ "version": "6.118.0",
4
4
  "main": "./node/index.js",
5
5
  "license": "MIT",
6
6
  "author": "Frontegg LTD",
7
7
  "dependencies": {
8
8
  "@babel/runtime": "^7.18.6",
9
- "@frontegg/types": "6.117.0-alpha.0"
9
+ "@frontegg/types": "6.118.0"
10
10
  },
11
11
  "browserslist": {
12
12
  "production": [