@scalar/fastify-api-reference 1.31.2 → 1.31.3

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/types.js ADDED
@@ -0,0 +1 @@
1
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": [],
4
+ "sourcesContent": [],
5
+ "mappings": "",
6
+ "names": []
7
+ }
@@ -1,23 +1,18 @@
1
- import fs from 'node:fs';
2
- import path from 'node:path';
3
- import { fileURLToPath } from 'node:url';
4
-
5
- /**
6
- * Read the JavaScript file.
7
- */
1
+ import fs from "node:fs";
2
+ import path from "node:path";
3
+ import { fileURLToPath } from "node:url";
8
4
  function getJavaScriptFile() {
9
- // Get the directory name
10
- const dirname = path.dirname(fileURLToPath(import.meta.url));
11
- // Find the JavaScript file
12
- const filePath = [
13
- path.resolve(`${dirname}/js/standalone.js`),
14
- path.resolve(`${dirname}/../../dist/js/standalone.js`),
15
- ].find((file) => fs.existsSync(file));
16
- // Throw an error if the file is not found
17
- if (filePath === undefined) {
18
- throw new Error(`JavaScript file not found: ${path.resolve(`${dirname}/js/standalone.js`)}`);
19
- }
20
- return fs.readFileSync(filePath, 'utf8');
5
+ const dirname = path.dirname(fileURLToPath(import.meta.url));
6
+ const filePath = [
7
+ path.resolve(`${dirname}/js/standalone.js`),
8
+ path.resolve(`${dirname}/../../dist/js/standalone.js`)
9
+ ].find((file) => fs.existsSync(file));
10
+ if (filePath === void 0) {
11
+ throw new Error(`JavaScript file not found: ${path.resolve(`${dirname}/js/standalone.js`)}`);
12
+ }
13
+ return fs.readFileSync(filePath, "utf8");
21
14
  }
22
-
23
- export { getJavaScriptFile };
15
+ export {
16
+ getJavaScriptFile
17
+ };
18
+ //# sourceMappingURL=getJavaScriptFile.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/utils/getJavaScriptFile.ts"],
4
+ "sourcesContent": ["import fs from 'node:fs'\nimport path from 'node:path'\nimport { fileURLToPath } from 'node:url'\n\n/**\n * Read the JavaScript file.\n */\nexport function getJavaScriptFile() {\n // Get the directory name\n const dirname = path.dirname(fileURLToPath(import.meta.url))\n\n // Find the JavaScript file\n const filePath = [\n path.resolve(`${dirname}/js/standalone.js`),\n path.resolve(`${dirname}/../../dist/js/standalone.js`),\n ].find((file: string) => fs.existsSync(file))\n\n // Throw an error if the file is not found\n if (filePath === undefined) {\n throw new Error(`JavaScript file not found: ${path.resolve(`${dirname}/js/standalone.js`)}`)\n }\n\n return fs.readFileSync(filePath, 'utf8')\n}\n"],
5
+ "mappings": "AAAA,OAAO,QAAQ;AACf,OAAO,UAAU;AACjB,SAAS,qBAAqB;AAKvB,SAAS,oBAAoB;AAElC,QAAM,UAAU,KAAK,QAAQ,cAAc,YAAY,GAAG,CAAC;AAG3D,QAAM,WAAW;AAAA,IACf,KAAK,QAAQ,GAAG,OAAO,mBAAmB;AAAA,IAC1C,KAAK,QAAQ,GAAG,OAAO,8BAA8B;AAAA,EACvD,EAAE,KAAK,CAAC,SAAiB,GAAG,WAAW,IAAI,CAAC;AAG5C,MAAI,aAAa,QAAW;AAC1B,UAAM,IAAI,MAAM,8BAA8B,KAAK,QAAQ,GAAG,OAAO,mBAAmB,CAAC,EAAE;AAAA,EAC7F;AAEA,SAAO,GAAG,aAAa,UAAU,MAAM;AACzC;",
6
+ "names": []
7
+ }
package/package.json CHANGED
@@ -17,7 +17,7 @@
17
17
  "openapi",
18
18
  "swagger"
19
19
  ],
20
- "version": "1.31.2",
20
+ "version": "1.31.3",
21
21
  "engines": {
22
22
  "node": ">=20"
23
23
  },
@@ -40,9 +40,9 @@
40
40
  "fastify-plugin": "^4.5.1",
41
41
  "github-slugger": "^2.0.0",
42
42
  "@scalar/core": "0.3.1",
43
- "@scalar/openapi-parser": "0.13.0",
44
43
  "@scalar/openapi-types": "0.3.1",
45
- "@scalar/types": "0.2.1"
44
+ "@scalar/types": "0.2.1",
45
+ "@scalar/openapi-parser": "0.14.0"
46
46
  },
47
47
  "devDependencies": {
48
48
  "@fastify/basic-auth": "^5.1.1",
@@ -57,11 +57,11 @@
57
57
  "vite-plugin-static-copy": "^1.0.2",
58
58
  "vitest": "^1.6.0",
59
59
  "yaml": "^2.4.5",
60
- "@scalar/api-reference": "1.31.2",
60
+ "@scalar/api-reference": "1.31.3",
61
61
  "@scalar/build-tooling": "0.2.1"
62
62
  },
