@mintlify/common 1.0.1161 → 1.0.1163

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,12 +1,8 @@
1
+ import { checkGroupAccess } from './groupAccess.js';
1
2
  export function checkNavAccess(page, userGroups, isPreview = false, checkHidden = true) {
2
3
  if (checkHidden && page.hidden)
3
4
  return false;
4
5
  if (isPreview)
5
6
  return true;
6
- const pageGroups = Array.isArray(page.groups) && page.groups.every((pageGroup) => typeof pageGroup === 'string')
7
- ? page.groups
8
- : undefined;
9
- if (!pageGroups)
10
- return true;
11
- return pageGroups.some((pageGroup) => userGroups.has(pageGroup));
7
+ return checkGroupAccess(page.groups, userGroups);
12
8
  }
@@ -0,0 +1,9 @@
1
+ import type { PageGroups } from '@mintlify/models';
2
+ export declare const WILDCARD_GROUP = "*";
3
+ export type NormalizedGroups = {
4
+ includes: string[] | undefined;
5
+ excludes: string[];
6
+ };
7
+ export declare const isPageGroups: (value: unknown) => value is PageGroups;
8
+ export declare function normalizeGroups(groups: PageGroups | undefined): NormalizedGroups | undefined;
9
+ export declare function checkGroupAccess(groups: PageGroups | undefined, readerGroups: ReadonlySet<string>): boolean;
@@ -0,0 +1,46 @@
1
+ export const WILDCARD_GROUP = '*';
2
+ const isStringArray = (value) => Array.isArray(value) && value.every((item) => typeof item === 'string');
3
+ const isGroupRule = (value) => typeof value === 'object' &&
4
+ value !== null &&
5
+ !Array.isArray(value) &&
6
+ (!('includes' in value) || value.includes === undefined || isStringArray(value.includes)) &&
7
+ (!('excludes' in value) || value.excludes === undefined || isStringArray(value.excludes));
8
+ export const isPageGroups = (value) => isStringArray(value) || (Array.isArray(value) && value.every(isGroupRule));
9
+ const DENY_ALL = { includes: [], excludes: [] };
10
+ export function normalizeGroups(groups) {
11
+ var _a;
12
+ if (groups == null)
13
+ return undefined;
14
+ if (!isPageGroups(groups))
15
+ return DENY_ALL;
16
+ if (isStringArray(groups))
17
+ return { includes: groups, excludes: [] };
18
+ const includes = new Set();
19
+ const excludes = new Set();
20
+ let hasIncludes = false;
21
+ for (const rule of groups) {
22
+ if (rule.includes) {
23
+ hasIncludes = true;
24
+ for (const group of rule.includes)
25
+ includes.add(group);
26
+ }
27
+ for (const group of (_a = rule.excludes) !== null && _a !== void 0 ? _a : []) {
28
+ if (group !== WILDCARD_GROUP)
29
+ excludes.add(group);
30
+ }
31
+ }
32
+ return {
33
+ includes: hasIncludes ? [...includes] : undefined,
34
+ excludes: [...excludes],
35
+ };
36
+ }
37
+ export function checkGroupAccess(groups, readerGroups) {
38
+ const normalized = normalizeGroups(groups);
39
+ if (!normalized)
40
+ return true;
41
+ if (normalized.excludes.some((group) => readerGroups.has(group)))
42
+ return false;
43
+ if (!normalized.includes)
44
+ return true;
45
+ return normalized.includes.some((group) => readerGroups.has(group));
46
+ }
@@ -7,6 +7,7 @@ export * from './getAllPathsInDocsNav.js';
7
7
  export * from './decoratedNavTree.js';
8
8
  export * from './getAllPathsInDecoratedNav.js';
9
9
  export * from './checkNavAccess.js';
10
+ export * from './groupAccess.js';
10
11
  export * from './filterDivisions.js';
11
12
  export * from './updateFirstHrefInDivision.js';
12
13
  export * from './scopeNavToPath.js';
@@ -7,6 +7,7 @@ export * from './getAllPathsInDocsNav.js';
7
7
  export * from './decoratedNavTree.js';
8
8
  export * from './getAllPathsInDecoratedNav.js';
9
9
  export * from './checkNavAccess.js';
10
+ export * from './groupAccess.js';
10
11
  export * from './filterDivisions.js';
11
12
  export * from './updateFirstHrefInDivision.js';
12
13
  export * from './scopeNavToPath.js';