Skip to content

Commit

Permalink
[SM-1394] Update NAPI language bindings (#934)
Browse files Browse the repository at this point in the history
## 🎟️ Tracking

<!-- Paste the link to the Jira or GitHub issue or otherwise describe /
point to where this change is coming from. -->
https://bitwarden.atlassian.net/browse/SM-1394

## 📔 Objective

<!-- Describe what the purpose of this PR is, for example what bug
you're fixing or new feature you're adding. -->
The objective of this PR is to get NAPI language bindings in sync with
latest SDK/schema changes.

This includes adding a project client, state file support, and updating
the secret client.
  • Loading branch information
Thomas-Avery authored Aug 8, 2024
1 parent 6e65f97 commit 3621c25
Show file tree
Hide file tree
Showing 6 changed files with 210 additions and 262 deletions.
5 changes: 1 addition & 4 deletions crates/bitwarden-napi/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,7 @@ const accessToken = "-- REDACTED --";
const client = new BitwardenClient(settings, LogLevel.Info);

// Authenticating using a machine account access token
const result = await client.loginWithAccessToken(accessToken);
if (!result.success) {
throw Error("Authentication failed");
}
await client.accessTokenLogin(accessToken);

// List secrets
const secrets = await client.secrets().list();
Expand Down
2 changes: 1 addition & 1 deletion crates/bitwarden-napi/binding.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export const enum LogLevel {
Warn = 3,
Error = 4,
}
export class BitwardenClient {
export declare class BitwardenClient {
constructor(settingsInput?: string | undefined | null, logLevel?: LogLevel | undefined | null);
runCommand(commandInput: string): Promise<string>;
}
76 changes: 71 additions & 5 deletions crates/bitwarden-napi/binding.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
const { existsSync, readFileSync } = require("fs");
/* tslint:disable */
/* eslint-disable */
/* prettier-ignore */

/* auto-generated by NAPI-RS */

const { existsSync, readFileSync } = require('fs')
const { join } = require("path");

const { platform, arch } = process;
Expand All @@ -11,7 +17,8 @@ function isMusl() {
// For Node 10
if (!process.report || typeof process.report.getReport !== "function") {
try {
return readFileSync("/usr/bin/ldd", "utf8").includes("musl");
const lddPath = require("child_process").execSync("which ldd").toString().trim();
return readFileSync(lddPath, "utf8").includes("musl");
} catch (e) {
return true;
}
Expand Down Expand Up @@ -95,6 +102,15 @@ switch (platform) {
}
break;
case "darwin":
localFileExisted = existsSync(join(__dirname, "sdk-napi.darwin-universal.node"));
try {
if (localFileExisted) {
nativeBinding = require("./sdk-napi.darwin-universal.node");
} else {
nativeBinding = require("@bitwarden/sdk-napi-darwin-universal");
}
break;
} catch {}
switch (arch) {
case "x64":
localFileExisted = existsSync(join(__dirname, "sdk-napi.darwin-x64.node"));
Expand Down Expand Up @@ -192,12 +208,62 @@ switch (platform) {
}
break;
case "arm":
localFileExisted = existsSync(join(__dirname, "sdk-napi.linux-arm-gnueabihf.node"));
if (isMusl()) {
localFileExisted = existsSync(join(__dirname, "sdk-napi.linux-arm-musleabihf.node"));
try {
if (localFileExisted) {
nativeBinding = require("./sdk-napi.linux-arm-musleabihf.node");
} else {
nativeBinding = require("@bitwarden/sdk-napi-linux-arm-musleabihf");
}
} catch (e) {
loadError = e;
}
} else {
localFileExisted = existsSync(join(__dirname, "sdk-napi.linux-arm-gnueabihf.node"));
try {
if (localFileExisted) {
nativeBinding = require("./sdk-napi.linux-arm-gnueabihf.node");
} else {
nativeBinding = require("@bitwarden/sdk-napi-linux-arm-gnueabihf");
}
} catch (e) {
loadError = e;
}
}
break;
case "riscv64":
if (isMusl()) {
localFileExisted = existsSync(join(__dirname, "sdk-napi.linux-riscv64-musl.node"));
try {
if (localFileExisted) {
nativeBinding = require("./sdk-napi.linux-riscv64-musl.node");
} else {
nativeBinding = require("@bitwarden/sdk-napi-linux-riscv64-musl");
}
} catch (e) {
loadError = e;
}
} else {
localFileExisted = existsSync(join(__dirname, "sdk-napi.linux-riscv64-gnu.node"));
try {
if (localFileExisted) {
nativeBinding = require("./sdk-napi.linux-riscv64-gnu.node");
} else {
nativeBinding = require("@bitwarden/sdk-napi-linux-riscv64-gnu");
}
} catch (e) {
loadError = e;
}
}
break;
case "s390x":
localFileExisted = existsSync(join(__dirname, "sdk-napi.linux-s390x-gnu.node"));
try {
if (localFileExisted) {
nativeBinding = require("./sdk-napi.linux-arm-gnueabihf.node");
nativeBinding = require("./sdk-napi.linux-s390x-gnu.node");
} else {
nativeBinding = require("@bitwarden/sdk-napi-linux-arm-gnueabihf");
nativeBinding = require("@bitwarden/sdk-napi-linux-s390x-gnu");
}
} catch (e) {
loadError = e;
Expand Down
211 changes: 2 additions & 209 deletions crates/bitwarden-napi/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions crates/bitwarden-napi/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,8 @@
"version": "napi version"
},
"devDependencies": {
"@napi-rs/cli": "^2.13.2",
"ts-node": "10.9.2",
"typescript": "^5.0.0"
"@napi-rs/cli": "2.18.4",
"typescript": "5.5.4"
},
"engines": {
"node": ">= 10"
Expand Down
Loading

0 comments on commit 3621c25

Please sign in to comment.