JavaScript SDK
Detailed Javascript SDK docs for Keeper Secrets Manager
Download and Installation
Install with NPM
npm install @keeper-security/secrets-manager-coreFor more information, see https://www.npmjs.com/package/@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)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
Binding Lifecycle
The one-time token is redeemed on the first getSecrets() call, not at construction. If you persist config to an external store (AWS Secrets Manager, Azure Key Vault, etc.), read it back only after that call. For the full explanation, see Binding Lifecycle.
Retrieve Secrets
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
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
secrets
KeeperSecrets
Yes
Secrets to query
query
string
Yes
Keeper Notation 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
url
string
Yes
TOTP Url
unixTimeSeconds
number
Optional
Current timestamp
Unix timestamp in seconds (for testing/verification)
* 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: Promise<{code: string, timeLeft: number, period: number} | null>
An object containing:
code- The TOTP code (6-8 digits)timeLeft- Seconds remaining until code expiresperiod- TOTP period in seconds (typically 30)
Returns null if the TOTP URL is invalid or cannot be processed.
PAM Record Types
Use record.data.type to identify PAM records.
For field schemas of all 11 PAM record types, see PAM Record Types.
Linked Credentials
Pass requestLinks: true in QueryOptions to retrieve PAM resource records with their linked pamUser records included.
Use getLinks(record) to get typed KeeperRecordLink objects with permission, data, and settings accessors. The raw record.links array is also still available.
getLinks(record) returns an empty array when links were not requested or none exist. For the full cross-SDK reference, see Linked Credentials.
Update a Secret
Record update commands don't update local record data on success (esp. updated record revision) so any consecutive updates to an already updated record will fail due to revision mismatch. Make sure to reload all updated records after each update batch.
Parameter
Type
Required
Default
Description
options
SecretManagerOptions
Yes
record
KeeperRecord
Yes
Returns
Type: Promise<void>
Generate a Random Password
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
file
KeeperFile
Yes
File to download
Response
Type: Promise<Uint8Array
Bytes of file for download
Download a Thumbnail
file
KeeperFile
Yes
File with thumbnail to download
Response
Type: Promise<Uint8Array>
Bytes of thumbnail for download
Upload a File
Upload File:
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:
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
options
SecretManagerOptions
Yes
folderUid
string
Yes
record
JSON Object
Yes
options
SecretManagerOptions
Yes
createOptions
CreateOptions
Yes
record
JSON Object
Yes
This example creates a login type record with a login value and a generated password.
Replace '[FOLDER UID]' in the example with the UID of a shared folder that your Secrets Manager has access to.
This example creates a record with a custom record type.
Replace '[FOLDER UID]' in the example with the UID of a shared folder that your Secrets Manager has access to.
Delete a Secret
The JavaScript KSM SDK can delete records in the Keeper Vault.
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:
Browser Secure Storage
In the browser, secureStorage(dbName) provides a storage backend that encrypts KSM credentials at rest in IndexedDB using a non-extractable AES-256-GCM key. The key is generated in the browser and can never be exported, so stored credentials are never held in extractable form.
secureStorage is asynchronous, await it to get the storage instance. It is available only in the browser build. Importing it outside a browser bundle (Node.js, SSR) yields undefined. It is not present in the node entry point.
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.
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.
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.
options
SecretsManagerOptions
Yes
Preconfigured options
folderUids
string[]
Yes
The folder UID list
forceDeletion
bool
No
false
Force deletion of non-empty folders
Example Usage
Custom Server Public Key
For isolated or private deployments where the server's public key is not provisioned with the SDK, you can supply it yourself. Set serverPublicKey (and optionally serverPublicKeyId) on the options object passed to getSecrets:
The same serverPublicKey / serverPublicKeyId values may instead be stored as fields in the configuration. While a custom server public key is configured, the SDK keeps using it and ignores server-pushed key-rotation hints. If the server rejects the configured key, getSecrets throws a plain Error (not KeeperError; see Error Handling) with the rejection reason in e.message. Wrap the call to surface the mismatch explicitly:
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
setCustomProxyAgent works only in NodeJs environment and is not supported in browser.
Error Handling
The SDK exports a KeeperError base class for the errors it raises. Catch it to distinguish SDK-originated errors from unexpected runtime failures. KeeperError extends the built-in Error, so existing instanceof Error handling continues to work.
In v17.5.0, KeeperThrottleError is the only error the SDK raises through the KeeperError hierarchy. Configuration and setup errors (missing fields, bad token, etc.) throw plain Error — they are caught by the else branch above, not instanceof KeeperError.
When the Keeper backend throttles a request (HTTP 403), the SDK automatically retries up to 5 times. When the server includes a retry_after value, the SDK uses that delay; otherwise it falls back to exponential backoff (~11, 22, 44, 88, and 176 seconds, each with jitter). If all retries are exhausted, it throws KeeperThrottleError. No caller changes are required to benefit from the automatic retry.
Last updated
Was this helpful?

