### Get Configuration (`getConfiguration`) Source: https://context7.com/microsoft/azure-devops-extension-sdk/llms.txt Retrieves the configuration object passed to the extension contribution at load time. Use this to access custom settings defined in the extension manifest. ```typescript import * as SDK from "azure-devops-extension-sdk"; await SDK.init(); const config = SDK.getConfiguration(); // config: { [key: string]: any } // e.g. { "widgetSize": { "columnSpan": 2, "rowSpan": 2 }, "customSetting": "value" } const size = config["widgetSize"]; if (size) { console.log(`Widget spans ${size.columnSpan} columns × ${size.rowSpan} rows`); } ``` -------------------------------- ### Get Extension Context (`getExtensionContext`) Source: https://context7.com/microsoft/azure-devops-extension-sdk/llms.txt Fetches details about the currently running extension, including its ID, publisher, version, and base URI for assets. Useful for constructing URLs to bundled resources. ```typescript import * as SDK from "azure-devops-extension-sdk"; await SDK.init(); const ext = SDK.getExtensionContext(); // ext: IExtensionContext // { // id: "my-publisher.my-extension", // publisherId: "my-publisher", // extensionId: "my-extension", // version: "1.2.3", // baseUri: "https://extmgmt.dev.azure.com/..." // } // Build a URL to a static asset bundled with the extension const iconUrl = `${ext.baseUri}/images/icon.png`; console.log(`Extension ${ext.id} v${ext.version} loaded`); ``` -------------------------------- ### Get Team Context (`getTeamContext`) Source: https://context7.com/microsoft/azure-devops-extension-sdk/llms.txt Retrieves the context of the currently active team, including its ID and name. This is essential for operations that are team-specific. ```typescript import * as SDK from "azure-devops-extension-sdk"; await SDK.init(); const team = SDK.getTeamContext(); // team: ITeamContext // { // id: "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx", // name: "Contoso Team" // } console.log(`Active team: ${team.name} (${team.id})`); ``` -------------------------------- ### Get Host Context (`getHost`) Source: https://context7.com/microsoft/azure-devops-extension-sdk/llms.txt Retrieves information about the Azure DevOps host (organization or server). Use this to determine if running on Azure DevOps Services or Server and to access host details like name and version. ```typescript import * as SDK from "azure-devops-extension-sdk"; import { HostType } from "azure-devops-extension-sdk"; await SDK.init(); const host = SDK.getHost(); // host: IHostContext // { // id: "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx", // name: "my-organization", // serviceVersion: "19.218.34106.5", // type: HostType.Organization, // 4 // isHosted: true // } if (host.isHosted) { console.log(`Running on Azure DevOps Services: ${host.name}`); } else { console.log(`Running on Azure DevOps Server v${host.serviceVersion}`); } ``` -------------------------------- ### Get Current User Context Source: https://context7.com/microsoft/azure-devops-extension-sdk/llms.txt Retrieve the `IUserContext` object after initialization to access details about the signed-in user, such as their display name and image URL. Use the `imageUrl` to display the user's avatar. ```typescript import * as SDK from "azure-devops-extension-sdk"; await SDK.init(); const user = SDK.getUser(); // user: IUserContext // { // id: "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx", // descriptor: "aad.BASE64ENCODEDVALUE", // name: "user@contoso.com", // displayName: "Jane Doe", // imageUrl: "https://dev.azure.com/_api/_common/identityImage?id=..." // } console.log(`Signed in as: ${user.displayName} (${user.name})`); // Use imageUrl to display an avatar const avatar = document.createElement("img"); avatar.src = user.imageUrl; avatar.alt = user.displayName; document.body.appendChild(avatar); ``` -------------------------------- ### Get Page Context (`getPageContext`) Source: https://context7.com/microsoft/azure-devops-extension-sdk/llms.txt Obtains comprehensive context for the current Azure DevOps page, including globalization settings (culture, theme, timezone) and web context (project and team identifiers). ```typescript import * as SDK from "azure-devops-extension-sdk"; await SDK.init(); const page = SDK.getPageContext(); // page.globalization: { culture: "en-US", theme: "dark", timeZoneId: "UTC", ... } // page.webContext.project: { id: "...", name: "MyProject" } // page.webContext.team: { id: "...", name: "MyTeam" } const { culture, theme } = page.globalization; console.log(`Page culture: ${culture}, theme: ${theme}`); console.log(`Project: ${page.webContext.project.name}`); ``` -------------------------------- ### Get Contribution ID (`getContributionId`) Source: https://context7.com/microsoft/azure-devops-extension-sdk/llms.txt Returns the unique ID of the contribution that initiated the extension's loading. This is useful for identifying the specific extension point being used. ```typescript import * as SDK from "azure-devops-extension-sdk"; await SDK.init(); const contributionId = SDK.getContributionId(); // e.g. "my-publisher.my-extension.my-hub" console.log(`Loaded via contribution: ${contributionId}`); ``` -------------------------------- ### Get a user-identity token Source: https://context7.com/microsoft/azure-devops-extension-sdk/llms.txt Returns a signed JWT token to identify the current user to a back-end service. This is useful for lightweight user-identity verification without requiring full API access. ```typescript import * as SDK from "azure-devops-extension-sdk"; await SDK.init(); const appToken = await SDK.getAppToken(); // appToken: "eyJ0eXAiOiJKV1Q..." // Send to your own back-end for verification const resp = await fetch("https://my-backend.example.com/api/verify-user", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ token: appToken }) }); const result = await resp.json(); console.log("User verified:", result.verified); ``` -------------------------------- ### Get Remote Object Proxy with XDM Source: https://context7.com/microsoft/azure-devops-extension-sdk/llms.txt Use channel.getRemoteObjectProxy to obtain a proxy for a remote object, enabling direct method calls on the remote service. This is useful for typed interfaces to complex remote services. ```typescript import { channelManager } from "azure-devops-extension-sdk/XDM"; interface IRemoteCalculator { add(a: number, b: number): Promise; multiply(a: number, b: number): Promise; } const iframe = document.getElementById("calc-frame") as HTMLIFrameElement; const channel = channelManager.addChannel(iframe.contentWindow!); const calculator = await channel.getRemoteObjectProxy("calculator"); const sum = await calculator.add(3, 4); // 7 const product = await calculator.multiply(3, 4); // 12 console.log(`3 + 4 = ${sum}, 3 × 4 = ${product}`); ``` -------------------------------- ### Get an Azure DevOps REST API access token Source: https://context7.com/microsoft/azure-devops-extension-sdk/llms.txt Retrieves a bearer token for authenticating REST calls to Azure DevOps services. The token is scoped to the current organization and can be used to access resources on behalf of the user. ```typescript import * as SDK from "azure-devops-extension-sdk"; await SDK.init(); const token = await SDK.getAccessToken(); // token: "eyJ0eXAiOiJKV1Q..." const host = SDK.getHost(); const response = await fetch( `https://dev.azure.com/${host.name}/_apis/projects?api-version=7.1`, { headers: { Authorization: `Bearer ${token}`, "Content-Type": "application/json" } } ); const projects = await response.json(); console.log("Projects:", projects.value.map((p: any) => p.name)); ``` -------------------------------- ### ready() Source: https://context7.com/microsoft/azure-devops-extension-sdk/llms.txt Returns a Promise that resolves once `init()` has completed its handshake with the host. This is useful for synchronizing code execution that depends on the SDK being fully initialized. ```APIDOC ## ready() ### Description Await completion of initialization. Returns a Promise that resolves once `init()` has completed its handshake with the host. Use this in any code path that may run before or concurrently with `init()`, to safely gate SDK context calls. ### Method `ready(): Promise` ### Response Example ```typescript import * as SDK from "azure-devops-extension-sdk"; SDK.init({ loaded: false }); // Independently running code that needs SDK to be ready SDK.ready().then(() => { const user = SDK.getUser(); console.log(`Hello, ${user.displayName}!`); SDK.notifyLoadSucceeded(); }); ``` ``` -------------------------------- ### Initialize SDK Source: https://github.com/microsoft/azure-devops-extension-sdk/blob/master/README.md Call SDK.init() after rendering your extension content to notify the host frame that your extension is ready. This ensures your content is displayed correctly. ```typescript import * as SDK from "azure-devops-extension-sdk"; SDK.init(); ``` -------------------------------- ### init(options?) Source: https://context7.com/microsoft/azure-devops-extension-sdk/llms.txt Initializes the extension and performs the handshake with the Azure DevOps host frame. This method must be called before accessing context data. It can be configured to automatically signal load completion or allow manual notification. ```APIDOC ## init(options?) ### Description Initiates the handshake with the Azure DevOps host frame. Must be called before any other SDK method that returns context data. Accepts an optional `IExtensionInitOptions` object to control whether the extension signals load completion automatically (`loaded: true`, the default) or manually via `notifyLoadSucceeded()`, and whether to apply the host's CSS theme to the extension content. ### Method `init(options?: IExtensionInitOptions)` ### Parameters #### Optional Parameters - **options** (`IExtensionInitOptions`) - An object to configure initialization behavior. - **loaded** (`boolean`) - Optional. If `true` (default), the host is automatically notified of load completion. If `false`, manual notification via `notifyLoadSucceeded()` is required. - **applyTheme** (`boolean`) - Optional. If `true`, the host's CSS theme is applied to the extension content. ### Request Example ```typescript import * as SDK from "azure-devops-extension-sdk"; // Option 1: Auto-notify host that extension is ready after handshake await SDK.init(); console.log("Extension initialized and visible to host"); // Option 2: Defer load notification (useful for async data fetching before display) await SDK.init({ loaded: false, applyTheme: true }); // ... perform async setup work ... try { await fetchMyExtensionData(); await SDK.notifyLoadSucceeded(); // Tell host to stop showing the spinner } catch (e) { await SDK.notifyLoadFailed(e as Error); // Tell host the extension failed } ``` ``` -------------------------------- ### Await Initialization Completion Source: https://context7.com/microsoft/azure-devops-extension-sdk/llms.txt Use SDK.ready() to ensure the SDK is initialized before accessing context data. This is useful when SDK calls might occur before or concurrently with SDK.init(). ```typescript import * as SDK from "azure-devops-extension-sdk"; SDK.init({ loaded: false }); // Independently running code that needs SDK to be ready SDK.ready().then(() => { const user = SDK.getUser(); console.log(`Hello, ${user.displayName}!`); SDK.notifyLoadSucceeded(); }); ``` -------------------------------- ### Initialize Extension and Perform Handshake Source: https://context7.com/microsoft/azure-devops-extension-sdk/llms.txt Call SDK.init() to establish communication with the host frame. Use `{ loaded: false }` to manually control load completion with `notifyLoadSucceeded()` or `notifyLoadFailed()`. ```typescript import * as SDK from "azure-devops-extension-sdk"; // Option 1: Auto-notify host that extension is ready after handshake await SDK.init(); console.log("Extension initialized and visible to host"); // Option 2: Defer load notification (useful for async data fetching before display) await SDK.init({ loaded: false, applyTheme: true }); // ... perform async setup work ... try { await fetchMyExtensionData(); await SDK.notifyLoadSucceeded(); // Tell host to stop showing the spinner } catch (e) { await SDK.notifyLoadFailed(e as Error); // Tell host the extension failed } ``` -------------------------------- ### Import SDK using AMD Modules Source: https://github.com/microsoft/azure-devops-extension-sdk/blob/master/README.md Use this method to import the SDK if your project is using AMD modules. No changes are needed for existing AMD projects. ```javascript require(['azure-devops-extension-sdk'], function(SDK) { // Use the module here }); ``` -------------------------------- ### getConfiguration() Source: https://context7.com/microsoft/azure-devops-extension-sdk/llms.txt Retrieves the initial configuration object provided to the extension by the host. ```APIDOC ## getConfiguration() ### Description Returns the initial configuration object passed by the host to this extension contribution at load time. Useful for reading properties defined in the extension manifest's contribution properties. ### Usage ```typescript import * as SDK from "azure-devops-extension-sdk"; await SDK.init(); const config = SDK.getConfiguration(); // config: { [key: string]: any } // e.g. { "widgetSize": { "columnSpan": 2, "rowSpan": 2 }, "customSetting": "value" } const size = config["widgetSize"]; if (size) { console.log(`Widget spans ${size.columnSpan} columns × ${size.rowSpan} rows`); } ``` ``` -------------------------------- ### Import SDK using ES Modules Source: https://github.com/microsoft/azure-devops-extension-sdk/blob/master/README.md Use this method to import the SDK for projects utilizing ES modules. This offers performance improvements and reduces application size. ```javascript import * as SDK from 'azure-devops-extension-sdk'; // Use the module here ``` -------------------------------- ### getHost() Source: https://context7.com/microsoft/azure-devops-extension-sdk/llms.txt Retrieves the host organization context, including details about whether the instance is hosted or on-premises. ```APIDOC ## getHost() ### Description Returns an `IHostContext` describing the Azure DevOps organization (or server instance) the extension is running in, including the host type (`Organization`, `Enterprise`, or `Deployment`) and whether it is a hosted (Azure DevOps Services) or on-premises (Azure DevOps Server) instance. ### Usage ```typescript import * as SDK from "azure-devops-extension-sdk"; import { HostType } from "azure-devops-extension-sdk"; await SDK.init(); const host = SDK.getHost(); // host: IHostContext // { // id: "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx", // name: "my-organization", // serviceVersion: "19.218.34106.5", // type: HostType.Organization, // 4 // isHosted: true // } if (host.isHosted) { console.log(`Running on Azure DevOps Services: ${host.name}`); } else { console.log(`Running on Azure DevOps Server v${host.serviceVersion}`); } ``` ``` -------------------------------- ### resize(width?, height?) Source: https://context7.com/microsoft/azure-devops-extension-sdk/llms.txt Requests the host to resize the extension iframe. Defaults to the current `document.body.scrollWidth` and `document.body.scrollHeight` if dimensions are omitted. ```APIDOC ## resize(width?, height?) ### Description Requests the parent Azure DevOps frame to resize the iframe container for this extension. Defaults to the current `document.body.scrollWidth` and `document.body.scrollHeight` if dimensions are omitted. ### Parameters - **width** (number) - Optional - The desired width of the iframe in pixels. - **height** (number) - Optional - The desired height of the iframe in pixels. ### Example ```typescript import * as SDK from "azure-devops-extension-sdk"; await SDK.init(); // Auto-resize to fit content SDK.resize(); // Or specify exact dimensions (pixels) SDK.resize(800, 600); // Useful after dynamic content updates function renderContent(items: string[]) { const list = document.getElementById("list")!; list.innerHTML = items.map(i => `
  • ${i}
  • `).join(""); SDK.resize(); // Fit the new content height } ``` ``` -------------------------------- ### notifyLoadSucceeded() Source: https://context7.com/microsoft/azure-devops-extension-sdk/llms.txt Signals to the host frame that the extension has successfully finished loading and its UI is ready. This is only necessary when `init()` is called with the `loaded: false` option. ```APIDOC ## notifyLoadSucceeded() ### Description Signal successful extension load. Notifies the host frame that the extension has finished loading and its UI is ready to be displayed. Only required when `init()` is called with `{ loaded: false }`. ### Method `notifyLoadSucceeded(): Promise` ### Request Example ```typescript import * as SDK from "azure-devops-extension-sdk"; await SDK.init({ loaded: false }); const data = await fetch("/my-extension-data").then(r => r.json()); renderUI(data); await SDK.notifyLoadSucceeded(); // Host removes loading spinner and shows extension content ``` ``` -------------------------------- ### applyTheme(themeData) Source: https://context7.com/microsoft/azure-devops-extension-sdk/llms.txt Injects a `