🎩 You're Invited:Meet the Socket team at Black Hat in Las Vegas, August 3-6.RSVP
Sign In

@bitwarden/sdk-napi

Package Overview
Dependencies
Maintainers
3
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@bitwarden/sdk-napi - npm Package Compare versions

Comparing version
0.1.2
to
0.1.3
+9
-11
package.json
{
"name": "@bitwarden/sdk-napi",
"version": "0.1.2",
"version": "0.1.3",
"license": "MIT",

@@ -22,3 +22,7 @@ "main": "./dist/index.js",

"name": "sdk-napi",
"triples": {}
"triples": {
"additional": [
"aarch64-apple-darwin"
]
}
},

@@ -32,13 +36,7 @@ "publishConfig": {

"tsc": "tsc",
"build-arm64": "napi build --target aarch64-apple-darwin --platform --release --js binding.js --dts binding.d.ts && tsc",
"build": "napi build --platform --release --js binding.js --dts binding.d.ts && tsc",
"build:debug": "napi build --platform",
"version": "napi version",
"prepublishOnly": "napi prepublish --skip-gh-release",
"publish": "napi prepublish --skip-gh-release && npm publish --access public"
},
"optionalDependencies": {
"@bitwarden/sdk-napi-win32-x64-msvc": "0.1.2",
"@bitwarden/sdk-napi-darwin-x64": "0.1.2",
"@bitwarden/sdk-napi-linux-x64-gnu": "0.1.2"
"version": "napi version"
}
}
}
+24
-37

@@ -1,47 +0,34 @@

