specra 0.1.13 → 0.2.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.
Files changed (276) hide show
  1. package/LICENSE.MD +25 -4
  2. package/README.md +67 -58
  3. package/config/specra.config.schema.json +16 -0
  4. package/config/svelte-config.js +63 -0
  5. package/dist/api-parser.types.d.ts +59 -0
  6. package/dist/api-parser.types.js +5 -0
  7. package/dist/api.types.d.ts +137 -0
  8. package/dist/api.types.js +5 -0
  9. package/dist/category.d.ts +21 -0
  10. package/dist/category.js +48 -0
  11. package/dist/components/ConfigProvider.svelte +13 -0
  12. package/dist/components/ConfigProvider.svelte.d.ts +31 -0
  13. package/dist/components/docs/Accordion.svelte +18 -0
  14. package/dist/components/docs/Accordion.svelte.d.ts +10 -0
  15. package/dist/components/docs/AccordionItem.svelte +41 -0
  16. package/dist/components/docs/AccordionItem.svelte.d.ts +10 -0
  17. package/dist/components/docs/Badge.svelte +28 -0
  18. package/dist/components/docs/Badge.svelte.d.ts +9 -0
  19. package/dist/components/docs/Breadcrumb.svelte +80 -0
  20. package/dist/components/docs/Breadcrumb.svelte.d.ts +8 -0
  21. package/dist/components/docs/Callout.svelte +96 -0
  22. package/dist/components/docs/Callout.svelte.d.ts +10 -0
  23. package/dist/components/docs/Card.svelte +63 -0
  24. package/dist/components/docs/Card.svelte.d.ts +12 -0
  25. package/dist/components/docs/CardGrid.svelte +24 -0
  26. package/dist/components/docs/CardGrid.svelte.d.ts +8 -0
  27. package/dist/components/docs/CategoryIndex.svelte +110 -0
  28. package/dist/components/docs/CategoryIndex.svelte.d.ts +29 -0
  29. package/dist/components/docs/CodeBlock.svelte +172 -0
  30. package/dist/components/docs/CodeBlock.svelte.d.ts +8 -0
  31. package/dist/components/docs/Column.svelte +25 -0
  32. package/dist/components/docs/Column.svelte.d.ts +8 -0
  33. package/dist/components/docs/Columns.svelte +38 -0
  34. package/dist/components/docs/Columns.svelte.d.ts +13 -0
  35. package/dist/components/docs/DevModeBadge.svelte +15 -0
  36. package/dist/components/docs/DevModeBadge.svelte.d.ts +18 -0
  37. package/dist/components/docs/DocBadge.svelte +28 -0
  38. package/dist/components/docs/DocBadge.svelte.d.ts +9 -0
  39. package/dist/components/docs/DocLayout.svelte +107 -0
  40. package/dist/components/docs/DocLayout.svelte.d.ts +32 -0
  41. package/dist/components/docs/DocLoading.svelte +53 -0
  42. package/dist/components/docs/DocLoading.svelte.d.ts +18 -0
  43. package/dist/components/docs/DocMetadata.svelte +106 -0
  44. package/dist/components/docs/DocMetadata.svelte.d.ts +18 -0
  45. package/dist/components/docs/DocNavigation.svelte +56 -0
  46. package/dist/components/docs/DocNavigation.svelte.d.ts +12 -0
  47. package/dist/components/docs/DocTags.svelte +22 -0
  48. package/dist/components/docs/DocTags.svelte.d.ts +6 -0
  49. package/dist/components/docs/DraftBadge.svelte +10 -0
  50. package/dist/components/docs/DraftBadge.svelte.d.ts +18 -0
  51. package/dist/components/docs/Footer.svelte +72 -0
  52. package/dist/components/docs/Footer.svelte.d.ts +7 -0
  53. package/dist/components/docs/Frame.svelte +27 -0
  54. package/dist/components/docs/Frame.svelte.d.ts +9 -0
  55. package/dist/components/docs/Header.svelte +123 -0
  56. package/dist/components/docs/Header.svelte.d.ts +9 -0
  57. package/dist/components/docs/HeaderWithMenu.svelte +34 -0
  58. package/dist/components/docs/HeaderWithMenu.svelte.d.ts +17 -0
  59. package/dist/components/docs/HotReloadIndicator.svelte +44 -0
  60. package/dist/components/docs/HotReloadIndicator.svelte.d.ts +3 -0
  61. package/dist/components/docs/Icon.svelte +103 -0
  62. package/dist/components/docs/Icon.svelte.d.ts +11 -0
  63. package/dist/components/docs/Image.svelte +88 -0
  64. package/dist/components/docs/Image.svelte.d.ts +11 -0
  65. package/dist/components/docs/ImageCard.svelte +91 -0
  66. package/dist/components/docs/ImageCard.svelte.d.ts +12 -0
  67. package/dist/components/docs/ImageCardGrid.svelte +25 -0
  68. package/dist/components/docs/ImageCardGrid.svelte.d.ts +8 -0
  69. package/dist/components/docs/LayoutProviders.svelte +57 -0
  70. package/dist/components/docs/LayoutProviders.svelte.d.ts +9 -0
  71. package/dist/components/docs/Logo.svelte +25 -0
  72. package/dist/components/docs/Logo.svelte.d.ts +11 -0
  73. package/dist/components/docs/Math.svelte +54 -0
  74. package/dist/components/docs/Math.svelte.d.ts +7 -0
  75. package/dist/components/docs/MdxContent.svelte +41 -0
  76. package/dist/components/docs/MdxHotReload.svelte +78 -0
  77. package/dist/components/docs/MdxHotReload.svelte.d.ts +9 -0
  78. package/dist/components/docs/MdxLayout.svelte +16 -0
  79. package/dist/components/docs/MdxLayout.svelte.d.ts +6 -0
  80. package/dist/components/docs/Mermaid.svelte +88 -0
  81. package/dist/components/docs/Mermaid.svelte.d.ts +7 -0
  82. package/dist/components/docs/MobileDocLayout.svelte +211 -0
  83. package/dist/components/docs/MobileDocLayout.svelte.d.ts +35 -0
  84. package/dist/components/docs/MobileSidebar.svelte +122 -0
  85. package/dist/components/docs/MobileSidebar.svelte.d.ts +31 -0
  86. package/dist/components/docs/MobileSidebarWrapper.svelte +122 -0
  87. package/dist/components/docs/MobileSidebarWrapper.svelte.d.ts +32 -0
  88. package/dist/components/docs/NotFoundContent.svelte +40 -0
  89. package/dist/components/docs/NotFoundContent.svelte.d.ts +6 -0
  90. package/dist/components/docs/SearchHighlight.svelte +116 -0
  91. package/dist/components/docs/SearchHighlight.svelte.d.ts +3 -0
  92. package/dist/components/docs/SearchModal.svelte +239 -0
  93. package/dist/components/docs/SearchModal.svelte.d.ts +9 -0
  94. package/dist/components/docs/Sidebar.svelte +69 -0
  95. package/dist/components/docs/Sidebar.svelte.d.ts +31 -0
  96. package/dist/components/docs/SidebarMenuItems.svelte +344 -0
  97. package/dist/components/docs/SidebarMenuItems.svelte.d.ts +33 -0
  98. package/dist/components/docs/SidebarSkeleton.svelte +50 -0
  99. package/dist/components/docs/SidebarSkeleton.svelte.d.ts +18 -0
  100. package/dist/components/docs/SiteBanner.svelte +92 -0
  101. package/dist/components/docs/SiteBanner.svelte.d.ts +7 -0
  102. package/dist/components/docs/Step.svelte +44 -0
  103. package/dist/components/docs/Step.svelte.d.ts +8 -0
  104. package/dist/components/docs/Steps.svelte +15 -0
  105. package/dist/components/docs/Steps.svelte.d.ts +7 -0
  106. package/dist/components/docs/Tab.svelte +40 -0
  107. package/dist/components/docs/Tab.svelte.d.ts +8 -0
  108. package/dist/components/docs/TabGroups.svelte +183 -0
  109. package/dist/components/docs/TabGroups.svelte.d.ts +25 -0
  110. package/dist/components/docs/TableOfContents.svelte +100 -0
  111. package/dist/components/docs/TableOfContents.svelte.d.ts +9 -0
  112. package/dist/components/docs/Tabs.svelte +69 -0
  113. package/dist/components/docs/Tabs.svelte.d.ts +8 -0
  114. package/dist/components/docs/ThemeToggle.svelte +16 -0
  115. package/dist/components/docs/ThemeToggle.svelte.d.ts +18 -0
  116. package/dist/components/docs/Tooltip.svelte +44 -0
  117. package/dist/components/docs/Tooltip.svelte.d.ts +10 -0
  118. package/dist/components/docs/VersionSwitcher.svelte +95 -0
  119. package/dist/components/docs/VersionSwitcher.svelte.d.ts +7 -0
  120. package/dist/components/docs/Video.svelte +84 -0
  121. package/dist/components/docs/Video.svelte.d.ts +12 -0
  122. package/dist/components/docs/api/ApiEndpoint.svelte +61 -0
  123. package/dist/components/docs/api/ApiEndpoint.svelte.d.ts +11 -0
  124. package/dist/components/docs/api/ApiParams.svelte +80 -0
  125. package/dist/components/docs/api/ApiParams.svelte.d.ts +14 -0
  126. package/dist/components/docs/api/ApiPlayground.svelte +259 -0
  127. package/dist/components/docs/api/ApiPlayground.svelte.d.ts +16 -0
  128. package/dist/components/docs/api/ApiReference.svelte +278 -0
  129. package/dist/components/docs/api/ApiReference.svelte.d.ts +23 -0
  130. package/dist/components/docs/api/ApiResponse.svelte +66 -0
  131. package/dist/components/docs/api/ApiResponse.svelte.d.ts +9 -0
  132. package/dist/components/docs/api/index.d.ts +5 -0
  133. package/dist/components/docs/api/index.js +5 -0
  134. package/dist/components/docs/componentTextProps.d.ts +3 -0
  135. package/dist/components/docs/componentTextProps.js +61 -0
  136. package/dist/components/docs/index.d.ts +54 -0
  137. package/dist/components/docs/index.js +56 -0
  138. package/dist/components/global/VersionNotFound.svelte +48 -0
  139. package/dist/components/global/VersionNotFound.svelte.d.ts +7 -0
  140. package/dist/components/global/index.d.ts +1 -0
  141. package/dist/components/global/index.js +1 -0
  142. package/dist/components/index.d.ts +6 -822
  143. package/dist/components/index.js +11 -3854
  144. package/dist/components/ui/Badge.svelte +48 -0
  145. package/dist/components/ui/Badge.svelte.d.ts +15 -0
  146. package/dist/components/ui/Button.svelte +58 -0
  147. package/dist/components/ui/Button.svelte.d.ts +17 -0
  148. package/dist/components/ui/Dialog.svelte +16 -0
  149. package/dist/components/ui/Dialog.svelte.d.ts +9 -0
  150. package/dist/components/ui/DialogClose.svelte +16 -0
  151. package/dist/components/ui/DialogClose.svelte.d.ts +9 -0
  152. package/dist/components/ui/DialogContent.svelte +43 -0
  153. package/dist/components/ui/DialogContent.svelte.d.ts +10 -0
  154. package/dist/components/ui/DialogDescription.svelte +21 -0
  155. package/dist/components/ui/DialogDescription.svelte.d.ts +9 -0
  156. package/dist/components/ui/DialogFooter.svelte +20 -0
  157. package/dist/components/ui/DialogFooter.svelte.d.ts +9 -0
  158. package/dist/components/ui/DialogHeader.svelte +20 -0
  159. package/dist/components/ui/DialogHeader.svelte.d.ts +9 -0
  160. package/dist/components/ui/DialogTitle.svelte +21 -0
  161. package/dist/components/ui/DialogTitle.svelte.d.ts +9 -0
  162. package/dist/components/ui/Input.svelte +23 -0
  163. package/dist/components/ui/Input.svelte.d.ts +8 -0
  164. package/dist/components/ui/Textarea.svelte +19 -0
  165. package/dist/components/ui/Textarea.svelte.d.ts +7 -0
  166. package/dist/components/ui/index.d.ts +11 -0
  167. package/dist/components/ui/index.js +11 -0
  168. package/dist/config.d.ts +8 -0
  169. package/dist/config.js +9 -0
  170. package/dist/config.schema.json +471 -0
  171. package/dist/config.server.d.ts +46 -0
  172. package/dist/config.server.js +149 -0
  173. package/dist/{mdx-ColN3Cyg.d.mts → config.types.d.ts} +22 -75
  174. package/dist/config.types.js +39 -0
  175. package/dist/dev-utils.d.ts +29 -0
  176. package/dist/dev-utils.js +63 -0
  177. package/dist/index.d.ts +19 -4
  178. package/dist/index.js +25 -4861
  179. package/dist/mdx-cache.d.ts +41 -0
  180. package/dist/mdx-cache.js +160 -0
  181. package/dist/mdx-components.js +50 -1931
  182. package/dist/mdx-security.d.ts +76 -0
  183. package/dist/mdx-security.js +217 -0
  184. package/dist/mdx.d.ts +73 -0
  185. package/dist/mdx.js +1099 -0
  186. package/dist/middleware/index.d.ts +1 -0
  187. package/dist/middleware/index.js +2 -0
  188. package/dist/middleware/security.d.ts +22 -47
  189. package/dist/middleware/security.js +111 -137
  190. package/dist/parsers/base-parser.d.ts +14 -0
  191. package/dist/parsers/base-parser.js +1 -0
  192. package/dist/parsers/index.d.ts +16 -0
  193. package/dist/parsers/index.js +51 -0
  194. package/dist/parsers/openapi-parser.d.ts +18 -0
  195. package/dist/parsers/openapi-parser.js +209 -0
  196. package/dist/parsers/postman-parser.d.ts +20 -0
  197. package/dist/parsers/postman-parser.js +260 -0
  198. package/dist/parsers/specra-parser.d.ts +10 -0
  199. package/dist/parsers/specra-parser.js +18 -0
  200. package/dist/redirects.d.ts +12 -0
  201. package/dist/redirects.js +30 -0
  202. package/dist/remark-code-meta.d.ts +6 -0
  203. package/dist/remark-code-meta.js +21 -0
  204. package/dist/sidebar-utils.d.ts +59 -0
  205. package/dist/sidebar-utils.js +144 -0
  206. package/dist/stores/config.d.ts +20 -0
  207. package/dist/stores/config.js +45 -0
  208. package/dist/stores/index.d.ts +4 -0
  209. package/dist/stores/index.js +4 -0
  210. package/dist/stores/sidebar.d.ts +7 -0
  211. package/dist/stores/sidebar.js +12 -0
  212. package/dist/stores/tabs.d.ts +6 -0
  213. package/dist/stores/tabs.js +41 -0
  214. package/dist/stores/theme.d.ts +7 -0
  215. package/dist/stores/theme.js +75 -0
  216. package/dist/{styles.css → styles/globals.css} +136 -6
  217. package/dist/toc.d.ts +9 -0
  218. package/dist/toc.js +15 -0
  219. package/dist/utils.d.ts +13 -0
  220. package/dist/utils.js +30 -0
  221. package/package.json +47 -90
  222. package/dist/app/api/mdx-watch/route.d.mts +0 -10
  223. package/dist/app/api/mdx-watch/route.d.ts +0 -10
  224. package/dist/app/api/mdx-watch/route.js +0 -118
  225. package/dist/app/api/mdx-watch/route.js.map +0 -1
  226. package/dist/app/api/mdx-watch/route.mjs +0 -91
  227. package/dist/app/api/mdx-watch/route.mjs.map +0 -1
  228. package/dist/chunk-6S3EJVEO.mjs +0 -259
  229. package/dist/chunk-6S3EJVEO.mjs.map +0 -1
  230. package/dist/chunk-BE7EROIW.mjs +0 -212
  231. package/dist/chunk-BE7EROIW.mjs.map +0 -1
  232. package/dist/chunk-CWHRZHZO.mjs +0 -168
  233. package/dist/chunk-CWHRZHZO.mjs.map +0 -1
  234. package/dist/chunk-D5VDVYFY.mjs +0 -1325
  235. package/dist/chunk-D5VDVYFY.mjs.map +0 -1
  236. package/dist/chunk-WMCO2UX5.mjs +0 -585
  237. package/dist/chunk-WMCO2UX5.mjs.map +0 -1
  238. package/dist/chunk-XEMGCPZZ.mjs +0 -475
  239. package/dist/chunk-XEMGCPZZ.mjs.map +0 -1
  240. package/dist/components/index.d.mts +0 -822
  241. package/dist/components/index.js.map +0 -1
  242. package/dist/components/index.mjs +0 -3741
  243. package/dist/components/index.mjs.map +0 -1
  244. package/dist/index.d.mts +0 -4
  245. package/dist/index.js.map +0 -1
  246. package/dist/index.mjs +0 -1897
  247. package/dist/index.mjs.map +0 -1
  248. package/dist/layouts/index.d.mts +0 -34
  249. package/dist/layouts/index.d.ts +0 -34
  250. package/dist/layouts/index.js +0 -453
  251. package/dist/layouts/index.js.map +0 -1
  252. package/dist/layouts/index.mjs +0 -173
  253. package/dist/layouts/index.mjs.map +0 -1
  254. package/dist/lib/index.d.mts +0 -583
  255. package/dist/lib/index.d.ts +0 -583
  256. package/dist/lib/index.js +0 -1595
  257. package/dist/lib/index.js.map +0 -1
  258. package/dist/lib/index.mjs +0 -111
  259. package/dist/lib/index.mjs.map +0 -1
  260. package/dist/mdx-ColN3Cyg.d.ts +0 -352
  261. package/dist/mdx-components.d.mts +0 -86
  262. package/dist/mdx-components.d.ts +0 -86
  263. package/dist/mdx-components.js.map +0 -1
  264. package/dist/mdx-components.mjs +0 -206
  265. package/dist/mdx-components.mjs.map +0 -1
  266. package/dist/middleware/security.d.mts +0 -82
  267. package/dist/middleware/security.js.map +0 -1
  268. package/dist/middleware/security.mjs +0 -84
  269. package/dist/middleware/security.mjs.map +0 -1
  270. package/dist/styles.css.map +0 -1
  271. package/dist/styles.d.mts +0 -2
  272. package/dist/styles.d.ts +0 -2
  273. package/dist/styles.js +0 -2
  274. package/dist/styles.js.map +0 -1
  275. package/dist/styles.mjs +0 -1
  276. package/dist/styles.mjs.map +0 -1
