Skip to content

Add CoreAPI to getAdoApi and getAdoApiWithAzCli return objects #196

@beauraines

Description

@beauraines

Problem

getAdoApi() and getAdoApiWithAzCli() in src/ado.js only return workAPI and workItemAPI. Consumers that need the Core API (e.g. to list projects) must create a separate WebApi connection manually, duplicating auth logic.

See: https://github.com/beauraines/ado-utilities/pull/27#discussion_r2835588502

Proposed Change

Add coreAPI to the returned object from both functions. The WebApi connection is already created — just add one more getCoreApi() call.

In getAdoApi() (~line 27):

const coreAPI = await connection.getCoreApi();

return {
    workAPI,
    workItemAPI,
    coreAPI,
    teamContext,
    config
}

In getAdoApiWithAzCli() (~line 73):

const coreAPI = await connection.getCoreApi();

return {
    workAPI,
    workItemAPI,
    coreAPI,
    teamContext,
    config
}

Consumer Impact

Once released, ado-utilities/src/getProjects.js can be simplified from:

const ado = require('@beauraines/node-helpers').ado;
const azdev = require('azure-devops-node-api');

async function listProjects() {
    const { config } = await ado.getAdoApiWithAzCli(configFile)
    const authHandler = azdev.getBearerHandler(config.token);
    const connection = new azdev.WebApi(config.org, authHandler);
    const coreApi = await connection.getCoreApi();
    const result = await coreApi.getProjects();
}

To:

const ado = require('@beauraines/node-helpers').ado;

async function listProjects() {
    const { coreAPI } = await ado.getAdoApiWithAzCli(configFile)
    const result = await coreAPI.getProjects();
}

This is a non-breaking change — existing destructuring patterns will continue to work.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions