@scalar/fastify-api-reference 0.7.2 → 0.7.4

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/CHANGELOG.md CHANGED
@@ -1,5 +1,21 @@
1
1
  # @scalar/fastify-api-reference
2
2
 
3
+ ## 0.7.4
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies [b65840b]
8
+ - Updated dependencies [95fbc01]
9
+ - Updated dependencies [b65840b]
10
+ - Updated dependencies [b974eeb]
11
+ - @scalar/api-reference@1.4.0
12
+
13
+ ## 0.7.3
14
+
15
+ ### Patch Changes
16
+
17
+ - 2bfab93: fix: JS is missing
18
+
3
19
  ## 0.7.2
4
20
 
5
21
  ### Patch Changes
@@ -1 +1 @@
1
- {"version":3,"file":"fastifyApiReference.d.ts","sourceRoot":"","sources":["../src/fastifyApiReference.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,sBAAsB,EAAE,MAAM,uBAAuB,CAAA;AACnE,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAA;AAKjD,MAAM,MAAM,0BAA0B,GAAG;IACvC;;;;OAIG;IACH,WAAW,EAAE,MAAM,CAAA;IACnB,aAAa,CAAC,EAAE,sBAAsB,CAAA;CACvC,CAAA;AAQD;;GAEG;AACH,eAAO,MAAM,UAAU,i8EA+EtB,CAAA;AAED;;GAEG;AACH,eAAO,MAAM,UAAU,kBAAmB,sBAAsB,WAgB/D,CAAA;AAED;;GAEG;AACH,wBAAgB,YAAY,CAAC,aAAa,EAAE,sBAAsB,UAqBjE;;AA4FD,wBAAsC"}
1
+ {"version":3,"file":"fastifyApiReference.d.ts","sourceRoot":"","sources":["../src/fastifyApiReference.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,sBAAsB,EAAE,MAAM,uBAAuB,CAAA;AACnE,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAA;AAKjD,MAAM,MAAM,0BAA0B,GAAG;IACvC;;;;OAIG;IACH,WAAW,EAAE,MAAM,CAAA;IACnB,aAAa,CAAC,EAAE,sBAAsB,CAAA;CACvC,CAAA;AAQD;;GAEG;AACH,eAAO,MAAM,UAAU,i8EA+EtB,CAAA;AAED;;GAEG;AACH,eAAO,MAAM,UAAU,kBAAmB,sBAAsB,WAgB/D,CAAA;AAED;;GAEG;AACH,wBAAgB,YAAY,CAAC,aAAa,EAAE,sBAAsB,UAqBjE;;AA8ED,wBAAsC"}
package/dist/index.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";const e=require("fastify-plugin"),n=require("node:fs"),t=require("node:path"),o={hide:!0};function r(e){return`\n<!DOCTYPE html>\n<html>\n <head>\n <title>API Reference</title>\n <meta charset="utf-8" />\n <meta\n name="viewport"\n content="width=device-width, initial-scale=1" />\n <style>\n body {\n margin: 0;\n }\n </style>\n </head>\n <body>\n ${(e=>{var n,t,o,r;return`\n <script\n id="api-reference"\n type="application/json"\n data-configuration="${JSON.stringify(e).split('"').join("&quot;")}">${(null==(n=e.spec)?void 0:n.content)?"function"==typeof(null==(t=e.spec)?void 0:t.content)?JSON.stringify(null==(o=e.spec)?void 0:o.content()):JSON.stringify(null==(r=e.spec)?void 0:r.content):""}<\/script>\n <script src="/@scalar/fastify-api-reference/browser.js"><\/script>\n `})(e)}\n </body>\n</html>\n`}const c=e((async(e,c)=>{var a,l;let{configuration:s}=c;const h=e.hasPlugin("@fastify/swagger");(null==(a=null==s?void 0:s.spec)?void 0:a.content)||(null==(l=null==s?void 0:s.spec)?void 0:l.url)||h?(e.route({method:"GET",url:c.routePrefix??"/",schema:o,async handler(n,t){var o,c;t.header("Content-Type","text/html; charset=utf-8"),(null==(o=null==s?void 0:s.spec)?void 0:o.content)||(null==(c=null==s?void 0:s.spec)?void 0:c.url)||!h||(s={...s,spec:{content:()=>e.swagger()}}),(null==s?void 0:s.customCss)||(null==s?void 0:s.theme)||(s={...s,customCss:"\n:root {\n --theme-font: 'Inter', var(--system-fonts);\n}\n\n.light-mode {\n color-scheme: light;\n --theme-color-1: #1c1e21;\n --theme-color-2: #757575;\n --theme-color-3: #8e8e8e;\n --theme-color-disabled: #b4b1b1;\n --theme-color-ghost: #a7a7a7;\n --theme-color-accent: #2f8555;\n --theme-background-1: #fff;\n --theme-background-2: #f5f5f5;\n --theme-background-3: #ededed;\n --theme-background-4: rgba(0, 0, 0, 0.06);\n --theme-background-accent: #2f85551f;\n\n --theme-border-color: rgba(0, 0, 0, 0.1);\n --theme-scrollbar-color: rgba(0, 0, 0, 0.18);\n --theme-scrollbar-color-active: rgba(0, 0, 0, 0.36);\n --theme-lifted-brightness: 1;\n --theme-backdrop-brightness: 1;\n\n --theme-shadow-1: 0 1px 3px 0 rgba(0, 0, 0, 0.11);\n --theme-shadow-2: rgba(0, 0, 0, 0.08) 0px 13px 20px 0px,\n rgba(0, 0, 0, 0.08) 0px 3px 8px 0px, #eeeeed 0px 0 0 1px;\n\n --theme-button-1: rgb(49 53 56);\n --theme-button-1-color: #fff;\n --theme-button-1-hover: rgb(28 31 33);\n\n --theme-color-green: #007300;\n --theme-color-red: #af272b;\n --theme-color-yellow: #b38200;\n --theme-color-blue: #3b8ba5;\n --theme-color-orange: #fb892c;\n --theme-color-purple: #5203d1;\n}\n\n.dark-mode {\n color-scheme: dark;\n --theme-color-1: rgba(255, 255, 255, 0.9);\n --theme-color-2: rgba(255, 255, 255, 0.62);\n --theme-color-3: rgba(255, 255, 255, 0.44);\n --theme-color-disabled: rgba(255, 255, 255, 0.34);\n --theme-color-ghost: rgba(255, 255, 255, 0.26);\n --theme-color-accent: #27c2a0;\n --theme-background-1: #1b1b1d;\n --theme-background-2: #242526;\n --theme-background-3: #3b3b3b;\n --theme-background-4: rgba(255, 255, 255, 0.06);\n --theme-background-accent: #27c2a01f;\n\n --theme-border-color: rgba(255, 255, 255, 0.1);\n --theme-scrollbar-color: rgba(255, 255, 255, 0.24);\n --theme-scrollbar-color-active: rgba(255, 255, 255, 0.48);\n --theme-lifted-brightness: 1.45;\n --theme-backdrop-brightness: 0.5;\n\n --theme-shadow-1: 0 1px 3px 0 rgb(0, 0, 0, 0.1);\n --theme-shadow-2: rgba(15, 15, 15, 0.2) 0px 3px 6px,\n rgba(15, 15, 15, 0.4) 0px 9px 24px, 0 0 0 1px rgba(255, 255, 255, 0.1);\n\n --theme-button-1: #f6f6f6;\n --theme-button-1-color: #000;\n --theme-button-1-hover: #e7e7e7;\n\n --theme-color-green: #26b226;\n --theme-color-red: #fb565b;\n --theme-color-yellow: #ffc426;\n --theme-color-blue: #6ecfef;\n --theme-color-orange: #ff8d4d;\n --theme-color-purple: #b191f9;\n}\n.scalar-card:nth-of-type(3) {\n display: none;\n}\n"});const a=r(s);t.send(a)}}),e.route({method:"GET",url:"/@scalar/fastify-api-reference/browser.js",schema:o,async handler(e,o){o.header("Content-Type","application/javascript; charset=utf-8");const r=t.join(__dirname,"../","node_modules","@scalar/api-reference","dist/browser/standalone.js"),c=n.readFileSync(r,"utf8");o.send(c)}})):console.warn("[@scalar/fastify-api-reference] You didn’t provide a spec.content or spec.url and @fastify/swagger could not be find either. Please provide one of these options.")}));module.exports=c;
1
+ "use strict";const e=require("fastify-plugin"),n=require("node:fs"),t=require("node:path");const o={hide:!0};function r(e){return`\n<!DOCTYPE html>\n<html>\n <head>\n <title>API Reference</title>\n <meta charset="utf-8" />\n <meta\n name="viewport"\n content="width=device-width, initial-scale=1" />\n <style>\n body {\n margin: 0;\n }\n </style>\n </head>\n <body>\n ${(e=>{var n,t,o,r;return`\n <script\n id="api-reference"\n type="application/json"\n data-configuration="${JSON.stringify(e).split('"').join("&quot;")}">${(null==(n=e.spec)?void 0:n.content)?"function"==typeof(null==(t=e.spec)?void 0:t.content)?JSON.stringify(null==(o=e.spec)?void 0:o.content()):JSON.stringify(null==(r=e.spec)?void 0:r.content):""}<\/script>\n <script src="/@scalar/fastify-api-reference/browser.js"><\/script>\n `})(e)}\n </body>\n</html>\n`}const c=e((async(e,c)=>{var a,l;let{configuration:s}=c;const i=e.hasPlugin("@fastify/swagger");if(!(null==(a=null==s?void 0:s.spec)?void 0:a.content)&&!(null==(l=null==s?void 0:s.spec)?void 0:l.url)&&!i)return void console.warn("[@scalar/fastify-api-reference] You didn’t provide a spec.content or spec.url and @fastify/swagger could not be find either. Please provide one of these options.");const h=function(){const e=[t.resolve(`${__dirname}/js/standalone.js`),t.resolve(`${__dirname}/../../dist/js/standalone.js`)].find((e=>n.existsSync(e)));if(void 0===e)throw new Error(`JavaScript file not found: ${t.resolve(`${__dirname}/js/standalone.js`)}`);return n.readFileSync(e,"utf8")}();e.route({method:"GET",url:c.routePrefix??"/",schema:o,async handler(n,t){var o,c;t.header("Content-Type","text/html; charset=utf-8"),(null==(o=null==s?void 0:s.spec)?void 0:o.content)||(null==(c=null==s?void 0:s.spec)?void 0:c.url)||!i||(s={...s,spec:{content:()=>e.swagger()}}),(null==s?void 0:s.customCss)||(null==s?void 0:s.theme)||(s={...s,customCss:"\n:root {\n --theme-font: 'Inter', var(--system-fonts);\n}\n\n.light-mode {\n color-scheme: light;\n --theme-color-1: #1c1e21;\n --theme-color-2: #757575;\n --theme-color-3: #8e8e8e;\n --theme-color-disabled: #b4b1b1;\n --theme-color-ghost: #a7a7a7;\n --theme-color-accent: #2f8555;\n --theme-background-1: #fff;\n --theme-background-2: #f5f5f5;\n --theme-background-3: #ededed;\n --theme-background-4: rgba(0, 0, 0, 0.06);\n --theme-background-accent: #2f85551f;\n\n --theme-border-color: rgba(0, 0, 0, 0.1);\n --theme-scrollbar-color: rgba(0, 0, 0, 0.18);\n --theme-scrollbar-color-active: rgba(0, 0, 0, 0.36);\n --theme-lifted-brightness: 1;\n --theme-backdrop-brightness: 1;\n\n --theme-shadow-1: 0 1px 3px 0 rgba(0, 0, 0, 0.11);\n --theme-shadow-2: rgba(0, 0, 0, 0.08) 0px 13px 20px 0px,\n rgba(0, 0, 0, 0.08) 0px 3px 8px 0px, #eeeeed 0px 0 0 1px;\n\n --theme-button-1: rgb(49 53 56);\n --theme-button-1-color: #fff;\n --theme-button-1-hover: rgb(28 31 33);\n\n --theme-color-green: #007300;\n --theme-color-red: #af272b;\n --theme-color-yellow: #b38200;\n --theme-color-blue: #3b8ba5;\n --theme-color-orange: #fb892c;\n --theme-color-purple: #5203d1;\n}\n\n.dark-mode {\n color-scheme: dark;\n --theme-color-1: rgba(255, 255, 255, 0.9);\n --theme-color-2: rgba(255, 255, 255, 0.62);\n --theme-color-3: rgba(255, 255, 255, 0.44);\n --theme-color-disabled: rgba(255, 255, 255, 0.34);\n --theme-color-ghost: rgba(255, 255, 255, 0.26);\n --theme-color-accent: #27c2a0;\n --theme-background-1: #1b1b1d;\n --theme-background-2: #242526;\n --theme-background-3: #3b3b3b;\n --theme-background-4: rgba(255, 255, 255, 0.06);\n --theme-background-accent: #27c2a01f;\n\n --theme-border-color: rgba(255, 255, 255, 0.1);\n --theme-scrollbar-color: rgba(255, 255, 255, 0.24);\n --theme-scrollbar-color-active: rgba(255, 255, 255, 0.48);\n --theme-lifted-brightness: 1.45;\n --theme-backdrop-brightness: 0.5;\n\n --theme-shadow-1: 0 1px 3px 0 rgb(0, 0, 0, 0.1);\n --theme-shadow-2: rgba(15, 15, 15, 0.2) 0px 3px 6px,\n rgba(15, 15, 15, 0.4) 0px 9px 24px, 0 0 0 1px rgba(255, 255, 255, 0.1);\n\n --theme-button-1: #f6f6f6;\n --theme-button-1-color: #000;\n --theme-button-1-hover: #e7e7e7;\n\n --theme-color-green: #26b226;\n --theme-color-red: #fb565b;\n --theme-color-yellow: #ffc426;\n --theme-color-blue: #6ecfef;\n --theme-color-orange: #ff8d4d;\n --theme-color-purple: #b191f9;\n}\n.scalar-card:nth-of-type(3) {\n display: none;\n}\n"});const a=r(s);t.send(a)}}),e.route({method:"GET",url:"/@scalar/fastify-api-reference/browser.js",schema:o,async handler(e,n){n.header("Content-Type","application/javascript; charset=utf-8"),n.send(h)}})}));module.exports=c;
package/dist/index.js CHANGED
@@ -10,6 +10,20 @@ const require2 = __createRequire(import.meta.url);
10
10
  import fp from "fastify-plugin";
11
11
  import fs from "node:fs";
12
12
  import path from "node:path";
13
+ function getJavaScriptFile() {
14
+ const filePath = [
15
+ path.resolve(`${__dirname}/js/standalone.js`),
16
+ path.resolve(`${__dirname}/../../dist/js/standalone.js`)
17
+ ].find((file) => fs.existsSync(file));
18
+ if (filePath === void 0) {
19
+ throw new Error(
20
+ `JavaScript file not found: ${path.resolve(
21
+ `${__dirname}/js/standalone.js`
22
+ )}`
23
+ );
24
+ }
25
+ return fs.readFileSync(filePath, "utf8");
26
+ }
13
27
  const schemaToHideRoute = {
14
28
  hide: true
15
29
  };
@@ -135,6 +149,7 @@ const fastifyApiReference = async (fastify, options) => {
135
149
  );
136
150
  return;
137
151
  }
152
+ const fileContent = getJavaScriptFile();
138
153
  fastify.route({
139
154
  method: "GET",
140
155
  url: options.routePrefix ?? "/",
@@ -172,16 +187,6 @@ const fastifyApiReference = async (fastify, options) => {
172
187
  schema: schemaToHideRoute,
173
188
  async handler(_, reply) {
174
189
  reply.header("Content-Type", "application/javascript; charset=utf-8");
175
- const packageName = "@scalar/api-reference";
176
- const jsFilePath = "dist/browser/standalone.js";
177
- const filePath = path.join(
178
- __dirname,
179
- "../",
180
- "node_modules",
181
- packageName,
182
- jsFilePath
183
- );
184
- const fileContent = fs.readFileSync(filePath, "utf8");
185
190
  reply.send(fileContent);
186
191
  }
187
192
  });