zudoku 0.78.0 → 0.78.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.
Files changed (91) hide show
  1. package/dist/cli/cli.js +602 -160
  2. package/dist/cli/worker.js +6 -4
  3. package/dist/declarations/app/adapter.d.ts +12 -0
  4. package/dist/declarations/app/adapters/cloudflare.d.ts +8 -0
  5. package/dist/declarations/app/adapters/lambda.d.ts +13 -0
  6. package/dist/declarations/app/adapters/node.d.ts +12 -0
  7. package/dist/declarations/app/adapters/vercel.d.ts +14 -0
  8. package/dist/declarations/app/entry.client.d.ts +2 -0
  9. package/dist/declarations/app/entry.server.d.ts +13 -0
  10. package/dist/declarations/app/protectChunks.d.ts +17 -0
  11. package/dist/declarations/app/wrapProtectedRoutes.d.ts +4 -0
  12. package/dist/declarations/config/validators/HeaderNavigationSchema.d.ts +216 -80
  13. package/dist/declarations/config/validators/ZudokuConfig.d.ts +81 -30
  14. package/dist/declarations/config/validators/icon-types.d.ts +1 -1
  15. package/dist/declarations/lib/authentication/authentication.d.ts +7 -0
  16. package/dist/declarations/lib/authentication/cookie-sync.d.ts +3 -0
  17. package/dist/declarations/lib/authentication/cookies.d.ts +10 -0
  18. package/dist/declarations/lib/authentication/providers/azureb2c.d.ts +6 -1
  19. package/dist/declarations/lib/authentication/providers/clerk.d.ts +1 -0
  20. package/dist/declarations/lib/authentication/providers/openid.d.ts +2 -1
  21. package/dist/declarations/lib/authentication/providers/supabase.d.ts +2 -0
  22. package/dist/declarations/lib/authentication/session-handler.d.ts +81 -0
  23. package/dist/declarations/lib/authentication/state.d.ts +7 -0
  24. package/dist/declarations/lib/authentication/verify-cache.d.ts +2 -0
  25. package/dist/declarations/lib/components/Bootstrap.d.ts +2 -2
  26. package/dist/declarations/lib/components/Heading.d.ts +1 -1
  27. package/dist/declarations/lib/components/context/RenderContext.d.ts +6 -0
  28. package/dist/declarations/lib/core/RouteGuard.d.ts +11 -0
  29. package/dist/declarations/lib/core/ZudokuContext.d.ts +5 -2
  30. package/dist/declarations/lib/manifest.d.ts +25 -0
  31. package/dist/declarations/lib/util/url.d.ts +2 -0
  32. package/dist/flat-config.d.ts +1 -1
  33. package/docs/configuration/protected-routes.md +21 -4
  34. package/docs/guides/server-side-content-protection.md +207 -0
  35. package/package.json +26 -4
  36. package/src/app/adapter.ts +16 -0
  37. package/src/app/adapters/cloudflare.ts +18 -0
  38. package/src/app/adapters/lambda.ts +36 -0
  39. package/src/app/adapters/node.ts +32 -0
  40. package/src/app/adapters/vercel.ts +39 -0
  41. package/src/app/demo.tsx +2 -2
  42. package/src/app/entry.client.tsx +19 -7
  43. package/src/app/entry.server.tsx +133 -9
  44. package/src/app/main.tsx +21 -3
  45. package/src/app/protectChunks.ts +64 -0
  46. package/src/app/standalone.tsx +2 -2
  47. package/src/app/wrapProtectedRoutes.ts +82 -0
  48. package/src/config/validators/icon-types.ts +17 -0
  49. package/src/lib/authentication/authentication.ts +15 -0
  50. package/src/lib/authentication/cookie-sync.ts +90 -0
  51. package/src/lib/authentication/cookies.ts +54 -0
  52. package/src/lib/authentication/hook.ts +13 -0
  53. package/src/lib/authentication/providers/azureb2c.tsx +70 -2
  54. package/src/lib/authentication/providers/clerk.tsx +49 -0
  55. package/src/lib/authentication/providers/openid.tsx +46 -0
  56. package/src/lib/authentication/providers/supabase.tsx +30 -2
  57. package/src/lib/authentication/session-handler.ts +164 -0
  58. package/src/lib/authentication/state.ts +36 -5
  59. package/src/lib/authentication/verify-cache.ts +32 -0
  60. package/src/lib/components/Bootstrap.tsx +20 -14
  61. package/src/lib/components/Header.tsx +56 -57
  62. package/src/lib/components/MobileTopNavigation.tsx +66 -67
  63. package/src/lib/components/Zudoku.tsx +14 -1
  64. package/src/lib/components/context/RenderContext.ts +8 -0
  65. package/src/lib/components/context/ZudokuContext.ts +2 -1
  66. package/src/lib/core/RouteGuard.tsx +50 -29
  67. package/src/lib/core/ZudokuContext.ts +39 -6
  68. package/src/lib/errors/RouterError.tsx +43 -1
  69. package/src/lib/manifest.ts +62 -0
  70. package/src/lib/oas/parser/dereference/index.ts +2 -1
  71. package/src/lib/oas/parser/dereference/resolveRef.ts +2 -1
  72. package/src/lib/oas/parser/index.ts +1 -1
  73. package/src/lib/plugins/openapi/client/createServer.ts +13 -4
  74. package/src/lib/plugins/search-pagefind/index.tsx +1 -4
  75. package/src/lib/util/os.ts +1 -0
  76. package/src/lib/util/url.ts +13 -0
  77. package/src/vite/build.ts +84 -24
  78. package/src/vite/config.ts +51 -5
  79. package/src/vite/dev-server.ts +61 -8
  80. package/src/vite/manifest.ts +15 -0
  81. package/src/vite/plugin-api.ts +3 -1
  82. package/src/vite/plugin-markdown-export.ts +3 -9
  83. package/src/vite/prerender/worker.ts +2 -4
  84. package/src/vite/protected/annotator.ts +136 -0
  85. package/src/vite/protected/build.ts +151 -0
  86. package/src/vite/protected/registry.ts +82 -0
  87. package/src/vite/ssr-templates/cloudflare.ts +5 -18
  88. package/src/vite/ssr-templates/lambda.ts +4 -0
  89. package/src/vite/ssr-templates/node.ts +7 -22
  90. package/src/vite/ssr-templates/vercel.ts +6 -20
  91. package/src/vite-env.d.ts +1 -0
