Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weโ€™ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SM-1394] Update NAPI language bindings #934

Merged
merged 6 commits into from
Aug 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading