@bndynet/vue-site 1.0.0 → 1.0.2

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/router.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import { RouterHistory } from 'vue-router';
1
2
  import { NavItem, ResolvedNavItem, StandalonePage } from './types';
2
3
  /**
3
4
  * Recursively drop nav items whose `visible()` predicate resolves to `false`. Sibling
@@ -6,4 +7,4 @@ import { NavItem, ResolvedNavItem, StandalonePage } from './types';
6
7
  */
7
8
  export declare function filterNavItems(items: NavItem[]): Promise<NavItem[]>;
8
9
  export declare function resolveNavItems(items: NavItem[], parentIndex?: number): ResolvedNavItem[];
9
- export declare function createSiteRouter(resolvedNav: ResolvedNavItem[], pages?: StandalonePage[]): Promise<import('vue-router').Router>;
10
+ export declare function createSiteRouter(resolvedNav: ResolvedNavItem[], pages?: StandalonePage[], history?: RouterHistory): Promise<import('vue-router').Router>;
package/dist/types.d.ts CHANGED
@@ -1,5 +1,44 @@
1
1
  import { App, Component } from 'vue';
2
2
  import { UserConfig as ViteUserConfig } from 'vite';
3
+ import { RouteLocationNormalized } from 'vue-router';
4
+ /**
5
+ * Per-page authorization requirement. Attached to a `NavItem` / `StandalonePage` via `auth`
6
+ * and stored on the route's `meta`. It is opaque metadata interpreted by
7
+ * `SiteConfig.auth.authorize` — use `true` for "any authenticated user", a role name or list of
8
+ * roles, or a custom predicate. The framework never inspects the rule itself; it forwards it to
9
+ * `authorize`.
10
+ */
11
+ export type AuthRule = boolean | string | string[] | ((ctx: AuthContext) => boolean | Promise<boolean>);
12
+ /**
13
+ * Context passed to `SiteConfig.auth.authorize`. `to` / `from` are present when the guard runs
14
+ * during navigation; they are absent during the one-time startup pass that filters the nav menu.
15
+ */
16
+ export interface AuthContext {
17
+ /** The `auth` rule declared on the matched nav / standalone item. */
18
+ rule: AuthRule;
19
+ /** The resolved nav item being evaluated, when available. */
20
+ item?: ResolvedNavItem;
21
+ /** Target route (navigation-time only). */
22
+ to?: RouteLocationNormalized;
23
+ /** Previous route (navigation-time only). */
24
+ from?: RouteLocationNormalized;
25
+ }
26
+ /** Central authorization policy. Configure once in `site.config.ts`; pages opt in with `auth`. */
27
+ export interface AuthConfig {
28
+ /**
29
+ * Decide whether the current user may access a route carrying `rule`. Return `true` to allow,
30
+ * `false` to deny, or a path string to redirect (e.g. your login page). Runs at navigation time
31
+ * on every guarded route, and once at startup (with only `rule` / `item`) to filter the nav menu
32
+ * — there, any result other than `true` hides the item.
33
+ */
34
+ authorize: (ctx: AuthContext) => boolean | string | Promise<boolean | string>;
35
+ /**
36
+ * Where to send users when `authorize` returns `false`. The denied target is appended as a
37
+ * `redirect` query param (e.g. `/login?redirect=/admin`). If omitted, denied navigations are
38
+ * simply cancelled.
39
+ */
40
+ loginPath?: string;
41
+ }
3
42
  export interface NavItem {
4
43
  label: string;
5
44
  icon?: string;
@@ -26,6 +65,14 @@ export interface NavItem {
26
65
  * permission changes (e.g. login/logout) without recreating the app.
27
66
  */
28
67
  visible?: () => boolean | Promise<boolean>;
68
+ /**
69
+ * Per-page authorization rule, interpreted by `SiteConfig.auth.authorize`. Unlike `visible`
70
+ * (a build/startup-time existence switch), `auth` keeps the route registered and is enforced by
71
+ * a navigation guard on every navigation, so it reacts to login/logout and can redirect to a
72
+ * login page. It is also evaluated once at startup to hide unauthorized items from the menu.
73
+ * Requires `SiteConfig.auth` to be set; otherwise it is ignored.
74
+ */
75
+ auth?: AuthRule;
29
76
  }
30
77
  /**
31
78
  * A standalone, full-screen page registered outside the `nav` tree.
@@ -46,6 +93,11 @@ export interface StandalonePage {
46
93
  * Evaluated only at startup, so it does not react to later permission changes.
47
94
  */
48
95
  visible?: () => boolean | Promise<boolean>;
96
+ /**
97
+ * Per-page authorization rule, interpreted by `SiteConfig.auth.authorize` and enforced by a
98
+ * navigation guard. See `NavItem.auth`. Requires `SiteConfig.auth` to be set.
99
+ */
100
+ auth?: AuthRule;
49
101
  }
