@scalar/workspace-store 0.19.0 → 0.20.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.
Files changed (74) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/dist/events/definitions/auth.d.ts +20 -2
  3. package/dist/events/definitions/auth.d.ts.map +1 -1
  4. package/dist/events/definitions/document.d.ts +5 -1
  5. package/dist/events/definitions/document.d.ts.map +1 -1
  6. package/dist/events/definitions/index.d.ts +1 -2
  7. package/dist/events/definitions/index.d.ts.map +1 -1
  8. package/dist/events/definitions/server.d.ts +20 -28
  9. package/dist/events/definitions/server.d.ts.map +1 -1
  10. package/dist/events/index.d.ts +2 -2
  11. package/dist/events/index.d.ts.map +1 -1
  12. package/dist/events/index.js.map +2 -2
  13. package/dist/mutators/auth.d.ts +10 -73
  14. package/dist/mutators/auth.d.ts.map +1 -1
  15. package/dist/mutators/auth.js +24 -91
  16. package/dist/mutators/auth.js.map +2 -2
  17. package/dist/mutators/document.d.ts +6 -0
  18. package/dist/mutators/document.d.ts.map +1 -0
  19. package/dist/mutators/document.js +10 -0
  20. package/dist/mutators/document.js.map +7 -0
  21. package/dist/mutators/index.d.ts +10 -7
  22. package/dist/mutators/index.d.ts.map +1 -1
  23. package/dist/mutators/index.js +36 -1
  24. package/dist/mutators/index.js.map +3 -3
  25. package/dist/mutators/server.d.ts +43 -8
  26. package/dist/mutators/server.d.ts.map +1 -1
  27. package/dist/mutators/server.js +112 -20
  28. package/dist/mutators/server.js.map +2 -2
  29. package/dist/navigation/helpers/traverse-document.d.ts +1 -0
  30. package/dist/navigation/helpers/traverse-document.d.ts.map +1 -1
  31. package/dist/navigation/helpers/traverse-document.js +2 -1
  32. package/dist/navigation/helpers/traverse-document.js.map +2 -2
  33. package/dist/plugins/client/persistence.d.ts +2 -1
  34. package/dist/plugins/client/persistence.d.ts.map +1 -1
  35. package/dist/plugins/client/persistence.js +11 -9
  36. package/dist/plugins/client/persistence.js.map +2 -2
  37. package/dist/schemas/extensions/document/x-scalar-document-security.d.ts +13 -0
  38. package/dist/schemas/extensions/document/x-scalar-document-security.d.ts.map +1 -0
  39. package/dist/schemas/extensions/document/x-scalar-document-security.js +8 -0
  40. package/dist/schemas/extensions/document/x-scalar-document-security.js.map +7 -0
  41. package/dist/schemas/extensions/security/x-scalar-selected-security.d.ts +7 -7
  42. package/dist/schemas/extensions/security/x-scalar-selected-security.d.ts.map +1 -1
  43. package/dist/schemas/extensions/security/x-scalar-selected-security.js +2 -2
  44. package/dist/schemas/extensions/security/x-scalar-selected-security.js.map +2 -2
  45. package/dist/schemas/extensions/server/x-scalar-selected-server.d.ts +8 -0
  46. package/dist/schemas/extensions/server/x-scalar-selected-server.d.ts.map +1 -0
  47. package/dist/schemas/extensions/server/x-scalar-selected-server.js +8 -0
  48. package/dist/schemas/extensions/server/x-scalar-selected-server.js.map +7 -0
  49. package/dist/schemas/inmemory-workspace.d.ts +20 -8
  50. package/dist/schemas/inmemory-workspace.d.ts.map +1 -1
  51. package/dist/schemas/navigation.d.ts +5 -0
  52. package/dist/schemas/navigation.d.ts.map +1 -1
  53. package/dist/schemas/navigation.js +1 -0
  54. package/dist/schemas/navigation.js.map +2 -2
  55. package/dist/schemas/reference-config/index.d.ts +10 -4
  56. package/dist/schemas/reference-config/index.d.ts.map +1 -1
  57. package/dist/schemas/reference-config/settings.d.ts +10 -4
  58. package/dist/schemas/reference-config/settings.d.ts.map +1 -1
  59. package/dist/schemas/v3.1/strict/openapi-document.d.ts +343 -137
  60. package/dist/schemas/v3.1/strict/openapi-document.d.ts.map +1 -1
  61. package/dist/schemas/v3.1/strict/openapi-document.js +8 -0
  62. package/dist/schemas/v3.1/strict/openapi-document.js.map +2 -2
  63. package/dist/schemas/v3.1/strict/operation.d.ts +2 -2
  64. package/dist/schemas/workspace-specification/config.d.ts +10 -4
  65. package/dist/schemas/workspace-specification/config.d.ts.map +1 -1
  66. package/dist/schemas/workspace-specification/index.d.ts +10 -4
  67. package/dist/schemas/workspace-specification/index.d.ts.map +1 -1
  68. package/dist/schemas/workspace.d.ts +70 -28
  69. package/dist/schemas/workspace.d.ts.map +1 -1
  70. package/package.json +5 -5
  71. package/dist/helpers/debounce.d.ts +0 -28
  72. package/dist/helpers/debounce.d.ts.map +0 -1
  73. package/dist/helpers/debounce.js +0 -31
  74. package/dist/helpers/debounce.js.map +0 -7
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/mutators/auth.ts"],
4
- "sourcesContent": ["import type { HttpMethod } from '@scalar/helpers/http/http-methods'\n\nimport { generateUniqueValue } from '@/helpers/generate-unique-value'\nimport { getResolvedRef } from '@/helpers/get-resolved-ref'\nimport type { WorkspaceDocument } from '@/schemas'\nimport type { SecurityRequirementObject } from '@/schemas/v3.1/strict/security-requirement'\nimport type { SecuritySchemeObject } from '@/schemas/v3.1/strict/security-scheme'\n\n/**\n * AuthMeta defines the meta information needed to specify whether the authentication operation\n * is being performed at the document level (entire API), or for a specific operation (specific path and method).\n *\n * - If type is 'document', the operation applies to the whole OpenAPI document.\n * - If type is 'operation', it targets a specific operation, identified by its path and method.\n */\nexport type AuthMeta =\n | {\n type: 'document'\n }\n | {\n type: 'operation'\n path: string\n method: HttpMethod\n }\n\n/**\n * Updates the selected security schemes for either the entire document or a specific operation.\n * - Adds newly created security schemes (if any) to the workspace document's components.\n * - Ensures that each new scheme name is unique within the document by using `generateUniqueValue`.\n * - Updates the `x-scalar-selected-security` property on the target (document or operation) to reflect the new set of selected security schemes.\n * - Corrects and maintains the selected index so it points to a valid security scheme.\n *\n * @param document - The workspace OpenAPI document to mutate (can be null, in which case nothing happens)\n * @param selectedSecuritySchemes - The current list of selected security scheme objects\n * @param create - Array of new schemes to create, each with a name and a scheme definition\n * @param meta - Location to update: whole document or a specific operation (`{ type: 'document' }` or `{ type: 'operation', path, method }`)\n *\n * Example usage:\n * ```\n * updateSelectedSecuritySchemes({\n * document,\n * selectedSecuritySchemes: [{ bearerAuth: [] }],\n * create: [\n * { name: 'ApiKeyAuth', scheme: { type: 'apiKey', in: 'header', name: 'X-API-Key' } }\n * ],\n * meta: { type: 'document' }\n * })\n * ```\n */\nexport const updateSelectedSecuritySchemes = ({\n document,\n selectedRequirements,\n newSchemes,\n meta,\n}: {\n document: WorkspaceDocument | null\n selectedRequirements: SecurityRequirementObject[]\n newSchemes: { name: string; scheme: SecuritySchemeObject }[]\n meta: AuthMeta\n}) => {\n if (!document) {\n return\n }\n\n // Helper to get the target (whole document or a specific operation)\n const getTarget = () => {\n if (meta.type === 'document') {\n return document\n }\n\n return getResolvedRef(document.paths?.[meta.path]?.[meta.method])\n }\n\n // Create any new security schemes required, ensuring unique names for the components\n const createdSchemes = newSchemes\n .map((scheme) => {\n const name = generateUniqueValue({\n defaultValue: scheme.name,\n validation: (value) => !document.components?.securitySchemes?.[value],\n maxRetries: 100,\n })\n\n if (!name) {\n return\n }\n\n // Ensure components and securitySchemes exist\n if (!document.components) {\n document.components = {}\n }\n if (!document.components.securitySchemes) {\n document.components.securitySchemes = {}\n }\n\n // Add the new security scheme definition\n document.components.securitySchemes[name] = scheme.scheme\n\n // Return an OpenAPI Security Requirement Object for this new scheme (empty scope array)\n return {\n [name]: [],\n }\n })\n .filter(Boolean) as SecurityRequirementObject[]\n\n const target = getTarget()\n\n const newSelectedSecuritySchemes = [...selectedRequirements, ...createdSchemes]\n\n // If the target (document/operation) doesn't exist, do nothing\n if (!target) {\n return\n }\n\n // Ensure the x-scalar-selected-security structure exists on the target\n if (!target['x-scalar-selected-security']) {\n target['x-scalar-selected-security'] = {\n 'x-selected-index': -1,\n 'x-schemes': [],\n }\n }\n\n const selectedIndex = target['x-scalar-selected-security']['x-selected-index']\n\n // Update the schemes array\n target['x-scalar-selected-security']['x-schemes'] = newSelectedSecuritySchemes\n\n // Adjust selected index if there are schemes and the index is unset/invalid\n if (newSelectedSecuritySchemes.length > 0 && selectedIndex < 0) {\n target['x-scalar-selected-security']['x-selected-index'] = 0\n }\n\n // If the selected index is now out of bounds, select the last available\n if (selectedIndex >= newSelectedSecuritySchemes.length) {\n target['x-scalar-selected-security']['x-selected-index'] = newSelectedSecuritySchemes.length - 1\n }\n}\n\n/**\n * SecuritySchemeUpdate represents the possible updates that can be made\n * to an OpenAPI security scheme object via UI interactions.\n *\n * - `http`: Updates to HTTP type schemes (e.g. basic, bearer), allowing token, username, and password changes.\n * - `apiKey`: Updates to API Key type schemes, allowing the key name and its value to be updated.\n * - `oauth2`: Updates to OAuth2 type schemes for each supported OAuth2 flow.\n * - Can set various properties such as auth/token URLs, tokens, PKCE method, client credentials, etc.\n */\nexport type SecuritySchemeUpdate =\n | {\n type: 'http'\n payload: Partial<{\n token: string\n username: string\n password: string\n }>\n }\n | {\n type: 'apiKey'\n payload: Partial<{\n name: string\n value: string\n }>\n }\n | {\n type: 'oauth2'\n flow: 'implicit' | 'password' | 'clientCredentials' | 'authorizationCode'\n payload: Partial<{\n authUrl: string\n tokenUrl: string\n token: string\n redirectUrl: string\n clientId: string\n clientSecret: string\n usePkce: 'no' | 'SHA-256' | 'plain'\n username: string\n password: string\n }>\n }\n\n/**\n * Updates a security scheme in the OpenAPI document's components object.\n * Handles updates for HTTP, API Key, and OAuth2 types, saving secret information and configuration for UI-auth flows.\n *\n * @param document - The OpenAPI workspace document (can be null)\n * @param data - The update information, including type and payload\n * @param name - The name of the security scheme in document.components.securitySchemes\n *\n * Example usage:\n *\n * updateSecurityScheme({\n * document,\n * data: {\n * type: 'http',\n * payload: {\n * username: 'user123',\n * password: 'pw123',\n * token: 'tokenval'\n * }\n * },\n * name: 'MyHttpAuth',\n * })\n */\nexport const updateSecurityScheme = ({\n document,\n data,\n name,\n}: {\n document: WorkspaceDocument | null\n data: SecuritySchemeUpdate\n name: string\n}) => {\n if (!document) {\n return\n }\n\n const target = getResolvedRef(document.components?.securitySchemes?.[name])\n\n if (!target) {\n return\n }\n\n // Handle HTTP (basic, bearer, etc.)\n if (target.type === 'http' && data.type === 'http') {\n if (data.payload.username) {\n target['x-scalar-secret-username'] = data.payload.username\n }\n if (data.payload.password) {\n target['x-scalar-secret-password'] = data.payload.password\n }\n if (data.payload.token) {\n target['x-scalar-secret-token'] = data.payload.token\n }\n\n // Handle API Key\n } else if (target.type === 'apiKey' && data.type === 'apiKey') {\n if (data.payload.name) {\n target.name = data.payload.name\n }\n if (data.payload.value) {\n target['x-scalar-secret-token'] = data.payload.value\n }\n\n // Handle OAuth2 (various flows)\n } else if (target.type === 'oauth2' && data.type === 'oauth2') {\n const flow = target.flows[data.flow]\n if (!flow) {\n // If the flow is not found, do nothing\n return\n }\n\n if (data.payload.authUrl && 'authorizationUrl' in flow) {\n flow.authorizationUrl = data.payload.authUrl\n }\n if (data.payload.tokenUrl && 'tokenUrl' in flow) {\n flow.tokenUrl = data.payload.tokenUrl\n }\n if (data.payload.token && 'x-scalar-secret-token' in flow) {\n flow['x-scalar-secret-token'] = data.payload.token\n }\n if (data.payload.redirectUrl && 'x-scalar-secret-redirect-uri' in flow) {\n flow['x-scalar-secret-redirect-uri'] = data.payload.redirectUrl\n }\n if (data.payload.clientId && 'x-scalar-secret-client-id' in flow) {\n flow['x-scalar-secret-client-id'] = data.payload.clientId\n }\n if (data.payload.clientSecret && 'x-scalar-secret-client-secret' in flow) {\n flow['x-scalar-secret-client-secret'] = data.payload.clientSecret\n }\n if (data.payload.usePkce && 'x-usePkce' in flow) {\n flow['x-usePkce'] = data.payload.usePkce\n }\n if (data.payload.username && 'x-scalar-secret-username' in flow) {\n flow['x-scalar-secret-username'] = data.payload.username\n }\n if (data.payload.password && 'x-scalar-secret-password' in flow) {\n flow['x-scalar-secret-password'] = data.payload.password\n }\n }\n\n // TODO: handle openid connect type in the future\n\n return\n}\n\n/**\n * Sets the selected authentication tab (scheme) index for the given OpenAPI document or operation.\n * - When on the document level, updates the 'x-selected-index' on the document's x-scalar-selected-security extension.\n * - When on an operation (endpoint) level, updates the 'x-selected-index' for that operation's x-scalar-selected-security.\n *\n * Also initializes the x-scalar-selected-security extension if it does not exist.\n *\n * @param document The OpenAPI document object (may be null)\n * @param index The index to set as selected\n * @param meta Context where the selection applies ('document' or specific operation)\n *\n * @example\n * // Document-level tab selection\n * updateSelectedAuthTab({\n * document,\n * index: 1,\n * meta: { type: 'document' }\n * });\n *\n * // Operation-level tab selection (e.g., GET /pets)\n * updateSelectedAuthTab({\n * document,\n * index: 0,\n * meta: { type: 'operation', path: '/pets', method: 'get' }\n * });\n */\nexport const updateSelectedAuthTab = ({\n document,\n index,\n meta,\n}: {\n document: WorkspaceDocument | null\n index: number\n meta: AuthMeta\n}) => {\n if (!document) {\n return\n }\n\n // Determine the target object for setting the auth tab index:\n // - Document/root level\n // - Operation/endpoint level (if meta specifies operation)\n const getTarget = () => {\n if (meta.type === 'document') {\n return document\n }\n return getResolvedRef(document.paths?.[meta.path]?.[meta.method])\n }\n\n const target = getTarget()\n if (!target) {\n return\n }\n\n // Ensure the 'x-scalar-selected-security' extension exists\n if (!target['x-scalar-selected-security']) {\n target['x-scalar-selected-security'] = {\n 'x-selected-index': 0,\n 'x-schemes': [],\n }\n }\n\n // Set the selected auth tab index\n target['x-scalar-selected-security']['x-selected-index'] = index\n}\n\n/**\n * Updates the scopes for a specific security requirement in the selected security schemes of\n * a document or operation.\n *\n * @param document - The OpenAPI WorkspaceDocument to update.\n * @param id - An array of scheme names that uniquely identifies the target security requirement.\n * For example: ['OAuth', 'ApiKeyAuth']\n * @param name - The security scheme name to update scopes for (e.g., 'OAuth').\n * @param scopes - The new list of scopes to set. For example: ['read:pets', 'write:pets']\n * @param meta - The context specifying whether the update is at the document-level or operation-level.\n *\n * Example usage:\n * ```ts\n * // Suppose your document (or operation) x-scalar-selected-security looks like:\n * // \"x-scalar-selected-security\": {\n * // \"x-selected-index\": 0,\n * // \"x-schemes\": [\n * // { \"OAuth\": [\"read:pets\"] },\n * // { \"ApiKeyAuth\": [] }\n * // ]\n * // }\n *\n * updateSelectedScopes({\n * document,\n * id: [\"OAuth\"], // identifies the scheme object: { \"OAuth\": [...] }\n * name: \"OAuth\", // scheme name to update within this security requirement\n * scopes: [\"write:pets\"], // new scopes array\n * meta: { type: \"document\" }\n * })\n * // After, the first scheme becomes: { \"OAuth\": [\"write:pets\"] }\n * ```\n */\nexport const updateSelectedScopes = ({\n document,\n id,\n name,\n scopes,\n meta,\n}: {\n document: WorkspaceDocument | null\n id: string[]\n name: string\n scopes: string[]\n meta: AuthMeta\n}) => {\n if (!document) {\n return\n }\n\n // Determine the target object (document or the operation)\n const getTarget = () => {\n if (meta.type === 'document') {\n return document\n }\n return getResolvedRef(document.paths?.[meta.path]?.[meta.method])\n }\n\n const target = getTarget()\n\n if (!target) {\n return\n }\n\n // Array of security requirement objects under x-scalar-selected-security\n const selectedSchemes = target['x-scalar-selected-security']?.['x-schemes']\n\n if (!selectedSchemes) {\n return\n }\n\n // Find the security requirement that matches the given id (scheme key names)\n // For example: if id = [\"OAuth\"], matches { OAuth: [...] }\n const scheme = selectedSchemes.find((scheme) => JSON.stringify(Object.keys(scheme)) === JSON.stringify(id))\n\n if (!scheme) {\n return\n }\n\n // Set the scopes array for the named security scheme within the found security requirement\n scheme[name] = scopes\n}\n\n/**\n * Deletes one or more security schemes from an OpenAPI WorkspaceDocument,\n * and removes all references to those schemes from selected security, document-level security,\n * and operation-level security/selected security (e.g., on paths).\n *\n * Example usage:\n *\n * ```ts\n * deleteSecurityScheme({\n * document, // The OpenAPI document to update\n * names: ['ApiKeyAuth', 'BearerAuth'], // The names of security schemes you want to delete\n * });\n * ```\n *\n * After running this function:\n * - The named security schemes are removed from the components.securitySchemes section.\n * - All document-level and operation-level security entries referencing those schemes are removed.\n * - Any extended x-scalar-selected-security references to those schemes are also removed.\n */\nexport const deleteSecurityScheme = ({ document, names }: { document: WorkspaceDocument | null; names: string[] }) => {\n if (!document) {\n // Early exit if there is no document to modify\n return\n }\n\n // Get the mutable reference to securitySchemes in components (may be a proxy/resolved reference)\n const target = getResolvedRef(document.components?.securitySchemes)\n\n if (!target) {\n // If there are no security schemes to delete from, return early\n return\n }\n\n // Remove each named security scheme from the components.securitySchemes object\n names.forEach((name) => {\n delete target[name]\n })\n\n // Function to remove any security requirement objects that reference given scheme names.\n const filterSecuritySchemes = (schemes: SecurityRequirementObject[]) => {\n // Remove schemes whose key is included in the `names` to be deleted.\n return schemes.filter((scheme) => !names.some((name) => Object.keys(scheme).includes(name)))\n }\n\n // -- Remove from document-level `x-scalar-selected-security` extension, if present\n if (document['x-scalar-selected-security']) {\n const selectedSecurity = document['x-scalar-selected-security']\n selectedSecurity['x-schemes'] = filterSecuritySchemes(selectedSecurity['x-schemes'])\n }\n\n // -- Remove from document-level `security` property, if present\n if (document['security']) {\n document['security'] = filterSecuritySchemes(document['security'])\n }\n\n // -- For each path and operation, remove deleted security schemes from operation-level security and custom extension\n Object.values(document.paths ?? {}).forEach((path) => {\n Object.values(path).forEach((operation) => {\n if (typeof operation !== 'object') {\n // Ignore operations that are not objects (could be undefined)\n return\n }\n\n // Get mutable reference for the operation (could resolve $ref proxies)\n const resolvedOperation = getResolvedRef(operation)\n\n // Remove from operation-level security array\n if ('security' in resolvedOperation && resolvedOperation['security']) {\n resolvedOperation['security'] = filterSecuritySchemes(resolvedOperation['security'])\n }\n\n // Remove from operation-level x-scalar-selected-security array\n if ('x-scalar-selected-security' in resolvedOperation && resolvedOperation['x-scalar-selected-security']) {\n resolvedOperation['x-scalar-selected-security']['x-schemes'] = filterSecuritySchemes(\n resolvedOperation['x-scalar-selected-security']['x-schemes'],\n )\n }\n })\n })\n}\n"],
5
- "mappings": "AAEA,SAAS,2BAA2B;AACpC,SAAS,sBAAsB;AA8CxB,MAAM,gCAAgC,CAAC;AAAA,EAC5C;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,MAKM;AACJ,MAAI,CAAC,UAAU;AACb;AAAA,EACF;AAGA,QAAM,YAAY,MAAM;AACtB,QAAI,KAAK,SAAS,YAAY;AAC5B,aAAO;AAAA,IACT;AAEA,WAAO,eAAe,SAAS,QAAQ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AAkB,UAAU,CAAC;AAAA,MACrF;AAGA,UAAI,gCAAgC,qBAAqB,kBAAkB,4BAA4B,GAAG;AACxG,0BAAkB,4BAA4B,EAAE,WAAW,IAAI;AAAA,UAC7D,kBAAkB,4BAA4B,EAAE,WAAW;AAAA,QAC7D;AAAA,MACF;AAAA,IACF,CAAC;AAAA,EACH,CAAC;AACH;",
4
+ "sourcesContent": ["import type { HttpMethod } from '@scalar/helpers/http/http-methods'\n\nimport type { AuthEvents } from '@/events/definitions/auth'\nimport { generateUniqueValue } from '@/helpers/generate-unique-value'\nimport { getResolvedRef } from '@/helpers/get-resolved-ref'\nimport { mergeObjects } from '@/helpers/merge-object'\nimport type { WorkspaceDocument } from '@/schemas'\nimport type { SecurityRequirementObject } from '@/schemas/v3.1/strict/security-requirement'\n\n/**\n * AuthMeta defines the meta information needed to specify whether the authentication operation\n * is being performed at the document level (entire API), or for a specific operation (specific path and method).\n *\n * - If type is 'document', the operation applies to the whole OpenAPI document.\n * - If type is 'operation', it targets a specific operation, identified by its path and method.\n */\nexport type AuthMeta =\n | {\n type: 'document'\n }\n | {\n type: 'operation'\n path: string\n method: HttpMethod\n }\n\n/**\n * Updates the selected security schemes for either the entire document or a specific operation.\n * - Adds newly created security schemes (if any) to the workspace document's components.\n * - Ensures that each new scheme name is unique within the document by using `generateUniqueValue`.\n * - Updates the `x-scalar-selected-security` property on the target (document or operation) to reflect the new set of selected security schemes.\n * - Corrects and maintains the selected index so it points to a valid security scheme.\n *\n * @param document - The workspace OpenAPI document to mutate (can be null, in which case nothing happens)\n * @param selectedSecuritySchemes - The current list of selected security scheme objects\n * @param create - Array of new schemes to create, each with a name and a scheme definition\n * @param meta - Location to update: whole document or a specific operation (`{ type: 'document' }` or `{ type: 'operation', path, method }`)\n *\n * Example usage:\n * ```\n * updateSelectedSecuritySchemes({\n * document,\n * selectedSecuritySchemes: [{ bearerAuth: [] }],\n * create: [\n * { name: 'ApiKeyAuth', scheme: { type: 'apiKey', in: 'header', name: 'X-API-Key' } }\n * ],\n * meta: { type: 'document' }\n * })\n * ```\n */\nexport const updateSelectedSecuritySchemes = (\n document: WorkspaceDocument | null,\n { selectedRequirements, newSchemes, meta }: AuthEvents['auth:update:selected-security-schemes'],\n) => {\n if (!document) {\n return\n }\n\n // Helper to get the target (whole document or a specific operation)\n const getTarget = () => {\n if (meta.type === 'document') {\n return document\n }\n\n return getResolvedRef(document.paths?.[meta.path]?.[meta.method])\n }\n\n // Create any new security schemes required, ensuring unique names for the components\n const createdSchemes = newSchemes\n .map((scheme) => {\n const name = generateUniqueValue({\n defaultValue: scheme.name,\n validation: (value) => !document.components?.securitySchemes?.[value],\n maxRetries: 100,\n })\n\n if (!name) {\n return\n }\n\n // Ensure components and securitySchemes exist\n if (!document.components) {\n document.components = {}\n }\n if (!document.components.securitySchemes) {\n document.components.securitySchemes = {}\n }\n\n // Add the new security scheme definition\n document.components.securitySchemes[name] = scheme.scheme\n\n // Return an OpenAPI Security Requirement Object for this new scheme (empty scope array)\n return {\n [name]: [],\n }\n })\n .filter(Boolean) as SecurityRequirementObject[]\n\n const target = getTarget()\n\n const newSelectedSecuritySchemes = [...selectedRequirements, ...createdSchemes]\n\n // If the target (document/operation) doesn't exist, do nothing\n if (!target) {\n return\n }\n\n // Ensure the x-scalar-selected-security structure exists on the target\n if (!target['x-scalar-selected-security']) {\n target['x-scalar-selected-security'] = {\n selectedIndex: -1,\n selectedSchemes: [],\n }\n }\n\n const selectedIndex = target['x-scalar-selected-security'].selectedIndex\n\n // Update the schemes array\n target['x-scalar-selected-security'].selectedSchemes = newSelectedSecuritySchemes\n\n // Adjust selected index if there are schemes and the index is unset/invalid\n if (newSelectedSecuritySchemes.length > 0 && selectedIndex < 0) {\n target['x-scalar-selected-security'].selectedIndex = 0\n }\n\n // If the selected index is now out of bounds, select the last available\n if (selectedIndex >= newSelectedSecuritySchemes.length) {\n target['x-scalar-selected-security'].selectedIndex = newSelectedSecuritySchemes.length - 1\n }\n}\n\n/**\n * Updates a security scheme in the OpenAPI document's components object.\n * Handles updates for HTTP, API Key, and OAuth2 types, saving secret information and configuration for UI-auth flows.\n *\n * @param document - The OpenAPI workspace document (can be null)\n * @param data - The update information, including type and payload\n * @param name - The name of the security scheme in document.components.securitySchemes\n *\n * Example usage:\n *\n * updateSecurityScheme({\n * document,\n * data: {\n * type: 'http',\n * payload: {\n * username: 'user123',\n * password: 'pw123',\n * token: 'tokenval'\n * }\n * },\n * name: 'MyHttpAuth',\n * })\n */\nexport const updateSecurityScheme = (\n document: WorkspaceDocument | null,\n { payload, name }: AuthEvents['auth:update:security-scheme'],\n) => {\n const target = getResolvedRef(document?.components?.securitySchemes?.[name])\n if (!target) {\n console.error(`Security scheme ${name} not found`)\n return\n }\n\n // Handle HTTP (basic, bearer, etc.)\n if (target.type === payload.type) {\n mergeObjects(target, payload)\n }\n\n return target\n}\n\n/**\n * Sets the selected authentication tab (scheme) index for the given OpenAPI document or operation.\n * - When on the document level, updates the 'selectedIndex' on the document's x-scalar-selected-security extension.\n * - When on an operation (endpoint) level, updates the 'selectedIndex' for that operation's x-scalar-selected-security.\n *\n * Also initializes the x-scalar-selected-security extension if it does not exist.\n *\n * @param document The OpenAPI document object (may be null)\n * @param index The index to set as selected\n * @param meta Context where the selection applies ('document' or specific operation)\n *\n * @example\n * // Document-level tab selection\n * updateSelectedAuthTab({\n * document,\n * index: 1,\n * meta: { type: 'document' }\n * });\n *\n * // Operation-level tab selection (e.g., GET /pets)\n * updateSelectedAuthTab({\n * document,\n * index: 0,\n * meta: { type: 'operation', path: '/pets', method: 'get' }\n * });\n */\nexport const updateSelectedAuthTab = (\n document: WorkspaceDocument | null,\n { index, meta }: AuthEvents['auth:update:active-index'],\n) => {\n if (!document) {\n return\n }\n\n // Determine the target object for setting the auth tab index:\n // - Document/root level\n // - Operation/endpoint level (if meta specifies operation)\n const getTarget = () => {\n if (meta.type === 'document') {\n return document\n }\n return getResolvedRef(document.paths?.[meta.path]?.[meta.method])\n }\n\n const target = getTarget()\n if (!target) {\n return\n }\n\n // Ensure the 'x-scalar-selected-security' extension exists\n if (!target['x-scalar-selected-security']) {\n target['x-scalar-selected-security'] = {\n selectedIndex: 0,\n selectedSchemes: [],\n }\n }\n\n // Set the selected auth tab index\n target['x-scalar-selected-security'].selectedIndex = index\n}\n\n/**\n * Updates the scopes for a specific security requirement in the selected security schemes of\n * a document or operation.\n *\n * @param document - The OpenAPI WorkspaceDocument to update.\n * @param id - An array of scheme names that uniquely identifies the target security requirement.\n * For example: ['OAuth', 'ApiKeyAuth']\n * @param name - The security scheme name to update scopes for (e.g., 'OAuth').\n * @param scopes - The new list of scopes to set. For example: ['read:pets', 'write:pets']\n * @param meta - The context specifying whether the update is at the document-level or operation-level.\n *\n * Example usage:\n * ```ts\n * // Suppose your document (or operation) x-scalar-selected-security looks like:\n * // \"x-scalar-selected-security\": {\n * // selectedIndex: 0,\n * // selectedSchemes: [\n * // { \"OAuth\": [\"read:pets\"] },\n * // { \"ApiKeyAuth\": [] }\n * // ]\n * // }\n *\n * updateSelectedScopes({\n * document,\n * id: [\"OAuth\"], // identifies the scheme object: { \"OAuth\": [...] }\n * name: \"OAuth\", // scheme name to update within this security requirement\n * scopes: [\"write:pets\"], // new scopes array\n * meta: { type: \"document\" }\n * })\n * // After, the first scheme becomes: { \"OAuth\": [\"write:pets\"] }\n * ```\n */\nexport const updateSelectedScopes = (\n document: WorkspaceDocument | null,\n { id, name, scopes, meta }: AuthEvents['auth:update:selected-scopes'],\n) => {\n if (!document) {\n return\n }\n\n // Determine the target object (document or the operation)\n const getTarget = () => {\n if (meta.type === 'document') {\n return document\n }\n return getResolvedRef(document.paths?.[meta.path]?.[meta.method])\n }\n\n const target = getTarget()\n\n if (!target) {\n return\n }\n\n // Array of security requirement objects under x-scalar-selected-security\n const selectedSchemes = target['x-scalar-selected-security']?.selectedSchemes\n\n if (!selectedSchemes) {\n return\n }\n\n // Find the security requirement that matches the given id (scheme key names)\n // For example: if id = [\"OAuth\"], matches { OAuth: [...] }\n const scheme = selectedSchemes.find((scheme) => JSON.stringify(Object.keys(scheme)) === JSON.stringify(id))\n\n if (!scheme) {\n return\n }\n\n // Set the scopes array for the named security scheme within the found security requirement\n scheme[name] = scopes\n}\n\n/**\n * Deletes one or more security schemes from an OpenAPI WorkspaceDocument,\n * and removes all references to those schemes from selected security, document-level security,\n * and operation-level security/selected security (e.g., on paths).\n *\n * Example usage:\n *\n * ```ts\n * deleteSecurityScheme({\n * document, // The OpenAPI document to update\n * names: ['ApiKeyAuth', 'BearerAuth'], // The names of security schemes you want to delete\n * });\n * ```\n *\n * After running this function:\n * - The named security schemes are removed from the components.securitySchemes section.\n * - All document-level and operation-level security entries referencing those schemes are removed.\n * - Any extended x-scalar-selected-security references to those schemes are also removed.\n */\nexport const deleteSecurityScheme = (\n document: WorkspaceDocument | null,\n { names }: AuthEvents['auth:delete:security-scheme'],\n) => {\n if (!document) {\n // Early exit if there is no document to modify\n return\n }\n\n // Get the mutable reference to securitySchemes in components (may be a proxy/resolved reference)\n const target = getResolvedRef(document.components?.securitySchemes)\n\n if (!target) {\n // If there are no security schemes to delete from, return early\n return\n }\n\n // Remove each named security scheme from the components.securitySchemes object\n names.forEach((name) => {\n delete target[name]\n })\n\n // Function to remove any security requirement objects that reference given scheme names.\n const filterSecuritySchemes = (schemes: SecurityRequirementObject[]) => {\n // Remove schemes whose key is included in the `names` to be deleted.\n return schemes.filter((scheme) => !names.some((name) => Object.keys(scheme).includes(name)))\n }\n\n // -- Remove from document-level `x-scalar-selected-security` extension, if present\n if (document['x-scalar-selected-security']) {\n const selectedSecurity = document['x-scalar-selected-security']\n selectedSecurity.selectedSchemes = filterSecuritySchemes(selectedSecurity.selectedSchemes)\n }\n\n // -- Remove from document-level `security` property, if present\n if (document['security']) {\n document['security'] = filterSecuritySchemes(document['security'])\n }\n\n // -- For each path and operation, remove deleted security schemes from operation-level security and custom extension\n Object.values(document.paths ?? {}).forEach((path) => {\n Object.values(path).forEach((operation) => {\n if (typeof operation !== 'object') {\n // Ignore operations that are not objects (could be undefined)\n return\n }\n\n // Get mutable reference for the operation (could resolve $ref proxies)\n const resolvedOperation = getResolvedRef(operation)\n\n // Remove from operation-level security array\n if ('security' in resolvedOperation && resolvedOperation['security']) {\n resolvedOperation['security'] = filterSecuritySchemes(resolvedOperation['security'])\n }\n\n // Remove from operation-level x-scalar-selected-security array\n if ('x-scalar-selected-security' in resolvedOperation && resolvedOperation['x-scalar-selected-security']) {\n resolvedOperation['x-scalar-selected-security'].selectedSchemes = filterSecuritySchemes(\n resolvedOperation['x-scalar-selected-security'].selectedSchemes,\n )\n }\n })\n })\n}\n"],
5
+ "mappings": "AAGA,SAAS,2BAA2B;AACpC,SAAS,sBAAsB;AAC/B,SAAS,oBAAoB;AA6CtB,MAAM,gCAAgC,CAC3C,UACA,EAAE,sBAAsB,YAAY,KAAK,MACtC;AACH,MAAI,CAAC,UAAU;AACb;AAAA,EACF;AAGA,QAAM,YAAY,MAAM;AACtB,QAAI,KAAK,SAAS,YAAY;AAC5B,aAAO;AAAA,IACT;AAEA,WAAO,eAAe,SAAS,QAAQ,KAAK,IAAI,IAAI,KAAK,MAAM,CAAC;AAAA,EAClE;AAGA,QAAM,iBAAiB,WACpB,IAAI,CAAC,WAAW;AACf,UAAM,OAAO,oBAAoB;AAAA,MAC/B,cAAc,OAAO;AAAA,MACrB,YAAY,CAAC,UAAU,CAAC,SAAS,YAAY,kBAAkB,KAAK;AAAA,MACpE,YAAY;AAAA,IACd,CAAC;AAED,QAAI,CAAC,MAAM;AACT;AAAA,IACF;AAGA,QAAI,CAAC,SAAS,YAAY;AACxB,eAAS,aAAa,CAAC;AAAA,IACzB;AACA,QAAI,CAAC,SAAS,WAAW,iBAAiB;AACxC,eAAS,WAAW,kBAAkB,CAAC;AAAA,IACzC;AAGA,aAAS,WAAW,gBAAgB,IAAI,IAAI,OAAO;AAGnD,WAAO;AAAA,MACL,CAAC,IAAI,GAAG,CAAC;AAAA,IACX;AAAA,EACF,CAAC,EACA,OAAO,O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,UAAU,GAAG;AACxB,aAAS,UAAU,IAAI,sBAAsB,SAAS,UAAU,CAAC;AAAA,EACnE;AAGA,SAAO,OAAO,SAAS,SAAS,CAAC,CAAC,EAAE,QAAQ,CAAC,SAAS;AACpD,WAAO,OAAO,IAAI,EAAE,QAAQ,CAAC,cAAc;AACzC,UAAI,OAAO,cAAc,UAAU;AAEjC;AAAA,MACF;AAGA,YAAM,oBAAoB,eAAe,SAAS;AAGlD,UAAI,cAAc,qBAAqB,kBAAkB,UAAU,GAAG;AACpE,0BAAkB,UAAU,IAAI,sBAAsB,kBAAkB,UAAU,CAAC;AAAA,MACrF;AAGA,UAAI,gCAAgC,qBAAqB,kBAAkB,4BAA4B,GAAG;AACxG,0BAAkB,4BAA4B,EAAE,kBAAkB;AAAA,UAChE,kBAAkB,4BAA4B,EAAE;AAAA,QAClD;AAAA,MACF;AAAA,IACF,CAAC;AAAA,EACH,CAAC;AACH;",
6
6
  "names": ["scheme"]
