@mintlify/common 1.0.1230 → 1.0.1232
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,9 +1,10 @@
|
|
|
1
1
|
import { visit } from 'unist-util-visit';
|
|
2
|
+
import { normalizeGroups } from '../../../navigation/groupAccess.js';
|
|
2
3
|
import { safeCleanHeadingId, slugify } from '../../../slugify.js';
|
|
3
4
|
import { createMdxJsxAttribute, getTableOfContentsTitle, getTitleMarkdownText, } from '../../lib/remark-utils.js';
|
|
4
5
|
import { isMdxJsxFragment } from '../../utils.js';
|
|
5
6
|
import { AVOIDED_PAGE_MODES, HEADING_LEVELS } from './remarkComponentIds.js';
|
|
6
|
-
import { isHiddenFromHumans, isVisibilityElement, resolveVisibilityFor, toVisibilityAuthRule, } from './remarkVisibilityForMarkdown.js';
|
|
7
|
+
import { isHiddenFromHumans, isVisibilityElement, resolveVisibilityFor, toPageGroups, toVisibilityAuthRule, } from './remarkVisibilityForMarkdown.js';
|
|
7
8
|
import { isVariationElement, resolveVariationIds } from './variation.js';
|
|
8
9
|
export const HEADING_NAMES = ['h1', 'h2', 'h3', 'h4'];
|
|
9
10
|
const COMPONENTS_TO_EXCLUDE_HEADINGS = [
|
|
@@ -20,7 +21,13 @@ function getStringAttribute(attributes, name) {
|
|
|
20
21
|
}
|
|
21
22
|
return undefined;
|
|
22
23
|
}
|
|
23
|
-
const
|
|
24
|
+
const sortedGroups = (groups) => groups && [...groups].sort();
|
|
25
|
+
const authRuleKey = (rule) => {
|
|
26
|
+
if (typeof rule === 'string')
|
|
27
|
+
return rule;
|
|
28
|
+
const normalized = normalizeGroups(toPageGroups(rule.groups));
|
|
29
|
+
return JSON.stringify([sortedGroups(normalized === null || normalized === void 0 ? void 0 : normalized.includes), sortedGroups(normalized === null || normalized === void 0 ? void 0 : normalized.excludes)]);
|
|
30
|
+
};
|
|
24
31
|
const hasAuthRules = (childRules, parentRules) => {
|
|
25
32
|
if (parentRules === undefined)
|
|
26
33
|
return true;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { PageGroupRule, PageGroups } from '@mintlify/models';
|
|
1
2
|
import type { Root } from 'mdast';
|
|
2
3
|
import type { MdxJsxFlowElement, MdxJsxTextElement } from 'mdast-util-mdx-jsx';
|
|
3
4
|
export type MdxJsxElement = MdxJsxFlowElement | MdxJsxTextElement;
|
|
@@ -8,9 +9,11 @@ export declare function isVisibilityElement(node: {
|
|
|
8
9
|
export declare const VISIBILITY_AUDIENCES: readonly ["humans", "agents", "signed-in", "signed-out"];
|
|
9
10
|
export type VisibilityAudience = (typeof VISIBILITY_AUDIENCES)[number];
|
|
10
11
|
export declare const VISIBILITY_FOR_EXPECTED = "\"humans\", \"agents\", \"signed-in\", \"signed-out\", or { groups: [...] }";
|
|
11
|
-
export type
|
|
12
|
-
|
|
12
|
+
export type VisibilityGroups = string[] | PageGroupRule;
|
|
13
|
+
export type VisibilityGroupsRule = {
|
|
14
|
+
groups: VisibilityGroups;
|
|
13
15
|
};
|
|
16
|
+
export type VisibilityAuthRule = 'signed-in' | 'signed-out' | VisibilityGroupsRule;
|
|
14
17
|
export type VisibilityViewer = {
|
|
15
18
|
signedIn: boolean;
|
|
16
19
|
groups: readonly string[];
|
|
@@ -20,7 +23,7 @@ export type VisibilityResolution = {
|
|
|
20
23
|
audience: VisibilityAudience;
|
|
21
24
|
} | {
|
|
22
25
|
kind: 'groups';
|
|
23
|
-
groups:
|
|
26
|
+
groups: VisibilityGroups;
|
|
24
27
|
} | {
|
|
25
28
|
kind: 'invalid';
|
|
26
29
|
raw: string;
|
|
@@ -30,6 +33,8 @@ export type VisibilityResolution = {
|
|
|
30
33
|
kind: 'missing';
|
|
31
34
|
};
|
|
32
35
|
export declare function isVisibilityAudience(value: unknown): value is VisibilityAudience;
|
|
36
|
+
export declare const toPageGroups: (groups: VisibilityGroups) => PageGroups;
|
|
37
|
+
export declare function toVisibilityGroupsRule(value: unknown): VisibilityGroupsRule | undefined;
|
|
33
38
|
export declare function resolveVisibilityFor(node: MdxJsxElement): VisibilityResolution;
|
|
34
39
|
export declare function isHiddenFromHumans(resolution: VisibilityResolution): boolean;
|
|
35
40
|
export declare function isHiddenFromAgents(resolution: VisibilityResolution): boolean;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { WILDCARD_GROUP, checkGroupAccess, isPageGroups } from '../../../navigation/groupAccess.js';
|
|
1
2
|
export function isVisibilityElement(node) {
|
|
2
3
|
return ((node.type === 'mdxJsxFlowElement' || node.type === 'mdxJsxTextElement') &&
|
|
3
4
|
node.name === 'Visibility');
|
|
@@ -42,19 +43,68 @@ function foldString(node) {
|
|
|
42
43
|
return undefined;
|
|
43
44
|
}
|
|
44
45
|
}
|
|
46
|
+
const trimGroupNames = (names) => [...new Set(names.map((name) => name.trim()))];
|
|
47
|
+
const isGroupNames = (groups) => groups.every((entry) => typeof entry === 'string');
|
|
48
|
+
export const toPageGroups = (groups) => Array.isArray(groups) ? groups : [groups];
|
|
49
|
+
function toVisibilityGroups(value) {
|
|
50
|
+
if (Array.isArray(value)) {
|
|
51
|
+
if (value.length === 0 || !isPageGroups(value) || !isGroupNames(value))
|
|
52
|
+
return undefined;
|
|
53
|
+
const names = trimGroupNames(value);
|
|
54
|
+
return isPageGroups(names) ? names : undefined;
|
|
55
|
+
}
|
|
56
|
+
const rules = [value];
|
|
57
|
+
if (!isPageGroups(rules) || isGroupNames(rules))
|
|
58
|
+
return undefined;
|
|
59
|
+
const [rule] = rules.map(({ includes, excludes }) => (Object.assign(Object.assign({}, (includes && { includes: trimGroupNames(includes) })), (excludes && { excludes: trimGroupNames(excludes) }))));
|
|
60
|
+
return rule && isPageGroups([rule]) ? rule : undefined;
|
|
61
|
+
}
|
|
62
|
+
export function toVisibilityGroupsRule(value) {
|
|
63
|
+
if (!isRecord(value) || Object.keys(value).length !== 1)
|
|
64
|
+
return undefined;
|
|
65
|
+
const groups = toVisibilityGroups(value.groups);
|
|
66
|
+
return groups && { groups };
|
|
67
|
+
}
|
|
68
|
+
function staticKey(property) {
|
|
69
|
+
if (property.type !== 'Property' || property.computed)
|
|
70
|
+
return undefined;
|
|
71
|
+
if (property.key.type === 'Identifier')
|
|
72
|
+
return property.key.name;
|
|
73
|
+
return property.key.type === 'Literal' && typeof property.key.value === 'string'
|
|
74
|
+
? property.key.value
|
|
75
|
+
: undefined;
|
|
76
|
+
}
|
|
77
|
+
function foldGroupNames(array) {
|
|
78
|
+
const names = array.elements.map((element) => foldString(element));
|
|
79
|
+
return names.every((name) => name !== undefined) ? names : undefined;
|
|
80
|
+
}
|
|
81
|
+
function foldGroupRule(object) {
|
|
82
|
+
const rule = {};
|
|
83
|
+
for (const property of object.properties) {
|
|
84
|
+
const key = staticKey(property);
|
|
85
|
+
if (property.type !== 'Property' || (key !== 'includes' && key !== 'excludes')) {
|
|
86
|
+
return undefined;
|
|
87
|
+
}
|
|
88
|
+
const names = property.value.type === 'ArrayExpression' ? foldGroupNames(property.value) : undefined;
|
|
89
|
+
if (!names)
|
|
90
|
+
return undefined;
|
|
91
|
+
rule[key] = names;
|
|
92
|
+
}
|
|
93
|
+
return rule;
|
|
94
|
+
}
|
|
45
95
|
function resolveGroups(value) {
|
|
46
96
|
const expression = expressionOf(value);
|
|
47
97
|
if ((expression === null || expression === void 0 ? void 0 : expression.type) !== 'ObjectExpression' || expression.properties.length !== 1)
|
|
48
98
|
return undefined;
|
|
49
99
|
const [property] = expression.properties;
|
|
50
|
-
if ((property === null || property === void 0 ? void 0 : property.type) !== 'Property' || property
|
|
51
|
-
return undefined;
|
|
52
|
-
const key = property.key.type === 'Identifier' ? property.key.name : undefined;
|
|
53
|
-
const literalKey = property.key.type === 'Literal' ? property.key.value : undefined;
|
|
54
|
-
if ((key !== null && key !== void 0 ? key : literalKey) !== 'groups' || property.value.type !== 'ArrayExpression')
|
|
100
|
+
if ((property === null || property === void 0 ? void 0 : property.type) !== 'Property' || staticKey(property) !== 'groups')
|
|
55
101
|
return undefined;
|
|
56
|
-
|
|
57
|
-
|
|
102
|
+
if (property.value.type === 'ObjectExpression') {
|
|
103
|
+
return toVisibilityGroups(foldGroupRule(property.value));
|
|
104
|
+
}
|
|
105
|
+
return property.value.type === 'ArrayExpression'
|
|
106
|
+
? toVisibilityGroups(foldGroupNames(property.value))
|
|
107
|
+
: undefined;
|
|
58
108
|
}
|
|
59
109
|
function mayOverrideFor(attr) {
|
|
60
110
|
if (attr.type !== 'mdxJsxExpressionAttribute')
|
|
@@ -172,7 +222,7 @@ export function matchesVisibilityAuthRule(rule, viewer) {
|
|
|
172
222
|
return viewer.signedIn;
|
|
173
223
|
if (rule === 'signed-out')
|
|
174
224
|
return !viewer.signedIn;
|
|
175
|
-
return viewer.signedIn
|
|
225
|
+
return checkGroupAccess(toPageGroups(rule.groups), new Set(viewer.signedIn ? [...viewer.groups, WILDCARD_GROUP] : []));
|
|
176
226
|
}
|
|
177
227
|
// `export * from` is intentionally ignored: it exposes no statically-knowable
|
|
178
228
|
// names and creates no page-local JSX bindings in MDX, so there is nothing to
|