@qodalis/cli-core 2.0.0-beta.12 → 2.0.0-beta.14

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
@@ -665,7 +665,7 @@ var require_compare_build = __commonJS({
665
665
  var require_sort = __commonJS({
666
666
  "../../node_modules/.pnpm/semver@7.7.4/node_modules/semver/functions/sort.js"(exports$1, module) {
667
667
  var compareBuild = require_compare_build();
668
- var sort = (list, loose) => list.sort((a, b) => compareBuild(a, b, loose));
668
+ var sort = (list2, loose) => list2.sort((a, b) => compareBuild(a, b, loose));
669
669
  module.exports = sort;
670
670
  }
671
671
  });
@@ -674,7 +674,7 @@ var require_sort = __commonJS({
674
674
  var require_rsort = __commonJS({
675
675
  "../../node_modules/.pnpm/semver@7.7.4/node_modules/semver/functions/rsort.js"(exports$1, module) {
676
676
  var compareBuild = require_compare_build();
677
- var rsort = (list, loose) => list.sort((a, b) => compareBuild(b, a, loose));
677
+ var rsort = (list2, loose) => list2.sort((a, b) => compareBuild(b, a, loose));
678
678
  module.exports = rsort;
679
679
  }
680
680
  });
@@ -2053,6 +2053,47 @@ var CliIcon = /* @__PURE__ */ ((CliIcon2) => {
2053
2053
  return CliIcon2;
2054
2054
  })(CliIcon || {});
2055
2055
 
2056
+ // src/lib/tokens.ts
2057
+ var ICliUserSessionService_TOKEN = "cli-user-session-service";
2058
+ var ICliUsersStoreService_TOKEN = "cli-users-store-service";
2059
+ var ICliGroupsStoreService_TOKEN = "cli-groups-store-service";
2060
+ var ICliAuthService_TOKEN = "cli-auth-service";
2061
+ var ICliCompletionProvider_TOKEN = "cli-completion-provider";
2062
+ var ICliDragDropService_TOKEN = "cli-drag-drop-service";
2063
+ var ICliFileTransferService_TOKEN = "cli-file-transfer-service";
2064
+ var ICliTranslationService_TOKEN = "cli-translation-service";
2065
+ var ICliPermissionService_TOKEN = "cli-permission-service";
2066
+ var ICliFilePickerProvider_TOKEN = "cli-file-picker-provider";
2067
+ var ICliHttpClient_TOKEN = "cli-http-client";
2068
+ var ICliUserEventService_TOKEN = "cli-user-event-service";
2069
+ var ICliAuditService_TOKEN = "cli-audit-service";
2070
+ var ICliAuthorizationService_TOKEN = "cli-authorization-service";
2071
+ var ICliPermissionRegistry_TOKEN = "cli-permission-registry";
2072
+ var ICliSessionsService_TOKEN = "cli-sessions-service";
2073
+ var ICliKeyValueStore_TOKEN = "cli-key-value-store";
2074
+
2075
+ // src/lib/interfaces/services.ts
2076
+ var ICliServerAuthTokenProvider_TOKEN = "cli-server-auth-token-provider";
2077
+ var ICliServerAuthService_TOKEN = "cli-server-auth-service";
2078
+ var ICliServerManager_TOKEN = "cli-server-manager";
2079
+
2080
+ // src/lib/models/server.ts
2081
+ function resolveHeaders(provider) {
2082
+ if (!provider) return {};
2083
+ return typeof provider === "function" ? provider() : provider;
2084
+ }
2085
+ function resolveServerHeaders(services, serverName, configHeaders) {
2086
+ if (services) {
2087
+ const authService = services.get(
2088
+ ICliServerAuthService_TOKEN
2089
+ );
2090
+ if (authService) {
2091
+ return authService.getHeaders(serverName, configHeaders);
2092
+ }
2093
+ }
2094
+ return resolveHeaders(configHeaders);
2095
+ }
2096
+
2056
2097
  // src/lib/models/options.ts
2057
2098
  var CliLogLevel = /* @__PURE__ */ ((CliLogLevel2) => {
2058
2099
  CliLogLevel2[CliLogLevel2["None"] = 0] = "None";
@@ -2076,17 +2117,112 @@ var enums = {
2076
2117
  CliLogLevel
2077
2118
  };
2078
2119
 
2079
- // src/lib/tokens.ts
2080
- var ICliUserSessionService_TOKEN = "cli-user-session-service";
2081
- var ICliUsersStoreService_TOKEN = "cli-users-store-service";
2082
- var ICliGroupsStoreService_TOKEN = "cli-groups-store-service";
2083
- var ICliAuthService_TOKEN = "cli-auth-service";
2084
- var ICliCompletionProvider_TOKEN = "cli-completion-provider";
2085
- var ICliDragDropService_TOKEN = "cli-drag-drop-service";
2086
- var ICliFileTransferService_TOKEN = "cli-file-transfer-service";
2087
- var ICliTranslationService_TOKEN = "cli-translation-service";
2088
- var ICliPermissionService_TOKEN = "cli-permission-service";
2089
- var ICliFilePickerProvider_TOKEN = "cli-file-picker-provider";
2120
+ // src/lib/interfaces/command-guards.ts
2121
+ var ICliCommandGuard_TOKEN = "cli-command-guard";
2122
+
2123
+ // src/lib/utils/permissions.ts
2124
+ function cliPermissionMatches(granted, required) {
2125
+ const g = granted.trim().toLowerCase().split(":");
2126
+ const r = required.trim().toLowerCase().split(":");
2127
+ for (let i = 0; i < g.length; i++) {
2128
+ if (g[i] === "*" && i === g.length - 1) return true;
2129
+ if (i >= r.length || g[i] !== "*" && g[i] !== r[i]) return false;
2130
+ }
2131
+ return g.length === r.length;
2132
+ }
2133
+ function cliHasPermission(granted, required) {
2134
+ return !!granted?.some((p) => cliPermissionMatches(p, required));
2135
+ }
2136
+ function cliMissingPermissions(granted, required) {
2137
+ return required.filter((r) => !cliHasPermission(granted, r));
2138
+ }
2139
+ function cliMergePermissions(...lists) {
2140
+ const seen = /* @__PURE__ */ new Set();
2141
+ const out = [];
2142
+ for (const list2 of lists) {
2143
+ for (const p of list2 ?? []) {
2144
+ const key = p.trim();
2145
+ if (key && !seen.has(key.toLowerCase())) {
2146
+ seen.add(key.toLowerCase());
2147
+ out.push(key);
2148
+ }
2149
+ }
2150
+ }
2151
+ return out;
2152
+ }
2153
+ var CliServerPermissions = {
2154
+ /** Open a remote shell on a server (`ssh`) */
2155
+ ShellExecute: "shell:execute"
2156
+ };
2157
+ var CliUsersPermissions = {
2158
+ UsersRead: "users:read",
2159
+ UsersCreate: "users:create",
2160
+ UsersUpdate: "users:update",
2161
+ UsersDelete: "users:delete",
2162
+ GroupsRead: "groups:read",
2163
+ GroupsCreate: "groups:create",
2164
+ GroupsUpdate: "groups:update",
2165
+ GroupsDelete: "groups:delete",
2166
+ SessionsRead: "sessions:read",
2167
+ SessionsRevoke: "sessions:revoke",
2168
+ AuditRead: "audit:read",
2169
+ AuditClear: "audit:clear"
2170
+ };
2171
+
2172
+ // src/lib/interfaces/authorization.ts
2173
+ var CliAccessDeniedError = class _CliAccessDeniedError extends Error {
2174
+ constructor(message = "permission denied") {
2175
+ super(message);
2176
+ this.code = "EACCES";
2177
+ this.name = "CliAccessDeniedError";
2178
+ Object.setPrototypeOf(this, _CliAccessDeniedError.prototype);
2179
+ }
2180
+ };
2181
+ function isCliAccessDeniedError(error) {
2182
+ return error instanceof CliAccessDeniedError || !!error && typeof error === "object" && error.name === "CliAccessDeniedError";
2183
+ }
2184
+ function authorizationService(context) {
2185
+ try {
2186
+ return context.services.get(ICliAuthorizationService_TOKEN);
2187
+ } catch {
2188
+ return void 0;
2189
+ }
2190
+ }
2191
+ function cliAuthorize(context, permission) {
2192
+ const auth = authorizationService(context);
2193
+ return auth ? auth.can(permission) : true;
2194
+ }
2195
+ function cliCanAccess(context, resource, action, bypassPermissions) {
2196
+ const auth = authorizationService(context);
2197
+ return auth ? auth.canAccess(resource, action, bypassPermissions) : true;
2198
+ }
2199
+ function cliEvaluateAccess(principal, resource, action, bypassPermissions = []) {
2200
+ const mode = resource.permissions;
2201
+ const owner = resource.ownership;
2202
+ if (!mode || mode.length < 9 || !owner) return true;
2203
+ if (principal && (cliHasPermission(principal.permissions, "*") || bypassPermissions.some((p) => cliHasPermission(principal.permissions, p)))) {
2204
+ return true;
2205
+ }
2206
+ let offset = 6;
2207
+ if (principal) {
2208
+ if (owner.uid === principal.name || owner.uid === principal.id) offset = 0;
2209
+ else if (principal.groups.some((g) => g.toLowerCase() === owner.gid.toLowerCase())) offset = 3;
2210
+ }
2211
+ const index = offset + (action === "read" ? 0 : action === "write" ? 1 : 2);
2212
+ return mode.charAt(index) !== "-";
2213
+ }
2214
+
2215
+ // src/lib/interfaces/http-client.ts
2216
+ var CliHttpError = class _CliHttpError extends Error {
2217
+ constructor(message, status, statusText = "", body) {
2218
+ super(message);
2219
+ this.status = status;
2220
+ this.statusText = statusText;
2221
+ this.body = body;
2222
+ this.name = "CliHttpError";
2223
+ Object.setPrototypeOf(this, _CliHttpError.prototype);
2224
+ }
2225
+ };
2090
2226
 
2091
2227
  // src/lib/constants/index.ts
2092
2228
  var DefaultLibraryAuthor = {
@@ -2250,7 +2386,7 @@ function getConfigValue(state, category, key, defaultValue) {
2250
2386
  }
2251
2387
  function getPluginConfigValue(context, category, key, defaultValue) {
2252
2388
  try {
2253
- const storeManager = context.services.get(
2389
+ const storeManager = context.services.getRequired(
2254
2390
  "cli-state-store-manager"
2255
2391
  );
2256
2392
  if (!storeManager) return defaultValue;
@@ -2315,7 +2451,7 @@ function satisfiesVersionRange(installed, range) {
2315
2451
  }
2316
2452
 
2317
2453
  // src/lib/version.ts
2318
- var LIBRARY_VERSION = "2.0.0-beta.12";
2454
+ var LIBRARY_VERSION = "2.0.0-beta.14";
2319
2455
  var API_VERSION = 2;
2320
2456
 
2321
2457
  // src/lib/utils/server-version-negotiator.ts
@@ -2339,9 +2475,12 @@ var ServerVersionNegotiator = class {
2339
2475
  * Returns the negotiated API version and the base path for all subsequent calls,
2340
2476
  * or null if the server is unreachable or incompatible.
2341
2477
  */
2342
- static async discover(baseUrl) {
2478
+ static async discover(baseUrl, headers) {
2343
2479
  try {
2344
- const response = await fetch(`${baseUrl}${VERSIONS_ENDPOINT}`);
2480
+ const resolved = resolveHeaders(headers);
2481
+ const response = await fetch(`${baseUrl}${VERSIONS_ENDPOINT}`, {
2482
+ headers: Object.keys(resolved).length > 0 ? resolved : void 0
2483
+ });
2345
2484
  if (!response.ok) return null;
2346
2485
  const info = await response.json();
2347
2486
  const version = this.negotiate(info);
@@ -2356,6 +2495,33 @@ var ServerVersionNegotiator = class {
2356
2495
  }
2357
2496
  };
2358
2497
 
2498
+ // src/lib/utils/websocket-auth.ts
2499
+ function buildAuthenticatedWebSocketUrl(wsUrl, headers) {
2500
+ const resolved = resolveHeaders(headers);
2501
+ if (Object.keys(resolved).length === 0) {
2502
+ return wsUrl;
2503
+ }
2504
+ const separator = wsUrl.includes("?") ? "&" : "?";
2505
+ const params = Object.entries(resolved).map(
2506
+ ([key, value]) => `_header_${encodeURIComponent(key)}=${encodeURIComponent(value)}`
2507
+ ).join("&");
2508
+ return `${wsUrl}${separator}${params}`;
2509
+ }
2510
+ async function resolveServerWebSocketUrl(services, serverName, wsUrl, configHeaders) {
2511
+ const authService = services?.get(ICliServerAuthService_TOKEN);
2512
+ const params = await authService?.getWebSocketParams?.(serverName);
2513
+ if (params) {
2514
+ return appendQueryParams(wsUrl, params);
2515
+ }
2516
+ return buildAuthenticatedWebSocketUrl(wsUrl, () => resolveServerHeaders(services, serverName, configHeaders));
2517
+ }
2518
+ function appendQueryParams(url, params) {
2519
+ const entries = Object.entries(params);
2520
+ if (!entries.length) return url;
2521
+ const query = entries.map(([k, v]) => `${encodeURIComponent(k)}=${encodeURIComponent(v)}`).join("&");
2522
+ return `${url}${url.includes("?") ? "&" : "?"}${query}`;
2523
+ }
2524
+
2359
2525
  // src/lib/utils/panel-theme-sync.ts
2360
2526
  function hexToRgb(hex) {
2361
2527
  const m = /^#?([0-9A-Fa-f]{6})([0-9A-Fa-f]{2})?$/.exec(hex);
@@ -2428,7 +2594,100 @@ function stripAnsi(text) {
2428
2594
  return text.replace(ANSI_RE, "");
2429
2595
  }
2430
2596
  function visibleLength(text) {
2431
- return stripAnsi(text).length;
2597
+ const stripped = stripAnsi(text);
2598
+ let width = 0;
2599
+ for (const ch of stripped) {
2600
+ const cp = ch.codePointAt(0);
2601
+ if (cp >= 65024 && cp <= 65039) continue;
2602
+ if (cp === 8205) continue;
2603
+ if (cp >= 768 && cp <= 879) continue;
2604
+ width += isWideCharacter(cp) ? 2 : 1;
2605
+ }
2606
+ return width;
2607
+ }
2608
+ function isWideCharacter(cp) {
2609
+ if (cp >= 126976) return true;
2610
+ if (cp >= 9728 && cp <= 10175) return true;
2611
+ if (cp >= 9984 && cp <= 10175) return true;
2612
+ if (cp >= 19968 && cp <= 40959) return true;
2613
+ if (cp >= 63744 && cp <= 64255) return true;
2614
+ if (cp >= 65281 && cp <= 65376) return true;
2615
+ if (cp >= 65504 && cp <= 65510) return true;
2616
+ if (cp >= 11904 && cp <= 12255) return true;
2617
+ if (cp >= 12288 && cp <= 12543) return true;
2618
+ if (cp >= 12800 && cp <= 13055) return true;
2619
+ if (cp >= 13056 && cp <= 13311) return true;
2620
+ if (cp >= 127232 && cp <= 127487) return true;
2621
+ if (cp >= 8960 && cp <= 9215) return true;
2622
+ return false;
2623
+ }
2624
+
2625
+ // src/lib/utils/access-guards.ts
2626
+ var list = (value) => Array.isArray(value) ? value.filter((v) => typeof v === "string" && v.trim()) : [];
2627
+ var authorization = (context) => {
2628
+ try {
2629
+ return context.services.get(ICliAuthorizationService_TOKEN);
2630
+ } catch {
2631
+ return void 0;
2632
+ }
2633
+ };
2634
+ function chain(processor) {
2635
+ const out = [];
2636
+ let current = processor;
2637
+ while (current && out.length < 32 && !out.includes(current)) {
2638
+ out.push(current);
2639
+ current = current.parent;
2640
+ }
2641
+ return out;
2642
+ }
2643
+ var requiredPermissionsOf = (p) => [...new Set(chain(p).flatMap((x) => list(x.metadata?.requiredPermissions)))];
2644
+ var requiredGroupLevels = (p) => chain(p).map((x) => list(x.metadata?.requiredGroups)).filter((g) => g.length > 0);
2645
+ var needsAuth = (p) => chain(p).some((x) => x.metadata?.requireAuth === true) || requiredGroupLevels(p).length > 0 || requiredPermissionsOf(p).length > 0;
2646
+ var cliRequireAuthGuard = {
2647
+ name: "access:require-auth",
2648
+ priority: -100,
2649
+ appliesTo: (processor, _command, context) => needsAuth(processor) && !!authorization(context),
2650
+ canActivate: (_command, processor, context) => authorization(context).getPrincipal() ? true : `${processor.command}: login required`
2651
+ };
2652
+ var cliRequiredGroupsGuard = {
2653
+ name: "access:required-groups",
2654
+ priority: -90,
2655
+ appliesTo: (processor, _command, context) => requiredGroupLevels(processor).length > 0 && !!authorization(context),
2656
+ canActivate: (_command, processor, context) => {
2657
+ const auth = authorization(context);
2658
+ const principal = auth.getPrincipal();
2659
+ if (!principal) return `${processor.command}: login required`;
2660
+ if (auth.can("*")) return true;
2661
+ for (const required of requiredGroupLevels(processor)) {
2662
+ const member = required.some((g) => principal.groups.some((pg) => pg.toLowerCase() === g.toLowerCase()));
2663
+ if (!member) return `${processor.command}: permission denied (requires group: ${required.join(" or ")})`;
2664
+ }
2665
+ return true;
2666
+ }
2667
+ };
2668
+ var cliRequiredPermissionsGuard = {
2669
+ name: "access:required-permissions",
2670
+ priority: -80,
2671
+ appliesTo: (processor, _command, context) => requiredPermissionsOf(processor).length > 0 && !!authorization(context),
2672
+ canActivate: (_command, processor, context) => {
2673
+ const principal = authorization(context).getPrincipal();
2674
+ if (!principal) return `${processor.command}: login required`;
2675
+ const missing = cliMissingPermissions(principal.permissions, requiredPermissionsOf(processor));
2676
+ return missing.length === 0 ? true : `${processor.command}: permission denied (requires ${missing.join(", ")})`;
2677
+ }
2678
+ };
2679
+ var cliAccessMetadataGuards = [
2680
+ cliRequireAuthGuard,
2681
+ cliRequiredGroupsGuard,
2682
+ cliRequiredPermissionsGuard
2683
+ ];
2684
+
2685
+ // src/lib/utils/server-target.ts
2686
+ function cliDefaultServer(context) {
2687
+ const servers = context.options?.servers ?? [];
2688
+ const manager = context.services?.get(ICliServerManager_TOKEN);
2689
+ const preferred = manager?.preferredServer?.();
2690
+ return (preferred ? servers.find((s) => s.name === preferred) : void 0) ?? servers[0];
2432
2691
  }
2433
2692
 
2434
2693
  // src/lib/utils/index.ts
@@ -3630,6 +3889,6 @@ var BrowserFileTransferService = class {
3630
3889
  }
3631
3890
  };
3632
3891
 
3633
- export { API_VERSION, BrowserFileTransferService, CANCELLATION_ERROR_MESSAGE, CLI_CONFIGURE_STORE_NAME, CancellablePromise, CliBackgroundColor, CliForegroundColor, CliIcon, CliLogLevel, CliModuleRegistry, DEFAULT_DIR_PERMISSIONS, DEFAULT_FILE_PERMISSIONS, DefaultLibraryAuthor, DefaultThemeInfos, DefaultThemes, ICliAuthService_TOKEN, ICliCompletionProvider_TOKEN, ICliDragDropService_TOKEN, ICliFilePickerProvider_TOKEN, ICliFileTransferService_TOKEN, ICliGroupsStoreService_TOKEN, ICliPermissionService_TOKEN, ICliTranslationService_TOKEN, ICliUserSessionService_TOKEN, ICliUsersStoreService_TOKEN, LIBRARY_VERSION, ObjectDescriber, ServerVersionNegotiator, bootCliModule, bootUmdModule, clearTerminalLine, colorFirstWord, colorizeJson, compareVersions, constants, createWorkerService, delay, derivePanelThemeStyles, enums, formatJson, getConfigValue, getParameterValue, getPluginConfigValue, getRightOfWord, highlightTextWithBg, initializeBrowserEnvironment, loadPanelPosition, nextPanelPosition, resolveConfigurationCategories, satisfiesMinVersion, satisfiesVersionRange, savePanelPosition, stripAnsi, toQueryString, utils, visibleLength };
3892
+ export { API_VERSION, BrowserFileTransferService, CANCELLATION_ERROR_MESSAGE, CLI_CONFIGURE_STORE_NAME, CancellablePromise, CliAccessDeniedError, CliBackgroundColor, CliForegroundColor, CliHttpError, CliIcon, 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, 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, bootUmdModule, buildAuthenticatedWebSocketUrl, clearTerminalLine, cliAccessMetadataGuards, cliAuthorize, cliCanAccess, cliDefaultServer, cliEvaluateAccess, cliHasPermission, cliMergePermissions, cliMissingPermissions, cliPermissionMatches, cliRequireAuthGuard, cliRequiredGroupsGuard, cliRequiredPermissionsGuard, colorFirstWord, colorizeJson, compareVersions, constants, createWorkerService, delay, derivePanelThemeStyles, enums, formatJson, getConfigValue, getParameterValue, getPluginConfigValue, getRightOfWord, highlightTextWithBg, initializeBrowserEnvironment, isCliAccessDeniedError, loadPanelPosition, nextPanelPosition, resolveConfigurationCategories, resolveHeaders, resolveServerHeaders, resolveServerWebSocketUrl, satisfiesMinVersion, satisfiesVersionRange, savePanelPosition, stripAnsi, toQueryString, utils, visibleLength };
3634
3893
  //# sourceMappingURL=public-api.mjs.map
3635
3894
  //# sourceMappingURL=public-api.mjs.map