docusaurus-roles-plugin 1.0.0-beta.1 → 1.0.0-beta.3
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/dist/chunk-6J2ZBQSX.js +18 -0
- package/dist/chunk-6J2ZBQSX.js.map +1 -0
- package/dist/index.cjs +11 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -7
- package/dist/index.d.ts +2 -7
- package/dist/index.js +14 -16
- package/dist/index.js.map +1 -1
- package/dist/options/index.cjs +43 -0
- package/dist/options/index.cjs.map +1 -0
- package/dist/options/index.d.cts +24 -0
- package/dist/options/index.d.ts +24 -0
- package/dist/options/index.js +9 -0
- package/dist/options/index.js.map +1 -0
- package/dist/theme/BlogListPage/index.js +21 -0
- package/dist/theme/BlogListPage/index.js.map +1 -0
- package/dist/theme/BlogPostItem/Forbidden.js +11 -0
- package/dist/theme/BlogPostItem/Forbidden.js.map +1 -0
- package/dist/theme/BlogPostItem/index.js +25 -0
- package/dist/theme/BlogPostItem/index.js.map +1 -0
- package/dist/theme/BlogSidebar/index.js +29 -0
- package/dist/theme/BlogSidebar/index.js.map +1 -0
- package/dist/theme/DocItem/Forbidden.js +11 -0
- package/dist/theme/DocItem/Forbidden.js.map +1 -0
- package/dist/theme/DocItem/index.js +23 -0
- package/dist/theme/DocItem/index.js.map +1 -0
- package/dist/theme/DocSidebar/index.js +28 -0
- package/dist/theme/DocSidebar/index.js.map +1 -0
- package/dist/theme/NavbarItem/index.js +17 -0
- package/dist/theme/NavbarItem/index.js.map +1 -0
- package/dist/theme/RoleGate.js +40 -0
- package/dist/theme/RoleGate.js.map +1 -0
- package/dist/theme/RootWarning.js +25 -0
- package/dist/theme/RootWarning.js.map +1 -0
- package/package.json +17 -2
- package/src/theme/BlogListPage/index.tsx +1 -1
- package/src/theme/BlogPostItem/Forbidden.tsx +1 -4
- package/src/theme/BlogPostItem/index.tsx +3 -3
- package/src/theme/BlogSidebar/index.tsx +4 -4
- package/src/theme/DocItem/Forbidden.tsx +1 -6
- package/src/theme/DocItem/index.tsx +3 -3
- package/src/theme/DocSidebar/index.tsx +2 -2
- package/src/theme/NavbarItem/index.tsx +1 -1
- package/src/theme/RoleGate.tsx +3 -3
- package/src/theme/RootWarning.tsx +0 -2
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
// src/options/index.ts
|
|
2
|
+
function getRoleFrontMatter(frontMatter) {
|
|
3
|
+
if (!frontMatter || typeof frontMatter !== "object") return {};
|
|
4
|
+
return frontMatter;
|
|
5
|
+
}
|
|
6
|
+
function getRoleRequirements(frontMatter) {
|
|
7
|
+
const roleFrontMatter = getRoleFrontMatter(frontMatter);
|
|
8
|
+
return {
|
|
9
|
+
requiredRoles: roleFrontMatter.required_roles ?? [],
|
|
10
|
+
requiredRolesMode: roleFrontMatter.required_roles_mode ?? "all"
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export {
|
|
15
|
+
getRoleFrontMatter,
|
|
16
|
+
getRoleRequirements
|
|
17
|
+
};
|
|
18
|
+
//# sourceMappingURL=chunk-6J2ZBQSX.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/options/index.ts"],"sourcesContent":["export type UnauthorizedBehavior = \"forbidden\" | \"redirect\";\n\nexport type RolesPluginOptions = {\n unauthorizedBehavior?: UnauthorizedBehavior;\n redirectTo?: string; // default '/access-denied'\n};\n\nexport type InternalRolesPluginOptions = {\n rolesByPermalink: RoleEntry[];\n} & RolesPluginOptions;\n\nexport type RolesMode = \"all\" | \"any\";\n\nexport type RoleRequirements = {\n requiredRoles: string[];\n requiredRolesMode: RolesMode;\n};\n\nexport type RoleFrontMatter = {\n required_roles?: string[];\n required_roles_mode?: RolesMode;\n};\n\nexport type RoleEntry = RoleRequirements & {\n permalink: string;\n};\n\nexport function getRoleFrontMatter(frontMatter: unknown): RoleFrontMatter {\n if (!frontMatter || typeof frontMatter !== \"object\") return {};\n return frontMatter as RoleFrontMatter;\n}\n\nexport function getRoleRequirements(frontMatter: unknown): RoleRequirements {\n const roleFrontMatter = getRoleFrontMatter(frontMatter);\n return {\n requiredRoles: roleFrontMatter.required_roles ?? [],\n requiredRolesMode: roleFrontMatter.required_roles_mode ?? \"all\",\n };\n}\n"],"mappings":";AA2BO,SAAS,mBAAmB,aAAuC;AACxE,MAAI,CAAC,eAAe,OAAO,gBAAgB,SAAU,QAAO,CAAC;AAC7D,SAAO;AACT;AAEO,SAAS,oBAAoB,aAAwC;AAC1E,QAAM,kBAAkB,mBAAmB,WAAW;AACtD,SAAO;AAAA,IACL,eAAe,gBAAgB,kBAAkB,CAAC;AAAA,IAClD,mBAAmB,gBAAgB,uBAAuB;AAAA,EAC5D;AACF;","names":[]}
|
package/dist/index.cjs
CHANGED
|
@@ -39,7 +39,7 @@ __export(index_exports, {
|
|
|
39
39
|
module.exports = __toCommonJS(index_exports);
|
|
40
40
|
var import_path = __toESM(require("path"), 1);
|
|
41
41
|
|
|
42
|
-
// src/options.ts
|
|
42
|
+
// src/options/index.ts
|
|
43
43
|
function getRoleFrontMatter(frontMatter) {
|
|
44
44
|
if (!frontMatter || typeof frontMatter !== "object") return {};
|
|
45
45
|
return frontMatter;
|
|
@@ -80,6 +80,12 @@ function createDeferred() {
|
|
|
80
80
|
});
|
|
81
81
|
return { promise, resolve, reject };
|
|
82
82
|
}
|
|
83
|
+
function withTimeout(p, ms) {
|
|
84
|
+
return Promise.race([
|
|
85
|
+
p,
|
|
86
|
+
new Promise((res) => setTimeout(() => res("timeout"), ms))
|
|
87
|
+
]);
|
|
88
|
+
}
|
|
83
89
|
var blogRolesReady = createDeferred();
|
|
84
90
|
var setRolesByPermaLink = (blogPosts) => {
|
|
85
91
|
blogRolesReady = createDeferred();
|
|
@@ -97,10 +103,13 @@ function pluginRoles(_context, options) {
|
|
|
97
103
|
return {
|
|
98
104
|
name: "docusaurus-roles-plugin",
|
|
99
105
|
getThemePath() {
|
|
106
|
+
return import_path.default.resolve(__dirname, "./theme");
|
|
107
|
+
},
|
|
108
|
+
getTypeScriptThemePath() {
|
|
100
109
|
return import_path.default.resolve(__dirname, "../src/theme");
|
|
101
110
|
},
|
|
102
111
|
async contentLoaded({ actions }) {
|
|
103
|
-
await blogRolesReady.promise;
|
|
112
|
+
await withTimeout(blogRolesReady.promise, 5e3);
|
|
104
113
|
actions.setGlobalData({
|
|
105
114
|
rolesByPermalink,
|
|
106
115
|
unauthorizedBehavior: options.unauthorizedBehavior ?? "notFound",
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts","../src/options.ts"],"sourcesContent":["import path from \"path\";\nimport type { LoadContext, Plugin } from \"@docusaurus/types\";\nimport {\n getRoleRequirements,\n type RolesPluginOptions,\n type RoleEntry,\n} from \"./options\";\nimport { BlogPost, ProcessBlogPostsFn } from \"@docusaurus/plugin-content-blog\";\nimport {\n SidebarItemsGeneratorDoc,\n SidebarItemsGeneratorOption,\n} from \"@docusaurus/plugin-content-docs/src/sidebars/types.js\";\n\nexport { RolesPluginOptions } from \"./options\";\n\n/**\n * Used to apply FrontMatter required_roles and required_roles_mode to\n * sidebar_custom_props.required_roles and sidebar_custom_props.required_roles_mode.\n *\n * Should use protectDocSidebar for simple use cases.\n *\n * @param docs - The docs to transform.\n */\nexport const addDocSidebarCustomProps = (docs: SidebarItemsGeneratorDoc[]) => {\n for (const doc of docs) {\n const roles = doc.frontMatter.required_roles;\n if (!roles) continue;\n\n const props = (doc.frontMatter.sidebar_custom_props ??= {});\n props.required_roles = roles;\n props.required_roles_mode = doc.frontMatter.required_roles_mode;\n }\n};\n\n/**\n * Used to protect docs sidebar is a plug and play for sidebarItemsGenerator\n */\nexport const protectDocSidebar: SidebarItemsGeneratorOption = async ({\n defaultSidebarItemsGenerator,\n ...args\n}) => {\n addDocSidebarCustomProps(args.docs);\n\n return defaultSidebarItemsGenerator(args);\n};\n\nlet rolesByPermalink: RoleEntry[] = [];\n\nfunction createDeferred<T>() {\n let resolve!: (value: T) => void;\n let reject!: (reason?: unknown) => void;\n const promise = new Promise<T>((res, rej) => {\n resolve = res;\n reject = rej;\n });\n return { promise, resolve, reject };\n}\n\nlet blogRolesReady = createDeferred<void>();\n\n/**\n * Used to set rolesByPermalink which is used by overriden BlogSidebar\n * to protect blog sidebar.\n */\nexport const setRolesByPermaLink = (blogPosts: BlogPost[]) => {\n blogRolesReady = createDeferred<void>();\n\n rolesByPermalink = blogPosts.map((bp) => ({\n permalink: bp.metadata.permalink,\n ...getRoleRequirements(bp.metadata.frontMatter),\n }));\n\n blogRolesReady.resolve();\n};\n\n/**\n * Used to protect blog sidebar is a plug and play for processBlogPosts.\n */\nexport const protectBlogSidebar: ProcessBlogPostsFn = async ({ blogPosts }) => {\n setRolesByPermaLink(blogPosts);\n return blogPosts;\n};\n\nexport default function pluginRoles(\n _context: LoadContext,\n options: RolesPluginOptions,\n): Plugin {\n return {\n name: \"docusaurus-roles-plugin\",\n\n getThemePath() {\n return path.resolve(__dirname, \"../src/theme\");\n },\n\n async contentLoaded({ actions }) {\n await blogRolesReady.promise;\n\n actions.setGlobalData({\n rolesByPermalink,\n unauthorizedBehavior: options.unauthorizedBehavior ?? \"notFound\",\n redirectTo: options.redirectTo ?? \"/access-denied\",\n });\n },\n };\n}\n","export type UnauthorizedBehavior = \"forbidden\" | \"redirect\";\n\nexport type RolesPluginOptions = {\n unauthorizedBehavior?: UnauthorizedBehavior;\n redirectTo?: string; // default '/access-denied'\n};\n\nexport type InternalRolesPluginOptions = {\n rolesByPermalink: RoleEntry[];\n} & RolesPluginOptions;\n\nexport type RolesMode = \"all\" | \"any\";\n\nexport type RoleRequirements = {\n requiredRoles: string[];\n requiredRolesMode: RolesMode;\n};\n\nexport type RoleFrontMatter = {\n required_roles?: string[];\n required_roles_mode?: RolesMode;\n};\n\nexport type RoleEntry = RoleRequirements & {\n permalink: string;\n};\n\nexport function getRoleFrontMatter(frontMatter: unknown): RoleFrontMatter {\n if (!frontMatter || typeof frontMatter !== \"object\") return {};\n return frontMatter as RoleFrontMatter;\n}\n\nexport function getRoleRequirements(frontMatter: unknown): RoleRequirements {\n const roleFrontMatter = getRoleFrontMatter(frontMatter);\n return {\n requiredRoles: roleFrontMatter.required_roles ?? [],\n requiredRolesMode: roleFrontMatter.required_roles_mode ?? \"all\",\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBAAiB;;;AC2BV,SAAS,mBAAmB,aAAuC;AACxE,MAAI,CAAC,eAAe,OAAO,gBAAgB,SAAU,QAAO,CAAC;AAC7D,SAAO;AACT;AAEO,SAAS,oBAAoB,aAAwC;AAC1E,QAAM,kBAAkB,mBAAmB,WAAW;AACtD,SAAO;AAAA,IACL,eAAe,gBAAgB,kBAAkB,CAAC;AAAA,IAClD,mBAAmB,gBAAgB,uBAAuB;AAAA,EAC5D;AACF;;;ADfO,IAAM,2BAA2B,CAAC,SAAqC;AAvB9E;AAwBE,aAAW,OAAO,MAAM;AACtB,UAAM,QAAQ,IAAI,YAAY;AAC9B,QAAI,CAAC,MAAO;AAEZ,UAAM,SAAS,SAAI,aAAY,yBAAhB,GAAgB,uBAAyB,CAAC;AACzD,UAAM,iBAAiB;AACvB,UAAM,sBAAsB,IAAI,YAAY;AAAA,EAC9C;AACF;AAKO,IAAM,oBAAiD,OAAO;AAAA,EACnE;AAAA,EACA,GAAG;AACL,MAAM;AACJ,2BAAyB,KAAK,IAAI;AAElC,SAAO,6BAA6B,IAAI;AAC1C;AAEA,IAAI,mBAAgC,CAAC;AAErC,SAAS,iBAAoB;AAC3B,MAAI;AACJ,MAAI;AACJ,QAAM,UAAU,IAAI,QAAW,CAAC,KAAK,QAAQ;AAC3C,cAAU;AACV,aAAS;AAAA,EACX,CAAC;AACD,SAAO,EAAE,SAAS,SAAS,OAAO;AACpC;AAEA,IAAI,iBAAiB,eAAqB;AAMnC,IAAM,sBAAsB,CAAC,cAA0B;AAC5D,mBAAiB,eAAqB;AAEtC,qBAAmB,UAAU,IAAI,CAAC,QAAQ;AAAA,IACxC,WAAW,GAAG,SAAS;AAAA,IACvB,GAAG,oBAAoB,GAAG,SAAS,WAAW;AAAA,EAChD,EAAE;AAEF,iBAAe,QAAQ;AACzB;AAKO,IAAM,qBAAyC,OAAO,EAAE,UAAU,MAAM;AAC7E,sBAAoB,SAAS;AAC7B,SAAO;AACT;AAEe,SAAR,YACL,UACA,SACQ;AACR,SAAO;AAAA,IACL,MAAM;AAAA,IAEN,eAAe;AACb,aAAO,YAAAA,QAAK,QAAQ,WAAW,cAAc;AAAA,IAC/C;AAAA,IAEA,MAAM,cAAc,EAAE,QAAQ,GAAG;AAC/B,YAAM,eAAe;
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/options/index.ts"],"sourcesContent":["import path from \"path\";\nimport type { LoadContext, Plugin } from \"@docusaurus/types\";\nimport {\n getRoleRequirements,\n type RolesPluginOptions,\n type RoleEntry,\n} from \"./options\";\nimport { BlogPost, ProcessBlogPostsFn } from \"@docusaurus/plugin-content-blog\";\nimport {\n SidebarItemsGeneratorDoc,\n SidebarItemsGeneratorOption,\n} from \"@docusaurus/plugin-content-docs/src/sidebars/types.js\";\n\nexport { type RolesPluginOptions } from \"./options\";\n\n/**\n * Used to apply FrontMatter required_roles and required_roles_mode to\n * sidebar_custom_props.required_roles and sidebar_custom_props.required_roles_mode.\n *\n * Should use protectDocSidebar for simple use cases.\n *\n * @param docs - The docs to transform.\n */\nexport const addDocSidebarCustomProps = (docs: SidebarItemsGeneratorDoc[]) => {\n for (const doc of docs) {\n const roles = doc.frontMatter.required_roles;\n if (!roles) continue;\n\n const props = (doc.frontMatter.sidebar_custom_props ??= {});\n props.required_roles = roles;\n props.required_roles_mode = doc.frontMatter.required_roles_mode;\n }\n};\n\n/**\n * Used to protect docs sidebar is a plug and play for sidebarItemsGenerator\n */\nexport const protectDocSidebar: SidebarItemsGeneratorOption = async ({\n defaultSidebarItemsGenerator,\n ...args\n}) => {\n addDocSidebarCustomProps(args.docs);\n\n return defaultSidebarItemsGenerator(args);\n};\n\nlet rolesByPermalink: RoleEntry[] = [];\n\nfunction createDeferred<T>() {\n let resolve!: (value: T) => void;\n let reject!: (reason?: unknown) => void;\n const promise = new Promise<T>((res, rej) => {\n resolve = res;\n reject = rej;\n });\n return { promise, resolve, reject };\n}\n\nfunction withTimeout<T>(p: Promise<T>, ms: number): Promise<T | \"timeout\"> {\n return Promise.race([\n p,\n new Promise<\"timeout\">((res) => setTimeout(() => res(\"timeout\"), ms)),\n ]);\n}\n\nlet blogRolesReady = createDeferred<void>();\n\n/**\n * Used to set rolesByPermalink which is used by overriden BlogSidebar\n * to protect blog sidebar.\n */\nexport const setRolesByPermaLink = (blogPosts: BlogPost[]) => {\n blogRolesReady = createDeferred<void>();\n\n rolesByPermalink = blogPosts.map((bp) => ({\n permalink: bp.metadata.permalink,\n ...getRoleRequirements(bp.metadata.frontMatter),\n }));\n\n blogRolesReady.resolve();\n};\n\n/**\n * Used to protect blog sidebar is a plug and play for processBlogPosts.\n */\nexport const protectBlogSidebar: ProcessBlogPostsFn = async ({ blogPosts }) => {\n setRolesByPermaLink(blogPosts);\n return blogPosts;\n};\n\nexport default function pluginRoles(\n _context: LoadContext,\n options: RolesPluginOptions,\n): Plugin {\n return {\n name: \"docusaurus-roles-plugin\",\n\n getThemePath() {\n return path.resolve(__dirname, \"./theme\");\n },\n\n getTypeScriptThemePath() {\n return path.resolve(__dirname, \"../src/theme\");\n },\n\n async contentLoaded({ actions }) {\n await withTimeout(blogRolesReady.promise, 5000);\n\n actions.setGlobalData({\n rolesByPermalink,\n unauthorizedBehavior: options.unauthorizedBehavior ?? \"notFound\",\n redirectTo: options.redirectTo ?? \"/access-denied\",\n });\n },\n };\n}\n","export type UnauthorizedBehavior = \"forbidden\" | \"redirect\";\n\nexport type RolesPluginOptions = {\n unauthorizedBehavior?: UnauthorizedBehavior;\n redirectTo?: string; // default '/access-denied'\n};\n\nexport type InternalRolesPluginOptions = {\n rolesByPermalink: RoleEntry[];\n} & RolesPluginOptions;\n\nexport type RolesMode = \"all\" | \"any\";\n\nexport type RoleRequirements = {\n requiredRoles: string[];\n requiredRolesMode: RolesMode;\n};\n\nexport type RoleFrontMatter = {\n required_roles?: string[];\n required_roles_mode?: RolesMode;\n};\n\nexport type RoleEntry = RoleRequirements & {\n permalink: string;\n};\n\nexport function getRoleFrontMatter(frontMatter: unknown): RoleFrontMatter {\n if (!frontMatter || typeof frontMatter !== \"object\") return {};\n return frontMatter as RoleFrontMatter;\n}\n\nexport function getRoleRequirements(frontMatter: unknown): RoleRequirements {\n const roleFrontMatter = getRoleFrontMatter(frontMatter);\n return {\n requiredRoles: roleFrontMatter.required_roles ?? [],\n requiredRolesMode: roleFrontMatter.required_roles_mode ?? \"all\",\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBAAiB;;;AC2BV,SAAS,mBAAmB,aAAuC;AACxE,MAAI,CAAC,eAAe,OAAO,gBAAgB,SAAU,QAAO,CAAC;AAC7D,SAAO;AACT;AAEO,SAAS,oBAAoB,aAAwC;AAC1E,QAAM,kBAAkB,mBAAmB,WAAW;AACtD,SAAO;AAAA,IACL,eAAe,gBAAgB,kBAAkB,CAAC;AAAA,IAClD,mBAAmB,gBAAgB,uBAAuB;AAAA,EAC5D;AACF;;;ADfO,IAAM,2BAA2B,CAAC,SAAqC;AAvB9E;AAwBE,aAAW,OAAO,MAAM;AACtB,UAAM,QAAQ,IAAI,YAAY;AAC9B,QAAI,CAAC,MAAO;AAEZ,UAAM,SAAS,SAAI,aAAY,yBAAhB,GAAgB,uBAAyB,CAAC;AACzD,UAAM,iBAAiB;AACvB,UAAM,sBAAsB,IAAI,YAAY;AAAA,EAC9C;AACF;AAKO,IAAM,oBAAiD,OAAO;AAAA,EACnE;AAAA,EACA,GAAG;AACL,MAAM;AACJ,2BAAyB,KAAK,IAAI;AAElC,SAAO,6BAA6B,IAAI;AAC1C;AAEA,IAAI,mBAAgC,CAAC;AAErC,SAAS,iBAAoB;AAC3B,MAAI;AACJ,MAAI;AACJ,QAAM,UAAU,IAAI,QAAW,CAAC,KAAK,QAAQ;AAC3C,cAAU;AACV,aAAS;AAAA,EACX,CAAC;AACD,SAAO,EAAE,SAAS,SAAS,OAAO;AACpC;AAEA,SAAS,YAAe,GAAe,IAAoC;AACzE,SAAO,QAAQ,KAAK;AAAA,IAClB;AAAA,IACA,IAAI,QAAmB,CAAC,QAAQ,WAAW,MAAM,IAAI,SAAS,GAAG,EAAE,CAAC;AAAA,EACtE,CAAC;AACH;AAEA,IAAI,iBAAiB,eAAqB;AAMnC,IAAM,sBAAsB,CAAC,cAA0B;AAC5D,mBAAiB,eAAqB;AAEtC,qBAAmB,UAAU,IAAI,CAAC,QAAQ;AAAA,IACxC,WAAW,GAAG,SAAS;AAAA,IACvB,GAAG,oBAAoB,GAAG,SAAS,WAAW;AAAA,EAChD,EAAE;AAEF,iBAAe,QAAQ;AACzB;AAKO,IAAM,qBAAyC,OAAO,EAAE,UAAU,MAAM;AAC7E,sBAAoB,SAAS;AAC7B,SAAO;AACT;AAEe,SAAR,YACL,UACA,SACQ;AACR,SAAO;AAAA,IACL,MAAM;AAAA,IAEN,eAAe;AACb,aAAO,YAAAA,QAAK,QAAQ,WAAW,SAAS;AAAA,IAC1C;AAAA,IAEA,yBAAyB;AACvB,aAAO,YAAAA,QAAK,QAAQ,WAAW,cAAc;AAAA,IAC/C;AAAA,IAEA,MAAM,cAAc,EAAE,QAAQ,GAAG;AAC/B,YAAM,YAAY,eAAe,SAAS,GAAI;AAE9C,cAAQ,cAAc;AAAA,QACpB;AAAA,QACA,sBAAsB,QAAQ,wBAAwB;AAAA,QACtD,YAAY,QAAQ,cAAc;AAAA,MACpC,CAAC;AAAA,IACH;AAAA,EACF;AACF;","names":["path"]}
|
package/dist/index.d.cts
CHANGED
|
@@ -1,13 +1,8 @@
|
|
|
1
1
|
import { LoadContext, Plugin } from '@docusaurus/types';
|
|
2
|
+
import { RolesPluginOptions } from './options/index.cjs';
|
|
2
3
|
import { BlogPost, ProcessBlogPostsFn } from '@docusaurus/plugin-content-blog';
|
|
3
4
|
import { SidebarItemsGeneratorDoc, SidebarItemsGeneratorOption } from '@docusaurus/plugin-content-docs/src/sidebars/types.js';
|
|
4
5
|
|
|
5
|
-
type UnauthorizedBehavior = "forbidden" | "redirect";
|
|
6
|
-
type RolesPluginOptions = {
|
|
7
|
-
unauthorizedBehavior?: UnauthorizedBehavior;
|
|
8
|
-
redirectTo?: string;
|
|
9
|
-
};
|
|
10
|
-
|
|
11
6
|
/**
|
|
12
7
|
* Used to apply FrontMatter required_roles and required_roles_mode to
|
|
13
8
|
* sidebar_custom_props.required_roles and sidebar_custom_props.required_roles_mode.
|
|
@@ -32,4 +27,4 @@ declare const setRolesByPermaLink: (blogPosts: BlogPost[]) => void;
|
|
|
32
27
|
declare const protectBlogSidebar: ProcessBlogPostsFn;
|
|
33
28
|
declare function pluginRoles(_context: LoadContext, options: RolesPluginOptions): Plugin;
|
|
34
29
|
|
|
35
|
-
export {
|
|
30
|
+
export { RolesPluginOptions, addDocSidebarCustomProps, pluginRoles as default, protectBlogSidebar, protectDocSidebar, setRolesByPermaLink };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,13 +1,8 @@
|
|
|
1
1
|
import { LoadContext, Plugin } from '@docusaurus/types';
|
|
2
|
+
import { RolesPluginOptions } from './options/index.js';
|
|
2
3
|
import { BlogPost, ProcessBlogPostsFn } from '@docusaurus/plugin-content-blog';
|
|
3
4
|
import { SidebarItemsGeneratorDoc, SidebarItemsGeneratorOption } from '@docusaurus/plugin-content-docs/src/sidebars/types.js';
|
|
4
5
|
|
|
5
|
-
type UnauthorizedBehavior = "forbidden" | "redirect";
|
|
6
|
-
type RolesPluginOptions = {
|
|
7
|
-
unauthorizedBehavior?: UnauthorizedBehavior;
|
|
8
|
-
redirectTo?: string;
|
|
9
|
-
};
|
|
10
|
-
|
|
11
6
|
/**
|
|
12
7
|
* Used to apply FrontMatter required_roles and required_roles_mode to
|
|
13
8
|
* sidebar_custom_props.required_roles and sidebar_custom_props.required_roles_mode.
|
|
@@ -32,4 +27,4 @@ declare const setRolesByPermaLink: (blogPosts: BlogPost[]) => void;
|
|
|
32
27
|
declare const protectBlogSidebar: ProcessBlogPostsFn;
|
|
33
28
|
declare function pluginRoles(_context: LoadContext, options: RolesPluginOptions): Plugin;
|
|
34
29
|
|
|
35
|
-
export {
|
|
30
|
+
export { RolesPluginOptions, addDocSidebarCustomProps, pluginRoles as default, protectBlogSidebar, protectDocSidebar, setRolesByPermaLink };
|
package/dist/index.js
CHANGED
|
@@ -1,20 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
// src/options.ts
|
|
5
|
-
function getRoleFrontMatter(frontMatter) {
|
|
6
|
-
if (!frontMatter || typeof frontMatter !== "object") return {};
|
|
7
|
-
return frontMatter;
|
|
8
|
-
}
|
|
9
|
-
function getRoleRequirements(frontMatter) {
|
|
10
|
-
const roleFrontMatter = getRoleFrontMatter(frontMatter);
|
|
11
|
-
return {
|
|
12
|
-
requiredRoles: roleFrontMatter.required_roles ?? [],
|
|
13
|
-
requiredRolesMode: roleFrontMatter.required_roles_mode ?? "all"
|
|
14
|
-
};
|
|
15
|
-
}
|
|
1
|
+
import {
|
|
2
|
+
getRoleRequirements
|
|
3
|
+
} from "./chunk-6J2ZBQSX.js";
|
|
16
4
|
|
|
17
5
|
// src/index.ts
|
|
6
|
+
import path from "path";
|
|
18
7
|
var addDocSidebarCustomProps = (docs) => {
|
|
19
8
|
var _a;
|
|
20
9
|
for (const doc of docs) {
|
|
@@ -42,6 +31,12 @@ function createDeferred() {
|
|
|
42
31
|
});
|
|
43
32
|
return { promise, resolve, reject };
|
|
44
33
|
}
|
|
34
|
+
function withTimeout(p, ms) {
|
|
35
|
+
return Promise.race([
|
|
36
|
+
p,
|
|
37
|
+
new Promise((res) => setTimeout(() => res("timeout"), ms))
|
|
38
|
+
]);
|
|
39
|
+
}
|
|
45
40
|
var blogRolesReady = createDeferred();
|
|
46
41
|
var setRolesByPermaLink = (blogPosts) => {
|
|
47
42
|
blogRolesReady = createDeferred();
|
|
@@ -59,10 +54,13 @@ function pluginRoles(_context, options) {
|
|
|
59
54
|
return {
|
|
60
55
|
name: "docusaurus-roles-plugin",
|
|
61
56
|
getThemePath() {
|
|
57
|
+
return path.resolve(__dirname, "./theme");
|
|
58
|
+
},
|
|
59
|
+
getTypeScriptThemePath() {
|
|
62
60
|
return path.resolve(__dirname, "../src/theme");
|
|
63
61
|
},
|
|
64
62
|
async contentLoaded({ actions }) {
|
|
65
|
-
await blogRolesReady.promise;
|
|
63
|
+
await withTimeout(blogRolesReady.promise, 5e3);
|
|
66
64
|
actions.setGlobalData({
|
|
67
65
|
rolesByPermalink,
|
|
68
66
|
unauthorizedBehavior: options.unauthorizedBehavior ?? "notFound",
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import path from \"path\";\nimport type { LoadContext, Plugin } from \"@docusaurus/types\";\nimport {\n getRoleRequirements,\n type RolesPluginOptions,\n type RoleEntry,\n} from \"./options\";\nimport { BlogPost, ProcessBlogPostsFn } from \"@docusaurus/plugin-content-blog\";\nimport {\n SidebarItemsGeneratorDoc,\n SidebarItemsGeneratorOption,\n} from \"@docusaurus/plugin-content-docs/src/sidebars/types.js\";\n\nexport { type RolesPluginOptions } from \"./options\";\n\n/**\n * Used to apply FrontMatter required_roles and required_roles_mode to\n * sidebar_custom_props.required_roles and sidebar_custom_props.required_roles_mode.\n *\n * Should use protectDocSidebar for simple use cases.\n *\n * @param docs - The docs to transform.\n */\nexport const addDocSidebarCustomProps = (docs: SidebarItemsGeneratorDoc[]) => {\n for (const doc of docs) {\n const roles = doc.frontMatter.required_roles;\n if (!roles) continue;\n\n const props = (doc.frontMatter.sidebar_custom_props ??= {});\n props.required_roles = roles;\n props.required_roles_mode = doc.frontMatter.required_roles_mode;\n }\n};\n\n/**\n * Used to protect docs sidebar is a plug and play for sidebarItemsGenerator\n */\nexport const protectDocSidebar: SidebarItemsGeneratorOption = async ({\n defaultSidebarItemsGenerator,\n ...args\n}) => {\n addDocSidebarCustomProps(args.docs);\n\n return defaultSidebarItemsGenerator(args);\n};\n\nlet rolesByPermalink: RoleEntry[] = [];\n\nfunction createDeferred<T>() {\n let resolve!: (value: T) => void;\n let reject!: (reason?: unknown) => void;\n const promise = new Promise<T>((res, rej) => {\n resolve = res;\n reject = rej;\n });\n return { promise, resolve, reject };\n}\n\nfunction withTimeout<T>(p: Promise<T>, ms: number): Promise<T | \"timeout\"> {\n return Promise.race([\n p,\n new Promise<\"timeout\">((res) => setTimeout(() => res(\"timeout\"), ms)),\n ]);\n}\n\nlet blogRolesReady = createDeferred<void>();\n\n/**\n * Used to set rolesByPermalink which is used by overriden BlogSidebar\n * to protect blog sidebar.\n */\nexport const setRolesByPermaLink = (blogPosts: BlogPost[]) => {\n blogRolesReady = createDeferred<void>();\n\n rolesByPermalink = blogPosts.map((bp) => ({\n permalink: bp.metadata.permalink,\n ...getRoleRequirements(bp.metadata.frontMatter),\n }));\n\n blogRolesReady.resolve();\n};\n\n/**\n * Used to protect blog sidebar is a plug and play for processBlogPosts.\n */\nexport const protectBlogSidebar: ProcessBlogPostsFn = async ({ blogPosts }) => {\n setRolesByPermaLink(blogPosts);\n return blogPosts;\n};\n\nexport default function pluginRoles(\n _context: LoadContext,\n options: RolesPluginOptions,\n): Plugin {\n return {\n name: \"docusaurus-roles-plugin\",\n\n getThemePath() {\n return path.resolve(__dirname, \"./theme\");\n },\n\n getTypeScriptThemePath() {\n return path.resolve(__dirname, \"../src/theme\");\n },\n\n async contentLoaded({ actions }) {\n await withTimeout(blogRolesReady.promise, 5000);\n\n actions.setGlobalData({\n rolesByPermalink,\n unauthorizedBehavior: options.unauthorizedBehavior ?? \"notFound\",\n redirectTo: options.redirectTo ?? \"/access-denied\",\n });\n },\n };\n}\n"],"mappings":";;;;;AAAA,OAAO,UAAU;AAuBV,IAAM,2BAA2B,CAAC,SAAqC;AAvB9E;AAwBE,aAAW,OAAO,MAAM;AACtB,UAAM,QAAQ,IAAI,YAAY;AAC9B,QAAI,CAAC,MAAO;AAEZ,UAAM,SAAS,SAAI,aAAY,yBAAhB,GAAgB,uBAAyB,CAAC;AACzD,UAAM,iBAAiB;AACvB,UAAM,sBAAsB,IAAI,YAAY;AAAA,EAC9C;AACF;AAKO,IAAM,oBAAiD,OAAO;AAAA,EACnE;AAAA,EACA,GAAG;AACL,MAAM;AACJ,2BAAyB,KAAK,IAAI;AAElC,SAAO,6BAA6B,IAAI;AAC1C;AAEA,IAAI,mBAAgC,CAAC;AAErC,SAAS,iBAAoB;AAC3B,MAAI;AACJ,MAAI;AACJ,QAAM,UAAU,IAAI,QAAW,CAAC,KAAK,QAAQ;AAC3C,cAAU;AACV,aAAS;AAAA,EACX,CAAC;AACD,SAAO,EAAE,SAAS,SAAS,OAAO;AACpC;AAEA,SAAS,YAAe,GAAe,IAAoC;AACzE,SAAO,QAAQ,KAAK;AAAA,IAClB;AAAA,IACA,IAAI,QAAmB,CAAC,QAAQ,WAAW,MAAM,IAAI,SAAS,GAAG,EAAE,CAAC;AAAA,EACtE,CAAC;AACH;AAEA,IAAI,iBAAiB,eAAqB;AAMnC,IAAM,sBAAsB,CAAC,cAA0B;AAC5D,mBAAiB,eAAqB;AAEtC,qBAAmB,UAAU,IAAI,CAAC,QAAQ;AAAA,IACxC,WAAW,GAAG,SAAS;AAAA,IACvB,GAAG,oBAAoB,GAAG,SAAS,WAAW;AAAA,EAChD,EAAE;AAEF,iBAAe,QAAQ;AACzB;AAKO,IAAM,qBAAyC,OAAO,EAAE,UAAU,MAAM;AAC7E,sBAAoB,SAAS;AAC7B,SAAO;AACT;AAEe,SAAR,YACL,UACA,SACQ;AACR,SAAO;AAAA,IACL,MAAM;AAAA,IAEN,eAAe;AACb,aAAO,KAAK,QAAQ,WAAW,SAAS;AAAA,IAC1C;AAAA,IAEA,yBAAyB;AACvB,aAAO,KAAK,QAAQ,WAAW,cAAc;AAAA,IAC/C;AAAA,IAEA,MAAM,cAAc,EAAE,QAAQ,GAAG;AAC/B,YAAM,YAAY,eAAe,SAAS,GAAI;AAE9C,cAAQ,cAAc;AAAA,QACpB;AAAA,QACA,sBAAsB,QAAQ,wBAAwB;AAAA,QACtD,YAAY,QAAQ,cAAc;AAAA,MACpC,CAAC;AAAA,IACH;AAAA,EACF;AACF;","names":[]}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/options/index.ts
|
|
21
|
+
var options_exports = {};
|
|
22
|
+
__export(options_exports, {
|
|
23
|
+
getRoleFrontMatter: () => getRoleFrontMatter,
|
|
24
|
+
getRoleRequirements: () => getRoleRequirements
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(options_exports);
|
|
27
|
+
function getRoleFrontMatter(frontMatter) {
|
|
28
|
+
if (!frontMatter || typeof frontMatter !== "object") return {};
|
|
29
|
+
return frontMatter;
|
|
30
|
+
}
|
|
31
|
+
function getRoleRequirements(frontMatter) {
|
|
32
|
+
const roleFrontMatter = getRoleFrontMatter(frontMatter);
|
|
33
|
+
return {
|
|
34
|
+
requiredRoles: roleFrontMatter.required_roles ?? [],
|
|
35
|
+
requiredRolesMode: roleFrontMatter.required_roles_mode ?? "all"
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
39
|
+
0 && (module.exports = {
|
|
40
|
+
getRoleFrontMatter,
|
|
41
|
+
getRoleRequirements
|
|
42
|
+
});
|
|
43
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/options/index.ts"],"sourcesContent":["export type UnauthorizedBehavior = \"forbidden\" | \"redirect\";\n\nexport type RolesPluginOptions = {\n unauthorizedBehavior?: UnauthorizedBehavior;\n redirectTo?: string; // default '/access-denied'\n};\n\nexport type InternalRolesPluginOptions = {\n rolesByPermalink: RoleEntry[];\n} & RolesPluginOptions;\n\nexport type RolesMode = \"all\" | \"any\";\n\nexport type RoleRequirements = {\n requiredRoles: string[];\n requiredRolesMode: RolesMode;\n};\n\nexport type RoleFrontMatter = {\n required_roles?: string[];\n required_roles_mode?: RolesMode;\n};\n\nexport type RoleEntry = RoleRequirements & {\n permalink: string;\n};\n\nexport function getRoleFrontMatter(frontMatter: unknown): RoleFrontMatter {\n if (!frontMatter || typeof frontMatter !== \"object\") return {};\n return frontMatter as RoleFrontMatter;\n}\n\nexport function getRoleRequirements(frontMatter: unknown): RoleRequirements {\n const roleFrontMatter = getRoleFrontMatter(frontMatter);\n return {\n requiredRoles: roleFrontMatter.required_roles ?? [],\n requiredRolesMode: roleFrontMatter.required_roles_mode ?? \"all\",\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AA2BO,SAAS,mBAAmB,aAAuC;AACxE,MAAI,CAAC,eAAe,OAAO,gBAAgB,SAAU,QAAO,CAAC;AAC7D,SAAO;AACT;AAEO,SAAS,oBAAoB,aAAwC;AAC1E,QAAM,kBAAkB,mBAAmB,WAAW;AACtD,SAAO;AAAA,IACL,eAAe,gBAAgB,kBAAkB,CAAC;AAAA,IAClD,mBAAmB,gBAAgB,uBAAuB;AAAA,EAC5D;AACF;","names":[]}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
type UnauthorizedBehavior = "forbidden" | "redirect";
|
|
2
|
+
type RolesPluginOptions = {
|
|
3
|
+
unauthorizedBehavior?: UnauthorizedBehavior;
|
|
4
|
+
redirectTo?: string;
|
|
5
|
+
};
|
|
6
|
+
type InternalRolesPluginOptions = {
|
|
7
|
+
rolesByPermalink: RoleEntry[];
|
|
8
|
+
} & RolesPluginOptions;
|
|
9
|
+
type RolesMode = "all" | "any";
|
|
10
|
+
type RoleRequirements = {
|
|
11
|
+
requiredRoles: string[];
|
|
12
|
+
requiredRolesMode: RolesMode;
|
|
13
|
+
};
|
|
14
|
+
type RoleFrontMatter = {
|
|
15
|
+
required_roles?: string[];
|
|
16
|
+
required_roles_mode?: RolesMode;
|
|
17
|
+
};
|
|
18
|
+
type RoleEntry = RoleRequirements & {
|
|
19
|
+
permalink: string;
|
|
20
|
+
};
|
|
21
|
+
declare function getRoleFrontMatter(frontMatter: unknown): RoleFrontMatter;
|
|
22
|
+
declare function getRoleRequirements(frontMatter: unknown): RoleRequirements;
|
|
23
|
+
|
|
24
|
+
export { type InternalRolesPluginOptions, type RoleEntry, type RoleFrontMatter, type RoleRequirements, type RolesMode, type RolesPluginOptions, type UnauthorizedBehavior, getRoleFrontMatter, getRoleRequirements };
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
type UnauthorizedBehavior = "forbidden" | "redirect";
|
|
2
|
+
type RolesPluginOptions = {
|
|
3
|
+
unauthorizedBehavior?: UnauthorizedBehavior;
|
|
4
|
+
redirectTo?: string;
|
|
5
|
+
};
|
|
6
|
+
type InternalRolesPluginOptions = {
|
|
7
|
+
rolesByPermalink: RoleEntry[];
|
|
8
|
+
} & RolesPluginOptions;
|
|
9
|
+
type RolesMode = "all" | "any";
|
|
10
|
+
type RoleRequirements = {
|
|
11
|
+
requiredRoles: string[];
|
|
12
|
+
requiredRolesMode: RolesMode;
|
|
13
|
+
};
|
|
14
|
+
type RoleFrontMatter = {
|
|
15
|
+
required_roles?: string[];
|
|
16
|
+
required_roles_mode?: RolesMode;
|
|
17
|
+
};
|
|
18
|
+
type RoleEntry = RoleRequirements & {
|
|
19
|
+
permalink: string;
|
|
20
|
+
};
|
|
21
|
+
declare function getRoleFrontMatter(frontMatter: unknown): RoleFrontMatter;
|
|
22
|
+
declare function getRoleRequirements(frontMatter: unknown): RoleRequirements;
|
|
23
|
+
|
|
24
|
+
export { type InternalRolesPluginOptions, type RoleEntry, type RoleFrontMatter, type RoleRequirements, type RolesMode, type RolesPluginOptions, type UnauthorizedBehavior, getRoleFrontMatter, getRoleRequirements };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import BlogListPage from "@theme-init/BlogListPage";
|
|
3
|
+
import { useRoles, isAllowed } from "docusaurus-roles-plugin/runtime";
|
|
4
|
+
import { getRoleFrontMatter } from "docusaurus-roles-plugin/options";
|
|
5
|
+
function BlogListPageWrapper({ items, ...rest }) {
|
|
6
|
+
const { roles, loading } = useRoles();
|
|
7
|
+
const filteredItems = items.filter((i) => {
|
|
8
|
+
const frontMatter = getRoleFrontMatter(i.content.frontMatter);
|
|
9
|
+
const { allowed } = isAllowed(
|
|
10
|
+
roles,
|
|
11
|
+
frontMatter.required_roles ?? [],
|
|
12
|
+
frontMatter.required_roles_mode ?? "all"
|
|
13
|
+
);
|
|
14
|
+
return allowed;
|
|
15
|
+
});
|
|
16
|
+
return /* @__PURE__ */ jsx(BlogListPage, { ...rest, items: filteredItems });
|
|
17
|
+
}
|
|
18
|
+
export {
|
|
19
|
+
BlogListPageWrapper as default
|
|
20
|
+
};
|
|
21
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/theme/BlogListPage/index.tsx"],"sourcesContent":["import BlogListPage from \"@theme-init/BlogListPage\";\nimport { useRoles, isAllowed } from \"docusaurus-roles-plugin/runtime\";\nimport type { Props } from \"@theme/BlogListPage\";\nimport { getRoleFrontMatter } from \"docusaurus-roles-plugin/options\";\n\nexport default function BlogListPageWrapper({ items, ...rest }: Props) {\n const { roles, loading } = useRoles();\n\n const filteredItems = items.filter((i) => {\n const frontMatter = getRoleFrontMatter(i.content.frontMatter);\n const { allowed } = isAllowed(\n roles,\n frontMatter.required_roles ?? [],\n frontMatter.required_roles_mode ?? \"all\",\n );\n return allowed;\n });\n\n return <BlogListPage {...rest} items={filteredItems} />;\n}\n"],"mappings":"AAkBS;AAlBT,OAAO,kBAAkB;AACzB,SAAS,UAAU,iBAAiB;AAEpC,SAAS,0BAA0B;AAEpB,SAAR,oBAAqC,EAAE,OAAO,GAAG,KAAK,GAAU;AACrE,QAAM,EAAE,OAAO,QAAQ,IAAI,SAAS;AAEpC,QAAM,gBAAgB,MAAM,OAAO,CAAC,MAAM;AACxC,UAAM,cAAc,mBAAmB,EAAE,QAAQ,WAAW;AAC5D,UAAM,EAAE,QAAQ,IAAI;AAAA,MAClB;AAAA,MACA,YAAY,kBAAkB,CAAC;AAAA,MAC/B,YAAY,uBAAuB;AAAA,IACrC;AACA,WAAO;AAAA,EACT,CAAC;AAED,SAAO,oBAAC,gBAAc,GAAG,MAAM,OAAO,eAAe;AACvD;","names":[]}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import { BaseForbiddenContent } from "docusaurus-roles-plugin/runtime";
|
|
3
|
+
function ForbiddenBlogPostItem({
|
|
4
|
+
missingRoles
|
|
5
|
+
}) {
|
|
6
|
+
return /* @__PURE__ */ jsx("main", { className: "container margin-vert--xl", children: /* @__PURE__ */ jsx(BaseForbiddenContent, { prefixTranslateId: "theme.BlogPostItem.Forbidden" }) });
|
|
7
|
+
}
|
|
8
|
+
export {
|
|
9
|
+
ForbiddenBlogPostItem as default
|
|
10
|
+
};
|
|
11
|
+
//# sourceMappingURL=Forbidden.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/theme/BlogPostItem/Forbidden.tsx"],"sourcesContent":["import { type ReactNode } from \"react\";\nimport { BaseForbiddenContent } from \"docusaurus-roles-plugin/runtime\";\n\nexport default function ForbiddenBlogPostItem({\n missingRoles,\n}: {\n missingRoles: string[];\n}): ReactNode {\n return (\n <main className={\"container margin-vert--xl\"}>\n <BaseForbiddenContent prefixTranslateId=\"theme.BlogPostItem.Forbidden\" />\n </main>\n );\n}\n"],"mappings":"AAUM;AATN,SAAS,4BAA4B;AAEtB,SAAR,sBAAuC;AAAA,EAC5C;AACF,GAEc;AACZ,SACE,oBAAC,UAAK,WAAW,6BACf,8BAAC,wBAAqB,mBAAkB,gCAA+B,GACzE;AAEJ;","names":[]}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import BlogPostItem from "@theme-init/BlogPostItem";
|
|
3
|
+
import RoleGate from "../RoleGate.js";
|
|
4
|
+
import { getRoleFrontMatter } from "docusaurus-roles-plugin/options";
|
|
5
|
+
import { useBlogPost } from "@docusaurus/plugin-content-blog/client";
|
|
6
|
+
import ForbiddenBlogPostItem from "./Forbidden.js";
|
|
7
|
+
function BlogPostItemWrapper(props) {
|
|
8
|
+
const { metadata } = useBlogPost();
|
|
9
|
+
const frontMatter = getRoleFrontMatter(metadata.frontMatter);
|
|
10
|
+
const requiredRoles = frontMatter.required_roles;
|
|
11
|
+
const mode = frontMatter.required_roles_mode;
|
|
12
|
+
return /* @__PURE__ */ jsx(
|
|
13
|
+
RoleGate,
|
|
14
|
+
{
|
|
15
|
+
requiredRoles,
|
|
16
|
+
mode,
|
|
17
|
+
forbidden: ForbiddenBlogPostItem,
|
|
18
|
+
children: /* @__PURE__ */ jsx(BlogPostItem, { ...props })
|
|
19
|
+
}
|
|
20
|
+
);
|
|
21
|
+
}
|
|
22
|
+
export {
|
|
23
|
+
BlogPostItemWrapper as default
|
|
24
|
+
};
|
|
25
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/theme/BlogPostItem/index.tsx"],"sourcesContent":["import BlogPostItem, { type Props } from \"@theme-init/BlogPostItem\";\nimport RoleGate from \"../RoleGate.js\";\nimport { getRoleFrontMatter } from \"docusaurus-roles-plugin/options\";\nimport { useBlogPost } from \"@docusaurus/plugin-content-blog/client\";\nimport ForbiddenBlogPostItem from \"./Forbidden.js\";\n\nexport default function BlogPostItemWrapper(props: Props) {\n const { metadata } = useBlogPost();\n const frontMatter = getRoleFrontMatter(metadata.frontMatter);\n const requiredRoles = frontMatter.required_roles;\n const mode = frontMatter.required_roles_mode;\n\n return (\n <RoleGate\n requiredRoles={requiredRoles}\n mode={mode}\n forbidden={ForbiddenBlogPostItem}\n >\n <BlogPostItem {...props} />\n </RoleGate>\n );\n}\n"],"mappings":"AAkBM;AAlBN,OAAO,kBAAkC;AACzC,OAAO,cAAc;AACrB,SAAS,0BAA0B;AACnC,SAAS,mBAAmB;AAC5B,OAAO,2BAA2B;AAEnB,SAAR,oBAAqC,OAAc;AACxD,QAAM,EAAE,SAAS,IAAI,YAAY;AACjC,QAAM,cAAc,mBAAmB,SAAS,WAAW;AAC3D,QAAM,gBAAgB,YAAY;AAClC,QAAM,OAAO,YAAY;AAEzB,SACE;AAAA,IAAC;AAAA;AAAA,MACC;AAAA,MACA;AAAA,MACA,WAAW;AAAA,MAEX,8BAAC,gBAAc,GAAG,OAAO;AAAA;AAAA,EAC3B;AAEJ;","names":[]}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import { usePluginData } from "@docusaurus/useGlobalData";
|
|
3
|
+
import BlogSidebar from "@theme-init/BlogSidebar";
|
|
4
|
+
import { isAllowed, useRoles } from "docusaurus-roles-plugin/runtime";
|
|
5
|
+
function BlogSidebarWrapper({ sidebar, ...props }) {
|
|
6
|
+
const plugin = usePluginData(
|
|
7
|
+
"docusaurus-roles-plugin"
|
|
8
|
+
);
|
|
9
|
+
const { roles } = useRoles();
|
|
10
|
+
if (sidebar) {
|
|
11
|
+
sidebar.items = sidebar.items.filter((i) => {
|
|
12
|
+
const roleInfo = plugin.rolesByPermalink.find(
|
|
13
|
+
(r) => r.permalink === i.permalink
|
|
14
|
+
);
|
|
15
|
+
if (!roleInfo) return true;
|
|
16
|
+
const { allowed } = isAllowed(
|
|
17
|
+
roles,
|
|
18
|
+
roleInfo.requiredRoles,
|
|
19
|
+
roleInfo.requiredRolesMode
|
|
20
|
+
);
|
|
21
|
+
return allowed;
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
return /* @__PURE__ */ jsx(BlogSidebar, { ...props, sidebar });
|
|
25
|
+
}
|
|
26
|
+
export {
|
|
27
|
+
BlogSidebarWrapper as default
|
|
28
|
+
};
|
|
29
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/theme/BlogSidebar/index.tsx"],"sourcesContent":["import { usePluginData } from \"@docusaurus/useGlobalData\";\nimport BlogSidebar, { type Props } from \"@theme-init/BlogSidebar\";\nimport { isAllowed, useRoles } from \"docusaurus-roles-plugin/runtime\";\nimport { type InternalRolesPluginOptions } from \"docusaurus-roles-plugin/options\";\n\nexport default function BlogSidebarWrapper({ sidebar, ...props }: Props) {\n const plugin = usePluginData(\n \"docusaurus-roles-plugin\",\n ) as InternalRolesPluginOptions;\n const { roles } = useRoles();\n if (sidebar) {\n sidebar.items = sidebar.items.filter((i) => {\n const roleInfo = plugin.rolesByPermalink.find(\n (r) => r.permalink === i.permalink,\n );\n if (!roleInfo) return true;\n const { allowed } = isAllowed(\n roles,\n roleInfo.requiredRoles,\n roleInfo.requiredRolesMode,\n );\n return allowed;\n });\n }\n return <BlogSidebar {...props} sidebar={sidebar} />;\n}\n"],"mappings":"AAwBS;AAxBT,SAAS,qBAAqB;AAC9B,OAAO,iBAAiC;AACxC,SAAS,WAAW,gBAAgB;AAGrB,SAAR,mBAAoC,EAAE,SAAS,GAAG,MAAM,GAAU;AACvE,QAAM,SAAS;AAAA,IACb;AAAA,EACF;AACA,QAAM,EAAE,MAAM,IAAI,SAAS;AAC3B,MAAI,SAAS;AACX,YAAQ,QAAQ,QAAQ,MAAM,OAAO,CAAC,MAAM;AAC1C,YAAM,WAAW,OAAO,iBAAiB;AAAA,QACvC,CAAC,MAAM,EAAE,cAAc,EAAE;AAAA,MAC3B;AACA,UAAI,CAAC,SAAU,QAAO;AACtB,YAAM,EAAE,QAAQ,IAAI;AAAA,QAClB;AAAA,QACA,SAAS;AAAA,QACT,SAAS;AAAA,MACX;AACA,aAAO;AAAA,IACT,CAAC;AAAA,EACH;AACA,SAAO,oBAAC,eAAa,GAAG,OAAO,SAAkB;AACnD;","names":[]}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import { BaseForbiddenContent } from "docusaurus-roles-plugin/runtime";
|
|
3
|
+
function ForbiddenDocItem({
|
|
4
|
+
missingRoles
|
|
5
|
+
}) {
|
|
6
|
+
return /* @__PURE__ */ jsx(BaseForbiddenContent, { prefixTranslateId: "theme.DocItem.Forbidden" });
|
|
7
|
+
}
|
|
8
|
+
export {
|
|
9
|
+
ForbiddenDocItem as default
|
|
10
|
+
};
|
|
11
|
+
//# sourceMappingURL=Forbidden.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/theme/DocItem/Forbidden.tsx"],"sourcesContent":["import { JSX } from \"react\";\nimport { BaseForbiddenContent } from \"docusaurus-roles-plugin/runtime\";\n\nexport default function ForbiddenDocItem({\n missingRoles,\n}: {\n missingRoles: string[];\n}): JSX.Element {\n return <BaseForbiddenContent prefixTranslateId=\"theme.DocItem.Forbidden\" />;\n}\n"],"mappings":"AAQS;AAPT,SAAS,4BAA4B;AAEtB,SAAR,iBAAkC;AAAA,EACvC;AACF,GAEgB;AACd,SAAO,oBAAC,wBAAqB,mBAAkB,2BAA0B;AAC3E;","names":[]}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import DocItem from "@theme-init/DocItem";
|
|
3
|
+
import RoleGate from "../RoleGate.js";
|
|
4
|
+
import { getRoleFrontMatter } from "docusaurus-roles-plugin/options";
|
|
5
|
+
import ForbiddenDocItem from "./Forbidden.js";
|
|
6
|
+
function DocItemWrapper(props) {
|
|
7
|
+
const frontMatter = getRoleFrontMatter(props?.content.frontMatter);
|
|
8
|
+
const requiredRoles = frontMatter.required_roles;
|
|
9
|
+
const mode = frontMatter.required_roles_mode;
|
|
10
|
+
return /* @__PURE__ */ jsx(
|
|
11
|
+
RoleGate,
|
|
12
|
+
{
|
|
13
|
+
requiredRoles,
|
|
14
|
+
mode,
|
|
15
|
+
forbidden: ForbiddenDocItem,
|
|
16
|
+
children: /* @__PURE__ */ jsx(DocItem, { ...props })
|
|
17
|
+
}
|
|
18
|
+
);
|
|
19
|
+
}
|
|
20
|
+
export {
|
|
21
|
+
DocItemWrapper as default
|
|
22
|
+
};
|
|
23
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/theme/DocItem/index.tsx"],"sourcesContent":["import DocItem, { type Props } from \"@theme-init/DocItem\";\nimport RoleGate from \"../RoleGate.js\";\nimport { getRoleFrontMatter } from \"docusaurus-roles-plugin/options\";\nimport ForbiddenDocItem from \"./Forbidden.js\";\n\nexport default function DocItemWrapper(props: Props) {\n const frontMatter = getRoleFrontMatter(props?.content.frontMatter);\n const requiredRoles = frontMatter.required_roles;\n const mode = frontMatter.required_roles_mode;\n\n return (\n <RoleGate\n requiredRoles={requiredRoles}\n mode={mode}\n forbidden={ForbiddenDocItem}\n >\n <DocItem {...props} />\n </RoleGate>\n );\n}\n"],"mappings":"AAgBM;AAhBN,OAAO,aAA6B;AACpC,OAAO,cAAc;AACrB,SAAS,0BAA0B;AACnC,OAAO,sBAAsB;AAEd,SAAR,eAAgC,OAAc;AACnD,QAAM,cAAc,mBAAmB,OAAO,QAAQ,WAAW;AACjE,QAAM,gBAAgB,YAAY;AAClC,QAAM,OAAO,YAAY;AAEzB,SACE;AAAA,IAAC;AAAA;AAAA,MACC;AAAA,MACA;AAAA,MACA,WAAW;AAAA,MAEX,8BAAC,WAAS,GAAG,OAAO;AAAA;AAAA,EACtB;AAEJ;","names":[]}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import DocSidebar from "@theme-init/DocSidebar";
|
|
3
|
+
import { getRoleFrontMatter } from "docusaurus-roles-plugin/options";
|
|
4
|
+
import { isAllowed, useRoles } from "docusaurus-roles-plugin/runtime";
|
|
5
|
+
const allowedOnly = (userRoles) => {
|
|
6
|
+
return (item) => {
|
|
7
|
+
const frontMatter = getRoleFrontMatter(item.customProps);
|
|
8
|
+
const category = item;
|
|
9
|
+
if (category.items) {
|
|
10
|
+
category.items = category.items.filter(allowedOnly(userRoles));
|
|
11
|
+
}
|
|
12
|
+
const { allowed } = isAllowed(
|
|
13
|
+
userRoles,
|
|
14
|
+
frontMatter.required_roles ?? [],
|
|
15
|
+
frontMatter.required_roles_mode ?? "all"
|
|
16
|
+
);
|
|
17
|
+
return allowed;
|
|
18
|
+
};
|
|
19
|
+
};
|
|
20
|
+
function RolesDocSidebar({ sidebar, ...props }) {
|
|
21
|
+
const { roles } = useRoles();
|
|
22
|
+
const filteredSidebar = sidebar.filter(allowedOnly(roles));
|
|
23
|
+
return /* @__PURE__ */ jsx(DocSidebar, { ...props, sidebar: filteredSidebar });
|
|
24
|
+
}
|
|
25
|
+
export {
|
|
26
|
+
RolesDocSidebar as default
|
|
27
|
+
};
|
|
28
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/theme/DocSidebar/index.tsx"],"sourcesContent":["import DocSidebar, { type Props } from \"@theme-init/DocSidebar\";\nimport { getRoleFrontMatter } from \"docusaurus-roles-plugin/options\";\nimport { isAllowed, useRoles } from \"docusaurus-roles-plugin/runtime\";\nimport type {\n PropSidebarItem,\n PropSidebarItemCategory,\n} from \"@docusaurus/plugin-content-docs\";\n\nconst allowedOnly = (userRoles: string[]) => {\n return (item: PropSidebarItem) => {\n const frontMatter = getRoleFrontMatter(item.customProps);\n const category = item as PropSidebarItemCategory;\n if (category.items) {\n category.items = category.items.filter(allowedOnly(userRoles));\n }\n const { allowed } = isAllowed(\n userRoles,\n frontMatter.required_roles ?? [],\n frontMatter.required_roles_mode ?? \"all\",\n );\n return allowed;\n };\n};\n\nexport default function RolesDocSidebar({ sidebar, ...props }: Props) {\n const { roles } = useRoles();\n const filteredSidebar = sidebar.filter(allowedOnly(roles));\n return <DocSidebar {...props} sidebar={filteredSidebar} />;\n}\n"],"mappings":"AA2BS;AA3BT,OAAO,gBAAgC;AACvC,SAAS,0BAA0B;AACnC,SAAS,WAAW,gBAAgB;AAMpC,MAAM,cAAc,CAAC,cAAwB;AAC3C,SAAO,CAAC,SAA0B;AAChC,UAAM,cAAc,mBAAmB,KAAK,WAAW;AACvD,UAAM,WAAW;AACjB,QAAI,SAAS,OAAO;AAClB,eAAS,QAAQ,SAAS,MAAM,OAAO,YAAY,SAAS,CAAC;AAAA,IAC/D;AACA,UAAM,EAAE,QAAQ,IAAI;AAAA,MAClB;AAAA,MACA,YAAY,kBAAkB,CAAC;AAAA,MAC/B,YAAY,uBAAuB;AAAA,IACrC;AACA,WAAO;AAAA,EACT;AACF;AAEe,SAAR,gBAAiC,EAAE,SAAS,GAAG,MAAM,GAAU;AACpE,QAAM,EAAE,MAAM,IAAI,SAAS;AAC3B,QAAM,kBAAkB,QAAQ,OAAO,YAAY,KAAK,CAAC;AACzD,SAAO,oBAAC,cAAY,GAAG,OAAO,SAAS,iBAAiB;AAC1D;","names":[]}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import NavbarItem from "@theme-init/NavbarItem";
|
|
3
|
+
import { useRoles, isAllowed } from "docusaurus-roles-plugin/runtime";
|
|
4
|
+
function RolesNavbarItem({
|
|
5
|
+
requiredRoles = [],
|
|
6
|
+
requiredRolesMode = "all",
|
|
7
|
+
...props
|
|
8
|
+
}) {
|
|
9
|
+
const { roles } = useRoles();
|
|
10
|
+
const { allowed } = isAllowed(roles, requiredRoles, requiredRolesMode);
|
|
11
|
+
if (!allowed) return;
|
|
12
|
+
return /* @__PURE__ */ jsx(NavbarItem, { ...props });
|
|
13
|
+
}
|
|
14
|
+
export {
|
|
15
|
+
RolesNavbarItem as default
|
|
16
|
+
};
|
|
17
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/theme/NavbarItem/index.tsx"],"sourcesContent":["import NavbarItem, { Props } from \"@theme-init/NavbarItem\";\nimport { useRoles, isAllowed } from \"docusaurus-roles-plugin/runtime\";\nimport { RoleRequirements } from \"docusaurus-roles-plugin/options\";\n\nexport default function RolesNavbarItem({\n requiredRoles = [],\n requiredRolesMode = \"all\",\n ...props\n}: Props & Partial<RoleRequirements>) {\n const { roles } = useRoles();\n\n const { allowed } = isAllowed(roles, requiredRoles, requiredRolesMode);\n if (!allowed) return;\n\n return <NavbarItem {...props} />;\n}\n"],"mappings":"AAcS;AAdT,OAAO,gBAA2B;AAClC,SAAS,UAAU,iBAAiB;AAGrB,SAAR,gBAAiC;AAAA,EACtC,gBAAgB,CAAC;AAAA,EACjB,oBAAoB;AAAA,EACpB,GAAG;AACL,GAAsC;AACpC,QAAM,EAAE,MAAM,IAAI,SAAS;AAE3B,QAAM,EAAE,QAAQ,IAAI,UAAU,OAAO,eAAe,iBAAiB;AACrE,MAAI,CAAC,QAAS;AAEd,SAAO,oBAAC,cAAY,GAAG,OAAO;AAChC;","names":[]}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { Fragment, jsx } from "react/jsx-runtime";
|
|
2
|
+
import { Redirect } from "@docusaurus/router";
|
|
3
|
+
import { usePluginData } from "@docusaurus/useGlobalData";
|
|
4
|
+
import {
|
|
5
|
+
useRoles,
|
|
6
|
+
isAllowed
|
|
7
|
+
} from "docusaurus-roles-plugin/runtime";
|
|
8
|
+
import RootWarning from "./RootWarning.js";
|
|
9
|
+
function getPluginConfig() {
|
|
10
|
+
return usePluginData("docusaurus-roles-plugin");
|
|
11
|
+
}
|
|
12
|
+
function RoleGate({
|
|
13
|
+
requiredRoles,
|
|
14
|
+
mode,
|
|
15
|
+
children,
|
|
16
|
+
forbidden: Forbidden
|
|
17
|
+
}) {
|
|
18
|
+
const pluginConfig = getPluginConfig();
|
|
19
|
+
const { roles, loading, hasProvider } = useRoles();
|
|
20
|
+
if (loading) {
|
|
21
|
+
return /* @__PURE__ */ jsx(Fragment, { children: "loading..." });
|
|
22
|
+
}
|
|
23
|
+
const required = requiredRoles ?? [];
|
|
24
|
+
if (required.length === 0) return children;
|
|
25
|
+
const effectiveMode = mode ?? "any";
|
|
26
|
+
if (!hasProvider) {
|
|
27
|
+
return /* @__PURE__ */ jsx(RootWarning, {});
|
|
28
|
+
}
|
|
29
|
+
const { allowed, missing } = isAllowed(roles, required, effectiveMode);
|
|
30
|
+
if (allowed) return children;
|
|
31
|
+
if (pluginConfig?.unauthorizedBehavior === "redirect") {
|
|
32
|
+
return /* @__PURE__ */ jsx(Redirect, { to: pluginConfig?.redirectTo ?? "/access-denied" });
|
|
33
|
+
}
|
|
34
|
+
return /* @__PURE__ */ jsx(Forbidden, { missingRoles: missing });
|
|
35
|
+
}
|
|
36
|
+
export {
|
|
37
|
+
RoleGate as default,
|
|
38
|
+
getPluginConfig
|
|
39
|
+
};
|
|
40
|
+
//# sourceMappingURL=RoleGate.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/theme/RoleGate.tsx"],"sourcesContent":["import React from \"react\";\nimport { Redirect } from \"@docusaurus/router\";\nimport { usePluginData } from \"@docusaurus/useGlobalData\";\nimport {\n useRoles,\n isAllowed,\n type RoleMode,\n} from \"docusaurus-roles-plugin/runtime\";\nimport RootWarning from \"./RootWarning.js\";\nimport { type RolesPluginOptions } from \"docusaurus-roles-plugin\";\n\ntype Props = {\n requiredRoles?: string[];\n mode?: RoleMode;\n children: React.ReactNode;\n forbidden: React.ElementType<{ missingRoles: string[] }>;\n};\n\nexport function getPluginConfig() {\n return usePluginData(\"docusaurus-roles-plugin\") as RolesPluginOptions;\n}\n\nexport default function RoleGate({\n requiredRoles,\n mode,\n children,\n forbidden: Forbidden,\n}: Props) {\n const pluginConfig = getPluginConfig();\n const { roles, loading, hasProvider } = useRoles();\n\n if (loading) {\n return <>loading...</>;\n }\n\n const required = requiredRoles ?? [];\n if (required.length === 0) return children;\n\n const effectiveMode: RoleMode = mode ?? \"any\";\n\n if (process.env.NODE_ENV !== \"production\" && !hasProvider) {\n return <RootWarning />;\n }\n\n const { allowed, missing } = isAllowed(roles, required, effectiveMode);\n if (allowed) return children;\n\n if (pluginConfig?.unauthorizedBehavior === \"redirect\") {\n return <Redirect to={pluginConfig?.redirectTo ?? \"/access-denied\"} />;\n }\n\n return <Forbidden missingRoles={missing} />;\n}\n"],"mappings":"AAgCW;AA/BX,SAAS,gBAAgB;AACzB,SAAS,qBAAqB;AAC9B;AAAA,EACE;AAAA,EACA;AAAA,OAEK;AACP,OAAO,iBAAiB;AAUjB,SAAS,kBAAkB;AAChC,SAAO,cAAc,yBAAyB;AAChD;AAEe,SAAR,SAA0B;AAAA,EAC/B;AAAA,EACA;AAAA,EACA;AAAA,EACA,WAAW;AACb,GAAU;AACR,QAAM,eAAe,gBAAgB;AACrC,QAAM,EAAE,OAAO,SAAS,YAAY,IAAI,SAAS;AAEjD,MAAI,SAAS;AACX,WAAO,gCAAE,wBAAU;AAAA,EACrB;AAEA,QAAM,WAAW,iBAAiB,CAAC;AACnC,MAAI,SAAS,WAAW,EAAG,QAAO;AAElC,QAAM,gBAA0B,QAAQ;AAExC,MAA6C,CAAC,aAAa;AACzD,WAAO,oBAAC,eAAY;AAAA,EACtB;AAEA,QAAM,EAAE,SAAS,QAAQ,IAAI,UAAU,OAAO,UAAU,aAAa;AACrE,MAAI,QAAS,QAAO;AAEpB,MAAI,cAAc,yBAAyB,YAAY;AACrD,WAAO,oBAAC,YAAS,IAAI,cAAc,cAAc,kBAAkB;AAAA,EACrE;AAEA,SAAO,oBAAC,aAAU,cAAc,SAAS;AAC3C;","names":[]}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
+
function RootWarning() {
|
|
3
|
+
return /* @__PURE__ */ jsxs("div", { style: { padding: 16 }, children: [
|
|
4
|
+
/* @__PURE__ */ jsx("h2", { children: "RolesProvider is missing" }),
|
|
5
|
+
/* @__PURE__ */ jsxs("p", { children: [
|
|
6
|
+
"You installed ",
|
|
7
|
+
/* @__PURE__ */ jsx("code", { children: "docusaurus-plugin-roles" }),
|
|
8
|
+
" but did not wrap your site Root with",
|
|
9
|
+
/* @__PURE__ */ jsx("code", { children: " RolesProvider" }),
|
|
10
|
+
"."
|
|
11
|
+
] }),
|
|
12
|
+
/* @__PURE__ */ jsxs("p", { children: [
|
|
13
|
+
"Swizzle Root and wrap it with ",
|
|
14
|
+
/* @__PURE__ */ jsx("code", { children: "RolesProvider" }),
|
|
15
|
+
" from",
|
|
16
|
+
" ",
|
|
17
|
+
/* @__PURE__ */ jsx("code", { children: "docusaurus-plugin-roles/runtime" }),
|
|
18
|
+
"."
|
|
19
|
+
] })
|
|
20
|
+
] });
|
|
21
|
+
}
|
|
22
|
+
export {
|
|
23
|
+
RootWarning as default
|
|
24
|
+
};
|
|
25
|
+
//# sourceMappingURL=RootWarning.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/theme/RootWarning.tsx"],"sourcesContent":["export default function RootWarning() {\n return (\n <div style={{ padding: 16 }}>\n <h2>RolesProvider is missing</h2>\n <p>\n You installed <code>docusaurus-plugin-roles</code> but did not wrap your\n site Root with\n <code> RolesProvider</code>.\n </p>\n <p>\n Swizzle Root and wrap it with <code>RolesProvider</code> from{\" \"}\n <code>docusaurus-plugin-roles/runtime</code>.\n </p>\n </div>\n );\n}\n"],"mappings":"AAGM,cACA,YADA;AAHS,SAAR,cAA+B;AACpC,SACE,qBAAC,SAAI,OAAO,EAAE,SAAS,GAAG,GACxB;AAAA,wBAAC,QAAG,sCAAwB;AAAA,IAC5B,qBAAC,OAAE;AAAA;AAAA,MACa,oBAAC,UAAK,qCAAuB;AAAA,MAAO;AAAA,MAElD,oBAAC,UAAK,4BAAc;AAAA,MAAO;AAAA,OAC7B;AAAA,IACA,qBAAC,OAAE;AAAA;AAAA,MAC6B,oBAAC,UAAK,2BAAa;AAAA,MAAO;AAAA,MAAM;AAAA,MAC9D,oBAAC,UAAK,6CAA+B;AAAA,MAAO;AAAA,OAC9C;AAAA,KACF;AAEJ;","names":[]}
|
package/package.json
CHANGED
|
@@ -1,7 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "docusaurus-roles-plugin",
|
|
3
|
-
"version": "1.0.0-beta.
|
|
3
|
+
"version": "1.0.0-beta.3",
|
|
4
4
|
"description": "Role-based gating for Docusaurus docs/blog via React context + front matter",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "git+https://github.com/NicholasMata/docusaurus-roles-plugin.git"
|
|
8
|
+
},
|
|
9
|
+
"homepage": "https://github.com/NicholasMata/docusaurus-roles-plugin",
|
|
10
|
+
"bugs": {
|
|
11
|
+
"url": "https://github.com/NicholasMata/docusaurus-roles-plugin/issues"
|
|
12
|
+
},
|
|
5
13
|
"license": "MIT",
|
|
6
14
|
"type": "module",
|
|
7
15
|
"main": "dist/index.cjs",
|
|
@@ -17,7 +25,14 @@
|
|
|
17
25
|
"types": "./dist/runtime/index.d.ts",
|
|
18
26
|
"require": "./dist/runtime/index.cjs",
|
|
19
27
|
"import": "./dist/runtime/index.js"
|
|
20
|
-
}
|
|
28
|
+
},
|
|
29
|
+
"./options": {
|
|
30
|
+
"import": "./dist/options/index.js",
|
|
31
|
+
"require": "./dist/options/index.cjs",
|
|
32
|
+
"types": "./dist/options/index.d.ts"
|
|
33
|
+
},
|
|
34
|
+
|
|
35
|
+
"./theme/*": "./dist/theme/*"
|
|
21
36
|
},
|
|
22
37
|
"files": [
|
|
23
38
|
"dist",
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import BlogListPage from "@theme-init/BlogListPage";
|
|
2
2
|
import { useRoles, isAllowed } from "docusaurus-roles-plugin/runtime";
|
|
3
3
|
import type { Props } from "@theme/BlogListPage";
|
|
4
|
-
import { getRoleFrontMatter } from "
|
|
4
|
+
import { getRoleFrontMatter } from "docusaurus-roles-plugin/options";
|
|
5
5
|
|
|
6
6
|
export default function BlogListPageWrapper({ items, ...rest }: Props) {
|
|
7
7
|
const { roles, loading } = useRoles();
|
|
@@ -8,10 +8,7 @@ export default function ForbiddenBlogPostItem({
|
|
|
8
8
|
}): ReactNode {
|
|
9
9
|
return (
|
|
10
10
|
<main className={"container margin-vert--xl"}>
|
|
11
|
-
<BaseForbiddenContent
|
|
12
|
-
prefixTranslateId="theme.BlogPostItem.Forbidden"
|
|
13
|
-
missingRoles={missingRoles}
|
|
14
|
-
/>
|
|
11
|
+
<BaseForbiddenContent prefixTranslateId="theme.BlogPostItem.Forbidden" />
|
|
15
12
|
</main>
|
|
16
13
|
);
|
|
17
14
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import BlogPostItem, { type Props } from "@theme-init/BlogPostItem";
|
|
2
|
-
import RoleGate from "../RoleGate";
|
|
3
|
-
import { getRoleFrontMatter } from "
|
|
2
|
+
import RoleGate from "../RoleGate.js";
|
|
3
|
+
import { getRoleFrontMatter } from "docusaurus-roles-plugin/options";
|
|
4
4
|
import { useBlogPost } from "@docusaurus/plugin-content-blog/client";
|
|
5
|
-
import ForbiddenBlogPostItem from "./Forbidden";
|
|
5
|
+
import ForbiddenBlogPostItem from "./Forbidden.js";
|
|
6
6
|
|
|
7
7
|
export default function BlogPostItemWrapper(props: Props) {
|
|
8
8
|
const { metadata } = useBlogPost();
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { usePluginData } from "@docusaurus/useGlobalData";
|
|
2
2
|
import BlogSidebar, { type Props } from "@theme-init/BlogSidebar";
|
|
3
3
|
import { isAllowed, useRoles } from "docusaurus-roles-plugin/runtime";
|
|
4
|
-
import { type
|
|
4
|
+
import { type InternalRolesPluginOptions } from "docusaurus-roles-plugin/options";
|
|
5
5
|
|
|
6
6
|
export default function BlogSidebarWrapper({ sidebar, ...props }: Props) {
|
|
7
|
-
const plugin = usePluginData(
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
const plugin = usePluginData(
|
|
8
|
+
"docusaurus-roles-plugin",
|
|
9
|
+
) as InternalRolesPluginOptions;
|
|
10
10
|
const { roles } = useRoles();
|
|
11
11
|
if (sidebar) {
|
|
12
12
|
sidebar.items = sidebar.items.filter((i) => {
|
|
@@ -6,10 +6,5 @@ export default function ForbiddenDocItem({
|
|
|
6
6
|
}: {
|
|
7
7
|
missingRoles: string[];
|
|
8
8
|
}): JSX.Element {
|
|
9
|
-
return
|
|
10
|
-
<BaseForbiddenContent
|
|
11
|
-
prefixTranslateId="theme.DocItem.Forbidden"
|
|
12
|
-
missingRoles={missingRoles}
|
|
13
|
-
/>
|
|
14
|
-
);
|
|
9
|
+
return <BaseForbiddenContent prefixTranslateId="theme.DocItem.Forbidden" />;
|
|
15
10
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import DocItem, { type Props } from "@theme-init/DocItem";
|
|
2
|
-
import RoleGate from "../RoleGate";
|
|
3
|
-
import { getRoleFrontMatter } from "
|
|
4
|
-
import ForbiddenDocItem from "./Forbidden";
|
|
2
|
+
import RoleGate from "../RoleGate.js";
|
|
3
|
+
import { getRoleFrontMatter } from "docusaurus-roles-plugin/options";
|
|
4
|
+
import ForbiddenDocItem from "./Forbidden.js";
|
|
5
5
|
|
|
6
6
|
export default function DocItemWrapper(props: Props) {
|
|
7
7
|
const frontMatter = getRoleFrontMatter(props?.content.frontMatter);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import DocSidebar, { type Props } from "@theme-init/DocSidebar";
|
|
2
|
-
import { getRoleFrontMatter } from "
|
|
3
|
-
import { isAllowed, useRoles } from "
|
|
2
|
+
import { getRoleFrontMatter } from "docusaurus-roles-plugin/options";
|
|
3
|
+
import { isAllowed, useRoles } from "docusaurus-roles-plugin/runtime";
|
|
4
4
|
import type {
|
|
5
5
|
PropSidebarItem,
|
|
6
6
|
PropSidebarItemCategory,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import NavbarItem, { Props } from "@theme-init/NavbarItem";
|
|
2
2
|
import { useRoles, isAllowed } from "docusaurus-roles-plugin/runtime";
|
|
3
|
-
import { RoleRequirements } from "
|
|
3
|
+
import { RoleRequirements } from "docusaurus-roles-plugin/options";
|
|
4
4
|
|
|
5
5
|
export default function RolesNavbarItem({
|
|
6
6
|
requiredRoles = [],
|
package/src/theme/RoleGate.tsx
CHANGED
|
@@ -6,8 +6,8 @@ import {
|
|
|
6
6
|
isAllowed,
|
|
7
7
|
type RoleMode,
|
|
8
8
|
} from "docusaurus-roles-plugin/runtime";
|
|
9
|
-
import RootWarning from "./RootWarning";
|
|
10
|
-
import {
|
|
9
|
+
import RootWarning from "./RootWarning.js";
|
|
10
|
+
import { type RolesPluginOptions } from "docusaurus-roles-plugin";
|
|
11
11
|
|
|
12
12
|
type Props = {
|
|
13
13
|
requiredRoles?: string[];
|
|
@@ -17,7 +17,7 @@ type Props = {
|
|
|
17
17
|
};
|
|
18
18
|
|
|
19
19
|
export function getPluginConfig() {
|
|
20
|
-
return usePluginData("docusaurus-roles-plugin") as
|
|
20
|
+
return usePluginData("docusaurus-roles-plugin") as RolesPluginOptions;
|
|
21
21
|
}
|
|
22
22
|
|
|
23
23
|
export default function RoleGate({
|