@1password/sdk 0.1.0-beta.11 → 0.1.0-beta.13

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
@@ -16,12 +16,8 @@
16
16
 
17
17
  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.
18
18
 
19
- ## 🔑 Authentication
20
-
21
19
  1Password SDKs support authentication with [1Password Service Accounts](https://developer.1password.com/docs/service-accounts/get-started/).
22
20
 
23
- Before you get started, [create a service account](https://developer.1password.com/docs/service-accounts/get-started/#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.
24
-
25
21
  ## ❗ Limitations
26
22
 
27
23
  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.
@@ -34,7 +30,8 @@ When managing items with 1Password SDKs, you must use [unique identifiers (IDs)]
34
30
 
35
31
  To use the 1Password JavaScript SDK in your project:
36
32
 
37
- 1. Provision your [service account](#authentication) token. We recommend provisioning your token from the environment. For example, to export your token to the `OP_SERVICE_ACCOUNT_TOKEN` environment variable:
33
+ 1. [Create a service account](https://my.1password.com/developer-tools/infrastructure-secrets/serviceaccount/) and give it the appropriate permissions in the vaults where the items you want to use with the SDK are saved.
34
+ 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:
38
35
 
39
36
  **macOS or Linux**
40
37
 
@@ -48,7 +45,7 @@ To use the 1Password JavaScript SDK in your project:
48
45
  $Env:OP_SERVICE_ACCOUNT_TOKEN = "<your-service-account-token>"
49
46
  ```
50
47
 
51
- 2. Install the 1Password JavaScript SDK in your project:
48
+ 3. Install the 1Password JavaScript SDK in your project:
52
49
 
53
50
  ```bash
54
51
  ## NPM
@@ -65,7 +62,7 @@ To use the 1Password JavaScript SDK in your project:
65
62
  yarn add @1password/sdk@beta
66
63
  ```
67
64
 
68
- 3. Use the JavaScript SDK in your project:
65
+ 4. Use the JavaScript SDK in your project:
69
66
 
70
67
  ```js
71
68
  import { createClient } from "@1password/sdk";
@@ -73,6 +70,7 @@ import { createClient } from "@1password/sdk";
73
70
  // Creates an authenticated client.
74
71
  const client = await createClient({
75
72
  auth: process.env.OP_SERVICE_ACCOUNT_TOKEN,
73
+ // Set the following to your own integration name and version.
76
74
  integrationName: "My 1Password Integration",
77
75
  integrationVersion: "v1.0.0",
78
76
  });
@@ -1,4 +1,6 @@
1
1
  import { ClientAuthConfig } from "./core.js";
2
+ export declare const LANGUAGE = "JS";
3
+ export declare const VERSION: any;
2
4
  export interface ClientConfiguration {
3
5
  auth: Auth;
4
6
  integrationName: string;
@@ -1,32 +1,13 @@
1
1
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
24
4
  };
25
5
  Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.getOsName = exports.clientAuthConfig = void 0;
27
- const os = __importStar(require("os"));
28
- const LANGUAGE = "JS";
29
- const VERSION = "0010011"; // v0.1.0-beta.11
6
+ exports.getOsName = exports.clientAuthConfig = exports.VERSION = exports.LANGUAGE = void 0;
7
+ const os_1 = __importDefault(require("os"));
8
+ const version_js_1 = require("../release/version.js");
9
+ exports.LANGUAGE = "JS";
10
+ exports.VERSION = version_js_1.SDK_BUILD_NUMBER;
30
11
  /**
31
12
  * Creates a default client configuration.
32
13
  * @returns The client configuration to instantiate the client with.
@@ -36,21 +17,21 @@ const clientAuthConfig = (userConfig) => {
36
17
  const defaultOsVersion = "0.0.0";
37
18
  return {
38
19
  serviceAccountToken: userConfig.auth,
39
- programmingLanguage: LANGUAGE,
40
- sdkVersion: VERSION,
20
+ programmingLanguage: exports.LANGUAGE,
21
+ sdkVersion: exports.VERSION,
41
22
  integrationName: userConfig.integrationName,
42
23
  integrationVersion: userConfig.integrationVersion,
43
24
  requestLibraryName: "Fetch API",
44
25
  requestLibraryVersion: "Fetch API",
45
26
  os: (0, exports.getOsName)(),
46
27
  osVersion: defaultOsVersion,
47
- architecture: os.arch(),
28
+ architecture: os_1.default.arch(),
48
29
  };
49
30
  };
50
31
  exports.clientAuthConfig = clientAuthConfig;
51
32
  const getOsName = () => {
52
33
  // Only supported on Node.js
53
- const os_name = os.type().toLowerCase();
34
+ const os_name = os_1.default.type().toLowerCase();
54
35
  if (os_name === "windows_nt") {
55
36
  return "windows";
56
37
  }
package/dist/items.d.ts CHANGED
@@ -1,18 +1,21 @@
1
1
  import { InnerClient } from "./core.js";
2
2
  import * as types from "./types.js";
3
+ /**
4
+ * The Items API holds all operations the SDK client can perform on 1Password items.
5
+ */
3
6
  export interface ItemsApi {
4
7
  /**
5
8
  * Create a new item
6
9
  */
7
- create(item: types.Item): Promise<types.Item>;
10
+ create(params: types.ItemCreateParams): Promise<types.Item>;
8
11
  /**
9
12
  * Get an item by vault and item ID
10
13
  */
11
14
  get(vaultId: string, itemId: string): Promise<types.Item>;
12
15
  /**
13
- * Update an existing item. You can currently only edit text and concealed fields.
16
+ * Update an existing item.
14
17
  */
15
- update(item: types.Item): Promise<types.Item>;
18
+ put(item: types.Item): Promise<types.Item>;
16
19
  /**
17
20
  * Delete an item.
18
21
  */
@@ -21,8 +24,20 @@ export interface ItemsApi {
21
24
  export declare class ItemsSource implements ItemsApi {
22
25
  #private;
23
26
  constructor(inner: InnerClient);
24
- create(item: types.Item): Promise<types.Item>;
27
+ /**
28
+ * Create a new item
29
+ */
30
+ create(params: types.ItemCreateParams): Promise<types.Item>;
31
+ /**
32
+ * Get an item by vault and item ID
33
+ */
25
34
  get(vaultId: string, itemId: string): Promise<types.Item>;
26
- update(item: types.Item): Promise<types.Item>;
35
+ /**
36
+ * Update an existing item.
37
+ */
38
+ put(item: types.Item): Promise<types.Item>;
39
+ /**
40
+ * Delete an item.
41
+ */
27
42
  delete(vaultId: string, itemId: string): Promise<void>;
28
43
  }
package/dist/items.js CHANGED
@@ -27,20 +27,26 @@ class ItemsSource {
27
27
  _ItemsSource_inner.set(this, void 0);
28
28
  __classPrivateFieldSet(this, _ItemsSource_inner, inner, "f");
29
29
  }
30
- create(item) {
30
+ /**
31
+ * Create a new item
32
+ */
33
+ create(params) {
31
34
  return __awaiter(this, void 0, void 0, function* () {
32
35
  const invocationConfig = {
33
36
  clientId: __classPrivateFieldGet(this, _ItemsSource_inner, "f").id,
34
37
  invocation: {
35
38
  name: "Create",
36
39
  parameters: {
37
- item,
40
+ params,
38
41
  },
39
42
  },
40
43
  };
41
44
  return JSON.parse(yield __classPrivateFieldGet(this, _ItemsSource_inner, "f").core.invoke(invocationConfig));
42
45
  });
43
46
  }
47
+ /**
48
+ * Get an item by vault and item ID
49
+ */
44
50
  get(vaultId, itemId) {
45
51
  return __awaiter(this, void 0, void 0, function* () {
46
52
  const invocationConfig = {
@@ -56,12 +62,15 @@ class ItemsSource {
56
62
  return JSON.parse(yield __classPrivateFieldGet(this, _ItemsSource_inner, "f").core.invoke(invocationConfig));
57
63
  });
58
64
  }
59
- update(item) {
65
+ /**
66
+ * Update an existing item.
67
+ */
68
+ put(item) {
60
69
  return __awaiter(this, void 0, void 0, function* () {
61
70
  const invocationConfig = {
62
71
  clientId: __classPrivateFieldGet(this, _ItemsSource_inner, "f").id,
63
72
  invocation: {
64
- name: "Update",
73
+ name: "Put",
65
74
  parameters: {
66
75
  item,
67
76
  },
@@ -70,6 +79,9 @@ class ItemsSource {
70
79
  return JSON.parse(yield __classPrivateFieldGet(this, _ItemsSource_inner, "f").core.invoke(invocationConfig));
71
80
  });
72
81
  }
82
+ /**
83
+ * Delete an item.
84
+ */
73
85
  delete(vaultId, itemId) {
74
86
  return __awaiter(this, void 0, void 0, function* () {
75
87
  const invocationConfig = {
package/dist/secrets.d.ts CHANGED
@@ -1,9 +1,19 @@
1
1
  import { InnerClient } from "./core.js";
2
+ /**
3
+ * The Secrets API includes all operations the SDK client can perform on secrets.
4
+ * Use secret reference URIs to securely load secrets from 1Password: op://<vault-name>/<item-name>[/<section-name>]/<field-name>
5
+ */
2
6
  export interface SecretsApi {
7
+ /**
8
+ * Resolve returns the secret the provided secret reference points to.
9
+ */
3
10
  resolve(secretReference: string): Promise<string>;
4
11
  }
5
12
  export declare class SecretsSource implements SecretsApi {
6
13
  #private;
7
14
  constructor(inner: InnerClient);
15
+ /**
16
+ * Resolve returns the secret the provided secret reference points to.
17
+ */
8
18
  resolve(secretReference: string): Promise<string>;
9
19
  }
package/dist/secrets.js CHANGED
@@ -27,6 +27,9 @@ class SecretsSource {
27
27
  _SecretsSource_inner.set(this, void 0);
28
28
  __classPrivateFieldSet(this, _SecretsSource_inner, inner, "f");
29
29
  }
30
+ /**
31
+ * Resolve returns the secret the provided secret reference points to.
32
+ */
30
33
  resolve(secretReference) {
31
34
  return __awaiter(this, void 0, void 0, function* () {
32
35
  const invocationConfig = {
package/dist/types.d.ts CHANGED
@@ -27,72 +27,67 @@ export declare enum ItemCategory {
27
27
  export declare enum ItemFieldType {
28
28
  Text = "Text",
29
29
  Concealed = "Concealed",
30
+ CreditCardType = "CreditCardType",
31
+ Phone = "Phone",
32
+ Url = "Url",
33
+ Totp = "Totp",
30
34
  Unsupported = "Unsupported"
31
35
  }
32
- /**
33
- * Stores a field's title and value.
34
- */
36
+ /** Field type-specific attributes. */
37
+ export type ItemFieldDetails =
38
+ /** The computed OTP code and other details */
39
+ {
40
+ type: "Otp";
41
+ content: OtpFieldDetails;
42
+ };
43
+ /** Represents a field within an item. */
35
44
  export interface ItemField {
36
- /**
37
- * The field's ID
38
- */
45
+ /** The field's ID */
39
46
  id: string;
40
- /**
41
- * The field's title
42
- */
47
+ /** The field's title */
43
48
  title: string;
44
- /**
45
- * The ID of the section containing the field
46
- */
49
+ /** The ID of the section containing the field. Built-in fields such as usernames and passwords don't require a section. */
47
50
  section_id?: string;
48
- /**
49
- * The type of value stored in the field
50
- */
51
+ /** The field's type */
51
52
  field_type: ItemFieldType;
52
- /**
53
- * The string representation of the field's value
54
- */
53
+ /** The string representation of the field's value */
55
54
  value: string;
55
+ /** Field type-specific attributes. */
56
+ details?: ItemFieldDetails;
56
57
  }
57
- /**
58
- * A section groups together multiple fields in an item.
59
- */
58
+ /** A section groups together multiple fields in an item. */
60
59
  export interface ItemSection {
61
- /**
62
- * The ID of the section
63
- */
60
+ /** The section's unique ID */
64
61
  id: string;
65
- /**
66
- * The title of the section
67
- */
62
+ /** The section's title */
68
63
  title: string;
69
64
  }
70
- /**
71
- * Represents a 1Password item.
72
- */
65
+ /** Represents a 1Password item. */
73
66
  export interface Item {
74
- /**
75
- * The item's unique ID
76
- */
67
+ /** The item's ID */
77
68
  id: string;
78
- /**
79
- * The item's title
80
- */
69
+ /** The item's title */
81
70
  title: string;
82
- /**
83
- * The item's category
84
- */
71
+ /** The item's category */
85
72
  category: ItemCategory;
86
- /**
87
- * The ID of the vault where the item is saved
88
- */
73
+ /** The ID of the vault where the item is saved */
89
74
  vault_id: string;
90
- /**
91
- * The item's fields
92
- */
75
+ /** The item's fields */
93
76
  fields: ItemField[];
94
- /**
95
- * The item's sections
96
- */
77
+ /** The item's sections */
97
78
  sections: ItemSection[];
98
79
  }
80
+ export interface ItemCreateParams {
81
+ category: ItemCategory;
82
+ vault_id: string;
83
+ title: string;
84
+ fields: ItemField[];
85
+ sections: ItemSection[];
86
+ }
87
+ /** Additional attributes for OTP fields. */
88
+ export interface OtpFieldDetails {
89
+ /** The OTP code, if successfully computed */
90
+ code?: string;
91
+ /** The error message, if the OTP code could not be computed */
92
+ error_message?: string;
93
+ }
package/dist/types.js CHANGED
@@ -35,5 +35,9 @@ var ItemFieldType;
35
35
  (function (ItemFieldType) {
36
36
  ItemFieldType["Text"] = "Text";
37
37
  ItemFieldType["Concealed"] = "Concealed";
38
+ ItemFieldType["CreditCardType"] = "CreditCardType";
39
+ ItemFieldType["Phone"] = "Phone";
40
+ ItemFieldType["Url"] = "Url";
41
+ ItemFieldType["Totp"] = "Totp";
38
42
  ItemFieldType["Unsupported"] = "Unsupported";
39
43
  })(ItemFieldType || (exports.ItemFieldType = ItemFieldType = {}));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@1password/sdk",
3
- "version": "0.1.0-beta.11",
3
+ "version": "0.1.0-beta.13",
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",
@@ -9,12 +9,14 @@
9
9
  "prettier-fix": "prettier --write 'src/*.ts'",
10
10
  "eslint": "eslint -c .eslintrc.json 'src/*.ts'",
11
11
  "prepare": "rm -rf ./dist && npm run build",
12
- "publish-test": "cp ../README.md . && npm publish --tag beta --dry-run && rm ./README.md",
13
- "publish-beta": "cp ../README.md . && npm publish --tag beta && rm ./README.md"
12
+ "publish-test": "cp ../README.md . && npm publish --tag \"${RELEASE_CHANNEL:-beta}\" --dry-run && rm ./README.md",
13
+ "publish-prod": "cp ../README.md . && npm publish --tag \"${RELEASE_CHANNEL:-beta}\" && rm ./README.md"
14
14
  },
15
15
  "author": "1Password",
16
16
  "license": "MIT",
17
- "files": ["./dist"],
17
+ "files": [
18
+ "./dist"
19
+ ],
18
20
  "exports": {
19
21
  ".": {
20
22
  "types": "./dist/sdk.d.ts",
@@ -24,22 +26,22 @@
24
26
  "main": "./dist/sdk.js",
25
27
  "types": "./dist/sdk.d.ts",
26
28
  "dependencies": {
27
- "@1password/sdk-core": "0.1.0-beta.9"
29
+ "@1password/sdk-core": "0.1.0-beta.12"
28
30
  },
29
31
  "devDependencies": {
30
32
  "@1password/eslint-config": "^4.0.0",
31
33
  "@1password/prettier-config": "^1.1.3",
34
+ "@babel/preset-env": "^7.23.8",
32
35
  "@jest/globals": "^29.7.0",
33
36
  "@types/jest": "^29.5.11",
34
- "jest": "^29.7.0",
37
+ "@types/node": "^20.11.0",
38
+ "babel-jest": "^29.7.0",
35
39
  "eslint": "^8.54.0",
36
- "prettier-plugin-organize-imports": "^3.2.3",
40
+ "jest": "^29.7.0",
37
41
  "jest-environment-jsdom": "^29.6.2",
38
42
  "prettier": "3.1.1",
43
+ "prettier-plugin-organize-imports": "^3.2.3",
39
44
  "ts-jest": "^29.1.1",
40
- "typescript": "^5.3.3",
41
- "@types/node": "^20.11.0",
42
- "@babel/preset-env": "^7.23.8",
43
- "babel-jest": "^29.7.0"
45
+ "typescript": "^5.3.3"
44
46
  }
45
47
  }