JSPM

  • Created
  • Published
  • Downloads 228134
  • Score
    100M100P100Q176496F
  • License MIT

The 1Password JavaScript SDK offers programmatic read access to your secrets in 1Password in an interface native to JavaScript. The SDK currently supports `Node.JS`

Package Exports

  • @1password/sdk

Readme

1Password JavaScript SDK (beta)

❗ The 1Password SDK project is in beta. Future iterations may bring backwards-incompatible changes.

Documentation | Examples


The 1Password JavaScript SDK offers programmatic access to your secrets in 1Password with JavaScript. The SDK currently supports Node.js. During the beta, you can create, retrieve, update, and delete items and resolve secret references.

1Password SDKs support authentication with 1Password Service Accounts.

❗ Limitations

1Password SDKs don't yet support using secret references with query parameters, so you can't retrieve file attachments or SSH keys, or get more information about field metadata.

1Password SDKs currently only support operations on text and concealed fields. As a result, you can't edit items that include information saved in other types of fields.

When managing items with 1Password SDKs, you must use unique identifiers (IDs) in place of vault, item, and field names.

🚀 Get started

To use the 1Password JavaScript SDK in your project:

  1. Create a service account and give it the appropriate permissions in the vaults where the items you want to use with the SDK are saved.

  2. Provision your service account token. We recommend provisioning your token from the environment. For example, to export your token to the OP_SERVICE_ACCOUNT_TOKEN environment variable:

    macOS or Linux

    export OP_SERVICE_ACCOUNT_TOKEN=<your-service-account-token>

    Windows

    $Env:OP_SERVICE_ACCOUNT_TOKEN = "<your-service-account-token>"
  3. Install the 1Password JavaScript SDK in your project:

    ## NPM
    npm install @1password/sdk@beta
    ## PNPM
    pnpm add @1password/sdk@beta
    ## Yarn
    yarn add @1password/sdk@beta
  4. Use the JavaScript SDK in your project:

import { createClient } from "@1password/sdk";

// Creates an authenticated client.
const client = await createClient({
  auth: process.env.OP_SERVICE_ACCOUNT_TOKEN,
  // Set the following to your own integration name and version.
  integrationName: "My 1Password Integration",
  integrationVersion: "v1.0.0",
});

// Fetches a secret.
const secret = await client.secrets.resolve("op://vault/item/field");

Make sure to use secret reference URIs with the syntax op://vault/item/field to securely load secrets from 1Password into your code.

Inside createClient(), set integrationName to the name of your application and integrationVersion to the version of your application.

📖 Learn more