@lukoweb/apitogo 0.1.1 → 0.1.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 +17 -6
  2. package/dist/declarations/lib/ui/Command.d.ts +1 -1
  3. package/dist/declarations/lib/util/MdxComponents.d.ts +1 -1
  4. package/package.json +1 -1
  5. package/src/app/main.tsx +150 -150
  6. package/src/config/loader.ts +245 -245
  7. package/src/index.ts +33 -33
  8. package/src/lib/authentication/components/CallbackHandler.tsx +45 -45
  9. package/src/lib/authentication/components/SignIn.tsx +46 -46
  10. package/src/lib/authentication/components/SignUp.tsx +48 -48
  11. package/src/lib/authentication/providers/clerk.tsx +224 -224
  12. package/src/lib/authentication/ui/AuthCard.tsx +7 -7
  13. package/src/lib/authentication/ui/EmailLinkCallbackUi.tsx +129 -125
  14. package/src/lib/authentication/ui/EmailLinkSentUi.tsx +105 -101
  15. package/src/lib/authentication/ui/EmailLinkSignInUi.tsx +100 -96
  16. package/src/lib/authentication/ui/EmailVerificationUi.tsx +128 -124
  17. package/src/lib/authentication/ui/ZudokuAuthUi.tsx +620 -616
  18. package/src/lib/components/AiAssistantMenuItems.tsx +102 -102
  19. package/src/lib/components/Autocomplete.tsx +123 -123
  20. package/src/lib/components/DeveloperHint.tsx +39 -35
  21. package/src/lib/components/Header.tsx +260 -260
  22. package/src/lib/components/Layout.tsx +53 -53
  23. package/src/lib/components/Main.tsx +51 -51
  24. package/src/lib/components/Mermaid.tsx +74 -70
  25. package/src/lib/components/MobileTopNavigation.tsx +276 -276
  26. package/src/lib/components/MultiSelect.tsx +86 -82
  27. package/src/lib/components/TopNavigation.tsx +103 -103
  28. package/src/lib/components/index.ts +26 -26
  29. package/src/lib/components/navigation/NavigationCategory.tsx +157 -157
  30. package/src/lib/components/navigation/NavigationFilterInput.tsx +35 -35
  31. package/src/lib/components/navigation/NavigationItem.tsx +181 -177
  32. package/src/lib/core/RouteGuard.tsx +193 -193
  33. package/src/lib/errors/ErrorMessage.tsx +50 -46
  34. package/src/lib/plugins/api-catalog/Catalog.tsx +80 -80
  35. package/src/lib/plugins/api-keys/CreateApiKey.tsx +128 -124
  36. package/src/lib/plugins/api-keys/CreateApiKeyDialog.tsx +49 -49
  37. package/src/lib/plugins/api-keys/SettingsApiKeys.tsx +72 -72
  38. package/src/lib/plugins/api-keys/settings/ApiKeyItem.tsx +342 -342
  39. package/src/lib/plugins/api-keys/settings/RevealApiKey.tsx +127 -127
  40. package/src/lib/plugins/markdown/MdxPage.tsx +285 -285
  41. package/src/lib/plugins/openapi/ApiHeader.tsx +96 -96
  42. package/src/lib/plugins/openapi/CollapsibleCode.tsx +88 -88
  43. package/src/lib/plugins/openapi/DownloadSchemaButton.tsx +94 -94
  44. package/src/lib/plugins/openapi/GeneratedExampleSidecarBox.tsx +52 -52
  45. package/src/lib/plugins/openapi/OperationListItem.tsx +183 -183
  46. package/src/lib/plugins/openapi/RequestBodySidecarBox.tsx +63 -63
  47. package/src/lib/plugins/openapi/ResponsesSidecarBox.tsx +120 -117
  48. package/src/lib/plugins/openapi/SchemaInfo.tsx +344 -344
  49. package/src/lib/plugins/openapi/SchemaList.tsx +113 -113
  50. package/src/lib/plugins/openapi/Sidecar.tsx +312 -309
  51. package/src/lib/plugins/openapi/SidecarExamples.tsx +177 -174
  52. package/src/lib/plugins/openapi/components/EnumValues.tsx +58 -58
  53. package/src/lib/plugins/openapi/components/ResponseContent.tsx +117 -114
  54. package/src/lib/plugins/openapi/playground/BodyPanel.tsx +274 -271
  55. package/src/lib/plugins/openapi/playground/CollapsibleHeader.tsx +51 -51
  56. package/src/lib/plugins/openapi/playground/ExamplesDropdown.tsx +60 -60
  57. package/src/lib/plugins/openapi/playground/Headers.tsx +188 -181
  58. package/src/lib/plugins/openapi/playground/IdentityDialog.tsx +75 -75
  59. package/src/lib/plugins/openapi/playground/IdentitySelector.tsx +38 -38
  60. package/src/lib/plugins/openapi/playground/ParamsGrid.tsx +45 -45
  61. package/src/lib/plugins/openapi/playground/Playground.tsx +602 -599
  62. package/src/lib/plugins/openapi/playground/PlaygroundDialog.tsx +56 -56
  63. package/src/lib/plugins/openapi/playground/QueryParams.tsx +151 -148
  64. package/src/lib/plugins/openapi/playground/RequestLoginDialog.tsx +70 -70
  65. package/src/lib/plugins/openapi/playground/request-panel/MultipartField.tsx +91 -91
  66. package/src/lib/plugins/openapi/playground/result-panel/AudioPlayer.tsx +50 -50
  67. package/src/lib/plugins/openapi/playground/result-panel/ResponseTab.tsx +355 -355
  68. package/src/lib/plugins/openapi/playground/result-panel/ResultPanel.tsx +106 -102
  69. package/src/lib/plugins/openapi/schema/SchemaPropertyItem.tsx +189 -184
  70. package/src/lib/plugins/openapi/schema/SchemaView.tsx +299 -299
  71. package/src/lib/plugins/search-pagefind/IndexingDialog.tsx +162 -162
  72. package/src/lib/plugins/search-pagefind/PagefindSearch.tsx +202 -202
  73. package/src/lib/plugins/search-pagefind/ResultList.tsx +122 -118
  74. package/src/lib/ui/ActionButton.tsx +21 -21
  75. package/src/lib/ui/Command.tsx +191 -191
  76. package/src/lib/util/MdxComponents.tsx +150 -150
  77. package/src/vite/config.ts +234 -231
  78. package/src/vite/dev-server.ts +291 -291
  79. package/src/vite/plugin-api-keys.ts +50 -50
  80. package/src/vite/plugin-api.ts +320 -318
  81. package/src/vite/plugin-auth.ts +38 -38
  82. package/src/vite/plugin-component.ts +45 -39
  83. package/src/vite/plugin-config.ts +75 -75
  84. package/src/vite/plugin-custom-pages.ts +36 -36
  85. package/src/vite/plugin-docs.ts +202 -202
  86. package/src/vite/plugin-markdown-export.ts +214 -214
  87. package/src/vite/plugin-mdx.ts +149 -149
  88. package/src/vite/plugin-navigation.ts +106 -106
  89. package/src/vite/plugin-search.ts +47 -47
  90. package/src/vite/plugin.ts +42 -42
  91. package/src/vite/prerender/prerender.ts +233 -233