63
63
  "scripts": {
64
- "build": "scalar-build-rollup && pnpm copy:standalone",
64
+ "build": "scalar-build-esbuild && pnpm copy:standalone",
65
65
  "build:playground": "cd playground && pnpm build",
66
66
  "copy:standalone": "shx mkdir -p ./dist/js && shx cp ../../packages/api-reference/dist/browser/standalone.js ./dist/js/standalone.js",
67
67
  "dev:doesnt-work": "cd playground && pnpm dev",
@@ -1,130 +0,0 @@
1
- /**
2
- * Helper function to add consistent indentation to multiline strings
3
- * @param str The string to indent
4
- * @param spaces Number of spaces for each level
5
- * @param initialIndent Whether to indent the first line
6
- */
7
- const addIndent = (str, spaces = 2, initialIndent = false) => {
8
- const indent = ' '.repeat(spaces);
9
- const lines = str.split('\n');
10
- return lines
11
- .map((line, index) => {
12
- if (index === 0 && !initialIndent) {
13
- return line;
14
- }
15
- return `${indent}${line}`;
16
- })
17
- .join('\n');
18
- };
19
- /**
20
- * Generate the style tag with custom theme if needed
21
- */
22
- const getStyles = (configuration, customTheme) => {
23
- const styles = [];
24
- if (configuration.customCss) {
25
- styles.push('/* Custom CSS */');
26
- styles.push(configuration.customCss);
27
- }
28
- if (!configuration.theme && customTheme) {
29
- styles.push('/* Custom Theme */');
30
- styles.push(customTheme);
31
- }
32
- if (styles.length === 0) {
33
- return '';
34
- }
35
- return `
36
- <style type="text/css">
37
- ${addIndent(styles.join('\n\n'), 6)}
38
- </style>`;
39
- };
40
- /**
41
- * The HTML document to render the Scalar API reference.
42
- *
43
- * We must check the passed in configuration and not the configuration for the theme as the configuration will have it
44
- * defaulted to 'default'
45
- */
46
- const getHtmlDocument = (givenConfiguration, customTheme = '') => {
47
- const { cdn, pageTitle, customCss, theme, ...rest } = givenConfiguration;
48
- const configuration = getConfiguration({
49
- ...rest,
50
- ...(theme ? { theme } : {}),
51
- customCss,
52
- });
53
- const content = `<!doctype html>
54
- <html>
55
- <head>
56
- <title>${pageTitle ?? 'Scalar API Reference'}</title>
57
- <meta charset="utf-8" />
58
- <meta
59
- name="viewport"
60
- content="width=device-width, initial-scale=1" />${getStyles(configuration, customTheme)}
61
- </head>
62
- <body>
63
- <div id="app"></div>${getScriptTags(configuration, cdn)}
64
- </body>
65
- </html>`;
66
- return content;
67
- };
68
- /**
69
- * The script tags to load the @scalar/api-reference package from the CDN.
70
- */
71
- function getScriptTags(configuration, cdn) {
72
- // Extract function properties before stringifying
73
- const { tagsSorter, operationsSorter, generateHeadingSlug, generateModelSlug, generateTagSlug, generateOperationSlug, generateWebhookSlug, onLoaded, redirect, onSpecUpdate, onServerChange, ...restConfig } = configuration;
74
- // Create the function strings if they exist
75
- const functionProps = [];
76
- const functionProperties = [
77
- { name: 'tagsSorter', value: tagsSorter },
78
- { name: 'operationsSorter', value: operationsSorter },
79
- { name: 'generateHeadingSlug', value: generateHeadingSlug },
80
- { name: 'generateModelSlug', value: generateModelSlug },
81
- { name: 'generateTagSlug', value: generateTagSlug },
82
- { name: 'generateOperationSlug', value: generateOperationSlug },
83
- { name: 'generateWebhookSlug', value: generateWebhookSlug },
84
- { name: 'onLoaded', value: onLoaded },
85
- { name: 'redirect', value: redirect },
86
- { name: 'onSpecUpdate', value: onSpecUpdate },
87
- { name: 'onServerChange', value: onServerChange },
88
- ];
89
- functionProperties.forEach(({ name, value }) => {
90
- if (value && typeof value === 'function') {
91
- functionProps.push(`"${name}": ${value.toString()}`);
92
- }
93
- });
94
- // Stringify the rest of the configuration
95
- const configString = JSON.stringify(restConfig, null, 2)
96
- .split('\n')
97
- .map((line, index) => (index === 0 ? line : ' ' + line))
98
- .join('\n')
99
- .replace(/\s*}$/, ''); // Remove the closing brace and any whitespace before it
100
- const functionPropsString = functionProps.length ? `,\n ${functionProps.join(',\n ')}\n }` : '}';
101
- return `
102
- <!-- Load the Script -->
103
- <script src="${cdn ?? 'https://cdn.jsdelivr.net/npm/@scalar/api-reference'}"></script>
104
-
105
- <!-- Initialize the Scalar API Reference -->
106
- <script type="text/javascript">
107
- Scalar.createApiReference('#app', ${configString}${functionPropsString})
108
- </script>`;
109
- }
110
- /**
111
- * The configuration to pass to the @scalar/api-reference package.
112
- */
113
- const getConfiguration = (givenConfiguration) => {
114
- // Clone the given configuration
115
- const configuration = {
116
- ...givenConfiguration,
117
- };
118
- // Execute content if it's a function
119
- if (typeof configuration.content === 'function') {
120
- configuration.content = configuration.content();
121
- }
122
- // Only remove content if url is provided
123
- if (configuration.content && configuration.url) {
124
- delete configuration.content;
125
- }
126
- // Just return regular JSON string, no HTML escaping needed
127
- return configuration;
128
- };
129
-
130
- export { getConfiguration, getHtmlDocument, getScriptTags };