@frontegg/js 6.149.0 → 6.151.0-alpha.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,6 +1,7 @@
1
1
  import { EnhancedStore, EntitledToOptions, Entitlement } from '@frontegg/redux-store';
2
2
  import { FronteggAppOptions, FronteggCheckoutDialogOptions, LocalizationsOverrides, LoadEntitlementsCallback } from '@frontegg/types';
3
3
  import { IFeatureFlagsAttributes } from '@frontegg/rest-api';
4
+ import { CustomAttributes } from '@frontegg/entitlements-javascript-commons';
4
5
  declare type FronteggAppContainers = {
5
6
  adminPortalEl: HTMLElement;
6
7
  loginBoxEl: HTMLElement;
@@ -49,6 +50,11 @@ export declare class FronteggApp {
49
50
  * @param previewFeatureFlags
50
51
  */
51
52
  setFeatureFlagsForPreview: (previewFeatureFlags: IFeatureFlagsAttributes) => void;
53
+ /**
54
+ * @param flags keys to check
55
+ * @returns an array of feature flags on/off boolean values
56
+ */
57
+ private queryFeatureFlags;
52
58
  initContainers(elements: FronteggAppContainers): Promise<void>;
53
59
  updateLocalizationsSetter: (localizationUpdateFn: (localizations: LocalizationsOverrides) => void) => void;
54
60
  updateMetadata(metadata: FronteggAppOptions['metadata']): void;
@@ -67,23 +73,35 @@ export declare class FronteggApp {
67
73
  */
68
74
  private getEntitlementsFromStore;
69
75
  /**
70
- @param key
76
+ * @returns user store data
77
+ */
78
+ private getUserFromStore;
79
+ /**
80
+ * @param customAttributes consumer attributes
81
+ * @returns is entitled query data including: entitltments state, final attributes (consumer and frontegg) and API version to use
82
+ */
83
+ private getEntitlementsQueryData;
84
+ /**
85
+ @param key feature key
86
+ @param customAttributes user attributes
71
87
  @returns if the user is entitled to the given feature. Attaching the justification if not
72
88
  @throws when entitlement is not enabled via frontegg options
73
89
  */
74
- getFeatureEntitlements(key: string): Entitlement;
90
+ getFeatureEntitlements(key: string, customAttributes?: CustomAttributes): Entitlement;
75
91
  /**
76
- @param key
92
+ @param key permission key
93
+ @param customAttributes user attributes
77
94
  @returns if the user is entitled to the given permission. Attaching the justification if not
78
95
  @throws when entitlement is not enabled via frontegg options
79
96
  */
80
- getPermissionEntitlements(key: string): Entitlement;
97
+ getPermissionEntitlements(key: string, customAttributes?: CustomAttributes): Entitlement;
81
98
  /**
82
99
  @param options - including permission or feature key
100
+ @param customAttributes user attributes
83
101
  @returns if the user is entitled to the given permission or feature. Attaching the justification if not
84
102
  @throws when entitlement is not enabled via frontegg options
85
103
  */
86
- getEntitlements(options: EntitledToOptions): Entitlement;
104
+ getEntitlements(options: EntitledToOptions, customAttributes?: CustomAttributes): Entitlement;
87
105
  /**
88
106
  * Load entitlements
89
107
  * @param callback called on request completed with true if succeeded, false if failed
@@ -1,3 +1,4 @@
1
+ import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
1
2
  import _extends from "@babel/runtime/helpers/esm/extends";
2
3
  import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
3
4
  import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
@@ -7,7 +8,7 @@ import { createFronteggStore, getPermissionEntitlements as _getPermissionEntitle
7
8
  import { Metadata } from '@frontegg/types';
8
9
  import { formatName, restoreSearchParams } from '../utils';
9
10
  import { AppHolder } from '../AppHolder';
10
- import { fetch as FronteggFetch, ContextHolder } from '@frontegg/rest-api';
11
+ import { fetch as FronteggFetch, ContextHolder, USE_ENTITLEMENTS_V2_ENDPOINT_FF } from '@frontegg/rest-api';
11
12
  import { RequestSource } from '@frontegg/rest-api';
12
13
  import * as FronteggRestApi from '@frontegg/rest-api';
13
14
  import * as FronteggTypes from '@frontegg/types';
@@ -138,6 +139,9 @@ export var FronteggApp = /*#__PURE__*/function () {
138
139
  this.setFeatureFlagsForPreview = function (previewFeatureFlags) {
139
140
  FronteggRestApi.FeatureFlags.set(_extends({}, mockFlagsList, previewFeatureFlags), _this.name);
140
141
  };
142
+ this.queryFeatureFlags = function (flags) {
143
+ return FronteggRestApi.FeatureFlags.getFeatureFlags(flags, _this.name);
144
+ };
141
145
  this.updateLocalizationsSetter = function (localizationUpdateFn) {
142
146
  _this.updateLocalizations = localizationUpdateFn;
143
147
  };
@@ -145,6 +149,25 @@ export var FronteggApp = /*#__PURE__*/function () {
145
149
  var _this$store$getState$;
146
150
  return (_this$store$getState$ = _this.store.getState().auth.user) == null ? void 0 : _this$store$getState$.entitlements;
147
151
  };
152
+ this.getUserFromStore = function () {
153
+ return _this.store.getState().auth.user;
154
+ };
155
+ this.getEntitlementsQueryData = function (customAttributes) {
156
+ var user = _this.getUserFromStore();
157
+ var entitlements = _this.getEntitlementsFromStore();
158
+ var attributes = {
159
+ custom: customAttributes,
160
+ jwt: user
161
+ };
162
+ var _this$queryFeatureFla = _this.queryFeatureFlags([USE_ENTITLEMENTS_V2_ENDPOINT_FF]),
163
+ _this$queryFeatureFla2 = _slicedToArray(_this$queryFeatureFla, 1),
164
+ useEntitlementsV2 = _this$queryFeatureFla2[0];
165
+ return {
166
+ entitlements: entitlements,
167
+ attributes: attributes,
168
+ isV2: useEntitlementsV2
169
+ };
170
+ };
148
171
  var appName = formatName(name);
149
172
  var customElementName = "frontegg-app-".concat(appName);
150
173
  this.iframeRendering = iframeRendering;
@@ -465,40 +488,49 @@ export var FronteggApp = /*#__PURE__*/function () {
465
488
  key: "getFeatureEntitlements",
466
489
  value:
467
490
  /**
468
- @param key
491
+ @param key feature key
492
+ @param customAttributes user attributes
469
493
  @returns if the user is entitled to the given feature. Attaching the justification if not
470
494
  @throws when entitlement is not enabled via frontegg options
471
495
  */
472
- function getFeatureEntitlements(key) {
473
- var entitlements = this.getEntitlementsFromStore();
474
- return _getFeatureEntitlements(entitlements, key);
496
+ function getFeatureEntitlements(key, customAttributes) {
497
+ var _this$getEntitlements = this.getEntitlementsQueryData(customAttributes),
498
+ entitlements = _this$getEntitlements.entitlements,
499
+ attributes = _this$getEntitlements.attributes,
500
+ isV2 = _this$getEntitlements.isV2;
501
+ return _getFeatureEntitlements(entitlements, key, attributes, isV2);
475
502
  }
476
503
 
477
504
  /**
478
- @param key
505
+ @param key permission key
506
+ @param customAttributes user attributes
479
507
  @returns if the user is entitled to the given permission. Attaching the justification if not
480
508
  @throws when entitlement is not enabled via frontegg options
481
509
  */
482
510
  }, {
483
511
  key: "getPermissionEntitlements",
484
- value: function getPermissionEntitlements(key) {
485
- var entitlements = this.getEntitlementsFromStore();
486
- return _getPermissionEntitlements(entitlements, key);
512
+ value: function getPermissionEntitlements(key, customAttributes) {
513
+ var _this$getEntitlements2 = this.getEntitlementsQueryData(customAttributes),
514
+ entitlements = _this$getEntitlements2.entitlements,
515
+ attributes = _this$getEntitlements2.attributes,
516
+ isV2 = _this$getEntitlements2.isV2;
517
+ return _getPermissionEntitlements(entitlements, key, attributes, isV2);
487
518
  }
488
519
 
489
520
  /**
490
521
  @param options - including permission or feature key
522
+ @param customAttributes user attributes
491
523
  @returns if the user is entitled to the given permission or feature. Attaching the justification if not
492
524
  @throws when entitlement is not enabled via frontegg options
493
525
  */
494
526
  }, {
495
527
  key: "getEntitlements",
496
- value: function getEntitlements(options) {
528
+ value: function getEntitlements(options, customAttributes) {
497
529
  // we use permissionKey (options key) to decide if the user is using permission key or feature key
498
530
  if ('permissionKey' in options) {
499
- return this.getPermissionEntitlements(options.permissionKey);
531
+ return this.getPermissionEntitlements(options.permissionKey, customAttributes);
500
532
  }
501
- return this.getFeatureEntitlements(options.featureKey);
533
+ return this.getFeatureEntitlements(options.featureKey, customAttributes);
502
534
  }
503
535
 
504
536
  /**
package/index.js CHANGED
@@ -1,4 +1,4 @@
1
- /** @license Frontegg v6.149.0
1
+ /** @license Frontegg v6.151.0-alpha.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.
@@ -7,6 +7,7 @@ Object.defineProperty(exports, "__esModule", {
7
7
  });
8
8
  exports.FronteggApp = void 0;
9
9
  var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
10
+ var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
10
11
  var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
11
12
  var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
12
13
  var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
@@ -145,6 +146,9 @@ var FronteggApp = /*#__PURE__*/function () {
145
146
  this.setFeatureFlagsForPreview = function (previewFeatureFlags) {
146
147
  FronteggRestApi.FeatureFlags.set((0, _extends2["default"])({}, _mockFlagsList.mockFlagsList, previewFeatureFlags), _this.name);
147
148
  };
149
+ this.queryFeatureFlags = function (flags) {
150
+ return FronteggRestApi.FeatureFlags.getFeatureFlags(flags, _this.name);
151
+ };
148
152
  this.updateLocalizationsSetter = function (localizationUpdateFn) {
149
153
  _this.updateLocalizations = localizationUpdateFn;
150
154
  };
@@ -152,6 +156,25 @@ var FronteggApp = /*#__PURE__*/function () {
152
156
  var _this$store$getState$;
153
157
  return (_this$store$getState$ = _this.store.getState().auth.user) == null ? void 0 : _this$store$getState$.entitlements;
154
158
  };
159
+ this.getUserFromStore = function () {
160
+ return _this.store.getState().auth.user;
161
+ };
162
+ this.getEntitlementsQueryData = function (customAttributes) {
163
+ var user = _this.getUserFromStore();
164
+ var entitlements = _this.getEntitlementsFromStore();
165
+ var attributes = {
166
+ custom: customAttributes,
167
+ jwt: user
168
+ };
169
+ var _this$queryFeatureFla = _this.queryFeatureFlags([FronteggRestApi.USE_ENTITLEMENTS_V2_ENDPOINT_FF]),
170
+ _this$queryFeatureFla2 = (0, _slicedToArray2["default"])(_this$queryFeatureFla, 1),
171
+ useEntitlementsV2 = _this$queryFeatureFla2[0];
172
+ return {
173
+ entitlements: entitlements,
174
+ attributes: attributes,
175
+ isV2: useEntitlementsV2
176
+ };
177
+ };
155
178
  var appName = (0, _utils.formatName)(name);
156
179
  var customElementName = "frontegg-app-".concat(appName);
157
180
  this.iframeRendering = iframeRendering;
@@ -472,40 +495,49 @@ var FronteggApp = /*#__PURE__*/function () {
472
495
  key: "getFeatureEntitlements",
473
496
  value:
474
497
  /**
475
- @param key
498
+ @param key feature key
499
+ @param customAttributes user attributes
476
500
  @returns if the user is entitled to the given feature. Attaching the justification if not
477
501
  @throws when entitlement is not enabled via frontegg options
478
502
  */
479
- function getFeatureEntitlements(key) {
480
- var entitlements = this.getEntitlementsFromStore();
481
- return (0, _reduxStore.getFeatureEntitlements)(entitlements, key);
503
+ function getFeatureEntitlements(key, customAttributes) {
504
+ var _this$getEntitlements = this.getEntitlementsQueryData(customAttributes),
505
+ entitlements = _this$getEntitlements.entitlements,
506
+ attributes = _this$getEntitlements.attributes,
507
+ isV2 = _this$getEntitlements.isV2;
508
+ return (0, _reduxStore.getFeatureEntitlements)(entitlements, key, attributes, isV2);
482
509
  }
483
510
 
484
511
  /**
485
- @param key
512
+ @param key permission key
513
+ @param customAttributes user attributes
486
514
  @returns if the user is entitled to the given permission. Attaching the justification if not
487
515
  @throws when entitlement is not enabled via frontegg options
488
516
  */
489
517
  }, {
490
518
  key: "getPermissionEntitlements",
491
- value: function getPermissionEntitlements(key) {
492
- var entitlements = this.getEntitlementsFromStore();
493
- return (0, _reduxStore.getPermissionEntitlements)(entitlements, key);
519
+ value: function getPermissionEntitlements(key, customAttributes) {
520
+ var _this$getEntitlements2 = this.getEntitlementsQueryData(customAttributes),
521
+ entitlements = _this$getEntitlements2.entitlements,
522
+ attributes = _this$getEntitlements2.attributes,
523
+ isV2 = _this$getEntitlements2.isV2;
524
+ return (0, _reduxStore.getPermissionEntitlements)(entitlements, key, attributes, isV2);
494
525
  }
495
526
 
496
527
  /**
497
528
  @param options - including permission or feature key
529
+ @param customAttributes user attributes
498
530
  @returns if the user is entitled to the given permission or feature. Attaching the justification if not
499
531
  @throws when entitlement is not enabled via frontegg options
500
532
  */
501
533
  }, {
502
534
  key: "getEntitlements",
503
- value: function getEntitlements(options) {
535
+ value: function getEntitlements(options, customAttributes) {
504
536
  // we use permissionKey (options key) to decide if the user is using permission key or feature key
505
537
  if ('permissionKey' in options) {
506
- return this.getPermissionEntitlements(options.permissionKey);
538
+ return this.getPermissionEntitlements(options.permissionKey, customAttributes);
507
539
  }
508
- return this.getFeatureEntitlements(options.featureKey);
540
+ return this.getFeatureEntitlements(options.featureKey, customAttributes);
509
541
  }
510
542
 
511
543
  /**
package/node/index.js CHANGED
@@ -1,4 +1,4 @@
1
- /** @license Frontegg v6.149.0
1
+ /** @license Frontegg v6.151.0-alpha.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.149.0'
8
+ cdnVersion: '6.151.0-alpha.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.149.0",
3
+ "version": "6.151.0-alpha.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.149.0"
9
+ "@frontegg/types": "6.151.0-alpha.0"
10
10
  },
11
11
  "browserslist": {
12
12
  "production": [