@qodalis/cli-core 2.0.0 → 2.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/public-api.mjs CHANGED
@@ -2597,7 +2597,7 @@ function satisfiesVersionRange(installed, range) {
2597
2597
  }
2598
2598
 
2599
2599
  // src/lib/version.ts
2600
- var LIBRARY_VERSION = "2.0.0";
2600
+ var LIBRARY_VERSION = "2.1.0";
2601
2601
  var API_VERSION = 2;
2602
2602
 
2603
2603
  // src/lib/utils/server-version-negotiator.ts
@@ -2659,13 +2659,61 @@ function buildAuthenticatedWebSocketUrl(wsUrl, headers) {
2659
2659
  ).join("&");
2660
2660
  return `${wsUrl}${separator}${params}`;
2661
2661
  }
2662
- async function resolveServerWebSocketUrl(services, serverName, wsUrl, configHeaders) {
2662
+ var CLI_WS_TICKET_PATH = "/api/v1/qcli/sessions/ws-ticket";
2663
+ var warnedServers = /* @__PURE__ */ new Set();
2664
+ async function buildServerWebSocketUrl(wsUrl, headers, options) {
2665
+ const resolved = resolveHeaders(headers);
2666
+ if (Object.keys(resolved).length === 0) {
2667
+ return wsUrl;
2668
+ }
2669
+ if (options?.unsafeHeadersInWebSocketUrl) {
2670
+ return buildAuthenticatedWebSocketUrl(wsUrl, resolved);
2671
+ }
2672
+ const httpBase = toHttpBaseUrl(wsUrl);
2673
+ const ticket = await fetchWebSocketTicket(httpBase, resolved);
2674
+ if (ticket) {
2675
+ return appendQueryParams(wsUrl, { ticket });
2676
+ }
2677
+ if (!warnedServers.has(httpBase)) {
2678
+ warnedServers.add(httpBase);
2679
+ console.warn(
2680
+ `[qodalis-cli] ${httpBase} issued no WebSocket ticket (${CLI_WS_TICKET_PATH}), so its sockets connect without credentials. Configured headers are never copied into WebSocket URLs; enable the users plugin on the server, or set \`unsafeHeadersInWebSocketUrl: true\` on the server config to keep the old behaviour.`
2681
+ );
2682
+ }
2683
+ return wsUrl;
2684
+ }
2685
+ async function resolveServerWebSocketUrl(services, serverName, wsUrl, configHeaders, options) {
2663
2686
  const authService = services?.get(ICliServerAuthService_TOKEN);
2664
2687
  const params = await authService?.getWebSocketParams?.(serverName);
2665
2688
  if (params) {
2666
2689
  return appendQueryParams(wsUrl, params);
2667
2690
  }
2668
- return buildAuthenticatedWebSocketUrl(wsUrl, () => resolveServerHeaders(services, serverName, configHeaders));
2691
+ return buildServerWebSocketUrl(
2692
+ wsUrl,
2693
+ () => resolveServerHeaders(services, serverName, configHeaders),
2694
+ options
2695
+ );
2696
+ }
2697
+ function toHttpBaseUrl(wsUrl) {
2698
+ const url = new URL(wsUrl);
2699
+ const wsSegment = url.pathname.indexOf("/ws/");
2700
+ const basePath = wsSegment >= 0 ? url.pathname.slice(0, wsSegment) : "";
2701
+ const protocol = url.protocol === "wss:" || url.protocol === "https:" ? "https:" : "http:";
2702
+ return `${protocol}//${url.host}${basePath}`;
2703
+ }
2704
+ async function fetchWebSocketTicket(httpBase, headers) {
2705
+ try {
2706
+ const response = await fetch(`${httpBase}${CLI_WS_TICKET_PATH}`, {
2707
+ method: "POST",
2708
+ headers: { ...headers, "Content-Type": "application/json" },
2709
+ body: "{}"
2710
+ });
2711
+ if (!response.ok) return void 0;
2712
+ const body = await response.json();
2713
+ return typeof body?.ticket === "string" && body.ticket ? body.ticket : void 0;
2714
+ } catch {
2715
+ return void 0;
2716
+ }
2669
2717
  }
2670
2718
  function appendQueryParams(url, params) {
2671
2719
  const entries = Object.entries(params);
@@ -4205,6 +4253,6 @@ var BrowserFileTransferService = class {
4205
4253
  }
4206
4254
  };
4207
4255
 
4208
- export { API_VERSION, BrowserFileTransferService, CANCELLATION_ERROR_MESSAGE, CLI_CONFIGURE_STORE_NAME, CancellablePromise, CliAccessDeniedError, CliBackgroundColor, CliForegroundColor, CliHttpError, CliIcon, CliKeyData, CliLogLevel, CliModuleRegistry, CliServerPermissions, CliUsersPermissions, DEFAULT_DIR_PERMISSIONS, DEFAULT_FILE_PERMISSIONS, DefaultLibraryAuthor, DefaultThemeInfos, DefaultThemes, ICliAuditService_TOKEN, ICliAuthService_TOKEN, ICliAuthorizationService_TOKEN, ICliCommandGuard_TOKEN, ICliCompletionProvider_TOKEN, ICliDragDropService_TOKEN, ICliEventBus_TOKEN, ICliFilePickerProvider_TOKEN, ICliFileTransferService_TOKEN, ICliGroupsStoreService_TOKEN, ICliHttpClient_TOKEN, ICliKeyValueStore_TOKEN, ICliPermissionRegistry_TOKEN, ICliPermissionService_TOKEN, ICliServerAuthService_TOKEN, ICliServerAuthTokenProvider_TOKEN, ICliServerManager_TOKEN, ICliSessionsService_TOKEN, ICliTranslationService_TOKEN, ICliUserEventService_TOKEN, ICliUserSessionService_TOKEN, ICliUsersStoreService_TOKEN, LIBRARY_VERSION, ObjectDescriber, ServerVersionNegotiator, appendQueryParams, bootCliModule, buildAuthenticatedWebSocketUrl, clearTerminalLine, cliAccessMetadataGuards, cliAuthorize, cliCanAccess, cliDefaultServer, cliEvaluateAccess, cliHasPermission, cliMergePermissions, cliMissingPermissions, cliPermissionMatches, cliRequireAuthGuard, cliRequiredGroupsGuard, cliRequiredPermissionsGuard, colorFirstWord, colorizeJson, compareVersions, constants, createCliToken, createWorkerService, delay, derivePanelThemeStyles, enums, formatJson, getConfigValue, getParameterValue, getPluginConfigValue, getRightOfWord, highlightTextWithBg, initializeBrowserEnvironment, isCliAccessDeniedError, joinShellWords, loadPanelPosition, nextPanelPosition, quoteShellWord, resolveConfigurationCategories, resolveHeaders, resolveServerHeaders, resolveServerWebSocketUrl, satisfiesMinVersion, satisfiesVersionRange, savePanelPosition, splitShellWords, stripAnsi, toQueryString, truncateToWidth, unquoteRawArgument, utils, visibleLength, writeExamples, writeHint, writeUsage, writeWrapped };
4256
+ export { API_VERSION, BrowserFileTransferService, CANCELLATION_ERROR_MESSAGE, CLI_CONFIGURE_STORE_NAME, CLI_WS_TICKET_PATH, CancellablePromise, CliAccessDeniedError, CliBackgroundColor, CliForegroundColor, CliHttpError, CliIcon, CliKeyData, CliLogLevel, CliModuleRegistry, CliServerPermissions, CliUsersPermissions, DEFAULT_DIR_PERMISSIONS, DEFAULT_FILE_PERMISSIONS, DefaultLibraryAuthor, DefaultThemeInfos, DefaultThemes, ICliAuditService_TOKEN, ICliAuthService_TOKEN, ICliAuthorizationService_TOKEN, ICliCommandGuard_TOKEN, ICliCompletionProvider_TOKEN, ICliDragDropService_TOKEN, ICliEventBus_TOKEN, ICliFilePickerProvider_TOKEN, ICliFileTransferService_TOKEN, ICliGroupsStoreService_TOKEN, ICliHttpClient_TOKEN, ICliKeyValueStore_TOKEN, ICliPermissionRegistry_TOKEN, ICliPermissionService_TOKEN, ICliServerAuthService_TOKEN, ICliServerAuthTokenProvider_TOKEN, ICliServerManager_TOKEN, ICliSessionsService_TOKEN, ICliTranslationService_TOKEN, ICliUserEventService_TOKEN, ICliUserSessionService_TOKEN, ICliUsersStoreService_TOKEN, LIBRARY_VERSION, ObjectDescriber, ServerVersionNegotiator, appendQueryParams, bootCliModule, buildAuthenticatedWebSocketUrl, buildServerWebSocketUrl, clearTerminalLine, cliAccessMetadataGuards, cliAuthorize, cliCanAccess, cliDefaultServer, cliEvaluateAccess, cliHasPermission, cliMergePermissions, cliMissingPermissions, cliPermissionMatches, cliRequireAuthGuard, cliRequiredGroupsGuard, cliRequiredPermissionsGuard, colorFirstWord, colorizeJson, compareVersions, constants, createCliToken, createWorkerService, delay, derivePanelThemeStyles, enums, formatJson, getConfigValue, getParameterValue, getPluginConfigValue, getRightOfWord, highlightTextWithBg, initializeBrowserEnvironment, isCliAccessDeniedError, joinShellWords, loadPanelPosition, nextPanelPosition, quoteShellWord, resolveConfigurationCategories, resolveHeaders, resolveServerHeaders, resolveServerWebSocketUrl, satisfiesMinVersion, satisfiesVersionRange, savePanelPosition, splitShellWords, stripAnsi, toQueryString, truncateToWidth, unquoteRawArgument, utils, visibleLength, writeExamples, writeHint, writeUsage, writeWrapped };
4209
4257
  //# sourceMappingURL=public-api.mjs.map
4210
4258
  //# sourceMappingURL=public-api.mjs.map