zudoku 0.0.0-zabced09d → 0.0.0-zc17c4c22

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 (128) hide show
  1. package/dist/config/validators/InputNavigationSchema.d.ts +56 -56
  2. package/dist/config/validators/ProtectedRoutesSchema.d.ts +1 -1
  3. package/dist/config/validators/validate.d.ts +1 -1
  4. package/dist/flat-config.d.ts +24 -24
  5. package/dist/lib/components/Heading.d.ts +1 -1
  6. package/dist/lib/components/index.d.ts +18 -74
  7. package/dist/lib/components/index.js +19 -36
  8. package/dist/lib/components/index.js.map +1 -1
  9. package/dist/lib/hooks/index.d.ts +7 -30
  10. package/dist/lib/hooks/index.js +7 -15
  11. package/dist/lib/hooks/index.js.map +1 -1
  12. package/dist/lib/oas/graphql/circular.d.ts +1 -1
  13. package/dist/lib/oas/graphql/circular.js +18 -35
  14. package/dist/lib/oas/graphql/circular.js.map +1 -1
  15. package/dist/lib/oas/graphql/circular.test.js +33 -2
  16. package/dist/lib/oas/graphql/circular.test.js.map +1 -1
  17. package/dist/lib/oas/parser/index.js +14 -5
  18. package/dist/lib/oas/parser/index.js.map +1 -1
  19. package/dist/lib/util/flattenAllOf.d.ts +0 -2
  20. package/dist/lib/util/flattenAllOf.js +0 -46
  21. package/dist/lib/util/flattenAllOf.js.map +1 -1
  22. package/dist/lib/util/flattenAllOf.test.js +2 -1
  23. package/dist/lib/util/flattenAllOf.test.js.map +1 -1
  24. package/dist/lib/util/flattenAllOfProcessor.d.ts +2 -0
  25. package/dist/lib/util/flattenAllOfProcessor.js +48 -0
  26. package/dist/lib/util/flattenAllOfProcessor.js.map +1 -0
  27. package/dist/vite/api/SchemaManager.js +1 -1
  28. package/dist/vite/api/SchemaManager.js.map +1 -1
  29. package/dist/vite/api/SchemaManager.test.js +1 -1
  30. package/dist/vite/api/SchemaManager.test.js.map +1 -1
  31. package/lib/{ClaudeLogo-DJ9bU-sO.js → ClaudeLogo-C6q-Xn_l.js} +26 -22
  32. package/lib/{ClaudeLogo-DJ9bU-sO.js.map → ClaudeLogo-C6q-Xn_l.js.map} +1 -1
  33. package/lib/{MdxPage-stpAoBtx.js → MdxPage-B1G4W1TK.js} +8 -8
  34. package/lib/{MdxPage-stpAoBtx.js.map → MdxPage-B1G4W1TK.js.map} +1 -1
  35. package/lib/{Mermaid-Koc3z8mU.js → Mermaid-B1xNo-pf.js} +3 -2
  36. package/lib/{Mermaid-Koc3z8mU.js.map → Mermaid-B1xNo-pf.js.map} +1 -1
  37. package/lib/{OAuthErrorPage-DJ811Bn_.js → OAuthErrorPage-01Ke086W.js} +20 -18
  38. package/lib/{OAuthErrorPage-DJ811Bn_.js.map → OAuthErrorPage-01Ke086W.js.map} +1 -1
  39. package/lib/{OasProvider-CS_ASmBB.js → OasProvider-oHPiMJZg.js} +3 -3
  40. package/lib/{OasProvider-CS_ASmBB.js.map → OasProvider-oHPiMJZg.js.map} +1 -1
  41. package/lib/{OperationList-Dq_AB4W9.js → OperationList-CZ4OK8Pm.js} +948 -945
  42. package/lib/OperationList-CZ4OK8Pm.js.map +1 -0
  43. package/lib/{RouteGuard--A04ESy8.js → RouteGuard-B1lCR0C_.js} +5 -5
  44. package/lib/{RouteGuard--A04ESy8.js.map → RouteGuard-B1lCR0C_.js.map} +1 -1
  45. package/lib/{SchemaList-BJZJv1gD.js → SchemaList-DoQFkJgM.js} +7 -7
  46. package/lib/{SchemaList-BJZJv1gD.js.map → SchemaList-DoQFkJgM.js.map} +1 -1
  47. package/lib/{SchemaView-U4JMYB3N.js → SchemaView-D2k6ZJck.js} +3 -3
  48. package/lib/{SchemaView-U4JMYB3N.js.map → SchemaView-D2k6ZJck.js.map} +1 -1
  49. package/lib/{SignUp-DCBViNUi.js → SignUp-8kDBaLbO.js} +31 -26
  50. package/lib/{SignUp-DCBViNUi.js.map → SignUp-8kDBaLbO.js.map} +1 -1
  51. package/lib/{SyntaxHighlight-Dshjn3Zf.js → SyntaxHighlight-hZOFnYl0.js} +3 -3
  52. package/lib/{SyntaxHighlight-Dshjn3Zf.js.map → SyntaxHighlight-hZOFnYl0.js.map} +1 -1
  53. package/lib/{Toc-Cgz6CPiE.js → Toc-qEIii_-W.js} +2 -2
  54. package/lib/{Toc-Cgz6CPiE.js.map → Toc-qEIii_-W.js.map} +1 -1
  55. package/lib/{index-CL8eDnQW.js → Zudoku-DUsdmPME.js} +2250 -2268
  56. package/lib/Zudoku-DUsdmPME.js.map +1 -0
  57. package/lib/{ZudokuContext-BZB1TWdT.js → ZudokuContext-BBI06sOx.js} +5 -5
  58. package/lib/{ZudokuContext-BZB1TWdT.js.map → ZudokuContext-BBI06sOx.js.map} +1 -1
  59. package/lib/{circular-BmMJjG1v.js → circular-D9tSKG2c.js} +1327 -1346
  60. package/lib/{circular-BmMJjG1v.js.map → circular-D9tSKG2c.js.map} +1 -1
  61. package/lib/createServer-BprC4n85.js +13036 -0
  62. package/lib/createServer-BprC4n85.js.map +1 -0
  63. package/lib/{errors-b9I-fAOY.js → errors-7hgPDs1h.js} +3 -3
  64. package/lib/{errors-b9I-fAOY.js.map → errors-7hgPDs1h.js.map} +1 -1
  65. package/lib/{firebase-BCXX7Qv5.js → firebase-Dwn-2ju-.js} +13 -13
  66. package/lib/{firebase-BCXX7Qv5.js.map → firebase-Dwn-2ju-.js.map} +1 -1
  67. package/lib/{hook-BGlHBdET.js → hook-ZEd1Es7D.js} +2 -2
  68. package/lib/{hook-BGlHBdET.js.map → hook-ZEd1Es7D.js.map} +1 -1
  69. package/lib/{index-O9RHI87z.js → index-CyIW9rHv.js} +463 -461
  70. package/lib/{index-O9RHI87z.js.map → index-CyIW9rHv.js.map} +1 -1
  71. package/lib/index-DAWHN3cH.js +86 -0
  72. package/lib/index-DAWHN3cH.js.map +1 -0
  73. package/lib/{index-UOLtazB8.js → index-Dxdhrp-I.js} +2 -2
  74. package/lib/{index-UOLtazB8.js.map → index-Dxdhrp-I.js.map} +1 -1
  75. package/lib/{index.esm-B_0dvNjB.js → index.esm-Ca5zvoff.js} +20 -20
  76. package/lib/{index.esm-B_0dvNjB.js.map → index.esm-Ca5zvoff.js.map} +1 -1
  77. package/lib/{index.esm-C5CBsVzN.js → index.esm-DG4KaDKR.js} +2 -2
  78. package/lib/index.esm-DG4KaDKR.js.map +1 -0
  79. package/lib/{invariant-BJAl77rw.js → invariant-B_t_F2s_.js} +3 -3
  80. package/lib/{invariant-BJAl77rw.js.map → invariant-B_t_F2s_.js.map} +1 -1
  81. package/lib/ui/SyntaxHighlight.js +3 -3
  82. package/lib/useExposedProps-CzTDfXfq.js +30 -0
  83. package/lib/useExposedProps-CzTDfXfq.js.map +1 -0
  84. package/lib/zudoku.__internal.js +1492 -1030
  85. package/lib/zudoku.__internal.js.map +1 -1
  86. package/lib/zudoku.auth-auth0.js +1 -1
  87. package/lib/zudoku.auth-azureb2c.js +4 -4
  88. package/lib/zudoku.auth-clerk.js +2 -2
  89. package/lib/zudoku.auth-firebase.js +5 -5
  90. package/lib/zudoku.auth-openid.js +5 -5
  91. package/lib/zudoku.auth-supabase.js +4 -4
  92. package/lib/zudoku.components.js +31 -29
  93. package/lib/zudoku.components.js.map +1 -1
  94. package/lib/zudoku.hooks.js +24 -11
  95. package/lib/zudoku.hooks.js.map +1 -1
  96. package/lib/zudoku.mermaid.js +4 -3
  97. package/lib/zudoku.mermaid.js.map +1 -1
  98. package/lib/zudoku.plugin-api-catalog.js +36 -32
  99. package/lib/zudoku.plugin-api-catalog.js.map +1 -1
  100. package/lib/zudoku.plugin-api-keys.js +131 -130
  101. package/lib/zudoku.plugin-api-keys.js.map +1 -1
  102. package/lib/zudoku.plugin-custom-pages.js +1 -1
  103. package/lib/zudoku.plugin-markdown.js +1 -1
  104. package/lib/zudoku.plugin-openapi.js +2 -2
  105. package/lib/zudoku.plugin-search-pagefind.js +2 -2
  106. package/package.json +4 -3
  107. package/src/lib/components/index.ts +19 -39
  108. package/src/lib/hooks/index.ts +7 -16
  109. package/src/lib/oas/graphql/circular.test.ts +37 -2
  110. package/src/lib/oas/graphql/circular.ts +25 -51
  111. package/src/lib/oas/parser/index.ts +17 -6
  112. package/src/lib/util/flattenAllOf.test.ts +2 -1
  113. package/src/lib/util/flattenAllOf.ts +0 -57
  114. package/src/lib/util/flattenAllOfProcessor.ts +58 -0
  115. package/src/zuplo/enrich-with-zuplo-mcp.ts +168 -0
  116. package/src/zuplo/enrich-with-zuplo.ts +254 -0
  117. package/src/zuplo/policy-types.ts +46 -0
  118. package/src/zuplo/with-zuplo-processors.ts +35 -0
  119. package/src/zuplo/with-zuplo.ts +14 -0
  120. package/lib/OperationList-Dq_AB4W9.js.map +0 -1
  121. package/lib/___vite-browser-external_commonjs-proxy-BttVsNON.js +0 -9
  122. package/lib/___vite-browser-external_commonjs-proxy-BttVsNON.js.map +0 -1
  123. package/lib/createServer-CLSZ7hWJ.js +0 -16693
  124. package/lib/createServer-CLSZ7hWJ.js.map +0 -1
  125. package/lib/index-CL8eDnQW.js.map +0 -1
  126. package/lib/index-DBjOT2H1.js +0 -133
  127. package/lib/index-DBjOT2H1.js.map +0 -1
  128. package/lib/index.esm-C5CBsVzN.js.map +0 -1