@@ -1,318 +1,320 @@
1
- import fs from "node:fs/promises";
2
- import path from "node:path";
3
- import { deepEqual } from "fast-equals";
4
- import { type Plugin, runnerImport } from "vite";
5
- import { ZuploEnv } from "../app/env.js";
6
- import { getZudokuRootDir } from "../cli/common/package-json.js";
7
- import { getCurrentConfig } from "../config/loader.js";
8
- import {
9
- getBuildConfig,
10
- type Processor,
11
- } from "../config/validators/BuildSchema.js";
12
- import { getAllTags } from "../lib/oas/graphql/index.js";
13
- import type {
14
- ApiCatalogItem,
15
- ApiCatalogPluginOptions,
16
- } from "../lib/plugins/api-catalog/index.js";
17
- import type { VersionedInput } from "../lib/plugins/openapi/interfaces.js";
18
- import { ensureArray } from "../lib/util/ensureArray.js";
19
- import { SchemaManager } from "./api/SchemaManager.js";
20
- import { reload } from "./plugin-config-reload.js";
21
- import { invalidate as invalidateNavigation } from "./plugin-navigation.js";
22
-
23
- const viteApiPlugin = async (): Promise<Plugin> => {
24
- const virtualModuleId = "virtual:zudoku-api-plugins";
25
- const resolvedVirtualModuleId = `\0${virtualModuleId}`;
26
-
27
- const initialConfig = getCurrentConfig();
28
-
29
- // Load Zuplo-specific processors if in Zuplo environment
30
- const zuploProcessors = ZuploEnv.isZuplo
31
- ? await runnerImport<{ default: (rootDir: string) => Processor[] }>(
32
- path.resolve(getZudokuRootDir(), "src/zuplo/with-zuplo-processors.ts"),
33
- ).then((m) => m.module.default(initialConfig.__meta.rootDir))
34
- : [];
35
-
36
- const buildConfig = await getBuildConfig();
37
- const buildProcessors = buildConfig?.processors ?? [];
38
-
39
- const tmpStoreDir = path.posix.join(
40
- initialConfig.__meta.rootDir,
41
- "node_modules/.apitogo/processed",
42
- );
43
-
44
- const processors = [...buildProcessors, ...zuploProcessors];
45
- const schemaManager = new SchemaManager({
46
- storeDir: tmpStoreDir,
47
- config: initialConfig,
48
- processors,
49
- });
50
-
51
- return {
52
- name: "zudoku-api-plugins",
53
- async buildStart() {
54
- await fs.rm(tmpStoreDir, { recursive: true, force: true });
55
- await fs.mkdir(tmpStoreDir, { recursive: true });
56
-
57
- await schemaManager.processAllSchemas();
58
-
59
- schemaManager
60
- .getAllTrackedFiles()
61
- .forEach((file) => this.addWatchFile(file));
62
- },
63
- configureServer(server) {
64
- // Serve original OpenAPI schema files
65
- server.middlewares.use(async (req, res, next) => {
66
- if (req.method !== "GET" || !req.url) return next();
67
- if (
68
- !req.url.toLowerCase().endsWith(".json") &&
69
- !req.url.toLowerCase().endsWith(".yaml")
70
- ) {
71
- return next();
72
- }
73
-
74
- const pathMap = schemaManager.getUrlToFilePathMap();
75
-
76
- const inputPath = pathMap.get(req.url);
77
- if (!inputPath) return next();
78
-
79
- const content = await fs.readFile(inputPath, "utf-8");
80
- const mimeType =
81
- path.extname(inputPath).toLowerCase() === ".json"
82
- ? "application/json"
83
- : "application/x-yaml";
84
-
85
- res.setHeader("Content-Type", `${mimeType}; charset=utf-8`);
86
- return res.end(content);
87
- });
88
-
89
- server.watcher.on("change", async (id) => {
90
- const mainFiles = schemaManager.getFilesToReprocess(id);
91
- if (mainFiles.length === 0) return;
92
-
93
- // biome-ignore lint/suspicious/noConsole: Logging allowed here
94
- console.log(`Re-processing schema ${id}`);
95
-
96
- for (const inputConfig of mainFiles) {
97
- await schemaManager.processSchema(inputConfig);
98
- }
99
- schemaManager
100
- .getAllTrackedFiles()
101
- .forEach((file) => server.watcher.add(file));
102
-
103
- invalidateNavigation(server);
104
- reload(server);
105
- });
106
- },
107
- resolveId(id) {
108
- if (id === virtualModuleId) {
109
- return resolvedVirtualModuleId;
110
- }
111
- },
112
- async load(id) {
113
- if (id !== resolvedVirtualModuleId) return;
114
-
115
- const config = getCurrentConfig();
116
-
117
- if (!deepEqual(schemaManager.config.apis, config.apis)) {
118
- schemaManager.config = config;
119
- await schemaManager.processAllSchemas();
120
- schemaManager
121
- .getAllTrackedFiles()
122
- .forEach((file) => this.addWatchFile(file));
123
- }
124
-
125
- if (config.__meta.mode === "standalone") {
126
- return [
127
- "export const configuredApiPlugins = [];",
128
- "export const configuredApiCatalogPlugins = [];",
129
- ].join("\n");
130
- }
131
-
132
- const code = [
133
- `import config from "virtual:zudoku-config";`,
134
- `const configuredApiPlugins = [];`,
135
- `const configuredApiCatalogPlugins = [];`,
136
- ];
137
-
138
- if (config.apis) {
139
- code.push('import { openApiPlugin } from "@lukoweb/apitogo/plugins/openapi";');
140
- code.push(
141
- `const apis = Array.isArray(config.apis) ? config.apis : [config.apis]`,
142
- );
143
- const apis = ensureArray(config.apis);
144
- const apiMetadata: ApiCatalogItem[] = [];
145
-
146
- for (const apiConfig of apis) {
147
- if (apiConfig.type === "file" && apiConfig.path) {
148
- const latestSchema = schemaManager.getLatestSchema(apiConfig.path);
149
- if (!latestSchema?.schema.info) continue;
150
-
151
- apiMetadata.push({
152
- path: apiConfig.path,
153
- label: latestSchema.schema.info.title,
154
- description: latestSchema.schema.info.description ?? "",
155
- categories: apiConfig.categories ?? [],
156
- });
157
- }
158
- }
159
-
160
- // Generate API plugin code
161
- let apiIndex = -1;
162
- for (const apiConfig of apis) {
163
- apiIndex++;
164
- if (apiConfig.type === "file") {
165
- if (!apiConfig.path) continue;
166
-
167
- const schemas = schemaManager.getSchemasForPath(apiConfig.path);
168
-
169
- if (!schemas?.length) continue;
170
-
171
- const allSlugs = new Set<string>();
172
- const versionedInput = schemas.map<VersionedInput>((s) => {
173
- const versionTags = getAllTags(s.schema);
174
- versionTags.forEach(({ slug }) => {
175
- if (slug) allSlugs.add(slug);
176
- });
177
-
178
- return {
179
- path: s.path,
180
- version: s.version,
181
- downloadUrl: s.downloadUrl,
182
- label: s.label ?? s.schema.info?.version,
183
- input: s.importKey,
184
- hasUntaggedOperations: versionTags.some(
185
- (tag) => tag.name === undefined,
186
- ),
187
- tagPages: versionTags.flatMap((t) => t.slug ?? []),
188
- };
189
- });
190
-
191
- const tags = Array.from(allSlugs);
192
-
193
- const schemaImports = schemaManager.getSchemaImports();
194
-
195
- code.push(
196
- "configuredApiPlugins.push(openApiPlugin({",
197
- ` type: "file",`,
198
- ` input: ${JSON.stringify(versionedInput)},`,
199
- ` path: ${JSON.stringify(apiConfig.path)},`,
200
- ` tagPages: ${JSON.stringify(tags)},`,
201
- ` options: {`,
202
- ` examplesLanguage: config.defaults?.apis?.examplesLanguage ?? config.defaults?.examplesLanguage,`,
203
- ` supportedLanguages: config.defaults?.apis?.supportedLanguages,`,
204
- ` disablePlayground: config.defaults?.apis?.disablePlayground,`,
205
- ` disableSidecar: config.defaults?.apis?.disableSidecar,`,
206
- ` showVersionSelect: config.defaults?.apis?.showVersionSelect ?? "if-available",`,
207
- ` expandAllTags: config.defaults?.apis?.expandAllTags ?? true,`,
208
- ` showInfoPage: config.defaults?.apis?.showInfoPage ?? true,`,
209
- ` schemaDownload: config.defaults?.apis?.schemaDownload,`,
210
- ` transformExamples: config.defaults?.apis?.transformExamples,`,
211
- ` generateCodeSnippet: config.defaults?.apis?.generateCodeSnippet,`,
212
- ` ...(apis[${apiIndex}].options ?? {}),`,
213
- ` },`,
214
- ` schemaImports: {`,
215
- ...schemaImports.map(
216
- (s) =>
217
- ` "${s.importKey.replaceAll("\\", "\\\\")}": () => import("${s.importKey.replaceAll("\\", "/")}?d=${s.processedTime}"),`,
218
- ),
219
- ` },`,
220
- "}));",
221
- );
222
- } else {
223
- code.push(
224
- "configuredApiPlugins.push(openApiPlugin({",
225
- ` ...${JSON.stringify(apiConfig)},`,
226
- " options: {",
227
- ` examplesLanguage: config.defaults?.apis?.examplesLanguage ?? config.defaults?.examplesLanguage,`,
228
- ` supportedLanguages: config.defaults?.apis?.supportedLanguages,`,
229
- ` disablePlayground: config.defaults?.apis?.disablePlayground,`,
230
- ` disableSidecar: config.defaults?.apis?.disableSidecar,`,
231
- ` showVersionSelect: config.defaults?.apis?.showVersionSelect ?? "if-available",`,
232
- ` expandAllTags: config.defaults?.apis?.expandAllTags ?? false,`,
233
- ` showInfoPage: config.defaults?.apis?.showInfoPage ?? true,`,
234
- ` schemaDownload: config.defaults?.apis?.schemaDownload,`,
235
- ` ...${JSON.stringify(apiConfig.options ?? {})},`,
236
- " },",
237
- "}));",
238
- );
239
- }
240
- }
241
-
242
- if (config.catalogs) {
243
- code.push(
244
- 'import { apiCatalogPlugin } from "@lukoweb/apitogo/plugins/api-catalog";',
245
- );
246
-
247
- const catalogs = ensureArray(config.catalogs);
248
-
249
- const categories = apis
250
- .flatMap((api) => api.categories ?? [])
251
- .reduce((acc, catalog) => {
252
- if (!acc.has(catalog.label)) {
253
- acc.set(catalog.label ?? "", new Set(catalog.tags));
254
- }
255
- for (const tag of catalog.tags) {
256
- acc.get(catalog.label ?? "")?.add(tag);
257
- }
258
- return acc;
259
- }, new Map<string, Set<string>>());
260
-
261
- const categoryList = Array.from(categories.entries()).map(
262
- ([label, tags]) => ({
263
- label,
264
- tags: Array.from(tags),
265
- }),
266
- );
267
-
268
- for (let i = 0; i < catalogs.length; i++) {
269
- const catalog = catalogs[i];
270
- if (!catalog) {
271
- continue;
272
- }
273
- const apiCatalogConfig: ApiCatalogPluginOptions = {
274
- ...catalog,
275
- items: apiMetadata,
276
- label: catalog.label,
277
- categories: categoryList,
278
- filterCatalogItems: catalog.filterItems,
279
- };
280
-
281
- code.push(
282
- `configuredApiCatalogPlugins.push(apiCatalogPlugin({`,
283
- ` ...${JSON.stringify(apiCatalogConfig, null, 2)},`,
284
- ` filterCatalogItems: Array.isArray(config.catalogs)`,
285
- ` ? config.catalogs[${i}].filterItems`,
286
- ` : config.catalogs.filterItems,`,
287
- `}));`,
288
- );
289
- }
290
- }
291
- }
292
-
293
- code.push(
294
- `export { configuredApiPlugins, configuredApiCatalogPlugins };`,
295
- );
296
-
297
- return code.join("\n");
298
- },
299
- async closeBundle() {
300
- if (this.environment.name === "ssr") return;
301
-
302
- const config = getCurrentConfig();
303
- const pathMap = schemaManager.getUrlToFilePathMap();
304
-
305
- if (process.env.NODE_ENV !== "production") return;
306
-
307
- for (const [urlPath, inputPath] of pathMap) {
308
- const content = await fs.readFile(inputPath, "utf-8");
309
- const outputPath = path.join(config.__meta.rootDir, "dist", urlPath);
310
-
311
- await fs.mkdir(path.dirname(outputPath), { recursive: true });
312
- await fs.writeFile(outputPath, content, "utf-8");
313
- }
314
- },
315
- };
316
- };
317
-
318
- export default viteApiPlugin;
1
+ import fs from "node:fs/promises";
2
+ import path from "node:path";
3
+ import { deepEqual } from "fast-equals";
4
+ import { type Plugin, runnerImport } from "vite";
5
+ import { ZuploEnv } from "../app/env.js";
6
+ import { getZudokuRootDir } from "../cli/common/package-json.js";
7
+ import { getCurrentConfig } from "../config/loader.js";
8
+ import {
9
+ getBuildConfig,
10
+ type Processor,
11
+ } from "../config/validators/BuildSchema.js";
12
+ import { getAllTags } from "../lib/oas/graphql/index.js";
13
+ import type {
14
+ ApiCatalogItem,
15
+ ApiCatalogPluginOptions,
16
+ } from "../lib/plugins/api-catalog/index.js";
17
+ import type { VersionedInput } from "../lib/plugins/openapi/interfaces.js";
18
+ import { ensureArray } from "../lib/util/ensureArray.js";
19
+ import { SchemaManager } from "./api/SchemaManager.js";
20
+ import { reload } from "./plugin-config-reload.js";
21
+ import { invalidate as invalidateNavigation } from "./plugin-navigation.js";
22
+
23
+ const viteApiPlugin = async (): Promise<Plugin> => {
24
+ const virtualModuleId = "virtual:zudoku-api-plugins";
25
+ const resolvedVirtualModuleId = `\0${virtualModuleId}`;
26
+
27
+ const initialConfig = getCurrentConfig();
28
+
29
+ // Load Zuplo-specific processors if in Zuplo environment
30
+ const zuploProcessors = ZuploEnv.isZuplo
31
+ ? await runnerImport<{ default: (rootDir: string) => Processor[] }>(
32
+ path.resolve(getZudokuRootDir(), "src/zuplo/with-zuplo-processors.ts"),
33
+ ).then((m) => m.module.default(initialConfig.__meta.rootDir))
34
+ : [];
35
+
36
+ const buildConfig = await getBuildConfig();
37
+ const buildProcessors = buildConfig?.processors ?? [];
38
+
39
+ const tmpStoreDir = path.posix.join(
40
+ initialConfig.__meta.rootDir,
41
+ "node_modules/.apitogo/processed",
42
+ );
43
+
44
+ const processors = [...buildProcessors, ...zuploProcessors];
45
+ const schemaManager = new SchemaManager({
46
+ storeDir: tmpStoreDir,
47
+ config: initialConfig,
48
+ processors,
49
+ });
50
+
51
+ return {
52
+ name: "zudoku-api-plugins",
53
+ async buildStart() {
54
+ await fs.rm(tmpStoreDir, { recursive: true, force: true });
55
+ await fs.mkdir(tmpStoreDir, { recursive: true });
56
+
57
+ await schemaManager.processAllSchemas();
58
+
59
+ schemaManager
60
+ .getAllTrackedFiles()
61
+ .forEach((file) => this.addWatchFile(file));
62
+ },
63
+ configureServer(server) {
64
+ // Serve original OpenAPI schema files
65
+ server.middlewares.use(async (req, res, next) => {
66
+ if (req.method !== "GET" || !req.url) return next();
67
+ if (
68
+ !req.url.toLowerCase().endsWith(".json") &&
69
+ !req.url.toLowerCase().endsWith(".yaml")
70
+ ) {
71
+ return next();
72
+ }
73
+
74
+ const pathMap = schemaManager.getUrlToFilePathMap();
75
+
76
+ const inputPath = pathMap.get(req.url);
77
+ if (!inputPath) return next();
78
+
79
+ const content = await fs.readFile(inputPath, "utf-8");
80
+ const mimeType =
81
+ path.extname(inputPath).toLowerCase() === ".json"
82
+ ? "application/json"
83
+ : "application/x-yaml";
84
+
85
+ res.setHeader("Content-Type", `${mimeType}; charset=utf-8`);
86
+ return res.end(content);
87
+ });
88
+
89
+ server.watcher.on("change", async (id) => {
90
+ const mainFiles = schemaManager.getFilesToReprocess(id);
91
+ if (mainFiles.length === 0) return;
92
+
93
+ // biome-ignore lint/suspicious/noConsole: Logging allowed here
94
+ console.log(`Re-processing schema ${id}`);
95
+
96
+ for (const inputConfig of mainFiles) {
97
+ await schemaManager.processSchema(inputConfig);
98
+ }
99
+ schemaManager
100
+ .getAllTrackedFiles()
101
+ .forEach((file) => server.watcher.add(file));
102
+
103
+ invalidateNavigation(server);
104
+ reload(server);
105
+ });
106
+ },
107
+ resolveId(id) {
108
+ if (id === virtualModuleId) {
109
+ return resolvedVirtualModuleId;
110
+ }
111
+ },
112
+ async load(id) {
113
+ if (id !== resolvedVirtualModuleId) return;
114
+
115
+ const config = getCurrentConfig();
116
+
117
+ if (!deepEqual(schemaManager.config.apis, config.apis)) {
118
+ schemaManager.config = config;
119
+ await schemaManager.processAllSchemas();
120
+ schemaManager
121
+ .getAllTrackedFiles()
122
+ .forEach((file) => this.addWatchFile(file));
123
+ }
124
+
125
+ if (config.__meta.mode === "standalone") {
126
+ return [
127
+ "export const configuredApiPlugins = [];",
128
+ "export const configuredApiCatalogPlugins = [];",
129
+ ].join("\n");
130
+ }
131
+
132
+ const code = [
133
+ `import config from "virtual:zudoku-config";`,
134
+ `const configuredApiPlugins = [];`,
135
+ `const configuredApiCatalogPlugins = [];`,
136
+ ];
137
+
138
+ if (config.apis) {
139
+ code.push(
140
+ 'import { openApiPlugin } from "@lukoweb/apitogo/plugins/openapi";',
141
+ );
142
+ code.push(
143
+ `const apis = Array.isArray(config.apis) ? config.apis : [config.apis]`,
144
+ );
145
+ const apis = ensureArray(config.apis);
146
+ const apiMetadata: ApiCatalogItem[] = [];
147
+
148
+ for (const apiConfig of apis) {
149
+ if (apiConfig.type === "file" && apiConfig.path) {
150
+ const latestSchema = schemaManager.getLatestSchema(apiConfig.path);
151
+ if (!latestSchema?.schema.info) continue;
152
+
153
+ apiMetadata.push({
154
+ path: apiConfig.path,
155
+ label: latestSchema.schema.info.title,
156
+ description: latestSchema.schema.info.description ?? "",
157
+ categories: apiConfig.categories ?? [],
158
+ });
159
+ }
160
+ }
161
+
162
+ // Generate API plugin code
163
+ let apiIndex = -1;
164
+ for (const apiConfig of apis) {
165
+ apiIndex++;
166
+ if (apiConfig.type === "file") {
167
+ if (!apiConfig.path) continue;
168
+
169
+ const schemas = schemaManager.getSchemasForPath(apiConfig.path);
170
+
171
+ if (!schemas?.length) continue;
172
+
173
+ const allSlugs = new Set<string>();
174
+ const versionedInput = schemas.map<VersionedInput>((s) => {
175
+ const versionTags = getAllTags(s.schema);
176
+ versionTags.forEach(({ slug }) => {
177
+ if (slug) allSlugs.add(slug);
178
+ });
179
+
180
+ return {
181
+ path: s.path,
182
+ version: s.version,
183
+ downloadUrl: s.downloadUrl,
184
+ label: s.label ?? s.schema.info?.version,
185
+ input: s.importKey,
186
+ hasUntaggedOperations: versionTags.some(
187
+ (tag) => tag.name === undefined,
188
+ ),
189
+ tagPages: versionTags.flatMap((t) => t.slug ?? []),
190
+ };
191
+ });
192
+
193
+ const tags = Array.from(allSlugs);
194
+
195
+ const schemaImports = schemaManager.getSchemaImports();
196
+
197
+ code.push(
198
+ "configuredApiPlugins.push(openApiPlugin({",
199
+ ` type: "file",`,
200
+ ` input: ${JSON.stringify(versionedInput)},`,
201
+ ` path: ${JSON.stringify(apiConfig.path)},`,
202
+ ` tagPages: ${JSON.stringify(tags)},`,
203
+ ` options: {`,
204
+ ` examplesLanguage: config.defaults?.apis?.examplesLanguage ?? config.defaults?.examplesLanguage,`,
205
+ ` supportedLanguages: config.defaults?.apis?.supportedLanguages,`,
206
+ ` disablePlayground: config.defaults?.apis?.disablePlayground,`,
207
+ ` disableSidecar: config.defaults?.apis?.disableSidecar,`,
208
+ ` showVersionSelect: config.defaults?.apis?.showVersionSelect ?? "if-available",`,
209
+ ` expandAllTags: config.defaults?.apis?.expandAllTags ?? true,`,
210
+ ` showInfoPage: config.defaults?.apis?.showInfoPage ?? true,`,
211
+ ` schemaDownload: config.defaults?.apis?.schemaDownload,`,
212
+ ` transformExamples: config.defaults?.apis?.transformExamples,`,
213
+ ` generateCodeSnippet: config.defaults?.apis?.generateCodeSnippet,`,
214
+ ` ...(apis[${apiIndex}].options ?? {}),`,
215
+ ` },`,
216
+ ` schemaImports: {`,
217
+ ...schemaImports.map(
218
+ (s) =>
219
+ ` "${s.importKey.replaceAll("\\", "\\\\")}": () => import("${s.importKey.replaceAll("\\", "/")}?d=${s.processedTime}"),`,
220
+ ),
221
+ ` },`,
222
+ "}));",
223
+ );
224
+ } else {
225
+ code.push(
226
+ "configuredApiPlugins.push(openApiPlugin({",
227
+ ` ...${JSON.stringify(apiConfig)},`,
228
+ " options: {",
229
+ ` examplesLanguage: config.defaults?.apis?.examplesLanguage ?? config.defaults?.examplesLanguage,`,
230
+ ` supportedLanguages: config.defaults?.apis?.supportedLanguages,`,
231
+ ` disablePlayground: config.defaults?.apis?.disablePlayground,`,
232
+ ` disableSidecar: config.defaults?.apis?.disableSidecar,`,
233
+ ` showVersionSelect: config.defaults?.apis?.showVersionSelect ?? "if-available",`,
234
+ ` expandAllTags: config.defaults?.apis?.expandAllTags ?? false,`,
235
+ ` showInfoPage: config.defaults?.apis?.showInfoPage ?? true,`,
236
+ ` schemaDownload: config.defaults?.apis?.schemaDownload,`,
237
+ ` ...${JSON.stringify(apiConfig.options ?? {})},`,
238
+ " },",
239
+ "}));",
240
+ );
241
+ }
242
+ }
243
+
244
+ if (config.catalogs) {
245
+ code.push(
246
+ 'import { apiCatalogPlugin } from "@lukoweb/apitogo/plugins/api-catalog";',
247
+ );
248
+
249
+ const catalogs = ensureArray(config.catalogs);
250
+
251
+ const categories = apis
252
+ .flatMap((api) => api.categories ?? [])
253
+ .reduce((acc, catalog) => {
254
+ if (!acc.has(catalog.label)) {
255
+ acc.set(catalog.label ?? "", new Set(catalog.tags));
256
+ }
257
+ for (const tag of catalog.tags) {
258
+ acc.get(catalog.label ?? "")?.add(tag);
259
+ }
260
+ return acc;
261
+ }, new Map<string, Set<string>>());
262
+
263
+ const categoryList = Array.from(categories.entries()).map(
264
+ ([label, tags]) => ({
265
+ label,
266
+ tags: Array.from(tags),
267
+ }),
268
+ );
269
+
270
+ for (let i = 0; i < catalogs.length; i++) {
271
+ const catalog = catalogs[i];
272
+ if (!catalog) {
273
+ continue;
274
+ }
275
+ const apiCatalogConfig: ApiCatalogPluginOptions = {
276
+ ...catalog,
277
+ items: apiMetadata,
278
+ label: catalog.label,
279
+ categories: categoryList,
280
+ filterCatalogItems: catalog.filterItems,
281
+ };
282
+
283
+ code.push(
284
+ `configuredApiCatalogPlugins.push(apiCatalogPlugin({`,
285
+ ` ...${JSON.stringify(apiCatalogConfig, null, 2)},`,
286
+ ` filterCatalogItems: Array.isArray(config.catalogs)`,
287
+ ` ? config.catalogs[${i}].filterItems`,
288
+ ` : config.catalogs.filterItems,`,
289
+ `}));`,
290
+ );
291
+ }
292
+ }
293
+ }
294
+
295
+ code.push(
296
+ `export { configuredApiPlugins, configuredApiCatalogPlugins };`,
297
+ );
298
+
299
+ return code.join("\n");
300
+ },
301
+ async closeBundle() {
302
+ if (this.environment.name === "ssr") return;
303
+
304
+ const config = getCurrentConfig();
305
+ const pathMap = schemaManager.getUrlToFilePathMap();
306
+
307
+ if (process.env.NODE_ENV !== "production") return;
308
+
309
+ for (const [urlPath, inputPath] of pathMap) {
310
+ const content = await fs.readFile(inputPath, "utf-8");
311
+ const outputPath = path.join(config.__meta.rootDir, "dist", urlPath);
312
+
313
+ await fs.mkdir(path.dirname(outputPath), { recursive: true });
314
+ await fs.writeFile(outputPath, content, "utf-8");
315
+ }
316
+ },
317
+ };
318
+ };
319
+
320
+ export default viteApiPlugin;