@frontegg/redux-store 7.78.0-alpha.0 → 7.78.0-alpha.1

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/index.js CHANGED
@@ -1,4 +1,4 @@
1
- /** @license Frontegg v7.78.0-alpha.0
1
+ /** @license Frontegg v7.78.0-alpha.1
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/mocks/index.d.ts CHANGED
@@ -45,12 +45,7 @@ declare const buildMockActions: (store: FronteggState, api: RestApi, actions: Sh
45
45
  };
46
46
  subscriptionsActions: import("..").SubscriptionsActions;
47
47
  subscriptionsStateActions: import("..").SubscriptionsStateActions;
48
- vendorActions: {
49
- setVendorState: (state: Partial<import("..").VendorState>) => void;
50
- resetVendorState: () => void;
51
- loadVendorPublicInfo: (payload?: import("../interfaces").WithRetryConfig<{}>) => Promise<void>;
52
- loadVendorPublicConfiguration: (payload?: import("../interfaces").WithRetryConfig<{}>) => Promise<void>;
53
- };
48
+ vendorActions: import("..").VendorActions;
54
49
  auditsActions: {
55
50
  setAuditsMetadataState: (state: Partial<import("..").AuditsMetadataState>) => void;
56
51
  resetAuditsMetadataState: () => void;
@@ -1,7 +1,2 @@
1
1
  import { FronteggState, RestApi, SharedActions } from '../../interfaces';
2
- export declare const buildVendorActions: (store: FronteggState, api: RestApi, actions: SharedActions) => {
3
- setVendorState: (state: Partial<import("../..").VendorState>) => void;
4
- resetVendorState: () => void;
5
- loadVendorPublicInfo: (payload?: import("../../interfaces").WithRetryConfig<{}>) => Promise<void>;
6
- loadVendorPublicConfiguration: (payload?: import("../../interfaces").WithRetryConfig<{}>) => Promise<void>;
7
- };
2
+ export declare const buildVendorActions: (store: FronteggState, api: RestApi, actions: SharedActions) => import("../../vendor").VendorActions;
package/node/index.js CHANGED
@@ -1,4 +1,4 @@
1
- /** @license Frontegg v7.78.0-alpha.0
1
+ /** @license Frontegg v7.78.0-alpha.1
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.
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.loadDynamicAction = loadDynamicAction;
7
+ /** Global caches so *all* lazy actions that share the same loader
8
+ * reuse the same import() and the same built-actions object */
9
+ const moduleCache = new WeakMap();
10
+ const actionsCache = new WeakMap();
11
+ function loadDynamicAction(store, api, shared, loader, key) {
12
+ /** step ① import() once per loader function */
13
+ function getModule() {
14
+ let p = moduleCache.get(loader);
15
+ if (!p) {
16
+ p = loader(); // dynamic import
17
+ moduleCache.set(loader, p);
18
+ }
19
+ return p;
20
+ }
21
+
22
+ /** step ② build actions once per (store, loader) combo */
23
+ async function getActions() {
24
+ let perStore = actionsCache.get(store);
25
+ if (!perStore) {
26
+ perStore = new WeakMap();
27
+ actionsCache.set(store, perStore);
28
+ }
29
+ let acts = perStore.get(loader);
30
+ if (!acts) {
31
+ const mod = await getModule();
32
+ acts = mod.default(store, api, shared); // 👈 pass sharedActions here
33
+ perStore.set(loader, acts);
34
+ }
35
+ return acts;
36
+ }
37
+
38
+ /* ----- the proxy function returned to the slice ----- */
39
+ return async (...args) => {
40
+ const fn = (await getActions())[key];
41
+ return fn(...args);
42
+ };
43
+ }
@@ -6,41 +6,28 @@ Object.defineProperty(exports, "__esModule", {
6
6
  });
7
7
  exports.default = void 0;
8
8
  var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