@@ -0,0 +1 @@
1
+ export * from './security.js';
@@ -0,0 +1,2 @@
1
+ // Security Middleware
2
+ export * from './security.js';
@@ -1,82 +1,57 @@
1
- import { NextResponse, NextRequest } from 'next/server';
2
-
3
1
  /**
4
- * Security Middleware for Next.js
2
+ * Security Middleware for SvelteKit
5
3
  *
6
4
  * Implements:
7
5
  * - Content Security Policy (CSP)
8
6
  * - Additional security headers
9
7
  * - Path traversal protection
8
+ *
9
+ * Usage in hooks.server.ts:
10
+ * ```typescript
11
+ * import { sequence } from '@sveltejs/kit/hooks'
12
+ * import { createSecurityHandle } from 'specra/middleware/security'
13
+ *
14
+ * export const handle = sequence(
15
+ * createSecurityHandle(),
16
+ * // ... other handles
17
+ * )
18
+ * ```
10
19
  */
11
-
20
+ import type { Handle } from '@sveltejs/kit';
12
21
  /**
13
22
  * Security headers configuration
14
23
  */
15
- declare const SECURITY_HEADERS: {
16
- "X-Frame-Options": string;
17
- "X-Content-Type-Options": string;
18
- "X-XSS-Protection": string;
19
- "Referrer-Policy": string;
20
- "Permissions-Policy": string;
21
- };
24
+ export declare const SECURITY_HEADERS: Record<string, string>;
22
25
  /**
23
- * Apply security headers to response
26
+ * Apply security headers to a Response
24
27
  */
