@scalar/postman-to-openapi 0.5.2 → 0.5.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/CHANGELOG.md +6 -0
- package/dist/convert.js +240 -212
- package/dist/helpers/auth.js +116 -92
- package/dist/helpers/contact.js +24 -20
- package/dist/helpers/external-docs.js +33 -25
- package/dist/helpers/form-data.js +42 -36
- package/dist/helpers/license.js +21 -17
- package/dist/helpers/logo.js +22 -21
- package/dist/helpers/markdown.js +33 -30
- package/dist/helpers/parameters.js +119 -96
- package/dist/helpers/path-items.js +244 -202
- package/dist/helpers/post-response-scripts.js +12 -12
- package/dist/helpers/pre-request-scripts.js +12 -12
- package/dist/helpers/prune-document.js +42 -35
- package/dist/helpers/request-body.js +102 -92
- package/dist/helpers/responses.js +62 -57
- package/dist/helpers/schemas.js +43 -37
- package/dist/helpers/servers.js +83 -57
- package/dist/helpers/status-codes.js +40 -30
- package/dist/helpers/urls.js +74 -51
- package/dist/index.js +1 -5
- package/dist/types.js +1 -1
- package/package.json +6 -11
- package/dist/convert.js.map +0 -7
- package/dist/helpers/auth.js.map +0 -7
- package/dist/helpers/contact.js.map +0 -7
- package/dist/helpers/external-docs.js.map +0 -7
- package/dist/helpers/form-data.js.map +0 -7
- package/dist/helpers/license.js.map +0 -7
- package/dist/helpers/logo.js.map +0 -7
- package/dist/helpers/markdown.js.map +0 -7
- package/dist/helpers/parameters.js.map +0 -7
- package/dist/helpers/path-items.js.map +0 -7
- package/dist/helpers/post-response-scripts.js.map +0 -7
- package/dist/helpers/pre-request-scripts.js.map +0 -7
- package/dist/helpers/prune-document.js.map +0 -7
- package/dist/helpers/request-body.js.map +0 -7
- package/dist/helpers/responses.js.map +0 -7
- package/dist/helpers/schemas.js.map +0 -7
- package/dist/helpers/servers.js.map +0 -7
- package/dist/helpers/status-codes.js.map +0 -7
- package/dist/helpers/urls.js.map +0 -7
- package/dist/index.js.map +0 -7
- package/dist/types.js.map +0 -7
package/dist/helpers/urls.js
CHANGED
|
@@ -1,58 +1,81 @@
|
|
|
1
|
-
import { REGEX } from
|
|
1
|
+
import { REGEX } from '@scalar/helpers/regex/regex-helpers';
|
|
2
|
+
/**
|
|
3
|
+
* Parses a URL string into its component parts.
|
|
4
|
+
*/
|
|
2
5
|
function parseUrl(urlString) {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
const url = new URL(urlString);
|
|
7
|
+
return {
|
|
8
|
+
protocol: url.protocol,
|
|
9
|
+
hostname: url.hostname,
|
|
10
|
+
port: url.port,
|
|
11
|
+
};
|
|
9
12
|
}
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
+
/**
|
|
14
|
+
* Extracts the domain (including protocol and port if present) from a given URL.
|
|
15
|
+
*/
|
|
16
|
+
export function getDomainFromUrl(url) {
|
|
17
|
+
const { protocol, hostname, port } = parseUrl(url);
|
|
18
|
+
return `${protocol}//${hostname}${port ? `:${port}` : ''}`;
|
|
13
19
|
}
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
20
|
+
/**
|
|
21
|
+
* Extracts the path from a given URL, removing any Postman variables.
|
|
22
|
+
*/
|
|
23
|
+
export function extractPathFromUrl(url) {
|
|
24
|
+
if (!url) {
|
|
25
|
+
return '/';
|
|
26
|
+
}
|
|
27
|
+
// Remove scheme, domain, query parameters, and hash fragments
|
|
28
|
+
const path = url.replace(/^(?:https?:\/\/)?[^/]+(\/|$)/, '/').split(/[?#]/)[0] ?? '';
|
|
29
|
+
// Replace Postman variables and ensure single leading slash
|
|
30
|
+
const finalPath = ('/' + path.replace(/\{\{([^{}]{0,1000})\}\}/g, '{$1}').replace(/^\/+/, '')).replace(/\/\/+/g, '/');
|
|
31
|
+
return finalPath;
|
|
21
32
|
}
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
33
|
+
/**
|
|
34
|
+
* Normalizes a path by converting colon-style parameters to curly brace style
|
|
35
|
+
* e.g., '/users/:id' becomes '/users/{id}'
|
|
36
|
+
*/
|
|
37
|
+
export const normalizePath = (path) => path.replace(/:(\w+)/g, '{$1}');
|
|
38
|
+
/**
|
|
39
|
+
* Extracts parameter names from a path string.
|
|
40
|
+
* Handles double curly braces {{param}}, single curly braces {param}, and colon format :param.
|
|
41
|
+
*/
|
|
42
|
+
export function extractPathParameterNames(path) {
|
|
43
|
+
const params = new Set();
|
|
44
|
+
let match;
|
|
45
|
+
while ((match = REGEX.TEMPLATE_VARIABLE.exec(path)) !== null) {
|
|
46
|
+
// match[1] contains the parameter name from {{param}}
|
|
47
|
+
// match[2] contains the parameter name from {param}
|
|
48
|
+
// match[0].slice(1) gets the parameter name from :param
|
|
49
|
+
const param = match[1] || match[2] || match[0].slice(1);
|
|
50
|
+
params.add(param.trim());
|
|
51
|
+
}
|
|
52
|
+
return Array.from(params);
|
|
31
53
|
}
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
54
|
+
/**
|
|
55
|
+
* Extracts the server URL from a request URL string.
|
|
56
|
+
* Handles URLs with or without protocol, with ports, etc.
|
|
57
|
+
* Returns undefined if no valid server URL can be extracted.
|
|
58
|
+
*/
|
|
59
|
+
export function extractServerFromUrl(url) {
|
|
60
|
+
if (!url) {
|
|
61
|
+
return undefined;
|
|
62
|
+
}
|
|
63
|
+
try {
|
|
64
|
+
// Check if URL has a protocol
|
|
65
|
+
const protocolMatch = url.match(/^(https?:\/\/)/i);
|
|
66
|
+
const protocol = protocolMatch ? protocolMatch[1] : null;
|
|
67
|
+
// Extract domain from URL
|
|
68
|
+
const urlMatch = url.match(/^(?:https?:\/\/)?([^/?#]+)/i);
|
|
69
|
+
if (!urlMatch?.[1]) {
|
|
70
|
+
return undefined;
|
|
71
|
+
}
|
|
72
|
+
const hostPart = urlMatch[1];
|
|
73
|
+
// Preserve the original protocol if present, otherwise default to https
|
|
74
|
+
const serverUrl = protocol ? `${protocol}${hostPart}`.replace(/\/$/, '') : `https://${hostPart}`.replace(/\/$/, '');
|
|
75
|
+
return serverUrl;
|
|
76
|
+
}
|
|
77
|
+
catch (error) {
|
|
78
|
+
console.error(`Error extracting server from URL "${url}":`, error);
|
|
79
|
+
return undefined;
|
|
42
80
|
}
|
|
43
|
-
const hostPart = urlMatch[1];
|
|
44
|
-
const serverUrl = protocol ? `${protocol}${hostPart}`.replace(/\/$/, "") : `https://${hostPart}`.replace(/\/$/, "");
|
|
45
|
-
return serverUrl;
|
|
46
|
-
} catch (error) {
|
|
47
|
-
console.error(`Error extracting server from URL "${url}":`, error);
|
|
48
|
-
return void 0;
|
|
49
|
-
}
|
|
50
81
|
}
|
|
51
|
-
export {
|
|
52
|
-
extractPathFromUrl,
|
|
53
|
-
extractPathParameterNames,
|
|
54
|
-
extractServerFromUrl,
|
|
55
|
-
getDomainFromUrl,
|
|
56
|
-
normalizePath
|
|
57
|
-
};
|
|
58
|
-
//# sourceMappingURL=urls.js.map
|
package/dist/index.js
CHANGED
package/dist/types.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
export {};
|
package/package.json
CHANGED
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
"export",
|
|
20
20
|
"scalar"
|
|
21
21
|
],
|
|
22
|
-
"version": "0.5.
|
|
22
|
+
"version": "0.5.3",
|
|
23
23
|
"engines": {
|
|
24
24
|
"node": ">=22"
|
|
25
25
|
},
|
|
@@ -38,21 +38,16 @@
|
|
|
38
38
|
"CHANGELOG.md"
|
|
39
39
|
],
|
|
40
40
|
"dependencies": {
|
|
41
|
-
"@scalar/
|
|
42
|
-
"@scalar/
|
|
41
|
+
"@scalar/openapi-types": "0.6.1",
|
|
42
|
+
"@scalar/helpers": "0.4.2"
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
45
45
|
"@types/node": "^24.1.0",
|
|
46
|
-
"vite": "
|
|
47
|
-
"@scalar/build-tooling": "0.5.0"
|
|
46
|
+
"vite": "8.0.0"
|
|
48
47
|
},
|
|
49
48
|
"scripts": {
|
|
50
|
-
"build": "
|
|
51
|
-
"format": "scalar-format",
|
|
52
|
-
"lint:check": "scalar-lint-check",
|
|
53
|
-
"lint:fix": "scalar-lint-fix",
|
|
49
|
+
"build": "tsc -p tsconfig.build.json && tsc-alias -p tsconfig.build.json",
|
|
54
50
|
"test": "vitest",
|
|
55
|
-
"types:
|
|
56
|
-
"types:check": "scalar-types-check"
|
|
51
|
+
"types:check": "tsc --noEmit"
|
|
57
52
|
}
|
|
58
53
|
}
|
package/dist/convert.js.map
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../src/convert.ts"],
|
|
4
|
-
"sourcesContent": ["import type { OpenAPIV3_1 } from '@scalar/openapi-types'\n\nimport { processAuth } from '@/helpers/auth'\nimport { processContact } from '@/helpers/contact'\nimport { processExternalDocs } from '@/helpers/external-docs'\nimport { processLicense } from '@/helpers/license'\nimport { processLogo } from '@/helpers/logo'\nimport { processItem } from '@/helpers/path-items'\nimport { pruneDocument } from '@/helpers/prune-document'\nimport { analyzeServerDistribution } from '@/helpers/servers'\nimport { normalizePath } from '@/helpers/urls'\n\nimport type { Description, Item, ItemGroup, PostmanCollection } from './types'\n\nconst OPERATION_KEYS: readonly (keyof OpenAPIV3_1.PathItemObject)[] = [\n 'get',\n 'put',\n 'post',\n 'delete',\n 'options',\n 'head',\n 'patch',\n 'trace',\n]\n\nconst normalizeDescription = (description?: Description): string | undefined => {\n if (typeof description === 'string') {\n return description\n }\n\n return description?.content\n}\n\nconst parseCollectionInput = (postmanCollection: PostmanCollection | string): unknown => {\n if (typeof postmanCollection !== 'string') {\n return postmanCollection\n }\n\n try {\n return JSON.parse(postmanCollection) as PostmanCollection\n } catch (error) {\n const details = error instanceof Error ? error.message : 'Unknown parse error'\n const parseError = new Error(`Invalid Postman collection JSON: ${details}`)\n parseError.name = 'PostmanCollectionParseError'\n throw parseError\n }\n}\n\nconst validateCollectionShape = (collection: unknown): PostmanCollection => {\n if (!collection || typeof collection !== 'object') {\n throw new Error('Invalid Postman collection: expected an object')\n }\n\n const candidate = collection as Partial<PostmanCollection>\n\n if (!candidate.info) {\n throw new Error('Missing required info on Postman collection')\n }\n\n if (!candidate.item || !Array.isArray(candidate.item)) {\n throw new Error('Invalid Postman collection: item must be an array')\n }\n\n if (typeof candidate.info !== 'object') {\n throw new Error('Invalid Postman collection: info must be an object')\n }\n\n if (!candidate.info.name) {\n throw new Error('Missing required info.name on Postman collection')\n }\n\n if (!candidate.info.schema) {\n throw new Error('Invalid Postman collection: missing info.schema')\n }\n\n if (candidate.variable && !Array.isArray(candidate.variable)) {\n throw new Error('Invalid Postman collection: variable must be an array when provided')\n }\n\n return candidate as PostmanCollection\n}\n\n/**\n * Extracts tags from Postman collection folders.\n * We keep folder nesting using \" > \" so tag names stay readable while preserving hierarchy.\n * Requests do not produce tags; only folders are reflected as tags.\n */\nconst isItemGroup = (item: Item | ItemGroup): item is ItemGroup => 'item' in item && Array.isArray(item.item)\n\nconst extractTags = (items: PostmanCollection['item']): OpenAPIV3_1.TagObject[] => {\n const collectTags = (item: Item | ItemGroup, parentPath: string = ''): OpenAPIV3_1.TagObject[] => {\n if (!isItemGroup(item)) {\n return []\n }\n\n const nextPath = item.name ? (parentPath ? `${parentPath} > ${item.name}` : item.name) : parentPath\n const description = normalizeDescription(item.description)\n const currentTag: OpenAPIV3_1.TagObject[] = item.name?.length\n ? [\n {\n name: nextPath,\n ...(description && { description }),\n },\n ]\n : []\n\n return [...currentTag, ...item.item.flatMap((subItem) => collectTags(subItem, nextPath))]\n }\n\n return items.flatMap((item) => collectTags(item))\n}\n\nconst mergeSecuritySchemes = (\n openapi: OpenAPIV3_1.Document,\n securitySchemes?: OpenAPIV3_1.ComponentsObject['securitySchemes'],\n): void => {\n if (!securitySchemes || Object.keys(securitySchemes).length === 0) {\n return\n }\n\n openapi.components = openapi.components || {}\n openapi.components.securitySchemes = {\n ...(openapi.components.securitySchemes ?? {}),\n ...securitySchemes,\n }\n}\n\nconst mergePathItem = (\n paths: OpenAPIV3_1.PathsObject,\n normalizedPathKey: string,\n pathItem: OpenAPIV3_1.PathItemObject,\n): void => {\n const targetPath = (paths[normalizedPathKey] ?? {}) as OpenAPIV3_1.PathItemObject\n\n for (const [key, value] of Object.entries(pathItem) as [\n keyof OpenAPIV3_1.PathItemObject,\n OpenAPIV3_1.PathItemObject[keyof OpenAPIV3_1.PathItemObject],\n ][]) {\n if (value === undefined) {\n continue\n }\n\n const isOperationKey = OPERATION_KEYS.includes(key)\n\n if (isOperationKey && targetPath[key]) {\n const operationName = typeof key === 'string' ? key.toUpperCase() : String(key)\n console.warn(\n `Duplicate operation detected for ${operationName} ${normalizedPathKey}. Last operation will overwrite previous.`,\n )\n }\n\n targetPath[key] = value\n }\n\n paths[normalizedPathKey] = targetPath\n}\n\nconst cleanupOperations = (paths: OpenAPIV3_1.PathsObject): void => {\n Object.values(paths).forEach((pathItem) => {\n if (!pathItem) {\n return\n }\n\n OPERATION_KEYS.forEach((operationKey) => {\n const operation = pathItem[operationKey]\n if (!operation) {\n return\n }\n\n if ('parameters' in operation && operation.parameters?.length === 0) {\n delete operation.parameters\n }\n\n if ('requestBody' in operation && operation.requestBody && 'content' in operation.requestBody) {\n const content = operation.requestBody.content\n if (content && 'text/plain' in content) {\n const text = content['text/plain']\n if (!text?.schema || (text.schema && Object.keys(text.schema).length === 0)) {\n content['text/plain'] = {}\n }\n }\n }\n\n if (!operation.description) {\n delete operation.description\n }\n })\n })\n}\n\n/**\n * Converts a Postman Collection to an OpenAPI 3.1.0 document.\n * This function processes the collection's information, servers, authentication,\n * and items to create a corresponding OpenAPI structure.\n */\nexport function convert(postmanCollection: PostmanCollection | string): OpenAPIV3_1.Document {\n const collection = validateCollectionShape(parseCollectionInput(postmanCollection))\n\n // Extract title from collection info, fallback to 'API' if not provided\n const title = collection.info.name || 'API'\n\n // Look for version in collection variables, default to '1.0.0'\n const version = (collection.variable?.find((v) => v.key === 'version')?.value as string) || '1.0.0'\n\n // Handle different description formats in Postman\n const description = normalizeDescription(collection.info.description) || ''\n\n // Process license and contact information\n const license = processLicense(collection)\n const contact = processContact(collection)\n\n // Process logo information\n const logo = processLogo(collection)\n\n // Initialize the OpenAPI document with required fields\n const openapi: OpenAPIV3_1.Document = {\n openapi: '3.1.0',\n info: {\n title,\n version,\n ...(description && { description }),\n ...(license && { license }),\n ...(contact && { contact }),\n ...(logo && { 'x-logo': logo }),\n },\n paths: {},\n }\n\n // Process external docs\n const externalDocs = processExternalDocs(collection)\n if (externalDocs) {\n openapi.externalDocs = externalDocs\n }\n\n // Process authentication if present in the collection\n if (collection.auth) {\n const { securitySchemes, security } = processAuth(collection.auth)\n mergeSecuritySchemes(openapi, securitySchemes)\n openapi.security = security\n }\n\n // Process each item in the collection and merge into OpenAPI spec\n const allServerUsage: Array<{\n serverUrl: string\n path: string\n method: 'get' | 'put' | 'post' | 'delete' | 'options' | 'head' | 'patch' | 'trace'\n }> = []\n\n if (collection.item) {\n // Extract tags from folders\n const tags = extractTags(collection.item)\n if (tags.length > 0) {\n openapi.tags = tags\n }\n\n collection.item.forEach((item) => {\n const { paths: itemPaths, components: itemComponents, serverUsage } = processItem(item)\n\n // Collect server usage information\n allServerUsage.push(...serverUsage)\n\n // Merge paths from the current item\n openapi.paths = openapi.paths || {}\n for (const [pathKey, pathItem] of Object.entries(itemPaths)) {\n // Convert colon-style params to curly brace style\n const normalizedPathKey = normalizePath(pathKey)\n\n if (!pathItem) {\n continue\n }\n\n mergePathItem(openapi.paths, normalizedPathKey, pathItem)\n }\n\n // Merge security schemes from the current item\n if (itemComponents?.securitySchemes) {\n mergeSecuritySchemes(openapi, itemComponents.securitySchemes)\n }\n })\n }\n\n // Extract all unique paths from the document\n const allUniquePaths = new Set<string>()\n if (openapi.paths) {\n for (const pathKey of Object.keys(openapi.paths)) {\n allUniquePaths.add(pathKey)\n }\n }\n\n // Analyze server distribution and place servers at appropriate levels\n const serverPlacement = analyzeServerDistribution(allServerUsage, allUniquePaths)\n\n // Add servers to document level\n if (serverPlacement.document.length > 0) {\n openapi.servers = serverPlacement.document\n }\n\n // Add servers to path items\n if (openapi.paths) {\n for (const [path, servers] of serverPlacement.pathItems.entries()) {\n const normalizedPathKey = normalizePath(path)\n const pathItem = openapi.paths[normalizedPathKey]\n if (pathItem) {\n pathItem.servers = servers\n }\n }\n\n // Add servers to operations\n for (const [path, methods] of serverPlacement.operations.entries()) {\n const normalizedPathKey = normalizePath(path)\n const pathItem = openapi.paths[normalizedPathKey]\n if (!pathItem) {\n continue\n }\n for (const [method, servers] of methods.entries()) {\n if (method in pathItem) {\n const operation = pathItem[method as keyof typeof pathItem]\n if (operation && typeof operation === 'object' && 'responses' in operation) {\n operation.servers = servers\n }\n }\n }\n }\n }\n\n // Clean up the generated paths\n if (openapi.paths) {\n cleanupOperations(openapi.paths)\n }\n\n // Remove empty components object\n if (Object.keys(openapi.components || {}).length === 0) {\n delete openapi.components\n }\n\n return pruneDocument(openapi)\n}\n"],
|
|
5
|
-
"mappings": "AAEA,SAAS,mBAAmB;AAC5B,SAAS,sBAAsB;AAC/B,SAAS,2BAA2B;AACpC,SAAS,sBAAsB;AAC/B,SAAS,mBAAmB;AAC5B,SAAS,mBAAmB;AAC5B,SAAS,qBAAqB;AAC9B,SAAS,iCAAiC;AAC1C,SAAS,qBAAqB;AAI9B,MAAM,iBAAgE;AAAA,EACpE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AAEA,MAAM,uBAAuB,CAAC,gBAAkD;AAC9E,MAAI,OAAO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Q,OAAO;AACjB,eAAW,CAAC,MAAM,OAAO,KAAK,gBAAgB,UAAU,QAAQ,GAAG;AACjE,YAAM,oBAAoB,cAAc,IAAI;AAC5C,YAAM,WAAW,QAAQ,MAAM,iBAAiB;AAChD,UAAI,UAAU;AACZ,iBAAS,UAAU;AAAA,MACrB;AAAA,IACF;AAGA,eAAW,CAAC,MAAM,OAAO,KAAK,gBAAgB,WAAW,QAAQ,GAAG;AAClE,YAAM,oBAAoB,cAAc,IAAI;AAC5C,YAAM,WAAW,QAAQ,MAAM,iBAAiB;AAChD,UAAI,CAAC,UAAU;AACb;AAAA,MACF;AACA,iBAAW,CAAC,QAAQ,OAAO,KAAK,QAAQ,QAAQ,GAAG;AACjD,YAAI,UAAU,UAAU;AACtB,gBAAM,YAAY,SAAS,MAA+B;AAC1D,cAAI,aAAa,OAAO,cAAc,YAAY,eAAe,WAAW;AAC1E,sBAAU,UAAU;AAAA,UACtB;AAAA,QACF;AAAA,MACF;AAAA,IACF;AAAA,EACF;AAGA,MAAI,QAAQ,OAAO;AACjB,sBAAkB,QAAQ,KAAK;AAAA,EACjC;AAGA,MAAI,OAAO,KAAK,QAAQ,cAAc,CAAC,CAAC,EAAE,WAAW,GAAG;AACtD,WAAO,QAAQ;AAAA,EACjB;AAEA,SAAO,cAAc,OAAO;AAC9B;",
|
|
6
|
-
"names": []
|
|
7
|
-
}
|
package/dist/helpers/auth.js.map
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../src/helpers/auth.ts"],
|
|
4
|
-
"sourcesContent": ["import type { OpenAPIV3_1 } from '@scalar/openapi-types'\n\nimport type { Auth } from '@/types'\n\n// Constants for security scheme names and URLs\nconst AUTH_SCHEMES = {\n API_KEY: 'apikeyAuth',\n BASIC: 'basicAuth',\n BEARER: 'bearerAuth',\n OAUTH2: 'oauth2Auth',\n} as const\n\nconst OAUTH2_DEFAULTS = {\n AUTHORIZE_URL: '/oauth/authorize',\n TOKEN_URL: '/oauth/token',\n} as const\n\ntype SecurityConfig = {\n scheme: OpenAPIV3_1.SecuritySchemeObject\n requirement: OpenAPIV3_1.SecurityRequirementObject\n}\n\n/**\n * Creates security configuration for API key authentication\n */\nfunction createApiKeyConfig(): SecurityConfig {\n return {\n scheme: {\n type: 'apiKey',\n name: 'api_key',\n in: 'header',\n },\n requirement: { [AUTH_SCHEMES.API_KEY]: [] },\n }\n}\n\n/**\n * Creates security configuration for Basic authentication\n */\nfunction createBasicConfig(): SecurityConfig {\n return {\n scheme: {\n type: 'http',\n scheme: 'basic',\n },\n requirement: { [AUTH_SCHEMES.BASIC]: [] },\n }\n}\n\n/**\n * Creates security configuration for Bearer token authentication\n */\nfunction createBearerConfig(): SecurityConfig {\n return {\n scheme: {\n type: 'http',\n scheme: 'bearer',\n },\n requirement: { [AUTH_SCHEMES.BEARER]: [] },\n }\n}\n\n/**\n * Creates security configuration for OAuth2 authentication\n * Extracts actual OAuth2 URLs and scopes from the Postman auth object\n */\nfunction createOAuth2Config(auth?: Auth): SecurityConfig {\n if (!auth) {\n return {\n scheme: {},\n requirement: {},\n }\n }\n\n const oauth2Attrs = auth.oauth2 || []\n const attrMap = new Map<string, string>()\n\n oauth2Attrs.forEach((attr) => {\n if (attr.key && attr.value !== undefined) {\n attrMap.set(attr.key, String(attr.value))\n }\n })\n\n const authUrl = attrMap.get('authUrl') || attrMap.get('authorizationUrl') || OAUTH2_DEFAULTS.AUTHORIZE_URL\n const tokenUrl = attrMap.get('accessTokenUrl') || attrMap.get('tokenUrl') || OAUTH2_DEFAULTS.TOKEN_URL\n const scopeValue = attrMap.get('scope') || ''\n\n // Parse scopes from the scope value (can be space or comma separated)\n const scopes: Record<string, string> = {}\n if (scopeValue) {\n const scopeList = scopeValue.split(/[,\\s]+/).filter(Boolean)\n scopeList.forEach((scope) => {\n scopes[scope] = scope\n })\n }\n\n return {\n scheme: {\n type: 'oauth2',\n flows: {\n authorizationCode: {\n authorizationUrl: authUrl,\n tokenUrl,\n scopes,\n },\n },\n },\n requirement: { [AUTH_SCHEMES.OAUTH2]: Object.keys(scopes) },\n }\n}\n\n/**\n * Creates security configuration for no authentication\n */\nfunction createNoAuthConfig(): SecurityConfig {\n return {\n scheme: {},\n requirement: {},\n }\n}\n\n/**\n * Maps authentication types to their configuration creators\n */\nconst AUTH_TYPE_HANDLERS: Record<string, (auth?: Auth) => SecurityConfig> = {\n apikey: createApiKeyConfig,\n basic: createBasicConfig,\n bearer: createBearerConfig,\n oauth2: createOAuth2Config,\n noauth: createNoAuthConfig,\n}\n\n/**\n * Processes authentication information from a Postman collection and updates\n * the OpenAPI document with the corresponding security schemes and requirements.\n * Supports API key, basic auth, bearer token, OAuth2, and no authentication types.\n */\nexport function processAuth(auth: Auth): {\n securitySchemes: Record<string, OpenAPIV3_1.SecuritySchemeObject>\n security: OpenAPIV3_1.SecurityRequirementObject[]\n} {\n const securitySchemes: Record<string, OpenAPIV3_1.SecuritySchemeObject> = {}\n const security: OpenAPIV3_1.SecurityRequirementObject[] = []\n\n try {\n const handler = AUTH_TYPE_HANDLERS[auth.type]\n if (!handler) {\n throw new Error(`Unsupported authentication type: ${auth.type}`)\n }\n\n const { scheme, requirement } = handler(auth)\n\n // Only add security schemes and requirements if they're not empty\n if (Object.keys(scheme).length > 0) {\n const schemeKey = `${auth.type}Auth`\n securitySchemes[schemeKey] = scheme\n security.push(requirement)\n }\n } catch (error) {\n console.error('Error processing authentication:', error)\n throw error\n }\n\n return { securitySchemes, security }\n}\n"],
|
|
5
|
-
"mappings": "AAKA,MAAM,eAAe;AAAA,EACnB,SAAS;AAAA,EACT,OAAO;AAAA,EACP,QAAQ;AAAA,EACR,QAAQ;AACV;AAEA,MAAM,kBAAkB;AAAA,EACtB,eAAe;AAAA,EACf,WAAW;AACb;AAUA,SAAS,qBAAqC;AAC5C,SAAO;AAAA,IACL,QAAQ;AAAA,MACN,MAAM;AAAA,MACN,MAAM;AAAA,MACN,IAAI;AAAA,IAC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ACN,OAAO;AAAA,QACL,mBAAmB;AAAA,UACjB,kBAAkB;AAAA,UAClB;AAAA,UACA;AAAA,QACF;AAAA,MACF;AAAA,IACF;AAAA,IACA,aAAa,EAAE,CAAC,aAAa,MAAM,GAAG,OAAO,KAAK,MAAM,EAAE;AAAA,EAC5D;AACF;AAKA,SAAS,qBAAqC;AAC5C,SAAO;AAAA,IACL,QAAQ,CAAC;AAAA,IACT,aAAa,CAAC;AAAA,EAChB;AACF;AAKA,MAAM,qBAAsE;AAAA,EAC1E,QAAQ;AAAA,EACR,OAAO;AAAA,EACP,QAAQ;AAAA,EACR,QAAQ;AAAA,EACR,QAAQ;AACV;AAOO,SAAS,YAAY,MAG1B;AACA,QAAM,kBAAoE,CAAC;AAC3E,QAAM,WAAoD,CAAC;AAE3D,MAAI;AACF,UAAM,UAAU,mBAAmB,KAAK,IAAI;AAC5C,QAAI,CAAC,SAAS;AACZ,YAAM,IAAI,MAAM,oCAAoC,KAAK,IAAI,EAAE;AAAA,IACjE;AAEA,UAAM,EAAE,QAAQ,YAAY,IAAI,QAAQ,IAAI;AAG5C,QAAI,OAAO,KAAK,MAAM,EAAE,SAAS,GAAG;AAClC,YAAM,YAAY,GAAG,KAAK,IAAI;AAC9B,sBAAgB,SAAS,IAAI;AAC7B,eAAS,KAAK,WAAW;AAAA,IAC3B;AAAA,EACF,SAAS,OAAO;AACd,YAAQ,MAAM,oCAAoC,KAAK;AACvD,UAAM;AAAA,EACR;AAEA,SAAO,EAAE,iBAAiB,SAAS;AACrC;",
|
|
6
|
-
"names": []
|
|
7
|
-
}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../src/helpers/contact.ts"],
|
|
4
|
-
"sourcesContent": ["import type { OpenAPIV3_1 } from '@scalar/openapi-types'\n\nimport type { PostmanCollection, Variable } from '@/types'\n\n// Constants for contact variable keys\nconst VARIABLE_KEYS = {\n NAME: 'contact.name',\n URL: 'contact.url',\n EMAIL: 'contact.email',\n} as const\n\n/**\n * Finds a specific variable in the collection by its key\n */\nfunction findVariable(collection: PostmanCollection, key: string): Variable | undefined {\n return collection.variable?.find((v) => v.key === key)\n}\n\n/**\n * Processes contact information from collection variables.\n * Returns an OpenAPI Contact Object if at least one contact field is present.\n */\nexport function processContact(collection: PostmanCollection): OpenAPIV3_1.ContactObject | undefined {\n const nameVar = findVariable(collection, VARIABLE_KEYS.NAME)\n const urlVar = findVariable(collection, VARIABLE_KEYS.URL)\n const emailVar = findVariable(collection, VARIABLE_KEYS.EMAIL)\n\n if (!nameVar?.value && !urlVar?.value && !emailVar?.value) {\n return undefined\n }\n\n return {\n ...(nameVar?.value && typeof nameVar.value === 'string' && { name: nameVar.value }),\n ...(urlVar?.value && typeof urlVar.value === 'string' && { url: urlVar.value }),\n ...(emailVar?.value && typeof emailVar.value === 'string' && { email: emailVar.value }),\n }\n}\n"],
|
|
5
|
-
"mappings": "AAKA,MAAM,gBAAgB;AAAA,EACpB,MAAM;AAAA,EACN,KAAK;AAAA,EACL,OAAO;AACT;AAKA,SAAS,aAAa,YAA+B,KAAmC;AACtF,SAAO,WAAW,UAAU,KAAK,CAAC,MAAM,EAAE,QAAQ,GAAG;AACvD;AAMO,SAAS,eAAe,YAAsE;AACnG,QAAM,UAAU,aAAa,YAAY,cAAc,IAAI;AAC3D,QAAM,SAAS,aAAa,YAAY,cAAc,GAAG;AACzD,QAAM,WAAW,aAAa,YAAY,cAAc,KAAK;AAE7D,MAAI,CAAC,SAAS,SAAS,CAAC,QAAQ,SAAS,CAAC,UAAU,OAAO;AACzD,WAAO;AAAA,EACT;AAEA,SAAO;AAAA,IACL,GAAI,SAAS,SAAS,OAAO,QAAQ,UAAU,YAAY,EAAE,MAAM,QAAQ,MAAM;AAAA,IACjF,GAAI,QAAQ,SAAS,OAAO,OAAO,UAAU,YAAY,EAAE,KAAK,OAAO,MAAM;AAAA,IAC7E,GAAI,UAAU,SAAS,OAAO,SAAS,UAAU,YAAY,EAAE,OAAO,SAAS,MAAM;AAAA,EACvF;AACF;",
|
|
6
|
-
"names": []
|
|
7
|
-
}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../src/helpers/external-docs.ts"],
|
|
4
|
-
"sourcesContent": ["import type { OpenAPIV3_1 } from '@scalar/openapi-types'\n\nimport type { PostmanCollection, Variable } from '@/types'\n\n// Constants for variable keys\nconst VARIABLE_KEYS = {\n URL: 'externalDocs.url',\n DESCRIPTION: 'externalDocs.description',\n} as const\n\n/**\n * Finds a specific variable in the collection by its key\n */\nfunction findVariable(collection: PostmanCollection, key: string): Variable | undefined {\n return collection.variable?.find((v) => v.key === key)\n}\n\n/**\n * Processes the external documentation information from a Postman Collection.\n * This function checks for 'externalDocs.url' and 'externalDocs.description'\n * in the collection variables and creates an OpenAPI External Documentation Object\n * if the URL is present.\n */\nexport function processExternalDocs(\n collection: PostmanCollection,\n): OpenAPIV3_1.ExternalDocumentationObject | undefined {\n try {\n const urlVariable = findVariable(collection, VARIABLE_KEYS.URL)\n const descriptionVariable = findVariable(collection, VARIABLE_KEYS.DESCRIPTION)\n\n if (!urlVariable?.value) {\n return undefined\n }\n\n if (typeof urlVariable.value !== 'string') {\n throw new Error('External docs URL must be a string')\n }\n\n return {\n url: urlVariable.value,\n ...(descriptionVariable?.value &&\n typeof descriptionVariable.value === 'string' && {\n description: descriptionVariable.value,\n }),\n }\n } catch (error) {\n console.error('Error processing external docs:', error)\n throw error\n }\n}\n"],
|
|
5
|
-
"mappings": "AAKA,MAAM,gBAAgB;AAAA,EACpB,KAAK;AAAA,EACL,aAAa;AACf;AAKA,SAAS,aAAa,YAA+B,KAAmC;AACtF,SAAO,WAAW,UAAU,KAAK,CAAC,MAAM,EAAE,QAAQ,GAAG;AACvD;AAQO,SAAS,oBACd,YACqD;AACrD,MAAI;AACF,UAAM,cAAc,aAAa,YAAY,cAAc,GAAG;AAC9D,UAAM,sBAAsB,aAAa,YAAY,cAAc,WAAW;AAE9E,QAAI,CAAC,aAAa,OAAO;AACvB,aAAO;AAAA,IACT;AAEA,QAAI,OAAO,YAAY,UAAU,UAAU;AACzC,YAAM,IAAI,MAAM,oCAAoC;AAAA,IACtD;AAEA,WAAO;AAAA,MACL,KAAK,YAAY;AAAA,MACjB,GAAI,qBAAqB,SACvB,OAAO,oBAAoB,UAAU,YAAY;AAAA,QAC/C,aAAa,oBAAoB;AAAA,MACnC;AAAA,IACJ;AAAA,EACF,SAAS,OAAO;AACd,YAAQ,MAAM,mCAAmC,KAAK;AACtD,UAAM;AAAA,EACR;AACF;",
|
|
6
|
-
"names": []
|
|
7
|
-
}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../src/helpers/form-data.ts"],
|
|
4
|
-
"sourcesContent": ["import type { OpenAPIV3_1 } from '@scalar/openapi-types'\n\nimport type { FormParameter } from '@/types'\n\n/**\n * Processes form data parameters from a Postman request and converts them into an OpenAPI schema.\n * Handles file uploads, required fields, and descriptions.\n */\nexport function processFormDataSchema(formdata: FormParameter[]): OpenAPIV3_1.SchemaObject {\n const schema: OpenAPIV3_1.SchemaObject = {\n type: 'object',\n properties: {},\n required: [],\n }\n\n formdata.forEach((item: FormParameter) => {\n if (!schema.properties) {\n return\n }\n\n const property: OpenAPIV3_1.SchemaObject = {\n type: 'string',\n }\n\n // Add description if present, handling both string and object descriptions\n if (item.description) {\n const descriptionText = typeof item.description === 'string' ? item.description : item.description.content || ''\n\n property.description = descriptionText.replace(' [required]', '')\n\n // If [required] was present, add to required array\n if (descriptionText.includes('[required]')) {\n schema.required?.push(item.key)\n }\n }\n\n // Handle file type fields\n if (item.type === 'file') {\n property.format = 'binary'\n } else {\n property.example = item.value\n }\n\n // Add x-scalar-disabled extension if parameter is disabled\n if (item.disabled === true) {\n property['x-scalar-disabled'] = true\n }\n\n schema.properties[item.key] = property\n })\n\n // Only keep required array if it has items\n if (schema.required?.length === 0) {\n delete schema.required\n }\n\n return schema\n}\n"],
|
|
5
|
-
"mappings": "AAQO,SAAS,sBAAsB,UAAqD;AACzF,QAAM,SAAmC;AAAA,IACvC,MAAM;AAAA,IACN,YAAY,CAAC;AAAA,IACb,UAAU,CAAC;AAAA,EACb;AAEA,WAAS,QAAQ,CAAC,SAAwB;AACxC,QAAI,CAAC,OAAO,YAAY;AACtB;AAAA,IACF;AAEA,UAAM,WAAqC;AAAA,MACzC,MAAM;AAAA,IACR;AAGA,QAAI,KAAK,aAAa;AACpB,YAAM,kBAAkB,OAAO,KAAK,gBAAgB,WAAW,KAAK,cAAc,KAAK,YAAY,WAAW;AAE9G,eAAS,cAAc,gBAAgB,QAAQ,eAAe,EAAE;AAGhE,UAAI,gBAAgB,SAAS,YAAY,GAAG;AAC1C,eAAO,UAAU,KAAK,KAAK,GAAG;AAAA,MAChC;AAAA,IACF;AAGA,QAAI,KAAK,SAAS,QAAQ;AACxB,eAAS,SAAS;AAAA,IACpB,OAAO;AACL,eAAS,UAAU,KAAK;AAAA,IAC1B;AAGA,QAAI,KAAK,aAAa,MAAM;AAC1B,eAAS,mBAAmB,IAAI;AAAA,IAClC;AAEA,WAAO,WAAW,KAAK,GAAG,IAAI;AAAA,EAChC,CAAC;AAGD,MAAI,OAAO,UAAU,WAAW,GAAG;AACjC,WAAO,OAAO;AAAA,EAChB;AAEA,SAAO;AACT;",
|
|
6
|
-
"names": []
|
|
7
|
-
}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../src/helpers/license.ts"],
|
|
4
|
-
"sourcesContent": ["import type { OpenAPIV3_1 } from '@scalar/openapi-types'\n\nimport type { PostmanCollection, Variable } from '@/types'\n\n// Constants for license variable keys\nconst VARIABLE_KEYS = {\n NAME: 'license.name',\n URL: 'license.url',\n} as const\n\n/**\n * Finds a specific variable in the collection by its key\n */\nfunction findVariable(collection: PostmanCollection, key: string): Variable | undefined {\n return collection.variable?.find((v) => v.key === key)\n}\n\n/**\n * Processes license information from collection variables.\n * Returns an OpenAPI License Object if the license name is present.\n */\nexport function processLicense(collection: PostmanCollection): OpenAPIV3_1.LicenseObject | undefined {\n const nameVar = findVariable(collection, VARIABLE_KEYS.NAME)\n if (!nameVar?.value || typeof nameVar.value !== 'string') {\n return undefined\n }\n\n const urlVar = findVariable(collection, VARIABLE_KEYS.URL)\n return {\n name: nameVar.value,\n ...(urlVar?.value && typeof urlVar.value === 'string' && { url: urlVar.value }),\n }\n}\n"],
|
|
5
|
-
"mappings": "AAKA,MAAM,gBAAgB;AAAA,EACpB,MAAM;AAAA,EACN,KAAK;AACP;AAKA,SAAS,aAAa,YAA+B,KAAmC;AACtF,SAAO,WAAW,UAAU,KAAK,CAAC,MAAM,EAAE,QAAQ,GAAG;AACvD;AAMO,SAAS,eAAe,YAAsE;AACnG,QAAM,UAAU,aAAa,YAAY,cAAc,IAAI;AAC3D,MAAI,CAAC,SAAS,SAAS,OAAO,QAAQ,UAAU,UAAU;AACxD,WAAO;AAAA,EACT;AAEA,QAAM,SAAS,aAAa,YAAY,cAAc,GAAG;AACzD,SAAO;AAAA,IACL,MAAM,QAAQ;AAAA,IACd,GAAI,QAAQ,SAAS,OAAO,OAAO,UAAU,YAAY,EAAE,KAAK,OAAO,MAAM;AAAA,EAC/E;AACF;",
|
|
6
|
-
"names": []
|
|
7
|
-
}
|
package/dist/helpers/logo.js.map
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../src/helpers/logo.ts"],
|
|
4
|
-
"sourcesContent": ["import type { PostmanCollection } from '@/types'\n\n/**\n * Processes logo information from a Postman Collection.\n * This function extracts logo-related variables from the collection\n * and constructs an object with logo properties.\n */\nexport function processLogo(postmanCollection: PostmanCollection) {\n const logoVariables = postmanCollection.variable?.filter((v) => v.key?.startsWith('x-logo.')) || []\n if (logoVariables.length === 0) {\n return null\n }\n\n const logo: Record<string, string> = {}\n logoVariables.forEach((v) => {\n if (v.key) {\n const key = v.key.replace('x-logo.', '').replace('Var', '')\n logo[key] = v.value as string\n }\n })\n\n return {\n url: logo.url,\n backgroundColor: logo.backgroundColor,\n altText: logo.altText,\n href: logo.href,\n }\n}\n"],
|
|
5
|
-
"mappings": "AAOO,SAAS,YAAY,mBAAsC;AAChE,QAAM,gBAAgB,kBAAkB,UAAU,OAAO,CAAC,MAAM,EAAE,KAAK,WAAW,SAAS,CAAC,KAAK,CAAC;AAClG,MAAI,cAAc,WAAW,GAAG;AAC9B,WAAO;AAAA,EACT;AAEA,QAAM,OAA+B,CAAC;AACtC,gBAAc,QAAQ,CAAC,MAAM;AAC3B,QAAI,EAAE,KAAK;AACT,YAAM,MAAM,EAAE,IAAI,QAAQ,WAAW,EAAE,EAAE,QAAQ,OAAO,EAAE;AAC1D,WAAK,GAAG,IAAI,EAAE;AAAA,IAChB;AAAA,EACF,CAAC;AAED,SAAO;AAAA,IACL,KAAK,KAAK;AAAA,IACV,iBAAiB,KAAK;AAAA,IACtB,SAAS,KAAK;AAAA,IACd,MAAM,KAAK;AAAA,EACb;AACF;",
|
|
6
|
-
"names": []
|
|
7
|
-
}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../src/helpers/markdown.ts"],
|
|
4
|
-
"sourcesContent": ["import type { TableCell, TableObject } from '@/types'\n\nconst supHeaders = ['object', 'name', 'description', 'example', 'type', 'required']\n\n/**\n * Parses a Markdown table and returns an object representation.\n */\nexport function parseMdTable(md: string): TableObject {\n const lines = md.split('\\n').filter((line) => line.trim() !== '')\n if (typeof lines[0] === 'undefined' || lines.length < 3) {\n return {}\n }\n\n const header = lines[0]\n .split('|')\n .map((cell) => cell.trim())\n .filter(Boolean)\n if (!header.includes('object') || !header.includes('name')) {\n return {}\n }\n\n const headers = header.map((h) => (supHeaders.includes(h) ? h : false))\n\n const rows = lines.slice(2).map((line) =>\n line\n .split('|')\n .map((cell) => cell.trim())\n .filter(Boolean),\n )\n\n const tableObj: TableObject = rows.reduce((accTable: TableObject, cell) => {\n const cellObj: TableCell = cell.reduce((accCell: TableCell, field, index) => {\n if (headers[index] && typeof headers[index] === 'string') {\n accCell[headers[index] as string] = field\n }\n return accCell\n }, {})\n if (cellObj.name) {\n accTable[cellObj.name] = cellObj\n }\n return accTable\n }, {})\n\n return tableObj\n}\n"],
|
|
5
|
-
"mappings": "AAEA,MAAM,aAAa,CAAC,UAAU,QAAQ,eAAe,WAAW,QAAQ,UAAU;AAK3E,SAAS,aAAa,IAAyB;AACpD,QAAM,QAAQ,GAAG,MAAM,IAAI,EAAE,OAAO,CAAC,SAAS,KAAK,KAAK,MAAM,EAAE;AAChE,MAAI,OAAO,MAAM,CAAC,MAAM,eAAe,MAAM,SAAS,GAAG;AACvD,WAAO,CAAC;AAAA,EACV;AAEA,QAAM,SAAS,MAAM,CAAC,EACnB,MAAM,GAAG,EACT,IAAI,CAAC,SAAS,KAAK,KAAK,CAAC,EACzB,OAAO,OAAO;AACjB,MAAI,CAAC,OAAO,SAAS,QAAQ,KAAK,CAAC,OAAO,SAAS,MAAM,GAAG;AAC1D,WAAO,CAAC;AAAA,EACV;AAEA,QAAM,UAAU,OAAO,IAAI,CAAC,MAAO,WAAW,SAAS,CAAC,IAAI,IAAI,KAAM;AAEtE,QAAM,OAAO,MAAM,MAAM,CAAC,EAAE;AAAA,IAAI,CAAC,SAC/B,KACG,MAAM,GAAG,EACT,IAAI,CAAC,SAAS,KAAK,KAAK,CAAC,EACzB,OAAO,OAAO;AAAA,EACnB;AAEA,QAAM,WAAwB,KAAK,OAAO,CAAC,UAAuB,SAAS;AACzE,UAAM,UAAqB,KAAK,OAAO,CAAC,SAAoB,OAAO,UAAU;AAC3E,UAAI,QAAQ,KAAK,KAAK,OAAO,QAAQ,KAAK,MAAM,UAAU;AACxD,gBAAQ,QAAQ,KAAK,CAAW,IAAI;AAAA,MACtC;AACA,aAAO;AAAA,IACT,GAAG,CAAC,CAAC;AACL,QAAI,QAAQ,MAAM;AAChB,eAAS,QAAQ,IAAI,IAAI;AAAA,IAC3B;AACA,WAAO;AAAA,EACT,GAAG,CAAC,CAAC;AAEL,SAAO;AACT;",
|
|
6
|
-
"names": []
|
|
7
|
-
}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../src/helpers/parameters.ts"],
|
|
4
|
-
"sourcesContent": ["import type { OpenAPIV3_1 } from '@scalar/openapi-types'\n\nimport type { Header, Request } from '@/types'\n\nimport { inferSchemaType } from './schemas'\n\n/**\n * Extracts parameters from a Postman request and converts them to OpenAPI parameter objects.\n * Processes query, path, and header parameters from the request URL and headers.\n */\nexport function extractParameters(request: Request): OpenAPIV3_1.ParameterObject[] {\n const parameters: OpenAPIV3_1.ParameterObject[] = []\n const parameterMap: Map<string, OpenAPIV3_1.ParameterObject> = new Map()\n\n if (typeof request === 'string' || !request.url) {\n return parameters\n }\n\n const url = typeof request.url === 'string' ? { raw: request.url } : request.url\n\n // Process query parameters\n if (url.query) {\n url.query.forEach((param) => {\n const paramObj = createParameterObject(param, 'query')\n if (paramObj.name) {\n parameterMap.set(paramObj.name, paramObj)\n }\n })\n }\n\n // Process path parameters\n if (url.variable) {\n url.variable.forEach((param) => {\n const paramObj = createParameterObject(param, 'path')\n if (paramObj.name) {\n parameterMap.set(paramObj.name, paramObj)\n }\n })\n }\n\n // Include variables extracted from url.path array\n if (url.path) {\n const pathArray = Array.isArray(url.path) ? url.path : [url.path]\n const extractedVariables = extractPathVariablesFromPathArray(pathArray)\n extractedVariables.forEach((varName) => {\n if (!parameterMap.has(varName)) {\n parameterMap.set(varName, {\n name: varName,\n in: 'path',\n required: true,\n schema: {\n type: 'string',\n },\n })\n }\n })\n }\n\n // Process header parameters\n if (request.header && Array.isArray(request.header)) {\n request.header.forEach((header: Header) => {\n const paramObj = createParameterObject(header, 'header')\n if (paramObj.name) {\n parameterMap.set(paramObj.name, paramObj)\n }\n })\n }\n\n return Array.from(parameterMap.values())\n}\n\n/**\n * Helper function to extract variables from the url.path array.\n */\nfunction extractPathVariablesFromPathArray(pathArray: (string | { type: string; value: string })[]): string[] {\n const variables: string[] = []\n const variableRegex = /{{\\s*([\\w.-]+)\\s*}}/\n\n pathArray.forEach((segment) => {\n const segmentString = typeof segment === 'string' ? segment : segment.value\n const match = segmentString.match(variableRegex)\n if (match?.[1]) {\n variables.push(match[1])\n }\n })\n\n return variables\n}\n\n/**\n * Creates an OpenAPI parameter object from a Postman parameter.\n */\nexport function createParameterObject(param: any, paramIn: 'query' | 'path' | 'header'): OpenAPIV3_1.ParameterObject {\n const parameter: OpenAPIV3_1.ParameterObject = {\n name: param.key || '',\n in: paramIn,\n description: param.description,\n }\n\n // Path parameters are always required in OpenAPI\n if (paramIn === 'path') {\n parameter.required = true\n } else if (paramIn === 'query') {\n // Check if the parameter is required based on description or name\n const isRequired =\n param.description?.toLowerCase().includes('[required]') || (param.key && param.key.toLowerCase() === 'required')\n\n if (isRequired) {\n parameter.required = true\n // Remove '[required]' from the description\n if (parameter.description) {\n parameter.description = parameter.description.replace(/\\[required\\]/gi, '').trim()\n }\n }\n }\n\n if (param.value !== undefined) {\n parameter.example = param.value\n // For path parameters, prefer string type unless value is explicitly a number type\n // This prevents converting string IDs like \"testId\" to integers\n if (paramIn === 'path') {\n // Path parameters are typically strings (IDs, slugs, etc.)\n // Only use number/integer if the value is actually a number type, not a string\n if (typeof param.value === 'number') {\n parameter.schema = inferSchemaType(param.value)\n } else {\n // For strings (including empty strings), default to string type\n parameter.schema = { type: 'string' }\n }\n } else {\n parameter.schema = inferSchemaType(param.value)\n }\n } else {\n parameter.schema = { type: 'string' } // Default to string if no value is provided\n }\n\n // Add x-scalar-disabled extension if parameter is disabled\n if (param.disabled === true) {\n // @ts-expect-error - x-scalar-disabled is not a valid parameter object property\n parameter['x-scalar-disabled'] = true\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AA,IAChD;AAAA,EACF,OAAO;AACL,cAAU,SAAS,EAAE,MAAM,SAAS;AAAA,EACtC;AAGA,MAAI,MAAM,aAAa,MAAM;AAE3B,cAAU,mBAAmB,IAAI;AAAA,EACnC;AAEA,SAAO;AACT;",
|
|
6
|
-
"names": []
|
|
7
|
-
}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../src/helpers/path-items.ts"],
|
|
4
|
-
"sourcesContent": ["import type { OpenAPIV3_1 } from '@scalar/openapi-types'\n\nimport type { Item, ItemGroup } from '@/types'\n\nimport { processAuth } from './auth'\nimport { parseMdTable } from './markdown'\nimport { extractParameters } from './parameters'\nimport { processPostResponseScripts } from './post-response-scripts'\nimport { processPreRequestScripts } from './pre-request-scripts'\nimport { extractRequestBody } from './request-body'\nimport { extractResponses } from './responses'\nimport { extractPathFromUrl, extractPathParameterNames, extractServerFromUrl, normalizePath } from './urls'\n\ntype HttpMethods = 'get' | 'put' | 'post' | 'delete' | 'options' | 'head' | 'patch' | 'trace'\n\n/**\n * Information about server usage for an operation.\n */\nexport type ServerUsage = {\n serverUrl: string\n path: string\n method: HttpMethods\n}\n\nfunction ensureRequestBodyContent(requestBody: OpenAPIV3_1.RequestBodyObject): void {\n const content = requestBody.content ?? {}\n\n if (Object.keys(content).length === 0) {\n requestBody.content = {\n 'text/plain': {},\n }\n return\n }\n\n if ('text/plain' in content) {\n const textContent = content['text/plain']\n if (!textContent?.schema || (textContent.schema && Object.keys(textContent.schema).length === 0)) {\n content['text/plain'] = {}\n }\n }\n}\n\n/**\n * Processes a Postman collection item or item group and returns\n * the corresponding OpenAPI paths and components.\n * Handles nested item groups, extracts request details, and generates corresponding\n * OpenAPI path items and operations.\n */\nexport function processItem(\n item: Item | ItemGroup,\n parentTags: string[] = [],\n parentPath: string = '',\n): {\n paths: OpenAPIV3_1.PathsObject\n components: OpenAPIV3_1.ComponentsObject\n serverUsage: ServerUsage[]\n} {\n const paths: OpenAPIV3_1.PathsObject = {}\n const components: OpenAPIV3_1.ComponentsObject = {}\n const serverUsage: ServerUsage[] = []\n\n if ('item' in item && Array.isArray(item.item)) {\n const newParentTags = item.name ? [...parentTags, item.name] : parentTags\n item.item.forEach((childItem) => {\n const childResult = processItem(childItem, newParentTags, `${parentPath}/${item.name || ''}`)\n // Merge child paths and components\n for (const [pathKey, pathItem] of Object.entries(childResult.paths)) {\n if (!paths[pathKey]) {\n paths[pathKey] = pathItem\n } else {\n paths[pathKey] = {\n ...paths[pathKey],\n ...pathItem,\n }\n }\n }\n\n // Merge components.securitySchemes\n if (childResult.components.securitySchemes) {\n components.securitySchemes = {\n ...components.securitySchemes,\n ...childResult.components.securitySchemes,\n }\n }\n\n // Merge server usage\n serverUsage.push(...childResult.serverUsage)\n })\n return { paths, components, serverUsage }\n }\n\n if (!('request' in item)) {\n return { paths, components, serverUsage }\n }\n\n const { request, name, response } = item\n const method = (typeof request === 'string' ? 'get' : request.method || 'get').toLowerCase() as HttpMethods\n\n const requestUrl =\n typeof request === 'string' ? request : typeof request.url === 'string' ? request.url : (request.url?.raw ?? '')\n\n const path = extractPathFromUrl(requestUrl)\n\n // Normalize path parameters from ':param' to '{param}'\n const normalizedPath = normalizePath(path)\n\n // Extract server URL from request URL\n const serverUrl = extractServerFromUrl(requestUrl)\n if (serverUrl) {\n serverUsage.push({\n serverUrl,\n path: normalizedPath,\n method,\n })\n }\n\n // Extract path parameter names\n const pathParameterNames = extractPathParameterNames(normalizedPath)\n\n // Extract operation ID if present\n const { operationId, summary } = extractOperationInfo(name)\n\n const description =\n typeof request === 'string'\n ? ''\n : typeof request.description === 'string'\n ? request.description\n : (request.description?.content ?? '')\n\n const operationObject: OpenAPIV3_1.OperationObject = {\n tags: parentTags.length > 0 ? [parentTags.join(' > ')] : undefined,\n summary,\n description,\n responses: extractResponses(response || [], item),\n parameters: [],\n }\n\n // Add pre-request scripts if present\n const preRequestScript = processPreRequestScripts(item.event)\n if (preRequestScript) {\n operationObject['x-pre-request'] = preRequestScript\n }\n\n // Add post-response scripts if present\n const postResponseScript = processPostResponseScripts(item.event)\n if (postResponseScript) {\n operationObject['x-post-response'] = postResponseScript\n }\n\n // Only add operationId if it was explicitly provided\n if (operationId) {\n operationObject.operationId = operationId\n }\n\n // Extract parameters from the request (query, path, header)\n // This should always happen, regardless of whether a description exists\n const extractedParameters = extractParameters(request)\n\n // Merge parameters, giving priority to those from the Markdown table if description exists\n const mergedParameters = new Map<string, OpenAPIV3_1.ParameterObject>()\n\n // Add extracted parameters, filtering out path parameters not in the path\n extractedParameters.forEach((param) => {\n if (param.name) {\n if (param.in === 'path' && !pathParameterNames.includes(param.name)) {\n return\n }\n mergedParameters.set(param.name, param)\n }\n })\n\n // Parse parameters from the description's Markdown table if description exists\n if (operationObject.description) {\n const { descriptionWithoutTable, parametersFromTable } = parseParametersFromDescription(operationObject.description)\n operationObject.description = descriptionWithoutTable.trim()\n\n // Add parameters from table, filtering out path parameters not in the path\n // These take priority over extracted parameters\n parametersFromTable.forEach((param) => {\n if (param.name) {\n if (param.in === 'path' && !pathParameterNames.includes(param.name)) {\n return\n }\n mergedParameters.set(param.name, param)\n }\n })\n }\n\n // Set parameters if we have any\n if (mergedParameters.size > 0) {\n operationObject.parameters = Array.from(mergedParameters.values())\n }\n\n if (typeof request !== 'string' && request.auth) {\n if (!operationObject.security) {\n operationObject.security = []\n }\n const { securitySchemes, security } = processAuth(request.auth)\n\n if (!components.securitySchemes) {\n components.securitySchemes = {}\n }\n components.securitySchemes = {\n ...components.securitySchemes,\n ...securitySchemes,\n }\n\n operationObject.security.push(...security)\n }\n\n // Allow request bodies for all methods (including GET) if body is present\n if (typeof request !== 'string' && request.body) {\n const requestBody = extractRequestBody(request.body)\n ensureRequestBodyContent(requestBody)\n // Only add requestBody if it has content\n if (requestBody.content && Object.keys(requestBody.content).length > 0) {\n operationObject.requestBody = requestBody\n }\n }\n\n if (!paths[path]) {\n paths[path] = {}\n }\n const pathItem = paths[path] as OpenAPIV3_1.PathItemObject\n pathItem[method] = operationObject\n\n return { paths, components, serverUsage }\n}\n\n// Helper function to parse parameters from the description if it is markdown\ntype ParameterRow = {\n object?: 'query' | 'header' | 'path' | string\n name?: string\n description?: string\n required?: string\n type?: string\n example?: string\n}\n\n/** OpenAPI 3.1 parameter schema types (ParameterObject uses OpenAPIV3_1). */\nconst OPENAPI_PARAM_SCHEMA_TYPES = ['string', 'number', 'integer', 'boolean', 'object', 'array'] as const\n\ntype OpenApiParamSchemaType = (typeof OPENAPI_PARAM_SCHEMA_TYPES)[number]\n\nfunction toOpenApiParamSchemaType(s: string | undefined): OpenApiParamSchemaType {\n const value = s ?? 'string'\n for (const t of OPENAPI_PARAM_SCHEMA_TYPES) {\n if (t === value) return t\n }\n return 'string'\n}\n\nfunction parameterSchemaFromType(type: OpenApiParamSchemaType): OpenAPIV3_1.ParameterObject['schema'] {\n if (type === 'array') {\n return { type: 'array' }\n }\n return { type }\n}\n\nfunction parseParametersFromDescription(description: string): {\n descriptionWithoutTable: string\n parametersFromTable: OpenAPIV3_1.ParameterObject[]\n} {\n const lines = description.split('\\n')\n let inTable = false\n const tableLines: string[] = []\n const descriptionLines: string[] = []\n\n for (const line of lines) {\n // Detect the start of the table\n if (line.trim().startsWith('|')) {\n // Remove any preceding headers or empty lines before the table\n while (\n descriptionLines.length > 0 &&\n (descriptionLines[descriptionLines.length - 1]?.trim() === '' ||\n descriptionLines[descriptionLines.length - 1]?.trim().startsWith('#'))\n ) {\n descriptionLines.pop()\n }\n\n // Start collecting table lines\n inTable = true\n }\n\n if (inTable) {\n tableLines.push(line)\n // Detect the end of the table (any line that doesn't start with '|', excluding the alignment line)\n if (!line.trim().startsWith('|') && !line.trim().match(/^-+$/)) {\n inTable = false\n }\n } else {\n descriptionLines.push(line)\n }\n }\n\n const tableMarkdown = tableLines.join('\\n')\n const parsedTable = parseMdTable(tableMarkdown)\n const parametersFromTable = Object.values(parsedTable)\n .map((paramData) => {\n const row = paramData as ParameterRow\n if (row.object !== 'query' && row.object !== 'header' && row.object !== 'path') {\n return undefined\n }\n\n if (!row.name) {\n return undefined\n }\n\n const param: OpenAPIV3_1.ParameterObject = {\n name: row.name,\n in: row.object,\n description: row.description,\n required: row.required === 'true',\n schema: parameterSchemaFromType(toOpenApiParamSchemaType(row.type)),\n }\n\n if (row.example) {\n param.example = row.example\n }\n\n return param\n })\n .filter((param): param is OpenAPIV3_1.ParameterObject => Boolean(param))\n\n const descriptionWithoutTable = descriptionLines.join('\\n')\n return { descriptionWithoutTable, parametersFromTable }\n}\n\n// Instead of using regex with \\s*, let's split this into two steps\nfunction extractOperationInfo(name: string | undefined) {\n if (!name) {\n return { operationId: undefined, summary: undefined }\n }\n\n // First check if the string ends with something in brackets\n const match = name.match(/\\[([^[\\]]{0,1000})\\]$/)\n if (!match) {\n return { operationId: undefined, summary: name }\n }\n\n // Get the operation ID from inside brackets\n const operationId = match[1]\n\n // Trim the brackets part from the end using string operations instead of regex\n const lastBracketIndex = name.lastIndexOf('[')\n const summary = name.substring(0, lastBracketIndex).trim()\n\n return { operationId, summary }\n}\n"],
|
|
5
|
-
"mappings": "AAIA,SAAS,mBAAmB;AAC5B,SAAS,oBAAoB;AAC7B,SAAS,yBAAyB;AAClC,SAAS,kCAAkC;AAC3C,SAAS,gCAAgC;AACzC,SAAS,0BAA0B;AACnC,SAAS,wBAAwB;AACjC,SAAS,oBAAoB,2BAA2B,sBAAsB,qBAAqB;AAanG,SAAS,yBAAyB,aAAkD;AAClF,QAAM,UAAU,YAAY,WAAW,CAAC;AAExC,MAAI,OAAO,KAAK,OAAO,EAAE,WAAW,GAAG;AACrC,gBAAY,UAAU;AAAA,MACpB,cAAc,CAAC;AAAA,IACjB;AACA;AAAA,EACF;AAEA,MAAI,gBAAgB,SAAS;AAC3B,UAAM,cAAc,QAAQ,YAAY;AACxC,QAAI,CAAC,aAAa,UAAW,YAAY,UAAU,OAAO,KAAK,YAAY,MAAM,EAAE,WAAW,GAAI;AAChG,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AAU,IAAI,aAAa;AAAA,MAC3B,QAAQ,wBAAwB,yBAAyB,IAAI,IAAI,CAAC;AAAA,IACpE;AAEA,QAAI,IAAI,SAAS;AACf,YAAM,UAAU,IAAI;AAAA,IACtB;AAEA,WAAO;AAAA,EACT,CAAC,EACA,OAAO,CAAC,UAAgD,QAAQ,KAAK,CAAC;AAEzE,QAAM,0BAA0B,iBAAiB,KAAK,IAAI;AAC1D,SAAO,EAAE,yBAAyB,oBAAoB;AACxD;AAGA,SAAS,qBAAqB,MAA0B;AACtD,MAAI,CAAC,MAAM;AACT,WAAO,EAAE,aAAa,QAAW,SAAS,OAAU;AAAA,EACtD;AAGA,QAAM,QAAQ,KAAK,MAAM,uBAAuB;AAChD,MAAI,CAAC,OAAO;AACV,WAAO,EAAE,aAAa,QAAW,SAAS,KAAK;AAAA,EACjD;AAGA,QAAM,cAAc,MAAM,CAAC;AAG3B,QAAM,mBAAmB,KAAK,YAAY,GAAG;AAC7C,QAAM,UAAU,KAAK,UAAU,GAAG,gBAAgB,EAAE,KAAK;AAEzD,SAAO,EAAE,aAAa,QAAQ;AAChC;",
|
|
6
|
-
"names": ["pathItem"]
|
|
7
|
-
}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../src/helpers/post-response-scripts.ts"],
|
|
4
|
-
"sourcesContent": ["import type { Event } from '@/types'\n\n/**\n * Processes Postman test scripts and converts them to OpenAPI x-post-response extension.\n * Extracts the test script from Postman events and returns it as a single string.\n */\nexport function processPostResponseScripts(events: Event[] = []): string | undefined {\n const testEvent = events.find((event) => event.listen === 'test')\n\n const exec = testEvent?.script?.exec\n\n if (!exec) {\n return undefined\n }\n\n const content = typeof exec === 'string' ? exec : exec.join('\\n')\n\n return content.trim() || undefined\n}\n"],
|
|
5
|
-
"mappings": "AAMO,SAAS,2BAA2B,SAAkB,CAAC,GAAuB;AACnF,QAAM,YAAY,OAAO,KAAK,CAAC,UAAU,MAAM,WAAW,MAAM;AAEhE,QAAM,OAAO,WAAW,QAAQ;AAEhC,MAAI,CAAC,MAAM;AACT,WAAO;AAAA,EACT;AAEA,QAAM,UAAU,OAAO,SAAS,WAAW,OAAO,KAAK,KAAK,IAAI;AAEhE,SAAO,QAAQ,KAAK,KAAK;AAC3B;",
|
|
6
|
-
"names": []
|
|
7
|
-
}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../src/helpers/pre-request-scripts.ts"],
|
|
4
|
-
"sourcesContent": ["import type { Event } from '@/types'\n\n/**\n * Processes Postman pre-request scripts and converts them to OpenAPI x-pre-request extension.\n * Extracts the pre-request script from Postman events and returns it as a single string.\n */\nexport function processPreRequestScripts(events: Event[] = []): string | undefined {\n const preRequestEvent = events.find((event) => event.listen === 'prerequest')\n\n const exec = preRequestEvent?.script?.exec\n\n if (!exec) {\n return undefined\n }\n\n const content = typeof exec === 'string' ? exec : exec.join('\\n')\n\n return content.trim() || undefined\n}\n"],
|
|
5
|
-
"mappings": "AAMO,SAAS,yBAAyB,SAAkB,CAAC,GAAuB;AACjF,QAAM,kBAAkB,OAAO,KAAK,CAAC,UAAU,MAAM,WAAW,YAAY;AAE5E,QAAM,OAAO,iBAAiB,QAAQ;AAEtC,MAAI,CAAC,MAAM;AACT,WAAO;AAAA,EACT;AAEA,QAAM,UAAU,OAAO,SAAS,WAAW,OAAO,KAAK,KAAK,IAAI;AAEhE,SAAO,QAAQ,KAAK,KAAK;AAC3B;",
|
|
6
|
-
"names": []
|
|
7
|
-
}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../src/helpers/prune-document.ts"],
|
|
4
|
-
"sourcesContent": ["import type { OpenAPIV3_1 } from '@scalar/openapi-types'\n\n/**\n * Recursively removes all undefined values from an object or array.\n * Preserves null values as they are valid in JSON/OpenAPI.\n * Returns a new object/array with undefined values removed.\n */\nconst removeUndefinedValues = (value: unknown): unknown => {\n if (value === null || value === undefined) {\n return value === null ? null : undefined\n }\n\n if (Array.isArray(value)) {\n return value.map(removeUndefinedValues).filter((item) => item !== undefined)\n }\n\n if (typeof value === 'object') {\n const cleaned: Record<string, unknown> = {}\n for (const [key, val] of Object.entries(value)) {\n const cleanedValue = removeUndefinedValues(val)\n if (cleanedValue !== undefined) {\n cleaned[key] = cleanedValue\n }\n }\n return cleaned\n }\n\n return value\n}\n\n/**\n * Prunes an OpenAPI document by removing empty arrays/objects and undefined values.\n * Removes empty tags, security arrays, and empty components objects.\n * Recursively removes all undefined values throughout the document structure.\n */\nexport const pruneDocument = (document: OpenAPIV3_1.Document): OpenAPIV3_1.Document => {\n const cleaned: OpenAPIV3_1.Document = { ...document }\n\n if (cleaned.tags?.length === 0) {\n delete cleaned.tags\n }\n\n if (cleaned.security?.length === 0) {\n delete cleaned.security\n }\n\n if (cleaned.components && Object.keys(cleaned.components).length === 0) {\n delete cleaned.components\n }\n\n if (cleaned.externalDocs === undefined) {\n delete cleaned.externalDocs\n }\n\n // Recursively remove all undefined values from the document\n return removeUndefinedValues(cleaned) as OpenAPIV3_1.Document\n}\n"],
|
|
5
|
-
"mappings": "AAOA,MAAM,wBAAwB,CAAC,UAA4B;AACzD,MAAI,UAAU,QAAQ,UAAU,QAAW;AACzC,WAAO,UAAU,OAAO,OAAO;AAAA,EACjC;AAEA,MAAI,MAAM,QAAQ,KAAK,GAAG;AACxB,WAAO,MAAM,IAAI,qBAAqB,EAAE,OAAO,CAAC,SAAS,SAAS,MAAS;AAAA,EAC7E;AAEA,MAAI,OAAO,UAAU,UAAU;AAC7B,UAAM,UAAmC,CAAC;AAC1C,eAAW,CAAC,KAAK,GAAG,KAAK,OAAO,QAAQ,KAAK,GAAG;AAC9C,YAAM,eAAe,sBAAsB,GAAG;AAC9C,UAAI,iBAAiB,QAAW;AAC9B,gBAAQ,GAAG,IAAI;AAAA,MACjB;AAAA,IACF;AACA,WAAO;AAAA,EACT;AAEA,SAAO;AACT;AAOO,MAAM,gBAAgB,CAAC,aAAyD;AACrF,QAAM,UAAgC,EAAE,GAAG,SAAS;AAEpD,MAAI,QAAQ,MAAM,WAAW,GAAG;AAC9B,WAAO,QAAQ;AAAA,EACjB;AAEA,MAAI,QAAQ,UAAU,WAAW,GAAG;AAClC,WAAO,QAAQ;AAAA,EACjB;AAEA,MAAI,QAAQ,cAAc,OAAO,KAAK,QAAQ,UAAU,EAAE,WAAW,GAAG;AACtE,WAAO,QAAQ;AAAA,EACjB;AAEA,MAAI,QAAQ,iBAAiB,QAAW;AACtC,WAAO,QAAQ;AAAA,EACjB;AAGA,SAAO,sBAAsB,OAAO;AACtC;",
|
|
6
|
-
"names": []
|
|
7
|
-
}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../src/helpers/request-body.ts"],
|
|
4
|
-
"sourcesContent": ["import type { OpenAPIV3_1 } from '@scalar/openapi-types'\n\nimport type { FormParameter, RequestBody, UrlEncodedParameter } from '@/types'\n\nimport { processFormDataSchema } from './form-data'\nimport { createParameterObject } from './parameters'\n\n/**\n * Extracts and converts the request body from a Postman request to an OpenAPI RequestBodyObject.\n * Handles raw JSON, form-data, and URL-encoded body types, creating appropriate schemas and content types.\n */\nexport function extractRequestBody(body: RequestBody): OpenAPIV3_1.RequestBodyObject {\n const requestBody: OpenAPIV3_1.RequestBodyObject = {\n content: {},\n }\n\n if (body.mode === 'raw') {\n handleRawBody(body, requestBody)\n return requestBody\n }\n\n if (body.mode === 'formdata' && body.formdata) {\n handleFormDataBody(body.formdata, requestBody)\n return requestBody\n }\n\n if (body.mode === 'urlencoded' && body.urlencoded) {\n handleUrlEncodedBody(body.urlencoded, requestBody)\n return requestBody\n }\n\n return requestBody\n}\n\nfunction handleRawBody(body: RequestBody, requestBody: OpenAPIV3_1.RequestBodyObject): void {\n const rawBody = body.raw || ''\n const isJsonLanguage = body.options?.raw?.language === 'json'\n\n // Check if body contains Postman variables (like {{bodyData}})\n const hasVariables = /\\{\\{[\\w-]+\\}\\}/.test(rawBody)\n\n // Try parsing the raw body as JSON\n // We use a boolean flag because `null` is a valid JSON value\n let jsonBody: unknown\n let isJsonBody = false\n try {\n jsonBody = JSON.parse(rawBody)\n isJsonBody = true\n } catch {\n // Parsing failed - will handle below\n }\n\n // If we have valid JSON, use it\n if (isJsonBody) {\n requestBody.content = {\n 'application/json': {\n schema: {\n type: 'object',\n example: jsonBody,\n },\n },\n }\n return\n }\n\n // If we have variables and JSON language but could not parse JSON,\n // create a JSON schema placeholder\n if (hasVariables && isJsonLanguage) {\n requestBody.content = {\n 'application/json': {\n schema: {\n type: 'object',\n description: 'Body data set via pre-request script',\n },\n },\n }\n return\n }\n\n // Fallback to text/plain\n requestBody.content = {\n 'text/plain': {\n schema: {\n type: 'string',\n examples: rawBody ? [rawBody] : undefined,\n },\n },\n }\n}\n\nfunction handleFormDataBody(formdata: FormParameter[], requestBody: OpenAPIV3_1.RequestBodyObject): void {\n requestBody.content = {\n 'multipart/form-data': {\n schema: processFormDataSchema(formdata),\n },\n }\n}\n\nfunction handleUrlEncodedBody(urlencoded: UrlEncodedParameter[], requestBody: OpenAPIV3_1.RequestBodyObject): void {\n const schema: OpenAPIV3_1.SchemaObject = {\n type: 'object',\n properties: {},\n required: [],\n }\n urlencoded.forEach((item: UrlEncodedParameter) => {\n if (schema.properties) {\n const paramObject = createParameterObject(item, 'query')\n const property: OpenAPIV3_1.SchemaObject = {\n type: 'string',\n examples: [item.value],\n description: paramObject.description,\n }\n // Add x-scalar-disabled extension if parameter is disabled\n if (item.disabled === true) {\n property['x-scalar-disabled'] = true\n }\n schema.properties[item.key] = property\n if (paramObject.required) {\n schema.required?.push(item.key)\n }\n }\n })\n requestBody.content = {\n 'application/x-www-form-urlencoded': {\n schema,\n },\n }\n}\n"],
|
|
5
|
-
"mappings": "AAIA,SAAS,6BAA6B;AACtC,SAAS,6BAA6B;A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AAA,IACxC;AAAA,EACF;AACF;AAEA,SAAS,qBAAqB,YAAmC,aAAkD;AACjH,QAAM,SAAmC;AAAA,IACvC,MAAM;AAAA,IACN,YAAY,CAAC;AAAA,IACb,UAAU,CAAC;AAAA,EACb;AACA,aAAW,QAAQ,CAAC,SAA8B;AAChD,QAAI,OAAO,YAAY;AACrB,YAAM,cAAc,sBAAsB,MAAM,OAAO;AACvD,YAAM,WAAqC;AAAA,QACzC,MAAM;AAAA,QACN,UAAU,CAAC,KAAK,KAAK;AAAA,QACrB,aAAa,YAAY;AAAA,MAC3B;AAEA,UAAI,KAAK,aAAa,MAAM;AAC1B,iBAAS,mBAAmB,IAAI;AAAA,MAClC;AACA,aAAO,WAAW,KAAK,GAAG,IAAI;AAC9B,UAAI,YAAY,UAAU;AACxB,eAAO,UAAU,KAAK,KAAK,GAAG;AAAA,MAChC;AAAA,IACF;AAAA,EACF,CAAC;AACD,cAAY,UAAU;AAAA,IACpB,qCAAqC;AAAA,MACnC;AAAA,IACF;AAAA,EACF;AACF;",
|
|
6
|
-
"names": []
|
|
7
|
-
}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../src/helpers/responses.ts"],
|
|
4
|
-
"sourcesContent": ["import type { OpenAPIV3_1 } from '@scalar/openapi-types'\n\nimport type { HeaderList, Item, Response } from '@/types'\n\nimport { inferSchemaFromExample } from './schemas'\nimport { extractStatusCodesFromTests } from './status-codes'\n\n/**\n * Extracts and converts Postman response objects to OpenAPI response objects.\n * Processes response status codes, descriptions, headers, and body content,\n * inferring schemas from example responses when possible.\n */\nexport function extractResponses(responses: Response[], item?: Item): OpenAPIV3_1.ResponsesObject | undefined {\n // Extract status codes from tests\n const statusCodes = item ? extractStatusCodesFromTests(item) : []\n\n // Create a map of status codes to descriptions from responses\n const responseMap = responses.reduce((acc, response) => {\n const statusCode = response.code?.toString() || 'default'\n acc[statusCode] = {\n description: response.status || 'Successful response',\n headers: extractHeaders(response.header),\n content: {\n 'application/json': {\n schema: inferSchemaFromExample(response.body || ''),\n examples: {\n default: tryParseJson(response.body || ''),\n },\n },\n },\n }\n return acc\n }, {} as OpenAPIV3_1.ResponsesObject)\n\n // Add status codes from tests if not already present\n statusCodes.forEach((code) => {\n const codeStr = code.toString()\n if (!responseMap[codeStr]) {\n responseMap[codeStr] = {\n description: 'Successful response',\n content: {\n 'application/json': {},\n },\n }\n }\n })\n\n if (Object.keys(responseMap).length === 0) {\n return undefined\n }\n\n return responseMap\n}\n\nfunction extractHeaders(\n headers: HeaderList | string | null | undefined,\n): { [key: string]: OpenAPIV3_1.HeaderObject } | undefined {\n if (!headers || typeof headers === 'string') {\n return undefined\n }\n const openapiHeaders: { [key: string]: OpenAPIV3_1.HeaderObject } = {}\n if (Array.isArray(headers)) {\n headers.forEach((header) => {\n openapiHeaders[header.key] = {\n schema: {\n type: 'string',\n examples: [header.value],\n },\n }\n })\n }\n return openapiHeaders\n}\n\nfunction tryParseJson(jsonString: string): Record<string, unknown> {\n try {\n return JSON.parse(jsonString) as Record<string, unknown>\n } catch (_e) {\n return { rawContent: jsonString }\n }\n}\n"],
|
|
5
|
-
"mappings": "AAIA,SAAS,8BAA8B;AACvC,SAAS,mCAAmC;AAOrC,SAAS,iBAAiB,WAAuB,MAAsD;AAE5G,QAAM,cAAc,OAAO,4BAA4B,IAAI,IAAI,CAAC;AAGhE,QAAM,cAAc,UAAU,OAAO,CAAC,KAAK,aAAa;AACtD,UAAM,aAAa,SAAS,MAAM,SAAS,KAAK;AAChD,QAAI,UAAU,IAAI;AAAA,MAChB,aAAa,SAAS,UAAU;AAAA,MAChC,SAAS,eAAe,SAAS,MAAM;AAAA,MACvC,SAAS;AAAA,QACP,oBAAoB;AAAA,UAClB,QAAQ,uBAAuB,SAAS,QAAQ,EAAE;AAAA,UAClD,UAAU;AAAA,YACR,SAAS,aAAa,SAAS,QAAQ,EAAE;AAAA,UAC3C;AAAA,QACF;AAAA,MACF;AAAA,IACF;AACA,WAAO;AAAA,EACT,GAAG,CAAC,CAAgC;AAGpC,cAAY,QAAQ,CAAC,SAAS;AAC5B,UAAM,UAAU,KAAK,SAAS;AAC9B,QAAI,CAAC,YAAY,OAAO,GAAG;AACzB,kBAAY,OAAO,IAAI;AAAA,QACrB,aAAa;AAAA,QACb,SAAS;AAAA,UACP,oBAAoB,CAAC;AAAA,QACvB;AAAA,MACF;AAAA,IACF;AAAA,EACF,CAAC;AAED,MAAI,OAAO,KAAK,WAAW,EAAE,WAAW,GAAG;AACzC,WAAO;AAAA,EACT;AAEA,SAAO;AACT;AAEA,SAAS,eACP,SACyD;AACzD,MAAI,CAAC,WAAW,OAAO,YAAY,UAAU;AAC3C,WAAO;AAAA,EACT;AACA,QAAM,iBAA8D,CAAC;AACrE,MAAI,MAAM,QAAQ,OAAO,GAAG;AAC1B,YAAQ,QAAQ,CAAC,WAAW;AAC1B,qBAAe,OAAO,GAAG,IAAI;AAAA,QAC3B,QAAQ;AAAA,UACN,MAAM;AAAA,UACN,UAAU,CAAC,OAAO,KAAK;AAAA,QACzB;AAAA,MACF;AAAA,IACF,CAAC;AAAA,EACH;AACA,SAAO;AACT;AAEA,SAAS,aAAa,YAA6C;AACjE,MAAI;AACF,WAAO,KAAK,MAAM,UAAU;AAAA,EAC9B,SAAS,IAAI;AACX,WAAO,EAAE,YAAY,WAAW;AAAA,EAClC;AACF;",
|
|
6
|
-
"names": []
|
|
7
|
-
}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../src/helpers/schemas.ts"],
|
|
4
|
-
"sourcesContent": ["import type { OpenAPIV3_1 } from '@scalar/openapi-types'\n\n/**\n * Infers the schema of an OpenAPI object based on an example value.\n * This function recursively analyzes the structure of the example value\n * and returns a corresponding OpenAPI schema object.\n */\nexport function inferSchemaFromExample(example: any): OpenAPIV3_1.SchemaObject {\n if (Array.isArray(example)) {\n return {\n type: 'array',\n items: example.length > 0 ? inferSchemaFromExample(example[0]) : {},\n }\n }\n if (typeof example === 'object' && example !== null) {\n const properties: { [key: string]: OpenAPIV3_1.SchemaObject } = {}\n for (const [key, value] of Object.entries(example)) {\n properties[key] = inferSchemaFromExample(value)\n }\n return {\n type: 'object',\n properties,\n }\n }\n return {\n type: typeof example as OpenAPIV3_1.NonArraySchemaObjectType,\n }\n}\n\n/**\n * Infers the schema type of a value based on its type.\n * This function determines the OpenAPI schema type of a value\n * by checking its JavaScript type and attempting to parse it\n * as a number or boolean if it's a string.\n */\nexport function inferSchemaType(value: any): OpenAPIV3_1.NonArraySchemaObject {\n if (typeof value === 'number') {\n return { type: Number.isInteger(value) ? 'integer' : 'number' }\n }\n\n if (typeof value === 'boolean') {\n return { type: 'boolean' }\n }\n\n if (typeof value === 'string') {\n const num = Number(value)\n\n if (!isNaN(num)) {\n return { type: Number.isInteger(num) ? 'integer' : 'number' }\n }\n\n if (value.toLowerCase() === 'true' || value.toLowerCase() === 'false') {\n return { type: 'boolean' }\n }\n }\n\n return { type: 'string' }\n}\n"],
|
|
5
|
-
"mappings": "AAOO,SAAS,uBAAuB,SAAwC;AAC7E,MAAI,MAAM,QAAQ,OAAO,GAAG;AAC1B,WAAO;AAAA,MACL,MAAM;AAAA,MACN,OAAO,QAAQ,SAAS,IAAI,uBAAuB,QAAQ,CAAC,CAAC,IAAI,CAAC;AAAA,IACpE;AAAA,EACF;AACA,MAAI,OAAO,YAAY,YAAY,YAAY,MAAM;AACnD,UAAM,aAA0D,CAAC;AACjE,eAAW,CAAC,KAAK,KAAK,KAAK,OAAO,QAAQ,OAAO,GAAG;AAClD,iBAAW,GAAG,IAAI,uBAAuB,KAAK;AAAA,IAChD;AACA,WAAO;AAAA,MACL,MAAM;AAAA,MACN;AAAA,IACF;AAAA,EACF;AACA,SAAO;AAAA,IACL,MAAM,OAAO;AAAA,EACf;AACF;AAQO,SAAS,gBAAgB,OAA8C;AAC5E,MAAI,OAAO,UAAU,UAAU;AAC7B,WAAO,EAAE,MAAM,OAAO,UAAU,KAAK,IAAI,YAAY,SAAS;AAAA,EAChE;AAEA,MAAI,OAAO,UAAU,WAAW;AAC9B,WAAO,EAAE,MAAM,UAAU;AAAA,EAC3B;AAEA,MAAI,OAAO,UAAU,UAAU;AAC7B,UAAM,MAAM,OAAO,KAAK;AAExB,QAAI,CAAC,MAAM,GAAG,GAAG;AACf,aAAO,EAAE,MAAM,OAAO,UAAU,GAAG,IAAI,YAAY,SAAS;AAAA,IAC9D;AAEA,QAAI,MAAM,YAAY,MAAM,UAAU,MAAM,YAAY,MAAM,SAAS;AACrE,aAAO,EAAE,MAAM,UAAU;AAAA,IAC3B;AAAA,EACF;AAEA,SAAO,EAAE,MAAM,SAAS;AAC1B;",
|
|
6
|
-
"names": []
|
|
7
|
-
}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../src/helpers/servers.ts"],
|
|
4
|
-
"sourcesContent": ["import type { OpenAPIV3_1 } from '@scalar/openapi-types'\n\nimport type { ServerUsage } from './path-items'\n\n/**\n * Information about where a server should be placed.\n */\ntype ServerPlacement = {\n document: OpenAPIV3_1.ServerObject[]\n pathItems: Map<string, OpenAPIV3_1.ServerObject[]>\n operations: Map<string, Map<string, OpenAPIV3_1.ServerObject[]>>\n}\n\n/**\n * Creates a unique key for a path/method combination.\n * Used to properly deduplicate operations in a Set since JavaScript Sets\n * compare objects by reference, not by value.\n */\nfunction createOperationKey(path: string, method: string): string {\n return `${path}::${method}`\n}\n\n/**\n * Parses an operation key back into its path and method components.\n */\nfunction parseOperationKey(key: string): { path: string; method: string } {\n const separatorIndex = key.lastIndexOf('::')\n return {\n path: key.substring(0, separatorIndex),\n method: key.substring(separatorIndex + 2),\n }\n}\n\n/**\n * Analyzes server usage and determines the optimal placement level for each server.\n * Placement logic:\n * - If server used in all paths \u2192 document level\n * - If server used in multiple paths \u2192 document level\n * - If server used in multiple operations within 1 path \u2192 path item level\n * - If server used in only 1 operation \u2192 operation level\n */\nexport function analyzeServerDistribution(serverUsage: ServerUsage[], allUniquePaths: Set<string>): ServerPlacement {\n const placement: ServerPlacement = {\n document: [],\n pathItems: new Map(),\n operations: new Map(),\n }\n\n if (serverUsage.length === 0) {\n return placement\n }\n\n // Build a map: serverUrl -> Set<operationKey>\n // Using string keys instead of objects because JavaScript Sets compare by reference\n const serverMap = new Map<string, Set<string>>()\n\n for (const usage of serverUsage) {\n if (!serverMap.has(usage.serverUrl)) {\n serverMap.set(usage.serverUrl, new Set())\n }\n serverMap.get(usage.serverUrl)!.add(createOperationKey(usage.path, usage.method))\n }\n\n // For each server, determine its placement\n for (const [serverUrl, operationKeys] of serverMap.entries()) {\n const serverObject: OpenAPIV3_1.ServerObject = { url: serverUrl }\n\n // Parse operation keys back to path/method pairs\n const operations = Array.from(operationKeys).map(parseOperationKey)\n\n // Count unique paths this server appears in\n const uniquePaths = new Set(operations.map((op) => op.path))\n const pathCount = uniquePaths.size\n\n // Check if server covers all paths in the document\n const coversAllPaths =\n allUniquePaths.size > 0 &&\n uniquePaths.size === allUniquePaths.size &&\n Array.from(uniquePaths).every((path) => allUniquePaths.has(path))\n\n if (coversAllPaths || pathCount > 1) {\n // Server used in all paths or multiple paths \u2192 document level\n placement.document.push(serverObject)\n } else if (operations.length > 1) {\n // Server used in multiple operations within 1 path \u2192 path item level\n const path = operations[0]?.path\n if (!path) {\n continue\n }\n if (!placement.pathItems.has(path)) {\n placement.pathItems.set(path, [])\n }\n placement.pathItems.get(path)!.push(serverObject)\n } else {\n // Server used in only 1 operation \u2192 operation level\n const operation = operations[0]\n if (!operation) {\n continue\n }\n // Use nested Map structure: path -> method -> servers\n if (!placement.operations.has(operation.path)) {\n placement.operations.set(operation.path, new Map())\n }\n const methodsMap = placement.operations.get(operation.path)!\n if (!methodsMap.has(operation.method)) {\n methodsMap.set(operation.method, [])\n }\n methodsMap.get(operation.method)!.push(serverObject)\n }\n }\n\n return placement\n}\n"],
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AEhC,YAAM,OAAO,WAAW,CAAC,GAAG;AAC5B,UAAI,CAAC,MAAM;AACT;AAAA,MACF;AACA,UAAI,CAAC,UAAU,UAAU,IAAI,IAAI,GAAG;AAClC,kBAAU,UAAU,IAAI,MAAM,CAAC,CAAC;AAAA,MAClC;AACA,gBAAU,UAAU,IAAI,IAAI,EAAG,KAAK,YAAY;AAAA,IAClD,OAAO;AAEL,YAAM,YAAY,WAAW,CAAC;AAC9B,UAAI,CAAC,WAAW;AACd;AAAA,MACF;AAEA,UAAI,CAAC,UAAU,WAAW,IAAI,UAAU,IAAI,GAAG;AAC7C,kBAAU,WAAW,IAAI,UAAU,MAAM,oBAAI,IAAI,CAAC;AAAA,MACpD;AACA,YAAM,aAAa,UAAU,WAAW,IAAI,UAAU,IAAI;AAC1D,UAAI,CAAC,WAAW,IAAI,UAAU,MAAM,GAAG;AACrC,mBAAW,IAAI,UAAU,QAAQ,CAAC,CAAC;AAAA,MACrC;AACA,iBAAW,IAAI,UAAU,MAAM,EAAG,KAAK,YAAY;AAAA,IACrD;AAAA,EACF;AAEA,SAAO;AACT;",
|
|
6
|
-
"names": []
|
|
7
|
-
}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../src/helpers/status-codes.ts"],
|
|
4
|
-
"sourcesContent": ["import type { Item } from '@/types'\n\n/**\n * Extracts expected status codes from the test scripts of a Postman item.\n * Looks for patterns like:\n * - pm.response.to.have.status(201)\n * - pm.expect(pm.response.code).to.eql(202)\n * - pm.expect(pm.response.status).to.equal(201)\n */\nexport function extractStatusCodesFromTests(item: Item): number[] {\n const statusCodes: number[] = []\n\n if (item.event?.length) {\n item.event.forEach((event) => {\n if (event.listen === 'test' && event.script?.exec) {\n const scriptLines = Array.isArray(event.script.exec) ? event.script.exec : [event.script.exec]\n\n scriptLines.forEach((line: string) => {\n const statusCode = parseStatusCodeFromLine(line)\n if (statusCode) {\n statusCodes.push(statusCode)\n }\n })\n }\n })\n }\n\n return statusCodes\n}\n\n/**\n * Parses a line of script to extract a status code.\n * Supports patterns like:\n * - pm.response.to.have.status(201)\n * - pm.expect(pm.response.code).to.eql(202)\n * - pm.expect(pm.response.status).to.equal(201)\n */\nfunction parseStatusCodeFromLine(line: string): number | null {\n const patterns = [\n /pm\\.response\\.to\\.have\\.status\\((\\d{3})\\)/,\n /pm\\.expect\\(pm\\.response\\.code\\)\\.to\\.(?:eql|equal)\\((\\d{3})\\)/,\n /pm\\.expect\\(pm\\.response\\.status\\)\\.to\\.(?:eql|equal)\\(['\"](\\d{3})['\"]\\)/,\n ]\n\n for (const pattern of patterns) {\n const match = pattern.exec(line)?.at(1)\n if (match) {\n return Number.parseInt(match, 10)\n }\n }\n\n return null\n}\n"],
|
|
5
|
-
"mappings": "AASO,SAAS,4BAA4B,MAAsB;AAChE,QAAM,cAAwB,CAAC;AAE/B,MAAI,KAAK,OAAO,QAAQ;AACtB,SAAK,MAAM,QAAQ,CAAC,UAAU;AAC5B,UAAI,MAAM,WAAW,UAAU,MAAM,QAAQ,MAAM;AACjD,cAAM,cAAc,MAAM,QAAQ,MAAM,OAAO,IAAI,IAAI,MAAM,OAAO,OAAO,CAAC,MAAM,OAAO,IAAI;AAE7F,oBAAY,QAAQ,CAAC,SAAiB;AACpC,gBAAM,aAAa,wBAAwB,IAAI;AAC/C,cAAI,YAAY;AACd,wBAAY,KAAK,UAAU;AAAA,UAC7B;AAAA,QACF,CAAC;AAAA,MACH;AAAA,IACF,CAAC;AAAA,EACH;AAEA,SAAO;AACT;AASA,SAAS,wBAAwB,MAA6B;AAC5D,QAAM,WAAW;AAAA,IACf;AAAA,IACA;AAAA,IACA;AAAA,EACF;AAEA,aAAW,WAAW,UAAU;AAC9B,UAAM,QAAQ,QAAQ,KAAK,IAAI,GAAG,GAAG,CAAC;AACtC,QAAI,OAAO;AACT,aAAO,OAAO,SAAS,OAAO,EAAE;AAAA,IAClC;AAAA,EACF;AAEA,SAAO;AACT;",
|
|
6
|
-
"names": []
|
|
7
|
-
}
|
package/dist/helpers/urls.js.map
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../src/helpers/urls.ts"],
|
|
4
|
-
"sourcesContent": ["import { REGEX } from '@scalar/helpers/regex/regex-helpers'\n\nimport type { ParsedUrl } from '@/types'\n\n/**\n * Parses a URL string into its component parts.\n */\nfunction parseUrl(urlString: string): ParsedUrl {\n const url = new URL(urlString)\n return {\n protocol: url.protocol,\n hostname: url.hostname,\n port: url.port,\n }\n}\n\n/**\n * Extracts the domain (including protocol and port if present) from a given URL.\n */\nexport function getDomainFromUrl(url: string): string {\n const { protocol, hostname, port } = parseUrl(url)\n return `${protocol}//${hostname}${port ? `:${port}` : ''}`\n}\n\n/**\n * Extracts the path from a given URL, removing any Postman variables.\n */\nexport function extractPathFromUrl(url: string | undefined): string {\n if (!url) {\n return '/'\n }\n\n // Remove scheme, domain, query parameters, and hash fragments\n const path = url.replace(/^(?:https?:\\/\\/)?[^/]+(\\/|$)/, '/').split(/[?#]/)[0] ?? ''\n\n // Replace Postman variables and ensure single leading slash\n const finalPath = ('/' + path.replace(/\\{\\{([^{}]{0,1000})\\}\\}/g, '{$1}').replace(/^\\/+/, '')).replace(/\\/\\/+/g, '/')\n\n return finalPath\n}\n\n/**\n * Normalizes a path by converting colon-style parameters to curly brace style\n * e.g., '/users/:id' becomes '/users/{id}'\n */\nexport const normalizePath = (path: string): string => path.replace(/:(\\w+)/g, '{$1}')\n\n/**\n * Extracts parameter names from a path string.\n * Handles double curly braces {{param}}, single curly braces {param}, and colon format :param.\n */\nexport function extractPathParameterNames(path: string): string[] {\n const params = new Set<string>()\n let match\n\n while ((match = REGEX.TEMPLATE_VARIABLE.exec(path)) !== null) {\n // match[1] contains the parameter name from {{param}}\n // match[2] contains the parameter name from {param}\n // match[0].slice(1) gets the parameter name from :param\n const param = match[1] || match[2] || match[0].slice(1)\n params.add(param.trim())\n }\n\n return Array.from(params)\n}\n\n/**\n * Extracts the server URL from a request URL string.\n * Handles URLs with or without protocol, with ports, etc.\n * Returns undefined if no valid server URL can be extracted.\n */\nexport function extractServerFromUrl(url: string | undefined): string | undefined {\n if (!url) {\n return undefined\n }\n\n try {\n // Check if URL has a protocol\n const protocolMatch = url.match(/^(https?:\\/\\/)/i)\n const protocol = protocolMatch ? protocolMatch[1] : null\n\n // Extract domain from URL\n const urlMatch = url.match(/^(?:https?:\\/\\/)?([^/?#]+)/i)\n if (!urlMatch?.[1]) {\n return undefined\n }\n\n const hostPart = urlMatch[1]\n // Preserve the original protocol if present, otherwise default to https\n const serverUrl = protocol ? `${protocol}${hostPart}`.replace(/\\/$/, '') : `https://${hostPart}`.replace(/\\/$/, '')\n\n return serverUrl\n } catch (error) {\n console.error(`Error extracting server from URL \"${url}\":`, error)\n return undefined\n }\n}\n"],
|
|
5
|
-
"mappings": "AAAA,SAAS,aAAa;AAOtB,SAAS,SAAS,WAA8B;AAC9C,QAAM,MAAM,IAAI,IAAI,SAAS;AAC7B,SAAO;AAAA,IACL,UAAU,IAAI;AAAA,IACd,UAAU,IAAI;AAAA,IACd,MAAM,IAAI;AAAA,EACZ;AACF;AAKO,SAAS,iBAAiB,KAAqB;AACpD,QAAM,EAAE,UAAU,UAAU,KAAK,IAAI,SAAS,GAAG;AACjD,SAAO,GAAG,QAAQ,KAAK,QAAQ,GAAG,OAAO,IAAI,IAAI,KAAK,EAAE;AAC1D;AAKO,SAAS,mBAAmB,KAAiC;AAClE,MAAI,CAAC,KAAK;AACR,WAAO;AAAA,EACT;AAGA,QAAM,OAAO,IAAI,QAAQ,gCAAgC,GAAG,EAAE,MAAM,MAAM,EAAE,CAAC,KAAK;AAGlF,QAAM,aAAa,MAAM,KAAK,QAAQ,4BAA4B,MAAM,EAAE,QAAQ,QAAQ,EAAE,GAAG,QAAQ,UAAU,GAAG;AAEpH,SAAO;AACT;AAMO,MAAM,gBAAgB,CAAC,SAAyB,K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