@asteby/metacore-permissions 0.0.0-stage → 0.1.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/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for describing the origin of the Work and
141
+ reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2026 Asteby, Inc.
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/README.md CHANGED
@@ -1,3 +1,38 @@
1
- # Temporary Holding Version
1
+ # @asteby/metacore-permissions
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Capability feed, role/grant API, screen-implied capabilities, nav gating and a
4
+ ready-made `PermissionsPage` built on `PermissionsManager`. Transport, labels,
5
+ navigation and translation are all injected - nothing here knows about a host
6
+ app or vertical.
7
+
8
+ ## Adoption
9
+
10
+ ```tsx
11
+ import {
12
+ createPermissionsApi, createScreenCapabilityRegistry, PermissionsPage,
13
+ useMyPermissions, filterNavGroupsByCan,
14
+ } from '@asteby/metacore-permissions'
15
+
16
+ const registry = createScreenCapabilityRegistry({
17
+ modules: { product: 'Products' }, // labels for implied caps
18
+ groups: { product: 'Catalog' },
19
+ screenAccess: t('permissions.access'),
20
+ })
21
+ const api = createPermissionsApi({ http: axiosInstance, registry })
22
+ // custom routes: createPermissionsApi({ http, paths: { me: '/v2/me' } })
23
+ ```
24
+
25
+ 1. **Session feed** - `useMyPermissions({ fetch: api.fetchMyPermissions, userId, scope })`
26
+ returns `{ permissions, role, isAdmin }` (persisted per scope for first paint);
27
+ feed it to `PermissionsProvider` from `@asteby/metacore-runtime-react`.
28
+ 2. **Page** - `<PermissionsPage api={api} groups={navGroups} extraItems={addonItems} registry={registry} translate={t} labels={{ title: t('permissions.title') }} />`.
29
+ States: loading (aria-busy skeleton), error (role=alert + retry), empty, ready.
30
+ Syncing invalidates `MY_PERMISSIONS_QUERY_KEY` so the signed-in user's gating refreshes.
31
+ 3. **Nav gating** - `filterNavGroupsByCan(groups, can, { trusted: sidebarTrustedPaths(host, addon), adminShellUrls })`.
32
+ Rules: `/m/<model>` needs `<model>.index`; addon screens need `screen.<slug>.access`;
33
+ `adminShellUrls` (default: small generic set) need the same probe; `folderKey` needs
34
+ `folder.<key>.access`; server-trusted leaves skip legacy probes.
35
+
36
+ Peers: `@asteby/metacore-runtime-react`, `@asteby/metacore-ui`, `@tanstack/react-query`, `react`.
37
+ Backend contract: `GET /permissions/me`, `GET /permissions/modules` (`modules`, `general`,
38
+ `screen_implies`; legacy `data[]` accepted), roles CRUD and `POST .../sync` (full replace).
@@ -0,0 +1,8 @@
1
+ export * from './types';
2
+ export * from './screen-capability-implies';
3
+ export * from './nav-permission-filter';
4
+ export * from './permissions-api';
5
+ export * from './use-my-permissions';
6
+ export * from './use-permissions-catalog';
7
+ export * from './permissions-page';
8
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAA;AACvB,cAAc,6BAA6B,CAAA;AAC3C,cAAc,yBAAyB,CAAA;AACvC,cAAc,mBAAmB,CAAA;AACjC,cAAc,sBAAsB,CAAA;AACpC,cAAc,2BAA2B,CAAA;AACzC,cAAc,oBAAoB,CAAA"}
package/dist/index.js ADDED
@@ -0,0 +1,8 @@
1
+ export * from './types';
2
+ export * from './screen-capability-implies';
3
+ export * from './nav-permission-filter';
4
+ export * from './permissions-api';
5
+ export * from './use-my-permissions';
6
+ export * from './use-permissions-catalog';
7
+ export * from './permissions-page';
8
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAA;AACvB,cAAc,6BAA6B,CAAA;AAC3C,cAAc,yBAAyB,CAAA;AACvC,cAAc,mBAAmB,CAAA;AACjC,cAAc,sBAAsB,CAAA;AACpC,cAAc,2BAA2B,CAAA;AACzC,cAAc,oBAAoB,CAAA"}
@@ -0,0 +1,56 @@
1
+ /**
2
+ * Pure nav permission helpers - free of React so tests and sidebars share the
3
+ * same gating rules.
4
+ */
5
+ import type { CanFn } from '@asteby/metacore-runtime-react';
6
+ import type { NavItemLike } from './types';
7
+ /**
8
+ * Generic host-shell routes hidden from capability-limited roles. Hosts pass
9
+ * their own set through `adminShellUrls`; this default is intentionally small.
10
+ */
11
+ export declare const DEFAULT_ADMIN_SHELL_URLS: ReadonlySet<string>;
12
+ /** Per-leaf predicate (e.g. the SDK's `useNavItemVisible`). */
13
+ export type NavLeafVisible = (item: {
14
+ url: string;
15
+ requires?: string;
16
+ }) => boolean;
17
+ export interface FilterNavOptions {
18
+ /** Leaf paths the server already authorised (skip legacy probes). */
19
+ trusted?: ReadonlySet<string>;
20
+ isItemVisible?: NavLeafVisible;
21
+ /** Routes requiring `screen.<slug>.access`. Defaults to DEFAULT_ADMIN_SHELL_URLS. */
22
+ adminShellUrls?: ReadonlySet<string>;
23
+ /** Prefix of addon screens gated by `screen.<slug>.access`. Default `/addons/`. */
24
+ addonUrlPrefix?: string;
25
+ }
26
+ /** Roles allowed to open admin-only viewers. */
27
+ export declare function isAdminRole(role: string | undefined | null, roles?: readonly string[]): boolean;
28
+ /** `/m/pos_orders?f_x=1` -> `pos_orders`; non-model URLs -> null. */
29
+ export declare function navUrlModel(url: unknown): string | null;
30
+ /** Normalised key used to match a nav leaf against the server-approved set. */
31
+ export declare function trustKey(url: unknown): string;
32
+ /** Leaf paths the server already authorised (server-filtered navigation). */
33
+ export declare function collectTrustedPaths(groups: ReadonlyArray<{
34
+ items: NavItemLike[];
35
+ }>): Set<string>;
36
+ /** Trusted set for a sidebar: host nav plus addon module items. */
37
+ export declare function sidebarTrustedPaths(hostGroups: ReadonlyArray<{
38
+ items: NavItemLike[];
39
+ }>, addonModuleItems: NavItemLike[]): Set<string>;
40
+ /** First leaf URL under a nav tree. */
41
+ export declare function firstLeafUrl(items: NavItemLike[]): string | undefined;
42
+ /**
43
+ * Single gating point for nav items:
44
+ * - trusted leaves skip the legacy probes
45
+ * - `/m/<model>` requires `can(<model>.index)`
46
+ * - addon screens require `can(screen.<slug>.access)`
47
+ * - admin shell routes require `can(screen.<slug>.access)` (admins pass)
48
+ * - folders require `can(folder.<key>.access)`
49
+ * - collapsible parents follow their children
50
+ */
51
+ export declare function filterNavItemsByCan<T extends NavItemLike>(items: T[], can: CanFn, options?: FilterNavOptions): T[];
52
+ /** Applies {@link filterNavItemsByCan} per group and drops emptied groups. */
53
+ export declare function filterNavGroupsByCan<G extends {
54
+ items: NavItemLike[];
55
+ }>(groups: G[], can: CanFn, options?: FilterNavOptions): G[];
56
+ //# sourceMappingURL=nav-permission-filter.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"nav-permission-filter.d.ts","sourceRoot":"","sources":["../src/nav-permission-filter.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,gCAAgC,CAAA;AAE3D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,SAAS,CAAA;AAI1C;;;GAGG;AACH,eAAO,MAAM,wBAAwB,EAAE,WAAW,CAAC,MAAM,CAOvD,CAAA;AAEF,+DAA+D;AAC/D,MAAM,MAAM,cAAc,GAAG,CAAC,IAAI,EAAE;IAAE,GAAG,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,EAAE,MAAM,CAAA;CAAE,KAAK,OAAO,CAAA;AAElF,MAAM,WAAW,gBAAgB;IAC/B,qEAAqE;IACrE,OAAO,CAAC,EAAE,WAAW,CAAC,MAAM,CAAC,CAAA;IAC7B,aAAa,CAAC,EAAE,cAAc,CAAA;IAC9B,qFAAqF;IACrF,cAAc,CAAC,EAAE,WAAW,CAAC,MAAM,CAAC,CAAA;IACpC,mFAAmF;IACnF,cAAc,CAAC,EAAE,MAAM,CAAA;CACxB;AAED,gDAAgD;AAChD,wBAAgB,WAAW,CACzB,IAAI,EAAE,MAAM,GAAG,SAAS,GAAG,IAAI,EAC/B,KAAK,GAAE,SAAS,MAAM,EAAqC,GAC1D,OAAO,CAET;AAOD,qEAAqE;AACrE,wBAAgB,WAAW,CAAC,GAAG,EAAE,OAAO,GAAG,MAAM,GAAG,IAAI,CAIvD;AAED,+EAA+E;AAC/E,wBAAgB,QAAQ,CAAC,GAAG,EAAE,OAAO,GAAG,MAAM,CAK7C;AAQD,6EAA6E;AAC7E,wBAAgB,mBAAmB,CACjC,MAAM,EAAE,aAAa,CAAC;IAAE,KAAK,EAAE,WAAW,EAAE,CAAA;CAAE,CAAC,GAC9C,GAAG,CAAC,MAAM,CAAC,CAab;AAED,mEAAmE;AACnE,wBAAgB,mBAAmB,CACjC,UAAU,EAAE,aAAa,CAAC;IAAE,KAAK,EAAE,WAAW,EAAE,CAAA;CAAE,CAAC,EACnD,gBAAgB,EAAE,WAAW,EAAE,GAC9B,GAAG,CAAC,MAAM,CAAC,CAEb;AAED,uCAAuC;AACvC,wBAAgB,YAAY,CAAC,KAAK,EAAE,WAAW,EAAE,GAAG,MAAM,GAAG,SAAS,CAUrE;AAED;;;;;;;;GAQG;AACH,wBAAgB,mBAAmB,CAAC,CAAC,SAAS,WAAW,EACvD,KAAK,EAAE,CAAC,EAAE,EACV,GAAG,EAAE,KAAK,EACV,OAAO,GAAE,gBAAqB,GAC7B,CAAC,EAAE,CAoCL;AAED,8EAA8E;AAC9E,wBAAgB,oBAAoB,CAAC,CAAC,SAAS;IAAE,KAAK,EAAE,WAAW,EAAE,CAAA;CAAE,EACrE,MAAM,EAAE,CAAC,EAAE,EACX,GAAG,EAAE,KAAK,EACV,OAAO,GAAE,gBAAqB,GAC7B,CAAC,EAAE,CAIL"}
@@ -0,0 +1,129 @@
1
+ import { screenKeyForUrl } from './screen-capability-implies';
2
+ const DYNAMIC_MODEL_URL_RE = /^\/m\/([^/?#]+)/;
3
+ /**
4
+ * Generic host-shell routes hidden from capability-limited roles. Hosts pass
5
+ * their own set through `adminShellUrls`; this default is intentionally small.
6
+ */
7
+ export const DEFAULT_ADMIN_SHELL_URLS = new Set([
8
+ '/users',
9
+ '/permissions',
10
+ '/organizations',
11
+ '/marketplace',
12
+ '/integrations',
13
+ '/activity',
14
+ ]);
15
+ /** Roles allowed to open admin-only viewers. */
16
+ export function isAdminRole(role, roles = ['owner', 'admin', 'superadmin']) {
17
+ return roles.includes((role ?? '').toLowerCase());
18
+ }
19
+ function navPath(url) {
20
+ if (typeof url !== 'string' || !url)
21
+ return null;
22
+ return url.split(/[?#]/)[0] || null;
23
+ }
24
+ /** `/m/pos_orders?f_x=1` -> `pos_orders`; non-model URLs -> null. */
25
+ export function navUrlModel(url) {
26
+ if (typeof url !== 'string')
27
+ return null;
28
+ const m = DYNAMIC_MODEL_URL_RE.exec(url);
29
+ return m?.[1] ? decodeURIComponent(m[1]).toLowerCase() : null;
30
+ }
31
+ /** Normalised key used to match a nav leaf against the server-approved set. */
32
+ export function trustKey(url) {
33
+ const s = typeof url === 'string' ? url : undefined;
34
+ const addon = s ? /^addon:\/\/([^/?#]+)\/?([^?#]*)/.exec(s) : null;
35
+ const resolved = addon ? `/addons/${addon[1]}/${addon[2]}`.replace(/\/+$/, '') : s;
36
+ return (navPath(resolved)?.replace(/\/+$/, '') ?? '').toLowerCase();
37
+ }
38
+ function isCollapsible(item) {
39
+ return Array.isArray(item.items) && item.items.length > 0;
40
+ }
41
+ /** Leaf paths the server already authorised (server-filtered navigation). */
42
+ export function collectTrustedPaths(groups) {
43
+ const out = new Set();
44
+ const walk = (items) => {
45
+ for (const item of items) {
46
+ if (isCollapsible(item))
47
+ walk(item.items);
48
+ else {
49
+ const k = trustKey(item.url);
50
+ if (k)
51
+ out.add(k);
52
+ }
53
+ }
54
+ };
55
+ for (const g of groups)
56
+ walk(g.items);
57
+ return out;
58
+ }
59
+ /** Trusted set for a sidebar: host nav plus addon module items. */
60
+ export function sidebarTrustedPaths(hostGroups, addonModuleItems) {
61
+ return collectTrustedPaths([...hostGroups, { items: addonModuleItems }]);
62
+ }
63
+ /** First leaf URL under a nav tree. */
64
+ export function firstLeafUrl(items) {
65
+ for (const item of items) {
66
+ if (isCollapsible(item)) {
67
+ const nested = firstLeafUrl(item.items);
68
+ if (nested)
69
+ return nested;
70
+ continue;
71
+ }
72
+ if (typeof item.url === 'string' && item.url)
73
+ return item.url;
74
+ }
75
+ return undefined;
76
+ }
77
+ /**
78
+ * Single gating point for nav items:
79
+ * - trusted leaves skip the legacy probes
80
+ * - `/m/<model>` requires `can(<model>.index)`
81
+ * - addon screens require `can(screen.<slug>.access)`
82
+ * - admin shell routes require `can(screen.<slug>.access)` (admins pass)
83
+ * - folders require `can(folder.<key>.access)`
84
+ * - collapsible parents follow their children
85
+ */
86
+ export function filterNavItemsByCan(items, can, options = {}) {
87
+ const { trusted, isItemVisible, adminShellUrls = DEFAULT_ADMIN_SHELL_URLS, addonUrlPrefix = '/addons/', } = options;
88
+ const visible = [];
89
+ for (const item of items) {
90
+ if (item.folderKey && !can(`folder.${item.folderKey}.access`))
91
+ continue;
92
+ if (isCollapsible(item)) {
93
+ const children = filterNavItemsByCan(item.items, can, options);
94
+ if (children.length === 0)
95
+ continue;
96
+ const url = navUrlModel(item.url)
97
+ ? (firstLeafUrl(children) ?? children[0]?.url)
98
+ : item.url;
99
+ visible.push({ ...item, url, items: children });
100
+ continue;
101
+ }
102
+ const url = typeof item.url === 'string' ? item.url : undefined;
103
+ const isTrusted = trusted?.has(trustKey(url)) ?? false;
104
+ const model = navUrlModel(url);
105
+ if (!isTrusted && model && !can(`${model}.index`))
106
+ continue;
107
+ if (!isTrusted && !model && url?.startsWith(addonUrlPrefix)) {
108
+ if (!can(`${screenKeyForUrl(url)}.access`))
109
+ continue;
110
+ }
111
+ const path = navPath(url);
112
+ if (path && adminShellUrls.has(path)) {
113
+ if (!can(`${screenKeyForUrl(path)}.access`))
114
+ continue;
115
+ }
116
+ if (!isTrusted && isItemVisible && url && !isItemVisible({ url, requires: item.requires })) {
117
+ continue;
118
+ }
119
+ visible.push(item);
120
+ }
121
+ return visible;
122
+ }
123
+ /** Applies {@link filterNavItemsByCan} per group and drops emptied groups. */
124
+ export function filterNavGroupsByCan(groups, can, options = {}) {
125
+ return groups
126
+ .map((g) => ({ ...g, items: filterNavItemsByCan(g.items, can, options) }))
127
+ .filter((g) => g.items.length > 0);
128
+ }
129
+ //# sourceMappingURL=nav-permission-filter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"nav-permission-filter.js","sourceRoot":"","sources":["../src/nav-permission-filter.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAA;AAG7D,MAAM,oBAAoB,GAAG,iBAAiB,CAAA;AAE9C;;;GAGG;AACH,MAAM,CAAC,MAAM,wBAAwB,GAAwB,IAAI,GAAG,CAAC;IACnE,QAAQ;IACR,cAAc;IACd,gBAAgB;IAChB,cAAc;IACd,eAAe;IACf,WAAW;CACZ,CAAC,CAAA;AAeF,gDAAgD;AAChD,MAAM,UAAU,WAAW,CACzB,IAA+B,EAC/B,QAA2B,CAAC,OAAO,EAAE,OAAO,EAAE,YAAY,CAAC;IAE3D,OAAO,KAAK,CAAC,QAAQ,CAAC,CAAC,IAAI,IAAI,EAAE,CAAC,CAAC,WAAW,EAAE,CAAC,CAAA;AACnD,CAAC;AAED,SAAS,OAAO,CAAC,GAAY;IAC3B,IAAI,OAAO,GAAG,KAAK,QAAQ,IAAI,CAAC,GAAG;QAAE,OAAO,IAAI,CAAA;IAChD,OAAO,GAAG,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,IAAI,IAAI,CAAA;AACrC,CAAC;AAED,qEAAqE;AACrE,MAAM,UAAU,WAAW,CAAC,GAAY;IACtC,IAAI,OAAO,GAAG,KAAK,QAAQ;QAAE,OAAO,IAAI,CAAA;IACxC,MAAM,CAAC,GAAG,oBAAoB,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;IACxC,OAAO,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,kBAAk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ACrC,IAAI,CAAC,GAAG,CAAC,GAAG,eAAe,CAAC,IAAI,CAAC,SAAS,CAAC;gBAAE,SAAQ;QACvD,CAAC;QACD,IAAI,CAAC,SAAS,IAAI,aAAa,IAAI,GAAG,IAAI,CAAC,aAAa,CAAC,EAAE,GAAG,EAAE,QAAQ,EAAE,IAAI,CAAC,QAAQ,EAAE,CAAC,EAAE,CAAC;YAC3F,SAAQ;QACV,CAAC;QACD,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;IACpB,CAAC;IACD,OAAO,OAAO,CAAA;AAChB,CAAC;AAED,8EAA8E;AAC9E,MAAM,UAAU,oBAAoB,CAClC,MAAW,EACX,GAAU,EACV,UAA4B,EAAE;IAE9B,OAAO,MAAM;SACV,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,EAAE,GAAG,CAAC,EAAE,KAAK,EAAE,mBAAmB,CAAC,CAAC,CAAC,KAAK,EAAE,GAAG,EAAE,OAAO,CAAC,EAAE,CAAC,CAAC;SACzE,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,CAAA;AACtC,CAAC"}
@@ -0,0 +1,43 @@
1
+ /**
2
+ * Permissions transport. Everything goes through an injected HTTP client so the
3
+ * package works with any axios-like instance and any route layout.
4
+ */
5
+ import type { PermissionsCatalog, RoleDef, RoleInput } from '@asteby/metacore-runtime-react';
6
+ import type { ScreenCapabilityRegistry } from './screen-capability-implies';
7
+ import type { PermissionsHttpClient } from './types';
8
+ export interface MyPermissions {
9
+ permissions: string[];
10
+ role: string;
11
+ isAdmin: boolean;
12
+ }
13
+ export declare const MY_PERMISSIONS_QUERY_KEY: readonly ["permissions", "me"];
14
+ /** Per-user key: SPA account switches never reuse another session's caps. */
15
+ export declare function myPermissionsQueryKey(userId: string | undefined | null): readonly ["permissions", "me", string];
16
+ export interface PermissionsApiPaths {
17
+ me: string;
18
+ modules: string;
19
+ roles: string;
20
+ /** `:id` is appended. */
21
+ rolePermissions: string;
22
+ }
23
+ export declare const DEFAULT_PERMISSIONS_PATHS: PermissionsApiPaths;
24
+ export interface PermissionsApiOptions {
25
+ http: PermissionsHttpClient;
26
+ paths?: Partial<PermissionsApiPaths>;
27
+ /** Registry fed by `screen_implies` and used to expand grants. Optional. */
28
+ registry?: ScreenCapabilityRegistry;
29
+ /** Default icon for new roles. */
30
+ defaultRoleIcon?: string;
31
+ }
32
+ export interface PermissionsApi {
33
+ fetchMyPermissions(): Promise<MyPermissions>;
34
+ loadPermissionModules(): Promise<PermissionsCatalog>;
35
+ loadRoles(): Promise<RoleDef[]>;
36
+ createRole(input: RoleInput): Promise<RoleDef | void>;
37
+ updateRole(roleId: string, input: RoleInput): Promise<RoleDef | void>;
38
+ deleteRole(roleId: string): Promise<void>;
39
+ loadRolePermissions(roleId: string): Promise<string[]>;
40
+ syncRolePermissions(roleId: string, capabilities: string[]): Promise<void>;
41
+ }
42
+ export declare function createPermissionsApi(opts: PermissionsApiOptions): PermissionsApi;
43
+ //# sourceMappingURL=permissions-api.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"permissions-api.d.ts","sourceRoot":"","sources":["../src/permissions-api.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,KAAK,EAGV,kBAAkB,EAClB,OAAO,EACP,SAAS,EACV,MAAM,gCAAgC,CAAA;AACvC,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,6BAA6B,CAAA;AAC3E,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,SAAS,CAAA;AAEpD,MAAM,WAAW,aAAa;IAC5B,WAAW,EAAE,MAAM,EAAE,CAAA;IACrB,IAAI,EAAE,MAAM,CAAA;IACZ,OAAO,EAAE,OAAO,CAAA;CACjB;AAED,eAAO,MAAM,wBAAwB,gCAAiC,CAAA;AAEtE,6EAA6E;AAC7E,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS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'me'];
2
+ /** Per-user key: SPA account switches never reuse another session's caps. */
3
+ export function myPermissionsQueryKey(userId) {
4
+ return [...MY_PERMISSIONS_QUERY_KEY, userId ?? 'anon'];
5
+ }
6
+ export const DEFAULT_PERMISSIONS_PATHS = {
7
+ me: '/permissions/me',
8
+ modules: '/permissions/modules',
9
+ roles: '/data/roles/me',
10
+ rolePermissions: '/permissions/role',
11
+ };
12
+ const CRUD_ACTION_KEYS = new Set(['index', 'create', 'update', 'delete', 'export', 'import']);
13
+ function toRoleDef(row) {
14
+ return {
15
+ id: row.id,
16
+ name: row.name,
17
+ label: row.label || undefined,
18
+ color: row.color || undefined,
19
+ icon: row.icon || undefined,
20
+ };
21
+ }
22
+ function asRole(data) {
23
+ const body = data;
24
+ const row = (body?.data ?? body);
25
+ if (row && typeof row.id === 'string' && typeof row.name === 'string')
26
+ return toRoleDef(row);
27
+ return undefined;
28
+ }
29
+ export function createPermissionsApi(opts) {
30
+ const { http, registry } = opts;
31
+ const paths = { ...DEFAULT_PERMISSIONS_PATHS, ...opts.paths };
32
+ const expand = (caps) => (registry ? registry.expand(caps) : caps);
33
+ return {
34
+ async fetchMyPermissions() {
35
+ const res = await http.get(paths.me);
36
+ const body = (res.data ?? {});
37
+ return {
38
+ permissions: Array.isArray(body.permissions) ? body.permissions : [],
39
+ role: typeof body.role === 'string' ? body.role : '',
40
+ // accept both casings so either side of a backend rollout works
41
+ isAdmin: Boolean(body.isAdmin ?? body.is_admin),
42
+ };
43
+ },
44
+ /**
45
+ * Accepts `{ modules, general, screen_implies }` (current contract) or the
46
+ * legacy `{ data: [{key, actions[]}] }` array.
47
+ */
48
+ async loadPermissionModules() {
49
+ const res = await http.get(paths.modules);
50
+ const body = (res.data ?? {});
51
+ if (body.screen_implies && typeof body.screen_implies === 'object') {
52
+ registry?.set(body.screen_implies);
53
+ }
54
+ const general = Array.isArray(body.general)
55
+ ? body.general
56
+ : [];
57
+ if (Array.isArray(body.modules) && body.modules.length > 0) {
58
+ return { modules: body.modules, general };
59
+ }
60
+ const legacy = Array.isArray(body.data) ? body.data : [];
61
+ return {
62
+ modules: legacy.map((m) => ({
63
+ key: m.key,
64
+ label: m.label || m.key,
65
+ actions: (m.actions ?? []).map((key) => ({
66
+ key,
67
+ label: m.actionLabels?.[key] || key,
68
+ icon: m.actionIcons?.[key],
69
+ kind: CRUD_ACTION_KEYS.has(key) ? 'crud' : 'custom',
70
+ })),
71
+ })),
72
+ general,
73
+ };
74
+ },
75
+ async loadRoles() {
76
+ const res = await http.get(paths.roles);
77
+ const body = res.data;
78
+ const rows = body?.data ?? body;
79
+ return (Array.isArray(rows) ? rows : []).map(toRoleDef);
80
+ },
81
+ async createRole(input) {
82
+ const res = await http.post(paths.roles, {
83
+ name: input.name,
84
+ label: input.label ?? input.name,
85
+ color: input.color ?? '',
86
+ icon: input.icon ?? opts.defaultRoleIcon ?? 'Shield',
87
+ });
88
+ return asRole(res.data);
89
+ },
90
+ async updateRole(roleId, input) {
91
+ const res = await http.put(`${paths.roles}/${encodeURIComponent(roleId)}`, {
92
+ name: input.name,
93
+ label: input.label ?? input.name,
94
+ color: input.color ?? '',
95
+ icon: input.icon ?? '',
96
+ });
97
+ return asRole(res.data);
98
+ },
99
+ async deleteRole(roleId) {
100
+ await http.delete(`${paths.roles}/${encodeURIComponent(roleId)}`);
101
+ },
102
+ async loadRolePermissions(roleId) {
103
+ const res = await http.get(`${paths.rolePermissions}/${encodeURIComponent(roleId)}`);
104
+ const data = res.data?.data;
105
+ return expand(Array.isArray(data) ? data : []);
106
+ },
107
+ /** Full-replace sync; screen access grants are expanded to their deps. */
108
+ async syncRolePermissions(roleId, capabilities) {
109
+ await http.post(`${paths.rolePermissions}/${encodeURIComponent(roleId)}/sync`, {
110
+ permissions: expand(capabilities),
111
+ });
112
+ },
113
+ };
114
+ }
115
+ //# sourceMappingURL=permissions-api.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"permissions-api.js","sourceRoot":"","sources":["../src/permissions-api.ts"],"names":[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AC;QAED,KAAK,CAAC,mBAAmB,CAAC,MAAM;YAC9B,MAAM,GAAG,GAAG,MAAM,IAAI,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC,eAAe,IAAI,kBAAkB,CAAC,MAAM,CAAC,EAAE,CAAC,CAAA;YACpF,MAAM,IAAI,GAAI,GAAG,CAAC,IAAuC,EAAE,IAAI,CAAA;YAC/D,OAAO,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAE,IAAiB,CAAC,CAAC,CAAC,EAAE,CAAC,CAAA;QAC9D,CAAC;QAED,0EAA0E;QAC1E,KAAK,CAAC,mBAAmB,CAAC,MAAM,EAAE,YAAY;YAC5C,MAAM,IAAI,CAAC,IAAI,CAAC,GAAG,KAAK,CAAC,eAAe,IAAI,kBAAkB,CAAC,MAAM,CAAC,OAAO,EAAE;gBAC7E,WAAW,EAAE,MAAM,CAAC,YAAY,CAAC;aAClC,CAAC,CAAA;QACJ,CAAC;KACF,CAAA;AACH,CAAC"}
@@ -0,0 +1,24 @@
1
+ import { type ReactNode } from 'react';
2
+ import { type PermissionsApi } from './permissions-api';
3
+ import { type UsePermissionsCatalogOptions } from './use-permissions-catalog';
4
+ export interface PermissionsPageLabels {
5
+ title?: string;
6
+ loading?: string;
7
+ error?: string;
8
+ retry?: string;
9
+ empty?: string;
10
+ }
11
+ export interface PermissionsPageProps extends Omit<UsePermissionsCatalogOptions, 'loadBackendCatalog'> {
12
+ api: PermissionsApi;
13
+ labels?: PermissionsPageLabels;
14
+ /** Extra content rendered above the manager (e.g. a breadcrumb). */
15
+ header?: ReactNode;
16
+ className?: string;
17
+ }
18
+ /**
19
+ * Role x module x action grid. States: loading (skeleton, aria-busy), error
20
+ * (alert + retry), empty (status) and ready (PermissionsManager). After a sync
21
+ * the signed-in user's own capability feed is invalidated.
22
+ */
23
+ export declare function PermissionsPage({ api, labels, header, className, ...catalogOpts }: PermissionsPageProps): import("react").JSX.Element;
24
+ //# sourceMappingURL=permissions-page.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"permissions-page.d.ts","sourceRoot":"","sources":["../src/permissions-page.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAe,KAAK,SAAS,EAAE,MAAM,OAAO,CAAA;AAInD,OAAO,EAA4B,KAAK,cAAc,EAAE,MAAM,mBAAmB,CAAA;AACjF,OAAO,EAAyB,KAAK,4BAA4B,EAAE,MAAM,2BAA2B,CAAA;AAEpG,MAAM,WAAW,qBAAqB;IACpC,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,KAAK,CAAC,EAAE,MAAM,CAAA;CACf;AAED,MAAM,WAAW,oBACf,SAAQ,IAAI,CAAC,4BAA4B,EAAE,oBAAoB,CAAC;IAChE,GAAG,EAAE,cAAc,CAAA;IACnB,MAAM,CAAC,EAAE,qBAAqB,CAAA;IAC9B,oEAAoE;IACpE,MAAM,CAAC,EAAE,SAAS,CAAA;IAClB,SAAS,CAAC,EAAE,MAAM,CAAA;CACnB;AAUD;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,GAAG,WAAW,EAAE,EAAE,oBAAoB,+BA4DvG"}
@@ -0,0 +1,43 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useCallback } from 'react';
3
+ import { useQueryClient } from '@tanstack/react-query';
4
+ import { PermissionsManager } from '@asteby/metacore-runtime-react';
5
+ import { Button, Skeleton } from '@asteby/metacore-ui';
6
+ import { MY_PERMISSIONS_QUERY_KEY } from './permissions-api';
7
+ import { usePermissionsCatalog } from './use-permissions-catalog';
8
+ const DEFAULT_LABELS = {
9
+ title: 'Permissions',
10
+ loading: 'Loading permissions',
11
+ error: 'Could not load the permission catalog.',
12
+ retry: 'Retry',
13
+ empty: 'No modules available to assign.',
14
+ };
15
+ /**
16
+ * Role x module x action grid. States: loading (skeleton, aria-busy), error
17
+ * (alert + retry), empty (status) and ready (PermissionsManager). After a sync
18
+ * the signed-in user's own capability feed is invalidated.
19
+ */
20
+ export function PermissionsPage({ api, labels, header, className, ...catalogOpts }) {
21
+ const l = { ...DEFAULT_LABELS, ...labels };
22
+ const qc = useQueryClient();
23
+ const cat = usePermissionsCatalog({ ...catalogOpts, loadBackendCatalog: api.loadPermissionModules });
24
+ const handleSync = useCallback(async (roleId, capabilities) => {
25
+ await api.syncRolePermissions(roleId, capabilities);
26
+ await qc.invalidateQueries({ queryKey: MY_PERMISSIONS_QUERY_KEY });
27
+ }, [api, qc]);
28
+ let body;
29
+ if (cat.isError) {
30
+ body = (_jsxs("div", { role: "alert", className: "flex flex-col items-start gap-3 text-sm", children: [_jsx("p", { className: "text-destructive", children: l.error }), _jsx(Button, { type: "button", variant: "outline", onClick: cat.retry, children: l.retry })] }));
31
+ }
32
+ else if (cat.ready) {
33
+ body = (_jsx(PermissionsManager, { title: l.title, loadModules: cat.loadModules, loadRoles: api.loadRoles, loadRolePermissions: api.loadRolePermissions, syncRolePermissions: handleSync, createRole: api.createRole, updateRole: api.updateRole, deleteRole: api.deleteRole }));
34
+ }
35
+ else if (cat.isLoading) {
36
+ body = (_jsxs("div", { role: "status", "aria-busy": "true", "aria-label": l.loading, className: "flex flex-col gap-4", children: [_jsx(Skeleton, { className: "h-9 w-64" }), _jsxs("div", { className: "grid grid-cols-1 gap-4 lg:grid-cols-2", children: [_jsx(Skeleton, { className: "h-72 w-full" }), _jsx(Skeleton, { className: "h-72 w-full" })] })] }));
37
+ }
38
+ else {
39
+ body = (_jsx("p", { role: "status", className: "text-sm text-muted-foreground", children: l.empty }));
40
+ }
41
+ return (_jsxs("div", { className: className ?? 'h-full overflow-y-auto p-6', children: [header, body] }));
42
+ }
43
+ //# sourceMappingURL=permissions-page.js.map
@@ -0,0 +1 @@
1
+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;IAED,OAAO,CACL,eAAK,SAAS,EAAE,SAAS,IAAI,4BAA4B,aACtD,MAAM,EACN,IAAI,IACD,CACP,CAAA;AACH,CAAC"}
@@ -0,0 +1,39 @@
1
+ /**
2
+ * Screen -> implied model capabilities.
3
+ *
4
+ * A "screen" grant (`screen.<slug>.access`) can imply model CRUD capabilities
5
+ * (declared by addon manifests as `requires_capabilities`). The host feeds the
6
+ * map in (usually from `GET /permissions/modules` -> `screen_implies`); labels
7
+ * are injected, nothing here knows about a specific addon or vertical.
8
+ */
9
+ import type { ModuleGroup, PermissionActionDef } from '@asteby/metacore-runtime-react';
10
+ export interface ScreenCapabilityLabels {
11
+ /** action key -> label (`index` -> "List / read"). Unknown keys render raw. */
12
+ actions?: Record<string, string>;
13
+ /** module key -> label. Unknown keys render raw. */
14
+ modules?: Record<string, string>;
15
+ /** module key -> section title for the shortcut badges. */
16
+ groups?: Record<string, string>;
17
+ /** Section for modules not present in `groups`. */
18
+ fallbackGroup?: string;
19
+ /** Title of the "implied API dependencies" catalog group. */
20
+ impliedGroupTitle?: string;
21
+ /** Label of the per-screen access action. */
22
+ screenAccess?: string;
23
+ /** Icon names understood by the PermissionsManager. */
24
+ dependencyIcon?: string;
25
+ }
26
+ export interface ScreenCapabilityRegistry {
27
+ set(map: Record<string, string[]> | null | undefined): void;
28
+ get(): Record<string, string[]>;
29
+ summarizeImpliedModules(screenAccessCap: string): string;
30
+ impliedShortcutActions(screenAccessCap: string): PermissionActionDef[];
31
+ expand(grant: string[]): string[];
32
+ buildImpliedApiModuleGroup(): ModuleGroup;
33
+ /** The screen "access" action definition (label injected). */
34
+ screenAction(): PermissionActionDef;
35
+ }
36
+ /** Route -> screen capability key: `/addons/x/y` -> `screen.addons.x.y`. */
37
+ export declare function screenKeyForUrl(url: string): string;
38
+ export declare function createScreenCapabilityRegistry(labels?: ScreenCapabilityLabels): ScreenCapabilityRegistry;
39
+ //# sourceMappingURL=screen-capability-implies.d.ts.map
@@ -0,0 +1 @@
1
+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8B,CAC5C,MAAM,GAAE,sBAA2B,GAClC,wBAAwB,CA8F1B"}
@@ -0,0 +1,119 @@
1
+ const DEFAULT_ACTION_LABELS = {
2
+ index: 'List / read',
3
+ create: 'Create',
4
+ update: 'Update',
5
+ delete: 'Delete',
6
+ };
7
+ /** Route -> screen capability key: `/addons/x/y` -> `screen.addons.x.y`. */
8
+ export function screenKeyForUrl(url) {
9
+ const slug = url
10
+ .replace(/^\/+/, '')
11
+ .replace(/[?#].*$/, '')
12
+ .replace(/[^a-zA-Z0-9]+/g, '.')
13
+ .replace(/\.+$/, '')
14
+ .toLowerCase();
15
+ return `screen.${slug || 'root'}`;
16
+ }
17
+ export function createScreenCapabilityRegistry(labels = {}) {
18
+ let implies = {};
19
+ const actionLabels = { ...DEFAULT_ACTION_LABELS, ...labels.actions };
20
+ const moduleLabels = labels.modules ?? {};
21
+ const groups = labels.groups ?? {};
22
+ const fallbackGroup = labels.fallbackGroup ?? 'Other APIs';
23
+ const icon = labels.dependencyIcon ?? 'Link2';
24
+ const split = (cap) => {
25
+ const dot = cap.indexOf('.');
26
+ return dot > 0 ? [cap.slice(0, dot), cap.slice(dot + 1)] : [cap, cap];
27
+ };
28
+ return {
29
+ set(map) {
30
+ implies = map && typeof map === 'object' ? { ...map } : {};
31
+ },
32
+ get: () => ({ ...implies }),
33
+ summarizeImpliedModules(cap) {
34
+ const caps = implies[cap];
35
+ if (!caps?.length)
36
+ return '';
37
+ const mods = new Set();
38
+ for (const c of caps) {
39
+ const mod = c.split('.')[0];
40
+ if (mod)
41
+ mods.add(moduleLabels[mod] ?? mod);
42
+ }
43
+ return [...mods].sort((a, b) => a.localeCompare(b)).join(', ');
44
+ },
45
+ impliedShortcutActions(cap) {
46
+ const caps = implies[cap];
47
+ if (!caps?.length)
48
+ return [];
49
+ return caps.map((c) => {
50
+ const [mod, action] = split(c);
51
+ return {
52
+ key: c,
53
+ label: moduleLabels[mod] ?? mod,
54
+ description: actionLabels[action] ?? action,
55
+ icon,
56
+ kind: 'dependency',
57
+ capability: c,
58
+ group: groups[mod] ?? fallbackGroup,
59
+ };
60
+ });
61
+ },
62
+ expand(grant) {
63
+ const seen = new Set();
64
+ const out = [];
65
+ const add = (name) => {
66
+ const n = name.trim();
67
+ if (!n || seen.has(n))
68
+ return;
69
+ seen.add(n);
70
+ out.push(n);
71
+ };
72
+ for (const name of grant)
73
+ add(name);
74
+ for (const name of grant)
75
+ for (const i of implies[name] ?? [])
76
+ add(i);
77
+ return out;
78
+ },
79
+ buildImpliedApiModuleGroup() {
80
+ const byModule = new Map();
81
+ for (const caps of Object.values(implies)) {
82
+ for (const c of caps) {
83
+ if (c.indexOf('.') <= 0)
84
+ continue;
85
+ const [mod, action] = split(c);
86
+ let set = byModule.get(mod);
87
+ if (!set)
88
+ byModule.set(mod, (set = new Set()));
89
+ set.add(action);
90
+ }
91
+ }
92
+ const modules = [...byModule.entries()]
93
+ .sort(([a], [b]) => a.localeCompare(b))
94
+ .map(([key, actions]) => ({
95
+ key,
96
+ label: moduleLabels[key] ?? key,
97
+ kind: 'model',
98
+ icon,
99
+ actions: [...actions].sort().map((a) => ({
100
+ key: a,
101
+ label: actionLabels[a] ?? a,
102
+ kind: 'crud',
103
+ })),
104
+ }));
105
+ return {
106
+ title: labels.impliedGroupTitle ??
107
+ 'API dependencies - granted with screen access (not shown in the menu)',
108
+ modules,
109
+ };
110
+ },
111
+ screenAction: () => ({
112
+ key: 'access',
113
+ label: labels.screenAccess ?? 'Access',
114
+ icon: 'Eye',
115
+ kind: 'screen',
116
+ }),
117
+ };
118
+ }
119
+ //# sourceMappingURL=screen-capability-implies.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"screen-capability-implies.js","sourceRoot":"","sources":["../src/screen-capability-implies.ts"],"names":[],"mappings":"AA+BA,MAAM,qBAAqB,GAA2B;IACpD,KAAK,EAAE,aAAa;IACpB,MAAM,EAAE,QAAQ;IAChB,MAAM,EAAE,QAAQ;IAChB,MAAM,EAAE,QAAQ;CACjB,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CAAC,GAAG,CAAC,GAAG,EAAE,CAAC,GAAG,GAAG,IAAI,GAAG,EAAE,CAAC,CAAC,CAAA;oBAC9C,GAAG,CAAC,GAAG,CAAC,MAAM,CAAC,CAAA;gBACjB,CAAC;YACH,CAAC;YACD,MAAM,OAAO,GAA0B,CAAC,GAAG,QAAQ,CAAC,OAAO,EAAE,CAAC;iBAC3D,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC;iBACtC,GAAG,CAAC,CAAC,CAAC,GAAG,EAAE,OAAO,CAAC,EAAE,EAAE,CAAC,CAAC;gBACxB,GAAG;gBACH,KAAK,EAAE,YAAY,CAAC,GAAG,CAAC,IAAI,GAAG;gBAC/B,IAAI,EAAE,OAAgB;gBACtB,IAAI;gBACJ,OAAO,EAAE,CAAC,GAAG,OAAO,CAAC,CAAC,IAAI,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;oBACvC,GAAG,EAAE,CAAC;oBACN,KAAK,EAAE,YAAY,CAAC,CAAC,CAAC,IAAI,CAAC;oBAC3B,IAAI,EAAE,MAAe;iBACtB,CAAC,CAAC;aACJ,CAAC,CAAC,CAAA;YACL,OAAO;gBACL,KAAK,EACH,MAAM,CAAC,iBAAiB;oBACxB,uEAAuE;gBACzE,OAAO;aACR,CAAA;QACH,CAAC;QACD,YAAY,EAAE,GAAG,EAAE,CAAC,CAAC;YACnB,GAAG,EAAE,QAAQ;YACb,KAAK,EAAE,MAAM,CAAC,YAAY,IAAI,QAAQ;YACtC,IAAI,EAAE,KAAK;YACX,IAAI,EAAE,QAAQ;SACf,CAAC;KACH,CAAA;AACH,CAAC"}
@@ -0,0 +1,29 @@
1
+ /** Minimal HTTP surface the package needs. An axios instance satisfies it. */
2
+ export interface PermissionsHttpClient {
3
+ get(url: string): Promise<{
4
+ data?: unknown;
5
+ }>;
6
+ post(url: string, body?: unknown): Promise<{
7
+ data?: unknown;
8
+ }>;
9
+ put(url: string, body?: unknown): Promise<{
10
+ data?: unknown;
11
+ }>;
12
+ delete(url: string): Promise<{
13
+ data?: unknown;
14
+ }>;
15
+ }
16
+ /** Structural nav item — compatible with the SDK's NavItem and with host types. */
17
+ export interface NavItemLike {
18
+ title: string;
19
+ url?: string | unknown;
20
+ icon?: unknown;
21
+ items?: NavItemLike[];
22
+ requires?: string;
23
+ folderKey?: string;
24
+ }
25
+ export interface NavGroupLike<T extends NavItemLike = NavItemLike> {
26
+ title: string;
27
+ items: T[];
28
+ }
29
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,8EAA8E;AAC9E,MAAM,WAAW,qBAAqB;IACpC,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;QAAE,IAAI,CAAC,EAAE,OAAO,CAAA;KAAE,CAAC,CAAA;IAC7C,IAAI,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC;QAAE,IAAI,CAAC,EAAE,OAAO,CAAA;KAAE,CAAC,CAAA;IAC9D,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC;QAAE,IAAI,CAAC,EAAE,OAAO,CAAA;KAAE,CAAC,CAAA;IAC7D,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;QAAE,IAAI,CAAC,EAAE,OAAO,CAAA;KAAE,CAAC,CAAA;CACjD;AAED,mFAAmF;AACnF,MAAM,WAAW,WAAW;IAC1B,KAAK,EAAE,MAAM,CAAA;IACb,GAAG,CAAC,EAAE,MAAM,GAAG,OAAO,CAAA;IACtB,IAAI,CAAC,EAAE,OAAO,CAAA;IACd,KAAK,CAAC,EAAE,WAAW,EAAE,CAAA;IACrB,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,SAAS,CAAC,EAAE,MAAM,CAAA;CACnB;AAED,MAAM,WAAW,YAAY,CAAC,CAAC,SAAS,WAAW,GAAG,WAAW;IAC/D,KAAK,EAAE,MAAM,CAAA;IACb,KAAK,EAAE,CAAC,EAAE,CAAA;CACX"}
package/dist/types.js ADDED
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
@@ -0,0 +1,24 @@
1
+ import { type MyPermissions } from './permissions-api';
2
+ export interface UseMyPermissionsOptions {
3
+ /** Loader, usually `api.fetchMyPermissions`. */
4
+ fetch: () => Promise<MyPermissions>;
5
+ /** Signed-in user id; the query is disabled while empty. */
6
+ userId: string | undefined | null;
7
+ /**
8
+ * Cache scope (org/user) for the persisted first-paint snapshot. When
9
+ * null/undefined (e.g. before the org is known) the query still runs, but
10
+ * nothing is read from or written to the snapshot: a scopeless entry could
11
+ * leak one org's capabilities to another on a shared browser.
12
+ */
13
+ scope: string | null | undefined;
14
+ /** localStorage namespace of the snapshot. Default `metacore:permissions-me`. */
15
+ snapshotKey?: string;
16
+ staleTime?: number;
17
+ }
18
+ /**
19
+ * The signed-in user's capability feed, seeded from a persisted per-scope
20
+ * snapshot so gated UI does not reorder on reload. UI gating only - the server
21
+ * still enforces every capability.
22
+ */
23
+ export declare function useMyPermissions(opts: UseMyPermissionsOptions): import("@tanstack/react-query").UseQueryResult<MyPermissions, Error>;
24
+ //# sourceMappingURL=use-my-permissions.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-my-permissions.d.ts","sourceRoot":"","sources":["../src/use-my-permissions.ts"],"names":[],"mappings":"AAKA,OAAO,EAAyB,KAAK,aAAa,EAAE,MAAM,mBAAmB,CAAA;AAE7E,MAAM,WAAW,uBAAuB;IACtC,gDAAgD;IAChD,KAAK,EAAE,MAAM,OAAO,CAAC,aAAa,CAAC,CAAA;IACnC,4DAA4D;IAC5D,MAAM,EAAE,MAAM,GAAG,SAAS,GAAG,IAAI,CAAA;IACjC;;;;;OAKG;IACH,KAAK,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,CAAA;IAChC,iFAAiF;IACjF,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,SAAS,CAAC,EAAE,MAAM,CAAA;CACnB;AAED;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,uBAAuB,wEAa7D"}
@@ -0,0 +1,20 @@
1
+ import { createPersistedSnapshot, usePersistedQuery, } from '@asteby/metacore-runtime-react';
2
+ import { useMemo } from 'react';
3
+ import { myPermissionsQueryKey } from './permissions-api';
4
+ /**
5
+ * The signed-in user's capability feed, seeded from a persisted per-scope
6
+ * snapshot so gated UI does not reorder on reload. UI gating only - the server
7
+ * still enforces every capability.
8
+ */
9
+ export function useMyPermissions(opts) {
10
+ const { fetch, userId, scope, snapshotKey = 'metacore:permissions-me', staleTime = 60_000 } = opts;
11
+ const snapshot = useMemo(() => createPersistedSnapshot({ key: snapshotKey, version: 1 }), [snapshotKey]);
12
+ return usePersistedQuery({
13
+ queryKey: myPermissionsQueryKey(userId),
14
+ queryFn: fetch,
15
+ enabled: Boolean(userId),
16
+ staleTime,
17
+ persist: { snapshot, scope },
18
+ });
19
+ }
20
+ //# sourceMappingURL=use-my-permissions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-my-permissions.js","sourceRoot":"","sources":["../src/use-my-permissions.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,uBAAuB,EACvB,iBAAiB,GAClB,MAAM,gCAAgC,CAAA;AACvC,OAAO,EAAE,OAAO,EAAE,MAAM,OAAO,CAAA;AAC/B,OAAO,EAAE,qBAAqB,EAAsB,MAAM,mBAAmB,CAAA;AAmB7E;;;;GAIG;AACH,MAAM,UAAU,gBAAgB,CAAC,IAA6B;IAC5D,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,WAAW,GAAG,yBAAyB,EAAE,SAAS,GAAG,MAAM,EAAE,GAAG,IAAI,CAAA;IAClG,MAAM,QAAQ,GAAG,OAAO,CACtB,GAAG,EAAE,CAAC,uBAAuB,CAAgB,EAAE,GAAG,EAAE,WAAW,EAAE,OAAO,EAAE,CAAC,EAAE,CAAC,EAC9E,CAAC,WAAW,CAAC,CACd,CAAA;IACD,OAAO,iBAAiB,CAAgB;QACtC,QAAQ,EAAE,qBAAqB,CAAC,MAAM,CAAC;QACvC,OAAO,EAAE,KAAK;QACd,OAAO,EAAE,OAAO,CAAC,MAAM,CAAC;QACxB,SAAS;QACT,OAAO,EAAE,EAAE,QAAQ,EAAE,KAAK,EAAE;KAC7B,CAAC,CAAA;AACJ,CAAC"}
@@ -0,0 +1,46 @@
1
+ import type { GeneralPermissionDef, ModuleGroup, PermissionActionDef, PermissionsCatalog } from '@asteby/metacore-runtime-react';
2
+ import { type ScreenCapabilityRegistry } from './screen-capability-implies';
3
+ import type { NavGroupLike, NavItemLike } from './types';
4
+ export interface BuildCatalogInput {
5
+ /** Host navigation groups. */
6
+ groups: NavGroupLike[];
7
+ /** Extra module items (e.g. addon contributions). */
8
+ extraItems?: NavItemLike[];
9
+ /** Backend action catalog. */
10
+ backend: PermissionsCatalog;
11
+ /** Title translator for nav titles. */
12
+ translate?: (s: string) => string;
13
+ registry?: ScreenCapabilityRegistry;
14
+ /** Fallback screen action when no registry is given. */
15
+ screenAction?: PermissionActionDef;
16
+ }
17
+ /** Pure: crosses the nav with the backend action catalog. */
18
+ export declare function buildCatalogFromNav(input: BuildCatalogInput): {
19
+ groups: ModuleGroup[];
20
+ general: GeneralPermissionDef[];
21
+ };
22
+ export interface UsePermissionsCatalogOptions {
23
+ /** Live nav groups (the host's navigation query result). */
24
+ groups: NavGroupLike[];
25
+ extraItems?: NavItemLike[];
26
+ /** Loads the backend catalog, usually `api.loadPermissionModules`. */
27
+ loadBackendCatalog: () => Promise<PermissionsCatalog>;
28
+ translate?: (s: string) => string;
29
+ registry?: ScreenCapabilityRegistry;
30
+ /** Gate extra readiness (e.g. nav still loading). Default true. */
31
+ navReady?: boolean;
32
+ queryKey?: readonly unknown[];
33
+ }
34
+ /**
35
+ * Returns `{ loadModules, ready, isError, error, retry }`. Render the
36
+ * PermissionsManager only when `ready` - it loads its catalog once on mount.
37
+ */
38
+ export declare function usePermissionsCatalog(opts: UsePermissionsCatalogOptions): {
39
+ loadModules: () => Promise<PermissionsCatalog>;
40
+ ready: boolean;
41
+ isLoading: boolean;
42
+ isError: boolean;
43
+ error: Error | null;
44
+ retry: () => undefined;
45
+ };
46
+ //# sourceMappingURL=use-permissions-catalog.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-permissions-catalog.d.ts","sourceRoot":"","sources":["../src/use-permissions-catalog.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EACV,oBAAoB,EACpB,WAAW,EACX,mBAAmB,EAEnB,kBAAkB,EACnB,MAAM,gCAAgC,CAAA;AACvC,OAAO,EAEL,KAAK,wBAAwB,EAC9B,MAAM,6BAA6B,CAAA;AACpC,OAAO,KAAK,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,SAAS,CAAA;AAIxD,MAAM,WAAW,iBAAiB;IAChC,8BAA8B;IAC9B,MAAM,EAAE,YAAY,EAAE,CAAA;IACtB,qDAAqD;IACrD,UAAU,CAAC,EAAE,WAAW,EAAE,CAAA;IAC1B,8BAA8B;IAC9B,OAAO,EAAE,kBAAkB,CAAA;IAC3B,uCAAuC;IACvC,SAAS,CAAC,EAAE,CAAC,CAAC,EAAE,MAAM,KAAK,MAAM,CAAA;IACjC,QAAQ,CAAC,EAAE,wBAAwB,CAAA;IACnC,wDAAwD;IACxD,YAAY,CAAC,EAAE,mBAAmB,CAAA;CACnC;AASD,6DAA6D;AAC7D,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,iBAAiB,GAAG;IAC7D,MAAM,EAAE,WAAW,EAAE,CAAA;IACrB,OAAO,EAAE,oBAAoB,EAAE,CAAA;CAChC,CAkDA;AAED,MAAM,WAAW,4BAA4B;IAC3C,4DAA4D;IAC5D,MAAM,EAAE,YAAY,EAAE,CAAA;IACtB,UAAU,CAAC,EAAE,WAAW,EAAE,CAAA;IAC1B,sEAAsE;IACtE,kBAAkB,EAAE,MAAM,OAAO,CAAC,kBAAkB,CAAC,CAAA;IACrD,SAAS,CAAC,EAAE,CAAC,CAAC,EAAE,MAAM,KAAK,MAAM,CAAA;IACjC,QAAQ,CAAC,EAAE,wBAAwB,CAAA;IACnC,mEAAmE;IACnE,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,QAAQ,CAAC,EAAE,SAAS,OAAO,EAAE,CAAA;CAC9B;AAED;;;GAGG;AACH,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,4BAA4B;uBAY5B,OAAO,CAAC,kBAAkB,CAAC;;;;;;EAUtE"}
@@ -0,0 +1,103 @@
1
+ /**
2
+ * Builds the PermissionsManager catalog from the SAME nav the sidebar renders,
3
+ * so the grid mirrors what users see. The backend supplies the actions per
4
+ * model; the host nav decides which modules appear and how they group.
5
+ */
6
+ import { useCallback, useMemo } from 'react';
7
+ import { useQuery } from '@tanstack/react-query';
8
+ import { screenKeyForUrl, } from './screen-capability-implies';
9
+ const MODEL_URL_RE = /^\/m\/([^/?#]+)/;
10
+ const FALLBACK_SCREEN_ACTION = {
11
+ key: 'access',
12
+ label: 'Access',
13
+ icon: 'Eye',
14
+ kind: 'screen',
15
+ };
16
+ /** Pure: crosses the nav with the backend action catalog. */
17
+ export function buildCatalogFromNav(input) {
18
+ const { backend, registry } = input;
19
+ const tr = input.translate ?? ((s) => s);
20
+ const screenAction = registry?.screenAction() ?? input.screenAction ?? FALLBACK_SCREEN_ACTION;
21
+ const flat = 'groups' in backend ? backend.groups.flatMap((g) => g.modules) : backend.modules;
22
+ const actionsByKey = new Map();
23
+ for (const m of flat)
24
+ actionsByKey.set(m.key.toLowerCase(), m.actions);
25
+ const general = backend.general ?? [];
26
+ const moduleForItem = (item) => {
27
+ const url = typeof item.url === 'string' ? item.url : '';
28
+ const icon = typeof item.icon === 'string' ? item.icon : undefined;
29
+ const m = MODEL_URL_RE.exec(url);
30
+ if (m?.[1]) {
31
+ const table = decodeURIComponent(m[1]).toLowerCase();
32
+ const actions = actionsByKey.get(table);
33
+ if (!actions || actions.length === 0)
34
+ return null;
35
+ return { key: table, label: tr(item.title), icon, kind: 'model', actions };
36
+ }
37
+ if (!url || url === '#')
38
+ return null;
39
+ const screenKey = screenKeyForUrl(url);
40
+ return {
41
+ key: screenKey,
42
+ label: tr(item.title),
43
+ icon,
44
+ kind: 'screen',
45
+ actions: [screenAction, ...(registry?.impliedShortcutActions(`${screenKey}.access`) ?? [])],
46
+ };
47
+ };
48
+ const groups = [];
49
+ const pushGroup = (title, items) => {
50
+ const modules = items.map(moduleForItem).filter((x) => x !== null);
51
+ if (modules.length > 0)
52
+ groups.push({ title, modules });
53
+ };
54
+ for (const g of input.groups) {
55
+ const leaves = [];
56
+ for (const item of g.items) {
57
+ if (item.items && item.items.length > 0)
58
+ pushGroup(tr(item.title), item.items);
59
+ else
60
+ leaves.push(item);
61
+ }
62
+ pushGroup(tr(g.title), leaves);
63
+ }
64
+ for (const item of input.extraItems ?? []) {
65
+ if (item.items && item.items.length > 0)
66
+ pushGroup(tr(item.title), item.items);
67
+ else
68
+ pushGroup(tr(item.title), [item]);
69
+ }
70
+ const implied = registry?.buildImpliedApiModuleGroup();
71
+ if (implied && implied.modules.length > 0)
72
+ groups.push(implied);
73
+ return { groups, general };
74
+ }
75
+ /**
76
+ * Returns `{ loadModules, ready, isError, error, retry }`. Render the
77
+ * PermissionsManager only when `ready` - it loads its catalog once on mount.
78
+ */
79
+ export function usePermissionsCatalog(opts) {
80
+ const { groups, extraItems, loadBackendCatalog, translate, registry, navReady = true } = opts;
81
+ const q = useQuery({
82
+ queryKey: opts.queryKey ?? ['permissions', 'modules', 'catalog'],
83
+ queryFn: loadBackendCatalog,
84
+ staleTime: 60_000,
85
+ });
86
+ const backend = q.data;
87
+ const catalog = useMemo(() => {
88
+ if (!backend || !navReady)
89
+ return { groups: [], general: [] };
90
+ return buildCatalogFromNav({ groups, extraItems, backend, translate, registry });
91
+ }, [groups, extraItems, backend, translate, registry, navReady]);
92
+ const loadModules = useCallback(async () => catalog, [catalog]);
93
+ const retry = useCallback(() => void q.refetch(), [q]);
94
+ return {
95
+ loadModules,
96
+ ready: catalog.groups.length > 0,
97
+ isLoading: q.isLoading || !navReady,
98
+ isError: q.isError,
99
+ error: q.error,
100
+ retry,
101
+ };
102
+ }
103
+ //# sourceMappingURL=use-permissions-catalog.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-permissions-catalog.js","sourceRoot":"","sources":["../src/use-permissions-catalog.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,OAAO,CAAA;AAC5C,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAA;AAQhD,OAAO,EACL,eAAe,GAEhB,MAAM,6BAA6B,CAAA;AAGpC,MAAM,YAAY,GAAG,iBAAiB,CAAA;AAgBtC,MAAM,sBAAsB,GAAwB;IAClD,GAAG,EAAE,QAAQ;IACb,KAAK,EAAE,QAAQ;IACf,IAAI,EAAE,KAAK;IACX,IAAI,EAAE,QAAQ;CACf,CAAA;AAED,6DAA6D;AAC7D,MAAM,UAAU,mBAAmB,CAAC,KAAwB;IAI1D,MAAM,EAAE,OAAO,EAAE,QAAQ,EAAE,GAAG,KAAK,CAAA;IACnC,MAAM,EAAE,GAAG,KAAK,CAAC,SAAS,IAAI,CAAC,CAAC,CAAS,EAAE,EAAE,CAAC,CAAC,CAAC,CAAA;IAChD,MAAM,YAAY,GAAG,QAAQ,EAAE,YAAY,EAAE,IAAI,KAAK,CAAC,YAAY,IAAI,sBAAsB,CAAA;IAC7F,MAAM,IAAI,GAAG,QAAQ,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MAAM,EAAE,UAAU,EAAE,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,CAAC,CAAA;IAClF,CAAC,EAAE,CAAC,MAAM,EAAE,UAAU,EAAE,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,QAAQ,CAAC,CAAC,CAAA;IAChE,MAAM,WAAW,GAAG,WAAW,CAAC,KAAK,IAAiC,EAAE,CAAC,OAAO,EAAE,CAAC,OAAO,CAAC,CAAC,CAAA;IAC5F,MAAM,KAAK,GAAG,WAAW,CAAC,GAAG,EAAE,CAAC,KAAK,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,CAAA;IACtD,OAAO;QACL,WAAW;QACX,KAAK,EAAE,OAAO,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC;QAChC,SAAS,EAAE,CAAC,CAAC,SAAS,IAAI,CAAC,QAAQ;QACnC,OAAO,EAAE,CAAC,CAAC,OAAO;QAClB,KAAK,EAAE,CAAC,CAAC,KAAK;QACd,KAAK;KACN,CAAA;AACH,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,54 @@
1
1
  {
2
2
  "name": "@asteby/metacore-permissions",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "0.1.1",
4
+ "description": "Metacore permissions — capability feed, role/grant API factory, screen-implied capabilities, nav gating and a PermissionsPage, all with injected transport, i18n and nav.",
5
+ "license": "Apache-2.0",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "https://github.com/asteby/metacore-sdk",
9
+ "directory": "packages/permissions"
10
+ },
11
+ "type": "module",
12
+ "main": "./dist/index.js",
13
+ "types": "./dist/index.d.ts",
14
+ "files": [
15
+ "dist",
16
+ "README.md"
17
+ ],
18
+ "exports": {
19
+ ".": {
20
+ "types": "./dist/index.d.ts",
21
+ "import": "./dist/index.js"
22
+ }
23
+ },
24
+ "peerDependencies": {
25
+ "@asteby/metacore-runtime-react": "^50.1.0",
26
+ "@asteby/metacore-ui": "^2.25.0",
27
+ "@tanstack/react-query": ">=5",
28
+ "react": ">=18",
29
+ "react-dom": ">=18"
30
+ },
31
+ "devDependencies": {
32
+ "@asteby/metacore-runtime-react": "50.1.0",
33
+ "@asteby/metacore-ui": "2.25.0",
34
+ "@tanstack/react-query": "^5.95.0",
35
+ "@testing-library/react": "^16.3.2",
36
+ "@types/react": "^19.0.0",
37
+ "@types/react-dom": "^19.0.0",
38
+ "happy-dom": "^20.10.2",
39
+ "react": "^19.2.4",
40
+ "react-dom": "^19.2.4",
41
+ "typescript": "^6.0.0",
42
+ "vitest": "^4.0.0"
43
+ },
44
+ "publishConfig": {
45
+ "access": "public"
46
+ },
47
+ "scripts": {
48
+ "build": "tsc -p tsconfig.json",
49
+ "dev": "tsc -w -p tsconfig.json",
50
+ "typecheck": "tsc -p tsconfig.json --noEmit",
51
+ "clean": "rm -rf dist",
52
+ "test": "vitest run"
53
+ }
6
54
  }