7
7
  }
@@ -0,0 +1,6 @@
1
+ import type { WorkspaceDocument } from '../schemas.js';
2
+ /**
3
+ * Toggle use document security
4
+ */
5
+ export declare const toggleDocumentSecurity: (document: WorkspaceDocument | null) => void;
6
+ //# sourceMappingURL=document.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"document.d.ts","sourceRoot":"","sources":["../../src/mutators/document.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAA;AAElD;;GAEG;AACH,eAAO,MAAM,sBAAsB,GAAI,UAAU,iBAAiB,GAAG,IAAI,SAMxE,CAAA"}
@@ -0,0 +1,10 @@
1
+ const toggleDocumentSecurity = (document) => {
2
+ if (!document) {
3
+ return;
4
+ }
5
+ document["x-scalar-document-security"] = !document["x-scalar-document-security"];
6
+ };
7
+ export {
8
+ toggleDocumentSecurity
9
+ };
10
+ //# sourceMappingURL=document.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/mutators/document.ts"],
4
+ "sourcesContent": ["import type { WorkspaceDocument } from '@/schemas'\n\n/**\n * Toggle use document security\n */\nexport const toggleDocumentSecurity = (document: WorkspaceDocument | null) => {\n if (!document) {\n return\n }\n\n document['x-scalar-document-security'] = !document['x-scalar-document-security']\n}\n"],
5
+ "mappings": "AAKO,MAAM,yBAAyB,CAAC,aAAuC;AAC5E,MAAI,CAAC,UAAU;AACb;AAAA,EACF;AAEA,WAAS,4BAA4B,IAAI,CAAC,SAAS,4BAA4B;AACjF;",
6
+ "names": []
7
+ }
@@ -1,5 +1,6 @@
1
1
  /** biome-ignore-all lint/performance/noBarrelFile: Mutators entry point */
