diff --git a/package-lock.json b/package-lock.json index ca8df19..2134650 100644 --- a/package-lock.json +++ b/package-lock.json @@ -13,7 +13,7 @@ "node-cmd": "^6.0.1" }, "devDependencies": { - "@intersystems-community/intersystems-servermanager": "^3.14.1", + "@intersystems-community/intersystems-servermanager": "3.15.0-beta.1", "@types/glob": "^7.1.1", "@types/mocha": "^9.0.0", "@types/node": "^20.14.0", @@ -68,9 +68,9 @@ } }, "node_modules/@intersystems-community/intersystems-servermanager": { - "version": "3.14.1", - "resolved": "https://registry.npmjs.org/@intersystems-community/intersystems-servermanager/-/intersystems-servermanager-3.14.1.tgz", - "integrity": "sha512-sGOq2agsIdN0dO6AwqciSbt8bV/y2gLBuRpiyq7hUR/7liE7s5a2EbYryN6A+h6J2lHLo/akiFz1ipmckIXvvg==", + "version": "3.15.0-beta.1", + "resolved": "https://registry.npmjs.org/@intersystems-community/intersystems-servermanager/-/intersystems-servermanager-3.15.0-beta.1.tgz", + "integrity": "sha512-5SXeAK4BNLHY9J8GyAlDhO/+nkT9jCuntPwL+N+YtTqKo5NmrZ+fY0glmKulIRmTBixXZtp5+qOA6vPjH5SPig==", "dev": true, "license": "MIT" }, diff --git a/package.json b/package.json index 7454b5e..45f510a 100644 --- a/package.json +++ b/package.json @@ -53,7 +53,7 @@ "node-cmd": "^6.0.1" }, "devDependencies": { - "@intersystems-community/intersystems-servermanager": "^3.14.1", + "@intersystems-community/intersystems-servermanager": "3.15.0-beta.1", "@types/glob": "^7.1.1", "@types/mocha": "^9.0.0", "@types/node": "^20.14.0", diff --git a/src/api/addServer.ts b/src/api/addServer.ts index b12e713..1d192cb 100644 --- a/src/api/addServer.ts +++ b/src/api/addServer.ts @@ -1,6 +1,6 @@ +import { IJSONServerSpec } from "@intersystems-community/intersystems-servermanager"; import * as vscode from "vscode"; import { promptOAuth2Authority, promptOAuth2ClientId } from "../oauth2Prompts"; -import { IServerSetting } from "../serverSetting"; import { getServerNames } from "./getServerNames"; export async function addServer( @@ -107,7 +107,7 @@ export async function addServer( { ignoreFocusOut: true, title: "Select the authentication method" }, ))?.label; if (authMethod === undefined) { return; } - let authDetails: Pick; + let authDetails: Pick; if (authMethod === "OAuth2") { const authority = (await promptOAuth2Authority(name))?.trim(); if (!authority) { return; } diff --git a/src/api/getServerSpec.ts b/src/api/getServerSpec.ts index 72d826f..8bbb2b0 100644 --- a/src/api/getServerSpec.ts +++ b/src/api/getServerSpec.ts @@ -1,7 +1,6 @@ -import { IServerSpec, Authorization, VSCodeObjectScriptAPI } from "@intersystems-community/intersystems-servermanager"; +import { IServerSpec, Authorization, VSCodeObjectScriptAPI, IJSONServerSpec } from "@intersystems-community/intersystems-servermanager"; import * as vscode from "vscode"; import { OAuth2Authorization, OBJECTSCRIPT_EXTENSIONID, BasicAuthorization } from "../commonActivate"; -import { IServerSetting } from "../serverSetting"; /** * Get a server specification. @@ -15,7 +14,7 @@ export async function getServerSpec( scope?: vscode.ConfigurationScope, ): Promise { // To avoid breaking existing users, continue to return a default server definition even after we dropped that feature - const setting = vscode.workspace.getConfiguration("intersystems.servers", scope).get(name) as IServerSetting | undefined || legacyEmbeddedServer(name); + const setting = vscode.workspace.getConfiguration("intersystems.servers", scope).get(name) as IJSONServerSpec | undefined || legacyEmbeddedServer(name); // Unknown server if (!setting) { const folder = vscode.workspace.workspaceFolders?.find((f) => f.name === name); @@ -52,8 +51,8 @@ export async function getServerSpec( }; } else { // Found a setting - const { username, password, oauth2, ...spec } = setting; - spec.name = name; + const { username, password, oauth2, ...kept } = setting; + const spec = { ...kept, name }; spec.description = spec.description || ""; spec.webServer.scheme = spec.webServer.scheme || "http"; spec.webServer.port = spec.webServer.port || (spec.webServer.scheme === "https" ? 443 : 80); @@ -81,10 +80,9 @@ export async function getServerSpec( * @param name The name. * @returns Server specification or undefined. */ -export function legacyEmbeddedServer(name: string): IServerSetting | undefined { +export function legacyEmbeddedServer(name: string): IJSONServerSpec | undefined { return { "default~iris": { - name: "default~iris", webServer: { scheme: "http", host: "127.0.0.1", @@ -93,7 +91,6 @@ export function legacyEmbeddedServer(name: string): IServerSetting | undefined { description: "Connection to local InterSystems IRIS™ installed with default settings.", }, "default~cache": { - name: "default~cache", webServer: { scheme: "http", host: "127.0.0.1", @@ -102,7 +99,6 @@ export function legacyEmbeddedServer(name: string): IServerSetting | undefined { description: "Connection to local InterSystems Caché installed with default settings.", }, "default~ensemble": { - name: "default~ensemble", webServer: { scheme: "http", host: "127.0.0.1", diff --git a/src/api/getServerSummary.ts b/src/api/getServerSummary.ts index 298dd9f..6ce7b5f 100644 --- a/src/api/getServerSummary.ts +++ b/src/api/getServerSummary.ts @@ -1,17 +1,16 @@ -import { IServerName } from "@intersystems-community/intersystems-servermanager"; +import { IServerName, IJSONServerSpec } from "@intersystems-community/intersystems-servermanager"; import * as vscode from "vscode"; -import { IServerSetting } from "../serverSetting"; import { legacyEmbeddedServer } from "./getServerSpec"; export function getServerSummary(name: string, scope?: vscode.ConfigurationScope): IServerName | undefined { // To avoid breaking existing users, continue to return a default server definition even after we dropped that feature - const server = vscode.workspace.getConfiguration("intersystems.servers", scope).get(name) as IServerSetting | undefined || legacyEmbeddedServer(name); + const server = vscode.workspace.getConfiguration("intersystems.servers", scope).get(name) || legacyEmbeddedServer(name); if (!server) { return undefined; } return { name, description: server.description || "", detail: serverDetail(server), scope }; } -export function serverDetail(connSpec: IServerSetting): string { +export function serverDetail(connSpec: IJSONServerSpec): string { return `${connSpec.webServer.scheme || "http"}://${connSpec.webServer.host}:${connSpec.webServer.port}${connSpec.webServer.pathPrefix || ""}/`; } diff --git a/src/commonActivate.ts b/src/commonActivate.ts index 99ce8ec..443b96d 100644 --- a/src/commonActivate.ts +++ b/src/commonActivate.ts @@ -1,4 +1,4 @@ -import { Authorization, IServerName, IServerSpec, ResolvedAuthorization, ServerManagerAPI } from "@intersystems-community/intersystems-servermanager"; +import { Authorization, IOAuth2Spec, IServerName, IServerSpec, ResolvedAuthorization, ServerManagerAPI } from "@intersystems-community/intersystems-servermanager"; import * as vscode from "vscode"; import { addServer } from "./api/addServer"; import { getPortalUri } from "./api/getPortalUri"; @@ -9,7 +9,6 @@ import { pickServer } from "./api/pickServer"; import { AUTHENTICATION_PROVIDER, ServerManagerAuthenticationProvider } from "./authenticationProvider"; import { initLogger } from "./logger"; import { logout, serverSessions } from "./makeRESTRequest"; -import { OAuth2Config } from "./serverSetting"; import { NamespaceTreeItem, ProjectTreeItem, ServerManagerView, ServerTreeItem, SMTreeItem, WebAppTreeItem } from "./ui/serverManagerView"; export const extensionId = "intersystems-community.servermanager"; @@ -75,10 +74,14 @@ export class BasicAuthorization implements Authorization { } } +interface ResolvedOAuth2Authorization extends ResolvedAuthorization { + get httpAuthorizationHeader(): string; +} + export class OAuth2Authorization implements Authorization { #username?: string; #bearer?: string; - constructor(public readonly oauth2: OAuth2Config, bearer?: string) { + constructor(public readonly oauth2: IOAuth2Spec, bearer?: string) { this.#bearer = bearer; } @@ -88,11 +91,11 @@ export class OAuth2Authorization implements Authorization { } } - public resolved(): this is ResolvedAuthorization { + public resolved(): this is ResolvedOAuth2Authorization { return this.#bearer ? true : false; } - public resolve({ accessToken, username }): this is ResolvedAuthorization { + public resolve({ accessToken, username }): this is ResolvedOAuth2Authorization { // empty accessTokens are ignored. if (accessToken) { this.#bearer = accessToken; @@ -151,8 +154,8 @@ export function commonActivate(context: vscode.ExtensionContext, view: ServerMan if (pathParts && pathParts.length === 4) { const serverName = pathParts[1]; const namespace = pathParts[3]; - const serverSetting = await getServerSpec(serverName); - if (serverSetting) { + const server = await getServerSpec(serverName); + if (server) { const isfsExtension = vscode.extensions.getExtension(OBJECTSCRIPT_EXTENSIONID); if (isfsExtension) { if (!isfsExtension.isActive) { diff --git a/src/oauth2Flow.ts b/src/oauth2Flow.ts index bb0927a..37c3aef 100644 --- a/src/oauth2Flow.ts +++ b/src/oauth2Flow.ts @@ -1,10 +1,9 @@ +import { IOAuth2Spec } from "@intersystems-community/intersystems-servermanager"; import axios from "axios"; import * as vscode from "vscode"; import { logger } from "./logger"; -export interface IOAuth2Config { - authority: string; - clientId: string; +export interface IOAuth2Config extends IOAuth2Spec { audience: string; } diff --git a/src/serverSetting.ts b/src/serverSetting.ts deleted file mode 100644 index 54a643d..0000000 --- a/src/serverSetting.ts +++ /dev/null @@ -1,13 +0,0 @@ -import { IServerSpec } from "@intersystems-community/intersystems-servermanager"; - -export interface OAuth2Config { - authority: string; - clientId: string; -} - -export interface IServerSetting extends Omit { - // username and password are deprecated in IServerSpec but not in IServerSetting - username?: string; - password?: string; - oauth2?: OAuth2Config; -} diff --git a/types/index.d.ts b/types/index.d.ts index 28c0eaa..e6dbb4e 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -22,9 +22,26 @@ export interface ISuperServerSpec { port: number; } +export interface IOAuth2Spec { + authority: string; + clientId: string; +} + +/** One entry of the 'intersystems.servers' setting; the server name is the key. */ export interface IJSONServerSpec { webServer: IWebServerSpec; superServer?: ISuperServerSpec; + username?: string; + password?: string; + oauth2?: IOAuth2Spec; + description?: string; +} + +/** + * Processed `IJSONServerSpec`: `name` added, `oauth2` folded into `auth`, and `username`/`password` deprecated in favour of `auth`. + */ +export interface IServerSpec extends Omit { + name: string; /** * @deprecated Use `auth.username` instead. Get credentials from the `auth` property. */ @@ -33,16 +50,7 @@ export interface IJSONServerSpec { * @deprecated Use `auth.password` instead. Get credentials from the `auth` property. */ password?: string; - auth?: Authorization; - description?: string; -} - -export interface IServerSpec extends IJSONServerSpec { - name: string; -} - -/** IServerSpec with `auth` guaranteed to be present. */ -export interface IServerSpecWithAuth extends IServerSpec { + /** Always present in current Server Manager versions; optional for compatibility with older ones. */ auth?: Authorization; } @@ -68,7 +76,7 @@ export interface ServerManagerAPI { scope?: vscode.ConfigurationScope, flushCredentialCache?: boolean, options?: { hideFromRecents?: boolean, /* Obsolete */ noCredentials?: boolean }, - ): Promise; + ): Promise; getAccount( serverSpec: Pick, @@ -106,10 +114,10 @@ export interface Authorization { get credentials(): undefined | { auth?: { username: string; password: string }; headers?: Record }; } -/** Narrowed `Authorization` known to hold usable credentials, per `resolved()`. */ +/** Narrowed `Authorization` known to hold usable credentials, per `resolved()`. `httpAuthorizationHeader` stays optional because UnknownUser has nothing to send. */ export interface ResolvedAuthorization extends Authorization { + /** Empty for UnknownUser, since unauthenticated access has no credential. */ get accessToken(): string; - get httpAuthorizationHeader(): string; get credentials(): { auth?: { username: string; password: string }; headers?: Record }; } diff --git a/types/package.json b/types/package.json index 7cd337f..f3f4e33 100644 --- a/types/package.json +++ b/types/package.json @@ -1,6 +1,6 @@ { "name": "@intersystems-community/intersystems-servermanager", - "version": "3.14.1", + "version": "3.15.0-beta.1", "description": "InterSystems Server Manager VS Code extension API interfaces and constants", "types": "index.d.ts", "main": "index.js",