bitwarden / sdk

Bitwarden SDK.
Other
237 stars 37 forks source link

Projects support for npm @bitwarden/sdk-napi #914

Open wmr-trevor opened 2 months ago

wmr-trevor commented 2 months ago

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/sdk-napi@0.3.1
  └── @bitwarden/sdk-napi-linux-x64-gnu@0.3.1

Operating System

Linux

Operating System Version

Pop!_OS 22.04 LTS

Build Version

@0.3.1

Issue Tracking Info

dani-garcia commented 1 month ago

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

Araxeus commented 1 month ago

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

Araxeus commented 3 weeks ago

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

Hinton commented 3 weeks ago

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