25
- declare function applySecurityHeaders(response: NextResponse, options?: {
28
+ export declare function applySecurityHeaders(response: Response, options?: {
26
29
  customCSP?: string;
27
30
  production?: boolean;
28
- }): NextResponse;
31
+ }): Response;
29
32
  /**
30
33
  * Validate request path for security issues
31
34
  */
32
- declare function validateRequestPath(pathname: string): {
35
+ export declare function validateRequestPath(pathname: string): {
33
36
  valid: boolean;
34
37
  reason?: string;
35
38
  };
36
39
  /**
37
- * Security proxy function (Next.js 16+)
38
- * Add this to your Next.js proxy.ts file
40
+ * Create a SvelteKit handle for security middleware
39
41
  */
40
- declare function createSecurityProxy(options?: {
42
+ export declare function createSecurityHandle(options?: {
41
43
  customCSP?: string;
42
44
  production?: boolean;
43
45
  strictPathValidation?: boolean;
44
- }): (request: NextRequest) => NextResponse;
45
- /**
46
- * @deprecated Use createSecurityProxy instead. Middleware is renamed to Proxy in Next.js 16+
47
- */
48
- declare const createSecurityMiddleware: typeof createSecurityProxy;
49
- /**
50
- * Example proxy configuration for your project
51
- *
52
- * Create this file: proxy.ts (at root of your Next.js app)
53
- *
54
- * ```typescript
55
- * import { createSecurityProxy } from 'specra/middleware/security'
56
- *
57
- * export const proxy = createSecurityProxy({
58
- * production: process.env.NODE_ENV === 'production',
59
- * strictPathValidation: true,
60
- * })
61
- *
62
- * export const config = {
63
- * matcher: [
64
- * // Match all paths except static files
65
- * '/((?!_next/static|_next/image|favicon.ico).*)',
66
- * ],
67
- * }
68
- * ```
69
- */
46
+ }): Handle;
70
47
  /**
71
48
  * Validate subdomain/organization isolation
72
49
  * Use this if you're building a multi-tenant system
73
50
  */
74
- declare function validateSubdomainIsolation(request: NextRequest, options: {
51
+ export declare function validateSubdomainIsolation(hostname: string, pathname: string, options: {
75
52
  allowedSubdomains?: string[];
76
53
  currentOrg?: string;
77
54
  }): {
78
55
  valid: boolean;
79
56
  reason?: string;
80
57
  };
81
-
82
- export { SECURITY_HEADERS, applySecurityHeaders, createSecurityMiddleware, createSecurityProxy, validateRequestPath, validateSubdomainIsolation };
@@ -1,144 +1,118 @@
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 });
1
+ /**
2
+ * Security Middleware for SvelteKit
3
+ *
4
+ * Implements:
5
+ * - Content Security Policy (CSP)
6
+ * - Additional security headers
7
+ * - Path traversal protection
8
+ *
9
+ * Usage in hooks.server.ts:
10
+ * ```typescript
11
+ * import { sequence } from '@sveltejs/kit/hooks'
12
+ * import { createSecurityHandle } from 'specra/middleware/security'
13
+ *
14
+ * export const handle = sequence(
15
+ * createSecurityHandle(),
16
+ * // ... other handles
17
+ * )
18
+ * ```
19
+ */
20
+ import { generateCSPHeader } from '../mdx-security.js';
21
+ /**
22
+ * Security headers configuration
23
+ */
24
+ export const SECURITY_HEADERS = {
25
+ // Prevent clickjacking
26
+ 'X-Frame-Options': 'SAMEORIGIN',
27
+ // Prevent MIME type sniffing
28
+ 'X-Content-Type-Options': 'nosniff',
29
+ // Enable XSS protection (legacy browsers)
30
+ 'X-XSS-Protection': '1; mode=block',
31
+ // Control referrer information
32
+ 'Referrer-Policy': 'strict-origin-when-cross-origin',
33
+ // Permissions Policy (formerly Feature Policy)
34
+ 'Permissions-Policy': 'camera=(), microphone=(), geolocation=()',
9
35
  };
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/middleware/security.ts
21
- var security_exports = {};
22
- __export(security_exports, {
23
- SECURITY_HEADERS: () => SECURITY_HEADERS,
24
- applySecurityHeaders: () => applySecurityHeaders,
25
- createSecurityMiddleware: () => createSecurityMiddleware,
26
- createSecurityProxy: () => createSecurityProxy,
27
- validateRequestPath: () => validateRequestPath,
28
- validateSubdomainIsolation: () => validateSubdomainIsolation
29
- });
30
- module.exports = __toCommonJS(security_exports);
31
- var import_server = require("next/server");
32
-
33
- // src/lib/mdx-security.ts
34
- var CSP_DIRECTIVES = {
35
- "default-src": ["'self'"],
36
- "script-src": [
37
- "'self'",
38
- "'unsafe-inline'",
39
- // Required for Next.js
40
- "'unsafe-eval'"
41
- // Required for dev mode - remove in production
42
- ],
43
- "style-src": ["'self'", "'unsafe-inline'"],
44
- // Required for styled-components/emotion
45
- "img-src": ["'self'", "data:", "https:"],
46
- "font-src": ["'self'", "data:"],
47
- "connect-src": ["'self'"],
48
- "frame-src": ["'self'"],
49
- "object-src": ["'none'"],
50
- "base-uri": ["'self'"],
51
- "form-action": ["'self'"],
52
- "frame-ancestors": ["'self'"],
53
- "upgrade-insecure-requests": []
54
- };
55
- function generateCSPHeader(customDirectives, production = true) {
56
- const directives = { ...CSP_DIRECTIVES, ...customDirectives };
57
- if (production && directives["script-src"]) {
58
- directives["script-src"] = directives["script-src"].filter(
59
- (src) => src !== "'unsafe-eval'"
60
- );
61
- }
62
- return Object.entries(directives).map(([key, values]) => `${key} ${values.join(" ")}`).join("; ");
36
+ /**
37
+ * Apply security headers to a Response
38
+ */
39
+ export function applySecurityHeaders(response, options) {
40
+ const { customCSP, production = true } = options || {};
41
+ // Apply standard security headers
42
+ for (const [key, value] of Object.entries(SECURITY_HEADERS)) {
43
+ response.headers.set(key, value);
44
+ }
45
+ // Apply CSP
46
+ const csp = customCSP || generateCSPHeader(undefined, production);
47
+ response.headers.set('Content-Security-Policy', csp);
48
+ return response;
63
49
  }
64
-
65
- // src/middleware/security.ts
66
- var SECURITY_HEADERS = {
67
- // Prevent clickjacking
68
- "X-Frame-Options": "SAMEORIGIN",
69
- // Prevent MIME type sniffing
70
- "X-Content-Type-Options": "nosniff",
71
- // Enable XSS protection (legacy browsers)
72
- "X-XSS-Protection": "1; mode=block",
73
- // Control referrer information
74
- "Referrer-Policy": "strict-origin-when-cross-origin",
75
- // Permissions Policy (formerly Feature Policy)
76
- "Permissions-Policy": "camera=(), microphone=(), geolocation=()"
77
- };
78
- function applySecurityHeaders(response, options) {
79
- const { customCSP, production = process.env.NODE_ENV === "production" } = options || {};
80
- Object.entries(SECURITY_HEADERS).forEach(([key, value]) => {
81
- response.headers.set(key, value);
82
- });
83
- const csp = customCSP || generateCSPHeader(void 0, production);
84
- response.headers.set("Content-Security-Policy", csp);
85
- return response;
50
+ /**
51
+ * Validate request path for security issues
52
+ */
53
+ export function validateRequestPath(pathname) {
54
+ // Decode the pathname to catch encoded attacks
55
+ const decoded = decodeURIComponent(pathname);
56
+ // Check for path traversal
57
+ if (decoded.includes('../') || decoded.includes('..\\')) {
58
+ return { valid: false, reason: 'Path traversal detected' };
59
+ }
60
+ // Check for encoded path traversal
61
+ if (decoded.includes('%2e%2e') ||
62
+ decoded.includes('%252e%252e') ||
63
+ pathname.includes('%2e%2e') ||
64
+ pathname.includes('%252e%252e')) {
65
+ return { valid: false, reason: 'Encoded path traversal detected' };
66
+ }
67
+ // Check for null bytes
68
+ if (decoded.includes('\0') || pathname.includes('%00')) {
69
+ return { valid: false, reason: 'Null byte injection detected' };
70
+ }
71
+ return { valid: true };
86
72
  }
87
- function validateRequestPath(pathname) {
88
- const decoded = decodeURIComponent(pathname);
89
- if (decoded.includes("../") || decoded.includes("..\\")) {
90
- return { valid: false, reason: "Path traversal detected" };
91
- }
92
- if (decoded.includes("%2e%2e") || decoded.includes("%252e%252e") || pathname.includes("%2e%2e") || pathname.includes("%252e%252e")) {
93
- return { valid: false, reason: "Encoded path traversal detected" };
94
- }
95
- if (decoded.includes("\0") || pathname.includes("%00")) {
96
- return { valid: false, reason: "Null byte injection detected" };
97
- }
98
- return { valid: true };
73
+ /**
74
+ * Create a SvelteKit handle for security middleware
75
+ */
76
+ export function createSecurityHandle(options) {
77
+ return async ({ event, resolve }) => {
78
+ const { strictPathValidation = true } = options || {};
79
+ // Validate request path
80
+ if (strictPathValidation) {
81
+ const pathValidation = validateRequestPath(event.url.pathname);
82
+ if (!pathValidation.valid) {
83
+ const ip = event.request.headers.get('x-forwarded-for') ||
84
+ event.request.headers.get('x-real-ip') ||
85
+ 'unknown';
86
+ console.warn(`[Security] Blocked request: ${pathValidation.reason}`, {
87
+ path: event.url.pathname,
88
+ ip,
89
+ });
90
+ return new Response('Bad Request', { status: 400 });
91
+ }
92
+ }
93
+ // Continue with the request and apply security headers
94
+ const response = await resolve(event);
95
+ return applySecurityHeaders(response, options);
96
+ };
99
97
  }
100
- function createSecurityProxy(options) {
101
- return function securityProxy(request) {
102
- const { strictPathValidation = true } = options || {};
103
- if (strictPathValidation) {
104
- const pathValidation = validateRequestPath(request.nextUrl.pathname);
105
- if (!pathValidation.valid) {
106
- const ip = request.headers.get("x-forwarded-for") || request.headers.get("x-real-ip") || "unknown";
107
- console.warn(`[Security] Blocked request: ${pathValidation.reason}`, {
108
- path: request.nextUrl.pathname,
109
- ip
110
- });
111
- return new import_server.NextResponse("Bad Request", { status: 400 });
112
- }
98
+ /**
99
+ * Validate subdomain/organization isolation
100
+ * Use this if you're building a multi-tenant system
101
+ */
102
+ export function validateSubdomainIsolation(hostname, pathname, options) {
103
+ const { allowedSubdomains, currentOrg } = options;
104
+ const subdomain = hostname.split('.')[0];
105
+ // If allowlist is provided, validate against it
106
+ if (allowedSubdomains && !allowedSubdomains.includes(subdomain)) {
107
+ return { valid: false, reason: 'Subdomain not in allowlist' };
113
108
  }
114
- const response = import_server.NextResponse.next();
115
- return applySecurityHeaders(response, options);
116
- };
117
- }
118
- var createSecurityMiddleware = createSecurityProxy;
119
- function validateSubdomainIsolation(request, options) {
120
- const { allowedSubdomains, currentOrg } = options;
121
- const hostname = request.headers.get("host") || "";
122
- const subdomain = hostname.split(".")[0];
123
- if (allowedSubdomains && !allowedSubdomains.includes(subdomain)) {
124
- return { valid: false, reason: "Subdomain not in allowlist" };
125
- }
126
- const pathMatch = request.nextUrl.pathname.match(/\/(static|assets|_.*?)\/([^/]+)/);
127
- if (pathMatch && currentOrg) {
128
- const pathOrg = pathMatch[2];
129
- if (pathOrg !== currentOrg) {
130
- return { valid: false, reason: "Cross-organization access detected" };
109
+ // Check for subdomain mismatch in paths
110
+ const pathMatch = pathname.match(/\/(static|assets|_.*?)\/([^/]+)/);
111
+ if (pathMatch && currentOrg) {
112
+ const pathOrg = pathMatch[2];
113
+ if (pathOrg !== currentOrg) {
114
+ return { valid: false, reason: 'Cross-organization access detected' };
115
+ }
131
116
  }
132
- }
133
- return { valid: true };
117
+ return { valid: true };
134
118
  }
135
- // Annotate the CommonJS export names for ESM import in node:
136
- 0 && (module.exports = {
137
- SECURITY_HEADERS,
138
- applySecurityHeaders,
139
- createSecurityMiddleware,
140
- createSecurityProxy,
141
- validateRequestPath,
142
- validateSubdomainIsolation
143
- });
144
- //# sourceMappingURL=security.js.map
@@ -0,0 +1,14 @@
1
+ import type { SpecraApiSpec } from "../api-parser.types";
2
+ /**
3
+ * Base interface for all API spec parsers
4
+ */
5
+ export interface ApiSpecParser {
6
+ /**
7
+ * Parse the input spec and convert to Specra format
8
+ */
9
+ parse(input: any): SpecraApiSpec;
10
+ /**
11
+ * Validate if the input is in the expected format
12
+ */
13
+ validate(input: any): boolean;
14
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,16 @@
1
+ import type { SpecraApiSpec } from "../api-parser.types";
2
+ import type { ApiSpecParser } from "./base-parser";
3
+ import { SpecraParser } from "./specra-parser";
4
+ import { OpenApiParser } from "./openapi-parser";
5
+ import { PostmanParser } from "./postman-parser";
6
+ export type ParserType = "auto" | "specra" | "openapi" | "postman";
7
+ /**
8
+ * Auto-detect the parser type based on the input structure
9
+ */
10
+ export declare function detectParserType(input: any): ParserType;
11
+ /**
12
+ * Parse an API spec using the specified or auto-detected parser
13
+ */
14
+ export declare function parseApiSpec(input: any, parserType?: ParserType): SpecraApiSpec;
15
+ export { SpecraParser, OpenApiParser, PostmanParser };
16
+ export type { ApiSpecParser };
@@ -0,0 +1,51 @@
1
+ import { SpecraParser } from "./specra-parser";
2
+ import { OpenApiParser } from "./openapi-parser";
3
+ import { PostmanParser } from "./postman-parser";
4
+ /**
5
+ * Registry of all available parsers
6
+ */
7
+ const parsers = new Map([
8
+ ["specra", new SpecraParser()],
9
+ ["openapi", new OpenApiParser()],
10
+ ["postman", new PostmanParser()],
11
+ ]);
12
+ /**
13
+ * Auto-detect the parser type based on the input structure
14
+ */
15
+ export function detectParserType(input) {
16
+ if (!input || typeof input !== "object") {
17
+ throw new Error("Invalid API spec: input must be an object");
18
+ }
19
+ // Check for Postman Collection
20
+ if (input.info?.schema?.includes("v2")) {
21
+ return "postman";
22
+ }
23
+ // Check for OpenAPI/Swagger
24
+ if (input.openapi || input.swagger) {
25
+ return "openapi";
26
+ }
27
+ // Check for Specra format
28
+ if (input.endpoints && Array.isArray(input.endpoints)) {
29
+ return "specra";
30
+ }
31
+ throw new Error("Unable to auto-detect API spec format. Supported formats: Specra, OpenAPI 3.x, Postman Collection v2.x");
32
+ }
33
+ /**
34
+ * Parse an API spec using the specified or auto-detected parser
35
+ */
36
+ export function parseApiSpec(input, parserType = "auto") {
37
+ // Auto-detect if needed
38
+ const actualType = parserType === "auto" ? detectParserType(input) : parserType;
39
+ // Get the parser
40
+ const parser = parsers.get(actualType);
41
+ if (!parser) {
42
+ throw new Error(`Unknown parser type: ${actualType}`);
43
+ }
44
+ // Validate and parse
45
+ if (!parser.validate(input)) {
46
+ throw new Error(`Input does not match ${actualType} format`);
47
+ }
48
+ return parser.parse(input);
49
+ }
50
+ // Export parsers for direct use
51
+ export { SpecraParser, OpenApiParser, PostmanParser };
@@ -0,0 +1,18 @@
1
+ import type { SpecraApiSpec } from "../api-parser.types";
2
+ import type { ApiSpecParser } from "./base-parser";
3
+ /**
4
+ * Parser for OpenAPI 3.0/3.1 specifications
5
+ */
6
+ export declare class OpenApiParser implements ApiSpecParser {
7
+ validate(input: any): boolean;
8
+ parse(input: any): SpecraApiSpec;
9
+ private extractBaseUrl;
10
+ private extractAuth;
11
+ private parseOperation;
12
+ private convertPathParams;
13
+ private parseParameters;
14
+ private parseRequestBody;
15
+ private parseResponses;
16
+ private generateExample;
17
+ private resolveRef;
18
+ }