50
102
  /** CSS custom properties for one theme (`--color-bg`, etc.). */
51
103
  export type ThemePaletteVars = Record<string, string>;
@@ -87,6 +139,24 @@ export interface ThemeConfig {
87
139
  dark?: ThemePaletteVars;
88
140
  };
89
141
  }
142
+ /** Router history configuration. */
143
+ export interface RouterConfig {
144
+ /**
145
+ * History mode:
146
+ * - `'hash'` (default) — URLs use a `#` fragment (e.g. `/app/#/admin`). Works on any static host
147
+ * with no server config; route paths are independent of the public base.
148
+ * - `'web'` — HTML5 history with clean URLs (e.g. `/app/admin`). Requires the host to serve
149
+ * `index.html` for unknown paths (SPA fallback).
150
+ * @default 'hash'
151
+ */
152
+ mode?: 'hash' | 'web';
153
+ /**
154
+ * Base path for `'web'` mode (ignored for `'hash'`). Defaults to the app's public base
155
+ * (`import.meta.env.BASE_URL`, set by the CLI's `--base` / `env.vite.base`). Set this only to
156
+ * override that default (e.g. when calling `createSiteApp` from a custom entry).
157
+ */
158
+ base?: string;
159
+ }
90
160
  export type SiteViteConfig = Partial<Omit<ViteUserConfig, 'root'>> & {
91
161
  /** Options passed to @vitejs/plugin-vue (the Vue plugin is added automatically) */
92
162
  vue?: Record<string, any>;
@@ -127,6 +197,14 @@ export interface SiteConfig {
127
197
  * still applies via root CSS variables.
128
198
  */
129
199
  pages?: StandalonePage[];
200
+ /**
201
+ * Central authorization policy. When set, any `NavItem` / `StandalonePage` carrying an `auth`
202
+ * rule is enforced by a navigation guard (redirecting to `auth.loginPath` on denial) and hidden
203
+ * from the nav menu at startup when not authorized. Omit to disable authorization entirely.
204
+ */
205
+ auth?: AuthConfig;
206
+ /** Router history configuration (hash vs HTML5). See `RouterConfig`. */
207
+ router?: RouterConfig;
130
208
  theme?: ThemeConfig;
131
209
  footer?: string;
132
210
  readme?: string;
@@ -137,6 +215,12 @@ export interface SiteConfig {
137
215
  * then site root). Injected by the `vue-site` CLI; omit when calling `createSiteApp` manually.
138
216
  */
139
217
  packageRepository?: string | null;
218
+ /**
219
+ * App public base path. Injected by the `vue-site` CLI from `import.meta.env.BASE_URL` (the
220
+ * resolved Vite `base`) and used as the default base for `'web'` history mode. Prefer setting
221
+ * `router.base` to override; omit when calling `createSiteApp` manually.
222
+ */
223
+ baseUrl?: string;
140
224
  /** Development / build environment configuration */
141
225
  env?: SiteEnvConfig;
142
226
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bndynet/vue-site",
3
- "version": "1.0.0",
3
+ "version": "1.0.2",
4
4
  "type": "module",
5
5
  "description": "A configurable Vue 3 site framework with sidebar navigation, markdown rendering, and theme switching.",
6
6
  "repository": {