@scalar/mock-server 0.6.1 → 0.7.0
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 +15 -0
- package/README.md +6 -172
- package/dist/create-mock-server.d.ts +7 -0
- package/dist/create-mock-server.d.ts.map +1 -0
- package/dist/create-mock-server.js +45 -0
- package/dist/create-mock-server.js.map +7 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/routes/{mockAnyResponse.d.ts → mock-any-response.d.ts} +3 -2
- package/dist/routes/mock-any-response.d.ts.map +1 -0
- package/dist/routes/{mockAnyResponse.js → mock-any-response.js} +16 -8
- package/dist/routes/mock-any-response.js.map +7 -0
- package/dist/routes/{respondWithAuthorizePage.d.ts → respond-with-authorize-page.d.ts} +1 -1
- package/dist/routes/respond-with-authorize-page.d.ts.map +1 -0
- package/dist/routes/{respondWithAuthorizePage.js → respond-with-authorize-page.js} +1 -1
- package/dist/routes/{respondWithAuthorizePage.js.map → respond-with-authorize-page.js.map} +1 -1
- package/dist/routes/{respondWithOpenApiDocument.d.ts → respond-with-openapi-document.d.ts} +1 -1
- package/dist/routes/respond-with-openapi-document.d.ts.map +1 -0
- package/dist/routes/{respondWithOpenApiDocument.js → respond-with-openapi-document.js} +1 -1
- package/dist/routes/{respondWithOpenApiDocument.js.map → respond-with-openapi-document.js.map} +1 -1
- package/dist/routes/{respondWithToken.d.ts → respond-with-token.d.ts} +1 -1
- package/dist/routes/respond-with-token.d.ts.map +1 -0
- package/dist/routes/{respondWithToken.js → respond-with-token.js} +1 -1
- package/dist/routes/{respondWithToken.js.map → respond-with-token.js.map} +1 -1
- package/dist/types.d.ts +18 -3
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/dist/utils/{createOpenApiDefinition.d.ts → create-openapi-definition.d.ts} +1 -1
- package/dist/utils/create-openapi-definition.d.ts.map +1 -0
- package/dist/utils/{createOpenApiDefinition.js → create-openapi-definition.js} +1 -1
- package/dist/utils/{createOpenApiDefinition.js.map → create-openapi-definition.js.map} +1 -1
- package/dist/utils/{findPreferredResponseKey.d.ts → find-preferred-response-key.d.ts} +1 -1
- package/dist/utils/find-preferred-response-key.d.ts.map +1 -0
- package/dist/utils/{findPreferredResponseKey.js → find-preferred-response-key.js} +1 -1
- package/dist/utils/{findPreferredResponseKey.js.map → find-preferred-response-key.js.map} +1 -1
- package/dist/utils/{getOpenAuthTokenUrls.d.ts → get-open-auth-token-urls.d.ts} +1 -1
- package/dist/utils/get-open-auth-token-urls.d.ts.map +1 -0
- package/dist/utils/{getOpenAuthTokenUrls.js → get-open-auth-token-urls.js} +1 -1
- package/dist/utils/{getOpenAuthTokenUrls.js.map → get-open-auth-token-urls.js.map} +1 -1
- package/dist/utils/{getOperations.d.ts → get-operation.d.ts} +1 -1
- package/dist/utils/{getOperations.d.ts.map → get-operation.d.ts.map} +1 -1
- package/dist/utils/{getOperations.js → get-operation.js} +1 -1
- package/dist/utils/{getOperations.js.map → get-operation.js.map} +1 -1
- package/dist/utils/{handleAuthentication.d.ts → handle-authentication.d.ts} +2 -2
- package/dist/utils/handle-authentication.d.ts.map +1 -0
- package/dist/utils/{handleAuthentication.js → handle-authentication.js} +1 -1
- package/dist/utils/handle-authentication.js.map +7 -0
- package/dist/utils/{honoRouteFromPath.d.ts → hono-route-from-path.d.ts} +1 -1
- package/dist/utils/hono-route-from-path.d.ts.map +1 -0
- package/dist/utils/{honoRouteFromPath.js → hono-route-from-path.js} +1 -1
- package/dist/utils/{honoRouteFromPath.js.map → hono-route-from-path.js.map} +1 -1
- package/dist/utils/{isAuthenticationRequired.d.ts → is-authentication-required.d.ts} +1 -1
- package/dist/utils/is-authentication-required.d.ts.map +1 -0
- package/dist/utils/{isAuthenticationRequired.js → is-authentication-required.js} +1 -1
- package/dist/utils/{isAuthenticationRequired.js.map → is-authentication-required.js.map} +1 -1
- package/dist/utils/{logAuthenticationInstructions.d.ts → log-authentication-instructions.d.ts} +1 -1
- package/dist/utils/log-authentication-instructions.d.ts.map +1 -0
- package/dist/utils/{logAuthenticationInstructions.js → log-authentication-instructions.js} +2 -2
- package/dist/utils/log-authentication-instructions.js.map +7 -0
- package/dist/utils/{setupAuthenticationRoutes.d.ts → set-up-authentication-routes.d.ts} +2 -2
- package/dist/utils/set-up-authentication-routes.d.ts.map +1 -0
- package/dist/utils/{setupAuthenticationRoutes.js → set-up-authentication-routes.js} +6 -6
- package/dist/utils/set-up-authentication-routes.js.map +7 -0
- package/package.json +4 -6
- package/dist/createMockServer.d.ts +0 -7
- package/dist/createMockServer.d.ts.map +0 -1
- package/dist/createMockServer.js +0 -39
- package/dist/createMockServer.js.map +0 -7
- package/dist/createMockServer.test.d.ts +0 -2
- package/dist/createMockServer.test.d.ts.map +0 -1
- package/dist/routes/mockAnyResponse.d.ts.map +0 -1
- package/dist/routes/mockAnyResponse.js.map +0 -7
- package/dist/routes/respondWithAuthorizePage.d.ts.map +0 -1
- package/dist/routes/respondWithOpenApiDocument.d.ts.map +0 -1
- package/dist/routes/respondWithToken.d.ts.map +0 -1
- package/dist/utils/createOpenApiDefinition.d.ts.map +0 -1
- package/dist/utils/findPreferredResponseKey.d.ts.map +0 -1
- package/dist/utils/findPreferredResponseKey.test.d.ts +0 -2
- package/dist/utils/findPreferredResponseKey.test.d.ts.map +0 -1
- package/dist/utils/getOpenAuthTokenUrls.d.ts.map +0 -1
- package/dist/utils/getOpenAuthTokenUrls.test.d.ts +0 -2
- package/dist/utils/getOpenAuthTokenUrls.test.d.ts.map +0 -1
- package/dist/utils/handleAuthentication.d.ts.map +0 -1
- package/dist/utils/handleAuthentication.js.map +0 -7
- package/dist/utils/honoRouteFromPath.d.ts.map +0 -1
- package/dist/utils/honoRouteFromPath.test.d.ts +0 -2
- package/dist/utils/honoRouteFromPath.test.d.ts.map +0 -1
- package/dist/utils/isAuthenticationRequired.d.ts.map +0 -1
- package/dist/utils/isAuthenticationRequired.test.d.ts +0 -2
- package/dist/utils/isAuthenticationRequired.test.d.ts.map +0 -1
- package/dist/utils/logAuthenticationInstructions.d.ts.map +0 -1
- package/dist/utils/logAuthenticationInstructions.js.map +0 -7
- package/dist/utils/setupAuthenticationRoutes.d.ts.map +0 -1
- package/dist/utils/setupAuthenticationRoutes.js.map +0 -7
|
@@ -4,4 +4,4 @@ import type { OpenAPI } from '@scalar/openapi-types';
|
|
|
4
4
|
*/
|
|
5
5
|
export declare function getPathFromUrl(url: string): string;
|
|
6
6
|
export declare function getOpenAuthTokenUrls(schema?: OpenAPI.Document): string[];
|
|
7
|
-
//# sourceMappingURL=
|
|
7
|
+
//# sourceMappingURL=get-open-auth-token-urls.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get-open-auth-token-urls.d.ts","sourceRoot":"","sources":["../../src/utils/get-open-auth-token-urls.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAA0B,MAAM,uBAAuB,CAAA;AAE5E;;GAEG;AACH,wBAAgB,cAAc,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAYlD;AAiBD,wBAAgB,oBAAoB,CAAC,MAAM,CAAC,EAAE,OAAO,CAAC,QAAQ,GAAG,MAAM,EAAE,CAgCxE"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["../../src/utils/
|
|
3
|
+
"sources": ["../../src/utils/get-open-auth-token-urls.ts"],
|
|
4
4
|
"sourcesContent": ["import type { OpenAPI, OpenAPIV3, OpenAPIV3_1 } from '@scalar/openapi-types'\n\n/**\n * Extract path from URL\n */\nexport function getPathFromUrl(url: string): string {\n try {\n // Handle relative URLs by prepending a base\n const urlObject = url.startsWith('http') ? new URL(url) : new URL(url, 'http://example.com')\n\n // Normalize: remove trailing slash except for root path\n const path = urlObject.pathname\n return path === '/' ? path : path.replace(/\\/$/, '')\n } catch {\n // If URL is invalid, return the original string\n return url\n }\n}\n\n/**\n * Returns all token URLs mentioned in the securitySchemes, without the domain\n */\n// Type guard for OAuth2 security scheme\nfunction isOAuth2Scheme(\n scheme: OpenAPIV3.SecuritySchemeObject | OpenAPIV3_1.SecuritySchemeObject,\n): scheme is OpenAPIV3.OAuth2SecurityScheme | OpenAPIV3_1.OAuth2SecurityScheme {\n return scheme.type === 'oauth2'\n}\n\n// Validate token URL\nfunction isValidTokenUrl(url: string): boolean {\n return url.trim().length > 0\n}\n\nexport function getOpenAuthTokenUrls(schema?: OpenAPI.Document): string[] {\n if (!schema?.components?.securitySchemes) {\n return []\n }\n\n const securitySchemes: Record<string, OpenAPIV3.SecuritySchemeObject | OpenAPIV3_1.SecuritySchemeObject> =\n schema.components.securitySchemes\n\n // Use Set from the start for better memory efficiency\n const tokenUrls = new Set<string>()\n\n // Iterate through all security schemes\n for (const scheme of Object.values(securitySchemes)) {\n if (!isOAuth2Scheme(scheme)) {\n continue\n }\n\n const flows = scheme.flows // Type assertion no longer needed\n\n // Helper to safely add valid token URLs\n const addTokenUrl = (url?: string) => {\n if (url && isValidTokenUrl(url)) {\n tokenUrls.add(getPathFromUrl(url))\n }\n }\n\n addTokenUrl(flows?.password?.tokenUrl)\n addTokenUrl(flows?.clientCredentials?.tokenUrl)\n addTokenUrl(flows?.authorizationCode?.tokenUrl)\n }\n\n return Array.from(tokenUrls)\n}\n"],
|
|
5
5
|
"mappings": "AAKO,SAAS,eAAe,KAAqB;AAClD,MAAI;AAEF,UAAM,YAAY,IAAI,WAAW,MAAM,IAAI,IAAI,IAAI,GAAG,IAAI,IAAI,IAAI,KAAK,oBAAoB;AAG3F,UAAM,OAAO,UAAU;AACvB,WAAO,SAAS,MAAM,OAAO,KAAK,QAAQ,OAAO,EAAE;AAAA,EACrD,QAAQ;AAEN,WAAO;AAAA,EACT;AACF;AAMA,SAAS,eACP,QAC6E;AAC7E,SAAO,OAAO,SAAS;AACzB;AAGA,SAAS,gBAAgB,KAAsB;AAC7C,SAAO,IAAI,KAAK,EAAE,SAAS;AAC7B;AAEO,SAAS,qBAAqB,QAAqC;AACxE,MAAI,CAAC,QAAQ,YAAY,iBAAiB;AACxC,WAAO,CAAC;AAAA,EACV;AAEA,QAAM,kBACJ,OAAO,WAAW;AAGpB,QAAM,YAAY,oBAAI,IAAY;AAGlC,aAAW,UAAU,OAAO,OAAO,eAAe,GAAG;AACnD,QAAI,CAAC,eAAe,MAAM,GAAG;AAC3B;AAAA,IACF;AAEA,UAAM,QAAQ,OAAO;AAGrB,UAAM,cAAc,CAAC,QAAiB;AACpC,UAAI,OAAO,gBAAgB,GAAG,GAAG;AAC/B,kBAAU,IAAI,eAAe,GAAG,CAAC;AAAA,MACnC;AAAA,IACF;AAEA,gBAAY,OAAO,UAAU,QAAQ;AACrC,gBAAY,OAAO,mBAAmB,QAAQ;AAC9C,gBAAY,OAAO,mBAAmB,QAAQ;AAAA,EAChD;AAEA,SAAO,MAAM,KAAK,SAAS;AAC7B;",
|
|
6
6
|
"names": []
|
|
@@ -5,4 +5,4 @@ import { type HttpMethod } from '../types.js';
|
|
|
5
5
|
* Ignores other attributes, like summary, parameters, etc.
|
|
6
6
|
*/
|
|
7
7
|
export declare function getOperations(path?: OpenAPIV2.PathItemObject | OpenAPIV3.PathItemObject | OpenAPIV3_1.PathItemObject): Record<HttpMethod, OpenAPI.Operation>;
|
|
8
|
-
//# sourceMappingURL=
|
|
8
|
+
//# sourceMappingURL=get-operation.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"
|
|
1
|
+
{"version":3,"file":"get-operation.d.ts","sourceRoot":"","sources":["../../src/utils/get-operation.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAA;AAEvF,OAAO,EAAE,KAAK,UAAU,EAAe,MAAM,SAAS,CAAA;AAEtD;;;GAGG;AACH,wBAAgB,aAAa,CAC3B,IAAI,CAAC,EAAE,SAAS,CAAC,cAAc,GAAG,SAAS,CAAC,cAAc,GAAG,WAAW,CAAC,cAAc,GACtF,MAAM,CAAC,UAAU,EAAE,OAAO,CAAC,SAAS,CAAC,CAUvC"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["../../src/utils/
|
|
3
|
+
"sources": ["../../src/utils/get-operation.ts"],
|
|
4
4
|
"sourcesContent": ["import type { OpenAPI, OpenAPIV2, OpenAPIV3, OpenAPIV3_1 } from '@scalar/openapi-types'\n\nimport { type HttpMethod, httpMethods } from '@/types'\n\n/**\n * Takes a dereferenced OpenAPI document and returns all operations.\n * Ignores other attributes, like summary, parameters, etc.\n */\nexport function getOperations(\n path?: OpenAPIV2.PathItemObject | OpenAPIV3.PathItemObject | OpenAPIV3_1.PathItemObject,\n): Record<HttpMethod, OpenAPI.Operation> {\n const operations = {} as Record<HttpMethod, OpenAPI.Operation>\n\n for (const method of httpMethods) {\n if (path?.[method]) {\n operations[method] = path?.[method]\n }\n }\n\n return operations\n}\n"],
|
|
5
5
|
"mappings": "AAEA,SAA0B,mBAAmB;AAMtC,SAAS,cACd,MACuC;AACvC,QAAM,aAAa,CAAC;AAEpB,aAAW,UAAU,aAAa;AAChC,QAAI,OAAO,MAAM,GAAG;AAClB,iBAAW,MAAM,IAAI,OAAO,MAAM;AAAA,IACpC;AAAA,EACF;AAEA,SAAO;AACT;",
|
|
6
6
|
"names": []
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { OpenAPI } from '@scalar/openapi-types';
|
|
2
2
|
import type { Context } from 'hono';
|
|
3
3
|
/**
|
|
4
|
-
* Handles authentication for incoming requests based on the OpenAPI
|
|
4
|
+
* Handles authentication for incoming requests based on the OpenAPI document.
|
|
5
5
|
*/
|
|
6
6
|
export declare function handleAuthentication(schema?: OpenAPI.Document, operation?: OpenAPI.Operation): (c: Context, next: () => Promise<void>) => Promise<Response | void>;
|
|
7
|
-
//# sourceMappingURL=
|
|
7
|
+
//# sourceMappingURL=handle-authentication.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"handle-authentication.d.ts","sourceRoot":"","sources":["../../src/utils/handle-authentication.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAA;AACpD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,MAAM,CAAA;AAGnC;;GAEG;AACH,wBAAgB,oBAAoB,CAAC,MAAM,CAAC,EAAE,OAAO,CAAC,QAAQ,EAAE,SAAS,CAAC,EAAE,OAAO,CAAC,SAAS,IAC7E,GAAG,OAAO,EAAE,MAAM,MAAM,OAAO,CAAC,IAAI,CAAC,KAAG,OAAO,CAAC,QAAQ,GAAG,IAAI,CAAC,CAmH/E"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/utils/handle-authentication.ts"],
|
|
4
|
+
"sourcesContent": ["import type { OpenAPI } from '@scalar/openapi-types'\nimport type { Context } from 'hono'\nimport { getCookie } from 'hono/cookie'\n\n/**\n * Handles authentication for incoming requests based on the OpenAPI document.\n */\nexport function handleAuthentication(schema?: OpenAPI.Document, operation?: OpenAPI.Operation) {\n return async (c: Context, next: () => Promise<void>): Promise<Response | void> => {\n const operationSecuritySchemes = operation?.security || schema?.security\n\n if (operationSecuritySchemes && operationSecuritySchemes.length > 0) {\n let isAuthenticated = false\n let authScheme = ''\n\n for (const securityRequirement of operationSecuritySchemes) {\n let securitySchemeAuthenticated = true\n\n for (const [schemeName] of Object.entries(securityRequirement)) {\n const scheme = schema?.components?.securitySchemes?.[schemeName]\n\n if (scheme) {\n switch (scheme.type) {\n case 'http':\n if (scheme.scheme === 'basic') {\n authScheme = 'Basic'\n const authHeader = c.req.header('Authorization')\n\n if (authHeader?.startsWith('Basic ')) {\n isAuthenticated = true\n }\n } else if (scheme.scheme === 'bearer') {\n authScheme = 'Bearer'\n const authHeader = c.req.header('Authorization')\n\n if (authHeader?.startsWith('Bearer ')) {\n isAuthenticated = true\n }\n }\n break\n case 'apiKey':\n authScheme = `ApiKey ${scheme.name}`\n\n if (scheme.in === 'header') {\n const apiKey = c.req.header(scheme.name)\n if (apiKey) {\n isAuthenticated = true\n }\n } else if (scheme.in === 'query') {\n const apiKey = c.req.query(scheme.name)\n\n if (apiKey) {\n isAuthenticated = true\n }\n } else if (scheme.in === 'cookie') {\n const apiKey = getCookie(c, scheme.name)\n\n if (apiKey) {\n isAuthenticated = true\n }\n }\n break\n case 'oauth2':\n authScheme = 'Bearer'\n // Handle OAuth 2.0 flows, including password grant\n if (c.req.header('Authorization')?.startsWith('Bearer ')) {\n isAuthenticated = true\n }\n break\n case 'openIdConnect':\n authScheme = 'Bearer'\n // Handle OpenID Connect similar to OAuth2\n if (c.req.header('Authorization')?.startsWith('Bearer ')) {\n isAuthenticated = true\n }\n break\n }\n }\n\n if (!isAuthenticated) {\n securitySchemeAuthenticated = false\n break\n }\n }\n\n if (securitySchemeAuthenticated) {\n isAuthenticated = true\n break\n }\n }\n\n if (!isAuthenticated) {\n let wwwAuthenticateValue = authScheme\n\n switch (authScheme) {\n case 'Basic':\n wwwAuthenticateValue += ' realm=\"Scalar Mock Server\", charset=\"UTF-8\"'\n break\n case 'Bearer':\n wwwAuthenticateValue +=\n ' realm=\"Scalar Mock Server\", error=\"invalid_token\", error_description=\"The access token is invalid or has expired\"'\n break\n case 'ApiKey':\n wwwAuthenticateValue += ` realm=\"Scalar Mock Server\", error=\"invalid_token\", error_description=\"Invalid or missing API key\"`\n break\n default:\n wwwAuthenticateValue = 'Bearer realm=\"Scalar Mock Server\"'\n }\n\n c.header('WWW-Authenticate', wwwAuthenticateValue)\n return c.json(\n {\n error: 'Unauthorized',\n message: 'Authentication is required to access this resource.',\n },\n 401,\n )\n }\n }\n\n // If all checks pass, continue to the next middleware\n await next()\n }\n}\n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;AACA;AAAA,cACF,KAAK;AACH,6BAAa;AAEb,oBAAI,EAAE,IAAI,OAAO,eAAe,GAAG,WAAW,SAAS,GAAG;AACxD,oCAAkB;AAAA,gBACpB;AACA;AAAA,cACF,KAAK;AACH,6BAAa;AAEb,oBAAI,EAAE,IAAI,OAAO,eAAe,GAAG,WAAW,SAAS,GAAG;AACxD,oCAAkB;AAAA,gBACpB;AACA;AAAA,YACJ;AAAA,UACF;AAEA,cAAI,CAAC,iBAAiB;AACpB,0CAA8B;AAC9B;AAAA,UACF;AAAA,QACF;AAEA,YAAI,6BAA6B;AAC/B,4BAAkB;AAClB;AAAA,QACF;AAAA,MACF;AAEA,UAAI,CAAC,iBAAiB;AACpB,YAAI,uBAAuB;AAE3B,gBAAQ,YAAY;AAAA,UAClB,KAAK;AACH,oCAAwB;AACxB;AAAA,UACF,KAAK;AACH,oCACE;AACF;AAAA,UACF,KAAK;AACH,oCAAwB;AACxB;AAAA,UACF;AACE,mCAAuB;AAAA,QAC3B;AAEA,UAAE,OAAO,oBAAoB,oBAAoB;AACjD,eAAO,EAAE;AAAA,UACP;AAAA,YACE,OAAO;AAAA,YACP,SAAS;AAAA,UACX;AAAA,UACA;AAAA,QACF;AAAA,MACF;AAAA,IACF;AAGA,UAAM,KAAK;AAAA,EACb;AACF;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hono-route-from-path.d.ts","sourceRoot":"","sources":["../../src/utils/hono-route-from-path.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,UAE7C"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["../../src/utils/
|
|
3
|
+
"sources": ["../../src/utils/hono-route-from-path.ts"],
|
|
4
4
|
"sourcesContent": ["/**\n * Convert path to route\n * Example: /posts/{id} -> /posts/:id\n */\nexport function honoRouteFromPath(path: string) {\n return path.replace(/{/g, ':').replace(/}/g, '')\n}\n"],
|
|
5
5
|
"mappings": "AAIO,SAAS,kBAAkB,MAAc;AAC9C,SAAO,KAAK,QAAQ,MAAM,GAAG,EAAE,QAAQ,MAAM,EAAE;AACjD;",
|
|
6
6
|
"names": []
|
|
@@ -3,4 +3,4 @@ import type { OpenAPIV3 } from '@scalar/openapi-types';
|
|
|
3
3
|
* Check whether the given security scheme key is in the `security` configuration for this operation.
|
|
4
4
|
*/
|
|
5
5
|
export declare function isAuthenticationRequired(security?: OpenAPIV3.SecurityRequirementObject[]): boolean;
|
|
6
|
-
//# sourceMappingURL=
|
|
6
|
+
//# sourceMappingURL=is-authentication-required.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"is-authentication-required.d.ts","sourceRoot":"","sources":["../../src/utils/is-authentication-required.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAA;AAEtD;;GAEG;AACH,wBAAgB,wBAAwB,CAAC,QAAQ,CAAC,EAAE,SAAS,CAAC,yBAAyB,EAAE,GAAG,OAAO,CAiBlG"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["../../src/utils/
|
|
3
|
+
"sources": ["../../src/utils/is-authentication-required.ts"],
|
|
4
4
|
"sourcesContent": ["import type { OpenAPIV3 } from '@scalar/openapi-types'\n\n/**\n * Check whether the given security scheme key is in the `security` configuration for this operation.\n */\nexport function isAuthenticationRequired(security?: OpenAPIV3.SecurityRequirementObject[]): boolean {\n // If security is not defined, auth is not required.\n if (!security) {\n return false\n }\n\n // Don't require auth if security is just an empty array []\n if (Array.isArray(security) && !security.length) {\n return false\n }\n\n // Includes empty object = auth is not required\n if ((security ?? []).some((securityRequirement) => !Object.keys(securityRequirement).length)) {\n return false\n }\n\n return true\n}\n"],
|
|
5
5
|
"mappings": "AAKO,SAAS,yBAAyB,UAA2D;AAElG,MAAI,CAAC,UAAU;AACb,WAAO;AAAA,EACT;AAGA,MAAI,MAAM,QAAQ,QAAQ,KAAK,CAAC,SAAS,QAAQ;AAC/C,WAAO;AAAA,EACT;AAGA,OAAK,YAAY,CAAC,GAAG,KAAK,CAAC,wBAAwB,CAAC,OAAO,KAAK,mBAAmB,EAAE,MAAM,GAAG;AAC5F,WAAO;AAAA,EACT;AAEA,SAAO;AACT;",
|
|
6
6
|
"names": []
|
package/dist/utils/{logAuthenticationInstructions.d.ts → log-authentication-instructions.d.ts}
RENAMED
|
@@ -3,4 +3,4 @@ import type { OpenAPIV3_1 } from '@scalar/openapi-types';
|
|
|
3
3
|
* Log authentication instructions for different security schemes
|
|
4
4
|
*/
|
|
5
5
|
export declare function logAuthenticationInstructions(securitySchemes: Record<string, OpenAPIV3_1.SecuritySchemeObject>): void;
|
|
6
|
-
//# sourceMappingURL=
|
|
6
|
+
//# sourceMappingURL=log-authentication-instructions.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"log-authentication-instructions.d.ts","sourceRoot":"","sources":["../../src/utils/log-authentication-instructions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAA;AAIxD;;GAEG;AACH,wBAAgB,6BAA6B,CAAC,eAAe,EAAE,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC,oBAAoB,CAAC,QAmH9G"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { getPathFromUrl } from "./
|
|
1
|
+
import { getPathFromUrl } from "./get-open-auth-token-urls.js";
|
|
2
2
|
function logAuthenticationInstructions(securitySchemes) {
|
|
3
3
|
if (!securitySchemes || Object.keys(securitySchemes).length === 0) {
|
|
4
4
|
return;
|
|
@@ -115,4 +115,4 @@ function logAuthenticationInstructions(securitySchemes) {
|
|
|
115
115
|
export {
|
|
116
116
|
logAuthenticationInstructions
|
|
117
117
|
};
|
|
118
|
-
//# sourceMappingURL=
|
|
118
|
+
//# sourceMappingURL=log-authentication-instructions.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/utils/log-authentication-instructions.ts"],
|
|
4
|
+
"sourcesContent": ["import type { OpenAPIV3_1 } from '@scalar/openapi-types'\n\nimport { getPathFromUrl } from './get-open-auth-token-urls'\n\n/**\n * Log authentication instructions for different security schemes\n */\nexport function logAuthenticationInstructions(securitySchemes: Record<string, OpenAPIV3_1.SecuritySchemeObject>) {\n if (!securitySchemes || Object.keys(securitySchemes).length === 0) {\n return\n }\n\n console.log('Authentication:')\n console.log()\n\n Object.entries(securitySchemes).forEach(([_, scheme]) => {\n switch (scheme.type) {\n case 'apiKey':\n if (scheme.in === 'header') {\n console.log('\u2705 API Key Authentication')\n console.log(` Use any API key in the ${scheme.name} header`)\n console.log()\n console.log(` ${scheme.name}: YOUR_API_KEY_HERE`)\n console.log()\n } else if (scheme.in === 'query') {\n console.log('\u2705 API Key Authentication')\n console.log(` Use any API key in the ${scheme.name} query parameter:`)\n console.log()\n console.log(` ?${scheme.name}=YOUR_API_KEY_HERE`)\n console.log()\n } else if (scheme.in === 'cookie') {\n console.log('\u2705 API Key Authentication')\n console.log(` Use any API key in the ${scheme.name} cookie:`)\n console.log()\n console.log(` Cookie: ${scheme.name}=YOUR_API_KEY_HERE`)\n console.log()\n } else {\n console.error(`\u274C Unsupported API Key Location: ${scheme.in}`)\n }\n break\n case 'http':\n if (scheme.scheme === 'basic') {\n console.log('\u2705 HTTP Basic Authentication')\n console.log(' Use an Authorization header with any credentials (\"username:password\" in base64):')\n console.log()\n console.log(' Authorization: Basic dXNlcm5hbWU6cGFzc3dvcmQ=')\n console.log()\n } else if (scheme.scheme === 'bearer') {\n console.log('\u2705 Bearer Token Authentication')\n console.log(' Use an Authorization header with any bearer token')\n console.log()\n console.log(' Authorization: Bearer YOUR_TOKEN_HERE')\n console.log()\n } else {\n console.error('\u274C Unknown Security Scheme:', scheme)\n }\n\n break\n case 'oauth2':\n if (scheme.flows) {\n Object.keys(scheme.flows).forEach((flow) => {\n switch (flow) {\n case 'implicit':\n console.log('\u2705 OAuth 2.0 Implicit Flow')\n console.log(' Use the following URL to initiate the OAuth 2.0 Implicit Flow:')\n console.log()\n console.log(\n ` GET ${scheme?.flows?.implicit?.authorizationUrl || '/oauth/authorize'}?response_type=token&client_id=YOUR_CLIENT_ID&redirect_uri=YOUR_REDIRECT_URI&scope=YOUR_SCOPES`,\n )\n console.log()\n break\n case 'password':\n console.log('\u2705 OAuth 2.0 Password Flow')\n console.log(' Use the following URL to obtain an access token:')\n console.log()\n console.log(` POST ${getPathFromUrl(scheme?.flows?.password?.tokenUrl || '/oauth/token')}`)\n console.log(' Content-Type: application/x-www-form-urlencoded')\n console.log()\n console.log(\n ' grant_type=password&username=YOUR_USERNAME&password=YOUR_PASSWORD&client_id=YOUR_CLIENT_ID&client_secret=YOUR_CLIENT_SECRET',\n )\n console.log()\n break\n case 'clientCredentials':\n console.log('\u2705 OAuth 2.0 Client Credentials Flow')\n console.log(' Use the following URL to obtain an access token:')\n console.log()\n console.log(` POST ${getPathFromUrl(scheme?.flows?.clientCredentials?.tokenUrl || '/oauth/token')}`)\n console.log(' Content-Type: application/x-www-form-urlencoded')\n console.log()\n console.log(\n ' grant_type=client_credentials&client_id=YOUR_CLIENT_ID&client_secret=YOUR_CLIENT_SECRET',\n )\n console.log()\n break\n case 'authorizationCode':\n console.log('\u2705 OAuth 2.0 Authorization Code Flow')\n console.log(' Use the following URL to initiate the OAuth 2.0 Authorization Code Flow:')\n console.log()\n console.log(\n ' GET',\n `${getPathFromUrl(scheme?.flows?.authorizationCode?.authorizationUrl || '/oauth/authorize')}?redirect_uri=https://YOUR_REDIRECT_URI_HERE`,\n )\n console.log()\n break\n default:\n console.warn(`Unsupported OAuth 2.0 flow: ${flow}`)\n }\n })\n }\n break\n case 'openIdConnect':\n console.log('\u2705 OpenID Connect Authentication')\n console.log(' Use the following OpenID Connect discovery URL:')\n console.log()\n console.log(` ${getPathFromUrl(scheme.openIdConnectUrl || '/.well-known/openid-configuration')}`)\n console.log()\n break\n default:\n console.warn(`Unsupported security scheme type: ${scheme.type}`)\n }\n })\n}\n"],
|
|
5
|
+
"mappings": "AAEA,SAAS,sBAAsB;AAKxB,SAAS,8BAA8B,iBAAmE;AAC/G,MAAI,CAAC,mBAAmB,OAAO,KAAK,eAAe,EAAE,WAAW,GAAG;AACjE;AAAA,EACF;AAEA,UAAQ,IAAI,iBAAiB;AAC7B,UAAQ,IAAI;AAEZ,SAAO,QAAQ,eAAe,EAAE,QAAQ,CAAC,CAAC,GAAG,MAAM,MAAM;AACvD,YAAQ,OAAO,MAAM;AAAA,MACnB,KAAK;AACH,YAAI,OAAO,OAAO,UAAU;AAC1B,kBAAQ,IAAI,+BAA0B;AACtC,kBAAQ,IAAI,6BAA6B,OAAO,IAAI,SAAS;AAC7D,kBAAQ,IAAI;AACZ,kBAAQ,IAAI,MAAM,OAAO,IAAI,qBAAqB;AAClD,kBAAQ,IAAI;AAAA,QACd,WAAW,OAAO,OAAO,SAAS;AAChC,kBAAQ,IAAI,+BAA0B;AACtC,kBAAQ,IAAI,6BAA6B,OAAO,IAAI,mBAAmB;AACvE,kBAAQ,IAAI;AACZ,kBAAQ,IAAI,OAAO,OAAO,IAAI,oBAAoB;AAClD,kBAAQ,IAAI;AAAA,QACd,WAAW,OAAO,OAAO,UAAU;AACjC,kBAAQ,IAAI,+BAA0B;AACtC,kBAAQ,IAAI,6BAA6B,OAAO,IAAI,UAAU;AAC9D,kBAAQ,IAAI;AACZ,kBAAQ,IAAI,cAAc,OAAO,IAAI,oBAAoB;AACzD,kBAAQ,IAAI;AAAA,QACd,OAAO;AACL,kBAAQ,MAAM,wCAAmC,OAAO,EAAE,EAAE;AAAA,QAC9D;AACA;AAAA,MACF,KAAK;AACH,YAAI,OAAO,WAAW,SAAS;AAC7B,kBAAQ,IAA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;AAAA,cACF,KAAK;AACH,wBAAQ,IAAI,0CAAqC;AACjD,wBAAQ,IAAI,6EAA6E;AACzF,wBAAQ,IAAI;AACZ,wBAAQ;AAAA,kBACN;AAAA,kBACA,GAAG,eAAe,QAAQ,OAAO,mBAAmB,oBAAoB,kBAAkB,CAAC;AAAA,gBAC7F;AACA,wBAAQ,IAAI;AACZ;AAAA,cACF;AACE,wBAAQ,KAAK,+BAA+B,IAAI,EAAE;AAAA,YACtD;AAAA,UACF,CAAC;AAAA,QACH;AACA;AAAA,MACF,KAAK;AACH,gBAAQ,IAAI,sCAAiC;AAC7C,gBAAQ,IAAI,oDAAoD;AAChE,gBAAQ,IAAI;AACZ,gBAAQ,IAAI,MAAM,eAAe,OAAO,oBAAoB,mCAAmC,CAAC,EAAE;AAClG,gBAAQ,IAAI;AACZ;AAAA,MACF;AACE,gBAAQ,KAAK,qCAAqC,OAAO,IAAI,EAAE;AAAA,IACnE;AAAA,EACF,CAAC;AACH;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -3,5 +3,5 @@ import type { Hono } from 'hono';
|
|
|
3
3
|
/**
|
|
4
4
|
* Helper function to set up authentication routes for OAuth 2.0 flows
|
|
5
5
|
*/
|
|
6
|
-
export declare function
|
|
7
|
-
//# sourceMappingURL=
|
|
6
|
+
export declare function setUpAuthenticationRoutes(app: Hono, schema?: OpenAPI.Document): void;
|
|
7
|
+
//# sourceMappingURL=set-up-authentication-routes.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"set-up-authentication-routes.d.ts","sourceRoot":"","sources":["../../src/utils/set-up-authentication-routes.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAA0B,MAAM,uBAAuB,CAAA;AAC5E,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,MAAM,CAAA;AAOhC;;GAEG;AACH,wBAAgB,yBAAyB,CAAC,GAAG,EAAE,IAAI,EAAE,MAAM,CAAC,EAAE,OAAO,CAAC,QAAQ,QA4F7E"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { respondWithAuthorizePage } from "../routes/
|
|
2
|
-
import { respondWithToken } from "../routes/
|
|
3
|
-
import { getOpenAuthTokenUrls, getPathFromUrl } from "./
|
|
4
|
-
function
|
|
1
|
+
import { respondWithAuthorizePage } from "../routes/respond-with-authorize-page.js";
|
|
2
|
+
import { respondWithToken } from "../routes/respond-with-token.js";
|
|
3
|
+
import { getOpenAuthTokenUrls, getPathFromUrl } from "./get-open-auth-token-urls.js";
|
|
4
|
+
function setUpAuthenticationRoutes(app, schema) {
|
|
5
5
|
const securitySchemes = schema?.components?.securitySchemes || {};
|
|
6
6
|
getOpenAuthTokenUrls(schema).forEach((tokenUrl) => {
|
|
7
7
|
app.post(tokenUrl, (c) => {
|
|
@@ -75,6 +75,6 @@ function setupAuthenticationRoutes(app, schema) {
|
|
|
75
75
|
});
|
|
76
76
|
}
|
|
77
77
|
export {
|
|
78
|
-
|
|
78
|
+
setUpAuthenticationRoutes
|
|
79
79
|
};
|
|
80
|
-
//# sourceMappingURL=
|
|
80
|
+
//# sourceMappingURL=set-up-authentication-routes.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/utils/set-up-authentication-routes.ts"],
|
|
4
|
+
"sourcesContent": ["import type { OpenAPI, OpenAPIV3, OpenAPIV3_1 } from '@scalar/openapi-types'\nimport type { Hono } from 'hono'\n\nimport { respondWithAuthorizePage } from '@/routes/respond-with-authorize-page'\nimport { respondWithToken } from '@/routes/respond-with-token'\n\nimport { getOpenAuthTokenUrls, getPathFromUrl } from './get-open-auth-token-urls'\n\n/**\n * Helper function to set up authentication routes for OAuth 2.0 flows\n */\nexport function setUpAuthenticationRoutes(app: Hono, schema?: OpenAPI.Document) {\n const securitySchemes: Record<string, OpenAPIV3.SecuritySchemeObject | OpenAPIV3_1.SecuritySchemeObject> =\n schema?.components?.securitySchemes || {}\n\n // Set up authentication routes for OAuth 2.0 flows\n getOpenAuthTokenUrls(schema).forEach((tokenUrl) => {\n app.post(tokenUrl, (c) => {\n return c.json(\n {\n access_token: 'super-secret-access-token',\n token_type: 'Bearer',\n expires_in: 3600,\n refresh_token: 'example-refresh-token',\n },\n 200,\n {\n /**\n * When responding with an access token, the server must also include the additional\n * Cache-Control: no-store HTTP header to ensure clients do not cache this request.\n *\n * @see https://www.oauth.com/oauth2-servers/access-tokens/access-token-response/\n */\n 'Cache-Control': 'no-store',\n },\n )\n })\n })\n\n // Set up routes for different OAuth 2.0 flows\n const authorizeUrls = new Set<string>()\n const tokenUrls = new Set<string>()\n\n Object.entries(securitySchemes).forEach(([_, scheme]) => {\n if (scheme.type === 'oauth2') {\n if (scheme.flows?.authorizationCode) {\n const authorizeRoute = scheme.flows.authorizationCode.authorizationUrl ?? '/oauth/authorize'\n const tokenRoute = scheme.flows.authorizationCode.tokenUrl ?? '/oauth/token'\n\n authorizeUrls.add(getPathFromUrl(authorizeRoute))\n tokenUrls.add(tokenRoute)\n }\n\n if (scheme.flows?.implicit) {\n const authorizeRoute = scheme.flows.implicit.authorizationUrl ?? '/oauth/authorize'\n authorizeUrls.add(getPathFromUrl(authorizeRoute))\n }\n\n if (scheme.flows?.password) {\n const tokenRoute = scheme.flows.password.tokenUrl ?? '/oauth/token'\n tokenUrls.add(tokenRoute)\n }\n\n if (scheme.flows?.clientCredentials) {\n const tokenRoute = scheme.flows.clientCredentials.tokenUrl ?? '/oauth/token'\n tokenUrls.add(tokenRoute)\n }\n } else if (scheme.type === 'openIdConnect') {\n // Handle OpenID Connect configuration\n if (scheme.openIdConnectUrl) {\n const configPath = getPathFromUrl(scheme.openIdConnectUrl ?? '/.well-known/openid-configuration')\n\n // Add route for OpenID Connect configuration\n app.get(configPath, (c) => {\n return c.json({\n issuer: 'https://example.com',\n authorization_endpoint: '/oauth/authorize',\n token_endpoint: '/oauth/token',\n response_types_supported: ['code', 'token', 'id_token'],\n subject_types_supported: ['public'],\n id_token_signing_alg_values_supported: ['RS256'],\n })\n })\n\n // Add standard endpoints\n const authorizeRoute = '/oauth/authorize'\n const tokenRoute = '/oauth/token'\n\n authorizeUrls.add(getPathFromUrl(authorizeRoute))\n tokenUrls.add(tokenRoute)\n }\n }\n })\n\n // Set up unique authorization routes\n authorizeUrls.forEach((authorizeUrl) => {\n app.get(authorizeUrl, (c) => respondWithAuthorizePage(c, schema?.info?.title))\n })\n\n // Set up unique token routes\n tokenUrls.forEach((tokenUrl) => {\n app.post(tokenUrl, respondWithToken)\n })\n}\n"],
|
|
5
|
+
"mappings": "AAGA,SAAS,gCAAgC;AACzC,SAAS,wBAAwB;AAEjC,SAAS,sBAAsB,sBAAsB;AAK9C,SAAS,0BAA0B,KAAW,QAA2B;AAC9E,QAAM,kBACJ,QAAQ,YAAY,mBAAmB,CAAC;AAG1C,uBAAqB,MAAM,EAAE,QAAQ,CAAC,aAAa;AACjD,QAAI,KAAK,UAAU,CAAC,MAAM;AACxB,aAAO,EAAE;AAAA,QACP;AAAA,UACE,cAAc;AAAA,UACd,YAAY;AAAA,UACZ,YAAY;AAAA,UACZ,eAAe;AAAA,QACjB;AAAA,QACA;AAAA,QACA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,UAOE,iBAAiB;AAAA,QACnB;AAAA,MACF;AAAA,IACF,CAAC;AAAA,EACH,CAAC;AAGD,QAAM,gBAAgB,oBAAI,IAAY;AACtC,QAAM,YAAY,oBAAI,IAAY;AAElC,SAAO,QAAQ,eAAe,EAAE,QAAQ,CAAC,CAAC,GAAG,MAAM,MAAM;AACvD,QAAI,OAAO,SAAS,UAAU;AAC5B,UAAI,OAAO,OAAO,mBAAmB;AACnC,cAAM,iBAAiB,OAAO,MAAM,kBAAkB,oBAAoB;AAC1E,cAAM,aAAa,OAAO,MAAM,kBAAkB,YAAY;AAE9D,sBAAc,IAAI,eAAe,cAAc,CAAC;AAChD,kBAAU,IAAI,UAAU;AAAA,M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|
|
19
|
-
"version": "0.
|
|
19
|
+
"version": "0.7.0",
|
|
20
20
|
"engines": {
|
|
21
21
|
"node": ">=20"
|
|
22
22
|
},
|
|
@@ -37,16 +37,14 @@
|
|
|
37
37
|
"module": "dist/index.js",
|
|
38
38
|
"dependencies": {
|
|
39
39
|
"hono": "4.10.2",
|
|
40
|
-
"@scalar/
|
|
41
|
-
"@scalar/
|
|
42
|
-
"@scalar/openapi-parser": "0.23.
|
|
40
|
+
"@scalar/oas-utils": "0.6.2",
|
|
41
|
+
"@scalar/helpers": "0.1.0",
|
|
42
|
+
"@scalar/openapi-parser": "0.23.1",
|
|
43
43
|
"@scalar/openapi-types": "0.5.1"
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
|
-
"@hono/node-server": "1.19.5",
|
|
47
46
|
"@types/node": "^22.9.0",
|
|
48
47
|
"vite": "7.1.11",
|
|
49
|
-
"@scalar/hono-api-reference": "0.9.23",
|
|
50
48
|
"@scalar/build-tooling": "0.2.8"
|
|
51
49
|
},
|
|
52
50
|
"scripts": {
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"createMockServer.d.ts","sourceRoot":"","sources":["../src/createMockServer.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAA;AAG3B,OAAO,KAAK,EAAc,iBAAiB,EAAE,MAAM,SAAS,CAAA;AAW5D;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,iBAAiB,GAAG,OAAO,CAAC,IAAI,CAAC,CAgD1E"}
|
package/dist/createMockServer.js
DELETED
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import { dereference } from "@scalar/openapi-parser";
|
|
2
|
-
import { Hono } from "hono";
|
|
3
|
-
import { cors } from "hono/cors";
|
|
4
|
-
import { getOperations } from "./utils/getOperations.js";
|
|
5
|
-
import { handleAuthentication } from "./utils/handleAuthentication.js";
|
|
6
|
-
import { honoRouteFromPath } from "./utils/honoRouteFromPath.js";
|
|
7
|
-
import { isAuthenticationRequired } from "./utils/isAuthenticationRequired.js";
|
|
8
|
-
import { logAuthenticationInstructions } from "./utils/logAuthenticationInstructions.js";
|
|
9
|
-
import { setupAuthenticationRoutes } from "./utils/setupAuthenticationRoutes.js";
|
|
10
|
-
import { mockAnyResponse } from "./routes/mockAnyResponse.js";
|
|
11
|
-
import { respondWithOpenApiDocument } from "./routes/respondWithOpenApiDocument.js";
|
|
12
|
-
function createMockServer(options) {
|
|
13
|
-
const app = new Hono();
|
|
14
|
-
const { schema } = dereference(options?.specification ?? {});
|
|
15
|
-
app.use(cors());
|
|
16
|
-
setupAuthenticationRoutes(app, schema);
|
|
17
|
-
logAuthenticationInstructions(
|
|
18
|
-
schema?.components?.securitySchemes || {}
|
|
19
|
-
);
|
|
20
|
-
const paths = schema?.paths ?? {};
|
|
21
|
-
Object.keys(paths).forEach((path) => {
|
|
22
|
-
const methods = Object.keys(getOperations(paths[path]));
|
|
23
|
-
methods.forEach((method) => {
|
|
24
|
-
const route = honoRouteFromPath(path);
|
|
25
|
-
const operation = schema?.paths?.[path]?.[method];
|
|
26
|
-
if (isAuthenticationRequired(operation.security)) {
|
|
27
|
-
app[method](route, handleAuthentication(schema, operation));
|
|
28
|
-
}
|
|
29
|
-
app[method](route, (c) => mockAnyResponse(c, operation, options));
|
|
30
|
-
});
|
|
31
|
-
});
|
|
32
|
-
app.get("/openapi.json", (c) => respondWithOpenApiDocument(c, options?.specification, "json"));
|
|
33
|
-
app.get("/openapi.yaml", (c) => respondWithOpenApiDocument(c, options?.specification, "yaml"));
|
|
34
|
-
return Promise.resolve(app);
|
|
35
|
-
}
|
|
36
|
-
export {
|
|
37
|
-
createMockServer
|
|
38
|
-
};
|
|
39
|
-
//# sourceMappingURL=createMockServer.js.map
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../src/createMockServer.ts"],
|
|
4
|
-
"sourcesContent": ["import { dereference } from '@scalar/openapi-parser'\nimport type { OpenAPI, OpenAPIV3_1 } from '@scalar/openapi-types'\nimport { Hono } from 'hono'\nimport { cors } from 'hono/cors'\n\nimport type { HttpMethod, MockServerOptions } from '@/types'\nimport { getOperations } from '@/utils/getOperations'\nimport { handleAuthentication } from '@/utils/handleAuthentication'\nimport { honoRouteFromPath } from '@/utils/honoRouteFromPath'\nimport { isAuthenticationRequired } from '@/utils/isAuthenticationRequired'\nimport { logAuthenticationInstructions } from '@/utils/logAuthenticationInstructions'\nimport { setupAuthenticationRoutes } from '@/utils/setupAuthenticationRoutes'\n\nimport { mockAnyResponse } from './routes/mockAnyResponse'\nimport { respondWithOpenApiDocument } from './routes/respondWithOpenApiDocument'\n\n/**\n * Create a mock server instance\n */\nexport function createMockServer(options: MockServerOptions): Promise<Hono> {\n const app = new Hono()\n\n /** Dereferenced OpenAPI document */\n const { schema } = dereference(options?.specification ?? {})\n\n // CORS headers\n app.use(cors())\n\n /** Authentication methods defined in the OpenAPI document */\n setupAuthenticationRoutes(app, schema)\n\n logAuthenticationInstructions(\n schema?.components?.securitySchemes || ({} as Record<string, OpenAPIV3_1.SecuritySchemeObject>),\n )\n\n /** Paths specified in the OpenAPI document */\n const paths = schema?.paths ?? {}\n\n Object.keys(paths).forEach((path) => {\n const methods = Object.keys(getOperations(paths[path])) as HttpMethod[]\n\n /** Keys for all operations of a specified path */\n methods.forEach((method) => {\n const route = honoRouteFromPath(path)\n const operation = schema?.paths?.[path]?.[method] as OpenAPI.Operation\n\n // Check if authentication is required for this operation\n if (isAuthenticationRequired(operation.security)) {\n app[method](route, handleAuthentication(schema, operation))\n }\n\n // Actual route\n app[method](route, (c) => mockAnyResponse(c, operation, options))\n })\n })\n\n // OpenAPI JSON file\n app.get('/openapi.json', (c) => respondWithOpenApiDocument(c, options?.specification, 'json'))\n\n // OpenAPI YAML file\n app.get('/openapi.yaml', (c) => respondWithOpenApiDocument(c, options?.specification, 'yaml'))\n\n /**\n * No async code, but returning a Promise to allow future async logic to be implemented\n * @see https://github.com/scalar/scalar/pull/7174#discussion_r2470046281\n */\n return Promise.resolve(app)\n}\n"],
|
|
5
|
-
"mappings": "AAAA,SAAS,mBAAmB;AAE5B,SAAS,YAAY;AACrB,SAAS,YAAY;AAGrB,SAAS,qBAAqB;AAC9B,SAAS,4BAA4B;AACrC,SAAS,yBAAyB;AAClC,SAAS,gCAAgC;AACzC,SAAS,qCAAqC;AAC9C,SAAS,iCAAiC;AAE1C,SAAS,uBAAuB;AAChC,SAAS,kCAAkC;AAKpC,SAAS,iBAAiB,SAA2C;AAC1E,QAAM,MAAM,IAAI,KAAK;AAGrB,QAAM,EAAE,OAAO,IAAI,YAAY,SAAS,iBAAiB,CAAC,CAAC;AAG3D,MAAI,IAAI,KAAK,CAAC;AAGd,4BAA0B,KAAK,MAAM;AAErC;AAAA,IACE,QAAQ,YAAY,mBAAoB,CAAC;AAAA,EAC3C;AAGA,QAAM,QAAQ,QAAQ,SAAS,CAAC;AAEhC,SAAO,KAAK,KAAK,EAAE,QAAQ,CAAC,SAAS;AACnC,UAAM,UAAU,OAAO,KAAK,cAAc,MAAM,IAAI,CAAC,CAAC;AAGtD,YAAQ,QAAQ,CAAC,WAAW;AAC1B,YAAM,QAAQ,kBAAkB,IAAI;AACpC,YAAM,YAAY,QAAQ,QAAQ,IAAI,IAAI,MAAM;AAGhD,UAAI,yBAAyB,UAAU,QAAQ,GAAG;AAChD,YAAI,MAAM,EAAE,OAAO,qBAAqB,QAAQ,SAAS,CAAC;AAAA,MAC5D;AAGA,UAAI,MAAM,EAAE,OAAO,CAAC,MAAM,gBAAgB,GAAG,WAAW,OAAO,CAAC;AAAA,IAClE,CAAC;AAAA,EACH,CAAC;AAGD,MAAI,IAAI,iBAAiB,CAAC,MAAM,2BAA2B,GAAG,SAAS,eAAe,MAAM,CAAC;AAG7F,MAAI,IAAI,iBAAiB,CAAC,MAAM,2BAA2B,GAAG,SAAS,eAAe,MAAM,CAAC;AAM7F,SAAO,QAAQ,QAAQ,GAAG;AAC5B;",
|
|
6
|
-
"names": []
|
|
7
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"createMockServer.test.d.ts","sourceRoot":"","sources":["../src/createMockServer.test.ts"],"names":[],"mappings":""}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"mockAnyResponse.d.ts","sourceRoot":"","sources":["../../src/routes/mockAnyResponse.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAA;AACpD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,MAAM,CAAA;AAInC,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAA;AAIhD;;GAEG;AACH,wBAAgB,eAAe,CAAC,CAAC,EAAE,OAAO,EAAE,SAAS,EAAE,OAAO,CAAC,SAAS,EAAE,OAAO,EAAE,iBAAiB;;mLAyEnG"}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../src/routes/mockAnyResponse.ts"],
|
|
4
|
-
"sourcesContent": ["import { getExampleFromSchema } from '@scalar/oas-utils/spec-getters'\nimport type { OpenAPI } from '@scalar/openapi-types'\nimport type { Context } from 'hono'\nimport { accepts } from 'hono/accepts'\nimport type { StatusCode } from 'hono/utils/http-status'\n\nimport type { MockServerOptions } from '@/types'\nimport { findPreferredResponseKey } from '@/utils/findPreferredResponseKey'\nimport { json2xml } from '@scalar/helpers/file/json2xml'\n\n/**\n * Mock any response\n */\nexport function mockAnyResponse(c: Context, operation: OpenAPI.Operation, options: MockServerOptions) {\n // Call onRequest callback\n if (options?.onRequest) {\n options.onRequest({\n context: c,\n operation,\n })\n }\n\n // Response\n // default, 200, 201 \u2026\n const preferredResponseKey = findPreferredResponseKey(Object.keys(operation.responses ?? {}))\n const preferredResponse = preferredResponseKey ? operation.responses?.[preferredResponseKey] : null\n\n if (!preferredResponse) {\n c.status(500)\n\n return c.json({ error: 'No response defined for this operation.' })\n }\n\n const supportedContentTypes = Object.keys(preferredResponse?.content ?? {})\n\n // Headers\n const headers = preferredResponse?.headers ?? {}\n Object.keys(headers).forEach((header) => {\n const value = headers[header].schema ? getExampleFromSchema(headers[header].schema) : null\n if (value !== null) {\n c.header(header, value)\n }\n })\n\n // Content-Type\n const acceptedContentType = accepts(c, {\n header: 'Accept',\n supports: supportedContentTypes,\n default: supportedContentTypes.includes('application/json')\n ? 'application/json'\n : (supportedContentTypes[0] ?? 'text/plain;charset=UTF-8'),\n })\n\n c.header('Content-Type', acceptedContentType)\n\n const acceptedResponse = preferredResponse?.content?.[acceptedContentType]\n\n // Body\n const body = acceptedResponse?.example\n ? acceptedResponse.example\n : acceptedResponse?.schema\n ? getExampleFromSchema(acceptedResponse.schema, {\n emptyString: 'string',\n variables: c.req.param(),\n mode: 'read',\n })\n : null\n\n // Status code\n const statusCode = Number.parseInt(\n preferredResponseKey === 'default' ? '200' : (preferredResponseKey ?? '200'),\n 10,\n ) as StatusCode\n\n c.status(statusCode)\n\n return c.body(\n typeof body === 'object'\n ? // XML\n acceptedContentType?.includes('xml')\n ? json2xml(body)\n : // JSON\n JSON.stringify(body, null, 2)\n : // String\n body,\n )\n}\n"],
|
|
5
|
-
"mappings": "AAAA,SAAS,4BAA4B;AAGrC,SAAS,eAAe;AAIxB,SAAS,gCAAgC;AACzC,SAAS,gBAAgB;AAKlB,SAAS,gBAAgB,GAAY,WAA8B,SAA4B;AAEpG,MAAI,SAAS,WAAW;AACtB,YAAQ,UAAU;AAAA,MAChB,SAAS;AAAA,MACT;AAAA,IACF,CAAC;AAAA,EACH;AAIA,QAAM,uBAAuB,yBAAyB,OAAO,KAAK,UAAU,aAAa,CAAC,CAAC,CAAC;AAC5F,QAAM,oBAAoB,uBAAuB,UAAU,YAAY,oBAAoB,IAAI;AAE/F,MAAI,CAAC,mBAAmB;AACtB,MAAE,OAAO,GAAG;AAEZ,WAAO,EA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uthorizePage.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,MAAM,CAAA;AAKnC;;GAEG;AACH,wBAAgB,wBAAwB,CAAC,CAAC,EAAE,OAAO,EAAE,KAAK,SAAK,YA2C9D"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"respondWithOpenApiDocument.d.ts","sourceRoot":"","sources":["../../src/routes/respondWithOpenApiDocument.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,MAAM,CAAA;AAEnC;;GAEG;AACH,wBAAgB,0BAA0B,CACxC,CAAC,EAAE,OAAO,EACV,KAAK,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EACpC,MAAM,GAAE,MAAM,GAAG,MAAe;;;;;;;;;;;;;;;;iBAwCjC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"respondWithToken.d.ts","sourceRoot":"","sources":["../../src/routes/respondWithToken.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,MAAM,CAAA;AAKnC;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,CAAC,EAAE,OAAO;;;;;;;;;mEAmD1C"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"createOpenApiDefinition.d.ts","sourceRoot":"","sources":["../../src/utils/createOpenApiDefinition.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAA;AAEnE,uEAAuE;AACvE,wBAAgB,uBAAuB,CACrC,eAAe,EAAE,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,oBAAoB,GAAG,WAAW,CAAC,oBAAoB,CAAC,GACjG,WAAW,CAAC,QAAQ,CAMtB"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"findPreferredResponseKey.d.ts","sourceRoot":"","sources":["../../src/utils/findPreferredResponseKey.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,wBAAgB,wBAAwB,CAAC,SAAS,CAAC,EAAE,MAAM,EAAE,sBAQ5D"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"findPreferredResponseKey.test.d.ts","sourceRoot":"","sources":["../../src/utils/findPreferredResponseKey.test.ts"],"names":[],"mappings":""}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"getOpenAuthTokenUrls.d.ts","sourceRoot":"","sources":["../../src/utils/getOpenAuthTokenUrls.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAA0B,MAAM,uBAAuB,CAAA;AAE5E;;GAEG;AACH,wBAAgB,cAAc,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAYlD;AAiBD,wBAAgB,oBAAoB,CAAC,MAAM,CAAC,EAAE,OAAO,CAAC,QAAQ,GAAG,MAAM,EAAE,CAgCxE"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"getOpenAuthTokenUrls.test.d.ts","sourceRoot":"","sources":["../../src/utils/getOpenAuthTokenUrls.test.ts"],"names":[],"mappings":""}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"handleAuthentication.d.ts","sourceRoot":"","sources":["../../src/utils/handleAuthentication.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAA;AACpD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,MAAM,CAAA;AAGnC;;GAEG;AACH,wBAAgB,oBAAoB,CAAC,MAAM,CAAC,EAAE,OAAO,CAAC,QAAQ,EAAE,SAAS,CAAC,EAAE,OAAO,CAAC,SAAS,IAC7E,GAAG,OAAO,EAAE,MAAM,MAAM,OAAO,CAAC,IAAI,CAAC,KAAG,OAAO,CAAC,QAAQ,GAAG,IAAI,CAAC,CAmH/E"}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../src/utils/handleAuthentication.ts"],
|
|
4
|
-
"sourcesContent": ["import type { OpenAPI } from '@scalar/openapi-types'\nimport type { Context } from 'hono'\nimport { getCookie } from 'hono/cookie'\n\n/**\n * Handles authentication for incoming requests based on the OpenAPI specification.\n */\nexport function handleAuthentication(schema?: OpenAPI.Document, operation?: OpenAPI.Operation) {\n return async (c: Context, next: () => Promise<void>): Promise<Response | void> => {\n const operationSecuritySchemes = operation?.security || schema?.security\n\n if (operationSecuritySchemes && operationSecuritySchemes.length > 0) {\n let isAuthenticated = false\n let authScheme = ''\n\n for (const securityRequirement of operationSecuritySchemes) {\n let securitySchemeAuthenticated = true\n\n for (const [schemeName] of Object.entries(securityRequirement)) {\n const scheme = schema?.components?.securitySchemes?.[schemeName]\n\n if (scheme) {\n switch (scheme.type) {\n case 'http':\n if (scheme.scheme === 'basic') {\n authScheme = 'Basic'\n const authHeader = c.req.header('Authorization')\n\n if (authHeader?.startsWith('Basic ')) {\n isAuthenticated = true\n }\n } else if (scheme.scheme === 'bearer') {\n authScheme = 'Bearer'\n const authHeader = c.req.header('Authorization')\n\n if (authHeader?.startsWith('Bearer ')) {\n isAuthenticated = true\n }\n }\n break\n case 'apiKey':\n authScheme = `ApiKey ${scheme.name}`\n\n if (scheme.in === 'header') {\n const apiKey = c.req.header(scheme.name)\n if (apiKey) {\n isAuthenticated = true\n }\n } else if (scheme.in === 'query') {\n const apiKey = c.req.query(scheme.name)\n\n if (apiKey) {\n isAuthenticated = true\n }\n } else if (scheme.in === 'cookie') {\n const apiKey = getCookie(c, scheme.name)\n\n if (apiKey) {\n isAuthenticated = true\n }\n }\n break\n case 'oauth2':\n authScheme = 'Bearer'\n // Handle OAuth 2.0 flows, including password grant\n if (c.req.header('Authorization')?.startsWith('Bearer ')) {\n isAuthenticated = true\n }\n break\n case 'openIdConnect':\n authScheme = 'Bearer'\n // Handle OpenID Connect similar to OAuth2\n if (c.req.header('Authorization')?.startsWith('Bearer ')) {\n isAuthenticated = true\n }\n break\n }\n }\n\n if (!isAuthenticated) {\n securitySchemeAuthenticated = false\n break\n }\n }\n\n if (securitySchemeAuthenticated) {\n isAuthenticated = true\n break\n }\n }\n\n if (!isAuthenticated) {\n let wwwAuthenticateValue = authScheme\n\n switch (authScheme) {\n case 'Basic':\n wwwAuthenticateValue += ' realm=\"Scalar Mock Server\", charset=\"UTF-8\"'\n break\n case 'Bearer':\n wwwAuthenticateValue +=\n ' realm=\"Scalar Mock Server\", error=\"invalid_token\", error_description=\"The access token is invalid or has expired\"'\n break\n case 'ApiKey':\n wwwAuthenticateValue += ` realm=\"Scalar Mock Server\", error=\"invalid_token\", error_description=\"Invalid or missing API key\"`\n break\n default:\n wwwAuthenticateValue = 'Bearer realm=\"Scalar Mock Server\"'\n }\n\n c.header('WWW-Authenticate', wwwAuthenticateValue)\n return c.json(\n {\n error: 'Unauthorized',\n message: 'Authentication is required to access this resource.',\n },\n 401,\n )\n }\n }\n\n // If all checks pass, continue to the next middleware\n await next()\n }\n}\n"],
|
|
5
|
-
"mappings": "AAEA,SAAS,iBAAiB;AAKnB,SAAS,qBAAqB,QAA2B,WAA+B;AAC7F,SAAO,OAAO,GAAY,SAAwD;AAChF,UAAM,2BAA2B,WAAW,YAAY,QAAQ;AAEhE,QAAI,4BAA4B,yBAAyB,SAAS,GAAG;AACnE,UAAI,kBAAkB;AACtB,UAAI,aAAa;AAEjB,iBAAW,uBAAuB,0BAA0B;AAC1D,YAAI,8BAA8B;AAElC,mBAAW,CAAC,UAAU,KAAK,OAAO,QAAQ,mBAAmB,GAAG;AAC9D,gBAAM,SAAS,QAAQ,YAAY,kBAAkB,UAAU;AAE/D,cAAI,QAAQ;AACV,oBAAQ,OAAO,MAAM;AAAA,cACnB,KAAK;AACH,oBAAI,OAAO,WAAW,SAAS;AAC7B,+BAAa;AACb,wBAAM,aAAa,EAAE,IAAI,OAAO,eAAe;AAE/C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AA,UACF,KAAK;AACH,oCAAwB;AACxB;AAAA,UACF;AACE,mCAAuB;AAAA,QAC3B;AAEA,UAAE,OAAO,oBAAoB,oBAAoB;AACjD,eAAO,EAAE;AAAA,UACP;AAAA,YACE,OAAO;AAAA,YACP,SAAS;AAAA,UACX;AAAA,UACA;AAAA,QACF;AAAA,MACF;AAAA,IACF;AAGA,UAAM,KAAK;AAAA,EACb;AACF;",
|
|
6
|
-
"names": []
|
|
7
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"honoRouteFromPath.d.ts","sourceRoot":"","sources":["../../src/utils/honoRouteFromPath.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,UAE7C"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"honoRouteFromPath.test.d.ts","sourceRoot":"","sources":["../../src/utils/honoRouteFromPath.test.ts"],"names":[],"mappings":""}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"isAuthenticationRequired.d.ts","sourceRoot":"","sources":["../../src/utils/isAuthenticationRequired.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAA;AAEtD;;GAEG;AACH,wBAAgB,wBAAwB,CAAC,QAAQ,CAAC,EAAE,SAAS,CAAC,yBAAyB,EAAE,GAAG,OAAO,CAiBlG"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"isAuthenticationRequired.test.d.ts","sourceRoot":"","sources":["../../src/utils/isAuthenticationRequired.test.ts"],"names":[],"mappings":""}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"logAuthenticationInstructions.d.ts","sourceRoot":"","sources":["../../src/utils/logAuthenticationInstructions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAA;AAIxD;;GAEG;AACH,wBAAgB,6BAA6B,CAAC,eAAe,EAAE,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC,oBAAoB,CAAC,QAmH9G"}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../src/utils/logAuthenticationInstructions.ts"],
|
|
4
|
-
"sourcesContent": ["import type { OpenAPIV3_1 } from '@scalar/openapi-types'\n\nimport { getPathFromUrl } from './getOpenAuthTokenUrls'\n\n/**\n * Log authentication instructions for different security schemes\n */\nexport function logAuthenticationInstructions(securitySchemes: Record<string, OpenAPIV3_1.SecuritySchemeObject>) {\n if (!securitySchemes || Object.keys(securitySchemes).length === 0) {\n return\n }\n\n console.log('Authentication:')\n console.log()\n\n Object.entries(securitySchemes).forEach(([_, scheme]) => {\n switch (scheme.type) {\n case 'apiKey':\n if (scheme.in === 'header') {\n console.log('\u2705 API Key Authentication')\n console.log(` Use any API key in the ${scheme.name} header`)\n console.log()\n console.log(` ${scheme.name}: YOUR_API_KEY_HERE`)\n console.log()\n } else if (scheme.in === 'query') {\n console.log('\u2705 API Key Authentication')\n console.log(` Use any API key in the ${scheme.name} query parameter:`)\n console.log()\n console.log(` ?${scheme.name}=YOUR_API_KEY_HERE`)\n console.log()\n } else if (scheme.in === 'cookie') {\n console.log('\u2705 API Key Authentication')\n console.log(` Use any API key in the ${scheme.name} cookie:`)\n console.log()\n console.log(` Cookie: ${scheme.name}=YOUR_API_KEY_HERE`)\n console.log()\n } else {\n console.error(`\u274C Unsupported API Key Location: ${scheme.in}`)\n }\n break\n case 'http':\n if (scheme.scheme === 'basic') {\n console.log('\u2705 HTTP Basic Authentication')\n console.log(' Use an Authorization header with any credentials (\"username:password\" in base64):')\n console.log()\n console.log(' Authorization: Basic dXNlcm5hbWU6cGFzc3dvcmQ=')\n console.log()\n } else if (scheme.scheme === 'bearer') {\n console.log('\u2705 Bearer Token Authentication')\n console.log(' Use an Authorization header with any bearer token')\n console.log()\n console.log(' Authorization: Bearer YOUR_TOKEN_HERE')\n console.log()\n } else {\n console.error('\u274C Unknown Security Scheme:', scheme)\n }\n\n break\n case 'oauth2':\n if (scheme.flows) {\n Object.keys(scheme.flows).forEach((flow) => {\n switch (flow) {\n case 'implicit':\n console.log('\u2705 OAuth 2.0 Implicit Flow')\n console.log(' Use the following URL to initiate the OAuth 2.0 Implicit Flow:')\n console.log()\n console.log(\n ` GET ${scheme?.flows?.implicit?.authorizationUrl || '/oauth/authorize'}?response_type=token&client_id=YOUR_CLIENT_ID&redirect_uri=YOUR_REDIRECT_URI&scope=YOUR_SCOPES`,\n )\n console.log()\n break\n case 'password':\n console.log('\u2705 OAuth 2.0 Password Flow')\n console.log(' Use the following URL to obtain an access token:')\n console.log()\n console.log(` POST ${getPathFromUrl(scheme?.flows?.password?.tokenUrl || '/oauth/token')}`)\n console.log(' Content-Type: application/x-www-form-urlencoded')\n console.log()\n console.log(\n ' grant_type=password&username=YOUR_USERNAME&password=YOUR_PASSWORD&client_id=YOUR_CLIENT_ID&client_secret=YOUR_CLIENT_SECRET',\n )\n console.log()\n break\n case 'clientCredentials':\n console.log('\u2705 OAuth 2.0 Client Credentials Flow')\n console.log(' Use the following URL to obtain an access token:')\n console.log()\n console.log(` POST ${getPathFromUrl(scheme?.flows?.clientCredentials?.tokenUrl || '/oauth/token')}`)\n console.log(' Content-Type: application/x-www-form-urlencoded')\n console.log()\n console.log(\n ' grant_type=client_credentials&client_id=YOUR_CLIENT_ID&client_secret=YOUR_CLIENT_SECRET',\n )\n console.log()\n break\n case 'authorizationCode':\n console.log('\u2705 OAuth 2.0 Authorization Code Flow')\n console.log(' Use the following URL to initiate the OAuth 2.0 Authorization Code Flow:')\n console.log()\n console.log(\n ' GET',\n `${getPathFromUrl(scheme?.flows?.authorizationCode?.authorizationUrl || '/oauth/authorize')}?redirect_uri=https://YOUR_REDIRECT_URI_HERE`,\n )\n console.log()\n break\n default:\n console.warn(`Unsupported OAuth 2.0 flow: ${flow}`)\n }\n })\n }\n break\n case 'openIdConnect':\n console.log('\u2705 OpenID Connect Authentication')\n console.log(' Use the following OpenID Connect discovery URL:')\n console.log()\n console.log(` ${getPathFromUrl(scheme.openIdConnectUrl || '/.well-known/openid-configuration')}`)\n console.log()\n break\n default:\n console.warn(`Unsupported security scheme type: ${scheme.type}`)\n }\n })\n}\n"],
|
|
5
|
-
"mappings": "AAEA,SAAS,sBAAsB;AAKxB,SAAS,8BAA8B,iBAAmE;AAC/G,MAAI,CAAC,mBAAmB,OAAO,KAAK,eAAe,EAAE,WAAW,GAAG;AACjE;AAAA,EACF;AAEA,UAAQ,IAAI,iBAAiB;AAC7B,UAAQ,IAAI;AAEZ,SAAO,QAAQ,eAAe,EAAE,QAAQ,CAAC,CAAC,GAAG,MAAM,MAAM;AACvD,YAAQ,OAAO,MAAM;AAAA,MACnB,KAAK;AACH,YAAI,OAAO,OAAO,UAAU;AAC1B,kBAAQ,IAAI,+BAA0B;AACtC,kBAAQ,IAAI,6BAA6B,OAAO,IAAI,SAAS;AAC7D,kBAAQ,IAAI;AACZ,kBAAQ,IAAI,MAAM,OAAO,IAAI,qBAAqB;AAClD,kBAAQ,IAAI;AAAA,QACd,WAAW,OAAO,OAAO,SAAS;AAChC,kBAAQ,IAAI,+BAA0B;AACtC,kBAAQ,IAAI,6BAA6B,OAAO,IAAI,mBAAmB;AACvE,kBAAQ,IAAI;AACZ,kBAAQ,IAAI,OAAO,OAAO,IAAI,oBAAoB;AAClD,kBAAQ,IAAI;AAAA,QACd,WAAW,OAAO,OAAO,UAAU;AACjC,kBAAQ,IAAI,+BAA0B;AACtC,kBAAQ,IAAI,6BAA6B,OAAO,IAAI,UAAU;AAC9D,kBAAQ,IAAI;AACZ,kBAAQ,IAAI,cAAc,OAAO,IAAI,oBAAoB;AACzD,kBAAQ,IAAI;AAAA,QACd,OAAO;AACL,kBAAQ,MAAM,wCAAmC,OAAO,EAAE,EAAE;AAAA,QAC9D;AACA;AAAA,MACF,KAAK;AACH,YAAI,OAAO,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A,gBACF;AACA,wBAAQ,IAAI;AACZ;AAAA,cACF,KAAK;AACH,wBAAQ,IAAI,0CAAqC;AACjD,wBAAQ,IAAI,6EAA6E;AACzF,wBAAQ,IAAI;AACZ,wBAAQ;AAAA,kBACN;AAAA,kBACA,GAAG,eAAe,QAAQ,OAAO,mBAAmB,oBAAoB,kBAAkB,CAAC;AAAA,gBAC7F;AACA,wBAAQ,IAAI;AACZ;AAAA,cACF;AACE,wBAAQ,KAAK,+BAA+B,IAAI,EAAE;AAAA,YACtD;AAAA,UACF,CAAC;AAAA,QACH;AACA;AAAA,MACF,KAAK;AACH,gBAAQ,IAAI,sCAAiC;AAC7C,gBAAQ,IAAI,oDAAoD;AAChE,gBAAQ,IAAI;AACZ,gBAAQ,IAAI,MAAM,eAAe,OAAO,oBAAoB,mCAAmC,CAAC,EAAE;AAClG,gBAAQ,IAAI;AACZ;AAAA,MACF;AACE,gBAAQ,KAAK,qCAAqC,OAAO,IAAI,EAAE;AAAA,IACnE;AAAA,EACF,CAAC;AACH;",
|
|
6
|
-
"names": []
|
|
7
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"setupAuthenticationRoutes.d.ts","sourceRoot":"","sources":["../../src/utils/setupAuthenticationRoutes.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAA0B,MAAM,uBAAuB,CAAA;AAC5E,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,MAAM,CAAA;AAOhC;;GAEG;AACH,wBAAgB,yBAAyB,CAAC,GAAG,EAAE,IAAI,EAAE,MAAM,CAAC,EAAE,OAAO,CAAC,QAAQ,QA4F7E"}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../src/utils/setupAuthenticationRoutes.ts"],
|
|
4
|
-
"sourcesContent": ["import type { OpenAPI, OpenAPIV3, OpenAPIV3_1 } from '@scalar/openapi-types'\nimport type { Hono } from 'hono'\n\nimport { respondWithAuthorizePage } from '@/routes/respondWithAuthorizePage'\nimport { respondWithToken } from '@/routes/respondWithToken'\n\nimport { getOpenAuthTokenUrls, getPathFromUrl } from './getOpenAuthTokenUrls'\n\n/**\n * Helper function to set up authentication routes for OAuth 2.0 flows\n */\nexport function setupAuthenticationRoutes(app: Hono, schema?: OpenAPI.Document) {\n const securitySchemes: Record<string, OpenAPIV3.SecuritySchemeObject | OpenAPIV3_1.SecuritySchemeObject> =\n schema?.components?.securitySchemes || {}\n\n // Set up authentication routes for OAuth 2.0 flows\n getOpenAuthTokenUrls(schema).forEach((tokenUrl) => {\n app.post(tokenUrl, (c) => {\n return c.json(\n {\n access_token: 'super-secret-access-token',\n token_type: 'Bearer',\n expires_in: 3600,\n refresh_token: 'example-refresh-token',\n },\n 200,\n {\n /**\n * When responding with an access token, the server must also include the additional\n * Cache-Control: no-store HTTP header to ensure clients do not cache this request.\n *\n * @see https://www.oauth.com/oauth2-servers/access-tokens/access-token-response/\n */\n 'Cache-Control': 'no-store',\n },\n )\n })\n })\n\n // Set up routes for different OAuth 2.0 flows\n const authorizeUrls = new Set<string>()\n const tokenUrls = new Set<string>()\n\n Object.entries(securitySchemes).forEach(([_, scheme]) => {\n if (scheme.type === 'oauth2') {\n if (scheme.flows?.authorizationCode) {\n const authorizeRoute = scheme.flows.authorizationCode.authorizationUrl ?? '/oauth/authorize'\n const tokenRoute = scheme.flows.authorizationCode.tokenUrl ?? '/oauth/token'\n\n authorizeUrls.add(getPathFromUrl(authorizeRoute))\n tokenUrls.add(tokenRoute)\n }\n\n if (scheme.flows?.implicit) {\n const authorizeRoute = scheme.flows.implicit.authorizationUrl ?? '/oauth/authorize'\n authorizeUrls.add(getPathFromUrl(authorizeRoute))\n }\n\n if (scheme.flows?.password) {\n const tokenRoute = scheme.flows.password.tokenUrl ?? '/oauth/token'\n tokenUrls.add(tokenRoute)\n }\n\n if (scheme.flows?.clientCredentials) {\n const tokenRoute = scheme.flows.clientCredentials.tokenUrl ?? '/oauth/token'\n tokenUrls.add(tokenRoute)\n }\n } else if (scheme.type === 'openIdConnect') {\n // Handle OpenID Connect configuration\n if (scheme.openIdConnectUrl) {\n const configPath = getPathFromUrl(scheme.openIdConnectUrl ?? '/.well-known/openid-configuration')\n\n // Add route for OpenID Connect configuration\n app.get(configPath, (c) => {\n return c.json({\n issuer: 'https://example.com',\n authorization_endpoint: '/oauth/authorize',\n token_endpoint: '/oauth/token',\n response_types_supported: ['code', 'token', 'id_token'],\n subject_types_supported: ['public'],\n id_token_signing_alg_values_supported: ['RS256'],\n })\n })\n\n // Add standard endpoints\n const authorizeRoute = '/oauth/authorize'\n const tokenRoute = '/oauth/token'\n\n authorizeUrls.add(getPathFromUrl(authorizeRoute))\n tokenUrls.add(tokenRoute)\n }\n }\n })\n\n // Set up unique authorization routes\n authorizeUrls.forEach((authorizeUrl) => {\n app.get(authorizeUrl, (c) => respondWithAuthorizePage(c, schema?.info?.title))\n })\n\n // Set up unique token routes\n tokenUrls.forEach((tokenUrl) => {\n app.post(tokenUrl, respondWithToken)\n })\n}\n"],
|
|
5
|
-
"mappings": "AAGA,SAAS,gCAAgC;AACzC,SAAS,wBAAwB;AAEjC,SAAS,sBAAsB,sBAAsB;AAK9C,SAAS,0BAA0B,KAAW,QAA2B;AAC9E,QAAM,kBACJ,QAAQ,YAAY,mBAAmB,CAAC;AAG1C,uBAAqB,MAAM,EAAE,QAAQ,CAAC,aAAa;AACjD,QAAI,KAAK,UAAU,CAAC,MAAM;AACxB,aAAO,EAAE;AAAA,QACP;AAAA,UACE,cAAc;AAAA,UACd,YAAY;AAAA,UACZ,YAAY;AAAA,UACZ,eAAe;AAAA,QACjB;AAAA,QACA;AAAA,QACA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,UAOE,iBAAiB;AAAA,QACnB;AAAA,MACF;AAAA,IACF,CAAC;AAAA,EACH,CAAC;AAGD,QAAM,gBAAgB,oBAAI,IAAY;AACtC,QAAM,YAAY,oBAAI,I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