@blaaiz/docs-core 0.1.1 → 0.3.0

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/generator.js CHANGED
@@ -1,4 +1,4 @@
1
- import { parseNavigation, planDocsTree, mergeOpenApiDocuments } from './chunk-3ZX4WIE3.js';
1
+ import { parseNavigation, planDocsTree, mergeOpenApiDocuments } from './chunk-ICDBGTIJ.js';
2
2
  import { readFile, rm, mkdir, writeFile } from 'fs/promises';
3
3
  import path from 'path';
4
4
 
package/dist/index.cjs CHANGED
@@ -2528,6 +2528,92 @@ function createSignOut(options = {}) {
2528
2528
  };
2529
2529
  }
2530
2530
 
2531
+ // src/core/auth/site-auth.ts
2532
+ var notConfigured = () => new Response("This sign-in method is not configured for this site.", { status: 501 });
2533
+ var PUBLIC_SITE = {
2534
+ enabled: false,
2535
+ signInPath: "/signin",
2536
+ secretEnabled: false,
2537
+ googleEnabled: false,
2538
+ emailSignIn: () => Promise.resolve(notConfigured()),
2539
+ secretSignIn: () => Promise.resolve(notConfigured()),
2540
+ google: {
2541
+ start: () => notConfigured(),
2542
+ callback: () => Promise.resolve(notConfigured())
2543
+ }
2544
+ };
2545
+ function createSiteAuth(auth, options = {}) {
2546
+ if (auth === "public") {
2547
+ return {
2548
+ ...PUBLIC_SITE,
2549
+ gate: () => Promise.resolve(null),
2550
+ signOut: createSignOut()
2551
+ };
2552
+ }
2553
+ return workspaceSiteAuth(auth, options);
2554
+ }
2555
+ function workspaceSiteAuth(auth, options) {
2556
+ const env = options.env ?? ((name) => process.env[name]);
2557
+ const signInPath = auth.signInPath ?? "/signin";
2558
+ const secure = auth.secureCookies ?? true;
2559
+ const ttlSeconds = auth.sessionTtlSeconds;
2560
+ const sessionSecretEnv = auth.sessionSecretEnv ?? "DOCS_SESSION_SECRET";
2561
+ const secret = env(sessionSecretEnv) ?? "";
2562
+ if (secret === "") {
2563
+ throw new DocsConfigError(
2564
+ `auth.mode is 'workspace': set the ${sessionSecretEnv} environment variable to a long random value (for example: openssl rand -hex 32).`
2565
+ );
2566
+ }
2567
+ const shared = {
2568
+ secret,
2569
+ allowedDomains: auth.allowedDomains,
2570
+ secureCookies: secure,
2571
+ signInPath,
2572
+ ...ttlSeconds === void 0 ? {} : { ttlSeconds }
2573
+ };
2574
+ const emailEnabled = auth.providers.email === true;
2575
+ const accessSecret = auth.providers.secret ? env(auth.providers.secret.secretEnv ?? "DOCS_ACCESS_SECRET") ?? "" : "";
2576
+ const secretEnabled = accessSecret !== "";
2577
+ const googleConfig = auth.providers.google;
2578
+ const clientId = googleConfig ? env(googleConfig.clientIdEnv ?? "GOOGLE_CLIENT_ID") : void 0;
2579
+ const clientSecret = googleConfig ? env(googleConfig.clientSecretEnv ?? "GOOGLE_CLIENT_SECRET") : void 0;
2580
+ const googleEnabled = Boolean(googleConfig && clientId && clientSecret);
2581
+ const emailSignIn = emailEnabled ? createEmailSignIn(shared) : null;
2582
+ const secretSignIn = secretEnabled ? createSecretSignIn({ ...shared, accessSecret }) : null;
2583
+ const googleFor = (request) => {
2584
+ if (!googleEnabled || !googleConfig || !clientId || !clientSecret) {
2585
+ return null;
2586
+ }
2587
+ const origin = new URL(request.url).origin;
2588
+ const redirectPath = googleConfig.redirectPath ?? "/api/auth/google/callback";
2589
+ return createGoogleAuth({
2590
+ ...shared,
2591
+ clientId,
2592
+ clientSecret,
2593
+ redirectUri: `${origin}${redirectPath}`
2594
+ });
2595
+ };
2596
+ return {
2597
+ enabled: true,
2598
+ signInPath,
2599
+ secretEnabled,
2600
+ googleEnabled,
2601
+ gate: createAuthGate({
2602
+ secret,
2603
+ allowedDomains: auth.allowedDomains,
2604
+ signInPath,
2605
+ publicPaths: [...options.publicPaths ?? ["/api/proxy"]]
2606
+ }),
2607
+ emailSignIn: (request) => emailSignIn?.(request) ?? Promise.resolve(notConfigured()),
2608
+ secretSignIn: (request) => secretSignIn?.(request) ?? Promise.resolve(notConfigured()),
2609
+ google: {
2610
+ start: (request) => googleFor(request)?.start(request) ?? notConfigured(),
2611
+ callback: (request) => googleFor(request)?.callback(request) ?? Promise.resolve(notConfigured())
2612
+ },
2613
+ signOut: createSignOut({ secureCookies: secure, redirectTo: signInPath })
2614
+ };
2615
+ }
2616
+
2531
2617
  // src/core/proxy.ts
2532
2618
  var DEFAULT_RATE_LIMIT_PER_MINUTE2 = 60;
2533
2619
  var ProxyTargetError = class extends Error {
@@ -3004,6 +3090,7 @@ exports.createGoogleAuth = createGoogleAuth;
3004
3090
  exports.createMarkdownRoute = createMarkdownRoute;
3005
3091
  exports.createSecretSignIn = createSecretSignIn;
3006
3092
  exports.createSignOut = createSignOut;
3093
+ exports.createSiteAuth = createSiteAuth;
3007
3094
  exports.createTryItProxy = createTryItProxy;
3008
3095
  exports.createTryItProxyRoute = createTryItProxyRoute;
3009
3096
  exports.defineDocsConfig = defineDocsConfig;