Skip to content

Commit 3621c25

Browse files
authored
[SM-1394] Update NAPI language bindings (#934)
## 🎟️ 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.
1 parent 6e65f97 commit 3621c25

File tree

6 files changed

+210
-262
lines changed

6 files changed

+210
-262
lines changed

Diff for: crates/bitwarden-napi/README.md

+1-4
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,7 @@ const accessToken = "-- REDACTED --";
2121
const client = new BitwardenClient(settings, LogLevel.Info);
2222

2323
// Authenticating using a machine account access token
24-
const result = await client.loginWithAccessToken(accessToken);
25-
if (!result.success) {
26-
throw Error("Authentication failed");
27-
}
24+
await client.accessTokenLogin(accessToken);
2825

2926
// List secrets
3027
const secrets = await client.secrets().list();

Diff for: crates/bitwarden-napi/binding.d.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export const enum LogLevel {
1010
Warn = 3,
1111
Error = 4,
1212
}
13-
export class BitwardenClient {
13+
export declare class BitwardenClient {
1414
constructor(settingsInput?: string | undefined | null, logLevel?: LogLevel | undefined | null);
1515
runCommand(commandInput: string): Promise<string>;
1616
}

Diff for: crates/bitwarden-napi/binding.js

+71-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1-
const { existsSync, readFileSync } = require("fs");
1+
/* tslint:disable */
2+
/* eslint-disable */
3+
/* prettier-ignore */
4+
5+
/* auto-generated by NAPI-RS */
6+
7+
const { existsSync, readFileSync } = require('fs')
28
const { join } = require("path");
39

410
const { platform, arch } = process;
@@ -11,7 +17,8 @@ function isMusl() {
1117
// For Node 10
1218
if (!process.report || typeof process.report.getReport !== "function") {
1319
try {
14-
return readFileSync("/usr/bin/ldd", "utf8").includes("musl");
20+
const lddPath = require("child_process").execSync("which ldd").toString().trim();
21+
return readFileSync(lddPath, "utf8").includes("musl");
1522
} catch (e) {
1623
return true;
1724
}
@@ -95,6 +102,15 @@ switch (platform) {
95102
}
96103
break;
97104
case "darwin":
105+
localFileExisted = existsSync(join(__dirname, "sdk-napi.darwin-universal.node"));
106+
try {
107+
if (localFileExisted) {
108+
nativeBinding = require("./sdk-napi.darwin-universal.node");
109+
} else {
110+
nativeBinding = require("@bitwarden/sdk-napi-darwin-universal");
111+
}
112+
break;
113+
} catch {}
98114
switch (arch) {
99115
case "x64":
100116
localFileExisted = existsSync(join(__dirname, "sdk-napi.darwin-x64.node"));
@@ -192,12 +208,62 @@ switch (platform) {
192208
}
193209
break;
194210
case "arm":
195-
localFileExisted = existsSync(join(__dirname, "sdk-napi.linux-arm-gnueabihf.node"));
211+
if (isMusl()) {
212+
localFileExisted = existsSync(join(__dirname, "sdk-napi.linux-arm-musleabihf.node"));
213+
try {
214+
if (localFileExisted) {
215+
nativeBinding = require("./sdk-napi.linux-arm-musleabihf.node");
216+
} else {
217+
nativeBinding = require("@bitwarden/sdk-napi-linux-arm-musleabihf");
218+
}
219+
} catch (e) {
220+
loadError = e;
221+
}
222+
} else {
223+
localFileExisted = existsSync(join(__dirname, "sdk-napi.linux-arm-gnueabihf.node"));
224+
try {
225+
if (localFileExisted) {
226+
nativeBinding = require("./sdk-napi.linux-arm-gnueabihf.node");
227+
} else {
228+
nativeBinding = require("@bitwarden/sdk-napi-linux-arm-gnueabihf");
229+
}
230+
} catch (e) {
231+
loadError = e;
232+
}
233+
}
234+
break;
235+
case "riscv64":
236+
if (isMusl()) {
237+
localFileExisted = existsSync(join(__dirname, "sdk-napi.linux-riscv64-musl.node"));
238+
try {
239+
if (localFileExisted) {
240+
nativeBinding = require("./sdk-napi.linux-riscv64-musl.node");
241+
} else {
242+
nativeBinding = require("@bitwarden/sdk-napi-linux-riscv64-musl");
243+
}
244+
} catch (e) {
245+
loadError = e;
246+
}
247+
} else {
248+
localFileExisted = existsSync(join(__dirname, "sdk-napi.linux-riscv64-gnu.node"));
249+
try {
250+
if (localFileExisted) {
251+
nativeBinding = require("./sdk-napi.linux-riscv64-gnu.node");
252+
} else {
253+
nativeBinding = require("@bitwarden/sdk-napi-linux-riscv64-gnu");
254+
}
255+
} catch (e) {
256+
loadError = e;
257+
}
258+
}
259+
break;
260+
case "s390x":
261+
localFileExisted = existsSync(join(__dirname, "sdk-napi.linux-s390x-gnu.node"));
196262
try {
197263
if (localFileExisted) {
198-
nativeBinding = require("./sdk-napi.linux-arm-gnueabihf.node");
264+
nativeBinding = require("./sdk-napi.linux-s390x-gnu.node");
199265
} else {
200-
nativeBinding = require("@bitwarden/sdk-napi-linux-arm-gnueabihf");
266+
nativeBinding = require("@bitwarden/sdk-napi-linux-s390x-gnu");
201267
}
202268
} catch (e) {
203269
loadError = e;

Diff for: crates/bitwarden-napi/package-lock.json

+2-209
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: crates/bitwarden-napi/package.json

+2-3
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,8 @@
2929
"version": "napi version"
3030
},
3131
"devDependencies": {
32-
"@napi-rs/cli": "^2.13.2",
33-
"ts-node": "10.9.2",
34-
"typescript": "^5.0.0"
32+
"@napi-rs/cli": "2.18.4",
33+
"typescript": "5.5.4"
3534
},
3635
"engines": {
3736
"node": ">= 10"

0 commit comments

Comments
 (0)