@1password/sdk 0.4.0 → 0.4.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,35 +173,50 @@ 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
- - [ ] User authentication
208
+ - [x] [1Password Service Accounts](https://developer.1password.com/docs/sdks/concepts#1password-service-account)
209
+ - [x] [User authentication](https://developer.1password.com/docs/sdks/concepts#1password-desktop-app)
139
210
  - [ ] 1Password Connect. For now, use [1Password/connect-sdk-js](https://github.com/1Password/connect-sdk-js).
140
211
 
141
212
  ## 📖 Learn more
142
213
 
143
- - [Load secrets with 1Password SDKs](https://developer.1password.com/docs/sdks/load-secrets)
144
- - [Manage items with 1Password SDKs](https://developer.1password.com/docs/sdks/manage-items)
145
- - [List vaults and items with 1Password SDKs](https://developer.1password.com/docs/sdks/list-vaults-items)
214
+ - [Load secrets](https://developer.1password.com/docs/sdks/load-secrets)
215
+ - [Manage items](https://developer.1password.com/docs/sdks/manage-items)
216
+ - [Manage files](https://developer.1password.com/docs/sdks/files)
217
+ - [Share items](https://developer.1password.com/docs/sdks/share-items)
218
+ - [List vaults and items](https://developer.1password.com/docs/sdks/list-vaults-items)
219
+ - [Manage vaults](https://developer.1password.com/docs/sdks/vaults)
220
+ - [Manage vault permissions](https://developer.1password.com/docs/sdks/vault-permissions)
221
+ - [Manage groups](https://developer.1password.com/docs/sdks/groups)
146
222
  - [1Password SDK concepts](https://developer.1password.com/docs/sdks/concepts)
package/dist/client.d.ts CHANGED
@@ -2,11 +2,13 @@ import { InnerClient } from "./core.js";
2
2
  import { SecretsApi } from "./secrets.js";
3
3
  import { ItemsApi } from "./items.js";
4
4
  import { VaultsApi } from "./vaults.js";
5
+ import { EnvironmentsApi } from "./environments.js";
5
6
  import { GroupsApi } from "./groups.js";
6
7
  export declare class Client {
7
8
  secrets: SecretsApi;
8
9
  items: ItemsApi;
9
10
  vaults: VaultsApi;
11
+ environments: EnvironmentsApi;
10
12
  groups: GroupsApi;
11
13
  constructor(innerClient: InnerClient);
12
14
  }
package/dist/client.js CHANGED
@@ -5,12 +5,14 @@ exports.Client = void 0;
5
5
  const secrets_js_1 = require("./secrets.js");
6
6
  const items_js_1 = require("./items.js");
7
7
  const vaults_js_1 = require("./vaults.js");
8
+ const environments_js_1 = require("./environments.js");
8
9
  const groups_js_1 = require("./groups.js");
9
10
  class Client {
10
11
  constructor(innerClient) {
11
12
  this.secrets = new secrets_js_1.Secrets(innerClient);
12
13
  this.items = new items_js_1.Items(innerClient);
13
14
  this.vaults = new vaults_js_1.Vaults(innerClient);
15
+ this.environments = new environments_js_1.Environments(innerClient);
14
16
  this.groups = new groups_js_1.Groups(innerClient);
15
17
  }
16
18
  }
@@ -1,6 +1,6 @@
1
1
  import { ClientAuthConfig } from "./core.js";
2
2
  export declare const LANGUAGE = "JS";
3
- export declare const VERSION = "0040003";
3
+ export declare const VERSION = "0040102";
4
4
  export interface ClientConfiguration {
5
5
  auth: Auth;
6
6
  integrationName: string;
@@ -0,0 +1,19 @@
1
+ import { InnerClient } from "./core.js";
2
+ import { GetVariablesResponse } from "./types.js";
3
+ /**
4
+ * The Environments API holds all the operations the SDK client can perform on 1Password Environments.
5
+ */
6
+ export interface EnvironmentsApi {
7
+ /**
8
+ * Get environment variables belonging to an Environment.
9
+ */
10
+ getVariables(environmentId: string): Promise<GetVariablesResponse>;
11
+ }
12
+ export declare class Environments implements EnvironmentsApi {
13
+ #private;
14
+ constructor(inner: InnerClient);
15
+ /**
16
+ * Get environment variables belonging to an Environment.
17
+ */
18
+ getVariables(environmentId: string): Promise<GetVariablesResponse>;
19
+ }
@@ -0,0 +1,53 @@
1
+ "use strict";
2
+ // Code generated by op-codegen - DO NOT EDIT MANUALLY
3
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
4
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
5
+ return new (P || (P = Promise))(function (resolve, reject) {
6
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
7
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
8
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
9
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
10
+ });
11
+ };
12
+ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
13
+ if (kind === "m") throw new TypeError("Private method is not writable");
14
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
15
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
16
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
17
+ };
18
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
19
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
20
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
21
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
22
+ };
23
+ var _Environments_inner;
24
+ Object.defineProperty(exports, "__esModule", { value: true });
25
+ exports.Environments = void 0;
26
+ const types_js_1 = require("./types.js");
27
+ class Environments {
28
+ constructor(inner) {
29
+ _Environments_inner.set(this, void 0);
30
+ __classPrivateFieldSet(this, _Environments_inner, inner, "f");
31
+ }
32
+ /**
33
+ * Get environment variables belonging to an Environment.
34
+ */
35
+ getVariables(environmentId) {
36
+ return __awaiter(this, void 0, void 0, function* () {
37
+ const invocationConfig = {
38
+ invocation: {
39
+ clientId: __classPrivateFieldGet(this, _Environments_inner, "f").id,
40
+ parameters: {
41
+ name: "EnvironmentsGetVariables",
42
+ parameters: {
43
+ environment_id: environmentId,
44
+ },
45
+ },
46
+ },
47
+ };
48
+ return JSON.parse(yield __classPrivateFieldGet(this, _Environments_inner, "f").invoke(invocationConfig), types_js_1.ReviverFunc);
49
+ });
50
+ }
51
+ }
52
+ exports.Environments = Environments;
53
+ _Environments_inner = new WeakMap();
package/dist/types.d.ts CHANGED
@@ -18,6 +18,15 @@ 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 */
22
+ export interface EnvironmentVariable {
23
+ /** An environment variable's name */
24
+ name: string;
25
+ /** An environment variable's value */
26
+ value: string;
27
+ /** An environment variable's masked state */
28
+ masked: boolean;
29
+ }
21
30
  export interface FileAttributes {
22
31
  /** The name of the file */
23
32
  name: string;
@@ -44,6 +53,11 @@ export interface GeneratePasswordResponse {
44
53
  /** The generated password. */
45
54
  password: string;
46
55
  }
56
+ /** Response containing the full set of environment variables from an Environment. */
57
+ export interface GetVariablesResponse {
58
+ /** List of environment variables. */
59
+ variables: EnvironmentVariable[];
60
+ }
47
61
  export declare enum GroupType {
48
62
  /**
49
63
  * The owners group, which gives the following permissions:
package/dist/version.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- export declare const SDK_VERSION = "0.4.0";
2
- export declare const SDK_BUILD_NUMBER = "0040003";
1
+ export declare const SDK_VERSION = "0.4.1";
2
+ export declare const SDK_BUILD_NUMBER = "0040102";
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.4.0";
5
- exports.SDK_BUILD_NUMBER = "0040003";
6
- const SDK_CORE_VERSION = "0.4.0";
4
+ exports.SDK_VERSION = "0.4.1";
5
+ exports.SDK_BUILD_NUMBER = "0040102";
6
+ const SDK_CORE_VERSION = "0.4.1";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@1password/sdk",
3
- "version": "0.4.0",
3
+ "version": "0.4.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.4.0"
29
+ "@1password/sdk-core": "0.4.1"
30
30
  },
31
31
  "devDependencies": {
32
32
  "@1password/eslint-config": "^4.0.0",