9
- var _state = require("./state");
10
- var _helpers = require("../helpers");
11
- var _default = (store, api, sharedActions) => {
12
- const setVendorState = state => {
13
- Object.assign(store.vendor, state);
14
- };
15
- const resetVendorState = () => {
16
- (0, _helpers.deepResetState)(store, ['vendor'], _state.initialState);
17
- };
9
+ var _helpers = require("../../helpers");
10
+ var _default = (store, api, actions) => {
18
11
  const loadVendorPublicInfo = async payload => {
19
- setVendorState({
12
+ actions.setVendorState({
20
13
  loading: true
21
14
  });
22
15
  try {
23
16
  var _vendorInfo$whiteLabe;
24
17
  const vendorInfo = await (0, _helpers.retryIfNeeded)(() => api.vendor.getVendorPublicInfo(), payload == null ? void 0 : payload.retryConfig);
25
18
  vendorInfo.whiteLabelMode = (_vendorInfo$whiteLabe = vendorInfo.whiteLabelMode) != null ? _vendorInfo$whiteLabe : false;
26
- setVendorState((0, _extends2.default)({}, vendorInfo, {
19
+ actions.setVendorState((0, _extends2.default)({}, vendorInfo, {
27
20
  loading: false
28
21
  }));
29
22
  } catch (e) {
30
- setVendorState({
23
+ actions.setVendorState({
31
24
  loading: false
32
25
  });
33
26
  console.error('failed to getVendorPublicInfo - ', e);
34
27
  }
35
28
  };
36
29
  return {
37
- setVendorState,
38
- resetVendorState,
39
- loadVendorPublicInfo,
40
- /**
41
- * @deprecated use loadVendorPublicInfo instead
42
- */
43
- loadVendorPublicConfiguration: loadVendorPublicInfo
30
+ loadVendorPublicInfo
44
31
  };
45
32
  };
46
33
  exports.default = _default;
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ var _helpers = require("../../helpers");
8
+ var _state = require("../state");
9
+ var _loadDynamicAction = require("../../toolkit/loadDynamicAction");
10
+ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
11
+ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
12
+ var _default = (store, api, actions) => {
13
+ const setVendorState = state => {
14
+ Object.assign(store.vendor, state);
15
+ };
16
+ const resetVendorState = () => {
17
+ (0, _helpers.deepResetState)(store, ['vendor'], _state.initialState);
18
+ };
19
+ const actionsLoader = () => Promise.resolve().then(() => _interopRequireWildcard(require('./actions')));
20
+ const loadVendorPublicInfo = (0, _loadDynamicAction.loadDynamicAction)(store, api, actions, actionsLoader, 'loadVendorPublicInfo');
21
+ return {
22
+ setVendorState,
23
+ resetVendorState,
24
+ loadVendorPublicInfo,
25
+ /**
26
+ * @deprecated use loadVendorPublicInfo instead
27
+ */
28
+ loadVendorPublicConfiguration: loadVendorPublicInfo
29
+ };
30
+ };
31
+ exports.default = _default;
@@ -4,6 +4,10 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
4
4
  Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
+ var _exportNames = {
8
+ createVendorState: true,
9
+ buildVendorActions: true
10
+ };
7
11
  Object.defineProperty(exports, "buildVendorActions", {
8
12
  enumerable: true,
9
13
  get: function () {
@@ -17,4 +21,16 @@ Object.defineProperty(exports, "createVendorState", {
17
21
  }
18
22
  });
19
23
  var _state = _interopRequireDefault(require("./state"));
20
- var _actions = _interopRequireDefault(require("./actions"));
24
+ var _actions = _interopRequireDefault(require("./actions"));
25
+ var _interfaces = require("./interfaces");
26
+ Object.keys(_interfaces).forEach(function (key) {
27
+ if (key === "default" || key === "__esModule") return;
28
+ if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
29
+ if (key in exports && exports[key] === _interfaces[key]) return;
30
+ Object.defineProperty(exports, key, {
31
+ enumerable: true,
32
+ get: function () {
33
+ return _interfaces[key];
34
+ }
35
+ });
36
+ });
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "@frontegg/redux-store",
3
- "version": "7.78.0-alpha.0",
3
+ "version": "7.78.0-alpha.1",
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
9
  "@frontegg/entitlements-javascript-commons": "1.1.2",
10
- "@frontegg/rest-api": "7.78.0-alpha.0",
10
+ "@frontegg/rest-api": "7.78.0-alpha.1",
11
11
  "fast-deep-equal": "3.1.3",
12
12
  "get-value": "^3.0.1",
13
13
  "proxy-compare": "^3.0.0",
@@ -0,0 +1,4 @@
1
+ import type { FronteggState, RestApi, SharedActions } from '../interfaces';
2
+ export declare function loadDynamicAction<TMod extends {
3
+ default: (s: FronteggState, a: RestApi, sh: SharedActions) => TActs;
4
+ }, TActs extends Record<string, (...args: any[]) => any>, K extends keyof TActs>(store: FronteggState, api: RestApi, shared: SharedActions, loader: () => Promise<TMod>, key: K): (...args: Parameters<TActs[K]>) => Promise<ReturnType<TActs[K]>>;
@@ -0,0 +1,37 @@
1
+ /** Global caches so *all* lazy actions that share the same loader
2
+ * reuse the same import() and the same built-actions object */
3
+ const moduleCache = new WeakMap();
4
+ const actionsCache = new WeakMap();
5
+ export function loadDynamicAction(store, api, shared, loader, key) {
6
+ /** step ① import() once per loader function */
7
+ function getModule() {
8
+ let p = moduleCache.get(loader);
9
+ if (!p) {
10
+ p = loader(); // dynamic import
11
+ moduleCache.set(loader, p);
12
+ }
13
+ return p;
14
+ }
15
+
16
+ /** step ② build actions once per (store, loader) combo */
17
+ async function getActions() {
18
+ let perStore = actionsCache.get(store);
19
+ if (!perStore) {
20
+ perStore = new WeakMap();
21
+ actionsCache.set(store, perStore);
22
+ }
23
+ let acts = perStore.get(loader);
24
+ if (!acts) {
25
+ const mod = await getModule();
26
+ acts = mod.default(store, api, shared); // 👈 pass sharedActions here
27
+ perStore.set(loader, acts);
28
+ }
29
+ return acts;
30
+ }
31
+
32
+ /* ----- the proxy function returned to the slice ----- */
33
+ return async (...args) => {
34
+ const fn = (await getActions())[key];
35
+ return fn(...args);
36
+ };
37
+ }
@@ -0,0 +1,4 @@
1
+ import { FronteggState, RestApi, SharedActions } from '../../interfaces';
2
+ import { AsyncVendorActions } from '../interfaces';
3
+ declare const _default: (store: FronteggState, api: RestApi, actions: SharedActions) => AsyncVendorActions;
4
+ export default _default;
@@ -1,38 +1,25 @@
1
1
  import _extends from "@babel/runtime/helpers/esm/extends";
2
- import { initialState } from './state';
3
- import { deepResetState, retryIfNeeded } from '../helpers';
4
- export default ((store, api, sharedActions) => {
5
- const setVendorState = state => {
6
- Object.assign(store.vendor, state);
7
- };
8
- const resetVendorState = () => {
9
- deepResetState(store, ['vendor'], initialState);
10
- };
2
+ import { retryIfNeeded } from '../../helpers';
3
+ export default ((store, api, actions) => {
11
4
  const loadVendorPublicInfo = async payload => {
12
- setVendorState({
5
+ actions.setVendorState({
13
6
  loading: true
14
7
  });
15
8
  try {
16
9
  var _vendorInfo$whiteLabe;
17
10
  const vendorInfo = await retryIfNeeded(() => api.vendor.getVendorPublicInfo(), payload == null ? void 0 : payload.retryConfig);
18
11
  vendorInfo.whiteLabelMode = (_vendorInfo$whiteLabe = vendorInfo.whiteLabelMode) != null ? _vendorInfo$whiteLabe : false;
19
- setVendorState(_extends({}, vendorInfo, {
12
+ actions.setVendorState(_extends({}, vendorInfo, {
20
13
  loading: false
21
14
  }));
22
15
  } catch (e) {
23
- setVendorState({
16
+ actions.setVendorState({
24
17
  loading: false
25
18
  });
26
19
  console.error('failed to getVendorPublicInfo - ', e);
27
20
  }
28
21
  };
29
22
  return {
30
- setVendorState,
31
- resetVendorState,
32
- loadVendorPublicInfo,
33
- /**
34
- * @deprecated use loadVendorPublicInfo instead
35
- */
36
- loadVendorPublicConfiguration: loadVendorPublicInfo
23
+ loadVendorPublicInfo
37
24
  };
38
25
  });
@@ -0,0 +1,4 @@
1
+ import { FronteggState, RestApi, SharedActions } from '../../interfaces';
2
+ import { VendorActions } from '../interfaces';
3
+ declare const _default: (store: FronteggState, api: RestApi, actions: SharedActions) => VendorActions;
4
+ export default _default;
@@ -0,0 +1,22 @@
1
+ import { deepResetState } from '../../helpers';
2
+ import { initialState } from '../state';
3
+ import { loadDynamicAction } from '../../toolkit/loadDynamicAction';
4
+ export default ((store, api, actions) => {
5
+ const setVendorState = state => {
6
+ Object.assign(store.vendor, state);
7
+ };
8
+ const resetVendorState = () => {
9
+ deepResetState(store, ['vendor'], initialState);
10
+ };
11
+ const actionsLoader = () => import('./actions');
12
+ const loadVendorPublicInfo = loadDynamicAction(store, api, actions, actionsLoader, 'loadVendorPublicInfo');
13
+ return {
14
+ setVendorState,
15
+ resetVendorState,
16
+ loadVendorPublicInfo,
17
+ /**
18
+ * @deprecated use loadVendorPublicInfo instead
19
+ */
20
+ loadVendorPublicConfiguration: loadVendorPublicInfo
21
+ };
22
+ });
package/vendor/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
1
  import createVendorState from './state';
2
2
  import buildVendorActions from './actions';
3
3
  export { createVendorState, buildVendorActions };
4
- export type VendorActions = ReturnType<typeof buildVendorActions>;
4
+ export * from './interfaces';
package/vendor/index.js CHANGED
@@ -1,3 +1,4 @@
1
1
  import createVendorState from './state';
2
2
  import buildVendorActions from './actions';
3
- export { createVendorState, buildVendorActions };
3
+ export { createVendorState, buildVendorActions };
4
+ export * from './interfaces';
@@ -1,3 +1,4 @@
1
+ import { WithRetryConfig } from '../interfaces';
1
2
  export interface VendorState {
2
3
  loading: boolean;
3
4
  name?: string;
@@ -5,3 +6,15 @@ export interface VendorState {
5
6
  icon?: string;
6
7
  whiteLabelMode?: boolean;
7
8
  }
9
+ export interface AsyncVendorActions {
10
+ loadVendorPublicInfo: (payload?: WithRetryConfig<{}>) => Promise<void>;
11
+ [key: string]: (...args: any[]) => any;
12
+ }
13
+ export interface VendorActions extends AsyncVendorActions {
14
+ setVendorState: (state: Partial<VendorState>) => void;
15
+ resetVendorState: () => void;
16
+ /**
17
+ * @deprecated use loadVendorPublicInfo instead
18
+ */
19
+ loadVendorPublicConfiguration: (payload?: WithRetryConfig<{}>) => Promise<void>;
20
+ }
@@ -1,12 +0,0 @@
1
- import { FronteggState, RestApi, SharedActions, WithRetryConfig } from '../interfaces';
2
- import { VendorState } from './interfaces';
3
- declare const _default: (store: FronteggState, api: RestApi, sharedActions: SharedActions) => {
4
- setVendorState: (state: Partial<VendorState>) => void;
5
- resetVendorState: () => void;
6
- loadVendorPublicInfo: (payload?: WithRetryConfig<{}>) => Promise<void>;
7
- /**
8
- * @deprecated use loadVendorPublicInfo instead
9
- */
10
- loadVendorPublicConfiguration: (payload?: WithRetryConfig<{}>) => Promise<void>;
11
- };
12
- export default _default;