sdk icon indicating copy to clipboard operation
sdk copied to clipboard

Projects support for npm @bitwarden/sdk-napi

Open wmr-trevor opened this issue 1 year ago • 2 comments

Steps To Reproduce

  1. Install the package npm i @bitwarden/sdk-napi
  2. Attempt to get project info

Expected Result

I would have expected the .project() property to be set in the BitwardenClient class similar to .secret()

I would also assume that a new ProjectsClient class will be needed similar to the SecretsClient class found in crates/bitwarden-napi/src-ts/bitwarden_client/index.ts

Actual Result

There is currently not a easy supported method to get project information like there is for secrets.

Screenshots or Videos

No response

Additional Context

The relavant information needed to successfully run the commands is in the schema file. So the following works to list the projects.

const { BitwardenClient } = require("@bitwarden/sdk-napi");
const {
    Convert,
} = require("@bitwarden/sdk-napi/dist/bitwarden_client/schemas");

async function main() {
    const organizationId = process.env.BWS_ORG_ID;
    const accessToken = process.env.BWS_ACCESS_TOKEN;
    if (
        typeof organizationId !== "string" ||
        !organizationId ||
        typeof accessToken !== "string" ||
        !accessToken
    ) {
        throw new Error("Missing required environment variables");
    }

    // setup the bitwarden secrets manager
    const settings = {};
    const client = new BitwardenClient(settings);

    const result = await client.loginWithAccessToken(accessToken);
    if (!result.success) {
        throw new Error("Failed to login with access token");
    }

    const cmdResult = await client.client.runCommand(
        Convert.commandToJson({
            projects: {
                list: {
                    organizationId,
                },
            },
        })
    );

    const list = Convert.toResponseForProjectsResponse(cmdResult).data;

    console.log(list);
}
main();

More Detailed Version Info

└─┬ @bitwarden/[email protected]
  └── @bitwarden/[email protected]

Operating System

Linux

Operating System Version

Pop!_OS 22.04 LTS

Build Version

@0.3.1

Issue Tracking Info

  • [X] I understand that work is tracked outside of Github. A PR will be linked to this issue should one be opened to address it, but Bitwarden doesn't use fields like "assigned", "milestone", or "project" to track progress.

wmr-trevor avatar Jul 19 '24 13:07 wmr-trevor

This should be fixed by https://github.com/bitwarden/sdk/pull/934 when it gets merged, I think

dani-garcia avatar Aug 07 '24 16:08 dani-garcia

It was merged last week but no new version was released?

Araxeus avatar Aug 14 '24 17:08 Araxeus

Merged one month ago but the version didn't change in the PR and the package wasn't published on npm @dani-garcia @Hinton

https://github.com/bitwarden/sdk/blob/7ee604f9a01cb6d3c4ea18d7048151ff4ececfbe/crates/bitwarden-napi/package.json#L3

Araxeus avatar Sep 04 '24 20:09 Araxeus

The team is working on publishing new versions of all the SDKs. I don't have a date but it should be soon.

Hinton avatar Sep 05 '24 08:09 Hinton

The 1.0 release: https://github.com/bitwarden/sdk/releases/tag/napi-v1.0.0

coltonhurst avatar Oct 09 '24 19:10 coltonhurst