@1password/sdk 0.5.0-beta.1 → 0.5.1-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -5,7 +5,7 @@
5
5
  </p>
6
6
 
7
7
  <p align="center">
8
- <h4 align="center">Build integrations that programmatically access your secrets in 1Password.</h4>
8
+ <h4 align="center">Build integrations that programmatically interact with 1Password.</h4>
9
9
  </p>
10
10
 
11
11
  <p align="center">
@@ -16,7 +16,62 @@
16
16
 
17
17
  ## 🚀 Get started
18
18
 
19
- To use the 1Password JavaScript SDK in your project:
19
+ You can choose between two [authentication methods](https://developer.1password.com/docs/sdks/concepts#authentication) for the 1Password JavaScript SDK: local authorization prompts from the [1Password desktop app](#option-1-1password-desktop-app) or automated authentication with a [1Password Service Account](#option-2-1password-service-account).
20
+
21
+ *This project is licensed under [MIT](./LICENSE). Use of the 1Password APIs and services accessed through these tools is governed by the [1Password API Terms of Service](https://1password.com/legal/api-sdk-terms-of-service).*
22
+
23
+ ### Option 1: 1Password desktop app
24
+
25
+ [1Password desktop app authentication](https://developer.1password.com/docs/sdks/concepts#1password-desktop-app) is best for local integrations that require minimal setup from end users and sensitive workflows that require human-in-the-loop approval.
26
+
27
+ 1. Install the [1Password desktop app](https://1password.com/downloads/) and sign in to your account in the app.
28
+ 2. Select your account or collection at the top of the sidebar, then navigate to **Settings** > **Developer**.
29
+ 3. Under Integrate with the 1Password SDKs, select **Integrate with other apps**.
30
+ 4. If you want to authenticate with biometrics, navigate to **Settings** > **Security**, then turn on the option to unlock using [Touch ID](https://support.1password.com/touch-id-mac/), [Windows Hello](https://support.1password.com/windows-hello/), or [system authentication](https://support.1password.com/system-authentication-linux/).
31
+ 5. Install the 1Password JavaScript SDK in your project:
32
+
33
+ ```bash
34
+ ## NPM
35
+ npm install @1password/sdk
36
+ ```
37
+
38
+ ```bash
39
+ ## PNPM
40
+ pnpm add @1password/sdk
41
+ ```
42
+
43
+ ```bash
44
+ ## Yarn
45
+ yarn add @1password/sdk
46
+
47
+ 6. To use the Javascript SDK in your project, replace `your-account-name` in the code below with the name of your 1Password account as it appears at the top left sidebar of the 1Password desktop app.
48
+
49
+ ```js
50
+ const sdk = require("@1password/sdk");
51
+
52
+ async function main() {
53
+ // Creates an authenticated client.
54
+ const client = await sdk.createClient({
55
+ auth: new sdk.DesktopAuth("your-account-name"),
56
+ // Set the following to your own integration name and version.
57
+ integrationName: "My 1Password Integration",
58
+ integrationVersion: "v1.0.0",
59
+ });
60
+
61
+ // Fetches a secret.
62
+ const secret = await client.secrets.resolve("op://vault/item/field");
63
+ }
64
+
65
+ main()
66
+ ```
67
+
68
+ Inside `createClient()`, set `integrationName` to the name of your application and `integrationVersion` to the version of your application.
69
+
70
+ Make sure to use [secret reference URIs](https://developer.1password.com/docs/cli/secret-reference-syntax/) with the syntax `op://vault/item/field` to securely load secrets from 1Password into your code.
71
+
72
+ ### Option 2: 1Password Service Account
73
+
74
+ [Service account authentication](https://developer.1password.com/docs/sdks/concepts/#1password-service-account) is best for automated access and limiting your integration to least privilege access.
20
75
 
21
76
  1. [Create a service account](https://my.1password.com/developer-tools/infrastructure-secrets/serviceaccount/?source=github-sdk) and give it the appropriate permissions in the vaults where the items you want to use with the SDK are saved.
22
77
  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:
@@ -53,18 +108,22 @@ To use the 1Password JavaScript SDK in your project:
53
108
  4. Use the JavaScript SDK in your project:
54
109
 
55
110
  ```js
56
- import { createClient } from "@1password/sdk";
57
-
58
- // Creates an authenticated client.
59
- const client = await createClient({
60
- auth: process.env.OP_SERVICE_ACCOUNT_TOKEN,
61
- // Set the following to your own integration name and version.
62
- integrationName: "My 1Password Integration",
63
- integrationVersion: "v1.0.0",
64
- });
65
-
66
- // Fetches a secret.
67
- const secret = await client.secrets.resolve("op://vault/item/field");
111
+ const sdk = require("@1password/sdk");
112
+
113
+ async function main() {
114
+ // Creates an authenticated client.
115
+ const client = await sdk.createClient({
116
+ auth: process.env.OP_SERVICE_ACCOUNT_TOKEN,
117
+ // Set the following to your own integration name and version.
118
+ integrationName: "My 1Password Integration",
119
+ integrationVersion: "v1.0.0",
120
+ });
121
+
122
+ // Fetches a secret.
123
+ const secret = await client.secrets.resolve("op://vault/item/field");
124
+ }
125
+
126
+ main()
68
127
  ```
69
128
 
70
129
  Make sure to use [secret reference URIs](https://developer.1password.com/docs/cli/secret-reference-syntax/) with the syntax `op://vault/item/field` to securely load secrets from 1Password into your code.
@@ -77,9 +136,10 @@ Inside `createClient()`, set `integrationName` to the name of your application a
77
136
 
78
137
  ### Item management
79
138
 
80
- Operations:
139
+ **Operations:**
81
140
 
82
141
  - [x] [Retrieve secrets](https://developer.1password.com/docs/sdks/load-secrets)
142
+ - [Read 1Password Environments (beta)](https://developer.1password.com/docs/sdks/environments)
83
143
  - [x] [Retrieve items](https://developer.1password.com/docs/sdks/manage-items#get-an-item)
84
144
  - [x] [Create items](https://developer.1password.com/docs/sdks/manage-items#create-an-item)
85
145
  - [x] [Update items](https://developer.1password.com/docs/sdks/manage-items#update-an-item)
@@ -89,7 +149,8 @@ Operations:
89
149
  - [x] [Share items](https://developer.1password.com/docs/sdks/share-items)
90
150
  - [x] [Generate PIN, random and memorable passwords](https://developer.1password.com/docs/sdks/manage-items#generate-a-password)
91
151
 
92
- Field types:
152
+ **Field types:**
153
+
93
154
  - [x] API Keys
94
155
  - [x] Passwords
95
156
  - [x] Concealed fields
@@ -112,42 +173,57 @@ Field types:
112
173
  - [ ] Passkeys
113
174
 
114
175
  ### Vault management
115
- - [ ] Retrieve vaults
116
- - [ ] Create vaults ([#50](https://github.com/1Password/onepassword-sdk-js/issues/50))
117
- - [ ] Update vaults
118
- - [ ] Delete vaults
119
- - [x] [List vaults](https://developer.1password.com/docs/sdks/list-vaults-items/)
176
+
177
+ - [x] [Retrieve vaults](https://developer.1password.com/docs/sdks/vaults#get-a-vault-overview)
178
+ - [x] [Create vaults](https://developer.1password.com/docs/sdks/vaults#create-a-vault)
179
+ - [x] [Update vaults](https://developer.1password.com/docs/sdks/vaults#update-a-vault)
180
+ - [x] [Delete vaults](https://developer.1password.com/docs/sdks/vaults#delete-a-vault)
181
+ - [x] [List vaults](https://developer.1password.com/docs/sdks/list-vaults-items#list-vaults)
182
+ - [x] [Manage group vault permissions](https://developer.1password.com/docs/sdks/vault-permissions)
183
+ - [ ] Manage user vault permissions
120
184
 
121
185
  ### User & access management
186
+
122
187
  - [ ] Provision users
123
188
  - [ ] Retrieve users
124
189
  - [ ] List users
125
190
  - [ ] Suspend users
191
+ - [x] [Retrieve groups](https://developer.1password.com/docs/sdks/groups/)
192
+ - [ ] List groups
126
193
  - [ ] Create groups
127
194
  - [ ] Update group membership
128
- - [ ] Update vault access & permissions
195
+
196
+ ## Environments management
197
+
198
+ - [x] [Read 1Password Environments](/docs/sdks/environments) (beta)
129
199
 
130
200
  ### Compliance & reporting
201
+
131
202
  - [ ] Watchtower insights
132
203
  - [ ] Travel mode
133
204
  - [ ] Events. For now, use [1Password Events Reporting API](https://developer.1password.com/docs/events-api/) directly.
134
205
 
135
206
  ### Authentication
136
207
 
137
- - [x] [1Password Service Accounts](https://developer.1password.com/docs/service-accounts/get-started/)
138
- - [x] [Workload identity](#workload-identity-beta) (beta)
139
- - [ ] User authentication
208
+ - [x] [1Password Service Accounts](https://developer.1password.com/docs/sdks/concepts#1password-service-account)
209
+ - [x] [Workload identity](#workload-identity-public-preview) (public preview)
210
+ - [x] [User authentication](https://developer.1password.com/docs/sdks/concepts#1password-desktop-app)
140
211
  - [ ] 1Password Connect. For now, use [1Password/connect-sdk-js](https://github.com/1Password/connect-sdk-js).
141
212
 
142
- ### Workload identity (beta)
213
+ ### Workload identity (public preview)
143
214
 
144
- > **Private beta.** Currently available for GitHub Actions via 1Password Credential Broker.
215
+ > **Public Preview** This feature is currently in *public preview*. Please see documentation [here](https://www.1password.dev/environments/credential-broker).
145
216
 
146
217
  Instead of a service account token, you can authenticate a workload by providing an OIDC token fetcher and your workload details. The SDK calls your `oidcFetcher` to obtain a token when it needs one.
147
218
 
148
219
  ## 📖 Learn more
149
220
 
150
- - [Load secrets with 1Password SDKs](https://developer.1password.com/docs/sdks/load-secrets)
151
- - [Manage items with 1Password SDKs](https://developer.1password.com/docs/sdks/manage-items)
152
- - [List vaults and items with 1Password SDKs](https://developer.1password.com/docs/sdks/list-vaults-items)
221
+ - [Load secrets](https://developer.1password.com/docs/sdks/load-secrets)
222
+ - [Manage items](https://developer.1password.com/docs/sdks/manage-items)
223
+ - [Manage files](https://developer.1password.com/docs/sdks/files)
224
+ - [Share items](https://developer.1password.com/docs/sdks/share-items)
225
+ - [List vaults and items](https://developer.1password.com/docs/sdks/list-vaults-items)
226
+ - [Manage vaults](https://developer.1password.com/docs/sdks/vaults)
227
+ - [Manage vault permissions](https://developer.1password.com/docs/sdks/vault-permissions)
228
+ - [Manage groups](https://developer.1password.com/docs/sdks/groups)
153
229
  - [1Password SDK concepts](https://developer.1password.com/docs/sdks/concepts)
@@ -1,6 +1,6 @@
1
1
  import { ClientAuthConfig, WorkloadDetails } from "./core.js";
2
2
  export declare const LANGUAGE = "JS";
3
- export declare const VERSION = "0050001";
3
+ export declare const VERSION = "0050101";
4
4
  export interface ClientConfiguration {
5
5
  auth?: Auth;
6
6
  integrationName: string;
package/dist/errors.d.ts CHANGED
@@ -6,4 +6,8 @@ export declare class RateLimitExceededError extends Error {
6
6
  message: string;
7
7
  constructor(message: string);
8
8
  }
9
+ export declare class AuthExpiredError extends Error {
10
+ message: string;
11
+ constructor(message: string);
12
+ }
9
13
  export declare const throwError: (errString: string) => never;
package/dist/errors.js CHANGED
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  // Code generated by op-codegen - DO NOT EDIT MANUALLY
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.throwError = exports.RateLimitExceededError = exports.DesktopSessionExpiredError = void 0;
4
+ exports.throwError = exports.AuthExpiredError = exports.RateLimitExceededError = exports.DesktopSessionExpiredError = void 0;
5
5
  class DesktopSessionExpiredError extends Error {
6
6
  constructor(message) {
7
7
  super();
@@ -16,6 +16,13 @@ class RateLimitExceededError extends Error {
16
16
  }
17
17
  }
18
18
  exports.RateLimitExceededError = RateLimitExceededError;
19
+ class AuthExpiredError extends Error {
20
+ constructor(message) {
21
+ super();
22
+ this.message = message;
23
+ }
24
+ }
25
+ exports.AuthExpiredError = AuthExpiredError;
19
26
  const throwError = (errString) => {
20
27
  let err;
21
28
  try {
@@ -29,6 +36,8 @@ const throwError = (errString) => {
29
36
  throw new DesktopSessionExpiredError(err.message);
30
37
  case "RateLimitExceeded":
31
38
  throw new RateLimitExceededError(err.message);
39
+ case "AuthExpired":
40
+ throw new AuthExpiredError(err.message);
32
41
  default:
33
42
  throw new Error(err.message);
34
43
  }
@@ -5,6 +5,13 @@ import { Core } from "./core";
5
5
  export declare class SharedLibCore implements Core {
6
6
  private lib;
7
7
  private acccountName;
8
+ /**
9
+ * Loads the 1Password desktop app's shared library.
10
+ *
11
+ * Throws if the desktop app can't be found or its library can't be loaded, so
12
+ * `createClient` rejects and the caller can handle it (for example, fall back
13
+ * to another auth method). It doesn't log the error itself.
14
+ */
8
15
  constructor(accountName: string);
9
16
  /**
10
17
  * callSharedLibrary - send string to native function, receive string back.
@@ -93,29 +93,30 @@ const find1PasswordLibPath = () => {
93
93
  * SharedLibCore: wrapper around the dynamically loaded shared library
94
94
  */
95
95
  class SharedLibCore {
96
+ /**
97
+ * Loads the 1Password desktop app's shared library.
98
+ *
99
+ * Throws if the desktop app can't be found or its library can't be loaded, so
100
+ * `createClient` rejects and the caller can handle it (for example, fall back
101
+ * to another auth method). It doesn't log the error itself.
102
+ */
96
103
  constructor(accountName) {
97
104
  this.lib = null;
98
- try {
99
- const libPath = find1PasswordLibPath();
100
- const moduleStub = { exports: {} };
101
- process.dlopen(moduleStub, libPath);
102
- // Safely check the structure of the loaded module before casting.
103
- if (typeof moduleStub === "object" &&
104
- moduleStub !== null &&
105
- typeof moduleStub.exports === "object" &&
106
- moduleStub.exports !== null &&
107
- "sendMessage" in moduleStub.exports &&
108
- typeof moduleStub.exports.sendMessage ===
109
- "function") {
110
- this.lib = moduleStub.exports;
111
- }
112
- else {
113
- throw new Error("Failed to initialize native library: sendMessage function not found on module.");
114
- }
105
+ const libPath = find1PasswordLibPath();
106
+ const moduleStub = { exports: {} };
107
+ process.dlopen(moduleStub, libPath);
108
+ // Safely check the structure of the loaded module before casting.
109
+ if (typeof moduleStub === "object" &&
110
+ moduleStub !== null &&
111
+ typeof moduleStub.exports === "object" &&
112
+ moduleStub.exports !== null &&
113
+ "sendMessage" in moduleStub.exports &&
114
+ typeof moduleStub.exports.sendMessage ===
115
+ "function") {
116
+ this.lib = moduleStub.exports;
115
117
  }
116
- catch (e) {
117
- console.error("A critical error occurred while loading the native addon:", e);
118
- this.lib = null;
118
+ else {
119
+ throw new Error("Failed to initialize native library: sendMessage function not found on module.");
119
120
  }
120
121
  this.acccountName = accountName;
121
122
  }
package/dist/types.d.ts CHANGED
@@ -18,7 +18,14 @@ export interface DocumentCreateParams {
18
18
  /** The content of the file */
19
19
  content: Uint8Array;
20
20
  }
21
- /** Represents an environment variable (name:value pair) and its masked state */
21
+ /**
22
+ * One environment variable resolved by the credential broker.
23
+ *
24
+ * Shared between the Environments API (`GetVariablesResponse`) and the
25
+ * Credentials API (`CredentialResponse::Environment`, gated on
26
+ * `brokered-access`), since both surfaces read from the same credential
27
+ * broker enclave endpoint.
28
+ */
22
29
  export interface EnvironmentVariable {
23
30
  /** An environment variable's name */
24
31
  name: string;
package/dist/version.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- export declare const SDK_VERSION = "0.5.0-beta.1";
2
- export declare const SDK_BUILD_NUMBER = "0050001";
1
+ export declare const SDK_VERSION = "0.5.1-beta.1";
2
+ export declare const SDK_BUILD_NUMBER = "0050101";
package/dist/version.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.SDK_BUILD_NUMBER = exports.SDK_VERSION = void 0;
4
- exports.SDK_VERSION = "0.5.0-beta.1";
5
- exports.SDK_BUILD_NUMBER = "0050001";
6
- const SDK_CORE_VERSION = "0.5.0-beta.1";
4
+ exports.SDK_VERSION = "0.5.1-beta.1";
5
+ exports.SDK_BUILD_NUMBER = "0050101";
6
+ const SDK_CORE_VERSION = "0.5.0";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@1password/sdk",
3
- "version": "0.5.0-beta.1",
3
+ "version": "0.5.1-beta.1",
4
4
  "description": "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`",
5
5
  "scripts": {
6
6
  "build": "tsc",
@@ -26,7 +26,7 @@
26
26
  "main": "./dist/sdk.js",
27
27
  "types": "./dist/sdk.d.ts",
28
28
  "dependencies": {
29
- "@1password/sdk-core": "0.5.0-beta.1"
29
+ "@1password/sdk-core": "0.5.0"
30
30
  },
31
31
  "devDependencies": {
32
32
  "@1password/eslint-config": "^4.0.0",
@@ -43,5 +43,10 @@
43
43
  "prettier-plugin-organize-imports": "^3.2.3",
44
44
  "ts-jest": "^29.1.1",
45
45
  "typescript": "^5.3.3"
46
+ },
47
+ "repository": {
48
+ "type": "git",
49
+ "url": "git+https://github.com/1Password/onepassword-sdk-js.git",
50
+ "directory": "client"
46
51
  }
47
52
  }