@@ -0,0 +1,254 @@
1
+ import type { OpenAPIV3_1 } from "openapi-types";
2
+ import type { ProcessorArg } from "../config/validators/BuildSchema.js";
3
+ import { objectEntries } from "../lib/util/objectEntries.js";
4
+ import type { RecordAny } from "../lib/util/traverse.js";
5
+ import type {
6
+ PoliciesConfigFile,
7
+ PolicyConfigurationFragment,
8
+ } from "./policy-types.js";
9
+
10
+ const API_KEY_REPLACEMENT_STRING = "YOUR_KEY_HERE";
11
+
12
+ const enrichWithApiKeyData = (
13
+ operationObject: RecordAny,
14
+ apiKeyPolicies: PolicyConfigurationFragment[],
15
+ ) => {
16
+ if (apiKeyPolicies.length === 0) {
17
+ return operationObject;
18
+ }
19
+
20
+ const firstPolicy = apiKeyPolicies[0];
21
+ const authorizationHeader =
22
+ (firstPolicy?.handler.options?.authHeader as string) || "Authorization";
23
+ const authorizationScheme = (firstPolicy?.handler.options?.authScheme ??
24
+ "Bearer") as string;
25
+ const authSchemeExample =
26
+ authorizationScheme !== ""
27
+ ? `${authorizationScheme} ${API_KEY_REPLACEMENT_STRING}`
28
+ : API_KEY_REPLACEMENT_STRING;
29
+
30
+ // Add API key header parameter
31
+ const apiKeyHeader: OpenAPIV3_1.ParameterObject = {
32
+ name: authorizationHeader,
33
+ in: "header",
34
+ required: true,
35
+ example: authSchemeExample,
36
+ schema: {
37
+ type: "string",
38
+ },
39
+ description: `The \`${authorizationHeader}\` header is used to authenticate with the API using your API key. Value is of the format \`${authSchemeExample}\`.`,
40
+ };
41
+
42
+ const parameters = operationObject.parameters || [];
43
+ if (
44
+ !parameters.some((param: RecordAny) => param.name === authorizationHeader)
45
+ ) {
46
+ operationObject.parameters = [apiKeyHeader, ...parameters];
47
+ }
48
+
49
+ // Add security scheme and requirement
50
+ const apiSecuritySchemeId = "api_key";
51
+ const apiKeySecurityRequirement = { [apiSecuritySchemeId]: [] };
52
+
53
+ if (!operationObject.security) {
54
+ operationObject.security = [apiKeySecurityRequirement];
55
+ } else if (
56
+ !operationObject.security.some((req: RecordAny) => req[apiSecuritySchemeId])
57
+ ) {
58
+ operationObject.security = [
59
+ apiKeySecurityRequirement,
60
+ ...operationObject.security,
61
+ ];
62
+ }
63
+
64
+ return operationObject;
65
+ };
66
+
67
+ const enrichWithRateLimitData = (
68
+ operationObject: RecordAny,
69
+ rateLimitPolicies: PolicyConfigurationFragment[],
70
+ ) => {
71
+ if (rateLimitPolicies.length === 0) {
72
+ return operationObject;
73
+ }
74
+
75
+ const shouldIncludeHeader = rateLimitPolicies.some(
76
+ (policy) => policy.handler.options?.headerMode !== "none",
77
+ );
78
+
79
+ if (!operationObject.responses) {
80
+ operationObject.responses = {};
81
+ }
82
+
83
+ if (!operationObject.responses["429"]) {
84
+ operationObject.responses["429"] = {
85
+ $ref: shouldIncludeHeader
86
+ ? "#/components/responses/RateLimitWithRetryAfter"
87
+ : "#/components/responses/RateLimitNoRetryAfter",
88
+ };
89
+ }
90
+
91
+ return operationObject;
92
+ };
93
+
94
+ // biome-ignore format: for readability
95
+ export const operations = [
96
+ "get", "put", "post", "delete",
97
+ "options", "head", "patch", "trace",
98
+ ];
99
+
100
+ const rateLimitingResponse: OpenAPIV3_1.ResponseObject = {
101
+ description: "Rate Limiting Response",
102
+ content: {
103
+ "application/json": {
104
+ schema: {
105
+ type: "object",
106
+ required: ["type", "title", "status"],
107
+ examples: [
108
+ {
109
+ type: "https://httpproblems.com/http-status/429",
110
+ title: "Too Many Requests",
111
+ status: 429,
112
+ instance: "/foo/bar",
113
+ },
114
+ ],
115
+ properties: {
116
+ type: {
117
+ type: "string",
118
+ example: "https://httpproblems.com/http-status/429",
119
+ description: "A URI reference that identifies the problem.",
120
+ },
121
+ title: {
122
+ type: "string",
123
+ example: "Too Many Requests",
124
+ description: "A short, human-readable summary of the problem.",
125
+ },
126
+ status: {
127
+ type: "number",
128
+ example: 429,
129
+ description: "The HTTP status code.",
130
+ },
131
+ instance: {
132
+ type: "string",
133
+ example: "/foo/bar",
134
+ },
135
+ },
136
+ },
137
+ },
138
+ },
139
+ };
140
+
141
+ const rateLimitingResponseWithHeader: OpenAPIV3_1.ResponseObject = {
142
+ ...rateLimitingResponse,
143
+ headers: {
144
+ "retry-after": {
145
+ description: "The number of seconds to wait before making a new request.",
146
+ schema: {
147
+ type: "integer",
148
+ example: 60,
149
+ },
150
+ },
151
+ },
152
+ };
153
+
154
+ export const enrichWithZuploData = ({
155
+ policiesConfig,
156
+ }: {
157
+ policiesConfig: PoliciesConfigFile;
158
+ }) => {
159
+ return ({ schema }: ProcessorArg) => {
160
+ if (!schema.paths) return schema;
161
+
162
+ let hasRateLimitPolicies = false;
163
+
164
+ for (const [, pathItem] of objectEntries<RecordAny>(schema.paths)) {
165
+ for (const method of operations) {
166
+ const operation = pathItem[method];
167
+ if (!operation?.["x-zuplo-route"]) continue;
168
+
169
+ const inboundPolicies = operation[
170
+ "x-zuplo-route"
171
+ ]?.policies?.inbound?.reduce((acc: string[], policyName: string) => {
172
+ const policy = policiesConfig.policies?.find(
173
+ ({ name }) => name === policyName,
174
+ );
175
+ if (!policy) return acc;
176
+
177
+ // Handle composite policies
178
+ if (policy.handler.export === "CompositeInboundPolicy") {
179
+ const childPolicies = policy.handler.options?.policies as
180
+ | string[]
181
+ | undefined;
182
+ return childPolicies ? [...acc, ...childPolicies] : acc;
183
+ }
184
+
185
+ return [...acc, policyName];
186
+ }, []);
187
+
188
+ if (!inboundPolicies) continue;
189
+
190
+ // Find API key policies
191
+ const apiKeyPolicies =
192
+ policiesConfig.policies?.filter(
193
+ (policy) =>
194
+ inboundPolicies.includes(policy.name) &&
195
+ (policy.handler.export === "ApiAuthKeyInboundPolicy" ||
196
+ policy.handler.export === "ApiKeyInboundPolicy") &&
197
+ !policy.handler.options
198
+ ?.disableAutomaticallyAddingKeyHeaderToOpenApi,
199
+ ) ?? [];
200
+
201
+ // Find rate limit policies
202
+ const rateLimitPolicies =
203
+ policiesConfig.policies?.filter(
204
+ (policy) =>
205
+ inboundPolicies.includes(policy.name) &&
206
+ (policy.handler.export === "RateLimitInboundPolicy" ||
207
+ policy.handler.export === "ComplexRateLimitInboundPolicy"),
208
+ ) ?? [];
209
+
210
+ if (rateLimitPolicies.length > 0) {
211
+ hasRateLimitPolicies = true;
212
+ }
213
+
214
+ // Apply enrichments directly to the operation
215
+ pathItem[method] = enrichWithApiKeyData(operation, apiKeyPolicies);
216
+ pathItem[method] = enrichWithRateLimitData(
217
+ pathItem[method],
218
+ rateLimitPolicies,
219
+ );
220
+ }
221
+ }
222
+
223
+ // Add security scheme if we have API key policies
224
+ if (
225
+ policiesConfig.policies?.some(
226
+ (policy) =>
227
+ policy.handler.export === "ApiAuthKeyInboundPolicy" ||
228
+ policy.handler.export === "ApiKeyInboundPolicy",
229
+ )
230
+ ) {
231
+ if (!schema.components) schema.components = {};
232
+ if (!schema.components.securitySchemes)
233
+ schema.components.securitySchemes = {};
234
+
235
+ if (!schema.components.securitySchemes.api_key) {
236
+ schema.components.securitySchemes.api_key = {
237
+ type: "http",
238
+ scheme: "bearer",
239
+ };
240
+ }
241
+ }
242
+
243
+ // Add rate limiting responses only if we found rate limiting policies
244
+ if (hasRateLimitPolicies) {
245
+ if (!schema.components) schema.components = {};
246
+ if (!schema.components.responses) schema.components.responses = {};
247
+ schema.components.responses.RateLimitNoRetryAfter = rateLimitingResponse;
248
+ schema.components.responses.RateLimitWithRetryAfter =
249
+ rateLimitingResponseWithHeader;
250
+ }
251
+
252
+ return schema;
253
+ };
254
+ };
@@ -0,0 +1,46 @@
1
+ /**
2
+ * This file was automatically generated by json-schema-to-typescript.
3
+ * DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file,
4
+ * and run json-schema-to-typescript to regenerate this file.
5
+ */
6
+
7
+ export interface PoliciesConfigFile {
8
+ policies?: PolicyConfigurationFragment[];
9
+ corsPolicies?: CorsPolicyConfiguration[];
10
+ }
11
+ export interface PolicyConfigurationFragment {
12
+ name: string;
13
+ policyType: string;
14
+ handler: HandlerDefinition;
15
+ options?: {
16
+ [k: string]: unknown;
17
+ };
18
+ }
19
+ export interface HandlerDefinition {
20
+ module: string;
21
+ export: string;
22
+ options?: {
23
+ [k: string]: unknown;
24
+ };
25
+ }
26
+ export interface CorsPolicyConfiguration {
27
+ name: string;
28
+ allowCredentials?: boolean;
29
+ maxAge?: number;
30
+ allowedOrigins: string[] | string;
31
+ allowedMethods?:
32
+ | (
33
+ | "GET"
34
+ | "HEAD"
35
+ | "POST"
36
+ | "PUT"
37
+ | "DELETE"
38
+ | "CONNECT"
39
+ | "OPTIONS"
40
+ | "TRACE"
41
+ | "PATCH"
42
+ )[]
43
+ | string;
44
+ allowedHeaders?: string[] | string;
45
+ exposeHeaders?: string[] | string;
46
+ }
@@ -0,0 +1,35 @@
1
+ import fs from "node:fs/promises";
2
+ import path from "node:path";
3
+ import { ZuploEnv } from "../app/env.js";
4
+ import type {
5
+ Processor,
6
+ ProcessorArg,
7
+ } from "../config/validators/BuildSchema.js";
8
+ import { removeExtensions } from "../lib/plugins/openapi/processors/removeExtensions.js";
9
+ import { removeParameters } from "../lib/plugins/openapi/processors/removeParameters.js";
10
+ import { removePaths } from "../lib/plugins/openapi/processors/removePaths.js";
11
+ import { enrichWithZuploData } from "./enrich-with-zuplo.js";
12
+ import { enrichWithZuploMcpServerData } from "./enrich-with-zuplo-mcp.js";
13
+
14
+ export const getProcessors = async (rootDir: string): Promise<Processor[]> => {
15
+ const policiesConfig = JSON.parse(
16
+ await fs.readFile(path.join(rootDir, "../config/policies.json"), "utf-8"),
17
+ );
18
+
19
+ return [
20
+ removePaths({ shouldRemove: ({ operation }) => operation["x-internal"] }),
21
+ removeParameters({
22
+ shouldRemove: ({ parameter }) => parameter["x-internal"],
23
+ }),
24
+ enrichWithZuploData({ policiesConfig }),
25
+ enrichWithZuploMcpServerData({ rootDir }),
26
+ ({ schema }: ProcessorArg) => {
27
+ const url = ZuploEnv.serverUrl;
28
+ if (!url) return schema;
29
+ return { ...schema, servers: [{ url }] };
30
+ },
31
+ removeExtensions({ shouldRemove: (key) => key.startsWith("x-zuplo") }),
32
+ ];
33
+ };
34
+
35
+ export default getProcessors;
@@ -0,0 +1,14 @@
1
+ import type { ZudokuConfig } from "../config/validators/validate.js";
2
+
3
+ /**
4
+ * @deprecated `withZuplo` is no longer needed and will automatically be applied. It will be removed in a future version.
5
+ */
6
+ const withZuplo = (config: ZudokuConfig): ZudokuConfig => {
7
+ // biome-ignore lint/suspicious/noConsole: Logging allowed here
8
+ console.warn(
9
+ "`withZuplo` is no longer needed and will automatically be applied. It will be removed in a future version.",
10
+ );
11
+ return config;
12
+ };
13
+
14
+ export default withZuplo;