@@ -2,7 +2,6 @@
2
2
  import fs from "node:fs/promises";
3
3
  import path from "node:path";
4
4
  import Piscina from "piscina";
5
- import { matchPath } from "react-router";
6
5
 
7
6
  // src/config/validators/ProtectedRoutesSchema.ts
8
7
  import { z } from "zod/mini";
@@ -45,6 +44,11 @@ var joinUrl = (...parts) => {
45
44
  return buildUrl(parsedParts);
46
45
  };
47
46
 
47
+ // src/lib/util/url.ts
48
+ import { matchPath } from "react-router";
49
+ var matchesProtectedPattern = (pattern, path2) => matchPath({ path: pattern, end: true }, path2) != null;
50
+ var matchesAnyProtectedPattern = (patterns, path2) => patterns.some((p) => matchesProtectedPattern(p, path2));
51
+
48
52
  // src/lib/core/transform-config.ts
49
53
  import { isValidElement } from "react";
50
54
  var isPlainObject = (value) => typeof value === "object" && value !== null && !Array.isArray(value) && Object.getPrototypeOf(value) === Object.prototype;
@@ -129,9 +133,7 @@ var renderPage = async ({ urlPath }) => {
129
133
  const outputPath = path.join(distDir, filename);
130
134
  const request = new Request(url);
131
135
  const protectedRoutes = ProtectedRoutesSchema.parse(config.protectedRoutes);
132
- const isProtectedRoute = protectedRoutes ? Object.keys(protectedRoutes).some(
133
- (route) => matchPath({ path: route, end: true }, urlPath)
134
- ) : false;
136
+ const isProtectedRoute = protectedRoutes ? matchesAnyProtectedPattern(Object.keys(protectedRoutes), urlPath) : false;
135
137
  const response = await server.handleRequest({
136
138
  template,
137
139
  request,
@@ -0,0 +1,12 @@
1
+ import type { Hono } from "hono";
2
+ import type { ZudokuManifest } from "../lib/manifest.js";
3
+ import type { protectChunks } from "./protectChunks.js";
4
+ export type AdapterContext = {
5
+ basePath?: string;
6
+ manifest: ZudokuManifest;
7
+ protectChunks: typeof protectChunks;
8
+ };
9
+ export type Adapter<T = Hono> = {
10
+ setup?: (app: Hono, ctx: AdapterContext) => void;
11
+ finalize?: (app: Hono) => T;
12
+ };
@@ -0,0 +1,8 @@
1
+ import type { Adapter } from "../adapter.js";
2
+ type AssetsBinding = {
3
+ ASSETS: {
4
+ fetch: (req: Request) => Promise<Response>;
5
+ };
6
+ };
7
+ export declare const cloudflare: <Env extends AssetsBinding = AssetsBinding>() => Adapter;
8
+ export {};
@@ -0,0 +1,13 @@
1
+ import { handle } from "hono/aws-lambda";
2
+ import type { Adapter } from "../adapter.js";
3
+ import type { protectChunks } from "../protectChunks.js";
4
+ type ProtectChunksOpts = Parameters<typeof protectChunks>[0];
5
+ type ServeStaticFactory = Extract<ProtectChunksOpts, {
6
+ serveStatic: unknown;
7
+ }>["serveStatic"];
8
+ export type LambdaAdapterOptions = {
9
+ serverDir?: string;
10
+ serveStatic?: ServeStaticFactory;
11
+ };
12
+ export declare const lambda: (opts?: LambdaAdapterOptions) => Adapter<ReturnType<typeof handle>>;
13
+ export {};
@@ -0,0 +1,12 @@
1
+ import type { Adapter } from "../adapter.js";
2
+ import type { protectChunks } from "../protectChunks.js";
3
+ type ProtectChunksOpts = Parameters<typeof protectChunks>[0];
4
+ type ServeStaticFactory = Extract<ProtectChunksOpts, {
5
+ serveStatic: unknown;
6
+ }>["serveStatic"];
7
+ export type NodeAdapterOptions = {
8
+ serverDir?: string;
9
+ serveStatic?: ServeStaticFactory;
10
+ };
11
+ export declare const node: (opts?: NodeAdapterOptions) => Adapter;
12
+ export {};
@@ -0,0 +1,14 @@
1
+ import { handle } from "hono/vercel";
2
+ import type { Adapter } from "../adapter.js";
3
+ import type { protectChunks } from "../protectChunks.js";
4
+ type ProtectChunksOpts = Parameters<typeof protectChunks>[0];
5
+ type ServeStaticFactory = Extract<ProtectChunksOpts, {
6
+ serveStatic: unknown;
7
+ }>["serveStatic"];
8
+ export type VercelAdapterOptions = {
9
+ serverDir?: string;
10
+ staticDir?: string;
11
+ serveStatic?: ServeStaticFactory;
12
+ };
13
+ export declare const vercel: (opts?: VercelAdapterOptions) => Adapter<ReturnType<typeof handle>>;
14
+ export {};
@@ -1,6 +1,8 @@
1
+ import type { DehydratedState } from "@tanstack/react-query";
1
2
  import "vite/modulepreload-polyfill";
2
3
  declare global {
3
4
  interface Window {
4
5
  ZUDOKU_VERSION: string;
6
+ ZUDOKU_DATA?: DehydratedState;
5
7
  }
6
8
  }
@@ -1,7 +1,12 @@
1
+ import { Hono } from "hono";
1
2
  import { type RouteObject } from "react-router";
2
3
  import "vite/modulepreload-polyfill";
4
+ import type { Adapter } from "./adapter.js";
3
5
  import { getRoutesByConfig } from "./main.js";
6
+ import { protectChunks as rawProtectChunks } from "./protectChunks.js";
4
7
  export { getRoutesByConfig };
8
+ export type { Adapter, AdapterContext } from "./adapter.js";
9
+ export declare const protectChunks: typeof rawProtectChunks;
5
10
  export declare const handleRequest: ({ template, request, routes, basePath, bypassProtection, }: {
6
11
  template: string;
7
12
  request: Request;
@@ -9,3 +14,11 @@ export declare const handleRequest: ({ template, request, routes, basePath, bypa
9
14
  basePath?: string;
10
15
  bypassProtection?: boolean;
11
16
  }) => Promise<Response>;
17
+ export declare const manifest: import("../lib/manifest.js").ZudokuManifest;
18
+ export declare const createApp: () => Hono<import("hono/types").BlankEnv, import("hono/types").BlankSchema, "/">;
19
+ export type MountOptions<T = Hono> = {
20
+ adapter?: Adapter<T>;
21
+ template?: string;
22
+ };
23
+ export declare const mount: <T = Hono>(app: Hono, options?: MountOptions<T>) => T;
24
+ export declare const createServer: <T = Hono>(options?: MountOptions<T>) => T;
@@ -0,0 +1,17 @@
1
+ import type { MiddlewareHandler } from "hono";
2
+ type ServeStaticFactory = (opts: {
3
+ root: string;
4
+ rewriteRequestPath?: (p: string) => string;
5
+ }) => MiddlewareHandler;
6
+ type FilesystemServe = {
7
+ serverDir: string;
8
+ serveStatic: ServeStaticFactory;
9
+ };
10
+ type CustomServe = {
11
+ serve: MiddlewareHandler;
12
+ };
13
+ export declare const protectChunks: (opts: {
14
+ basePath?: string;
15
+ verifyAccessToken?: (token: string) => Promise<unknown>;
16
+ } & (FilesystemServe | CustomServe)) => MiddlewareHandler;
17
+ export {};
@@ -0,0 +1,4 @@
1
+ import type { RouteObject } from "react-router";
2
+ import type { ProtectedRoutesInput } from "../config/validators/ProtectedRoutesSchema.js";
3
+ export declare const wrapProtectedRoutes: (routes: RouteObject[], protectedRoutes: ProtectedRoutesInput, isAuthenticated: boolean, basePath?: string) => RouteObject[];
4
+ export declare const warnInlineProtectedRoutes: (routes: RouteObject[], protectedRoutes: ProtectedRoutesInput, basePath?: string) => void;