## Bitwarden-napi crate
## Bitwarden Secrets Manager SDK
This crate is used to create a complied Node.js package for the Bitwarden SDK using the NAPI-RS framework.
Node-API bindings for interacting with the Bitwarden Secrets Manager. This is a beta release and
might be missing some functionality.
This was created using the [napi new command](https://napi.rs/docs/introduction/simple-package)
## Getting started
### Move to the bitwarden-napi directory
```ts
import { BitwardenClient, ClientSettings, DeviceType, LogLevel } from "@bitwarden/sdk-napi";
```bash
cd ./crates/bitwarden-napi
```
// Optional settings
const settings: ClientSettings = {
api_url: "https://api.bitwarden.com",
identity_url: "https://identity.bitwarden.com",
user_agent: "Bitwarden SDK",
device_type: DeviceType.SDK,
};
### Install the npm dependencies (note node needs to be installed)
const accessToken = "-- REDACTED --";
```bash
npm install
```
const client = new BitwardenClient(settings, LogLevel.Info);
### Build
// Authenticating using a service accounts access token
const result = await client.loginWithAccessToken(accessToken);
if (!result.success) {
throw Error("Authentication failed");
}
```bash
npm run build
// List secrets
const secrets = await client.secrets().list();
// Get a specific secret
const secret = await client.secrets().get("secret-id");
```
In the ./crates/bitwarden-napi directory three files will be generated:
- `sdk-napi.*.node`
- `binding.js`
- `binding.d.ts`
The `sdk-napi.*.node` is a Node.js addon binary file, for the current running operating system.
For example on an M1 MacBook `sdk-napi.darwin-arm64.node` will be generated.
The `binding.js` is the generated JavaScript binding file which helps export the addon to the package caller.
The `binding.d.ts` is the generated TypeScript definition file used for TypeScript definitions for the package caller.
### Package
- `binding` files
- TypeScript source files `./src/bitwarden_client`
- JS and TypeScript definition files `./lib/bitwarden_client`
Make up the entire NPM package bundled together and defined in `index.js` and `index.d.ts`.
import * as rust from "../../binding";
import { LogLevel } from "../../binding";
import { ClientSettings, ResponseForAPIKeyLoginResponse, ResponseForPasswordLoginResponse, ResponseForSecretIdentifiersResponse, ResponseForSecretResponse, ResponseForSecretsDeleteResponse, ResponseForSyncResponse, ResponseForUserAPIKeyResponse } from "./schemas";
export declare class BitwardenClient {
client: rust.BitwardenClient;
constructor(settings?: ClientSettings, logging_level?: LogLevel);
login(email: string, password: string): Promise<ResponseForPasswordLoginResponse>;
loginWithAccessToken(accessToken: string): Promise<ResponseForAPIKeyLoginResponse>;
getUserApiKey(secret: string, isOtp?: boolean): Promise<ResponseForUserAPIKeyResponse>;
sync(exclude_subdomains?: boolean): Promise<ResponseForSyncResponse>;
secrets(): SecretsClient;
}
export declare class SecretsClient {
client: rust.BitwardenClient;
constructor(client: rust.BitwardenClient);
get(id: string): Promise<ResponseForSecretResponse>;
create(key: string, note: string, organization_id: string, value: string): Promise<ResponseForSecretResponse>;
list(organization_id: string): Promise<ResponseForSecretIdentifiersResponse>;
update(id: string, key: string, note: string, organization_id: string, value: string): Promise<ResponseForSecretResponse>;
delete(ids: string[]): Promise<ResponseForSecretsDeleteResponse>;
}
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.SecretsClient = exports.BitwardenClient = void 0;
const rust = __importStar(require("../../binding"));
const schemas_1 = require("./schemas");
class BitwardenClient {
constructor(settings, logging_level) {
const settings_json = settings == null ? null : schemas_1.Convert.clientSettingsToJson(settings);
this.client = new rust.BitwardenClient(settings_json, logging_level !== null && logging_level !== void 0 ? logging_level : 2 /* LogLevel.Info */);
}
login(email, password) {
return __awaiter(this, void 0, void 0, function* () {
const response = yield this.client.runCommand(schemas_1.Convert.commandToJson({
PasswordLogin: {
email: email,
password: password,
},
}));
return schemas_1.Convert.toResponseForPasswordLoginResponse(response);
});
}
loginWithAccessToken(accessToken) {
return __awaiter(this, void 0, void 0, function* () {
const commandInput = schemas_1.Convert.commandToJson({
AccessTokenLogin: {
access_token: accessToken,
},
});
const response = yield this.client.runCommand(commandInput);
return schemas_1.Convert.toResponseForAPIKeyLoginResponse(response);
});
}
getUserApiKey(secret, isOtp = false) {
return __awaiter(this, void 0, void 0, function* () {
const response = yield this.client.runCommand(schemas_1.Convert.commandToJson({
GetUserApiKey: {
master_password: isOtp ? null : secret,
otp: isOtp ? secret : null,
},
}));
return schemas_1.Convert.toResponseForUserAPIKeyResponse(response);
});
}
sync(exclude_subdomains = false) {
return __awaiter(this, void 0, void 0, function* () {
const response = yield this.client.runCommand(schemas_1.Convert.commandToJson({
Sync: {
exclude_subdomains,
},
}));
return schemas_1.Convert.toResponseForSyncResponse(response);
});
}
secrets() {
return new SecretsClient(this.client);
}
}
exports.BitwardenClient = BitwardenClient;
class SecretsClient {
constructor(client) {
this.client = client;
}
get(id) {
return __awaiter(this, void 0, void 0, function* () {
const response = yield this.client.runCommand(schemas_1.Convert.commandToJson({
Secrets: {
Get: { id },
},
}));
return schemas_1.Convert.toResponseForSecretResponse(response);
});
}
create(key, note, organization_id, value) {
return __awaiter(this, void 0, void 0, function* () {
const response = yield this.client.runCommand(schemas_1.Convert.commandToJson({
Secrets: {
Create: { key, note, organization_id, value },
},
}));
return schemas_1.Convert.toResponseForSecretResponse(response);
});
}
list(organization_id) {
return __awaiter(this, void 0, void 0, function* () {
const response = yield this.client.runCommand(schemas_1.Convert.commandToJson({
Secrets: {
List: { organization_id },
},
}));
return schemas_1.Convert.toResponseForSecretIdentifiersResponse(response);
});
}
update(id, key, note, organization_id, value) {
return __awaiter(this, void 0, void 0, function* () {
const response = yield this.client.runCommand(schemas_1.Convert.commandToJson({
Secrets: {
Update: { id, key, note, organization_id, value },
},
}));
return schemas_1.Convert.toResponseForSecretResponse(response);
});
}
delete(ids) {
return __awaiter(this, void 0, void 0, function* () {
const response = yield this.client.runCommand(schemas_1.Convert.commandToJson({
Secrets: {
Delete: { ids },
},
}));
return schemas_1.Convert.toResponseForSecretsDeleteResponse(response);
});
}
}
exports.SecretsClient = SecretsClient;
/**
* Basic client behavior settings. These settings specify the various targets and behavior
* of the Bitwarden Client. They are optional and uneditable once the client is
* initialized.
*
* Defaults to
*
* ``` # use bitwarden::sdk::request::client_settings::{ClientSettings, DeviceType}; # use
* assert_matches::assert_matches; let settings = ClientSettings { identity_url:
* "https://identity.bitwarden.com".to_string(), api_url:
* "https://api.bitwarden.com".to_string(), user_agent: "Bitwarden Rust-SDK".to_string(),
* device_type: DeviceType::SDK, }; let default = ClientSettings::default();
* assert_matches!(settings, default); ```
*
* Targets `localhost:8080` for debug builds.
*/
export interface ClientSettings {
/**
* The api url of the targeted Bitwarden instance. Defaults to `https://api.bitwarden.com`
*/
api_url: string;
/**
* Device type to send to Bitwarden. Defaults to SDK
*/
device_type: DeviceType;
/**
* The identity url of the targeted Bitwarden instance. Defaults to
* `https://identity.bitwarden.com`
*/
identity_url: string;
/**
* The user_agent to sent to Bitwarden. Defaults to `Bitwarden Rust-SDK`
*/
user_agent: string;
}
/**
* Device type to send to Bitwarden. Defaults to SDK
*/
export declare enum DeviceType {
Android = "Android",
AndroidAmazon = "AndroidAmazon",
ChromeBrowser = "ChromeBrowser",
ChromeExtension = "ChromeExtension",
EdgeBrowser = "EdgeBrowser",
EdgeExtension = "EdgeExtension",
FirefoxBrowser = "FirefoxBrowser",
FirefoxExtension = "FirefoxExtension",
IEBrowser = "IEBrowser",
IOS = "iOS",
LinuxDesktop = "LinuxDesktop",
MACOSDesktop = "MacOsDesktop",
OperaBrowser = "OperaBrowser",
OperaExtension = "OperaExtension",
SDK = "SDK",
SafariBrowser = "SafariBrowser",
SafariExtension = "SafariExtension",
UWP = "UWP",
UnknownBrowser = "UnknownBrowser",
VivaldiBrowser = "VivaldiBrowser",
VivaldiExtension = "VivaldiExtension",
WindowsDesktop = "WindowsDesktop"
}
/**
* Login with username and password
*
* This command is for initiating an authentication handshake with Bitwarden. Authorization
* may fail due to requiring 2fa or captcha challenge completion despite accurate
* credentials.
*
* This command is not capable of handling authentication requiring 2fa or captcha.
*
* Returns: [PasswordLoginResponse](crate::sdk::auth::response::PasswordLoginResponse)
*
* Login with API Key
*
* This command is for initiating an authentication handshake with Bitwarden.
*
* Returns: [ApiKeyLoginResponse](crate::sdk::auth::response::ApiKeyLoginResponse)
*
* Login with Secrets Manager Access Token
*
* This command is for initiating an authentication handshake with Bitwarden.
*
* Returns: [ApiKeyLoginResponse](crate::sdk::auth::response::ApiKeyLoginResponse)
*
* > Requires Authentication Get the API key of the currently authenticated user
*
* Returns:
* [UserApiKeyResponse](crate::sdk::response::user_api_key_response::UserApiKeyResponse)
*
* > Requires Authentication Retrieve all user data, ciphers and organizations the user is a
* part of
*
* Returns: [SyncResponse](crate::sdk::response::sync_response::SyncResponse)
*/
export interface Command {
PasswordLogin?: PasswordLoginRequest;
ApiKeyLogin?: APIKeyLoginRequest;
AccessTokenLogin?: AccessTokenLoginRequest;
GetUserApiKey?: SecretVerificationRequest;
Sync?: SyncRequest;
Secrets?: SecretsCommand;
Projects?: ProjectsCommand;
}
/**
* Login to Bitwarden with access token
*/
export interface AccessTokenLoginRequest {
/**
* Bitwarden service API access token
*/
access_token: string;
}
/**
* Login to Bitwarden with Api Key
*/
export interface APIKeyLoginRequest {
/**
* Bitwarden account client_id
*/
client_id: string;
/**
* Bitwarden account client_secret
*/
client_secret: string;
/**
* Bitwarden account master password
*/
password: string;
}
export interface SecretVerificationRequest {
/**
* The user's master password to use for user verification. If supplied, this will be used
* for verification purposes.
*/
master_password?: null | string;
/**
* Alternate user verification method through OTP. This is provided for users who have no
* master password due to use of Customer Managed Encryption. Must be present and valid if
* master_password is absent.
*/
otp?: null | string;
}
/**
* Login to Bitwarden with Username and Password
*/
export interface PasswordLoginRequest {
/**
* Bitwarden account email address
*/
email: string;
/**
* Bitwarden account master password
*/
password: string;
}
/**
* > Requires Authentication > Requires using an Access Token for login or calling Sync at
* least once Retrieve a project by the provided identifier
*
* Returns: [ProjectResponse](crate::sdk::response::projects_response::ProjectResponse)
*
* > Requires Authentication > Requires using an Access Token for login or calling Sync at
* least once Lists all projects of the given organization
*
* Returns: [ProjectsResponse](crate::sdk::response::projects_response::ProjectsResponse)
*/
export interface ProjectsCommand {
Get?: ProjectGetRequest;
List?: ProjectsListRequest;
}
export interface ProjectGetRequest {
/**
* ID of the project to retrieve
*/
id: string;
}
export interface ProjectsListRequest {
/**
* Organization to retrieve all the projects from
*/
organization_id: string;
}
/**
* > Requires Authentication > Requires using an Access Token for login or calling Sync at
* least once Retrieve a secret by the provided identifier
*
* Returns: [SecretResponse](crate::sdk::response::secrets_response::SecretResponse)
*
* > Requires Authentication > Requires using an Access Token for login or calling Sync at
* least once Creates a new secret in the provided organization using the given data
*
* Returns: [SecretResponse](crate::sdk::response::secrets_response::SecretResponse)
*
* > Requires Authentication > Requires using an Access Token for login or calling Sync at
* least once Lists all secret identifiers of the given organization, to then retrieve each
* secret, use `CreateSecret`
*
* Returns:
* [SecretIdentifiersResponse](crate::sdk::response::secrets_response::SecretIdentifiersResponse)
*
* > Requires Authentication > Requires using an Access Token for login or calling Sync at
* least once Updates an existing secret with the provided ID using the given data
*
* Returns: [SecretResponse](crate::sdk::response::secrets_response::SecretResponse)
*
* > Requires Authentication > Requires using an Access Token for login or calling Sync at
* least once Deletes all the secrets whose IDs match the provided ones
*
* Returns:
* [SecretsDeleteResponse](crate::sdk::response::secrets_response::SecretsDeleteResponse)
*/
export interface SecretsCommand {
Get?: SecretGetRequest;
Create?: SecretCreateRequest;
List?: SecretIdentifiersRequest;
Update?: SecretPutRequest;
Delete?: SecretsDeleteRequest;
}
export interface SecretCreateRequest {
key: string;
note: string;
/**
* Organization where the secret will be created
*/
organization_id: string;
value: string;
}
export interface SecretsDeleteRequest {
/**
* IDs of the secrets to delete
*/
ids: string[];
}
export interface SecretGetRequest {
/**
* ID of the secret to retrieve
*/
id: string;
}
export interface SecretIdentifiersRequest {
/**
* Organization to retrieve all the secrets from
*/
organization_id: string;
}
export interface SecretPutRequest {
/**
* ID of the secret to modify
*/
id: string;
key: string;
note: string;
/**
* Organization ID of the secret to modify
*/
organization_id: string;
value: string;
}
export interface SyncRequest {
/**
* Exclude the subdomains from the response, defaults to false
*/
exclude_subdomains?: boolean | null;
}
export interface ResponseForAPIKeyLoginResponse {
/**
* The response data. Populated if `success` is true.
*/
data?: null | APIKeyLoginResponse;
/**
* A message for any error that may occur. Populated if `success` is false.
*/
error_message?: null | string;
/**
* Whether or not the SDK request succeeded.
*/
success: boolean;
}
export interface APIKeyLoginResponse {
authenticated: boolean;
/**
* Whether or not the user is required to update their master password
*/
force_password_reset: boolean;
/**
* TODO: What does this do?
*/
reset_master_password: boolean;
two_factor?: null | APIKeyLoginResponseTwoFactorProviders;
}
export interface APIKeyLoginResponseTwoFactorProviders {
authenticator?: {
[key: string]: any;
} | null;
/**
* Duo-backed 2fa
*/
duo?: null | PurpleDuo;
/**
* Email 2fa
*/
email?: null | PurpleEmail;
/**
* Duo-backed 2fa operated by an organization the user is a member of
*/
organization_duo?: null | PurpleDuo;
/**
* Presence indicates the user has stored this device as bypassing 2fa
*/
remember?: {
[key: string]: any;
} | null;
/**
* WebAuthn-backed 2fa
*/
web_authn?: {
[key: string]: any;
} | null;
/**
* Yubikey-backed 2fa
*/
yubi_key?: null | PurpleYubiKey;
}
export interface PurpleDuo {
host: string;
signature: string;
}
export interface PurpleEmail {
/**
* The email to request a 2fa TOTP for
*/
email: string;
}
export interface PurpleYubiKey {
/**
* Whether the stored yubikey supports near field communication
*/
nfc: boolean;
}
export interface ResponseForPasswordLoginResponse {
/**
* The response data. Populated if `success` is true.
*/
data?: null | PasswordLoginResponse;
/**
* A message for any error that may occur. Populated if `success` is false.
*/
error_message?: null | string;
/**
* Whether or not the SDK request succeeded.
*/
success: boolean;
}
export interface PasswordLoginResponse {
authenticated: boolean;
/**
* The information required to present the user with a captcha challenge. Only present when
* authentication fails due to requiring validation of a captcha challenge.
*/
captcha?: null | CAPTCHAResponse;
/**
* Whether or not the user is required to update their master password
*/
force_password_reset: boolean;
/**
* TODO: What does this do?
*/
reset_master_password: boolean;
/**
* The available two factor authentication options. Present only when authentication fails
* due to requiring a second authentication factor.
*/
two_factor?: null | PasswordLoginResponseTwoFactorProviders;
}
export interface CAPTCHAResponse {
/**
* hcaptcha site key
*/
site_key: string;
}
export interface PasswordLoginResponseTwoFactorProviders {
authenticator?: {
[key: string]: any;
} | null;
/**
* Duo-backed 2fa
*/
duo?: null | FluffyDuo;
/**
* Email 2fa
*/
email?: null | FluffyEmail;
/**
* Duo-backed 2fa operated by an organization the user is a member of
*/
organization_duo?: null | FluffyDuo;
/**
* Presence indicates the user has stored this device as bypassing 2fa
*/
remember?: {
[key: string]: any;
} | null;
/**
* WebAuthn-backed 2fa
*/
web_authn?: {
[key: string]: any;
} | null;
/**
* Yubikey-backed 2fa
*/
yubi_key?: null | FluffyYubiKey;
}
export interface FluffyDuo {
host: string;
signature: string;
}
export interface FluffyEmail {
/**
* The email to request a 2fa TOTP for
*/
email: string;
}
export interface FluffyYubiKey {
/**
* Whether the stored yubikey supports near field communication
*/
nfc: boolean;
}
export interface ResponseForSecretDeleteResponse {
/**
* The response data. Populated if `success` is true.
*/
data?: null | SecretDeleteResponse;
/**
* A message for any error that may occur. Populated if `success` is false.
*/
error_message?: null | string;
/**
* Whether or not the SDK request succeeded.
*/
success: boolean;
}
export interface SecretDeleteResponse {
error?: null | string;
id: string;
}
export interface ResponseForSecretIdentifierResponse {
/**
* The response data. Populated if `success` is true.
*/
data?: null | SecretIdentifierResponse;
/**
* A message for any error that may occur. Populated if `success` is false.
*/
error_message?: null | string;
/**
* Whether or not the SDK request succeeded.
*/
success: boolean;
}
export interface SecretIdentifierResponse {
id: string;
key: string;
organization_id: string;
}
export interface ResponseForSecretIdentifiersResponse {
/**
* The response data. Populated if `success` is true.
*/
data?: null | SecretIdentifiersResponse;
/**
* A message for any error that may occur. Populated if `success` is false.
*/
error_message?: null | string;
/**
* Whether or not the SDK request succeeded.
*/
success: boolean;
}
export interface SecretIdentifiersResponse {
data: DatumElement[];
}
export interface DatumElement {
id: string;
key: string;
organization_id: string;
}
export interface ResponseForSecretResponse {
/**
* The response data. Populated if `success` is true.
*/
data?: null | SecretResponse;
/**
* A message for any error that may occur. Populated if `success` is false.
*/
error_message?: null | string;
/**
* Whether or not the SDK request succeeded.
*/
success: boolean;
}
export interface SecretResponse {
creation_date: string;
id: string;
key: string;
note: string;
object: string;
organization_id: string;
project_id?: null | string;
revision_date: string;
value: string;
}
export interface ResponseForSecretsDeleteResponse {
/**
* The response data. Populated if `success` is true.
*/
data?: null | SecretsDeleteResponse;
/**
* A message for any error that may occur. Populated if `success` is false.
*/
error_message?: null | string;
/**
* Whether or not the SDK request succeeded.
*/
success: boolean;
}
export interface SecretsDeleteResponse {
data: DatumObject[];
}
export interface DatumObject {
error?: null | string;
id: string;
}
export interface ResponseForSyncResponse {
/**
* The response data. Populated if `success` is true.
*/
data?: null | SyncResponse;
/**
* A message for any error that may occur. Populated if `success` is false.
*/
error_message?: null | string;
/**
* Whether or not the SDK request succeeded.
*/
success: boolean;
}
export interface SyncResponse {
/**
* List of ciphers accesible by the user
*/
ciphers: {
[key: string]: any;
}[];
/**
* Data about the user, including their encryption keys and the organizations they are a
* part of
*/
profile: ProfileResponse;
}
/**
* Data about the user, including their encryption keys and the organizations they are a
* part of
*/
export interface ProfileResponse {
email: string;
id: string;
name: string;
organizations: ProfileOrganizationResponse[];
}
export interface ProfileOrganizationResponse {
id: string;
}
export interface ResponseForUserAPIKeyResponse {
/**
* The response data. Populated if `success` is true.
*/
data?: null | UserAPIKeyResponse;
/**
* A message for any error that may occur. Populated if `success` is false.
*/
error_message?: null | string;
/**
* Whether or not the SDK request succeeded.
*/
success: boolean;
}
export interface UserAPIKeyResponse {
/**
* The user's API key, which represents the client_secret portion of an oauth request.
*/
api_key: string;
}
export declare class Convert {
static toClientSettings(json: string): ClientSettings;
static clientSettingsToJson(value: ClientSettings): string;
static toCommand(json: string): Command;
static commandToJson(value: Command): string;
static toResponseForAPIKeyLoginResponse(json: string): ResponseForAPIKeyLoginResponse;
static responseForAPIKeyLoginResponseToJson(value: ResponseForAPIKeyLoginResponse): string;
static toResponseForPasswordLoginResponse(json: string): ResponseForPasswordLoginResponse;
static responseForPasswordLoginResponseToJson(value: ResponseForPasswordLoginResponse): string;
static toResponseForSecretDeleteResponse(json: string): ResponseForSecretDeleteResponse;
static responseForSecretDeleteResponseToJson(value: ResponseForSecretDeleteResponse): string;
static toResponseForSecretIdentifierResponse(json: string): ResponseForSecretIdentifierResponse;
static responseForSecretIdentifierResponseToJson(value: ResponseForSecretIdentifierResponse): string;
static toResponseForSecretIdentifiersResponse(json: string): ResponseForSecretIdentifiersResponse;
static responseForSecretIdentifiersResponseToJson(value: ResponseForSecretIdentifiersResponse): string;
static toResponseForSecretResponse(json: string): ResponseForSecretResponse;
static responseForSecretResponseToJson(value: ResponseForSecretResponse): string;
static toResponseForSecretsDeleteResponse(json: string): ResponseForSecretsDeleteResponse;
static responseForSecretsDeleteResponseToJson(value: ResponseForSecretsDeleteResponse): string;
static toResponseForSyncResponse(json: string): ResponseForSyncResponse;
static responseForSyncResponseToJson(value: ResponseForSyncResponse): string;
static toResponseForUserAPIKeyResponse(json: string): ResponseForUserAPIKeyResponse;
static responseForUserAPIKeyResponseToJson(value: ResponseForUserAPIKeyResponse): string;
}
"use strict";
// To parse this data:
//
// import { Convert, ClientSettings, Command, ResponseForAPIKeyLoginResponse, ResponseForPasswordLoginResponse, ResponseForSecretDeleteResponse, ResponseForSecretIdentifierResponse, ResponseForSecretIdentifiersResponse, ResponseForSecretResponse, ResponseForSecretsDeleteResponse, ResponseForSyncResponse, ResponseForUserAPIKeyResponse } from "./file";
//
// const clientSettings = Convert.toClientSettings(json);
// const command = Convert.toCommand(json);
// const responseForAPIKeyLoginResponse = Convert.toResponseForAPIKeyLoginResponse(json);
// const responseForPasswordLoginResponse = Convert.toResponseForPasswordLoginResponse(json);
// const responseForSecretDeleteResponse = Convert.toResponseForSecretDeleteResponse(json);
// const responseForSecretIdentifierResponse = Convert.toResponseForSecretIdentifierResponse(json);
// const responseForSecretIdentifiersResponse = Convert.toResponseForSecretIdentifiersResponse(json);
// const responseForSecretResponse = Convert.toResponseForSecretResponse(json);
// const responseForSecretsDeleteResponse = Convert.toResponseForSecretsDeleteResponse(json);
// const responseForSyncResponse = Convert.toResponseForSyncResponse(json);
// const responseForUserAPIKeyResponse = Convert.toResponseForUserAPIKeyResponse(json);
//
// These functions will throw an error if the JSON doesn't
// match the expected interface, even if the JSON is valid.
Object.defineProperty(exports, "__esModule", { value: true });
exports.Convert = exports.DeviceType = void 0;
/**
* Device type to send to Bitwarden. Defaults to SDK
*/
var DeviceType;
(function (DeviceType) {
DeviceType["Android"] = "Android";
DeviceType["AndroidAmazon"] = "AndroidAmazon";
DeviceType["ChromeBrowser"] = "ChromeBrowser";
DeviceType["ChromeExtension"] = "ChromeExtension";
DeviceType["EdgeBrowser"] = "EdgeBrowser";
DeviceType["EdgeExtension"] = "EdgeExtension";
DeviceType["FirefoxBrowser"] = "FirefoxBrowser";
DeviceType["FirefoxExtension"] = "FirefoxExtension";
DeviceType["IEBrowser"] = "IEBrowser";
DeviceType["IOS"] = "iOS";
DeviceType["LinuxDesktop"] = "LinuxDesktop";
DeviceType["MACOSDesktop"] = "MacOsDesktop";
DeviceType["OperaBrowser"] = "OperaBrowser";
DeviceType["OperaExtension"] = "OperaExtension";
DeviceType["SDK"] = "SDK";
DeviceType["SafariBrowser"] = "SafariBrowser";
DeviceType["SafariExtension"] = "SafariExtension";
DeviceType["UWP"] = "UWP";
DeviceType["UnknownBrowser"] = "UnknownBrowser";
DeviceType["VivaldiBrowser"] = "VivaldiBrowser";
DeviceType["VivaldiExtension"] = "VivaldiExtension";
DeviceType["WindowsDesktop"] = "WindowsDesktop";
})(DeviceType = exports.DeviceType || (exports.DeviceType = {}));
// Converts JSON strings to/from your types
// and asserts the results of JSON.parse at runtime
class Convert {
static toClientSettings(json) {
return cast(JSON.parse(json), r("ClientSettings"));
}
static clientSettingsToJson(value) {
return JSON.stringify(uncast(value, r("ClientSettings")), null, 2);
}
static toCommand(json) {
return cast(JSON.parse(json), r("Command"));
}
static commandToJson(value) {
return JSON.stringify(uncast(value, r("Command")), null, 2);
}
static toResponseForAPIKeyLoginResponse(json) {
return cast(JSON.parse(json), r("ResponseForAPIKeyLoginResponse"));
}
static responseForAPIKeyLoginResponseToJson(value) {
return JSON.stringify(uncast(value, r("ResponseForAPIKeyLoginResponse")), null, 2);
}
static toResponseForPasswordLoginResponse(json) {
return cast(JSON.parse(json), r("ResponseForPasswordLoginResponse"));
}
static responseForPasswordLoginResponseToJson(value) {
return JSON.stringify(uncast(value, r("ResponseForPasswordLoginResponse")), null, 2);
}
static toResponseForSecretDeleteResponse(json) {
return cast(JSON.parse(json), r("ResponseForSecretDeleteResponse"));
}
static responseForSecretDeleteResponseToJson(value) {
return JSON.stringify(uncast(value, r("ResponseForSecretDeleteResponse")), null, 2);
}
static toResponseForSecretIdentifierResponse(json) {
return cast(JSON.parse(json), r("ResponseForSecretIdentifierResponse"));
}
static responseForSecretIdentifierResponseToJson(value) {
return JSON.stringify(uncast(value, r("ResponseForSecretIdentifierResponse")), null, 2);
}
static toResponseForSecretIdentifiersResponse(json) {
return cast(JSON.parse(json), r("ResponseForSecretIdentifiersResponse"));
}
static responseForSecretIdentifiersResponseToJson(value) {
return JSON.stringify(uncast(value, r("ResponseForSecretIdentifiersResponse")), null, 2);
}
static toResponseForSecretResponse(json) {
return cast(JSON.parse(json), r("ResponseForSecretResponse"));
}
static responseForSecretResponseToJson(value) {
return JSON.stringify(uncast(value, r("ResponseForSecretResponse")), null, 2);
}
static toResponseForSecretsDeleteResponse(json) {
return cast(JSON.parse(json), r("ResponseForSecretsDeleteResponse"));
}
static responseForSecretsDeleteResponseToJson(value) {
return JSON.stringify(uncast(value, r("ResponseForSecretsDeleteResponse")), null, 2);
}
static toResponseForSyncResponse(json) {
return cast(JSON.parse(json), r("ResponseForSyncResponse"));
}
static responseForSyncResponseToJson(value) {
return JSON.stringify(uncast(value, r("ResponseForSyncResponse")), null, 2);
}
static toResponseForUserAPIKeyResponse(json) {
return cast(JSON.parse(json), r("ResponseForUserAPIKeyResponse"));
}
static responseForUserAPIKeyResponseToJson(value) {
return JSON.stringify(uncast(value, r("ResponseForUserAPIKeyResponse")), null, 2);
}
}
exports.Convert = Convert;
function invalidValue(typ, val, key = '') {
if (key) {
throw Error(`Invalid value for key "${key}". Expected type ${JSON.stringify(typ)} but got ${JSON.stringify(val)}`);
}
throw Error(`Invalid value ${JSON.stringify(val)} for type ${JSON.stringify(typ)}`);
}
function jsonToJSProps(typ) {
if (typ.jsonToJS === undefined) {
const map = {};
typ.props.forEach((p) => map[p.json] = { key: p.js, typ: p.typ });
typ.jsonToJS = map;
}
return typ.jsonToJS;
}
function jsToJSONProps(typ) {
if (typ.jsToJSON === undefined) {
const map = {};
typ.props.forEach((p) => map[p.js] = { key: p.json, typ: p.typ });
typ.jsToJSON = map;
}
return typ.jsToJSON;
}
function transform(val, typ, getProps, key = '') {
function transformPrimitive(typ, val) {
if (typeof typ === typeof val)
return val;
return invalidValue(typ, val, key);
}
function transformUnion(typs, val) {
// val must validate against one typ in typs
const l = typs.length;
for (let i = 0; i < l; i++) {
const typ = typs[i];
try {
return transform(val, typ, getProps);
}
catch (_) { }
}
return invalidValue(typs, val);
}
function transformEnum(cases, val) {
if (cases.indexOf(val) !== -1)
return val;
return invalidValue(cases, val);
}
function transformArray(typ, val) {
// val must be an array with no invalid elements
if (!Array.isArray(val))
return invalidValue("array", val);
return val.map(el => transform(el, typ, getProps));
}
function transformDate(val) {
if (val === null) {
return null;
}
const d = new Date(val);
if (isNaN(d.valueOf())) {
return invalidValue("Date", val);
}
return d;
}
function transformObject(props, additional, val) {
if (val === null || typeof val !== "object" || Array.isArray(val)) {
return invalidValue("object", val);
}
const result = {};
Object.getOwnPropertyNames(props).forEach(key => {
const prop = props[key];
const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined;
result[prop.key] = transform(v, prop.typ, getProps, prop.key);
});
Object.getOwnPropertyNames(val).forEach(key => {
if (!Object.prototype.hasOwnProperty.call(props, key)) {
result[key] = transform(val[key], additional, getProps, key);
}
});
return result;
}
if (typ === "any")
return val;
if (typ === null) {
if (val === null)
return val;
return invalidValue(typ, val);
}
if (typ === false)
return invalidValue(typ, val);
while (typeof typ === "object" && typ.ref !== undefined) {
typ = typeMap[typ.ref];
}
if (Array.isArray(typ))
return transformEnum(typ, val);
if (typeof typ === "object") {
return typ.hasOwnProperty("unionMembers") ? transformUnion(typ.unionMembers, val)
: typ.hasOwnProperty("arrayItems") ? transformArray(typ.arrayItems, val)
: typ.hasOwnProperty("props") ? transformObject(getProps(typ), typ.additional, val)
: invalidValue(typ, val);
}
// Numbers can be parsed by Date but shouldn't be.
if (typ === Date && typeof val !== "number")
return transformDate(val);
return transformPrimitive(typ, val);
}
function cast(val, typ) {
return transform(val, typ, jsonToJSProps);
}
function uncast(val, typ) {
return transform(val, typ, jsToJSONProps);
}
function a(typ) {
return { arrayItems: typ };
}
function u(...typs) {
return { unionMembers: typs };
}
function o(props, additional) {
return { props, additional };
}
function m(additional) {
return { props: [], additional };
}
function r(name) {
return { ref: name };
}
const typeMap = {
"ClientSettings": o([
{ json: "api_url", js: "api_url", typ: "" },
{ json: "device_type", js: "device_type", typ: r("DeviceType") },
{ json: "identity_url", js: "identity_url", typ: "" },
{ json: "user_agent", js: "user_agent", typ: "" },
], "any"),
"Command": o([
{ json: "PasswordLogin", js: "PasswordLogin", typ: u(undefined, r("PasswordLoginRequest")) },
{ json: "ApiKeyLogin", js: "ApiKeyLogin", typ: u(undefined, r("APIKeyLoginRequest")) },
{ json: "AccessTokenLogin", js: "AccessTokenLogin", typ: u(undefined, r("AccessTokenLoginRequest")) },
{ json: "GetUserApiKey", js: "GetUserApiKey", typ: u(undefined, r("SecretVerificationRequest")) },
{ json: "Sync", js: "Sync", typ: u(undefined, r("SyncRequest")) },
{ json: "Secrets", js: "Secrets", typ: u(undefined, r("SecretsCommand")) },
{ json: "Projects", js: "Projects", typ: u(undefined, r("ProjectsCommand")) },
], false),
"AccessTokenLoginRequest": o([
{ json: "access_token", js: "access_token", typ: "" },
], "any"),
"APIKeyLoginRequest": o([
{ json: "client_id", js: "client_id", typ: "" },
{ json: "client_secret", js: "client_secret", typ: "" },
{ json: "password", js: "password", typ: "" },
], "any"),
"SecretVerificationRequest": o([
{ json: "master_password", js: "master_password", typ: u(undefined, u(null, "")) },
{ json: "otp", js: "otp", typ: u(undefined, u(null, "")) },
], "any"),
"PasswordLoginRequest": o([
{ json: "email", js: "email", typ: "" },
{ json: "password", js: "password", typ: "" },
], "any"),
"ProjectsCommand": o([
{ json: "Get", js: "Get", typ: u(undefined, r("ProjectGetRequest")) },
{ json: "List", js: "List", typ: u(undefined, r("ProjectsListRequest")) },
], false),
"ProjectGetRequest": o([
{ json: "id", js: "id", typ: "" },
], "any"),
"ProjectsListRequest": o([
{ json: "organization_id", js: "organization_id", typ: "" },
], "any"),
"SecretsCommand": o([
{ json: "Get", js: "Get", typ: u(undefined, r("SecretGetRequest")) },
{ json: "Create", js: "Create", typ: u(undefined, r("SecretCreateRequest")) },
{ json: "List", js: "List", typ: u(undefined, r("SecretIdentifiersRequest")) },
{ json: "Update", js: "Update", typ: u(undefined, r("SecretPutRequest")) },
{ json: "Delete", js: "Delete", typ: u(undefined, r("SecretsDeleteRequest")) },
], false),
"SecretCreateRequest": o([
{ json: "key", js: "key", typ: "" },
{ json: "note", js: "note", typ: "" },
{ json: "organization_id", js: "organization_id", typ: "" },
{ json: "value", js: "value", typ: "" },
], "any"),
"SecretsDeleteRequest": o([
{ json: "ids", js: "ids", typ: a("") },
], "any"),
"SecretGetRequest": o([
{ json: "id", js: "id", typ: "" },
], "any"),
"SecretIdentifiersRequest": o([
{ json: "organization_id", js: "organization_id", typ: "" },
], "any"),
"SecretPutRequest": o([
{ json: "id", js: "id", typ: "" },
{ json: "key", js: "key", typ: "" },
{ json: "note", js: "note", typ: "" },
{ json: "organization_id", js: "organization_id", typ: "" },
{ json: "value", js: "value", typ: "" },
], "any"),
"SyncRequest": o([
{ json: "exclude_subdomains", js: "exclude_subdomains", typ: u(undefined, u(true, null)) },
], "any"),
"ResponseForAPIKeyLoginResponse": o([
{ json: "data", js: "data", typ: u(undefined, u(null, r("APIKeyLoginResponse"))) },
{ json: "error_message", js: "error_message", typ: u(undefined, u(null, "")) },
{ json: "success", js: "success", typ: true },
], "any"),
"APIKeyLoginResponse": o([
{ json: "authenticated", js: "authenticated", typ: true },
{ json: "force_password_reset", js: "force_password_reset", typ: true },
{ json: "reset_master_password", js: "reset_master_password", typ: true },
{ json: "two_factor", js: "two_factor", typ: u(undefined, u(null, r("APIKeyLoginResponseTwoFactorProviders"))) },
], "any"),
"APIKeyLoginResponseTwoFactorProviders": o([
{ json: "authenticator", js: "authenticator", typ: u(undefined, u(m("any"), null)) },
{ json: "duo", js: "duo", typ: u(undefined, u(null, r("PurpleDuo"))) },
{ json: "email", js: "email", typ: u(undefined, u(null, r("PurpleEmail"))) },
{ json: "organization_duo", js: "organization_duo", typ: u(undefined, u(null, r("PurpleDuo"))) },
{ json: "remember", js: "remember", typ: u(undefined, u(m("any"), null)) },
{ json: "web_authn", js: "web_authn", typ: u(undefined, u(m("any"), null)) },
{ json: "yubi_key", js: "yubi_key", typ: u(undefined, u(null, r("PurpleYubiKey"))) },
], "any"),
"PurpleDuo": o([
{ json: "host", js: "host", typ: "" },
{ json: "signature", js: "signature", typ: "" },
], "any"),
"PurpleEmail": o([
{ json: "email", js: "email", typ: "" },
], "any"),
"PurpleYubiKey": o([
{ json: "nfc", js: "nfc", typ: true },
], "any"),
"ResponseForPasswordLoginResponse": o([
{ json: "data", js: "data", typ: u(undefined, u(null, r("PasswordLoginResponse"))) },
{ json: "error_message", js: "error_message", typ: u(undefined, u(null, "")) },
{ json: "success", js: "success", typ: true },
], "any"),
"PasswordLoginResponse": o([
{ json: "authenticated", js: "authenticated", typ: true },
{ json: "captcha", js: "captcha", typ: u(undefined, u(null, r("CAPTCHAResponse"))) },
{ json: "force_password_reset", js: "force_password_reset", typ: true },
{ json: "reset_master_password", js: "reset_master_password", typ: true },
{ json: "two_factor", js: "two_factor", typ: u(undefined, u(null, r("PasswordLoginResponseTwoFactorProviders"))) },
], "any"),
"CAPTCHAResponse": o([
{ json: "site_key", js: "site_key", typ: "" },
], "any"),
"PasswordLoginResponseTwoFactorProviders": o([
{ json: "authenticator", js: "authenticator", typ: u(undefined, u(m("any"), null)) },
{ json: "duo", js: "duo", typ: u(undefined, u(null, r("FluffyDuo"))) },
{ json: "email", js: "email", typ: u(undefined, u(null, r("FluffyEmail"))) },
{ json: "organization_duo", js: "organization_duo", typ: u(undefined, u(null, r("FluffyDuo"))) },
{ json: "remember", js: "remember", typ: u(undefined, u(m("any"), null)) },
{ json: "web_authn", js: "web_authn", typ: u(undefined, u(m("any"), null)) },
{ json: "yubi_key", js: "yubi_key", typ: u(undefined, u(null, r("FluffyYubiKey"))) },
], "any"),
"FluffyDuo": o([
{ json: "host", js: "host", typ: "" },
{ json: "signature", js: "signature", typ: "" },
], "any"),
"FluffyEmail": o([
{ json: "email", js: "email", typ: "" },
], "any"),
"FluffyYubiKey": o([
{ json: "nfc", js: "nfc", typ: true },
], "any"),
"ResponseForSecretDeleteResponse": o([
{ json: "data", js: "data", typ: u(undefined, u(null, r("SecretDeleteResponse"))) },
{ json: "error_message", js: "error_message", typ: u(undefined, u(null, "")) },
{ json: "success", js: "success", typ: true },
], "any"),
"SecretDeleteResponse": o([
{ json: "error", js: "error", typ: u(undefined, u(null, "")) },
{ json: "id", js: "id", typ: "" },
], "any"),
"ResponseForSecretIdentifierResponse": o([
{ json: "data", js: "data", typ: u(undefined, u(null, r("SecretIdentifierResponse"))) },
{ json: "error_message", js: "error_message", typ: u(undefined, u(null, "")) },
{ json: "success", js: "success", typ: true },
], "any"),
"SecretIdentifierResponse": o([
{ json: "id", js: "id", typ: "" },
{ json: "key", js: "key", typ: "" },
{ json: "organization_id", js: "organization_id", typ: "" },
], "any"),
"ResponseForSecretIdentifiersResponse": o([
{ json: "data", js: "data", typ: u(undefined, u(null, r("SecretIdentifiersResponse"))) },
{ json: "error_message", js: "error_message", typ: u(undefined, u(null, "")) },
{ json: "success", js: "success", typ: true },
], "any"),
"SecretIdentifiersResponse": o([
{ json: "data", js: "data", typ: a(r("DatumElement")) },
], "any"),
"DatumElement": o([
{ json: "id", js: "id", typ: "" },
{ json: "key", js: "key", typ: "" },
{ json: "organization_id", js: "organization_id", typ: "" },
], "any"),
"ResponseForSecretResponse": o([
{ json: "data", js: "data", typ: u(undefined, u(null, r("SecretResponse"))) },
{ json: "error_message", js: "error_message", typ: u(undefined, u(null, "")) },
{ json: "success", js: "success", typ: true },
], "any"),
"SecretResponse": o([
{ json: "creation_date", js: "creation_date", typ: "" },
{ json: "id", js: "id", typ: "" },
{ json: "key", js: "key", typ: "" },
{ json: "note", js: "note", typ: "" },
{ json: "object", js: "object", typ: "" },
{ json: "organization_id", js: "organization_id", typ: "" },
{ json: "project_id", js: "project_id", typ: u(undefined, u(null, "")) },
{ json: "revision_date", js: "revision_date", typ: "" },
{ json: "value", js: "value", typ: "" },
], "any"),
"ResponseForSecretsDeleteResponse": o([
{ json: "data", js: "data", typ: u(undefined, u(null, r("SecretsDeleteResponse"))) },
{ json: "error_message", js: "error_message", typ: u(undefined, u(null, "")) },
{ json: "success", js: "success", typ: true },
], "any"),
"SecretsDeleteResponse": o([
{ json: "data", js: "data", typ: a(r("DatumObject")) },
], "any"),
"DatumObject": o([
{ json: "error", js: "error", typ: u(undefined, u(null, "")) },
{ json: "id", js: "id", typ: "" },
], "any"),
"ResponseForSyncResponse": o([
{ json: "data", js: "data", typ: u(undefined, u(null, r("SyncResponse"))) },
{ json: "error_message", js: "error_message", typ: u(undefined, u(null, "")) },
{ json: "success", js: "success", typ: true },
], "any"),
"SyncResponse": o([
{ json: "ciphers", js: "ciphers", typ: a(m("any")) },
{ json: "profile", js: "profile", typ: r("ProfileResponse") },
], "any"),
"ProfileResponse": o([
{ json: "email", js: "email", typ: "" },
{ json: "id", js: "id", typ: "" },
{ json: "name", js: "name", typ: "" },
{ json: "organizations", js: "organizations", typ: a(r("ProfileOrganizationResponse")) },
], "any"),
"ProfileOrganizationResponse": o([
{ json: "id", js: "id", typ: "" },
], "any"),
"ResponseForUserAPIKeyResponse": o([
{ json: "data", js: "data", typ: u(undefined, u(null, r("UserAPIKeyResponse"))) },
{ json: "error_message", js: "error_message", typ: u(undefined, u(null, "")) },
{ json: "success", js: "success", typ: true },
], "any"),
"UserAPIKeyResponse": o([
{ json: "api_key", js: "api_key", typ: "" },
], "any"),
"DeviceType": [
"Android",
"AndroidAmazon",
"ChromeBrowser",
"ChromeExtension",
"EdgeBrowser",
"EdgeExtension",
"FirefoxBrowser",
"FirefoxExtension",
"IEBrowser",
"iOS",
"LinuxDesktop",
"MacOsDesktop",
"OperaBrowser",
"OperaExtension",
"SDK",
"SafariBrowser",
"SafariExtension",
"UWP",
"UnknownBrowser",
"VivaldiBrowser",
"VivaldiExtension",
"WindowsDesktop",
],
};