@1password/sdk 0.1.0-beta.3 → 0.1.0-beta.7
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 +92 -0
- package/dist/configuration.d.ts +1 -0
- package/dist/configuration.js +11 -3
- package/dist/core.d.ts +36 -0
- package/dist/core.js +3 -1
- package/dist/items.d.ts +16 -0
- package/dist/items.js +29 -0
- package/dist/sdk.d.ts +1 -0
- package/dist/sdk.js +1 -0
- package/dist/types.d.ts +48 -0
- package/package.json +5 -3
package/README.md
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
<p align="center">
|
|
2
|
+
<a href="https://1password.com">
|
|
3
|
+
<h1 align="center">1Password JavaScript SDK (beta)</h1>
|
|
4
|
+
</a>
|
|
5
|
+
</p>
|
|
6
|
+
|
|
7
|
+
<p align="center">
|
|
8
|
+
<h4 align="center"> ❗ The 1Password SDK project is in beta. Future iterations may bring backwards-incompatible changes.</h4>
|
|
9
|
+
</p>
|
|
10
|
+
|
|
11
|
+
<p align="center">
|
|
12
|
+
<a href="https://developer.1password.com/docs/sdks/">Documentation</a> | <a href="https://github.com/1Password/onepassword-sdk-js/tree/main/examples">Examples</a>
|
|
13
|
+
<br/>
|
|
14
|
+
|
|
15
|
+
---
|
|
16
|
+
|
|
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
|
+
|
|
19
|
+
## 🔑 Authentication
|
|
20
|
+
|
|
21
|
+
1Password SDKs support authentication with [1Password Service Accounts](https://developer.1password.com/docs/service-accounts/get-started/).
|
|
22
|
+
|
|
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
|
+
## ❗ Limitations
|
|
26
|
+
|
|
27
|
+
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.
|
|
28
|
+
|
|
29
|
+
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.
|
|
30
|
+
|
|
31
|
+
When managing items with 1Password SDKs, you must use [unique identifiers (IDs)](https://developer.1password.com/docs/sdks/concepts#unique-identifiers) in place of vault, item, and field names.
|
|
32
|
+
|
|
33
|
+
## 🚀 Get started
|
|
34
|
+
|
|
35
|
+
To use the 1Password JavaScript SDK in your project:
|
|
36
|
+
|
|
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:
|
|
38
|
+
|
|
39
|
+
**macOS or Linux**
|
|
40
|
+
|
|
41
|
+
```bash
|
|
42
|
+
export OP_SERVICE_ACCOUNT_TOKEN=<your-service-account-token>
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
**Windows**
|
|
46
|
+
|
|
47
|
+
```powershell
|
|
48
|
+
$Env:OP_SERVICE_ACCOUNT_TOKEN = "<your-service-account-token>"
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
2. Install the 1Password JavaScript SDK in your project:
|
|
52
|
+
|
|
53
|
+
```bash
|
|
54
|
+
## NPM
|
|
55
|
+
npm install @1password/sdk@beta
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
```bash
|
|
59
|
+
## PNPM
|
|
60
|
+
pnpm add @1password/sdk@beta
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
```bash
|
|
64
|
+
## Yarn
|
|
65
|
+
yarn add @1password/sdk@beta
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
3. Use the JavaScript SDK in your project:
|
|
69
|
+
|
|
70
|
+
```js
|
|
71
|
+
import { createClient } from "@1password/sdk";
|
|
72
|
+
|
|
73
|
+
// Creates an authenticated client.
|
|
74
|
+
const client = await createClient({
|
|
75
|
+
auth: process.env.OP_SERVICE_ACCOUNT_TOKEN,
|
|
76
|
+
integrationName: "My 1Password Integration",
|
|
77
|
+
integrationVersion: "v1.0.0",
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
// Fetches a secret.
|
|
81
|
+
const secret = await client.secrets.resolve("op://vault/item/field");
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
Make sure to use [secret reference URIs](https://developer.1password.com/docs/cli/secrets-reference-syntax/) with the syntax `op://vault/item/field` to securely load secrets from 1Password into your code.
|
|
85
|
+
|
|
86
|
+
Inside `createClient()`, set `integrationName` to the name of your application and `integrationVersion` to the version of your application.
|
|
87
|
+
|
|
88
|
+
## 📖 Learn more
|
|
89
|
+
|
|
90
|
+
- [Load secrets with 1Password SDKs](https://developer.1password.com/docs/sdks/load-secrets)
|
|
91
|
+
- [Manage items with 1Password SDKs](https://developer.1password.com/docs/sdks/manage-items)
|
|
92
|
+
- [1Password SDK concepts](https://developer.1password.com/docs/sdks/concepts)
|
package/dist/configuration.d.ts
CHANGED
package/dist/configuration.js
CHANGED
|
@@ -23,7 +23,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.clientAuthConfig = void 0;
|
|
26
|
+
exports.getOsName = exports.clientAuthConfig = void 0;
|
|
27
27
|
const os = __importStar(require("os"));
|
|
28
28
|
const LANGUAGE = "JS";
|
|
29
29
|
const VERSION = "0010001"; // v0.1.0
|
|
@@ -42,10 +42,18 @@ const clientAuthConfig = (userConfig) => {
|
|
|
42
42
|
integrationVersion: userConfig.integrationVersion,
|
|
43
43
|
requestLibraryName: "Fetch API",
|
|
44
44
|
requestLibraryVersion: "Fetch API",
|
|
45
|
-
|
|
46
|
-
os: os.type().toLowerCase(),
|
|
45
|
+
os: (0, exports.getOsName)(),
|
|
47
46
|
osVersion: defaultOsVersion,
|
|
48
47
|
architecture: os.arch(),
|
|
49
48
|
};
|
|
50
49
|
};
|
|
51
50
|
exports.clientAuthConfig = clientAuthConfig;
|
|
51
|
+
const getOsName = () => {
|
|
52
|
+
// Only supported on Node.js
|
|
53
|
+
const os_name = os.type().toLowerCase();
|
|
54
|
+
if (os_name === "windows_nt") {
|
|
55
|
+
return "windows";
|
|
56
|
+
}
|
|
57
|
+
return os_name;
|
|
58
|
+
};
|
|
59
|
+
exports.getOsName = getOsName;
|
package/dist/core.d.ts
CHANGED
|
@@ -1,8 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Exposes the SDK core to the host JS SDK.
|
|
3
|
+
*/
|
|
1
4
|
export interface Core {
|
|
5
|
+
/**
|
|
6
|
+
* Allocates a new authenticated client and returns its id.
|
|
7
|
+
*/
|
|
2
8
|
initClient(config: ClientAuthConfig): Promise<string>;
|
|
9
|
+
/**
|
|
10
|
+
* Calls business logic from a given client and returns the result.
|
|
11
|
+
*/
|
|
3
12
|
invoke(config: InvokeConfig): Promise<string>;
|
|
13
|
+
/**
|
|
14
|
+
* Deallocates memory held by the given client in the SDK core when it goes out of scope.
|
|
15
|
+
*/
|
|
4
16
|
releaseClient(clientId: number): void;
|
|
5
17
|
}
|
|
18
|
+
/**
|
|
19
|
+
* Wraps configuration information needed to allocate and authenticate a client instance and sends it to the SDK core.
|
|
20
|
+
*/
|
|
6
21
|
export interface ClientAuthConfig {
|
|
7
22
|
serviceAccountToken: string;
|
|
8
23
|
programmingLanguage: string;
|
|
@@ -15,21 +30,42 @@ export interface ClientAuthConfig {
|
|
|
15
30
|
osVersion: string;
|
|
16
31
|
architecture: string;
|
|
17
32
|
}
|
|
33
|
+
/**
|
|
34
|
+
* Contains the information sent to the SDK core when you call (invoke) a function.
|
|
35
|
+
*/
|
|
18
36
|
export interface InvokeConfig {
|
|
37
|
+
/**
|
|
38
|
+
* Identifies the client instance for which you called the function.
|
|
39
|
+
*/
|
|
19
40
|
clientId: number;
|
|
20
41
|
invocation: Invocation;
|
|
21
42
|
}
|
|
43
|
+
/**
|
|
44
|
+
* Calls certain logic from the SDK core, with the given parameters.
|
|
45
|
+
*/
|
|
22
46
|
interface Invocation {
|
|
47
|
+
/**
|
|
48
|
+
* Functionality name
|
|
49
|
+
*/
|
|
23
50
|
name: string;
|
|
51
|
+
/**
|
|
52
|
+
* Parameters
|
|
53
|
+
*/
|
|
24
54
|
parameters: {
|
|
25
55
|
[key: string]: unknown;
|
|
26
56
|
};
|
|
27
57
|
}
|
|
58
|
+
/**
|
|
59
|
+
* An implementation of the `Core` interface that shares resources across all clients.
|
|
60
|
+
*/
|
|
28
61
|
export declare class SharedCore implements Core {
|
|
29
62
|
initClient(config: ClientAuthConfig): Promise<string>;
|
|
30
63
|
invoke(config: InvokeConfig): Promise<string>;
|
|
31
64
|
releaseClient(clientId: number): void;
|
|
32
65
|
}
|
|
66
|
+
/**
|
|
67
|
+
* Represents the client instance on which a call is made.
|
|
68
|
+
*/
|
|
33
69
|
export interface InnerClient {
|
|
34
70
|
id: number;
|
|
35
71
|
core: Core;
|
package/dist/core.js
CHANGED
|
@@ -11,7 +11,9 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.SharedCore = void 0;
|
|
13
13
|
const sdk_core_1 = require("@1password/sdk-core");
|
|
14
|
-
|
|
14
|
+
/**
|
|
15
|
+
* An implementation of the `Core` interface that shares resources across all clients.
|
|
16
|
+
*/
|
|
15
17
|
class SharedCore {
|
|
16
18
|
initClient(config) {
|
|
17
19
|
return __awaiter(this, void 0, void 0, function* () {
|
package/dist/items.d.ts
CHANGED
|
@@ -1,12 +1,28 @@
|
|
|
1
1
|
import { InnerClient } from "./core.js";
|
|
2
2
|
import * as types from "./types.js";
|
|
3
3
|
export interface ItemsApi {
|
|
4
|
+
/**
|
|
5
|
+
* Create a new item
|
|
6
|
+
*/
|
|
4
7
|
create(item: types.Item): Promise<types.Item>;
|
|
8
|
+
/**
|
|
9
|
+
* Get an item by vault and item ID
|
|
10
|
+
*/
|
|
5
11
|
get(vaultId: string, itemId: string): Promise<types.Item>;
|
|
12
|
+
/**
|
|
13
|
+
* Update an existing item. Warning: Only text and concealed fields are currently supported. Other fields will be permanently lost when you update an item.
|
|
14
|
+
*/
|
|
15
|
+
update(item: types.Item): Promise<types.Item>;
|
|
16
|
+
/**
|
|
17
|
+
* Delete an item. Warning: Information saved in fields other than text and concealed fields will be permanently lost.
|
|
18
|
+
*/
|
|
19
|
+
delete(vaultId: string, itemId: string): Promise<void>;
|
|
6
20
|
}
|
|
7
21
|
export declare class ItemsSource implements ItemsApi {
|
|
8
22
|
#private;
|
|
9
23
|
constructor(inner: InnerClient);
|
|
10
24
|
create(item: types.Item): Promise<types.Item>;
|
|
11
25
|
get(vaultId: string, itemId: string): Promise<types.Item>;
|
|
26
|
+
update(item: types.Item): Promise<types.Item>;
|
|
27
|
+
delete(vaultId: string, itemId: string): Promise<void>;
|
|
12
28
|
}
|
package/dist/items.js
CHANGED
|
@@ -56,6 +56,35 @@ class ItemsSource {
|
|
|
56
56
|
return JSON.parse(yield __classPrivateFieldGet(this, _ItemsSource_inner, "f").core.invoke(invocationConfig));
|
|
57
57
|
});
|
|
58
58
|
}
|
|
59
|
+
update(item) {
|
|
60
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
61
|
+
const invocationConfig = {
|
|
62
|
+
clientId: __classPrivateFieldGet(this, _ItemsSource_inner, "f").id,
|
|
63
|
+
invocation: {
|
|
64
|
+
name: "Update",
|
|
65
|
+
parameters: {
|
|
66
|
+
item,
|
|
67
|
+
},
|
|
68
|
+
},
|
|
69
|
+
};
|
|
70
|
+
return JSON.parse(yield __classPrivateFieldGet(this, _ItemsSource_inner, "f").core.invoke(invocationConfig));
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
delete(vaultId, itemId) {
|
|
74
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
75
|
+
const invocationConfig = {
|
|
76
|
+
clientId: __classPrivateFieldGet(this, _ItemsSource_inner, "f").id,
|
|
77
|
+
invocation: {
|
|
78
|
+
name: "Delete",
|
|
79
|
+
parameters: {
|
|
80
|
+
vault_id: vaultId,
|
|
81
|
+
item_id: itemId,
|
|
82
|
+
},
|
|
83
|
+
},
|
|
84
|
+
};
|
|
85
|
+
yield __classPrivateFieldGet(this, _ItemsSource_inner, "f").core.invoke(invocationConfig);
|
|
86
|
+
});
|
|
87
|
+
}
|
|
59
88
|
}
|
|
60
89
|
exports.ItemsSource = ItemsSource;
|
|
61
90
|
_ItemsSource_inner = new WeakMap();
|
package/dist/sdk.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ import { Client } from "./client.js";
|
|
|
3
3
|
export declare const DEFAULT_INTEGRATION_NAME = "Unknown";
|
|
4
4
|
export declare const DEFAULT_INTEGRATION_VERSION = "Unknown";
|
|
5
5
|
export * from "./client.js";
|
|
6
|
+
export * from "./types.js";
|
|
6
7
|
/**
|
|
7
8
|
* Creates a default 1Password SDK client.
|
|
8
9
|
* @returns The authenticated 1Password SDK client.
|
package/dist/sdk.js
CHANGED
|
@@ -29,6 +29,7 @@ const client_builder_js_1 = require("./client_builder.js");
|
|
|
29
29
|
exports.DEFAULT_INTEGRATION_NAME = "Unknown";
|
|
30
30
|
exports.DEFAULT_INTEGRATION_VERSION = "Unknown";
|
|
31
31
|
__exportStar(require("./client.js"), exports);
|
|
32
|
+
__exportStar(require("./types.js"), exports);
|
|
32
33
|
/**
|
|
33
34
|
* Creates a default 1Password SDK client.
|
|
34
35
|
* @returns The authenticated 1Password SDK client.
|
package/dist/types.d.ts
CHANGED
|
@@ -29,22 +29,70 @@ export declare enum ItemFieldType {
|
|
|
29
29
|
Concealed = "Concealed",
|
|
30
30
|
Unsupported = "Unsupported"
|
|
31
31
|
}
|
|
32
|
+
/**
|
|
33
|
+
* Stores a field's title and value.
|
|
34
|
+
*/
|
|
32
35
|
export interface ItemField {
|
|
36
|
+
/**
|
|
37
|
+
* The field's ID
|
|
38
|
+
*/
|
|
33
39
|
id: string;
|
|
40
|
+
/**
|
|
41
|
+
* The field's title
|
|
42
|
+
*/
|
|
34
43
|
title: string;
|
|
44
|
+
/**
|
|
45
|
+
* The ID of the section containing the field
|
|
46
|
+
*/
|
|
35
47
|
section_id?: string;
|
|
48
|
+
/**
|
|
49
|
+
* The type of value stored in the field
|
|
50
|
+
*/
|
|
36
51
|
field_type: ItemFieldType;
|
|
52
|
+
/**
|
|
53
|
+
* The string representation of the field's value
|
|
54
|
+
*/
|
|
37
55
|
value: string;
|
|
38
56
|
}
|
|
57
|
+
/**
|
|
58
|
+
* A section groups together multiple fields in an item.
|
|
59
|
+
*/
|
|
39
60
|
export interface ItemSection {
|
|
61
|
+
/**
|
|
62
|
+
* The ID of the section
|
|
63
|
+
*/
|
|
40
64
|
id: string;
|
|
65
|
+
/**
|
|
66
|
+
* The title of the section
|
|
67
|
+
*/
|
|
41
68
|
title: string;
|
|
42
69
|
}
|
|
70
|
+
/**
|
|
71
|
+
* Represents a 1Password item.
|
|
72
|
+
*/
|
|
43
73
|
export interface Item {
|
|
74
|
+
/**
|
|
75
|
+
* The item's unique ID
|
|
76
|
+
*/
|
|
44
77
|
id: string;
|
|
78
|
+
/**
|
|
79
|
+
* The item's title
|
|
80
|
+
*/
|
|
45
81
|
title: string;
|
|
82
|
+
/**
|
|
83
|
+
* The item's category
|
|
84
|
+
*/
|
|
46
85
|
category: ItemCategory;
|
|
86
|
+
/**
|
|
87
|
+
* The ID of the vault where the item is saved
|
|
88
|
+
*/
|
|
47
89
|
vault_id: string;
|
|
90
|
+
/**
|
|
91
|
+
* The item's fields
|
|
92
|
+
*/
|
|
48
93
|
fields: ItemField[];
|
|
94
|
+
/**
|
|
95
|
+
* The item's sections
|
|
96
|
+
*/
|
|
49
97
|
sections: ItemSection[];
|
|
50
98
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@1password/sdk",
|
|
3
|
-
"version": "0.1.0-beta.
|
|
3
|
+
"version": "0.1.0-beta.7",
|
|
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",
|
|
@@ -8,7 +8,9 @@
|
|
|
8
8
|
"prettier": "prettier --check 'src/*.ts'",
|
|
9
9
|
"prettier-fix": "prettier --write 'src/*.ts'",
|
|
10
10
|
"eslint": "eslint -c .eslintrc.json 'src/*.ts'",
|
|
11
|
-
"prepare": "npm run build"
|
|
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
14
|
},
|
|
13
15
|
"author": "1Password",
|
|
14
16
|
"license": "MIT",
|
|
@@ -24,7 +26,7 @@
|
|
|
24
26
|
"main": "./dist/sdk.js",
|
|
25
27
|
"types": "./dist/sdk.d.ts",
|
|
26
28
|
"dependencies": {
|
|
27
|
-
"@1password/sdk-core": "0.1.0-
|
|
29
|
+
"@1password/sdk-core": "0.1.0-beta.6"
|
|
28
30
|
},
|
|
29
31
|
"devDependencies": {
|
|
30
32
|
"@1password/eslint-config": "^4.0.0",
|