2
2
  import type { WorkspaceStore } from '../client.js';
3
+ import type { ServerObject } from '../schemas/v3.1/strict/openapi-document.js';
3
4
  /**
4
5
  * Generates a set of mutators for managing OpenAPI document and workspace state.
5
6
  *
@@ -18,11 +19,11 @@ export declare function generateClientMutators(store: WorkspaceStore): {
18
19
  deleteCookie: (cookieName: string) => boolean;
19
20
  };
20
21
  serverMutators: {
21
- addServer: (server: import("../schemas/v3.1/strict/server.js").ServerObject) => boolean;
22
+ addServer: (server: ServerObject) => boolean;
22
23
  deleteServer: (url: string) => boolean;
23
24
  };
24
25
  securitySchemeMutators: {
25
- addSecurityScheme: (name: string, securityScheme: import("../schemas/v3.1/strict/security-scheme.js").SecuritySchemeObject) => boolean;
26
+ addSecurityScheme: (name: string, securityScheme: import("../schemas/v3.1/strict/openapi-document.js").SecuritySchemeObject) => boolean;
26
27
  deleteSecurityScheme: (name: string) => boolean;
27
28
  };
28
29
  };
@@ -39,7 +40,7 @@ export declare function generateClientMutators(store: WorkspaceStore): {
39
40
  deleteRequest: ({ path, method }: import("../mutators/request.js").OperationIdentifier) => boolean;
40
41
  };
41
42
  securitySchemeMutators: {
42
- addSecurityScheme: (name: string, securityScheme: import("../schemas/v3.1/strict/security-scheme.js").SecuritySchemeObject) => boolean;
43
+ addSecurityScheme: (name: string, securityScheme: import("../schemas/v3.1/strict/openapi-document.js").SecuritySchemeObject) => boolean;
43
44
  deleteSecurityScheme: (name: string) => boolean;
44
45
  };
45
46
  cookieMutators: {
@@ -47,7 +48,7 @@ export declare function generateClientMutators(store: WorkspaceStore): {
47
48
  deleteCookie: (cookieName: string) => boolean;
48
49
  };
49
50
  serverMutators: {
50
- addServer: (server: import("../schemas/v3.1/strict/server.js").ServerObject) => boolean;
51
+ addServer: (server: ServerObject) => boolean;
51
52
  deleteServer: (url: string) => boolean;
52
53
  };
53
54
  };
@@ -65,7 +66,7 @@ export declare function generateClientMutators(store: WorkspaceStore): {
65
66
  deleteRequest: ({ path, method }: import("../mutators/request.js").OperationIdentifier) => boolean;
66
67
  };
67
68
  securitySchemeMutators: {
68
- addSecurityScheme: (name: string, securityScheme: import("../schemas/v3.1/strict/security-scheme.js").SecuritySchemeObject) => boolean;
69
+ addSecurityScheme: (name: string, securityScheme: import("../schemas/v3.1/strict/openapi-document.js").SecuritySchemeObject) => boolean;
69
70
  deleteSecurityScheme: (name: string) => boolean;
70
71
  };
71
72
  cookieMutators: {
@@ -73,12 +74,14 @@ export declare function generateClientMutators(store: WorkspaceStore): {
73
74
  deleteCookie: (cookieName: string) => boolean;
74
75
  };
75
76
  serverMutators: {
76
- addServer: (server: import("../schemas/v3.1/strict/server.js").ServerObject) => boolean;
77
+ addServer: (server: ServerObject) => boolean;
77
78
  deleteServer: (url: string) => boolean;
78
79
  };
79
80
  };
80
81
  };
81
- export { type AuthMeta, type SecuritySchemeUpdate, deleteSecurityScheme, updateSecurityScheme, updateSelectedAuthTab, updateSelectedScopes, updateSelectedSecuritySchemes, } from './auth.js';
82
+ export { type AuthMeta, deleteSecurityScheme, updateSecurityScheme, updateSelectedAuthTab, updateSelectedScopes, updateSelectedSecuritySchemes, } from './auth.js';
83
+ export { toggleDocumentSecurity } from './document.js';
82
84
  export { upsertEnvironment, upsertEnvironmentVariable, } from './environment.js';
83
85
  export { type OperationExampleMeta, type OperationMeta, addOperationParameter, addOperationRequestBodyFormRow, deleteAllOperationParameters, deleteOperationParameter, deleteOperationRequestBodyFormRow, updateOperationMethodDraft as updateOperationMethod, updateOperationParameter, updateOperationPathDraft as updateOperationPath, updateOperationRequestBodyContentType, updateOperationRequestBodyExample, updateOperationRequestBodyFormRow, updateOperationSummary, } from './operation.js';
86
+ export { addServer, deleteServer, updateSelectedServer, updateServer, updateServerVariables, } from './server.js';
84
87
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/mutators/index.ts"],"names":[],"mappings":"AAAA,2EAA2E;AAC3E,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,UAAU,CAAA;AAO9C;;;;;;;GAOG;AACH,wBAAgB,sBAAsB,CAAC,KAAK,EAAE,cAAc;IA4DxD;;OAEG;;;;;;;;;;;;;;;IAEH;;;OAGG;;;;;;;;;;;;;;;;;;;;;;IAGH;;;;OAIG;gBACS,MAAM;;;;;;;;;;;;;;;;;;;;;EAErB;AAED,OAAO,EACL,KAAK,QAAQ,EACb,KAAK,oBAAoB,EACzB,oBAAoB,EACpB,oBAAoB,EACpB,qBAAqB,EACrB,oBAAoB,EACpB,6BAA6B,GAC9B,MAAM,QAAQ,CAAA;AACf,OAAO,EACL,iBAAiB,EACjB,yBAAyB,GAC1B,MAAM,eAAe,CAAA;AACtB,OAAO,EACL,KAAK,oBAAoB,EACzB,KAAK,aAAa,EAClB,qBAAqB,EACrB,8BAA8B,EAC9B,4BAA4B,EAC5B,wBAAwB,EACxB,iCAAiC,EACjC,0BAA0B,IAAI,qBAAqB,EACnD,wBAAwB,EACxB,wBAAwB,IAAI,mBAAmB,EAC/C,qCAAqC,EACrC,iCAAiC,EACjC,iCAAiC,EACjC,sBAAsB,GACvB,MAAM,aAAa,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/mutators/index.ts"],"names":[],"mappings":"AAAA,2EAA2E;AAC3E,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,UAAU,CAAA;AAK9C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,wCAAwC,CAAA;AAE1E;;;;;;;GAOG;AACH,wBAAgB,sBAAsB,CAAC,KAAK,EAAE,cAAc;IAqGxD;;OAEG;;;;;;;gCA1FwB,YAAY,KAAG,OAAO;gCAatB,MAAM,KAAG,OAAO;;;;;;;IA+E3C;;;OAGG;;;;;;;;;;;;;;;;;;gCA/FwB,YAAY,KAAG,OAAO;gCAatB,MAAM,KAAG,OAAO;;;IAqF3C;;;;OAIG;gBACS,MAAM;;;;;;;;;;;;;;;;;gCAvGS,YAAY,KAAG,OAAO;gCAatB,MAAM,KAAG,OAAO;;;EA4F9C;AAED,OAAO,EACL,KAAK,QAAQ,EACb,oBAAoB,EACpB,oBAAoB,EACpB,qBAAqB,EACrB,oBAAoB,EACpB,6BAA6B,GAC9B,MAAM,QAAQ,CAAA;AACf,OAAO,EAAE,sBAAsB,EAAE,MAAM,YAAY,CAAA;AACnD,OAAO,EACL,iBAAiB,EACjB,yBAAyB,GAC1B,MAAM,eAAe,CAAA;AACtB,OAAO,EACL,KAAK,oBAAoB,EACzB,KAAK,aAAa,EAClB,qBAAqB,EACrB,8BAA8B,EAC9B,4BAA4B,EAC5B,wBAAwB,EACxB,iCAAiC,EACjC,0BAA0B,IAAI,qBAAqB,EACnD,wBAAwB,EACxB,wBAAwB,IAAI,mBAAmB,EAC/C,qCAAqC,EACrC,iCAAiC,EACjC,iCAAiC,EACjC,sBAAsB,GACvB,MAAM,aAAa,CAAA;AACpB,OAAO,EACL,SAAS,EACT,YAAY,EACZ,oBAAoB,EACpB,YAAY,EACZ,qBAAqB,GACtB,MAAM,UAAU,CAAA"}
@@ -2,8 +2,29 @@ import { cookieMutators } from "../mutators/cookie.js";
2
2
  import { getDocument } from "../mutators/helpers.js";
3
3
  import { requestMutators } from "../mutators/request.js";
4
4
  import { securitySchemeMutators } from "../mutators/security-schemes.js";
5
- import { serverMutators } from "../mutators/server.js";
6
5
  function generateClientMutators(store) {
6
+ const serverMutators = (target) => {
7
+ const addServer2 = (server) => {
8
+ if (!target) {
9
+ return false;
10
+ }
11
+ target.push(server);
12
+ return true;
13
+ };
14
+ const deleteServer2 = (url) => {
15
+ if (!target) {
16
+ return false;
17
+ }
18
+ const newTarget = [...target.filter((it) => it.url !== url)];
19
+ target.splice(0, target.length);
20
+ target.push(...newTarget);
21
+ return true;
22
+ };
23
+ return {
24
+ addServer: addServer2,
25
+ deleteServer: deleteServer2
26
+ };
27
+ };
7
28
  const documentMutators = (documentName) => {
8
29
  const document = getDocument(store, documentName);
9
30
  if (document) {
@@ -63,6 +84,7 @@ import {
63
84
  updateSelectedScopes,
64
85
  updateSelectedSecuritySchemes
65
86
  } from "./auth.js";
87
+ import { toggleDocumentSecurity } from "./document.js";
66
88
  import {
67
89
  upsertEnvironment,
68
90
  upsertEnvironmentVariable
@@ -81,14 +103,24 @@ import {
81
103
  updateOperationRequestBodyFormRow,
82
104
  updateOperationSummary
83
105
  } from "./operation.js";
106
+ import {
107
+ addServer,
108
+ deleteServer,
109
+ updateSelectedServer,
110
+ updateServer,
111
+ updateServerVariables
112
+ } from "./server.js";
84
113
  export {
85
114
  addOperationParameter,
86
115
  addOperationRequestBodyFormRow,
116
+ addServer,
87
117
  deleteAllOperationParameters,
88
118
  deleteOperationParameter,
89
119
  deleteOperationRequestBodyFormRow,
90
120
  deleteSecurityScheme,
121
+ deleteServer,
91
122
  generateClientMutators,
123
+ toggleDocumentSecurity,
92
124
  updateOperationMethodDraft as updateOperationMethod,
93
125
  updateOperationParameter,
94
126
  updateOperationPathDraft as updateOperationPath,
@@ -100,6 +132,9 @@ export {
100
132
  updateSelectedAuthTab,
101
133
  updateSelectedScopes,
102
134
  updateSelectedSecuritySchemes,
135
+ updateSelectedServer,
136
+ updateServer,
137
+ updateServerVariables,
103
138
  upsertEnvironment,
104
139
  upsertEnvironmentVariable
105
140
  };
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/mutators/index.ts"],
4
- "sourcesContent": ["/** biome-ignore-all lint/performance/noBarrelFile: Mutators entry point */\nimport type { WorkspaceStore } from '@/client'\nimport { cookieMutators } from '@/mutators/cookie'\nimport { getDocument } from '@/mutators/helpers'\nimport { requestMutators } from '@/mutators/request'\nimport { securitySchemeMutators } from '@/mutators/security-schemes'\nimport { serverMutators } from '@/mutators/server'\n\n/**\n * Generates a set of mutators for managing OpenAPI document and workspace state.\n *\n * @deprecated use the individual mutators instead, this will be removed after we move fully to the new store\n *\n * @param store - The workspace store containing all documents and workspace-level data\n * @returns An object with mutators for the workspace, the active document, and any named document\n */\nexport function generateClientMutators(store: WorkspaceStore) {\n /**\n * Returns mutators for a specific document by name.\n *\n * @param documentName - The name of the document to get mutators for\n * @returns An object containing mutators for requests, request examples, security schemes, environments, and cookies\n */\n const documentMutators = (documentName: string) => {\n const document = getDocument(store, documentName)\n\n if (document) {\n // Make sure the document has a servers array\n if (!document.servers) {\n document.servers = []\n }\n\n // Make sure the document has the securitySchema object\n if (!document.components) {\n document.components = {}\n }\n\n if (!document.components.securitySchemes) {\n document.components.securitySchemes = {}\n }\n }\n\n return {\n requestMutators: requestMutators(document),\n securitySchemeMutators: securitySchemeMutators(document?.components?.securitySchemes),\n cookieMutators: cookieMutators(document),\n serverMutators: serverMutators(document?.servers),\n }\n }\n\n /**\n * Returns mutators for the workspace-level configuration.\n *\n * @returns An object containing mutators for environments and cookies at the workspace level\n */\n const workspaceMutators = () => {\n const workspace = store.workspace\n\n // Make sure the workspace has a servers array\n if (!workspace['x-scalar-client-config-servers']) {\n workspace['x-scalar-client-config-servers'] = []\n }\n\n // Make sure the workspace has the securitySchema object\n if (!store.workspace['x-scalar-client-config-security-schemes']) {\n store.workspace['x-scalar-client-config-security-schemes'] = {}\n }\n\n return {\n cookieMutators: cookieMutators(store.workspace),\n serverMutators: serverMutators(store.workspace['x-scalar-client-config-servers']),\n securitySchemeMutators: securitySchemeMutators(store.workspace['x-scalar-client-config-security-schemes']),\n }\n }\n\n return {\n /**\n * Returns mutators for the workspace-level configuration.\n */\n workspace: () => workspaceMutators(),\n /**\n * Returns mutators for the currently active document.\n * Falls back to the first document if no active document is set.\n */\n active: () =>\n documentMutators(store.workspace['x-scalar-active-document'] ?? Object.keys(store.workspace.documents)[0] ?? ''),\n /**\n * Returns mutators for a specific document by name.\n *\n * @param name - The name of the document\n */\n doc: (name: string) => documentMutators(name),\n }\n}\n\nexport {\n type AuthMeta,\n type SecuritySchemeUpdate,\n deleteSecurityScheme,\n updateSecurityScheme,\n updateSelectedAuthTab,\n updateSelectedScopes,\n updateSelectedSecuritySchemes,\n} from './auth'\nexport {\n upsertEnvironment,\n upsertEnvironmentVariable,\n} from './environment'\nexport {\n type OperationExampleMeta,\n type OperationMeta,\n addOperationParameter,\n addOperationRequestBodyFormRow,\n deleteAllOperationParameters,\n deleteOperationParameter,\n deleteOperationRequestBodyFormRow,\n updateOperationMethodDraft as updateOperationMethod,\n updateOperationParameter,\n updateOperationPathDraft as updateOperationPath,\n updateOperationRequestBodyContentType,\n updateOperationRequestBodyExample,\n updateOperationRequestBodyFormRow,\n updateOperationSummary,\n} from './operation'\n"],
5
- "mappings": "AAEA,SAAS,sBAAsB;AAC/B,SAAS,mBAAmB;AAC5B,SAAS,uBAAuB;AAChC,SAAS,8BAA8B;AACvC,SAAS,sBAAsB;AAUxB,SAAS,uBAAuB,OAAuB;AAO5D,QAAM,mBAAmB,CAAC,iBAAyB;AACjD,UAAM,WAAW,YAAY,OAAO,YAAY;AAEhD,QAAI,UAAU;AAEZ,UAAI,CAAC,SAAS,SAAS;AACrB,iBAAS,UAAU,CAAC;AAAA,MACtB;AAGA,UAAI,CAAC,SAAS,YAAY;AACxB,iBAAS,aAAa,CAAC;AAAA,MACzB;AAEA,UAAI,CAAC,SAAS,WAAW,iBAAiB;AACxC,iBAAS,WAAW,kBAAkB,CAAC;AAAA,MACzC;AAAA,IACF;AAEA,WAAO;AAAA,MACL,iBAAiB,gBAAgB,QAAQ;AAAA,MACzC,wBAAwB,uBAAuB,UAAU,YAAY,eAAe;AAAA,MACpF,gBAAgB,eAAe,QAAQ;AAAA,MACvC,gBAAgB,eAAe,UAAU,OAAO;AAAA,IAClD;AAAA,EACF;AAOA,QAAM,oBAAoB,MAAM;AAC9B,UAAM,YAAY,MAAM;AAGxB,QAAI,CAAC,UAAU,gCAAgC,GAAG;AAChD,gBAAU,gCAAgC,IAAI,CAAC;AAAA,IACjD;AAGA,QAAI,CAAC,MAAM,UAAU,yCAAyC,GAAG;AAC/D,YAAM,UAAU,yCAAyC,IAAI,CAAC;AAAA,IAChE;AAEA,WAAO;AAAA,MACL,gBAAgB,eAAe,MAAM,SAAS;AAAA,MAC9C,gBAAgB,eAAe,MAAM,UAAU,gCAAgC,CAAC;AAAA,MAChF,wBAAwB,uBAAuB,MAAM,UAAU,yCAAyC,CAAC;AAAA,IAC3G;AAAA,EACF;AAEA,SAAO;AAAA;AAAA;AAAA;AAAA,IAIL,WAAW,MAAM,kBAAkB;AAAA;AAAA;AAAA;AAAA;AAAA,IAKnC,QAAQ,MACN,iBAAiB,MAAM,UAAU,0BAA0B,KAAK,OAAO,KAAK,MAAM,UAAU,SAAS,EAAE,CAAC,KAAK,EAAE;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAMjH,KAAK,CAAC,SAAiB,iBAAiB,IAAI;AAAA,EAC9C;AACF;AAEA;AAAA,EAGE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP;AAAA,EACE;AAAA,EACA;AAAA,OACK;AACP;AAAA,EAGE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EAC8B;AAAA,EAC9B;AAAA,EAC4B;AAAA,EAC5B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;",
6
- "names": []
4
+ "sourcesContent": ["/** biome-ignore-all lint/performance/noBarrelFile: Mutators entry point */\nimport type { WorkspaceStore } from '@/client'\nimport { cookieMutators } from '@/mutators/cookie'\nimport { getDocument } from '@/mutators/helpers'\nimport { requestMutators } from '@/mutators/request'\nimport { securitySchemeMutators } from '@/mutators/security-schemes'\nimport type { ServerObject } from '@/schemas/v3.1/strict/openapi-document'\n\n/**\n * Generates a set of mutators for managing OpenAPI document and workspace state.\n *\n * @deprecated use the individual mutators instead, this will be removed after we move fully to the new store\n *\n * @param store - The workspace store containing all documents and workspace-level data\n * @returns An object with mutators for the workspace, the active document, and any named document\n */\nexport function generateClientMutators(store: WorkspaceStore) {\n /**\n * Provides mutator functions for managing an array of OpenAPI ServerObject entries.\n *\n * @param target - The array of ServerObject to mutate. If not provided, mutators will be no-ops.\n * @returns An object with addServer and deleteServer methods.\n */\n const serverMutators = (target?: ServerObject[]) => {\n /**\n * Adds a new ServerObject to the target array.\n * @param server - The ServerObject to add.\n * @returns true if the server was added, false if target is undefined.\n */\n const addServer = (server: ServerObject): boolean => {\n if (!target) {\n return false\n }\n target.push(server)\n return true\n }\n\n /**\n * Deletes a ServerObject at the specified index from the target array.\n * @param index - The index of the server to delete.\n * @returns true if the server was deleted, false if target is undefined.\n */\n const deleteServer = (url: string): boolean => {\n if (!target) {\n return false\n }\n const newTarget = [...target.filter((it) => it.url !== url)]\n target.splice(0, target.length)\n target.push(...newTarget)\n return true\n }\n\n return {\n addServer,\n deleteServer,\n }\n }\n\n /**\n * Returns mutators for a specific document by name.\n *\n * @param documentName - The name of the document to get mutators for\n * @returns An object containing mutators for requests, request examples, security schemes, environments, and cookies\n */\n const documentMutators = (documentName: string) => {\n const document = getDocument(store, documentName)\n\n if (document) {\n // Make sure the document has a servers array\n if (!document.servers) {\n document.servers = []\n }\n\n // Make sure the document has the securitySchema object\n if (!document.components) {\n document.components = {}\n }\n\n if (!document.components.securitySchemes) {\n document.components.securitySchemes = {}\n }\n }\n\n return {\n requestMutators: requestMutators(document),\n securitySchemeMutators: securitySchemeMutators(document?.components?.securitySchemes),\n cookieMutators: cookieMutators(document),\n serverMutators: serverMutators(document?.servers),\n }\n }\n\n /**\n * Returns mutators for the workspace-level configuration.\n *\n * @returns An object containing mutators for environments and cookies at the workspace level\n */\n const workspaceMutators = () => {\n const workspace = store.workspace\n\n // Make sure the workspace has a servers array\n if (!workspace['x-scalar-client-config-servers']) {\n workspace['x-scalar-client-config-servers'] = []\n }\n\n // Make sure the workspace has the securitySchema object\n if (!store.workspace['x-scalar-client-config-security-schemes']) {\n store.workspace['x-scalar-client-config-security-schemes'] = {}\n }\n\n return {\n cookieMutators: cookieMutators(store.workspace),\n serverMutators: serverMutators(store.workspace['x-scalar-client-config-servers']),\n securitySchemeMutators: securitySchemeMutators(store.workspace['x-scalar-client-config-security-schemes']),\n }\n }\n\n return {\n /**\n * Returns mutators for the workspace-level configuration.\n */\n workspace: () => workspaceMutators(),\n /**\n * Returns mutators for the currently active document.\n * Falls back to the first document if no active document is set.\n */\n active: () =>\n documentMutators(store.workspace['x-scalar-active-document'] ?? Object.keys(store.workspace.documents)[0] ?? ''),\n /**\n * Returns mutators for a specific document by name.\n *\n * @param name - The name of the document\n */\n doc: (name: string) => documentMutators(name),\n }\n}\n\nexport {\n type AuthMeta,\n deleteSecurityScheme,\n updateSecurityScheme,\n updateSelectedAuthTab,\n updateSelectedScopes,\n updateSelectedSecuritySchemes,\n} from './auth'\nexport { toggleDocumentSecurity } from './document'\nexport {\n upsertEnvironment,\n upsertEnvironmentVariable,\n} from './environment'\nexport {\n type OperationExampleMeta,\n type OperationMeta,\n addOperationParameter,\n addOperationRequestBodyFormRow,\n deleteAllOperationParameters,\n deleteOperationParameter,\n deleteOperationRequestBodyFormRow,\n updateOperationMethodDraft as updateOperationMethod,\n updateOperationParameter,\n updateOperationPathDraft as updateOperationPath,\n updateOperationRequestBodyContentType,\n updateOperationRequestBodyExample,\n updateOperationRequestBodyFormRow,\n updateOperationSummary,\n} from './operation'\nexport {\n addServer,\n deleteServer,\n updateSelectedServer,\n updateServer,\n updateServerVariables,\n} from './server'\n"],
5
+ "mapp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C;AAAA,IACjD;AAGA,QAAI,CAAC,MAAM,UAAU,yCAAyC,GAAG;AAC/D,YAAM,UAAU,yCAAyC,IAAI,CAAC;AAAA,IAChE;AAEA,WAAO;AAAA,MACL,gBAAgB,eAAe,MAAM,SAAS;AAAA,MAC9C,gBAAgB,eAAe,MAAM,UAAU,gCAAgC,CAAC;AAAA,MAChF,wBAAwB,uBAAuB,MAAM,UAAU,yCAAyC,CAAC;AAAA,IAC3G;AAAA,EACF;AAEA,SAAO;AAAA;AAAA;AAAA;AAAA,IAIL,WAAW,MAAM,kBAAkB;AAAA;AAAA;AAAA;AAAA;AAAA,IAKnC,QAAQ,MACN,iBAAiB,MAAM,UAAU,0BAA0B,KAAK,OAAO,KAAK,MAAM,UAAU,SAAS,EAAE,CAAC,KAAK,EAAE;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAMjH,KAAK,CAAC,SAAiB,iBAAiB,IAAI;AAAA,EAC9C;AACF;AAEA;AAAA,EAEE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,8BAA8B;AACvC;AAAA,EACE;AAAA,EACA;AAAA,OACK;AACP;AAAA,EAGE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EAC8B;AAAA,EAC9B;AAAA,EAC4B;AAAA,EAC5B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;",
6
+ "names": ["addServer", "deleteServer"]
7
7
  }
@@ -1,12 +1,47 @@
1
- import type { ServerObject } from '../schemas/v3.1/strict/openapi-document.js';
1
+ import type { ServerEvents } from '../events/definitions/server.js';
2
+ import { type ServerObject } from '../schemas/v3.1/strict/openapi-document.js';
3
+ import type { WorkspaceDocument } from '../schemas/workspace.js';
2
4
  /**
3
- * Provides mutator functions for managing an array of OpenAPI ServerObject entries.
5
+ * Adds a new ServerObject to the document.
4
6
  *
5
- * @param target - The array of ServerObject to mutate. If not provided, mutators will be no-ops.
6
- * @returns An object with addServer and deleteServer methods.
7
+ * @param document - The document to add the server to
8
+ * @returns the new server object or undefined if the document is not found
7
9
  */
8
- export declare const serverMutators: (target?: ServerObject[]) => {
9
- addServer: (server: ServerObject) => boolean;
10
- deleteServer: (url: string) => boolean;
11
- };
10
+ export declare const addServer: (document: WorkspaceDocument | null) => ServerObject | undefined;
11
+ /**
12
+ * Updates a ServerObject in the document.
13
+ * When the URL changes, intelligently syncs variables by preserving configurations
14
+ * for renamed variables (detected by position) and existing variables.
15
+ *
16
+ * @param document - The document containing the server to update
17
+ * @param index - The index of the server to update
18
+ * @param server - The partial server object with fields to update
19
+ * @returns the updated server object or undefined if the server is not found
20
+ */
21
+ export declare const updateServer: (document: WorkspaceDocument | null, { index, server }: ServerEvents["server:update:server"]) => ServerObject | undefined;
22
+ /**
23
+ * Deletes a ServerObject at the specified index from the target array.
24
+ *
25
+ * @param document - The document to delete the server from
26
+ * @param index - The index of the server to delete.
27
+ */
28
+ export declare const deleteServer: (document: WorkspaceDocument | null, { index }: ServerEvents["server:delete:server"]) => void;
29
+ /**
30
+ * Updates a server variable for the selected server
31
+ *
32
+ * @param document - The document to update the server variables in
33
+ * @param index - The index of the server to update
34
+ * @param key - The key of the variable to update
35
+ * @param value - The new value of the variable
36
+ * @returns the updated variable or undefined if the variable is not found
37
+ */
38
+ export declare const updateServerVariables: (document: WorkspaceDocument | null, { index, key, value }: ServerEvents["server:update:variables"]) => import("../schemas/v3.1/strict/openapi-document.js").ServerVariableObject | undefined;
39
+ /**
40
+ * Updates the selected server for the document
41
+ *
42
+ * @param document - The document to update the selected server in
43
+ * @param index - The index of the server to update
44
+ * @returns the url of the selected server or undefined if the server is not found
45
+ */
46
+ export declare const updateSelectedServer: (document: WorkspaceDocument | null, { index }: ServerEvents["server:update:selected"]) => string | undefined;
12
47
  //# sourceMappingURL=server.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../src/mutators/server.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,wCAAwC,CAAA;AAE1E;;;;;GAKG;AACH,eAAO,MAAM,cAAc,GAAI,SAAS,YAAY,EAAE;wBAMzB,YAAY,KAAG,OAAO;wBAatB,MAAM,KAAG,OAAO;CAc5C,CAAA"}
1
+ {"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../src/mutators/server.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAA;AAE/D,OAAO,EAAE,KAAK,YAAY,EAAsB,MAAM,wCAAwC,CAAA;AAC9F,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAA;AAE5D;;;;;GAKG;AACH,eAAO,MAAM,SAAS,GAAI,UAAU,iBAAiB,GAAG,IAAI,KAAG,YAAY,GAAG,SAc7E,CAAA;AAgFD;;;;;;;;;GASG;AACH,eAAO,MAAM,YAAY,GACvB,UAAU,iBAAiB,GAAG,IAAI,EAClC,mBAAmB,YAAY,CAAC,sBAAsB,CAAC,KACtD,YAAY,GAAG,SA+BjB,CAAA;AAED;;;;;GAKG;AACH,eAAO,MAAM,YAAY,GAAI,UAAU,iBAAiB,GAAG,IAAI,EAAE,WAAW,YAAY,CAAC,sBAAsB,CAAC,SAY/G,CAAA;AAED;;;;;;;;GAQG;AACH,eAAO,MAAM,qBAAqB,GAChC,UAAU,iBAAiB,GAAG,IAAI,EAClC,uBAAuB,YAAY,CAAC,yBAAyB,CAAC,sFAkB/D,CAAA;AAED;;;;;;GAMG;AACH,eAAO,MAAM,oBAAoB,GAC/B,UAAU,iBAAiB,GAAG,IAAI,EAClC,WAAW,YAAY,CAAC,wBAAwB,CAAC,KAChD,MAAM,GAAG,SAUX,CAAA"}
@@ -1,26 +1,118 @@
1
- const serverMutators = (target) => {
2
- const addServer = (server) => {
3
- if (!target) {
4
- return false;
1
+ import { findVariables } from "@scalar/helpers/regex/find-variables";
2
+ import { coerceValue } from "../schemas/typebox-coerce.js";
3
+ import { ServerObjectSchema } from "../schemas/v3.1/strict/openapi-document.js";
4
+ const addServer = (document) => {
5
+ if (!document) {
6
+ return void 0;
7
+ }
8
+ const parsed = coerceValue(ServerObjectSchema, {});
9
+ if (!document.servers) {
10
+ document.servers = [];
11
+ }
12
+ document.servers.push(parsed);
13
+ return parsed;
14
+ };
15
+ const getVariablePositions = (url, variables) => {
16
+ const positions = {};
17
+ for (const varName of variables) {
18
+ const position = url.indexOf(`{${varName}}`);
19
+ if (position !== -1) {
20
+ positions[varName] = position;
21
+ }
22
+ }
23
+ return positions;
24
+ };
25
+ const syncVariablesForUrlChange = (newUrl, oldUrl, existingVariables) => {
26
+ const oldVariables = findVariables(oldUrl, { includePath: true, includeEnv: false }).filter(
27
+ (v) => v !== void 0
28
+ );
29
+ const newVariables = findVariables(newUrl, { includePath: true, includeEnv: false }).filter(
30
+ (v) => v !== void 0
31
+ );
32
+ const oldPositions = getVariablePositions(oldUrl, oldVariables);
33
+ const newPositions = getVariablePositions(newUrl, newVariables);
34
+ const usedOldVariables = /* @__PURE__ */ new Set();
35
+ const syncedVariables = {};
36
+ for (const newVar of newVariables) {
37
+ if (existingVariables[newVar]) {
38
+ syncedVariables[newVar] = existingVariables[newVar];
39
+ usedOldVariables.add(newVar);
40
+ continue;
41
+ }
42
+ const newVarPosition = newPositions[newVar];
43
+ const oldVarAtPosition = oldVariables.find(
44
+ (oldVar) => oldPositions[oldVar] === newVarPosition && !usedOldVariables.has(oldVar)
45
+ );
46
+ if (oldVarAtPosition && existingVariables[oldVarAtPosition]) {
47
+ syncedVariables[newVar] = existingVariables[oldVarAtPosition];
48
+ usedOldVariables.add(oldVarAtPosition);
49
+ continue;
5
50
  }
6
- target.push(server);
7
- return true;
8
- };
9
- const deleteServer = (url) => {
10
- if (!target) {
11
- return false;
51
+ syncedVariables[newVar] = { default: "" };
52
+ }
53
+ return syncedVariables;
54
+ };
55
+ const updateServer = (document, { index, server }) => {
56
+ const oldServer = document?.servers?.[index];
57
+ if (!oldServer) {
58
+ console.error("Server not found at index:", index);
59
+ return void 0;
60
+ }
61
+ const oldUrl = oldServer.url;
62
+ const updatedServer = coerceValue(ServerObjectSchema, { ...oldServer, ...server });
63
+ const hasUrlChanged = oldUrl && oldUrl !== updatedServer.url;
64
+ if (hasUrlChanged) {
65
+ const existingVariables = updatedServer.variables ?? {};
66
+ updatedServer.variables = syncVariablesForUrlChange(updatedServer.url, oldUrl, existingVariables);
67
+ if (document["x-scalar-selected-server"] === oldUrl) {
68
+ document["x-scalar-selected-server"] = updatedServer.url;
12
69
  }
13
- const newTarget = [...target.filter((it) => it.url !== url)];
14
- target.splice(0, target.length);
15
- target.push(...newTarget);
16
- return true;
17
- };
18
- return {
19
- addServer,
20
- deleteServer
21
- };
70
+ }
71
+ if (!document.servers) {
72
+ document.servers = [updatedServer];
73
+ } else {
74
+ document.servers[index] = updatedServer;
75
+ }
76
+ return updatedServer;
77
+ };
78
+ const deleteServer = (document, { index }) => {
79
+ if (!document?.servers) {
80
+ return;
81
+ }
82
+ const url = document.servers[index]?.url;
83
+ document.servers.splice(index, 1);
84
+ if (document["x-scalar-selected-server"] === url) {
85
+ document["x-scalar-selected-server"] = document.servers[0]?.url ?? void 0;
86
+ }
87
+ };
88
+ const updateServerVariables = (document, { index, key, value }) => {
89
+ const variable = document?.servers?.[index]?.variables?.[key];
90
+ if (!variable) {
91
+ console.error("Variable not found", key, index);
92
+ return;
93
+ }
94
+ variable.default = value;
95
+ const url = document?.servers?.[index]?.url;
96
+ if (!url) {
97
+ console.error("URL not found", index);
98
+ return;
99
+ }
100
+ return variable;
101
+ };
102
+ const updateSelectedServer = (document, { index }) => {
103
+ const url = document?.servers?.[index]?.url;
104
+ if (!url) {
105
+ console.error("Server not found", index, document?.servers);
106
+ return;
107
+ }
108
+ document["x-scalar-selected-server"] = url;
109
+ return document["x-scalar-selected-server"];
22
110
  };
23
111
  export {
24
- serverMutators
112
+ addServer,
113
+ deleteServer,
114
+ updateSelectedServer,
115
+ updateServer,
116
+ updateServerVariables
25
117
  };
26
118
  //# sourceMappingURL=server.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/mutators/server.ts"],
4
- "sourcesContent": ["import type { ServerObject } from '@/schemas/v3.1/strict/openapi-document'\n\n/**\n * Provides mutator functions for managing an array of OpenAPI ServerObject entries.\n *\n * @param target - The array of ServerObject to mutate. If not provided, mutators will be no-ops.\n * @returns An object with addServer and deleteServer methods.\n */\nexport const serverMutators = (target?: ServerObject[]) => {\n /**\n * Adds a new ServerObject to the target array.\n * @param server - The ServerObject to add.\n * @returns true if the server was added, false if target is undefined.\n */\n const addServer = (server: ServerObject): boolean => {\n if (!target) {\n return false\n }\n target.push(server)\n return true\n }\n\n /**\n * Deletes a ServerObject at the specified index from the target array.\n * @param index - The index of the server to delete.\n * @returns true if the server was deleted, false if target is undefined.\n */\n const deleteServer = (url: string): boolean => {\n if (!target) {\n return false\n }\n const newTarget = [...target.filter((it) => it.url !== url)]\n target.splice(0, target.length)\n target.push(...newTarget)\n return true\n }\n\n return {\n addServer,\n deleteServer,\n }\n}\n"],
5
- "mappings": "AAQO,MAAM,iBAAiB,CAAC,WAA4B;AAMzD,QAAM,YAAY,CAAC,WAAkC;AACnD,QAAI,CAAC,QAAQ;AACX,aAAO;AAAA,IACT;AACA,WAAO,KAAK,MAAM;AAClB,WAAO;AAAA,EACT;AAOA,QAAM,eAAe,CAAC,QAAyB;AAC7C,QAAI,CAAC,QAAQ;AACX,aAAO;AAAA,IACT;AACA,UAAM,YAAY,CAAC,GAAG,OAAO,OAAO,CAAC,OAAO,GAAG,QAAQ,GAAG,CAAC;AAC3D,WAAO,OAAO,GAAG,OAAO,MAAM;AAC9B,WAAO,KAAK,GAAG,SAAS;AACxB,WAAO;AAAA,EACT;AAEA,SAAO;AAAA,IACL;AAAA,IACA;AAAA,EACF;AACF;",
4
+ "sourcesContent": ["import { findVariables } from '@scalar/helpers/regex/find-variables'\n\nimport type { ServerEvents } from '@/events/definitions/server'\nimport { coerceValue } from '@/schemas/typebox-coerce'\nimport { type ServerObject, ServerObjectSchema } from '@/schemas/v3.1/strict/openapi-document'\nimport type { WorkspaceDocument } from '@/schemas/workspace'\n\n/**\n * Adds a new ServerObject to the document.\n *\n * @param document - The document to add the server to\n * @returns the new server object or undefined if the document is not found\n */\nexport const addServer = (document: WorkspaceDocument | null): ServerObject | undefined => {\n if (!document) {\n return undefined\n }\n\n const parsed = coerceValue(ServerObjectSchema, {})\n\n // Initialize the servers array if it doesn't exist\n if (!document.servers) {\n document.servers = []\n }\n\n document.servers.push(parsed)\n return parsed\n}\n\n/**\n * Creates a map of variable names to their character positions in a URL.\n * Used to detect renamed variables by position matching.\n */\nconst getVariablePositions = (url: string, variables: readonly string[]): Record<string, number> => {\n const positions: Record<string, number> = {}\n\n for (const varName of variables) {\n const position = url.indexOf(`{${varName}}`)\n if (position !== -1) {\n positions[varName] = position\n }\n }\n\n return positions\n}\n\ntype VariableConfig = {\n description?: string\n default?: string\n enum?: string[]\n}\n\n/**\n * Syncs server variables when the URL changes.\n *\n * Preserves variable configurations by:\n * 1. Keeping variables with matching names\n * 2. Renaming variables at the same position\n * 3. Creating new variables with empty defaults\n */\nconst syncVariablesForUrlChange = (\n newUrl: string,\n oldUrl: string,\n existingVariables: Record<string, VariableConfig>,\n): Record<string, VariableConfig> => {\n // Filter out undefined values from findVariables results\n const oldVariables = findVariables(oldUrl, { includePath: true, includeEnv: false }).filter(\n (v): v is string => v !== undefined,\n )\n const newVariables = findVariables(newUrl, { includePath: true, includeEnv: false }).filter(\n (v): v is string => v !== undefined,\n )\n\n const oldPositions = getVariablePositions(oldUrl, oldVariables)\n const newPositions = getVariablePositions(newUrl, newVariables)\n\n const usedOldVariables = new Set<string>()\n const syncedVariables: Record<string, VariableConfig> = {}\n\n for (const newVar of newVariables) {\n // Case 1: Variable with same name exists - preserve its config\n if (existingVariables[newVar]) {\n syncedVariables[newVar] = existingVariables[newVar]\n usedOldVariables.add(newVar)\n continue\n }\n\n // Case 2: Check for variable at same position (likely a rename)\n const newVarPosition = newPositions[newVar]\n const oldVarAtPosition = oldVariables.find(\n (oldVar) => oldPositions[oldVar] === newVarPosition && !usedOldVariables.has(oldVar),\n )\n\n if (oldVarAtPosition && existingVariables[oldVarAtPosition]) {\n // Rename: transfer the old variable's config to the new name\n syncedVariables[newVar] = existingVariables[oldVarAtPosition]\n usedOldVariables.add(oldVarAtPosition)\n continue\n }\n\n // Case 3: New variable - create with empty default\n syncedVariables[newVar] = { default: '' }\n }\n\n return syncedVariables\n}\n\n/**\n * Updates a ServerObject in the document.\n * When the URL changes, intelligently syncs variables by preserving configurations\n * for renamed variables (detected by position) and existing variables.\n *\n * @param document - The document containing the server to update\n * @param index - The index of the server to update\n * @param server - The partial server object with fields to update\n * @returns the updated server object or undefined if the server is not found\n */\nexport const updateServer = (\n document: WorkspaceDocument | null,\n { index, server }: ServerEvents['server:update:server'],\n): ServerObject | undefined => {\n const oldServer = document?.servers?.[index]\n\n if (!oldServer) {\n console.error('Server not found at index:', index)\n return undefined\n }\n\n const oldUrl = oldServer.url\n const updatedServer = coerceValue(ServerObjectSchema, { ...oldServer, ...server })\n\n // Sync variables if the URL changed\n const hasUrlChanged = oldUrl && oldUrl !== updatedServer.url\n if (hasUrlChanged) {\n const existingVariables = updatedServer.variables ?? {}\n updatedServer.variables = syncVariablesForUrlChange(updatedServer.url, oldUrl, existingVariables)\n\n // If the selected server is the one being updated, set the selected server to the new server\n if (document['x-scalar-selected-server'] === oldUrl) {\n document['x-scalar-selected-server'] = updatedServer.url\n }\n }\n\n // Ensure servers array exists and update the server at the specified index\n if (!document.servers) {\n document.servers = [updatedServer]\n } else {\n document.servers[index] = updatedServer\n }\n\n return updatedServer\n}\n\n/**\n * Deletes a ServerObject at the specified index from the target array.\n *\n * @param document - The document to delete the server from\n * @param index - The index of the server to delete.\n */\nexport const deleteServer = (document: WorkspaceDocument | null, { index }: ServerEvents['server:delete:server']) => {\n if (!document?.servers) {\n return\n }\n\n const url = document.servers[index]?.url\n document.servers.splice(index, 1)\n\n // If the selected server is the one being deleted, set the selected server to the first one after removal\n if (document['x-scalar-selected-server'] === url) {\n document['x-scalar-selected-server'] = document.servers[0]?.url ?? undefined\n }\n}\n\n/**\n * Updates a server variable for the selected server\n *\n * @param document - The document to update the server variables in\n * @param index - The index of the server to update\n * @param key - The key of the variable to update\n * @param value - The new value of the variable\n * @returns the updated variable or undefined if the variable is not found\n */\nexport const updateServerVariables = (\n document: WorkspaceDocument | null,\n { index, key, value }: ServerEvents['server:update:variables'],\n) => {\n const variable = document?.servers?.[index]?.variables?.[key]\n if (!variable) {\n console.error('Variable not found', key, index)\n return\n }\n\n variable.default = value\n\n // Now we need to make the url reflect the new variable value\n const url = document?.servers?.[index]?.url\n if (!url) {\n console.error('URL not found', index)\n return\n }\n\n return variable\n}\n\n/**\n * Updates the selected server for the document\n *\n * @param document - The document to update the selected server in\n * @param index - The index of the server to update\n * @returns the url of the selected server or undefined if the server is not found\n */\nexport const updateSelectedServer = (\n document: WorkspaceDocument | null,\n { index }: ServerEvents['server:update:selected'],\n): string | undefined => {\n const url = document?.servers?.[index]?.url\n if (!url) {\n console.error('Server not found', index, document?.servers)\n return\n }\n\n // Set it and return the url\n document['x-scalar-selected-server'] = url\n return document['x-scalar-selected-server']\n}\n"],
5
+ "mappings": "AAAA,SAAS,qBAAqB;AAG9B,SAAS,mBAAmB;AAC5B,SAA4B,0BAA0B;AAS/C,MAAM,YAAY,CAAC,aAAiE;AACzF,MAAI,CAAC,UAAU;AACb,WAAO;AAAA,EACT;AAEA,QAAM,SAAS,YAAY,oBAAoB,CAAC,CAAC;AAGjD,MAAI,CAAC,SAAS,SAAS;AACrB,aAAS,UAAU,CAAC;AAAA,EACtB;AAEA,WAAS,QAAQ,KAAK,MAAM;AAC5B,SAAO;AACT;AAMA,MAAM,uBAAu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AE,MAAM,MACe;AACvB,QAAM,MAAM,UAAU,UAAU,KAAK,GAAG;AACxC,MAAI,CAAC,KAAK;AACR,YAAQ,MAAM,oBAAoB,OAAO,UAAU,OAAO;AAC1D;AAAA,EACF;AAGA,WAAS,0BAA0B,IAAI;AACvC,SAAO,SAAS,0BAA0B;AAC5C;",
6
6
  "names": []
7
7
  }
@@ -14,6 +14,7 @@ export declare const traverseDocument: (documentName: string, document: OpenApiD
14
14
  id: string;
15
15
  type: "document";
16
16
  title: string;
17
+ name: string;
17
18
  children: TraversedEntry[];
18
19
  };
19
20
  //# sourceMappingURL=traverse-document.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"traverse-document.d.ts","sourceRoot":"","sources":["../../../src/navigation/helpers/traverse-document.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAqB,cAAc,EAAE,MAAM,sBAAsB,CAAA;AAC7E,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,wCAAwC,CAAA;AAC7E,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,0CAA0C,CAAA;AAQrF;;;;;;;;GAQG;AACH,eAAO,MAAM,gBAAgB,GAAI,cAAc,MAAM,EAAE,UAAU,eAAe,EAAE,SAAS,qBAAqB;;;;;CA6F/G,CAAA"}
1
+ {"version":3,"file":"traverse-document.d.ts","sourceRoot":"","sources":["../../../src/navigation/helpers/traverse-document.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAqB,cAAc,EAAE,MAAM,sBAAsB,CAAA;AAC7E,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,wCAAwC,CAAA;AAC7E,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,0CAA0C,CAAA;AAQrF;;;;;;;;GAQG;AACH,eAAO,MAAM,gBAAgB,GAAI,cAAc,MAAM,EAAE,UAAU,eAAe,EAAE,SAAS,qBAAqB;;;;;;CA8F/G,CAAA"}
@@ -76,7 +76,8 @@ const traverseDocument = (documentName, document, config) => {
76
76
  return {
77
77
  id: documentId,
78
78
  type: "document",
79
- title: documentName,
79
+ title: document.info.title,
80
+ name: documentName,
80
81
  children: entries
81
82
  };
82
83
  };