@redhat-cloud-services/hcc-storybook-hub 0.1.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.
@@ -0,0 +1,149 @@
1
+ export { chromeAppNavClickSpy, configureChromeMock } from './mocks/useChrome.js';
2
+ import React, { ReactNode } from 'react';
3
+ export { F as FeatureFlagsConfig, a as FeatureFlagsContext, b as FeatureFlagsProvider } from './FeatureFlagsProvider-C_Xxe83Z.js';
4
+ import '@vitest/spy';
5
+
6
+ type Environment = 'production' | 'staging';
7
+ interface MockUserIdentity {
8
+ account_number?: string;
9
+ org_id?: string;
10
+ user?: {
11
+ is_org_admin?: boolean;
12
+ username?: string;
13
+ email?: string;
14
+ is_internal?: boolean;
15
+ first_name?: string;
16
+ last_name?: string;
17
+ is_active?: boolean;
18
+ locale?: string;
19
+ };
20
+ organization?: {
21
+ name?: string;
22
+ };
23
+ internal?: {
24
+ account_id?: string;
25
+ cross_access?: boolean;
26
+ };
27
+ entitlements?: Record<string, {
28
+ is_entitled?: boolean;
29
+ is_trial?: boolean;
30
+ }>;
31
+ }
32
+ interface WorkspacePermissionsMap {
33
+ view: string[];
34
+ edit: string[];
35
+ delete: string[];
36
+ create: string[];
37
+ move: string[];
38
+ }
39
+ declare const EMPTY_WORKSPACE_PERMISSIONS: WorkspacePermissionsMap;
40
+ interface TenantPermissionsMap {
41
+ rbac_roles_read: boolean;
42
+ rbac_roles_write: boolean;
43
+ rbac_groups_read: boolean;
44
+ rbac_groups_write: boolean;
45
+ rbac_principal_read: boolean;
46
+ rbac_workspace_view: boolean;
47
+ rbac_workspace_edit: boolean;
48
+ rbac_workspace_create: boolean;
49
+ rbac_workspace_delete: boolean;
50
+ rbac_workspace_move: boolean;
51
+ }
52
+ declare const EMPTY_TENANT_PERMISSIONS: TenantPermissionsMap;
53
+ interface MockState {
54
+ environment: Environment;
55
+ isOrgAdmin: boolean;
56
+ permissions: string[];
57
+ workspacePermissions: WorkspacePermissionsMap;
58
+ tenantPermissions: TenantPermissionsMap;
59
+ userIdentity?: MockUserIdentity;
60
+ }
61
+ interface StoryParameters {
62
+ noWrapping?: boolean;
63
+ permissions?: readonly string[];
64
+ orgAdmin?: boolean;
65
+ environment?: 'staging' | 'production';
66
+ workspacePermissions?: Partial<WorkspacePermissionsMap>;
67
+ tenantPermissions?: Partial<TenantPermissionsMap>;
68
+ userIdentity?: MockUserIdentity;
69
+ featureFlags?: Record<string, boolean>;
70
+ msw?: {
71
+ handlers: unknown[];
72
+ };
73
+ }
74
+ declare const StorybookMockContext: React.Context<MockState>;
75
+ interface ProviderProps extends Partial<MockState> {
76
+ children: ReactNode;
77
+ }
78
+ declare const StorybookMockProvider: React.FC<ProviderProps>;
79
+ declare const useMockState: () => MockState;
80
+
81
+ interface ChromeConfig {
82
+ environment: string;
83
+ [key: string]: any;
84
+ }
85
+ declare const ChromeContext: React.Context<ChromeConfig>;
86
+ declare const ChromeProvider: React.FC<{
87
+ value: ChromeConfig;
88
+ children: ReactNode;
89
+ }>;
90
+
91
+ /**
92
+ * Derives Kessel tenant permissions from Chrome-style permission strings.
93
+ *
94
+ * V2 domain hooks (useRolesAccess, useGroupsAccess, etc.) consume tenantPermissions
95
+ * from the Kessel mock. Stories typically set Chrome-style `permissions` (e.g.
96
+ * ['rbac:group:read', 'rbac:role:write']). This helper converts those to the
97
+ * tenant relation format expected by useSelfAccessCheck.
98
+ */
99
+
100
+ /**
101
+ * Converts Chrome-style permissions to Kessel tenant permissions.
102
+ * When a story sets `permissions` but not `tenantPermissions`, this is used
103
+ * to auto-derive tenant relations so V2 domain hooks work correctly.
104
+ */
105
+ declare function deriveTenantPermissions(permissions: string[]): Partial<TenantPermissionsMap>;
106
+
107
+ interface PermissionsArgs {
108
+ orgAdmin?: boolean;
109
+ userAccessAdministrator?: boolean;
110
+ }
111
+ interface ChromeArgs {
112
+ environment?: 'prod' | 'stage' | 'ci-beta' | 'ci-stable' | 'qa-beta' | 'qa-stable';
113
+ }
114
+ interface FeatureFlagsArgs {
115
+ [key: string]: boolean | undefined;
116
+ }
117
+ type DecoratorArgs = PermissionsArgs & ChromeArgs & FeatureFlagsArgs;
118
+ type StoryArgs<T = {}> = T & DecoratorArgs;
119
+ declare const DEFAULT_DECORATOR_ARGS: {
120
+ orgAdmin: boolean;
121
+ userAccessAdministrator: boolean;
122
+ environment: string;
123
+ };
124
+ declare const DECORATOR_ARG_TYPES: {
125
+ readonly orgAdmin: {
126
+ readonly control: "boolean";
127
+ readonly description: "Organization admin permissions";
128
+ readonly table: {
129
+ readonly category: "Permissions";
130
+ };
131
+ };
132
+ readonly userAccessAdministrator: {
133
+ readonly control: "boolean";
134
+ readonly description: "User access administrator permissions";
135
+ readonly table: {
136
+ readonly category: "Permissions";
137
+ };
138
+ };
139
+ readonly environment: {
140
+ readonly control: "select";
141
+ readonly options: readonly ["prod", "stage", "ci-beta", "ci-stable", "qa-beta", "qa-stable"];
142
+ readonly description: "Environment for Chrome API";
143
+ readonly table: {
144
+ readonly category: "Chrome";
145
+ };
146
+ };
147
+ };
148
+
149
+ export { type ChromeConfig, ChromeContext, ChromeProvider, DECORATOR_ARG_TYPES, DEFAULT_DECORATOR_ARGS, type DecoratorArgs, EMPTY_TENANT_PERMISSIONS, EMPTY_WORKSPACE_PERMISSIONS, type Environment, type MockState, type MockUserIdentity, type StoryArgs, type StoryParameters, StorybookMockContext, StorybookMockProvider, type TenantPermissionsMap, type WorkspacePermissionsMap, deriveTenantPermissions, useMockState };
package/dist/index.js ADDED
@@ -0,0 +1,97 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
+
3
+
4
+ var _chunkYTIDUO5Ejs = require('./chunk-YTIDUO5E.js');
5
+
6
+
7
+
8
+ var _chunkNXYQ66I7js = require('./chunk-NXYQ66I7.js');
9
+
10
+
11
+
12
+
13
+
14
+
15
+ var _chunkKVKMLDB5js = require('./chunk-KVKMLDB5.js');
16
+
17
+ // lib/providers/ChromeProvider.tsx
18
+ var _react = require('react');
19
+ var _jsxruntime = require('react/jsx-runtime');
20
+ var ChromeContext = _react.createContext.call(void 0, {
21
+ environment: "prod"
22
+ });
23
+ var ChromeProvider = ({
24
+ value,
25
+ children
26
+ }) => /* @__PURE__ */ _jsxruntime.jsx.call(void 0, ChromeContext.Provider, { value, children });
27
+
28
+ // lib/helpers/derive-tenant-permissions.ts
29
+ function hasPermission(permissions, perm) {
30
+ return permissions.some((p) => {
31
+ if (p === perm) return true;
32
+ const [pApp, pRes, pAct] = p.split(":");
33
+ const [rApp, rRes, rAct] = perm.split(":");
34
+ if (pApp !== rApp) return false;
35
+ if (pRes !== "*" && pRes !== rRes) return false;
36
+ if (pAct !== "*" && pAct !== rAct) return false;
37
+ return true;
38
+ });
39
+ }
40
+ function deriveTenantPermissions(permissions) {
41
+ const has = (perm) => hasPermission(permissions, perm);
42
+ return {
43
+ ..._chunkKVKMLDB5js.EMPTY_TENANT_PERMISSIONS,
44
+ rbac_roles_read: has("rbac:role:read"),
45
+ rbac_roles_write: has("rbac:role:write"),
46
+ rbac_groups_read: has("rbac:group:read"),
47
+ rbac_groups_write: has("rbac:group:write"),
48
+ rbac_principal_read: has("rbac:principal:read"),
49
+ // Workspace tenant-level permissions (inventory:groups:* → rbac_workspace_*)
50
+ rbac_workspace_view: has("inventory:groups:read"),
51
+ rbac_workspace_edit: has("inventory:groups:write"),
52
+ rbac_workspace_create: has("inventory:groups:write"),
53
+ rbac_workspace_delete: has("inventory:groups:write"),
54
+ rbac_workspace_move: has("inventory:groups:write")
55
+ };
56
+ }
57
+
58
+ // lib/types.ts
59
+ var DEFAULT_DECORATOR_ARGS = {
60
+ orgAdmin: false,
61
+ userAccessAdministrator: false,
62
+ environment: "prod"
63
+ };
64
+ var DECORATOR_ARG_TYPES = {
65
+ orgAdmin: {
66
+ control: "boolean",
67
+ description: "Organization admin permissions",
68
+ table: { category: "Permissions" }
69
+ },
70
+ userAccessAdministrator: {
71
+ control: "boolean",
72
+ description: "User access administrator permissions",
73
+ table: { category: "Permissions" }
74
+ },
75
+ environment: {
76
+ control: "select",
77
+ options: ["prod", "stage", "ci-beta", "ci-stable", "qa-beta", "qa-stable"],
78
+ description: "Environment for Chrome API",
79
+ table: { category: "Chrome" }
80
+ }
81
+ };
82
+
83
+
84
+
85
+
86
+
87
+
88
+
89
+
90
+
91
+
92
+
93
+
94
+
95
+
96
+
97
+ exports.ChromeContext = ChromeContext; exports.ChromeProvider = ChromeProvider; exports.DECORATOR_ARG_TYPES = DECORATOR_ARG_TYPES; exports.DEFAULT_DECORATOR_ARGS = DEFAULT_DECORATOR_ARGS; exports.EMPTY_TENANT_PERMISSIONS = _chunkKVKMLDB5js.EMPTY_TENANT_PERMISSIONS; exports.EMPTY_WORKSPACE_PERMISSIONS = _chunkKVKMLDB5js.EMPTY_WORKSPACE_PERMISSIONS; exports.FeatureFlagsContext = _chunkNXYQ66I7js.FeatureFlagsContext; exports.FeatureFlagsProvider = _chunkNXYQ66I7js.FeatureFlagsProvider; exports.StorybookMockContext = _chunkKVKMLDB5js.StorybookMockContext; exports.StorybookMockProvider = _chunkKVKMLDB5js.StorybookMockProvider; exports.chromeAppNavClickSpy = _chunkYTIDUO5Ejs.chromeAppNavClickSpy; exports.configureChromeMock = _chunkYTIDUO5Ejs.configureChromeMock; exports.deriveTenantPermissions = deriveTenantPermissions; exports.useMockState = _chunkKVKMLDB5js.useMockState;
package/dist/index.mjs ADDED
@@ -0,0 +1,97 @@
1
+ import {
2
+ chromeAppNavClickSpy,
3
+ configureChromeMock
4
+ } from "./chunk-EPJ4YIIZ.mjs";
5
+ import {
6
+ FeatureFlagsContext,
7
+ FeatureFlagsProvider
8
+ } from "./chunk-WZJQMQID.mjs";
9
+ import {
10
+ EMPTY_TENANT_PERMISSIONS,
11
+ EMPTY_WORKSPACE_PERMISSIONS,
12
+ StorybookMockContext,
13
+ StorybookMockProvider,
14
+ useMockState
15
+ } from "./chunk-UCQY2VRL.mjs";
16
+
17
+ // lib/providers/ChromeProvider.tsx
18
+ import { createContext } from "react";
19
+ import { jsx } from "react/jsx-runtime";
20
+ var ChromeContext = createContext({
21
+ environment: "prod"
22
+ });
23
+ var ChromeProvider = ({
24
+ value,
25
+ children
26
+ }) => /* @__PURE__ */ jsx(ChromeContext.Provider, { value, children });
27
+
28
+ // lib/helpers/derive-tenant-permissions.ts
29
+ function hasPermission(permissions, perm) {
30
+ return permissions.some((p) => {
31
+ if (p === perm) return true;
32
+ const [pApp, pRes, pAct] = p.split(":");
33
+ const [rApp, rRes, rAct] = perm.split(":");
34
+ if (pApp !== rApp) return false;
35
+ if (pRes !== "*" && pRes !== rRes) return false;
36
+ if (pAct !== "*" && pAct !== rAct) return false;
37
+ return true;
38
+ });
39
+ }
40
+ function deriveTenantPermissions(permissions) {
41
+ const has = (perm) => hasPermission(permissions, perm);
42
+ return {
43
+ ...EMPTY_TENANT_PERMISSIONS,
44
+ rbac_roles_read: has("rbac:role:read"),
45
+ rbac_roles_write: has("rbac:role:write"),
46
+ rbac_groups_read: has("rbac:group:read"),
47
+ rbac_groups_write: has("rbac:group:write"),
48
+ rbac_principal_read: has("rbac:principal:read"),
49
+ // Workspace tenant-level permissions (inventory:groups:* → rbac_workspace_*)
50
+ rbac_workspace_view: has("inventory:groups:read"),
51
+ rbac_workspace_edit: has("inventory:groups:write"),
52
+ rbac_workspace_create: has("inventory:groups:write"),
53
+ rbac_workspace_delete: has("inventory:groups:write"),
54
+ rbac_workspace_move: has("inventory:groups:write")
55
+ };
56
+ }
57
+
58
+ // lib/types.ts
59
+ var DEFAULT_DECORATOR_ARGS = {
60
+ orgAdmin: false,
61
+ userAccessAdministrator: false,
62
+ environment: "prod"
63
+ };
64
+ var DECORATOR_ARG_TYPES = {
65
+ orgAdmin: {
66
+ control: "boolean",
67
+ description: "Organization admin permissions",
68
+ table: { category: "Permissions" }
69
+ },
70
+ userAccessAdministrator: {
71
+ control: "boolean",
72
+ description: "User access administrator permissions",
73
+ table: { category: "Permissions" }
74
+ },
75
+ environment: {
76
+ control: "select",
77
+ options: ["prod", "stage", "ci-beta", "ci-stable", "qa-beta", "qa-stable"],
78
+ description: "Environment for Chrome API",
79
+ table: { category: "Chrome" }
80
+ }
81
+ };
82
+ export {
83
+ ChromeContext,
84
+ ChromeProvider,
85
+ DECORATOR_ARG_TYPES,
86
+ DEFAULT_DECORATOR_ARGS,
87
+ EMPTY_TENANT_PERMISSIONS,
88
+ EMPTY_WORKSPACE_PERMISSIONS,
89
+ FeatureFlagsContext,
90
+ FeatureFlagsProvider,
91
+ StorybookMockContext,
92
+ StorybookMockProvider,
93
+ chromeAppNavClickSpy,
94
+ configureChromeMock,
95
+ deriveTenantPermissions,
96
+ useMockState
97
+ };
@@ -0,0 +1,17 @@
1
+ interface CreateMainConfigOptions {
2
+ stories?: string[];
3
+ extraAddons?: any[];
4
+ staticDirs?: string[];
5
+ extraAliases?: Record<string, string>;
6
+ extraWebpackRules?: any[];
7
+ webpackFallback?: Record<string, string | false>;
8
+ webpackPlugins?: any[];
9
+ docs?: Record<string, any>;
10
+ typescript?: Record<string, any>;
11
+ remarkPlugins?: any[];
12
+ msw?: boolean;
13
+ a11y?: boolean;
14
+ }
15
+ declare function createMainConfig(options?: CreateMainConfigOptions): Record<string, any>;
16
+
17
+ export { createMainConfig };
@@ -0,0 +1,17 @@
1
+ interface CreateMainConfigOptions {
2
+ stories?: string[];
3
+ extraAddons?: any[];
4
+ staticDirs?: string[];
5
+ extraAliases?: Record<string, string>;
6
+ extraWebpackRules?: any[];
7
+ webpackFallback?: Record<string, string | false>;
8
+ webpackPlugins?: any[];
9
+ docs?: Record<string, any>;
10
+ typescript?: Record<string, any>;
11
+ remarkPlugins?: any[];
12
+ msw?: boolean;
13
+ a11y?: boolean;
14
+ }
15
+ declare function createMainConfig(options?: CreateMainConfigOptions): Record<string, any>;
16
+
17
+ export { createMainConfig };
@@ -0,0 +1,96 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }// lib/main/createMainConfig.ts
2
+ var _path = require('path'); var _path2 = _interopRequireDefault(_path);
3
+ var _url = require('url');
4
+ function createMainConfig(options = {}) {
5
+ const {
6
+ stories = ["../src/**/*.mdx", "../src/**/*.stories.@(js|jsx|mjs|ts|tsx)"],
7
+ extraAddons = [],
8
+ staticDirs,
9
+ extraAliases = {},
10
+ extraWebpackRules = [],
11
+ webpackFallback,
12
+ webpackPlugins = [],
13
+ docs = { defaultName: "Documentation" },
14
+ typescript,
15
+ remarkPlugins,
16
+ msw = true,
17
+ a11y = true
18
+ } = options;
19
+ const addons = ["@storybook/addon-webpack5-compiler-swc"];
20
+ if (_optionalChain([remarkPlugins, 'optionalAccess', _ => _.length])) {
21
+ addons.push({
22
+ name: "@storybook/addon-docs",
23
+ options: {
24
+ mdxPluginOptions: {
25
+ mdxCompileOptions: {
26
+ remarkPlugins
27
+ }
28
+ }
29
+ }
30
+ });
31
+ } else {
32
+ addons.push("@storybook/addon-docs");
33
+ }
34
+ if (msw) {
35
+ addons.push("msw-storybook-addon");
36
+ }
37
+ if (a11y) {
38
+ addons.push("@storybook/addon-a11y");
39
+ }
40
+ addons.push(...extraAddons);
41
+ const currentDir = typeof __dirname !== "undefined" ? __dirname : _path2.default.dirname(_url.fileURLToPath.call(void 0, import.meta.url));
42
+ const hubMocksDir = _path2.default.resolve(currentDir, "mocks");
43
+ const config = {
44
+ stories,
45
+ addons,
46
+ framework: {
47
+ name: "@storybook/react-webpack5",
48
+ options: {}
49
+ },
50
+ docs,
51
+ typescript: _nullishCoalesce(typescript, () => ( {
52
+ check: false,
53
+ reactDocgen: "react-docgen-typescript",
54
+ reactDocgenTypescriptOptions: {
55
+ shouldExtractLiteralValuesFromEnum: true,
56
+ propFilter: (prop) => prop.parent ? !/node_modules/.test(prop.parent.fileName) : true
57
+ }
58
+ })),
59
+ webpackFinal: async (webpackConfig) => {
60
+ webpackConfig.resolve = {
61
+ ...webpackConfig.resolve,
62
+ alias: {
63
+ ..._optionalChain([webpackConfig, 'access', _2 => _2.resolve, 'optionalAccess', _3 => _3.alias]),
64
+ "@redhat-cloud-services/frontend-components/useChrome": _path2.default.join(hubMocksDir, "useChrome.js"),
65
+ "@redhat-cloud-services/frontend-components-utilities/RBACHook": _path2.default.join(hubMocksDir, "RBACHook.js"),
66
+ "@unleash/proxy-client-react": _path2.default.join(hubMocksDir, "unleash.js"),
67
+ "@project-kessel/react-kessel-access-check": _path2.default.join(hubMocksDir, "kesselAccessCheck.js"),
68
+ ...extraAliases
69
+ },
70
+ fallback: {
71
+ ..._optionalChain([webpackConfig, 'access', _4 => _4.resolve, 'optionalAccess', _5 => _5.fallback]),
72
+ ...webpackFallback
73
+ }
74
+ };
75
+ webpackConfig.module = webpackConfig.module || {};
76
+ webpackConfig.module.rules = webpackConfig.module.rules || [];
77
+ webpackConfig.module.rules.push({
78
+ test: /\.s[ac]ss$/i,
79
+ use: ["style-loader", "css-loader", "sass-loader"]
80
+ });
81
+ webpackConfig.module.rules.push(...extraWebpackRules);
82
+ if (webpackPlugins.length) {
83
+ webpackConfig.plugins = webpackConfig.plugins || [];
84
+ webpackConfig.plugins.push(...webpackPlugins);
85
+ }
86
+ return webpackConfig;
87
+ }
88
+ };
89
+ if (staticDirs) {
90
+ config.staticDirs = staticDirs;
91
+ }
92
+ return config;
93
+ }
94
+
95
+
96
+ exports.createMainConfig = createMainConfig;
@@ -0,0 +1,96 @@
1
+ // lib/main/createMainConfig.ts
2
+ import path from "path";
3
+ import { fileURLToPath } from "url";
4
+ function createMainConfig(options = {}) {
5
+ const {
6
+ stories = ["../src/**/*.mdx", "../src/**/*.stories.@(js|jsx|mjs|ts|tsx)"],
7
+ extraAddons = [],
8
+ staticDirs,
9
+ extraAliases = {},
10
+ extraWebpackRules = [],
11
+ webpackFallback,
12
+ webpackPlugins = [],
13
+ docs = { defaultName: "Documentation" },
14
+ typescript,
15
+ remarkPlugins,
16
+ msw = true,
17
+ a11y = true
18
+ } = options;
19
+ const addons = ["@storybook/addon-webpack5-compiler-swc"];
20
+ if (remarkPlugins?.length) {
21
+ addons.push({
22
+ name: "@storybook/addon-docs",
23
+ options: {
24
+ mdxPluginOptions: {
25
+ mdxCompileOptions: {
26
+ remarkPlugins
27
+ }
28
+ }
29
+ }
30
+ });
31
+ } else {
32
+ addons.push("@storybook/addon-docs");
33
+ }
34
+ if (msw) {
35
+ addons.push("msw-storybook-addon");
36
+ }
37
+ if (a11y) {
38
+ addons.push("@storybook/addon-a11y");
39
+ }
40
+ addons.push(...extraAddons);
41
+ const currentDir = typeof __dirname !== "undefined" ? __dirname : path.dirname(fileURLToPath(import.meta.url));
42
+ const hubMocksDir = path.resolve(currentDir, "mocks");
43
+ const config = {
44
+ stories,
45
+ addons,
46
+ framework: {
47
+ name: "@storybook/react-webpack5",
48
+ options: {}
49
+ },
50
+ docs,
51
+ typescript: typescript ?? {
52
+ check: false,
53
+ reactDocgen: "react-docgen-typescript",
54
+ reactDocgenTypescriptOptions: {
55
+ shouldExtractLiteralValuesFromEnum: true,
56
+ propFilter: (prop) => prop.parent ? !/node_modules/.test(prop.parent.fileName) : true
57
+ }
58
+ },
59
+ webpackFinal: async (webpackConfig) => {
60
+ webpackConfig.resolve = {
61
+ ...webpackConfig.resolve,
62
+ alias: {
63
+ ...webpackConfig.resolve?.alias,
64
+ "@redhat-cloud-services/frontend-components/useChrome": path.join(hubMocksDir, "useChrome.js"),
65
+ "@redhat-cloud-services/frontend-components-utilities/RBACHook": path.join(hubMocksDir, "RBACHook.js"),
66
+ "@unleash/proxy-client-react": path.join(hubMocksDir, "unleash.js"),
67
+ "@project-kessel/react-kessel-access-check": path.join(hubMocksDir, "kesselAccessCheck.js"),
68
+ ...extraAliases
69
+ },
70
+ fallback: {
71
+ ...webpackConfig.resolve?.fallback,
72
+ ...webpackFallback
73
+ }
74
+ };
75
+ webpackConfig.module = webpackConfig.module || {};
76
+ webpackConfig.module.rules = webpackConfig.module.rules || [];
77
+ webpackConfig.module.rules.push({
78
+ test: /\.s[ac]ss$/i,
79
+ use: ["style-loader", "css-loader", "sass-loader"]
80
+ });
81
+ webpackConfig.module.rules.push(...extraWebpackRules);
82
+ if (webpackPlugins.length) {
83
+ webpackConfig.plugins = webpackConfig.plugins || [];
84
+ webpackConfig.plugins.push(...webpackPlugins);
85
+ }
86
+ return webpackConfig;
87
+ }
88
+ };
89
+ if (staticDirs) {
90
+ config.staticDirs = staticDirs;
91
+ }
92
+ return config;
93
+ }
94
+ export {
95
+ createMainConfig
96
+ };
@@ -0,0 +1,7 @@
1
+ interface UsePermissionsResult {
2
+ hasAccess: boolean;
3
+ isLoading: boolean;
4
+ }
5
+ declare const usePermissions: (_app: string, requiredPermissions: string[], _disableCache?: boolean, checkAll?: boolean) => UsePermissionsResult;
6
+
7
+ export { usePermissions as default };
@@ -0,0 +1,7 @@
1
+ interface UsePermissionsResult {
2
+ hasAccess: boolean;
3
+ isLoading: boolean;
4
+ }
5
+ declare const usePermissions: (_app: string, requiredPermissions: string[], _disableCache?: boolean, checkAll?: boolean) => UsePermissionsResult;
6
+
7
+ export { usePermissions as default };
@@ -0,0 +1,26 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
+
3
+ var _chunkKVKMLDB5js = require('../chunk-KVKMLDB5.js');
4
+
5
+ // lib/mocks/RBACHook.ts
6
+ var _react = require('react');
7
+ var matchPermission = (granted, required) => {
8
+ if (granted === required) return true;
9
+ const [gApp, gResource, gAction] = granted.split(":");
10
+ const [rApp, rResource, rAction] = required.split(":");
11
+ if (gApp !== rApp) return false;
12
+ if (gResource !== "*" && gResource !== rResource) return false;
13
+ if (gAction !== "*" && gAction !== rAction) return false;
14
+ return true;
15
+ };
16
+ var usePermissions = (_app, requiredPermissions, _disableCache, checkAll) => {
17
+ const mock = _chunkKVKMLDB5js.useMockState.call(void 0, );
18
+ const mockRef = _react.useRef.call(void 0, mock);
19
+ mockRef.current = mock;
20
+ const hasAccess = checkAll ? requiredPermissions.every((req) => mockRef.current.permissions.some((granted) => matchPermission(granted, req))) : requiredPermissions.some((req) => mockRef.current.permissions.some((granted) => matchPermission(granted, req)));
21
+ return { hasAccess, isLoading: false };
22
+ };
23
+ var RBACHook_default = usePermissions;
24
+
25
+
26
+ exports.default = RBACHook_default;
@@ -0,0 +1,26 @@
1
+ import {
2
+ useMockState
3
+ } from "../chunk-UCQY2VRL.mjs";
4
+
5
+ // lib/mocks/RBACHook.ts
6
+ import { useRef } from "react";
7
+ var matchPermission = (granted, required) => {
8
+ if (granted === required) return true;
9
+ const [gApp, gResource, gAction] = granted.split(":");
10
+ const [rApp, rResource, rAction] = required.split(":");
11
+ if (gApp !== rApp) return false;
12
+ if (gResource !== "*" && gResource !== rResource) return false;
13
+ if (gAction !== "*" && gAction !== rAction) return false;
14
+ return true;
15
+ };
16
+ var usePermissions = (_app, requiredPermissions, _disableCache, checkAll) => {
17
+ const mock = useMockState();
18
+ const mockRef = useRef(mock);
19
+ mockRef.current = mock;
20
+ const hasAccess = checkAll ? requiredPermissions.every((req) => mockRef.current.permissions.some((granted) => matchPermission(granted, req))) : requiredPermissions.some((req) => mockRef.current.permissions.some((granted) => matchPermission(granted, req)));
21
+ return { hasAccess, isLoading: false };
22
+ };
23
+ var RBACHook_default = usePermissions;
24
+ export {
25
+ RBACHook_default as default
26
+ };