@scalar/fastify-api-reference 1.24.73 → 1.24.75
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 +8 -0
- package/dist/fastifyApiReference.d.ts +9 -1
- package/dist/fastifyApiReference.d.ts.map +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.js +12 -0
- package/dist/js/standalone.js +12564 -12621
- package/package.json +3 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { ReferenceConfiguration } from '@scalar/api-reference';
|
|
2
|
-
import type { FastifyBaseLogger, FastifyTypeProviderDefault, RawServerDefault } from 'fastify';
|
|
2
|
+
import type { FastifyBaseLogger, FastifyTypeProviderDefault, RawServerDefault, onRequestHookHandler, preHandlerHookHandler } from 'fastify';
|
|
3
3
|
export type FastifyApiReferenceOptions = {
|
|
4
4
|
/**
|
|
5
5
|
* If you’re prefixing Fastify with a path, you can set it here.
|
|
@@ -20,7 +20,15 @@ export type FastifyApiReferenceOptions = {
|
|
|
20
20
|
* Read more: https://github.com/scalar/scalar
|
|
21
21
|
*/
|
|
22
22
|
configuration?: ReferenceConfiguration;
|
|
23
|
+
/**
|
|
24
|
+
* The hooks for the API Reference.
|
|
25
|
+
*/
|
|
26
|
+
hooks?: FastifyApiReferenceHooksOptions;
|
|
23
27
|
};
|
|
28
|
+
export type FastifyApiReferenceHooksOptions = Partial<{
|
|
29
|
+
onRequest?: onRequestHookHandler;
|
|
30
|
+
preHandler?: preHandlerHookHandler;
|
|
31
|
+
}>;
|
|
24
32
|
/**
|
|
25
33
|
* The Fastify custom theme CSS
|
|
26
34
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fastifyApiReference.d.ts","sourceRoot":"","sources":["../src/fastifyApiReference.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,uBAAuB,CAAA;AACnE,OAAO,KAAK,EACV,iBAAiB,EACjB,0BAA0B,EAC1B,gBAAgB,
|
|
1
|
+
{"version":3,"file":"fastifyApiReference.d.ts","sourceRoot":"","sources":["../src/fastifyApiReference.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,uBAAuB,CAAA;AACnE,OAAO,KAAK,EACV,iBAAiB,EACjB,0BAA0B,EAC1B,gBAAgB,EAChB,oBAAoB,EACpB,qBAAqB,EACtB,MAAM,SAAS,CAAA;AAKhB,MAAM,MAAM,0BAA0B,GAAG;IACvC;;;;;OAKG;IACH,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB;;;;OAIG;IACH,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB;;;;OAIG;IACH,aAAa,CAAC,EAAE,sBAAsB,CAAA;IACtC;;OAEG;IACH,KAAK,CAAC,EAAE,+BAA+B,CAAA;CACxC,CAAA;AAED,MAAM,MAAM,+BAA+B,GAAG,OAAO,CAAC;IACpD,SAAS,CAAC,EAAE,oBAAoB,CAAA;IAChC,UAAU,CAAC,EAAE,qBAAqB,CAAA;CACnC,CAAC,CAAA;AAcF;;GAEG;AACH,eAAO,MAAM,UAAU,s4EAwEtB,CAAA;AAED;;GAEG;AACH,eAAO,MAAM,UAAU,YAAa,0BAA0B,WAkB7D,CAAA;AAED;;GAEG;AACH,wBAAgB,YAAY,CAAC,OAAO,EAAE,0BAA0B,UAgB/D;AAED,QAAA,MAAM,mBAAmB,sIA+FxB,CAAA;AAED,eAAe,mBAAmB,CAAA"}
|
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";const r=require("fastify-plugin"),n=require("node:fs"),a=require("node:path"),e=require("node:url");var o="undefined"!=typeof document?document.currentScript:null;const c={hide:!0},l=(r,n)=>`${n??""}${r??"/reference"}/@scalar/fastify-api-reference/js/browser.js`.replace(/\/\//g,"/");function s(r){return`\n<!DOCTYPE html>\n<html>\n <head>\n <title>Scalar API Reference</title>\n <meta charset="utf-8" />\n <meta\n name="viewport"\n content="width=device-width, initial-scale=1" />\n </head>\n <body>\n ${(r=>{var n,a,e,o;const{configuration:c}=r;return`\n <script\n id="api-reference"\n type="application/json"\n data-configuration="${JSON.stringify(c??{}).split('"').join(""")}">${(null==(n=null==c?void 0:c.spec)?void 0:n.content)?"function"==typeof(null==(a=null==c?void 0:c.spec)?void 0:a.content)?JSON.stringify(null==(e=null==c?void 0:c.spec)?void 0:e.content()):JSON.stringify(null==(o=null==c?void 0:c.spec)?void 0:o.content):""}<\/script>\n <script src="${l(r.routePrefix,r.publicPath)}"><\/script>\n `})(r)}\n </body>\n</html>\n`}const t=r((async(r,t)=>{var i,d;let{configuration:u}=t;const f=r.hasPlugin("@fastify/swagger");if(!(null==(i=null==u?void 0:u.spec)?void 0:i.content)&&!(null==(d=null==u?void 0:u.spec)?void 0:d.url)&&!f)return void r.log.warn("[@scalar/fastify-api-reference] You didn’t provide a spec.content or spec.url, and @fastify/swagger could not be found. Please provide one of these options.");const b=function(){const r=a.dirname(e.fileURLToPath("undefined"==typeof document?require("url").pathToFileURL(__filename).href:o&&o.src||new URL("index.cjs",document.baseURI).href)),c=[a.resolve(`${r}/js/standalone.js`),a.resolve(`${r}/../../dist/js/standalone.js`)].find((r=>n.existsSync(r)));if(void 0===c)throw new Error(`JavaScript file not found: ${a.resolve(`${r}/js/standalone.js`)}`);return n.readFileSync(c,"utf8")}();r.route({method:"GET",url:t.routePrefix??"/reference",schema:c,handler(n,a){var e,o;return(null==(e=null==u?void 0:u.spec)?void 0:e.content)||(null==(o=null==u?void 0:u.spec)?void 0:o.url)||!f||(u={...u,spec:{content:()=>r.swagger()}}),(null==u?void 0:u.customCss)||(null==u?void 0:u.theme)||(u={...u,customCss:"\n.light-mode {\n color-scheme: light;\n --scalar-color-1: #1c1e21;\n --scalar-color-2: #757575;\n --scalar-color-3: #8e8e8e;\n --scalar-color-disabled: #b4b1b1;\n --scalar-color-ghost: #a7a7a7;\n --scalar-color-accent: #2f8555;\n --scalar-background-1: #fff;\n --scalar-background-2: #f5f5f5;\n --scalar-background-3: #ededed;\n --scalar-background-4: rgba(0, 0, 0, 0.06);\n --scalar-background-accent: #2f85551f;\n\n --scalar-border-color: rgba(0, 0, 0, 0.1);\n --scalar-scrollbar-color: rgba(0, 0, 0, 0.18);\n --scalar-scrollbar-color-active: rgba(0, 0, 0, 0.36);\n --scalar-lifted-brightness: 1;\n --scalar-backdrop-brightness: 1;\n\n --scalar-shadow-1: 0 1px 3px 0 rgba(0, 0, 0, 0.11);\n --scalar-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 --scalar-button-1: rgb(49 53 56);\n --scalar-button-1-color: #fff;\n --scalar-button-1-hover: rgb(28 31 33);\n\n --scalar-color-green: #007300;\n --scalar-color-red: #af272b;\n --scalar-color-yellow: #b38200;\n --scalar-color-blue: #3b8ba5;\n --scalar-color-orange: #fb892c;\n --scalar-color-purple: #5203d1;\n}\n\n.dark-mode {\n color-scheme: dark;\n --scalar-color-1: rgba(255, 255, 255, 0.9);\n --scalar-color-2: rgba(255, 255, 255, 0.62);\n --scalar-color-3: rgba(255, 255, 255, 0.44);\n --scalar-color-disabled: rgba(255, 255, 255, 0.34);\n --scalar-color-ghost: rgba(255, 255, 255, 0.26);\n --scalar-color-accent: #27c2a0;\n --scalar-background-1: #1b1b1d;\n --scalar-background-2: #242526;\n --scalar-background-3: #3b3b3b;\n --scalar-background-4: rgba(255, 255, 255, 0.06);\n --scalar-background-accent: #27c2a01f;\n\n --scalar-border-color: rgba(255, 255, 255, 0.1);\n --scalar-scrollbar-color: rgba(255, 255, 255, 0.24);\n --scalar-scrollbar-color-active: rgba(255, 255, 255, 0.48);\n --scalar-lifted-brightness: 1.45;\n --scalar-backdrop-brightness: 0.5;\n\n --scalar-shadow-1: 0 1px 3px 0 rgb(0, 0, 0, 0.1);\n --scalar-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 --scalar-button-1: #f6f6f6;\n --scalar-button-1-color: #000;\n --scalar-button-1-hover: #e7e7e7;\n\n --scalar-color-green: #26b226;\n --scalar-color-red: #fb565b;\n --scalar-color-yellow: #ffc426;\n --scalar-color-blue: #6ecfef;\n --scalar-color-orange: #ff8d4d;\n --scalar-color-purple: #b191f9;\n}\n"}),a.header("Content-Type","text/html; charset=utf-8").send(s({...t,configuration:u}))}}),r.route({method:"GET",url:l(t.routePrefix),schema:c,handler:(r,n)=>n.header("Content-Type","application/javascript; charset=utf-8").send(b)})}),{name:"@scalar/fastify-api-reference"});module.exports=t;
|
|
1
|
+
"use strict";const r=require("fastify-plugin"),n=require("node:fs"),a=require("node:path"),e=require("node:url");var o="undefined"!=typeof document?document.currentScript:null;const c={hide:!0},l=(r,n)=>`${n??""}${r??"/reference"}/@scalar/fastify-api-reference/js/browser.js`.replace(/\/\//g,"/");function s(r){return`\n<!DOCTYPE html>\n<html>\n <head>\n <title>Scalar API Reference</title>\n <meta charset="utf-8" />\n <meta\n name="viewport"\n content="width=device-width, initial-scale=1" />\n </head>\n <body>\n ${(r=>{var n,a,e,o;const{configuration:c}=r;return`\n <script\n id="api-reference"\n type="application/json"\n data-configuration="${JSON.stringify(c??{}).split('"').join(""")}">${(null==(n=null==c?void 0:c.spec)?void 0:n.content)?"function"==typeof(null==(a=null==c?void 0:c.spec)?void 0:a.content)?JSON.stringify(null==(e=null==c?void 0:c.spec)?void 0:e.content()):JSON.stringify(null==(o=null==c?void 0:c.spec)?void 0:o.content):""}<\/script>\n <script src="${l(r.routePrefix,r.publicPath)}"><\/script>\n `})(r)}\n </body>\n</html>\n`}const t=r((async(r,t)=>{var i,d;let{configuration:u}=t;const f=r.hasPlugin("@fastify/swagger");if(!(null==(i=null==u?void 0:u.spec)?void 0:i.content)&&!(null==(d=null==u?void 0:u.spec)?void 0:d.url)&&!f)return void r.log.warn("[@scalar/fastify-api-reference] You didn’t provide a spec.content or spec.url, and @fastify/swagger could not be found. Please provide one of these options.");const b=function(){const r=a.dirname(e.fileURLToPath("undefined"==typeof document?require("url").pathToFileURL(__filename).href:o&&o.src||new URL("index.cjs",document.baseURI).href)),c=[a.resolve(`${r}/js/standalone.js`),a.resolve(`${r}/../../dist/js/standalone.js`)].find((r=>n.existsSync(r)));if(void 0===c)throw new Error(`JavaScript file not found: ${a.resolve(`${r}/js/standalone.js`)}`);return n.readFileSync(c,"utf8")}(),p={};if(t.hooks){const r=["onRequest","preHandler"];for(const n of r)p[n]=t.hooks[n]}r.route({method:"GET",url:t.routePrefix??"/reference",schema:c,...p,handler(n,a){var e,o;return(null==(e=null==u?void 0:u.spec)?void 0:e.content)||(null==(o=null==u?void 0:u.spec)?void 0:o.url)||!f||(u={...u,spec:{content:()=>r.swagger()}}),(null==u?void 0:u.customCss)||(null==u?void 0:u.theme)||(u={...u,customCss:"\n.light-mode {\n color-scheme: light;\n --scalar-color-1: #1c1e21;\n --scalar-color-2: #757575;\n --scalar-color-3: #8e8e8e;\n --scalar-color-disabled: #b4b1b1;\n --scalar-color-ghost: #a7a7a7;\n --scalar-color-accent: #2f8555;\n --scalar-background-1: #fff;\n --scalar-background-2: #f5f5f5;\n --scalar-background-3: #ededed;\n --scalar-background-4: rgba(0, 0, 0, 0.06);\n --scalar-background-accent: #2f85551f;\n\n --scalar-border-color: rgba(0, 0, 0, 0.1);\n --scalar-scrollbar-color: rgba(0, 0, 0, 0.18);\n --scalar-scrollbar-color-active: rgba(0, 0, 0, 0.36);\n --scalar-lifted-brightness: 1;\n --scalar-backdrop-brightness: 1;\n\n --scalar-shadow-1: 0 1px 3px 0 rgba(0, 0, 0, 0.11);\n --scalar-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 --scalar-button-1: rgb(49 53 56);\n --scalar-button-1-color: #fff;\n --scalar-button-1-hover: rgb(28 31 33);\n\n --scalar-color-green: #007300;\n --scalar-color-red: #af272b;\n --scalar-color-yellow: #b38200;\n --scalar-color-blue: #3b8ba5;\n --scalar-color-orange: #fb892c;\n --scalar-color-purple: #5203d1;\n}\n\n.dark-mode {\n color-scheme: dark;\n --scalar-color-1: rgba(255, 255, 255, 0.9);\n --scalar-color-2: rgba(255, 255, 255, 0.62);\n --scalar-color-3: rgba(255, 255, 255, 0.44);\n --scalar-color-disabled: rgba(255, 255, 255, 0.34);\n --scalar-color-ghost: rgba(255, 255, 255, 0.26);\n --scalar-color-accent: #27c2a0;\n --scalar-background-1: #1b1b1d;\n --scalar-background-2: #242526;\n --scalar-background-3: #3b3b3b;\n --scalar-background-4: rgba(255, 255, 255, 0.06);\n --scalar-background-accent: #27c2a01f;\n\n --scalar-border-color: rgba(255, 255, 255, 0.1);\n --scalar-scrollbar-color: rgba(255, 255, 255, 0.24);\n --scalar-scrollbar-color-active: rgba(255, 255, 255, 0.48);\n --scalar-lifted-brightness: 1.45;\n --scalar-backdrop-brightness: 0.5;\n\n --scalar-shadow-1: 0 1px 3px 0 rgb(0, 0, 0, 0.1);\n --scalar-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 --scalar-button-1: #f6f6f6;\n --scalar-button-1-color: #000;\n --scalar-button-1-hover: #e7e7e7;\n\n --scalar-color-green: #26b226;\n --scalar-color-red: #fb565b;\n --scalar-color-yellow: #ffc426;\n --scalar-color-blue: #6ecfef;\n --scalar-color-orange: #ff8d4d;\n --scalar-color-purple: #b191f9;\n}\n"}),a.header("Content-Type","text/html; charset=utf-8").send(s({...t,configuration:u}))}}),r.route({method:"GET",url:l(t.routePrefix),schema:c,...p,handler:(r,n)=>n.header("Content-Type","application/javascript; charset=utf-8").send(b)})}),{name:"@scalar/fastify-api-reference"});module.exports=t;
|
package/dist/index.js
CHANGED
|
@@ -137,12 +137,23 @@ const fastifyApiReference = fp(
|
|
|
137
137
|
return;
|
|
138
138
|
}
|
|
139
139
|
const fileContent = getJavaScriptFile();
|
|
140
|
+
const hooks = {};
|
|
141
|
+
if (options.hooks) {
|
|
142
|
+
const additionalHooks = [
|
|
143
|
+
"onRequest",
|
|
144
|
+
"preHandler"
|
|
145
|
+
];
|
|
146
|
+
for (const hook of additionalHooks) {
|
|
147
|
+
hooks[hook] = options.hooks[hook];
|
|
148
|
+
}
|
|
149
|
+
}
|
|
140
150
|
fastify.route({
|
|
141
151
|
method: "GET",
|
|
142
152
|
url: options.routePrefix ?? "/reference",
|
|
143
153
|
// We don’t know whether @fastify/swagger is registered, but it doesn’t hurt to add a schema anyway.
|
|
144
154
|
// @ts-ignore
|
|
145
155
|
schema: schemaToHideRoute,
|
|
156
|
+
...hooks,
|
|
146
157
|
handler(_, reply) {
|
|
147
158
|
var _a2, _b2;
|
|
148
159
|
if (!((_a2 = configuration == null ? void 0 : configuration.spec) == null ? void 0 : _a2.content) && !((_b2 = configuration == null ? void 0 : configuration.spec) == null ? void 0 : _b2.url) && hasSwaggerPlugin) {
|
|
@@ -170,6 +181,7 @@ const fastifyApiReference = fp(
|
|
|
170
181
|
// We don’t know whether @fastify/swagger is registered, but it doesn’t hurt to add a schema anyway.
|
|
171
182
|
// @ts-ignore
|
|
172
183
|
schema: schemaToHideRoute,
|
|
184
|
+
...hooks,
|
|
173
185
|
handler(_, reply) {
|
|
174
186
|
return reply.header("Content-Type", "application/javascript; charset=utf-8").send(fileContent);
|
|
175
187
|
}
|