JavaScript SDK

Detailed Javascript SDK docs for Keeper Secrets Manager

Download and Installation

Install with NPM

npm install @keeper-security/secrets-manager-core

Source Code

Find the JavaScript source code in the GitHub repository

Using the SDK

Initialize Storage

Using token only to generate a new config (for later usage) requires at least one read operation to bind the token and fully populate config.json

In order to retrieve secrets, you must first initialize the local storage on your machine.

initializeStorage(storage: KeyValueStorage, clientKey: String? = null, hostName: String? = null)

Parameter

Type

Required

Default

Description

storage

KeyValueStorage

Yes

storage location

clientKey

string

Optional

null

token for connecting with Keeper Secrets Manager

hostName

string

Optional

null

server location to get secrets. If nothing is passed, will use keepersecurity.com (US)

Example Usage

Retrieve Secrets

Parameter

Type

Required

Default

Description

storage

KeyValueStorage

Yes

Storage location

recordsFilter

string[]

Optional

Empty List

Record UIDs to get

Response

Type: KeeperSecrets

Object containing all Keeper records, or records that match the given filter criteria

Example Usage

Retrieve all Secrets

Retrieve Secrets by Title

Parameter
Type
Required
Description

options

SecretsManagerOptions

Yes

Preconfigured options

recordTitle

string

Yes

Record title to search for

Example Usage

Retrieve Values From a Secret

Retrieve a Password

Field types are based on the Keeper Record Type. For a detailed list of available fields based on the Keeper Record Type, see the record-type-info command in Keeper Commander.

Retrieve other Fields with Keeper Notation

See Keeper Notation documentation to learn about Keeper Notation format and capabilities

Parameter

Type

Required

Default

Description

secrets

KeeperSecrets

Yes

Secrets to query

query

string

Yes

Keeper Notation query

* The record UID in the notation query must be for a secret passed in the secrets parameter or nothing will be found by the query

Returns

Type: any

The value of the field at the location specified by the dot notation query if any, otherwise undefined.

Retrieve a TOTP Code

See Keeper Notation documentation to learn about Keeper Notation format and capabilities

Parameter

Type

Required

Default

Description

url

string

Yes

TOTP Url

* The record UID in the notation query must be for a secret passed in the secrets parameter or nothing will be found by the query

Returns

Type: any

The value of the field at the location specified by the dot notation query if any, otherwise undefined.

Update a Secret

Parameter

Type

Required

Default

Description

options

SecretManagerOptions

Yes

record

KeeperRecord

Yes

Returns

Type: Promise<void>

Generate a Random Password

Parameter
Type
Required
Default

length

int

Optional

64

lowercase

int

Optional

0

uppercase

int

Optional

0

digits

int

Optional

0

specialCharacters

int

Optional

0

Each parameter indicates the min number of a type of character to include. For example, 'uppercase' indicates the minimum number of uppercase letters to include.

Returns

Type: String

Download a File

Parameter

Type

Required

Default

Description

file

KeeperFile

Yes

File to download

Response

Type: Promise<Uint8Array

Bytes of file for download

Download a Thumbnail

Parameter

Type

Required

Default

Description

file

KeeperFile

Yes

File with thumbnail to download

Response

Type: Promise<Uint8Array>

Bytes of thumbnail for download

Upload a File

Upload File:

Parameter
Type
Required
Description

options

SecretsManagerOptions

Yes

Storage and query configuration

ownerRecord

KeeperRecord

Yes

The record to attach the uploaded file to

file

KeeperFileUpload

Yes

The File to upload

Creating the Keeper File Upload Object:

Parameter
Type
Required
Description

name

string

Yes

What the name of the file will be in Keeper once uploaded

title

string

Yes

What the title of the file will be in Keeper once uploaded

type

string

Optional

The mime type of data in the file. 'application/octet-stream' will be used if nothing is given

data

Uint8Array

Yes

File data as bytes

Example Usage

Create a Secret

Prerequisites:

  • Shared folder UID

    • Shared folder must be accessible by the Secrets Manager Application

    • You and the Secrets Manager application must have edit permission

    • There must be at least one record in the shared folder

  • Created records and record fields must be formatted correctly

    • See the documentation for expected field formats for each record type

  • TOTP fields accept only URL generated outside of the KSM SDK

  • After record creation, you can upload file attachments using uploadFile

Parameter
Type
Required
Default

options

SecretManagerOptions

Yes

folderUid

string

Yes

record

JSON Object

Yes

Delete a Secret

The JavaScript KSM SDK can delete records in the Keeper Vault.

Parameter
Type
Required

smOptions

SecretManagerOptions

Yes

recordUids

string[]

Yes

Caching

To protect against losing access to your secrets when network access is lost, the JavaScript SDK allows caching of secrets to the local machine in an encrypted file.

Add queryFunction: cachingPostFunction to SecretManagerOptions

Example usage:

Folders

Folders have full CRUD support - create, read, update and delete operations.

Read Folders

Downloads full folder hierarchy.

Response

Type: KeeperFolder[]

Example Usage

Create a Folder

Requires CreateOptions and folder name to be provided. The folder UID parameter in CreateOptions is required - UID of a shared folder, while sub-folder UID is optional and if missing new regular folder is created directly under the parent (shared folder). There's no requirement for the sub-folder to be a direct descendant of the parent shared folder - it could be many levels deep.

Parameter
Type
Required
Description

options

SecretsManagerOptions

Yes

Preconfigured options

createOptions

CreateOptions

Yes

The parent and sub-folder UIDs

folderName

string

Yes

The Folder name

Example Usage

Update a Folder

Updates the folder metadata - currently folder name only.

Parameter
Type
Required
Description

options

SecretsManagerOptions

Yes

Preconfigured options

folderUid

string

Yes

The folder UID

folderName

string

Yes

The new folder name

Example Usage

Delete Folders

Removes a list of folders. Use forceDeletion flag to remove non-empty folders.

When using forceDeletion avoid sending parent with its children folder UIDs. Depending on the delete order you may get an error - ex. if parent force-deleted child first. There's no guarantee that list will always be processed in FIFO order.

Any folders UIDs missing from the vault or not shared to the KSM Application will not result in error.

Parameter
Type
Required
Default
Description

options

SecretsManagerOptions

Yes

Preconfigured options

folderUids

string[]

Yes

The folder UID list

forceDeletion

bool

No

false

Force deletion of non-empty folders

Example Usage

Proxy Support

In order to use proxy, you need to install and set a proxy agent using setCustomProxyAgent from @keeper-security/secrets-manager-core

Example Usage

Last updated

Was this helpful?